sbase

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

commit b8edf3b4ee860f49f8059354704ac9a379930ef1
parent 34f7a688cb9b924aacd422fb4ed13f187ea63487
Author: sin <sin@2f30.org>
Date:   Wed Nov 13 11:39:24 +0000

Add weprintf() and replace fprintf(stderr, ...) calls

There is still some programs left to be updated for this.

Many of these programs would stop on the first file that they
could not open.

Diffstat:
cat.c | 7++++---
cksum.c | 4+---
cut.c | 6++++--
du.c | 4+---
expand.c | 3++-
fold.c | 5+----
head.c | 4+---
nl.c | 6++++--
sort.c | 6++++--
stat.c | 4+---
strings.c | 6++++--
tail.c | 4+---
util.h | 2+-
util/eprintf.c | 15+++++++++++++++
wc.c | 6++++--
15 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/cat.c b/cat.c @@ -26,9 +26,10 @@ main(int argc, char *argv[]) if(argc == 0) { concat(stdin, "<stdin>", stdout, "<stdout>"); } else for(i = 0; i < argc; i++) { - if(!(fp = fopen(argv[i], "r"))) - eprintf("fopen %s:", argv[i]); - + if(!(fp = fopen(argv[i], "r"))) { + weprintf("fopen %s:", argv[i]); + continue; + } concat(fp, argv[i], stdout, "<stdout>"); fclose(fp); } diff --git a/cksum.c b/cksum.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -77,8 +76,7 @@ main(int argc, char *argv[]) } else { for(; argc > 0; argc--, argv++) { if (!(fp = fopen(argv[0], "r"))) { - fprintf(stderr, "fopen %s: %s\n", argv[0], - strerror(errno)); + weprintf("fopen %s:", argv[0]); continue; } cksum(fp, argv[0]); diff --git a/cut.c b/cut.c @@ -155,8 +155,10 @@ main(int argc, char *argv[]) if(!argc) cut(stdin); else for(; argc--; argv++) { - if(!(fp = strcmp(*argv, "-") ? fopen(*argv, "r") : stdin)) - eprintf("fopen %s:", *argv); + if(!(fp = strcmp(*argv, "-") ? fopen(*argv, "r") : stdin)) { + weprintf("fopen %s:", *argv); + continue; + } cut(fp); fclose(fp); } diff --git a/du.c b/du.c @@ -3,7 +3,6 @@ #include <sys/stat.h> #include <dirent.h> #include <unistd.h> -#include <errno.h> #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -120,8 +119,7 @@ du(const char *path) dp = opendir(path); if (!dp) { - fprintf(stderr, "opendir: %s: %s\n", path, - strerror(errno)); + weprintf("opendir %s:", path); goto done; } diff --git a/expand.c b/expand.c @@ -41,7 +41,8 @@ main(int argc, char *argv[]) } else { for (; argc > 0; argc--) { if (!(fp = fopen(*argv, "r"))) { - eprintf("fopen %s:", *argv); + weprintf("fopen %s:", *argv); + continue; } dsc.name = *argv; dsc.fp = fp; diff --git a/fold.c b/fold.c @@ -1,10 +1,8 @@ /* See LICENSE file for copyright and license details. */ #include <ctype.h> -#include <errno.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> #include "text.h" #include "util.h" @@ -48,8 +46,7 @@ main(int argc, char *argv[]) fold(stdin, width); } else for(; argc > 0; argc--, argv++) { if(!(fp = fopen(argv[0], "r"))) { - fprintf(stderr, "fopen %s: %s\n", argv[0], - strerror(errno)); + weprintf("fopen %s:", argv[0]); continue; } fold(fp, width); diff --git a/head.c b/head.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -35,8 +34,7 @@ main(int argc, char *argv[]) head(stdin, "<stdin>", n); } else for(; argc > 0; argc--, argv++) { if(!(fp = fopen(argv[0], "r"))) { - fprintf(stderr, "fopen %s: %s\n", argv[0], - strerror(errno)); + weprintf("fopen %s:", argv[0]); continue; } head(fp, argv[0], n); diff --git a/nl.c b/nl.c @@ -50,8 +50,10 @@ main(int argc, char *argv[]) if(argc == 0) { nl(stdin); } else for(; argc > 0; argc--, argv++) { - if(!(fp = fopen(argv[0], "r"))) - eprintf("fopen %s:", argv[0]); + if(!(fp = fopen(argv[0], "r"))) { + weprintf("fopen %s:", argv[0]); + continue; + } nl(fp); fclose(fp); } diff --git a/sort.c b/sort.c @@ -40,8 +40,10 @@ main(int argc, char *argv[]) if(argc == 0) { getlines(stdin, &linebuf); } else for(; argc > 0; argc--, argv++) { - if(!(fp = fopen(argv[0], "r"))) - eprintf("fopen %s:", argv[0]); + if(!(fp = fopen(argv[0], "r"))) { + weprintf("fopen %s:", argv[0]); + continue; + } getlines(fp, &linebuf); fclose(fp); } diff --git a/stat.c b/stat.c @@ -42,9 +42,7 @@ main(int argc, char *argv[]) for (i = 0; i < argc; i++) { fn = Lflag ? stat : lstat; if (fn(argv[i], &st) == -1) { - fprintf(stderr, "%s %s: ", Lflag ? "stat" : "lstat", - argv[i]); - perror(NULL); + weprintf("%s %s:", Lflag ? "stat" : "lstat", argv[i]); ret = EXIT_FAILURE; continue; } diff --git a/strings.c b/strings.c @@ -26,8 +26,10 @@ main(int argc, char *argv[]) dostrings(stdin, "<stdin>"); } else { for (; argc > 0; argc--, argv++) { - if (!(fp = fopen(argv[0], "r"))) - eprintf("open %s:", argv[0]); + if (!(fp = fopen(argv[0], "r"))) { + weprintf("fopen %s:", argv[0]); + continue; + } dostrings(fp, argv[0]); fclose(fp); } diff --git a/tail.c b/tail.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -42,8 +41,7 @@ main(int argc, char *argv[]) } else { for (; argc > 0; argc--, argv++) { if(!(fp = fopen(argv[0], "r"))) { - fprintf(stderr, "fopen %s: %s\n", argv[0], - strerror(errno)); + weprintf("fopen %s:", argv[0]); continue; } tail(fp, argv[0], n); diff --git a/util.h b/util.h @@ -20,4 +20,4 @@ long estrtol(const char *, int); void fnck(const char *, const char *, int (*)(const char *, const char *)); void putword(const char *); void recurse(const char *, void (*)(const char *)); - +void weprintf(const char *, ...); diff --git a/util/eprintf.c b/util/eprintf.c @@ -45,3 +45,17 @@ venprintf(int status, const char *fmt, va_list ap) exit(status); } +void +weprintf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } +}+ \ No newline at end of file diff --git a/wc.c b/wc.c @@ -47,8 +47,10 @@ main(int argc, char *argv[]) wc(stdin, NULL); } else { for (i = 0; i < argc; i++) { - if(!(fp = fopen(argv[i], "r"))) - eprintf("fopen %s:", argv[i]); + if(!(fp = fopen(argv[i], "r"))) { + weprintf("fopen %s:", argv[i]); + continue; + } wc(fp, argv[i]); fclose(fp); }