[hackers] [sbase] Add support for '-' to cat || sin

From: <git_AT_suckless.org>
Date: Fri, 04 Jul 2014 17:52:31 +0200

commit 5dc02f757bd528e666534cd6492c7c61cdf1a6e4
Author: sin <sin_AT_2f30.org>
Date: Fri Jul 4 16:45:20 2014 +0100

    Add support for '-' to cat
    
    This chunk will need to be librarified at some point.

diff --git a/cat.c b/cat.c
index ebc624f..d22d040 100644
--- a/cat.c
+++ b/cat.c
_AT_@ -15,6 +15,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
+ char *p;
         FILE *fp;
         int i;
 
_AT_@ -27,11 +28,14 @@ main(int argc, char *argv[])
                 concat(stdin, "<stdin>", stdout, "<stdout>");
         } else {
                 for(i = 0; i < argc; i++) {
- if(!(fp = fopen(argv[i], "r"))) {
+ p = argv[i];
+ if (argv[i][0] == '-')
+ p = "/dev/stdin";
+ if(!(fp = fopen(p, "r"))) {
                                 weprintf("fopen %s:", argv[i]);
                                 continue;
                         }
- concat(fp, argv[i], stdout, "<stdout>");
+ concat(fp, p, stdout, "<stdout>");
                         fclose(fp);
                 }
         }
Received on Fri Jul 04 2014 - 17:52:31 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 04 2014 - 18:00:11 CEST