sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 4c6c3798125fdb022a265b1e56642bebb7affa30
parent 8c76381e9199137db0a1cdc7e49cfa92f1863ea8
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Tue May 24 11:05:36 +0100

handle --
Diffstat:
cat.c | 14++++++++------
grep.c | 2+-
sleep.c | 6++++--
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/cat.c b/cat.c @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include "util.h" static void cat(FILE *, const char *); @@ -8,15 +9,16 @@ static void cat(FILE *, const char *); int main(int argc, char *argv[]) { - int i; FILE *fp; - if(argc == 1) + if(getopt(argc, argv, "") != -1) + exit(EXIT_FAILURE); + if(optind == argc) cat(stdin, "<stdin>"); - else for(i = 1; i < argc; i++) { - if(!(fp = fopen(argv[i], "r"))) - eprintf("fopen %s:", argv[i]); - cat(fp, argv[i]); + else for(; optind < argc; optind++) { + if(!(fp = fopen(argv[optind], "r"))) + eprintf("fopen %s:", argv[optind]); + cat(fp, argv[optind]); fclose(fp); } return EXIT_SUCCESS; diff --git a/grep.c b/grep.c @@ -36,7 +36,7 @@ main(int argc, char *argv[]) vflag = true; break; default: - exit(EXIT_FAILURE); + exit(2); } if(optind == argc) { fprintf(stderr, "usage: %s [-cilnqv] pattern [files...]\n", argv[0]); diff --git a/sleep.c b/sleep.c @@ -8,10 +8,12 @@ main(int argc, char *argv[]) { unsigned int seconds; - if(argc != 2) + if(getopt(argc, argv, "") != -1) + exit(EXIT_FAILURE); + if(optind != argc-1) eprintf("usage: %s seconds\n", argv[0]); - seconds = atoi(argv[1]); + seconds = atoi(argv[optind]); while((seconds = sleep(seconds)) > 0) ; return EXIT_SUCCESS;