From 58c9a4b908c79c0b6183951e7dd68dc69cbf4415 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman Date: Wed, 5 Jun 2019 06:21:58 -0500 Subject: usr.bin/sort: make buildable with libbsd --- usr.bin/sort/append.c | 2 -- usr.bin/sort/fields.c | 42 ++++++++++++++++++++---------------------- usr.bin/sort/files.c | 26 ++++++++++++-------------- usr.bin/sort/fsort.c | 8 +++----- usr.bin/sort/init.c | 4 +--- usr.bin/sort/msort.c | 21 +++++++++------------ usr.bin/sort/radix_sort.c | 22 ++++++---------------- usr.bin/sort/sort.c | 26 ++++++++++---------------- usr.bin/sort/sort.h | 35 +++++++++++++++++++---------------- usr.bin/sort/tmp.c | 4 ---- 10 files changed, 80 insertions(+), 110 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/sort/append.c b/usr.bin/sort/append.c index 07e15e1..2eb6a07 100644 --- a/usr.bin/sort/append.c +++ b/usr.bin/sort/append.c @@ -63,8 +63,6 @@ #include "sort.h" -__RCSID("$NetBSD: append.c,v 1.23 2009/11/06 18:34:22 joerg Exp $"); - #include /* diff --git a/usr.bin/sort/fields.c b/usr.bin/sort/fields.c index 6208a78..29b7682 100644 --- a/usr.bin/sort/fields.c +++ b/usr.bin/sort/fields.c @@ -65,8 +65,6 @@ #include "sort.h" -__RCSID("$NetBSD: fields.c,v 1.33 2013/01/20 10:12:58 apb Exp $"); - #define SKIP_BLANKS(ptr) { \ if (BLANK & d_mask[*(ptr)]) \ while (BLANK & d_mask[*(++(ptr))]); \ @@ -78,9 +76,9 @@ __RCSID("$NetBSD: fields.c,v 1.33 2013/01/20 10:12:58 apb Exp $"); while ((*(pos+1) != '\0') && !((FLD_D | REC_D_F) & l_d_mask[*++pos]));\ } -static u_char *enterfield(u_char *, const u_char *, struct field *, int); -static u_char *number(u_char *, const u_char *, u_char *, u_char *, int); -static u_char *length(u_char *, const u_char *, u_char *, u_char *, int); +static unsigned char *enterfield(unsigned char *, const unsigned char *, struct field *, int); +static unsigned char *number(unsigned char *, const unsigned char *, unsigned char *, unsigned char *, int); +static unsigned char *length(unsigned char *, const unsigned char *, unsigned char *, unsigned char *, int); #define DECIMAL_POINT '.' @@ -89,15 +87,15 @@ static u_char *length(u_char *, const u_char *, u_char *, u_char *, int); * followed by the original line. */ length_t -enterkey(RECHEADER *keybuf, const u_char *keybuf_end, u_char *line_data, +enterkey(RECHEADER *keybuf, const unsigned char *keybuf_end, unsigned char *line_data, size_t line_size, struct field fieldtable[]) /* keybuf: pointer to start of key */ { int i; - u_char *l_d_mask; - u_char *lineend, *pos; - const u_char *endkey; - u_char *keypos; + unsigned char *l_d_mask; + unsigned char *lineend, *pos; + const unsigned char *endkey; + unsigned char *keypos; struct coldesc *clpos; int col = 1; struct field *ftpos; @@ -170,13 +168,13 @@ enterkey(RECHEADER *keybuf, const u_char *keybuf_end, u_char *line_data, /* * constructs a field (as defined by -k) within a key */ -static u_char * -enterfield(u_char *tablepos, const u_char *endkey, struct field *cur_fld, +static unsigned char * +enterfield(unsigned char *tablepos, const unsigned char *endkey, struct field *cur_fld, int gflags) { - u_char *start, *end, *lineend, *mask, *lweight; + unsigned char *start, *end, *lineend, *mask, *lweight; struct column icol, tcol; - u_int flags; + unsigned int flags; icol = cur_fld->icol; tcol = cur_fld->tcol; @@ -247,17 +245,17 @@ enterfield(u_char *tablepos, const u_char *endkey, struct field *cur_fld, */ #define MAX_EXP_ENC ((int)sizeof(int)) -static u_char * -number(u_char *pos, const u_char *bufend, u_char *line, u_char *lineend, +static unsigned char * +number(unsigned char *pos, const unsigned char *bufend, unsigned char *line, unsigned char *lineend, int reverse) { int exponent = -1; int had_dp = 0; - u_char *tline; + unsigned char *tline; char ch; unsigned int val; - u_char *last_nz_pos; - u_char negate; + unsigned char *last_nz_pos; + unsigned char negate; if (reverse & R) negate = 0xff; @@ -368,11 +366,11 @@ number(u_char *pos, const u_char *bufend, u_char *line, u_char *lineend, return (last_nz_pos); } -static u_char * -length(u_char *pos, const u_char *bufend, u_char *line, u_char *lineend, +static unsigned char * +length(unsigned char *pos, const unsigned char *bufend, unsigned char *line, unsigned char *lineend, int flag) { - u_char buf[32]; + unsigned char buf[32]; int l; SKIP_BLANKS(line); l = snprintf((char *)buf, sizeof(buf), "%td", lineend - line); diff --git a/usr.bin/sort/files.c b/usr.bin/sort/files.c index 7cb27c5..937a3da 100644 --- a/usr.bin/sort/files.c +++ b/usr.bin/sort/files.c @@ -64,21 +64,19 @@ #include "sort.h" #include "fsort.h" -__RCSID("$NetBSD: files.c,v 1.42 2015/08/05 07:10:03 mrg Exp $"); - #include /* Align records in temporary files to avoid misaligned copies */ #define REC_ROUNDUP(n) (((n) + sizeof (long) - 1) & ~(sizeof (long) - 1)) -static ssize_t seq(FILE *, u_char **); +static ssize_t seq(FILE *, unsigned char **); /* * this is called when there is no special key. It's only called * in the first fsort pass. */ -static u_char *opos; +static unsigned char *opos; static size_t osz; void @@ -88,9 +86,9 @@ makeline_copydown(RECHEADER *recbuf) } int -makeline(FILE *fp, RECHEADER *recbuf, u_char *bufend, struct field *dummy2) +makeline(FILE *fp, RECHEADER *recbuf, unsigned char *bufend, struct field *dummy2) { - u_char *pos; + unsigned char *pos; int c; pos = recbuf->data; @@ -141,9 +139,9 @@ makeline(FILE *fp, RECHEADER *recbuf, u_char *bufend, struct field *dummy2) * This generates keys. It's only called in the first fsort pass */ int -makekey(FILE *fp, RECHEADER *recbuf, u_char *bufend, struct field *ftbl) +makekey(FILE *fp, RECHEADER *recbuf, unsigned char *bufend, struct field *ftbl) { - static u_char *line_data; + static unsigned char *line_data; static ssize_t line_size; static int overflow = 0; @@ -171,13 +169,13 @@ makekey(FILE *fp, RECHEADER *recbuf, u_char *bufend, struct field *ftbl) * get a line of input from fp */ static ssize_t -seq(FILE *fp, u_char **line) +seq(FILE *fp, unsigned char **line) { - static u_char *buf; + static unsigned char *buf; static size_t buf_size = DEFLLEN; - u_char *end, *pos; + unsigned char *end, *pos; int c; - u_char *new_buf; + unsigned char *new_buf; if (!buf) { /* one-time initialization */ @@ -254,14 +252,14 @@ putkeydump(const RECHEADER *rec, FILE *fp) * get a record from a temporary file. (Used by merge sort.) */ int -geteasy(FILE *fp, RECHEADER *rec, u_char *end, struct field *dummy2) +geteasy(FILE *fp, RECHEADER *rec, unsigned char *end, struct field *dummy2) { length_t file_len; int i; (void)sizeof (char[offsetof(RECHEADER, length) == 0 ? 1 : -1]); - if ((u_char *)(rec + 1) > end) + if ((unsigned char *)(rec + 1) > end) return (BUFFEND); if (!fread(&rec->length, 1, sizeof rec->length, fp)) { fclose(fp); diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c index c229ae2..124bd82 100644 --- a/usr.bin/sort/fsort.c +++ b/usr.bin/sort/fsort.c @@ -71,8 +71,6 @@ #include "sort.h" #include "fsort.h" -__RCSID("$NetBSD: fsort.c,v 1.47 2010/02/05 21:58:41 enami Exp $"); - #include #include @@ -85,7 +83,7 @@ fsort(struct filelist *filelist, int nfiles, FILE *outfp, struct field *ftbl) RECHEADER **keypos, **keyp; RECHEADER *buffer; size_t bufsize = DEFBUFSIZE; - u_char *bufend; + unsigned char *bufend; int mfct = 0; int c, nelem; get_func_t get; @@ -96,7 +94,7 @@ fsort(struct filelist *filelist, int nfiles, FILE *outfp, struct field *ftbl) int max_recs = DEBUG('m') ? 16 : MAXNUM; buffer = allocrec(NULL, bufsize); - bufend = (u_char *)buffer + bufsize; + bufend = (unsigned char *)buffer + bufsize; /* Allocate double length keymap for radix_sort */ keylist = malloc(2 * max_recs * sizeof(*keylist)); if (buffer == NULL || keylist == NULL) @@ -166,7 +164,7 @@ fsort(struct filelist *filelist, int nfiles, FILE *outfp, struct field *ftbl) crec = nbuffer + (crec - buffer); buffer = nbuffer; - bufend = (u_char *)buffer + bufsize; + bufend = (unsigned char *)buffer + bufsize; } /* Sort this set of records */ diff --git a/usr.bin/sort/init.c b/usr.bin/sort/init.c index ff1799b..279deb2 100644 --- a/usr.bin/sort/init.c +++ b/usr.bin/sort/init.c @@ -63,8 +63,6 @@ #include "sort.h" -__RCSID("$NetBSD: init.c,v 1.29 2013/10/18 20:47:06 christos Exp $"); - #include #include @@ -74,7 +72,7 @@ static const char *setcolumn(const char *, struct field *); /* * masks of ignored characters. */ -static u_char dtable[NBINS], itable[NBINS]; +static unsigned char dtable[NBINS], itable[NBINS]; /* * parsed key options diff --git a/usr.bin/sort/msort.c b/usr.bin/sort/msort.c index 6cbcf90..fd31278 100644 --- a/usr.bin/sort/msort.c +++ b/usr.bin/sort/msort.c @@ -64,12 +64,9 @@ #include "sort.h" #include "fsort.h" -__RCSID("$NetBSD: msort.c,v 1.31 2016/06/01 02:37:55 kre Exp $"); - #include #include #include -#include /* Subroutines using comparisons: merge sort and check order */ #define DELETE (1) @@ -78,7 +75,7 @@ typedef struct mfile { FILE *fp; get_func_t get; RECHEADER *rec; - u_char *end; + unsigned char *end; } MFILE; static int cmp(RECHEADER *, RECHEADER *); @@ -197,7 +194,7 @@ merge_sort_fstack(FILE *outfp, put_func_t put, struct field *ftbl) { struct mfile *flistb[MERGE_FNUM], **flist = flistb, *cfile; RECHEADER *new_rec; - u_char *new_end; + unsigned char *new_end; void *tmp; int c, i, nfiles; size_t sz; @@ -207,7 +204,7 @@ merge_sort_fstack(FILE *outfp, put_func_t put, struct field *ftbl) cfile = &fstack[i]; if (cfile->rec == NULL) { cfile->rec = allocrec(NULL, DEFLLEN); - cfile->end = (u_char *)cfile->rec + DEFLLEN; + cfile->end = (unsigned char *)cfile->rec + DEFLLEN; } rewind(cfile->fp); @@ -218,9 +215,9 @@ merge_sort_fstack(FILE *outfp, put_func_t put, struct field *ftbl) if (c == BUFFEND) { /* Double buffer size */ - sz = (cfile->end - (u_char *)cfile->rec) * 2; + sz = (cfile->end - (unsigned char *)cfile->rec) * 2; cfile->rec = allocrec(cfile->rec, sz); - cfile->end = (u_char *)cfile->rec + sz; + cfile->end = (unsigned char *)cfile->rec + sz; continue; } @@ -246,7 +243,7 @@ merge_sort_fstack(FILE *outfp, put_func_t put, struct field *ftbl) * list. */ new_rec = allocrec(NULL, DEFLLEN); - new_end = (u_char *)new_rec + DEFLLEN; + new_end = (unsigned char *)new_rec + DEFLLEN; for (;;) { cfile = flist[0]; c = cfile->get(cfile->fp, new_rec, new_end, ftbl); @@ -262,9 +259,9 @@ merge_sort_fstack(FILE *outfp, put_func_t put, struct field *ftbl) } if (c == BUFFEND) { /* Buffer not large enough - double in size */ - sz = (new_end - (u_char *)new_rec) * 2; + sz = (new_end - (unsigned char *)new_rec) * 2; new_rec = allocrec(new_rec, sz); - new_end = (u_char *)new_rec +sz; + new_end = (unsigned char *)new_rec +sz; continue; } @@ -369,7 +366,7 @@ order(struct filelist *filelist, struct field *ftbl, int quiet) { get_func_t get = SINGL_FLD ? makeline : makekey; RECHEADER *crec, *prec, *trec; - u_char *crec_end, *prec_end, *trec_end; + unsigned char *crec_end, *prec_end, *trec_end; FILE *fp; int c; diff --git a/usr.bin/sort/radix_sort.c b/usr.bin/sort/radix_sort.c index 4ec5ff8..588fca4 100644 --- a/usr.bin/sort/radix_sort.c +++ b/usr.bin/sort/radix_sort.c @@ -32,15 +32,6 @@ * SUCH DAMAGE. */ -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95"; -#else -__RCSID("$NetBSD: radix_sort.c,v 1.4 2009/09/19 16:18:00 dsl Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - /* * 'stable' radix sort initially from libc/stdlib/radixsort.c */ @@ -49,7 +40,6 @@ __RCSID("$NetBSD: radix_sort.c,v 1.4 2009/09/19 16:18:00 dsl Exp $"); #include #include -#include #include "sort.h" typedef struct { @@ -70,14 +60,14 @@ static void simplesort(RECHEADER **, int, int); void radix_sort(RECHEADER **a, RECHEADER **ta, int n) { - u_int count[256], nc, bmin; - u_int c; + unsigned int count[256], nc, bmin; + unsigned int c; RECHEADER **ak, **tai, **lim; RECHEADER *hdr; int stack_size = 512; stack *s, *sp, *sp0, *sp1, temp; RECHEADER **top[256]; - u_int *cp, bigc; + unsigned int *cp, bigc; int data_index = 0; if (n < THRESHOLD && !DEBUG('r')) { @@ -85,7 +75,7 @@ radix_sort(RECHEADER **a, RECHEADER **ta, int n) return; } - s = emalloc(stack_size * sizeof *s); + s = malloc(stack_size * sizeof *s); memset(&count, 0, sizeof count); /* Technically 'top' doesn't need zeroing */ memset(&top, 0, sizeof top); @@ -129,7 +119,7 @@ radix_sort(RECHEADER **a, RECHEADER **ta, int n) */ if (sp + nc > s + stack_size) { stack_size *= 2; - sp1 = erealloc(s, stack_size * sizeof *s); + sp1 = realloc(s, stack_size * sizeof *s); sp = sp1 + (sp - s); s = sp1; } @@ -170,7 +160,7 @@ simplesort(RECHEADER **a, int n, int data_index) RECHEADER **ak, **ai; RECHEADER *akh; RECHEADER **lim = a + n; - const u_char *s, *t; + const unsigned char *s, *t; int s_len, t_len; int i; int r; diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index ee5ffdb..1dd772a 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -60,12 +60,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1993\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ -__RCSID("$NetBSD: sort.c,v 1.64 2017/01/10 21:13:45 christos Exp $"); /* Sort sorts a file using an optional user-defined key. * Sort uses radix sort for internal sorting, and allows @@ -81,23 +75,23 @@ __RCSID("$NetBSD: sort.c,v 1.64 2017/01/10 21:13:45 christos Exp $"); #include #include #include +#include #include #include -#include #include "sort.h" #include "fsort.h" #include "pathnames.h" int REC_D = '\n'; -u_char d_mask[NBINS]; /* flags for rec_d, field_d, */ +unsigned char d_mask[NBINS]; /* flags for rec_d, field_d, */ /* * weight tables. Gweights is one of ascii, Rascii.. * modified to weight rec_d = 0 (or 255) */ -u_char *const weight_tables[4] = { ascii, Rascii, Ftable, RFtable }; -u_char ascii[NBINS], Rascii[NBINS], RFtable[NBINS], Ftable[NBINS]; +unsigned char *const weight_tables[4] = { ascii, Rascii, Ftable, RFtable }; +unsigned char ascii[NBINS], Rascii[NBINS], RFtable[NBINS], Ftable[NBINS]; int SINGL_FLD = 0, SEP_FLAG = 0, UNIQUE = 0; int REVERSE = 0; @@ -111,7 +105,7 @@ const char *tmpdir; /* where temporary files should be put */ static void cleanup(void); static void onsignal(int); -__dead static void usage(const char *); +static void usage(const char *); int main(int argc, char *argv[]) @@ -142,7 +136,7 @@ main(int argc, char *argv[]) /* fldtab[0] is the global options. */ fldtab_sz = 3; fld_cnt = 0; - fldtab = emalloc(fldtab_sz * sizeof(*fldtab)); + fldtab = malloc(fldtab_sz * sizeof(*fldtab)); memset(fldtab, 0, fldtab_sz * sizeof(*fldtab)); #define SORT_OPTS "bcCdD:fHik:lmno:rR:sSt:T:u" @@ -175,7 +169,7 @@ main(int argc, char *argv[]) /* That is now the default. */ break; case 'k': - fldtab = erealloc(fldtab, (fldtab_sz + 1) * sizeof(*fldtab)); + fldtab = realloc(fldtab, (fldtab_sz + 1) * sizeof(*fldtab)); memset(&fldtab[fldtab_sz], 0, sizeof(fldtab[0])); fldtab_sz++; @@ -234,8 +228,8 @@ main(int argc, char *argv[]) d_mask[' '] &= ~FLD_D; d_mask['\t'] &= ~FLD_D; d_mask['\n'] &= ~FLD_D; - d_mask[(u_char)*optarg] |= FLD_D; - if (d_mask[(u_char)*optarg] & REC_D_F) + d_mask[(unsigned char)*optarg] |= FLD_D; + if (d_mask[(unsigned char)*optarg] & REC_D_F) errx(2, "record/field delimiter clash"); break; case 'T': @@ -415,5 +409,5 @@ RECHEADER * allocrec(RECHEADER *rec, size_t size) { - return (erealloc(rec, size + sizeof(long) - 1)); + return (realloc(rec, size + sizeof(long) - 1)); } diff --git a/usr.bin/sort/sort.h b/usr.bin/sort/sort.h index d7a3144..4d87a11 100644 --- a/usr.bin/sort/sort.h +++ b/usr.bin/sort/sort.h @@ -118,7 +118,7 @@ typedef struct recheader { length_t length; /* total length of key and line */ length_t offset; /* to line */ int keylen; /* length of key */ - u_char data[]; /* key then line */ + unsigned char data[]; /* key then line */ } RECHEADER; /* This is the column as seen by struct field. It is used by enterfield. @@ -134,8 +134,8 @@ struct column { * corresponding column in the current line. This is determined in enterkey. */ typedef struct coldesc { - u_char *start; - u_char *end; + unsigned char *start; + unsigned char *end; int num; } COLDESC; @@ -150,21 +150,21 @@ typedef struct coldesc { struct field { struct column icol; struct column tcol; - u_int flags; - u_char *mask; - u_char *weights; + unsigned int flags; + unsigned char *mask; + unsigned char *weights; }; struct filelist { const char * const * names; }; -typedef int (*get_func_t)(FILE *, RECHEADER *, u_char *, struct field *); +typedef int (*get_func_t)(FILE *, RECHEADER *, unsigned char *, struct field *); typedef void (*put_func_t)(const RECHEADER *, FILE *); -extern u_char ascii[NBINS], Rascii[NBINS], Ftable[NBINS], RFtable[NBINS]; -extern u_char *const weight_tables[4]; /* ascii, Rascii, Ftable, RFtable */ -extern u_char d_mask[NBINS]; +extern unsigned char ascii[NBINS], Rascii[NBINS], Ftable[NBINS], RFtable[NBINS]; +extern unsigned char *const weight_tables[4]; /* ascii, Rascii, Ftable, RFtable */ +extern unsigned char d_mask[NBINS]; extern int SINGL_FLD, SEP_FLAG, UNIQUE, REVERSE; extern int posix_sort; extern int REC_D; @@ -178,7 +178,7 @@ extern unsigned int debug_flags; RECHEADER *allocrec(RECHEADER *, size_t); void append(RECHEADER **, int, FILE *, void (*)(const RECHEADER *, FILE *)); void concat(FILE *, FILE *); -length_t enterkey(RECHEADER *, const u_char *, u_char *, size_t, struct field *); +length_t enterkey(RECHEADER *, const unsigned char *, unsigned char *, size_t, struct field *); void fixit(int *, char **, const char *); void fldreset(struct field *); FILE *ftmp(void); @@ -186,16 +186,19 @@ void fmerge(struct filelist *, int, FILE *, struct field *); void save_for_merge(FILE *, get_func_t, struct field *); void merge_sort(FILE *, put_func_t, struct field *); void fsort(struct filelist *, int, FILE *, struct field *); -int geteasy(FILE *, RECHEADER *, u_char *, struct field *); -int makekey(FILE *, RECHEADER *, u_char *, struct field *); -int makeline(FILE *, RECHEADER *, u_char *, struct field *); +int geteasy(FILE *, RECHEADER *, unsigned char *, struct field *); +int makekey(FILE *, RECHEADER *, unsigned char *, struct field *); +int makeline(FILE *, RECHEADER *, unsigned char *, struct field *); void makeline_copydown(RECHEADER *); int optval(int, int); -__dead void order(struct filelist *, struct field *, int); +void order(struct filelist *, struct field *, int); void putline(const RECHEADER *, FILE *); void putrec(const RECHEADER *, FILE *); void putkeydump(const RECHEADER *, FILE *); -void rd_append(int, int, int, FILE *, u_char *, u_char *); +void rd_append(int, int, int, FILE *, unsigned char *, unsigned char *); void radix_sort(RECHEADER **, RECHEADER **, int); int setfield(const char *, struct field *, int); void settables(void); + +#define ALLPERMS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) + diff --git a/usr.bin/sort/tmp.c b/usr.bin/sort/tmp.c index 155b3f5..ca12d55 100644 --- a/usr.bin/sort/tmp.c +++ b/usr.bin/sort/tmp.c @@ -61,10 +61,6 @@ * SUCH DAMAGE. */ -#include - -__RCSID("$NetBSD: tmp.c,v 1.16 2009/11/06 18:34:22 joerg Exp $"); - #include #include -- cgit v1.2.3-70-g09d2