From 37f94908b8c4f996713a094340b9f15a09227d97 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 9 Jan 2022 03:12:52 -0600 Subject: [PATCH] Cleanup nl (it had a stale TODO entry). Also, the user of FLAG(E) depended on it being 1 and it wasn't, finish -E test. --- tests/nl.test | 3 ++- toys/posix/nl.c | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/nl.test b/tests/nl.test index 046773f5..4bf8e394 100755 --- a/tests/nl.test +++ b/tests/nl.test @@ -52,4 +52,5 @@ testing "-l" "nl -ba -l2 -w2 - input" \ testing "no space" "nl -w 1 -v 42" "42\tline\n" "" "line\n" # Should test for -E but no other implementation seems to have it? -#testing "-E" "nl -w2 -sx -Ebp'(one|two)'" " 1x" "one\nand\ntwo\n" +toyonly testing "-E" "nl -w2 -sx -Ebp'(one|two)'" " 1xone\n and\n 2xtwo\n" \ + "" "one\nand\ntwo\n" diff --git a/toys/posix/nl.c b/toys/posix/nl.c index ef2d7ab3..af95d942 100644 --- a/toys/posix/nl.c +++ b/toys/posix/nl.c @@ -4,10 +4,10 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/nl.html * - * This implements a subset: only one logical page (-ip), no sections (-dfh). - * todo: -l + * Deviations from posix: only one logical page (no -ip), no sections (-dfh), + * add -E, support multiple FILE, -n output is long not int. -USE_NL(NEWTOY(nl, "v#=1l#w#<0=6Eb:n:s:", TOYFLAG_USR|TOYFLAG_BIN)) +USE_NL(NEWTOY(nl, "v#=1l#w#<0=6b:n:s:E", TOYFLAG_USR|TOYFLAG_BIN)) config NL bool "nl" @@ -34,8 +34,7 @@ GLOBALS( long w, l, v; // Count of consecutive blank lines for -l has to persist between files - long lcount; - long slen; + long lcount, slen; ) static void do_nl(char **pline, long len) @@ -71,10 +70,10 @@ void nl_main(void) sprintf(toybuf, "%%%s%s", clip, "*ld%s"); if (!TT.b) TT.b = "t"; - if (*TT.b == 'p' && TT.b[1]) - xregcomp((void *)(toybuf+16), TT.b+1, - REG_NOSUB | (toys.optflags&FLAG_E)*REG_EXTENDED); - else if (!strchr("atn", *TT.b)) error_exit("bad -b '%s'", TT.b); + if (*TT.b=='p' && TT.b[1]) + xregcomp((void *)(toybuf+16), TT.b+1, REG_NOSUB|FLAG(E)*REG_EXTENDED); + else if (!TT.b[0] || TT.b[1] || !strchr("atn", *TT.b)) + error_exit("bad -b '%s'", TT.b); loopfiles_lines(toys.optargs, do_nl); } -- 2.39.2