exit(1);
}
-#define STR(str) ((str) == NULL ? "NULL" : (str))
+#define STR(str) ((!str) ? "NULL" : (str))
/*
* calc_equal_probs:
{
Num_files = Num_kids = 0;
FILEDESC *fiddlylist = File_list;
- while (fiddlylist != NULL)
+ while (fiddlylist)
{
Num_files++;
Num_kids += fiddlylist->num_children;
*/
static void print_list(FILEDESC *list, int lev)
{
- while (list != NULL)
+ while (list)
{
fprintf(stderr, "%*s", lev * 4, "");
if (list->percent == NO_PROB)
DPRINTF(1, (stderr, " (%s, %s, %s)\n", STR(list->path),
STR(list->datfile), STR(list->posfile)));
putc('\n', stderr);
- if (list->child != NULL)
+ if (list->child)
print_list(list->child, lev + 1);
list = list->next;
}
{
char *sp;
unsigned int cnt;
- char *new;
+ char *new_buf;
cnt = 1; /* allow for '\0' */
for (sp = orig; *sp != '\0'; sp++)
cnt += 4;
else
cnt++;
- if ((new = malloc(cnt)) == NULL)
+ if (!(new_buf = malloc(cnt)))
{
fprintf(stderr, "pattern too long for ignoring case\n");
exit(1);
}
- for (sp = new; *orig != '\0'; orig++)
+ for (sp = new_buf; *orig != '\0'; orig++)
{
if (islower(*orig))
{
*sp++ = *orig;
}
*sp = '\0';
- return new;
+ return new_buf;
}
#endif /* NO_REGEX */
DPRINTF(2, (stderr, "false (file starts with '.')\n"));
return false;
}
- if ((sp = strrchr(sp, '.')) != NULL)
+ if ((sp = strrchr(sp, '.')))
{
sp++;
- for (int i = 0; suflist[i] != NULL; i++)
+ for (int i = 0; suflist[i]; ++i)
if (strcmp(sp, suflist[i]) == 0)
{
DPRINTF(2, (stderr, "false (file has suffix \".%s\")\n", sp));
DPRINTF(2, (stderr, "false (no \".dat\" file)\n"));
return false;
}
- if (datp != NULL)
+ if (datp)
*datp = datfile;
else
free(datfile);
char *sp;
struct stat statbuf;
- if (dir == NULL)
+ if (!dir)
{
path = strdup(file);
}
return false;
}
const int isdir = is_dir(path);
- if ((isdir > 0 && parent != NULL) || (isdir < 0))
+ if ((isdir > 0 && parent) || (isdir < 0))
{
free(path);
return false; /* don't recurse */
debugprint("sarahhhhh fd=%d path=<%s> dir=<%s> file=<%s> percent=%d\n",
fd, path, dir, file, percent);
bool found = false;
- if (dir == NULL && (strchr(file, '/') == NULL))
+ if (!dir && (!strchr(file, '/')))
{
if (((sp = strrchr(file, '-')) != NULL) && (strcmp(sp, "-o") == 0))
{
#undef COND_CALL__add_file
#undef CALL__add_file
}
- if (!found && parent == NULL && dir == NULL)
+ if (!found && !parent && !dir)
{ /* don't display an error when trying language specific files */
if (env_lang)
{
if ((isdir && !add_dir(fp)) || (!isdir && !is_fortfile(path, &fp->datfile)))
{
- if (parent == NULL)
+ if (!parent)
fprintf(
stderr, "fortune:%s not a fortune file or directory\n", path);
free(path);
}
/* End hack. */
- if (*head == NULL)
+ if (!(*head))
*head = *tail = fp;
else if (fp->percent == NO_PROB)
{
close(fp->fd);
fp->fd = -1;
- if ((dir = opendir(fp->path)) == NULL)
+ if (!(dir = opendir(fp->path)))
{
debugprint("yonah\n");
perror(fp->path);
perror("Out of RAM!");
exit(-1);
}
- while ((dirent = readdir(dir)) != NULL)
+ while ((dirent = readdir(dir)))
{
if (dirent->d_name[0] == 0)
continue;
#endif /* DEBUG */
/* If (Find_files) print_list() moved to main */
#ifndef NO_REGEX
- if (pat != NULL)
+ if (pat)
{
if (ignore_case)
pat = conv_pat(pat);
* (if any).
*/
FILEDESC *last = NULL;
- for (fp = File_tail; fp != NULL; fp = fp->prev)
+ for (fp = File_tail; fp; fp = fp->prev)
if (fp->percent == NO_PROB)
{
num_noprob++;
if (fp->read_tbl)
return;
- if (fp->child == NULL)
+ if (!(fp->child))
{
if ((fd = open(fp->datfile, O_RDONLY | O_BINARY)) < 0)
{
else
{
zero_tbl(&fp->tbl);
- for (child = fp->child; child != NULL; child = child->next)
+ for (child = fp->child; child; child = child->next)
{
get_tbl(child);
sum_tbl(&fp->tbl, &child->tbl);
if (did_noprobs)
return;
zero_tbl(&Noprob_tbl);
- while (fp != NULL)
+ while (fp)
{
get_tbl(fp);
/* This conditional should help us return correct values for -f
FILEDESC *fp;
int choice;
- if (File_list->next == NULL || File_list->percent == NO_PROB)
+ if (!File_list->next || File_list->percent == NO_PROB)
fp = File_list;
else
{
get_tbl(fp);
else
{
- if (fp->next != NULL)
+ if (fp->next)
{
sum_noprobs(fp);
choice = (int)(my_random(Noprob_tbl.str_numstr));
fprintf(stderr, "fortune: no fortune found\n");
exit(1);
}
- if (fp->child != NULL)
+ if (fp->child)
{
DPRINTF(1, (stderr, "picking child\n"));
fp = pick_child(fp);
*/
static void open_fp(FILEDESC *fp)
{
- if (fp->inf == NULL && (fp->inf = fdopen(fp->fd, "r")) == NULL)
+ if (!fp->inf && !(fp->inf = fdopen(fp->fd, "r")))
{
perror(fp->path);
exit(1);
FILEDESC *fp;
int len, maxlen = 0;
- for (fp = list; fp != NULL; fp = fp->next)
+ for (fp = list; fp; fp = fp->next)
{
- if (fp->child != NULL)
+ if (fp->child)
{
if ((len = maxlen_in_list(fp->child)) > maxlen)
maxlen = len;
int in_file, nchar;
char *output;
- for (fp = list; fp != NULL; fp = fp->next)
+ for (fp = list; fp; fp = fp->next)
{
- if (fp->child != NULL)
+ if (fp->child)
{
matches_in_list(fp->child);
continue;
open_fp(fp);
sp = Fortbuf;
in_file = false;
- while (fgets((char *)sp, Fort_len, fp->inf) != NULL)
+ while (fgets((char *)sp, Fort_len, fp->inf))
{
if (!STR_ENDSTRING(sp, fp->tbl))
{
fseek(fp->inf, (long)Seekpts[0], SEEK_SET);
if (Show_filename)
printf("(%s)\n%%\n", fp->name);
- for (Fort_len = 0; fgets((char *)line, sizeof line, fp->inf) != NULL &&
+ for (Fort_len = 0; fgets((char *)line, sizeof line, fp->inf) &&
!STR_ENDSTRING(line, fp->tbl);
Fort_len++)
{
open_fp(Fortfile);
fseek(Fortfile->inf, (long)Seekpts[0], SEEK_SET);
nchar = 0;
- while (fgets(line, sizeof line, Fortfile->inf) != NULL &&
+ while (fgets(line, sizeof line, Fortfile->inf) &&
!STR_ENDSTRING(line, Fortfile->tbl))
nchar += strlen(line);
}
static void order_unstr(STRFILE *tbl)
{
- uint32_t i;
- char *sp;
int32_t pos;
char buf[BUFSIZ];
int printedsome;
- for (i = 0; i <= tbl->str_numstr; i++)
+ for (uint32_t i = 0; i <= tbl->str_numstr; ++i)
{
if (!fread((char *)&pos, 1, sizeof pos, Dataf))
{
printedsome = 0;
for (;;)
{
- sp = fgets(buf, sizeof buf, Inf);
- if (sp == NULL || STR_ENDSTRING(sp, *tbl))
+ char *const sp = fgets(buf, sizeof buf, Inf);
+ if ((!sp) || STR_ENDSTRING(sp, *tbl))
{
if (sp || printedsome)
fprintf(Outf, "%c\n", delimiter_char);
static STRFILE tbl; /* description table */
getargs(ac, av);
- if ((Inf = fopen(input_filename, "r")) == NULL)
+ if (!(Inf = fopen(input_filename, "r")))
{
perror(input_filename);
exit(1);
}
- if ((Dataf = fopen(data_filename, "r")) == NULL)
+ if (!(Dataf = fopen(data_filename, "r")))
{
perror(data_filename);
exit(1);
}
if (*output_filename == '\0')
Outf = stdout;
- else if ((Outf = fopen(output_filename, "w+")) == NULL)
+ else if (!(Outf = fopen(output_filename, "w+")))
{
perror(output_filename);
exit(1);