projects
/
oweals
/
busybox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ff724fb
)
fix n, add N, P
author
Glenn L McGrath
<bug1@ihug.co.nz>
Mon, 10 Mar 2003 04:12:35 +0000
(
04:12
-0000)
committer
Glenn L McGrath
<bug1@ihug.co.nz>
Mon, 10 Mar 2003 04:12:35 +0000
(
04:12
-0000)
editors/sed.c
patch
|
blob
|
history
diff --git
a/editors/sed.c
b/editors/sed.c
index 5b08c8ee15a4ec3bf4fb155c65e488112c899d80..e1242671e6ec4e5855aaaf3e3a4786c664ab0f26 100644
(file)
--- a/
editors/sed.c
+++ b/
editors/sed.c
@@
-382,7
+382,7
@@
static char *parse_cmd_str(sed_cmd_t * const sed_cmd, char *cmdstr)
{
/* 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 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("n
p
qd=", sed_cmd->cmd)) {
+ if (strchr("n
NpP
qd=", sed_cmd->cmd)) {
cmdstr++;
}
/* handle (s)ubstitution command */
cmdstr++;
}
/* handle (s)ubstitution command */
@@
-680,6
+680,7
@@
static void process_file(FILE *file)
if (line == NULL) {
return;
}
if (line == NULL) {
return;
}
+ chomp(line);
/* go through every line in the file */
do {
/* go through every line in the file */
do {
@@
-688,7
+689,7
@@
static void process_file(FILE *file)
/* Read one line in advance so we can act on the last line, the '$' address */
next_line = get_line_from_file(file);
/* 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;
linenum++;
altered = 0;
@@
-722,10
+723,15
@@
static void process_file(FILE *file)
case '=':
printf("%d\n", linenum);
break;
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;
puts(line);
break;
-
case 'd':
altered++;
deleted = 1;
case 'd':
altered++;
deleted = 1;
@@
-808,8
+814,19
@@
static void process_file(FILE *file)
free(line);
return;
case 'n': /* Read next line from input */
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;
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++;
}
}
}
}