From: fcambus Date: Sun, 4 Jun 2017 13:39:25 +0000 (+0000) Subject: Use proper bool types in fortune(6). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=117857630c77e0cd405cd286b1cbde5ef925171d;p=openbsd Use proper bool types in fortune(6). OK tb@, phessler@ (previous version) --- diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c index 41b5b179ebd..73d4def5958 100644 --- a/games/fortune/fortune/fortune.c +++ b/games/fortune/fortune/fortune.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fortune.c,v 1.56 2017/06/02 20:02:39 fcambus Exp $ */ +/* $OpenBSD: fortune.c,v 1.57 2017/06/04 13:39:25 fcambus Exp $ */ /* $NetBSD: fortune.c,v 1.8 1995/03/23 08:28:40 cgd Exp $ */ /*- @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -50,8 +51,6 @@ #include "pathnames.h" #include "strfile.h" -#define bool short - #define MINW 6 /* minimum wait if desired */ #define CPERS 20 /* # of chars for each sec */ #define SLEN 160 /* # of chars in short fortune */ @@ -82,15 +81,15 @@ typedef struct fd { struct fd *next, *prev; } FILEDESC; -bool Found_one; /* did we find a match? */ -bool Find_files = 0; /* just find a list of proper fortune files */ -bool Wait = 0; /* wait desired after fortune */ -bool Short_only = 0; /* short fortune desired */ -bool Long_only = 0; /* long fortune desired */ -bool Offend = 0; /* offensive fortunes only */ -bool All_forts = 0; /* any fortune allowed */ -bool Equal_probs = 0; /* scatter un-allocted prob equally */ -bool Match = 0; /* dump fortunes matching a pattern */ +bool Found_one = false; /* did we find a match? */ +bool Find_files = false; /* display a list of fortune files */ +bool Wait = false; /* wait desired after fortune */ +bool Short_only = false; /* short fortune desired */ +bool Long_only = false; /* long fortune desired */ +bool Offend = false; /* offensive fortunes only */ +bool All_forts = false; /* any fortune allowed */ +bool Equal_probs = false; /* scatter un-allocted prob equally */ +bool Match = false; /* dump fortunes matching a pattern */ #ifdef DEBUG int Debug = 0; /* print debug messages */ #endif @@ -250,35 +249,35 @@ getargs(int argc, char *argv[]) #endif /* DEBUG */ switch(ch) { case 'a': /* any fortune */ - All_forts = 1; + All_forts = true; break; #ifdef DEBUG case 'D': Debug++; break; #endif /* DEBUG */ - case 'e': - Equal_probs = 1; /* scatter un-allocted prob equally */ + case 'e': /* scatter un-allocted prob equally */ + Equal_probs = true; break; case 'f': /* find fortune files */ - Find_files = 1; + Find_files = true; break; case 'l': /* long ones only */ - Long_only = 1; - Short_only = 0; + Long_only = true; + Short_only = false; break; case 'o': /* offensive ones only */ - Offend = 1; + Offend = true; break; case 's': /* short ones only */ - Short_only = 1; - Long_only = 0; + Short_only = true; + Long_only = false; break; case 'w': /* give time to read */ - Wait = 1; + Wait = true; break; case 'm': /* dump out the fortunes */ - Match = 1; + Match = true; pat = optarg; break; case 'i': /* case-insensitive match */ @@ -380,11 +379,11 @@ add_file(int percent, char *file, char *dir, FILEDESC **head, FILEDESC **tail, if (dir == NULL) { path = file; - was_malloc = 0; + was_malloc = false; } else { if (asprintf(&path, "%s/%s", dir, file) == -1) err(1, NULL); - was_malloc = 1; + was_malloc = true; } if ((isdir = is_dir(path)) && parent != NULL) { if (was_malloc) @@ -400,7 +399,7 @@ add_file(int percent, char *file, char *dir, FILEDESC **head, FILEDESC **tail, free(path); path = offensive; file = off_name(file); - was_malloc = 1; + was_malloc = true; } } @@ -420,7 +419,7 @@ over: if (was_malloc) free(path); offensive = NULL; - was_malloc = 1; + was_malloc = true; DPRINTF(1, (stderr, "\ttrying \"%s\"\n", path)); file = off_name(file); goto over; @@ -886,7 +885,7 @@ pick_child(FILEDESC *parent) void sum_noprobs(FILEDESC *fp) { - static bool did_noprobs = 0; + static bool did_noprobs = false; if (did_noprobs) return; @@ -896,7 +895,7 @@ sum_noprobs(FILEDESC *fp) sum_tbl(&Noprob_tbl, &fp->tbl); fp = fp->next; } - did_noprobs = 1; + did_noprobs = true; } int @@ -1099,7 +1098,7 @@ find_matches(void) if ((Fortbuf = malloc(Fort_len + 10)) == NULL) err(1, NULL); - Found_one = 0; + Found_one = false; matches_in_list(File_list); return Found_one; } @@ -1185,7 +1184,7 @@ matches_in_list(FILEDESC *list) fp->tbl.str_delim); if (!in_file) { printf(" (%s)", fp->name); - Found_one = 1; + Found_one = true; in_file = 1; } putchar('\n'); diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c index 9a9e6dce867..76623d0d458 100644 --- a/games/fortune/strfile/strfile.c +++ b/games/fortune/strfile/strfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strfile.c,v 1.28 2016/03/07 12:07:56 mestre Exp $ */ +/* $OpenBSD: strfile.c,v 1.29 2017/06/04 13:39:25 fcambus Exp $ */ /* $NetBSD: strfile.c,v 1.4 1995/04/24 12:23:09 cgd Exp $ */ /*- @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -66,9 +67,6 @@ * Added ordering options. */ -#define TRUE 1 -#define FALSE 0 - #define STORING_PTRS (Oflag || Rflag) #define CHUNKSIZE 512 @@ -92,11 +90,11 @@ char *Infile = NULL, /* input file name */ Outfile[PATH_MAX] = "", /* output file name */ Delimch = '%'; /* delimiting character */ -int Sflag = FALSE; /* silent run flag */ -int Oflag = FALSE; /* ordering flag */ -int Iflag = FALSE; /* ignore case flag */ -int Rflag = FALSE; /* randomize order flag */ -int Xflag = FALSE; /* set rotated bit */ +bool Sflag = false; /* silent run flag */ +bool Oflag = false; /* ordering flag */ +bool Iflag = false; /* ignore case flag */ +bool Rflag = false; /* randomize order flag */ +bool Xflag = false; /* set rotated bit */ long Num_pts = 0; /* number of pointers/strings */ int32_t *Seekpts; @@ -128,11 +126,12 @@ __dead void usage(void); int main(int ac, char *av[]) { + bool first; char *sp, dc; FILE *inf, *outf; int32_t last_off, length, pos; int32_t *p; - int first, cnt; + int cnt; char *nsp; STR *fp; static char string[257]; @@ -189,7 +188,7 @@ main(int ac, char *av[]) else fp->first = *nsp; fp->pos = Seekpts[Num_pts - 1]; - first = FALSE; + first = false; } } while (sp != NULL); @@ -267,19 +266,19 @@ getargs(int argc, char *argv[]) } break; case 'i': /* ignore case in ordering */ - Iflag++; + Iflag = true; break; case 'o': /* order strings */ - Oflag++; + Oflag = true; break; case 'r': /* randomize pointers */ - Rflag++; + Rflag = true; break; case 's': /* silent */ - Sflag++; + Sflag = true; break; case 'x': /* set the rotated bit */ - Xflag++; + Xflag = true; break; case 'h': default: @@ -380,8 +379,8 @@ unctrl(char c) int cmp_str(const void *p1, const void *p2) { + bool n1, n2; int c1, c2; - int n1, n2; # define SET_N(nf,ch) (nf = (ch == '\n')) # define IS_END(ch,nf) (ch == Delimch && nf) @@ -394,8 +393,8 @@ cmp_str(const void *p1, const void *p2) (void) fseek(Sort_1, ((STR *)p1)->pos, SEEK_SET); (void) fseek(Sort_2, ((STR *)p2)->pos, SEEK_SET); - n1 = FALSE; - n2 = FALSE; + n1 = false; + n2 = false; while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0') SET_N(n1, c1); while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0')