Anonymous avatar Anonymous committed 844affb

change from file descriptors to streams so i can use fgets/fputs, and the rest because puts(3) says don't mix calls to stdio output functions with calls to write(2)

Comments (0)

Files changed (2)

 Copyright \(co 2010 by Evan Gates <evan.gates (at) gmail (dot) com>
 
 .SH SEE ALSO
-.BI ii (1),
-.BI pcw (1)
+.BR ii (1),
+.BR pcw (1),
+.BR sic (1)
 char  scrl_prompt_right[] = ">";
 char  nrml_prompt_default[] = ">";
 char *nrml_prompt = nrml_prompt_default;
-char  word_separators[] = " \t~!@#$%^&*-+=\\|/?.,><";
+char  word_separators[] = " \t~!@#$%^&*-+=\\|/?.,<>()[]{}";
 
 int start = 0, cur = 0, len = 0;
 int mfd;
 	}
 }
 
-void my_write(int fd, const char *buf, size_t count)
+void my_write(FILE *f, const char *buf, size_t count)
 {
 	int i, wrlen;
 
 	for (i = wrlen = 0; i < count; i += wrlen)
-		if ((wrlen = write(fd, buf + i, count - i)) < 0)
-			warn("failed to write fd = %d", fd);
+		if ((wrlen = fwrite(buf + i, 1, count - i, f)) < 0)
+			warn("failed to write fd = %d", fileno(f));
 }
 
 void erase_usr(void)
 
 	if (start > 0 || len > cols) {
 		left_prompt_len = strlen(scrl_prompt_left);
-		my_write(STDOUT, scrl_prompt_left, left_prompt_len);
+		my_write(stdout, scrl_prompt_left, left_prompt_len);
 		cols = ws.ws_col - 1 - left_prompt_len;
 		start = start_pos(start, cur, len, cols);
 	} else {
-		my_write(STDOUT, nrml_prompt, left_prompt_len);
+		my_write(stdout, nrml_prompt, left_prompt_len);
 	}
 
 	if (start + cols < len) {
 		start = start_pos(start, cur, len, cols);
 	}
 
-	my_write(STDOUT, usrbuf + start, MIN(cols, len));
+	my_write(stdout, usrbuf + start, MIN(cols, len));
 
 	if (start + cols < len)
-		my_write(STDOUT, scrl_prompt_right, right_prompt_len);
+		my_write(stdout, scrl_prompt_right, right_prompt_len);
 
 	cursor_beg();
 	cursor_fwd(left_prompt_len + cur - start);
 	int rdlen, i;
 	char c;
 	fd_set rd;
+	FILE *mf;
+
+	if ((mf = fdopen(mfd, "w+")) == NULL)
+		err(1, "could not fdopen");
 
 	for (;;) {
 		FD_ZERO(&rd);
 					case LINEFEED :
 						erase_usr();
 						usrbuf[len++] = '\n';
-						my_write(mfd, usrbuf, len);
+						my_write(mf, usrbuf, len);
 						start = cur = len = 0;
 						break;
 					case BACKSPACE :
 			print_usr();
 		}
 		if (FD_ISSET(mfd, &rd)) {
-			if ((rdlen = read(mfd, buf, sizeof(buf))) < 0)
-				warn("failed to read from master");
-
 			erase_usr();
-			my_write(STDOUT, buf, rdlen);
+			while (fgets(buf, sizeof(buf), mf))
+				fputs(buf, stdout);
 			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.