* [9fans] news(1) patch: make -a and -n get along
@ 2021-01-24 21:01 Lyndon Nerenberg
0 siblings, 0 replies; only message in thread
From: Lyndon Nerenberg @ 2021-01-24 21:01 UTC (permalink / raw)
To: Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 132 bytes --]
[ Originally send to 9front-bugs, but this is applicable
across the board ... ]
This patch makes 'news -an' do the right thing.
[-- Attachment #2: Type: text/plain, Size: 1847 bytes --]
/n/dump/2021/0122/sys/src/cmd/news.c:44,65 - news.c:44,72
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;
+ // eachitem(print_item, 1, 0);
break;
case 'n': /* names only */
- eachitem(note, 0, 0);
- if(n_items)
- Bputc(&bout, '\n');
+ doupdate = 0;
+ printer = note;
+ // eachitem(note, 0, 0);
+ // if(n_items)
+ // Bputc(&bout, '\n');
break;
default:
/n/dump/2021/0122/sys/src/cmd/news.c:66,73 - news.c:73,87
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);
}
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/Td990983e87321183-M486341df8c5b1a9191d4c728
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-24 21:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24 21:01 [9fans] news(1) patch: make -a and -n get along Lyndon Nerenberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).