aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/sed.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-04 21:29:51 -0600
committerRob Landley <rob@landley.net>2018-12-04 21:29:51 -0600
commit747e296ff656813340c9355d98b0a13cba8473bc (patch)
treee7ef2b20be56e2e5a2062168aa822fd6c6139b7d /toys/posix/sed.c
parent141a075c0e192dc9910e777270114b1864270bfd (diff)
downloadtoybox-747e296ff656813340c9355d98b0a13cba8473bc.tar.gz
Add FLAG(x) macro, expanding to (toys.optflags & FLAG_##x)
Diffstat (limited to 'toys/posix/sed.c')
-rw-r--r--toys/posix/sed.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index eadac885..03179ca2 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -260,7 +260,7 @@ static void sed_line(char **pline, long plen)
int eol = 0, tea = 0;
// Ignore EOF for all files before last unless -i
- if (!pline && !(toys.optflags&FLAG_i)) return;
+ if (!pline && !FLAG(i)) return;
// Grab next line for deferred processing (EOF detection: we get a NULL
// pline at EOF to flush last line). Note that only end of _last_ input
@@ -600,7 +600,7 @@ writenow:
command = command->next;
}
- if (line && !(toys.optflags & FLAG_n)) emit(line, len, eol);
+ if (line && !FLAG(n)) emit(line, len, eol);
done:
if (dlist_terminate(append)) while (append) {
@@ -627,10 +627,9 @@ done:
// Callback called on each input file
static void do_sed_file(int fd, char *name)
{
- int i = toys.optflags & FLAG_i;
char *tmp;
- if (i) {
+ if (FLAG(i)) {
struct sedcmd *command;
if (!fd) return error_msg("-i on stdin");
@@ -640,7 +639,7 @@ static void do_sed_file(int fd, char *name)
command->hit = 0;
}
do_lines(fd, sed_line);
- if (i) {
+ if (FLAG(i)) {
replace_tempfile(-1, TT.fdout, &tmp);
TT.fdout = 1;
TT.nextline = 0;
@@ -780,7 +779,7 @@ static void parse_pattern(char **pline, long len)
if (!(s = unescape_delimited_string(&line, 0))) goto error;
if (!*s) command->rmatch[i] = 0;
else {
- xregcomp((void *)reg, s, (toys.optflags & FLAG_r)*REG_EXTENDED);
+ xregcomp((void *)reg, s, FLAG(r)*REG_EXTENDED);
command->rmatch[i] = reg-toybuf;
reg += sizeof(regex_t);
}
@@ -874,7 +873,7 @@ resume_s:
// allocating the space was done by extend_string() above
if (!*TT.remember) command->arg1 = 0;
else xregcomp((void *)(command->arg1 + (char *)command), TT.remember,
- ((toys.optflags & FLAG_r)*REG_EXTENDED)|((command->sflags&1)*REG_ICASE));
+ (FLAG(r)*REG_EXTENDED)|((command->sflags&1)*REG_ICASE));
free(TT.remember);
TT.remember = 0;
if (*line == 'w') {
@@ -995,13 +994,13 @@ void sed_main(void)
// Lie to autoconf when it asks stupid questions, so configure regexes
// that look for "GNU sed version %f" greater than some old buggy number
// don't fail us for not matching their narrow expectations.
- if (toys.optflags & FLAG_version) {
+ if (FLAG(version)) {
xprintf("This is not GNU sed version 9.0\n");
return;
}
// Handling our own --version means we handle our own --help too.
- if (toys.optflags&FLAG_help) help_exit(0);
+ if (FLAG(help)) help_exit(0);
// Parse pattern into commands.
@@ -1027,7 +1026,7 @@ void sed_main(void)
loopfiles_rw(args, O_RDONLY|WARN_ONLY, 0, do_sed_file);
// Provide EOF flush at end of cumulative input for non-i mode.
- if (!(toys.optflags & FLAG_i)) {
+ if (!FLAG(i)) {
toys.optflags |= FLAG_i;
sed_line(0, 0);
}