X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/31f3bac6b88bfb55f83358b8a827924631f828ea..fae54db4d115cb57da03e0b7f5b4fa2abde95da2:/fortune/strfile/strfile.c diff --git a/fortune/strfile/strfile.c b/fortune/strfile/strfile.c index ba35de82..15509370 100644 --- a/fortune/strfile/strfile.c +++ b/fortune/strfile/strfile.c @@ -1,4 +1,4 @@ -/* $NetBSD: strfile.c,v 1.19 2000/01/13 16:22:10 jsm Exp $ */ +/* $NetBSD: strfile.c,v 1.25 2007/12/18 08:45:03 dogcow Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -47,11 +43,13 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ #if 0 static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: strfile.c,v 1.19 2000/01/13 16:22:10 jsm Exp $"); +__RCSID("$NetBSD: strfile.c,v 1.25 2007/12/18 08:45:03 dogcow Exp $"); #endif #endif /* not lint */ #endif /* __NetBSD__ */ +/* n.b.: this file is used at build-time - i.e. during build.sh. */ + # include # include # include @@ -70,8 +68,23 @@ __RCSID("$NetBSD: strfile.c,v 1.19 2000/01/13 16:22:10 jsm Exp $"); # define MAXPATHLEN 1024 # endif /* MAXPATHLEN */ +u_int32_t +h2nl(u_int32_t h) +{ + unsigned char c[4]; + u_int32_t rv; + + c[0] = (h >> 24) & 0xff; + c[1] = (h >> 16) & 0xff; + c[2] = (h >> 8) & 0xff; + c[3] = (h >> 0) & 0xff; + memcpy(&rv, c, sizeof rv); + + return (rv); +} + /* - * This program takes a file composed of strings seperated by + * This program takes a file composed of strings separated by * lines starting with two consecutive delimiting character (default * character is '%') and creates another file which consists of a table * describing the file (structure from "strfile.h"), a table of seek @@ -133,11 +146,15 @@ STRFILE Tbl; /* statistics table */ STR *Firstch; /* first chars of each string */ #ifdef __GNUC__ -#define NORETURN __attribute__((__noreturn__)) +#define NORETURN __dead #else #define NORETURN #endif +#ifndef __dead /* not NetBSD, presumably */ +#define __dead ; +#endif + void add_offset(FILE *, off_t); int cmp_str(const void *, const void *); void die(const char *) NORETURN; @@ -213,12 +230,12 @@ main(ac, av) first = Oflag; } else if (first) { - for (nsp = sp; !isalnum(*nsp); nsp++) + for (nsp = sp; !isalnum((unsigned char)*nsp); nsp++) continue; ALLOC(Firstch, Num_pts); fp = &Firstch[Num_pts - 1]; - if (Iflag && isupper(*nsp)) - fp->first = tolower(*nsp); + if (Iflag && isupper((unsigned char)*nsp)) + fp->first = tolower((unsigned char)*nsp); else fp->first = *nsp; fp->pos = Seekpts[Num_pts - 1]; @@ -253,11 +270,11 @@ main(ac, av) } (void) fseek(outf, (off_t) 0, SEEK_SET); - Tbl.str_version = htonl(Tbl.str_version); - Tbl.str_numstr = htonl(Num_pts - 1); - Tbl.str_longlen = htonl(Tbl.str_longlen); - Tbl.str_shortlen = htonl(Tbl.str_shortlen); - Tbl.str_flags = htonl(Tbl.str_flags); + Tbl.str_version = h2nl(Tbl.str_version); + Tbl.str_numstr = h2nl(Num_pts - 1); + Tbl.str_longlen = h2nl(Tbl.str_longlen); + Tbl.str_shortlen = h2nl(Tbl.str_shortlen); + Tbl.str_flags = h2nl(Tbl.str_flags); (void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf); if (STORING_PTRS) { for (p = Seekpts, cnt = Num_pts; cnt--; ++p)