diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-01-26 18:07:04 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-01-26 18:07:04 -0800 |
commit | a5517fca5fff3b6038b5e5a1f3dbc828d798fe92 (patch) | |
tree | 97270a1210a0bdf1fb08334bbdd58640119d0147 | |
parent | 21e5726f43707a5736be0f0e38f41c058620401b (diff) | |
download | plan9front-a5517fca5fff3b6038b5e5a1f3dbc828d798fe92.tar.xz |
news: make -a and -n get along (thanks lyndon)
currently, -a and -n are mutually exclusive.
this change allows them to be used together.
-rw-r--r-- | sys/src/cmd/news.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/sys/src/cmd/news.c b/sys/src/cmd/news.c index ddc58d6de..ef601172c 100644 --- a/sys/src/cmd/news.c +++ b/sys/src/cmd/news.c @@ -44,30 +44,39 @@ void note(char *s); void main(int argc, char *argv[]) { - int i; + int i, aflag = 0, nflag = 0; + int doupdate = 1; + int printall = 0; + void (*printer)(char*) = print_item; Binit(&bout, 1, OWRITE); if(argc == 1) { - eachitem(print_item, 0, 1); + eachitem(print_item, printall, doupdate); exits(0); } ARGBEGIN{ case 'a': /* print all */ - eachitem(print_item, 1, 0); + doupdate = 0; + printall = 1; break; case 'n': /* names only */ - eachitem(note, 0, 0); - if(n_items) - Bputc(&bout, '\n'); + doupdate = 0; + printer = note; break; default: fprint(2, "news: bad option %c\n", ARGC()); exits("usage"); }ARGEND - for(i=0; i<argc; i++) - print_item(argv[i]); + + if (argc == 0) + eachitem(printer, printall, doupdate); + else + for(i=0; i<argc; i++) + print_item(argv[i]); + if (n_items) + Bputc(&bout, '\n'); exits(0); } @@ -227,3 +236,4 @@ note(char *file) Bprint(&bout, " %s", file); n_items++; } + |