Commits

Anonymous committed b03a21d

different tab settings at home and work

Comments (0)

Files changed (1)

 #define STDOUT 1
 #define STDERR 2
 
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
+#define TO_LOWER(c) ((c) | 0x20)
+#define CTRL(c)     (TO_LOWER(c)-'a'+1)
+
 
 char csi[] = {0x1b, '[', 0};
 char buf[4096], usrbuf[4096];
 char  scrl_prompt_default[] = "<";
 char *nrml_prompt = nrml_prompt_default;
 char *scrl_prompt = scrl_prompt_default;
-int pos = 0;
+int end = 0;
 pid_t child;
 
 void usage(void)
 			warn("failed to write fd = %d", fd);
 }
 
-void prompt(int *start, int *cols, int pos)
+void prompt(int *start, int *cols, int end)
 {
 	int prompt_len, scrl_len, nrml_len;
 	char *prompt;
 	nrml_len = strlen(nrml_prompt);
 	scrl_len = strlen(scrl_prompt);
 
-	*start = MAX(0, pos - *cols + nrml_len);
+	*start = MAX(0, end - *cols + nrml_len);
 
 	prompt     = *start ? scrl_prompt : nrml_prompt;
 	prompt_len = *start ? scrl_len    : nrml_len;
 
-	*start = MAX(0, pos - *cols + prompt_len);
+	*start = MAX(0, end - *cols + prompt_len);
 
 	my_write(STDOUT, prompt, prompt_len);
 	*cols -= prompt_len;
 	cols = ws.ws_col - 1;
 
 	erase_usr();
-	prompt(&start, &cols, pos);
-	my_write(STDOUT, usrbuf + start, pos - start);
+	prompt(&start, &cols, end);
+	my_write(STDOUT, usrbuf + start, end - start);
 }
 
 int main(int argc, char **argv)
 		select(mfd + 1, &rd, NULL, NULL, NULL);
 
 		if (FD_ISSET(STDIN, &rd)) {
-			if ((rdlen = read(STDIN, usrbuf + pos, 1)) < 0)
+			if ((rdlen = read(STDIN, usrbuf + end, 1)) < 0)
 				warn("failed to read from stdin");
 
-			switch (usrbuf[pos++]) {
+			switch (usrbuf[end++]) {
 				case '\n':
 					erase_usr();
-					my_write(mfd, usrbuf, pos);
-					pos = 0;
+					my_write(mfd, usrbuf, end);
+					end = 0;
 					break;
 				case '\b' :
 				case 0x7f :
-					pos -= (pos > 1) ? 2 : 1;
+					end -= (end > 1) ? 2 : 1;
 					break;
 				case 0x15 : // Control-u
-					pos = 0;
+					end = 0;
 					break;
 				case 0x17 :
-					for (i = pos - 2; i >= 0 && strchr(word_separators, usrbuf[i]); i--)
-					    ;
+					for (i = end - 2; i >= 0 && strchr(word_separators, usrbuf[i]); i--)
+						;
 					for (i = MAX(i, 0); i >=0 && !strchr(word_separators, usrbuf[i]); i--)
-					    ;
-					pos = i + 1;
+						;
+					end = i + 1;
 					break;
 			}
 			print_usr();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.