diff --git a/src/dj.c b/src/dj.c index 894feba..1913dd9 100644 --- a/src/dj.c +++ b/src/dj.c @@ -30,7 +30,7 @@ extern int errno; -static char *program_name = "dj"; +char *program_name = "dj"; /* dj uses two structures that respectively correspond to the reading and * writing ends of its jockeyed "pipe". User-configurable members are noted @@ -163,7 +163,7 @@ int main(int argc, char *argv[]) { size_t i; /* side of io being modified */ char noerror; /* 0=exits (default) 1=retries on partial reads or writes */ struct Io io[2 /* { in, out } */]; - char *s = (argv[0] == NULL ? program_name : argv[0]); + program_name = (argv[0] == NULL ? program_name : argv[0]); /* Set defaults. */ align = -1; @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) { /* FALLTHROUGH */ default: - return usage(s); + return usage(program_name); } } } @@ -242,7 +242,7 @@ int main(int argc, char *argv[]) { assert(io->fd != STDIN_FILENO || io->fl == read_flags); assert(io->fd != STDOUT_FILENO || io->fl == write_flags); - if (argc > optind) { return usage(s); } + if (argc > optind) { return usage(program_name); } for (i = 0; i < (sizeof io) / (sizeof *io); ++i) { /* buffer allocation */ diff --git a/src/intcmp.c b/src/intcmp.c index 41a1592..7673944 100644 --- a/src/intcmp.c +++ b/src/intcmp.c @@ -30,7 +30,7 @@ /* 0b?00 */ /* Lesser or Equal | -le | 0b101 | 5 */ #define LESSER 0x04 /* Inequal (Greater or Lesser) | -gl | 0b110 | 6 */ -static char *program_name = "intcmp"; +char *program_name = "intcmp"; int usage(char *s) { fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s); @@ -43,22 +43,22 @@ int main(int argc, char *argv[]) { size_t i; unsigned char mode; int r; /* reference integer */ - char *s = (argv[0] == NULL ? program_name : argv[0]); + program_name = (argv[0] == NULL ? program_name : argv[0]); mode = 0; - if (argc == 0 | argc < 3) { return usage(s); } + if (argc == 0 | argc < 3) { return usage(program_name); } while ((c = getopt(argc, argv, "egl")) != -1) { switch (c) { case 'e': mode |= EQUAL; break; case 'g': mode |= GREATER; break; case 'l': mode |= LESSER; break; - default: return usage(s); + default: return usage(program_name); } } - if (optind + 2 /* ref cmp */ > argc) { return usage(s); } + if (optind + 2 /* ref cmp */ > argc) { return usage(program_name); } i = optind; @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { if (*argv[i] != '\0' || errno != 0) { fprintf( - stderr, "%s: argument #%d: Invalid integer\n", argv[0], (int)i + stderr, "%s: argument #%d: Invalid integer\n", program_name, (int)i ); return EX_USAGE; } diff --git a/src/mm.c b/src/mm.c index 459d3b3..63cc3ff 100644 --- a/src/mm.c +++ b/src/mm.c @@ -48,7 +48,7 @@ struct Files{ #endif /* pre-allocated strings */ -static char *program_name = "mm"; +char *program_name = "mm"; static char *stdin_name = ""; static char *stdout_name = ""; static char *stderr_name = ""; @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { size_t j; size_t k; /* loop index but also unbuffer status */ int retval; - char *s = argv[0] == NULL ? program_name : argv[0]; + program_name = (argv[0] == NULL ? program_name : argv[0]); /* Initializes the files structs with their default values, standard * input and standard output. If an input or an output is specified @@ -150,8 +150,6 @@ int main(int argc, char *argv[]) { k = 0; - if (argc > 0) { program_name = s; } - if (argc > 1) { while ((c = getopt(argc, argv, "aehi:no:u")) != -1) { switch (c){ @@ -164,7 +162,7 @@ int main(int argc, char *argv[]) { break; } - retval = oserr(s, "-e"); + retval = oserr(program_name, "-e"); terminate; case 'i': if ( @@ -173,7 +171,7 @@ int main(int argc, char *argv[]) { || Files_open(&files[0], optarg) != NULL ) { break; } - retval = oserr(s, optarg); + retval = oserr(program_name, optarg); terminate; case 'o': if ( @@ -191,25 +189,25 @@ int main(int argc, char *argv[]) { } } - retval = oserr(s, optarg); + retval = oserr(program_name, optarg); terminate; case 'n': if (signal(SIGINT, SIG_IGN) != SIG_ERR) { break; } - retval = oserr(s, "-n"); + retval = oserr(program_name, "-n"); terminate; case 'u': k = 1; break; default: - retval = usage(s); + retval = usage(program_name); terminate; } } } if (optind != argc) { - retval = usage(s); + retval = usage(program_name); terminate; } diff --git a/src/npc.c b/src/npc.c index 0767163..4f74c6f 100644 --- a/src/npc.c +++ b/src/npc.c @@ -23,7 +23,7 @@ #include /* getopt(3) */ #include /* EX_OK, EX_USAGE */ -static char *program_name = "dj"; +char *program_name = "npc"; int usage(char *s) { fprintf(stderr, "Usage: %s [-et]\n", s); @@ -34,19 +34,19 @@ int main(int argc, char *argv[]) { int c; char showend = 0; /* print a dollar sign before each newline */ char showtab = 0; /* prints tab characters in caret notation */ - char *s = (argv[0] == NULL ? program_name : argv[0]); + program_name = (argv[0] == NULL ? program_name : argv[0]); if (argc > 0) { while ((c = getopt(argc, argv, "et")) != -1) { switch (c){ case 'e': showend = 1; break; case 't': showtab = 1; break; - default: return usage(s); + default: return usage(program_name); } } } - if (argc > optind) { return usage(s); } + if (argc > optind) { return usage(program_name); } while ((c = getc(stdin)) != EOF) { if ((c & 0x80) != 0) { fputs("M-", stdout); } diff --git a/src/scrut.c b/src/scrut.c index ad2ed92..7320c8f 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -26,7 +26,7 @@ * S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK, * S_ISUID, S_ISVTX */ -static char *program_name = "scrut"; +char *program_name = "scrut"; static char args[] = "bcdefgkprsuwxLS"; int usage(char *s) { @@ -36,16 +36,16 @@ int usage(char *s) { int main(int argc, char *argv[]) { char sel[(sizeof args) / (sizeof *args)]; - char *s = (argv[0] == NULL ? program_name : argv[0]); + program_name = (argv[0] == NULL ? program_name : argv[0]); - if (argc < 2) { return usage(s); } + if (argc < 2) { return usage(program_name); } { /* option parsing */ char *p; memset(sel, '\0', sizeof sel); for (int c; (c = getopt(argc, argv, args)) != -1;) { - if ((p = strchr(args, c)) == NULL) { return usage(s); } + if ((p = strchr(args, c)) == NULL) { return usage(program_name); } else { sel[p - args] = c; } } @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { } } - if (optind == argc) { return usage(argv[0]); } + if (optind == argc) { return usage(program_name); } for (argv += optind ; *argv != NULL; ++argv) { struct stat buf; diff --git a/src/strcmp.c b/src/strcmp.c index c9d56b0..16ec3ca 100644 --- a/src/strcmp.c +++ b/src/strcmp.c @@ -20,7 +20,7 @@ #include /* fprintf(3), stderr */ #include /* EX_OK, EX_USAGE */ -static char *program_name = "strcmp"; +char *program_name = "strcmp"; int main(int argc, char *argv[]) { int i;