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