dj(1), mm(1), npc(1), scrut(1), str(1): consistent argv[0] handling

This commit is contained in:
2024-07-20 07:18:59 -06:00
parent f96ed9c1f3
commit 0282b60e65
5 changed files with 29 additions and 22 deletions

View File

@@ -23,6 +23,8 @@
#include <unistd.h> /* getopt(3) */
#include <sysexits.h> /* EX_OK, EX_USAGE */
static char *program_name = "dj";
int usage(char *s) {
fprintf(stderr, "Usage: %s [-et]\n", s);
return EX_USAGE;
@@ -32,18 +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]);
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(argv[0]);
default: return usage(s);
}
}
}
if (argc > optind) { return usage(argv[0]); }
if (argc > optind) { return usage(s); }
while ((c = getc(stdin)) != EOF) {
if ((c & 0x80) != 0) { fputs("M-", stdout); }