[hackers] [sbase] fix problems in sed || izabera
commit 038dffaa5050cc0179340dabbe3a3a10c4cd61ef
Author: izabera <izaberina_AT_gmail.com>
AuthorDate: Sun Feb 14 13:43:53 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Sun Feb 14 15:05:18 2016 +0000
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
diff --git a/sed.c b/sed.c
index 8480477..6cfd121 100644
--- a/sed.c
+++ b/sed.c
_AT_@ -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;
}
_AT_@ -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;
_AT_@ -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;
}
Received on Sun Feb 14 2016 - 16:05:24 CET
This archive was generated by hypermail 2.3.0
: Sun Feb 14 2016 - 16:12:13 CET