logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 0b09cf601eeeb5bf0511d0c928a9f443f9197fd9
parent 06f8c6580928c47958549885b1c5ca28c3e34f6c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat,  7 Dec 2024 04:52:46 +0100

cmd/join: switch from <err.h> to ./lib/err.h

Diffstat:

MMakefile4++++
Mcmd/join.c47+++++++++++++++++++++++------------------------
2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile @@ -218,3 +218,7 @@ cmd/printf: cmd/printf.c lib/err.c lib/err.h Makefile config.mk cmd/paste: cmd/paste.c lib/err.c lib/err.h Makefile config.mk $(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} $(CC) -std=c99 $(CFLAGS) -o cmd/paste cmd/paste.c lib/err.c $(LDFLAGS) $(LDSTATIC) + +cmd/join: cmd/join.c lib/err.c lib/err.h Makefile config.mk + $(RM) -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) -o cmd/join cmd/join.c lib/err.c $(LDFLAGS) $(LDSTATIC) diff --git a/cmd/join.c b/cmd/join.c @@ -35,7 +35,8 @@ #define _BSD_SOURCE -#include <err.h> +#include "../lib/err.h" + #include <errno.h> #include <limits.h> #include <locale.h> @@ -124,15 +125,13 @@ main(int argc, char *argv[]) switch(ch) { case '1': - 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); + 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); --F1->joinf; break; case '2': - 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); + 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); --F2->joinf; break; case 'a': @@ -146,18 +145,18 @@ main(int argc, char *argv[]) F2->unpair = 1; break; default: - errx(1, "error: -a option file number not 1 or 2"); + errx(1, "-a option file number not 1 or 2"); break; } - if(*end) errx(1, "error: illegal file number -- %s", optarg); + if(*end) errx(1, "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, "error: -j option field number less than 1"); - if(*end) errx(1, "error: illegal field number -- %s", optarg); + errx(1, "-j option field number less than 1"); + if(*end) errx(1, "illegal field number -- %s", optarg); --F1->joinf; --F2->joinf; break; @@ -167,7 +166,7 @@ main(int argc, char *argv[]) case 't': spans = 0; if(mbrtowc(&tabchar[0], optarg, MB_LEN_MAX, NULL) != strlen(optarg)) - errx(1, "error: illegal tab character specification"); + errx(1, "illegal tab character specification"); tabchar[1] = L'\0'; break; case 'v': @@ -182,10 +181,10 @@ main(int argc, char *argv[]) F2->unpair = 1; break; default: - errx(1, "error: -v option file number not 1 or 2"); + errx(1, "-v option file number not 1 or 2"); break; } - if(*end) errx(1, "error: illegal file number -- %s", optarg); + if(*end) errx(1, "illegal file number -- %s", optarg); break; case ':': fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt); @@ -202,7 +201,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if(aflag && vflag) errx(1, "error: the -a and -v options are mutually exclusive"); + if(aflag && vflag) errx(1, "the -a and -v options are mutually exclusive"); if(argc != 2) { @@ -214,13 +213,13 @@ main(int argc, char *argv[]) if(!strcmp(*argv, "-")) F1->fp = stdin; else if((F1->fp = fopen(*argv, "r")) == NULL) - err(1, "error: %s", *argv); + err(1, "%s", *argv); ++argv; if(!strcmp(*argv, "-")) F2->fp = stdin; else if((F2->fp = fopen(*argv, "r")) == NULL) - err(1, "error: %s", *argv); - if(F1->fp == stdin && F2->fp == stdin) errx(1, "error: only one input file may be stdin"); + err(1, "%s", *argv); + if(F1->fp == stdin && F2->fp == stdin) errx(1, "only one input file may be stdin"); slurp(F1); slurp(F2); @@ -473,7 +472,7 @@ outoneline(INPUT *F, LINE *lp) if(F->joinf != cnt) outfield(lp, cnt, 0); } (void)printf("\n"); - if(ferror(stdout)) err(1, "error: stdout"); + if(ferror(stdout)) err(1, "stdout"); needsep = 0; } @@ -509,7 +508,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, "error: stdout"); + if(ferror(stdout)) err(1, "stdout"); needsep = 0; } @@ -529,7 +528,7 @@ outfield(LINE *lp, unsigned long fieldno, int out_empty) (void)printf("%s", lp->fields[fieldno]); } } - if(ferror(stdout)) err(1, "error: stdout"); + if(ferror(stdout)) err(1, "stdout"); } /* @@ -551,12 +550,12 @@ fieldarg(char *option) { filenum = token[0] - '0'; fieldno = strtol(token + 2, &end, 10); - if(*end) errx(1, "error: malformed -o option field"); - if(fieldno == 0) errx(1, "error: field numbers are 1 based"); + if(*end) errx(1, "malformed -o option field"); + if(fieldno == 0) errx(1, "field numbers are 1 based"); --fieldno; } else - errx(1, "error: malformed -o option field"); + errx(1, "malformed -o option field"); if(olistcnt == olistalloc) { olistalloc += 50;