-/* $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 $ */
/*-
#include <err.h>
#include <fcntl.h>
#include <limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 */
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
#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 */
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)
free(path);
path = offensive;
file = off_name(file);
- was_malloc = 1;
+ was_malloc = true;
}
}
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;
void
sum_noprobs(FILEDESC *fp)
{
- static bool did_noprobs = 0;
+ static bool did_noprobs = false;
if (did_noprobs)
return;
sum_tbl(&Noprob_tbl, &fp->tbl);
fp = fp->next;
}
- did_noprobs = 1;
+ did_noprobs = true;
}
int
if ((Fortbuf = malloc(Fort_len + 10)) == NULL)
err(1, NULL);
- Found_one = 0;
+ Found_one = false;
matches_in_list(File_list);
return Found_one;
}
fp->tbl.str_delim);
if (!in_file) {
printf(" (%s)", fp->name);
- Found_one = 1;
+ Found_one = true;
in_file = 1;
}
putchar('\n');
-/* $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 $ */
/*-
#include <ctype.h>
#include <err.h>
#include <limits.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
* Added ordering options.
*/
-#define TRUE 1
-#define FALSE 0
-
#define STORING_PTRS (Oflag || Rflag)
#define CHUNKSIZE 512
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;
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];
else
fp->first = *nsp;
fp->pos = Seekpts[Num_pts - 1];
- first = FALSE;
+ first = false;
}
} while (sp != NULL);
}
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:
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)
(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')