diff options
Diffstat (limited to 'c/head.c')
| -rw-r--r-- | c/head.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -1,12 +1,13 @@ #include "gbos.h" -/* head [n]: print the first n lines of stdin (default 10). Drains the rest to - EOF so the shell sees a clean end of input. */ +/* head [-n N] [N]: print the first N lines of stdin (default 10). */ void main(void) { - char *a = getargs(); - unsigned char n = 10; - unsigned char lines = 0; + char *argv[8]; + unsigned char argc = argv_parse(argv, 8); + char *nv = optval(argv, argc, 'n'); + unsigned char n = 10, lines = 0; char c; - if (*a) n = atou(a); + if (nv) n = atou(nv); + else if (argc > 0 && argv[0][0] >= '0' && argv[0][0] <= '9') n = atou(argv[0]); for (;;) { c = readc(); if (c == EOF) break; |
