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.
This commit is contained in:
parent
34f7a688cb
commit
b8edf3b4ee
7
cat.c
7
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);
|
||||
}
|
||||
|
|
4
cksum.c
4
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]);
|
||||
|
|
6
cut.c
6
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);
|
||||
}
|
||||
|
|
4
du.c
4
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;
|
||||
}
|
||||
|
||||
|
|
3
expand.c
3
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;
|
||||
|
|
5
fold.c
5
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);
|
||||
|
|
4
head.c
4
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);
|
||||
|
|
6
nl.c
6
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);
|
||||
}
|
||||
|
|
6
sort.c
6
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);
|
||||
}
|
||||
|
|
4
stat.c
4
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
4
tail.c
4
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);
|
||||
|
|
2
util.h
2
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 *, ...);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user