diff options
Diffstat (limited to '')
-rw-r--r-- | src/commands/head.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/commands/head.c b/src/commands/head.c index c09dc9a..da8b9b3 100644 --- a/src/commands/head.c +++ b/src/commands/head.c @@ -66,22 +66,32 @@ static void head_file(char* path, bool many) { static int short_arg(char c, char* next) { switch(c) { case 'c': { + long int bkm; + flags.lines = false; + check_arg(next); - long int bkm = get_blkm(next); + bkm = get_blkm(next); + if (bkm < 1) { error("bkm cannot be less than 1"); } + flags.count = bkm; return ARG_USED; } case 'n': { + long int bkm; + flags.lines = true; + check_arg(next); - long int bkm = get_blkm(next); + bkm = get_blkm(next); + if (bkm < 1) { error("bkm cannot be less than 1"); } + flags.count = bkm; return ARG_USED; } @@ -98,14 +108,17 @@ static int short_arg(char c, char* next) { } COMMAND(head) { + + int start, count, i; + flags.count = 10; flags.lines = true; flags.print_headers = false; flags.dont_print_headers = false; - int start = parse_args(argc, argv, help, short_arg, NULL); + start = parse_args(argc, argv, help, short_arg, NULL); - int count = argc - start; + count = argc - start; if (count < 1) { head_file_lines(stdin); @@ -116,8 +129,8 @@ COMMAND(head) { head_file(argv[start], false); return EXIT_SUCCESS; } - - for (int i = 0; i < count; i++) { + + for (i = 0; i < count; i++) { head_file(argv[start + i], true); } |