logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 2a3955731ccffee4cb95ce17eeffde861c9a70e0
parent 2648303fe7df979887467701d552b92c17eb6ae0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  3 Sep 2024 08:26:48 +0200

cmd/join: remove obvious BSDisms

Diffstat:

Mcmd/join.c77++++++++++++++++++++++++++++++++++++-----------------------------------------
1 file changed, 36 insertions(+), 41 deletions(-)

diff --git a/cmd/join.c b/cmd/join.c @@ -33,16 +33,8 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)join.c 8.6 (Berkeley) 5/4/95"; -#endif -#endif /* not lint */ +#define _BSD_SOURCE + #include <err.h> #include <errno.h> #include <limits.h> @@ -50,7 +42,6 @@ static char sccsid[] = "@(#)join.c 8.6 (Berkeley) 5/4/95"; #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/cdefs.h> #include <sys/param.h> #include <unistd.h> #include <wchar.h> @@ -63,36 +54,36 @@ static char sccsid[] = "@(#)join.c 8.6 (Berkeley) 5/4/95"; */ typedef struct { - char *line; /* line */ - u_long linealloc; /* line allocated count */ - char **fields; /* line field(s) */ - u_long fieldcnt; /* line field(s) count */ - u_long fieldalloc; /* line field(s) allocated count */ + char *line; /* line */ + unsigned long linealloc; /* line allocated count */ + char **fields; /* line field(s) */ + unsigned long fieldcnt; /* line field(s) count */ + unsigned long fieldalloc; /* line field(s) allocated count */ } LINE; typedef struct { - FILE *fp; /* file descriptor */ - u_long joinf; /* join field (-1, -2, -j) */ - int unpair; /* output unpairable lines (-a) */ - u_long number; /* 1 for file 1, 2 for file 2 */ - - LINE *set; /* set of lines with same field */ - int pushbool; /* if pushback is set */ - u_long pushback; /* line on the stack */ - u_long setcnt; /* set count */ - u_long setalloc; /* set allocated count */ + FILE *fp; /* file descriptor */ + unsigned long joinf; /* join field (-1, -2, -j) */ + int unpair; /* output unpairable lines (-a) */ + unsigned long number; /* 1 for file 1, 2 for file 2 */ + + LINE *set; /* set of lines with same field */ + int pushbool; /* if pushback is set */ + unsigned long pushback; /* line on the stack */ + unsigned long setcnt; /* set count */ + unsigned long setalloc; /* set allocated count */ } INPUT; static INPUT input1 = {NULL, 0, 0, 1, NULL, 0, 0, 0, 0}, input2 = {NULL, 0, 0, 2, NULL, 0, 0, 0, 0}; typedef struct { - u_long filenum; /* file number */ - u_long fieldno; /* field number */ + unsigned long filenum; /* file number */ + unsigned long fieldno; /* field number */ } OLIST; -static OLIST *olist; /* output field list */ -static u_long olistcnt; /* output field list count */ -static u_long olistalloc; /* output field allocated count */ +static OLIST *olist; /* output field list */ +static unsigned long olistcnt; /* output field list count */ +static unsigned long olistalloc; /* output field allocated count */ static int joinout = 1; /* show lines with matched join fields (-v) */ static int needsep; /* need separator character */ @@ -101,18 +92,18 @@ static char *empty; /* empty field replacement string (-e) */ static wchar_t default_tabchar[] = L" \t"; static wchar_t *tabchar = default_tabchar; /* delimiter characters (-t) */ -static int cmp(LINE *, u_long, LINE *, u_long); +static int cmp(LINE *, unsigned long, LINE *, unsigned long); static void fieldarg(char *); static void joinlines(INPUT *, INPUT *); static int mbscoll(const char *, const char *); static char *mbssep(char **, const wchar_t *); static void obsolete(char **); -static void outfield(LINE *, u_long, int); +static void outfield(LINE *, unsigned long, int); static void outoneline(INPUT *, LINE *); static void outtwoline(INPUT *, LINE *, INPUT *, LINE *); static void slurp(INPUT *); static wchar_t *towcs(const char *); -static void usage(void) __dead2; +static void usage(void); int main(int argc, char *argv[]) @@ -366,7 +357,11 @@ mbssep(char **stringp, const wchar_t *delim) for(tok = s;;) { n = mbrtowc(&c, s, MB_LEN_MAX, NULL); - if(n == (size_t)-1 || n == (size_t)-2) errc(1, EILSEQ, NULL); /* XXX */ + if(n == (size_t)-1 || n == (size_t)-2) + { + fprintf(stderr, "join: mbrtowc: Illegal byte sequence\n"); + exit(1); + } s += n; spanp = delim; do @@ -385,7 +380,7 @@ mbssep(char **stringp, const wchar_t *delim) } static int -cmp(LINE *lp1, u_long fieldno1, LINE *lp2, u_long fieldno2) +cmp(LINE *lp1, unsigned long fieldno1, LINE *lp2, unsigned long fieldno2) { if(lp1->fieldcnt <= fieldno1) return (lp2->fieldcnt <= fieldno2 ? 0 : 1); if(lp2->fieldcnt <= fieldno2) return (-1); @@ -421,7 +416,7 @@ towcs(const char *s) static void joinlines(INPUT *F1, INPUT *F2) { - u_long cnt1, cnt2; + unsigned long cnt1, cnt2; /* * Output the results of a join comparison. The output may be from @@ -442,7 +437,7 @@ joinlines(INPUT *F1, INPUT *F2) static void outoneline(INPUT *F, LINE *lp) { - u_long cnt; + unsigned long cnt; /* * Output a single line from one of the files, according to the @@ -476,7 +471,7 @@ outoneline(INPUT *F, LINE *lp) static void outtwoline(INPUT *F1, LINE *lp1, INPUT *F2, LINE *lp2) { - u_long cnt; + unsigned long cnt; /* Output a pair of lines according to the join list (if any). */ if(olist) @@ -510,7 +505,7 @@ outtwoline(INPUT *F1, LINE *lp1, INPUT *F2, LINE *lp2) } static void -outfield(LINE *lp, u_long fieldno, int out_empty) +outfield(LINE *lp, unsigned long fieldno, int out_empty) { if(needsep++) (void)printf("%lc", (wint_t)*tabchar); if(!ferror(stdout)) @@ -535,7 +530,7 @@ outfield(LINE *lp, u_long fieldno, int out_empty) static void fieldarg(char *option) { - u_long fieldno, filenum; + unsigned long fieldno, filenum; char *end, *token; while((token = strsep(&option, ", \t")) != NULL)