logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: f7a210aac07f4507330ddf2f816dc1919d80031d
parent 33515c4fd533d1cfdeb02b3cc124d47d660b3f9a
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 02:48:59 +0200

cmd/join: unify error message formatting

Diffstat:

Mcmd/join.c46++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/cmd/join.c b/cmd/join.c @@ -122,13 +122,15 @@ main(int argc, char *argv[]) switch(ch) { case '1': - if((F1->joinf = strtol(optarg, &end, 10)) < 1) errx(1, "-1 option field number less than 1"); - if(*end) errx(1, "illegal field number -- %s", optarg); + if((F1->joinf = strtol(optarg, &end, 10)) < 1) + errx(1, "error: -1 option field number less than 1"); + if(*end) errx(1, "error: illegal field number -- %s", optarg); --F1->joinf; break; case '2': - if((F2->joinf = strtol(optarg, &end, 10)) < 1) errx(1, "-2 option field number less than 1"); - if(*end) errx(1, "illegal field number -- %s", optarg); + if((F2->joinf = strtol(optarg, &end, 10)) < 1) + errx(1, "error: -2 option field number less than 1"); + if(*end) errx(1, "error: illegal field number -- %s", optarg); --F2->joinf; break; case 'a': @@ -142,18 +144,18 @@ main(int argc, char *argv[]) F2->unpair = 1; break; default: - errx(1, "-a option file number not 1 or 2"); + errx(1, "error: -a option file number not 1 or 2"); break; } - if(*end) errx(1, "illegal file number -- %s", optarg); + if(*end) errx(1, "error: illegal file number -- %s", optarg); break; case 'e': empty = optarg; break; case 'j': if((F1->joinf = F2->joinf = strtol(optarg, &end, 10)) < 1) - errx(1, "-j option field number less than 1"); - if(*end) errx(1, "illegal field number -- %s", optarg); + errx(1, "error: -j option field number less than 1"); + if(*end) errx(1, "error: illegal field number -- %s", optarg); --F1->joinf; --F2->joinf; break; @@ -163,7 +165,7 @@ main(int argc, char *argv[]) case 't': spans = 0; if(mbrtowc(&tabchar[0], optarg, MB_LEN_MAX, NULL) != strlen(optarg)) - errx(1, "illegal tab character specification"); + errx(1, "error: illegal tab character specification"); tabchar[1] = L'\0'; break; case 'v': @@ -178,10 +180,10 @@ main(int argc, char *argv[]) F2->unpair = 1; break; default: - errx(1, "-v option file number not 1 or 2"); + errx(1, "error: -v option file number not 1 or 2"); break; } - if(*end) errx(1, "illegal file number -- %s", optarg); + if(*end) errx(1, "error: illegal file number -- %s", optarg); break; case '?': default: @@ -191,7 +193,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if(aflag && vflag) errx(1, "the -a and -v options are mutually exclusive"); + if(aflag && vflag) errx(1, "error: the -a and -v options are mutually exclusive"); if(argc != 2) usage(); @@ -199,13 +201,13 @@ main(int argc, char *argv[]) if(!strcmp(*argv, "-")) F1->fp = stdin; else if((F1->fp = fopen(*argv, "r")) == NULL) - err(1, "%s", *argv); + err(1, "error: %s", *argv); ++argv; if(!strcmp(*argv, "-")) F2->fp = stdin; else if((F2->fp = fopen(*argv, "r")) == NULL) - err(1, "%s", *argv); - if(F1->fp == stdin && F2->fp == stdin) errx(1, "only one input file may be stdin"); + err(1, "error: %s", *argv); + if(F1->fp == stdin && F2->fp == stdin) errx(1, "error: only one input file may be stdin"); slurp(F1); slurp(F2); @@ -353,7 +355,7 @@ mbssep(char **stringp, const wchar_t *delim) n = mbrtowc(&c, s, MB_LEN_MAX, NULL); if(n == (size_t)-1 || n == (size_t)-2) { - fprintf(stderr, "join: mbrtowc: Illegal byte sequence\n"); + fprintf(stderr, "join: error: mbrtowc: Illegal byte sequence\n"); exit(1); } s += n; @@ -458,7 +460,7 @@ outoneline(INPUT *F, LINE *lp) if(F->joinf != cnt) outfield(lp, cnt, 0); } (void)printf("\n"); - if(ferror(stdout)) err(1, "stdout"); + if(ferror(stdout)) err(1, "error: stdout"); needsep = 0; } @@ -494,7 +496,7 @@ outtwoline(INPUT *F1, LINE *lp1, INPUT *F2, LINE *lp2) if(F2->joinf != cnt) outfield(lp2, cnt, 0); } (void)printf("\n"); - if(ferror(stdout)) err(1, "stdout"); + if(ferror(stdout)) err(1, "error: stdout"); needsep = 0; } @@ -514,7 +516,7 @@ outfield(LINE *lp, unsigned long fieldno, int out_empty) (void)printf("%s", lp->fields[fieldno]); } } - if(ferror(stdout)) err(1, "stdout"); + if(ferror(stdout)) err(1, "error: stdout"); } /* @@ -536,12 +538,12 @@ fieldarg(char *option) { filenum = token[0] - '0'; fieldno = strtol(token + 2, &end, 10); - if(*end) errx(1, "malformed -o option field"); - if(fieldno == 0) errx(1, "field numbers are 1 based"); + if(*end) errx(1, "error: malformed -o option field"); + if(fieldno == 0) errx(1, "error: field numbers are 1 based"); --fieldno; } else - errx(1, "malformed -o option field"); + errx(1, "error: malformed -o option field"); if(olistcnt == olistalloc) { olistalloc += 50;