[hackers] [sbase] cat: ARGBEGIN || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Thu, 31 May 2012 20:38:48 +0200 (CEST)

changeset: 141:b98778a933b8
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Thu May 31 19:38:18 2012 +0100
files: cat.c
description:
cat: ARGBEGIN


diff -r 30cfaffd10d6 -r b98778a933b8 cat.c
--- a/cat.c Fri May 25 21:56:00 2012 +0100
+++ b/cat.c Thu May 31 19:38:18 2012 +0100
_AT_@ -9,15 +9,19 @@
 main(int argc, char *argv[])
 {
         FILE *fp;
+ int i;
 
- if(getopt(argc, argv, "") != -1)
- exit(EXIT_FAILURE);
- if(optind == argc)
+ ARGBEGIN {
+ default:
+ eprintf("usage: %s [files...]\n", argv0);
+ } ARGEND;
+
+ if(argc == 0)
                 concat(stdin, "<stdin>", stdout, "<stdout>");
- else for(; optind < argc; optind++) {
- if(!(fp = fopen(argv[optind], "r")))
- eprintf("fopen %s:", argv[optind]);
- concat(fp, argv[optind], stdout, "<stdout>");
+ else for(i = 0; i < argc; i++) {
+ if(!(fp = fopen(argv[i], "r")))
+ eprintf("fopen %s:", argv[i]);
+ concat(fp, argv[i], stdout, "<stdout>");
                 fclose(fp);
         }
         return EXIT_SUCCESS;
Received on Thu May 31 2012 - 20:38:48 CEST

This archive was generated by hypermail 2.3.0 : Thu May 31 2012 - 20:48:07 CEST