From f0c896bb3071e753e41afbf9a467793d4fe0ab2c Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Sun, 2 Jun 2019 06:04:18 -0500 Subject: usr.bin/join: make buildable with libbsd --- usr.bin/join/join.c | 71 ++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) (limited to 'usr.bin/join') diff --git a/usr.bin/join/join.c b/usr.bin/join/join.c index b377ec2..f9181f1 100644 --- a/usr.bin/join/join.c +++ b/usr.bin/join/join.c @@ -33,30 +33,13 @@ * SUCH DAMAGE. */ -#if HAVE_NBTOOL_CONFIG_H -#include "nbtool_config.h" -#endif - -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1991\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "from: @(#)join.c 5.1 (Berkeley) 11/18/91"; -#else -__RCSID("$NetBSD: join.c,v 1.31 2011/09/04 20:27:52 joerg Exp $"); -#endif -#endif /* not lint */ - #include #include #include #include #include #include +#include #include #include @@ -68,10 +51,10 @@ __RCSID("$NetBSD: join.c,v 1.31 2011/09/04 20:27:52 joerg Exp $"); */ typedef struct { char *line; /* line */ - u_long linealloc; /* line allocated count */ + unsigned 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 */ + unsigned long fieldcnt; /* line field(s) count */ + unsigned long fieldalloc; /* line field(s) allocated count */ } LINE; static char nolineline[1] = { '\0' }; @@ -79,27 +62,27 @@ static LINE noline = {nolineline, 0, 0, 0, 0}; /* arg for outfield if no line to typedef struct { FILE *fp; /* file descriptor */ - u_long joinf; /* join field (-1, -2, -j) */ + unsigned long joinf; /* join field (-1, -2, -j) */ int unpair; /* output unpairable lines (-a) */ int number; /* 1 for file 1, 2 for file 2 */ LINE *set; /* set of lines with same field */ - u_long pushback; /* line on the stack */ - u_long setcnt; /* set count */ - u_long setalloc; /* set allocated count */ + 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, -1, 0, 0, }, input2 = { NULL, 0, 0, 2, NULL, -1, 0, 0, }; typedef struct { - u_long fileno; /* file number */ - u_long fieldno; /* field number */ + unsigned long fileno; /* 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 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 */ @@ -107,16 +90,16 @@ static int spans = 1; /* span multiple delimiters (-t) */ static char *empty; /* empty field replacement string (-e) */ static const char *tabchar = " \t"; /* delimiter characters (-t) */ -static int cmp(LINE *, u_long, LINE *, u_long); -__dead static void enomem(void); +static int cmp(LINE *, unsigned long, LINE *, unsigned long); +static void enomem(void); static void fieldarg(char *); static void joinlines(INPUT *, INPUT *); static void obsolete(char **); -static void outfield(LINE *, u_long); +static void outfield(LINE *, unsigned long); static void outoneline(INPUT *, LINE *); static void outtwoline(INPUT *, LINE *, INPUT *, LINE *); static void slurp(INPUT *); -__dead static void usage(void); +static void usage(void); int main(int argc, char *argv[]) @@ -303,9 +286,9 @@ slurp(INPUT *F) LINE tmp; LINE *nline; size_t len; - u_long cnt; + unsigned long cnt; char *bp, *fieldp; - u_long nsize; + unsigned long nsize; /* * Read all of the lines from an input file that have the same @@ -340,11 +323,11 @@ slurp(INPUT *F) * but it's probably okay as is. */ lp = &F->set[F->setcnt]; - if (F->pushback != (u_long)-1) { + if (F->pushback != (unsigned long)-1) { tmp = F->set[F->setcnt]; F->set[F->setcnt] = F->set[F->pushback]; F->set[F->pushback] = tmp; - F->pushback = (u_long)-1; + F->pushback = (unsigned long)-1; continue; } if ((bp = fgetln(F->fp, &len)) == NULL) @@ -403,7 +386,7 @@ slurp(INPUT *F) } 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) @@ -416,7 +399,7 @@ cmp(LINE *lp1, u_long fieldno1, LINE *lp2, u_long fieldno2) 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 @@ -436,7 +419,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 @@ -445,7 +428,7 @@ outoneline(INPUT *F, LINE *lp) */ if (olist) for (cnt = 0; cnt < olistcnt; ++cnt) { - if (olist[cnt].fileno == (u_long)F->number) + if (olist[cnt].fileno == (unsigned long)F->number) outfield(lp, olist[cnt].fieldno); else outfield(&noline, 1); @@ -462,7 +445,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) { @@ -491,7 +474,7 @@ outtwoline(INPUT *F1, LINE *lp1, INPUT *F2, LINE *lp2) } static void -outfield(LINE *lp, u_long fieldno) +outfield(LINE *lp, unsigned long fieldno) { if (needsep++) (void)printf("%c", *tabchar); @@ -516,7 +499,7 @@ outfield(LINE *lp, u_long fieldno) static void fieldarg(char *option) { - u_long fieldno; + unsigned long fieldno; char *end, *token; OLIST *n; -- cgit v1.2.3-60-g2f50