Anonymous avatar Anonymous committed dc5ba6b

cleanup

Comments (0)

Files changed (1)

 
 char csi[] = {0x1b, '[', 0};
 char buf[4096], usrbuf[4096];
-char scrl_prompt[] = "<";
-char nrml_prompt[] = ">";
+char  nrml_prompt_default[] = ">";
+char  scrl_prompt_default[] = "<";
+char *nrml_prompt = nrml_prompt_default;
+char *scrl_prompt = scrl_prompt_default;
 int pos = 0;
 
+void usage(void)
+{
+	printf("Usage: srw [-p prompt] [-P scroll_prompt] cmd [args]...\n");
+}
+
 void my_write(int fd, const void *buf, size_t count)
 {
 	int i, wrlen;
 	*cols -= prompt_len;
 }
 
-void erase_usr()
+void erase_usr(void)
 {
 	printf("%s1G", csi); //first column
 	printf("%sJ",  csi); //erase
 	fflush(stdout);
 }
 
-void print_usr()
+void print_usr(void)
 {
 	int start, cols;
 	struct winsize ws;
 
 int main(int argc, char **argv)
 {
-	int mfd, rdlen, wrlen, i;
+	int mfd, rdlen, i;
 	fd_set rd;
 	struct termios set;
 
+	for (i = 1; i < argc; i++) {
+		if (argv[i][0] != '-')
+			break;
+		if (argv[i][2] != '\0')
+			usage();
+		switch (argv[i][1]) {
+			case 'p' : nrml_prompt = argv[++i]; break;
+			case 'P' : scrl_prompt = argv[++i]; break;
+			default  : usage();
+		}
+		if (i >= argc)
+			usage();
+	}
+
 	tcgetattr(0, &set);
 	set.c_lflag &= ~ECHO;
 
 	if (forkpty(&mfd, NULL, &set, NULL) == 0) { //child
-		execvp(argv[1], &argv[1]);
-		err("failed execvp %s", argv[1]);
+		execvp(argv[i], &argv[i]);
+		err("failed execvp %s", argv[i]);
 	}
 
 	// read one character at a time;
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.