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:
parent
60ef169a18
commit
038dffaa50
5
sed.c
5
sed.c
|
@ -553,8 +553,8 @@ find_delim(char *s, Rune delim, int do_brackets)
|
||||||
else if (state == BRACKETS_INSIDE && r == ']' ) { state = OUTSIDE ; }
|
else if (state == BRACKETS_INSIDE && r == ']' ) { state = OUTSIDE ; }
|
||||||
else if (state == OUTSIDE && escape ) { escape = 0 ; }
|
else if (state == OUTSIDE && escape ) { escape = 0 ; }
|
||||||
else if (state == OUTSIDE && r == '\\' ) { escape = 1 ; }
|
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 && r == delim) return s;
|
||||||
|
else if (state == OUTSIDE && do_brackets && r == '[' ) { state = BRACKETS_OPENING; }
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -892,6 +892,7 @@ get_s_arg(Cmd *c, char *s)
|
||||||
for (; s < p; s++) {
|
for (; s < p; s++) {
|
||||||
if (isdigit(*s)) {
|
if (isdigit(*s)) {
|
||||||
c->u.s.occurrence = stol(s, &s);
|
c->u.s.occurrence = stol(s, &s);
|
||||||
|
s--; /* for loop will advance pointer */
|
||||||
} else {
|
} else {
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
case 'g': c->u.s.occurrence = 0; break;
|
case 'g': c->u.s.occurrence = 0; break;
|
||||||
|
@ -899,7 +900,7 @@ get_s_arg(Cmd *c, char *s)
|
||||||
case 'w':
|
case 'w':
|
||||||
/* must be last flag, take everything up to newline/semicolon
|
/* must be last flag, take everything up to newline/semicolon
|
||||||
* s == p after this */
|
* 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;
|
c->u.s.file = buf.u.file;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user