[BusyBox-cvs] busybox/editors sed.c,1.104,1.105

Glenn McGrath bug1 at busybox.net
Mon Mar 10 04:12:39 UTC 2003


Update of /var/cvs/busybox/editors
In directory winder:/tmp/cvs-serv13743/editors

Modified Files:
	sed.c 
Log Message:
fix n, add N, P


Index: sed.c
===================================================================
RCS file: /var/cvs/busybox/editors/sed.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- sed.c	10 Mar 2003 02:56:56 -0000	1.104
+++ sed.c	10 Mar 2003 04:12:35 -0000	1.105
@@ -382,7 +382,7 @@
 {
 	/* if it was a single-letter command that takes no arguments (such as 'p'
 	 * or 'd') all we need to do is increment the index past that command */
-	if (strchr("npqd=", sed_cmd->cmd)) {
+	if (strchr("nNpPqd=", sed_cmd->cmd)) {
 		cmdstr++;
 	}
 	/* handle (s)ubstitution command */
@@ -680,6 +680,7 @@
 	if (line == NULL) {
 		return;
 	}
+	chomp(line);
 
 	/* go through every line in the file */
 	do {
@@ -688,7 +689,7 @@
 		/* Read one line in advance so we can act on the last line, the '$' address */
 		next_line = get_line_from_file(file);
 
-		chomp(line);
+		chomp(next_line);
 		linenum++;
 		altered = 0;
 
@@ -722,10 +723,15 @@
 					case '=':
 						printf("%d\n", linenum);
 						break;
-					case 'p':
+					case 'P': {	/* Write the current pattern space upto the first newline */
+							char *tmp = strchr(line, '\n');
+							if (tmp) {
+								*tmp = '\0';
+							}
+						}
+					case 'p':	/* Write the current pattern space to output */
 						puts(line);
 						break;
-
 					case 'd':
 						altered++;
 						deleted = 1;
@@ -808,8 +814,19 @@
 						free(line);
 						return;
 					case 'n':	/* Read next line from input */
-						i = ncmds;
+						free(line);
+						line = next_line;
+						next_line = get_line_from_file(file);
+						chomp(next_line);
+						linenum++;
 						break;
+					case 'N':	/* Append the next line to the current line */
+						line = realloc(line, strlen(line) + strlen(next_line) + 2);
+						strcat(line, "\n");
+						strcat(line, next_line);
+						next_line = get_line_from_file(file);
+						chomp(next_line);
+						linenum++;
 				}
 			}
 




More information about the busybox-cvs mailing list