fix problems in sed

s/x/y/w file          <- chomp whitespace
s/x/y/1p              <- don't ignore first char after number
s[x[y[                <- [ is a valid delim
This commit is contained in:
izabera 2016-02-14 13:43:53 +01:00 committed by sin
parent 60ef169a18
commit 038dffaa50

5
sed.c
View File

@ -553,8 +553,8 @@ find_delim(char *s, Rune delim, int do_brackets)
else if (state == BRACKETS_INSIDE && r == ']' ) { state = OUTSIDE ; }
else if (state == OUTSIDE && escape ) { escape = 0 ; }
else if (state == OUTSIDE && r == '\\' ) { escape = 1 ; }
else if (state == OUTSIDE && do_brackets && r == '[' ) { state = BRACKETS_OPENING; }
else if (state == OUTSIDE && r == delim) return s;
else if (state == OUTSIDE && do_brackets && r == '[' ) { state = BRACKETS_OPENING; }
}
return s;
}
@ -892,6 +892,7 @@ get_s_arg(Cmd *c, char *s)
for (; s < p; s++) {
if (isdigit(*s)) {
c->u.s.occurrence = stol(s, &s);
s--; /* for loop will advance pointer */
} else {
switch (*s) {
case 'g': c->u.s.occurrence = 0; break;
@ -899,7 +900,7 @@ get_s_arg(Cmd *c, char *s)
case 'w':
/* must be last flag, take everything up to newline/semicolon
* s == p after this */
s = get_w_arg(&buf, s);
s = get_w_arg(&buf, chomp(s+1));
c->u.s.file = buf.u.file;
break;
}