#ifdef DEBUG
#define DPRINTF(l, x) \
if (Debug >= l) \
- fprintf x;
+ { \
+ fprintf x; \
+ }
#else
#define DPRINTF(l, x)
#endif
{
fprintf(stderr, "%*s", lev * 4, "");
if (list->percent == NO_PROB)
+ {
if (!Equal_probs)
+ {
/* This, with some changes elsewhere, gives proper percentages
* for every case fprintf(stderr, "___%%"); */
fprintf(stderr, "%5.2f%%",
(100.0 - Spec_prob) * list->tbl.str_numstr /
Noprob_tbl.str_numstr);
+ }
else if (lev == 0)
+ {
fprintf(stderr, "%5.2f%%", 100.0 / Num_files);
+ }
else
+ {
fprintf(stderr, "%5.2f%%", 100.0 / Num_kids);
+ }
+ }
else
+ {
fprintf(stderr, "%5.2f%%", 1.0 * list->percent);
+ }
fprintf(stderr, " %s", STR(list->name));
DPRINTF(1, (stderr, " (%s, %s, %s)\n", STR(list->path),
STR(list->datfile), STR(list->posfile)));
putc('\n', stderr);
if (list->child)
+ {
print_list(list->child, lev + 1);
+ }
list = list->next;
}
}
{
const size_t prev_cnt = cnt;
if (isalpha(*sp))
+ {
cnt += 4;
+ }
else
- cnt++;
+ {
+ ++cnt;
+ }
if (prev_cnt >= cnt)
{
fprintf(stderr, "%s",
*dest_ptr++ = ']';
}
else
+ {
*dest_ptr++ = *orig;
+ }
}
*dest_ptr = '\0';
return new_buf;
struct stat staat;
if (stat(file, &staat) == 0)
+ {
return true;
+ }
switch (errno)
{
case ENOENT:
DPRINTF(2, (stderr, "is_fortfile(%s) returns ", file));
if (!sp)
+ {
sp = file;
+ }
else
+ {
sp++;
+ }
if (*sp == '.')
{
DPRINTF(2, (stderr, "%s", "false (file starts with '.')\n"));
{
sp++;
for (int i = 0; suflist[i]; ++i)
+ {
if (strcmp(sp, suflist[i]) == 0)
{
DPRINTF(2, (stderr, "false (file has suffix \".%s\")\n", sp));
return false;
}
+ }
}
const size_t do_len = (strlen(file) + 6);
return false;
}
if (datp)
+ {
*datp = datfile;
+ }
else
+ {
free(datfile);
+ }
DPRINTF(2, (stderr, "%s", "true\n"));
return true;
}
*sp = '-';
}
else if (All_forts)
+ {
found =
(CALL__add_file(LOCFORTDIR) || CALL__add_file(LOCOFFDIR) ||
COND_CALL__add_file(LOCFORTDIR, FORTDIR) ||
COND_CALL__add_file(LOCOFFDIR, OFFDIR));
+ }
else if (Offend)
+ {
found = (CALL__add_file(LOCOFFDIR) ||
COND_CALL__add_file(LOCOFFDIR, OFFDIR));
+ }
else
+ {
found = (CALL__add_file(LOCFORTDIR) ||
COND_CALL__add_file(LOCFORTDIR, FORTDIR));
+ }
#undef COND_CALL__add_file
#undef CALL__add_file
}
{
char *p = strchr(lang, ':');
if (p)
+ {
*p++ = '\0';
+ }
snprintf(langdir, sizeof(langdir), "%s/%s", FORTDIR, lang);
if (strncmp(path, lang, 2) == 0)
+ {
ret = 1;
+ }
else if (strncmp(path, langdir, strlen(FORTDIR) + 3) == 0)
+ {
ret = 1;
+ }
lang = p;
}
if (!ret)
snprintf(testpath, do_len, "%s.u8", path);
// fprintf(stderr, "State mal: %s\n", testpath);
if (stat(testpath, &statbuf) == 0)
+ {
fp->utf8_charset = true;
+ }
free(testpath);
testpath = NULL;
if ((isdir && !add_dir(fp)) || (!isdir && !is_fortfile(path, &fp->datfile)))
{
if (!parent)
+ {
fprintf(
stderr, "fortune:%s not a fortune file or directory\n", path);
+ }
free(path);
path = NULL;
free(fp->datfile);
free(fp->name);
free(fp->path);
if (fp->fd >= 0)
+ {
close(fp->fd);
+ }
free(fp);
return false;
}
free(fp->name);
free(fp->path);
if (fp->fd >= 0)
+ {
close(fp->fd);
+ }
free(fp);
return true;
}
/* End hack. */
if (!(*head))
+ {
*head = *tail = fp;
+ }
else if (fp->percent == NO_PROB)
{
(*tail)->next = fp;
while ((dirent = readdir(dir)))
{
if (dirent->d_name[0] == 0)
+ {
continue;
+ }
char *name = strdup(dirent->d_name);
if (count_names == max_count_names)
{
{
p = strchr(lang, ':');
if (p)
+ {
*p++ = '\0';
+ }
/* first try full locale */
ret = add_file(
/* if we have found one we have finished */
if (ret)
+ {
return ret;
+ }
lang = p;
}
/* default */
{
percent = NO_PROB;
if (!isdigit(files[i][0]))
+ {
sp = files[i];
+ }
else
{
const int MAX_PERCENT = 100;
{
char *p = strchr(lang, ':');
if (p)
+ {
*p++ = '\0';
+ }
/* first try full locale */
snprintf(
}
/* default */
if (!ret)
+ {
ret = add_file(
percent, fullpathname, NULL, &File_list, &File_tail, NULL);
+ }
if (!ret &&
strncmp(fullpathname, locpathname, sizeof(fullpathname)))
+ {
ret = add_file(
percent, locpathname, NULL, &File_list, &File_tail, NULL);
-
+ }
if (!ret)
{
snprintf(locpathname, sizeof(locpathname), "%s/%s",
}
else if (!add_file(
percent, fullpathname, NULL, &File_list, &File_tail, NULL))
+ {
return false;
+ }
}
return true;
}
while ((ch = getopt(argc, argv,
"ac" DEBUG_GETOPT "efilm:n:" OFFENSIVE_GETOPT "suvw")) != EOF)
+ {
switch (ch)
{
case 'a': /* any fortune */
case 'i': /* case-insensitive match */
case 'm': /* dump out the fortunes */
(void)fprintf(stderr, "%s",
- "fortune: can't match fortunes on this system (Sorry)\n");
+ "fortune: can't match fortunes on this system "
+ "(Sorry)\n");
exit(0);
#else /* NO_REGEX */
case 'm': /* dump out the fortunes */
default:
usage();
}
+ }
argc -= optind;
argv += optind;
if (pat)
{
if (ignore_case)
+ {
pat = conv_pat(pat);
+ }
if (BAD_COMP(RE_COMP(pat)))
{
fprintf(stderr, "bad pattern: %s\n", pat);
*/
FILEDESC *last = NULL;
for (fp = File_tail; fp; fp = fp->prev)
+ {
if (fp->percent == NO_PROB)
{
num_noprob++;
if (Equal_probs)
+ {
last = fp;
+ }
}
else
+ {
percent += fp->percent;
+ }
+ }
DPRINTF(1, (stderr, "summing probabilities:%d%% with %d NO_PROB's\n",
percent, num_noprob));
if (percent > 100)
else if (percent < 100 && num_noprob == 0)
{
fprintf(stderr,
- "fortune: no place to put residual probability (%d%%)\n", percent);
+ "fortune: no place to put residual probability "
+ "(%d%%)\n",
+ percent);
exit(1);
}
else if (percent == 100 && num_noprob != 0)
{
- fprintf(
- stderr, "fortune: no probability left to put in residual files\n");
+ fprintf(stderr, "fortune: no probability left to put in "
+ "residual files\n");
exit(1);
}
- Spec_prob = percent; /* this is for -f when % is specified on cmd line */
+ Spec_prob = percent; /* this is for -f when % is specified on
+ cmd line */
percent = 100 - percent;
if (Equal_probs)
{
frac = percent / num_noprob;
DPRINTF(1, (stderr, ", frac = %d%%", frac));
for (fp = File_tail; fp != last; fp = fp->prev)
+ {
if (fp->percent == NO_PROB)
{
fp->percent = frac;
percent -= frac;
}
+ }
}
last->percent = percent;
DPRINTF(1, (stderr, ", residual = %d%%", percent));
#ifdef DEBUG
#if 0
if (Debug >= 1)
+ {
print_list(File_list, 0); /* Causes crash with new %% code */
+ }
#endif
#endif
{
t1->str_numstr += t2->str_numstr;
if (t1->str_longlen < t2->str_longlen)
+ {
t1->str_longlen = t2->str_longlen;
+ }
if (t1->str_shortlen > t2->str_shortlen)
+ {
t1->str_shortlen = t2->str_shortlen;
+ }
}
/*
FILEDESC *child;
if (fp->read_tbl)
+ {
return;
+ }
if (!(fp->child))
{
if ((fd = open4read(fp->datfile)) < 0)
static bool did_noprobs = false;
if (did_noprobs)
+ {
return;
+ }
zero_tbl(&Noprob_tbl);
while (fp)
{
get_tbl(fp);
- /* This conditional should help us return correct values for -f
- * when a percentage is specified */
+ /* This conditional should help us return correct values for
+ * -f when a percentage is specified */
if (fp->percent == NO_PROB)
+ {
sum_tbl(&Noprob_tbl, &fp->tbl);
+ }
fp = fp->next;
}
did_noprobs = true;
DPRINTF(1, (stderr, " choice = %d (of %d)\n", choice,
parent->num_children));
for (fp = parent->child; choice--; fp = fp->next)
+ {
continue;
+ }
DPRINTF(1, (stderr, " using %s\n", fp->name));
return fp;
}
/*
* get_pos:
- * Get the position from the pos file, if there is one. If not,
- * return a random number.
+ * Get the position from the pos file, if there is one. If
+ * not, return a random number.
*/
static void get_pos(FILEDESC *fp)
{
fp->pos = (int32_t)(my_random(fp->tbl.str_numstr));
}
if (++(fp->pos) >= (int32_t)fp->tbl.str_numstr)
+ {
fp->pos -= fp->tbl.str_numstr;
+ }
DPRINTF(1, (stderr, "pos for %s is %ld\n", fp->name, fp->pos));
}
/*
* get_fort:
- * Get the fortune data file's seek pointer for the next fortune.
+ * Get the fortune data file's seek pointer for the next
+ * fortune.
*/
static void get_fort(void)
{
int choice;
if (!File_list->next || File_list->percent == NO_PROB)
+ {
fp = File_list;
+ }
else
{
choice = my_random(100);
DPRINTF(1, (stderr, "choice = %d\n", choice));
for (fp = File_list; fp->percent != NO_PROB; fp = fp->next)
+ {
if (choice < fp->percent)
+ {
break;
+ }
else
{
choice -= fp->percent;
DPRINTF(1, (stderr, " skip \"%s\", %d%% (choice = %d)\n",
fp->name, fp->percent, choice));
}
+ }
DPRINTF(1, (stderr, "using \"%s\", %d%% (choice = %d)\n", fp->name,
fp->percent, choice));
}
if (fp->percent != NO_PROB)
+ {
get_tbl(fp);
+ }
else
{
if (fp->next)
if (fp->child)
{
if ((len = maxlen_in_list(fp->child)) > maxlen)
+ {
maxlen = len;
+ }
}
else
{
for (p = (unsigned char *)output; (ch = *p); ++p)
{
if (isupper(ch) && isascii(ch))
+ {
*p = 'A' + (ch - 'A' + 13) % 26;
+ }
else if (islower(ch) && isascii(ch))
+ {
*p = 'a' + (ch - 'a' + 13) % 26;
+ }
}
}
/*
* find_matches:
- * Find all the fortunes which match the pattern we've been given.
+ * Find all the fortunes which match the pattern we've been
+ * given.
*/
static int find_matches(void)
{
open_fp(fp);
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) &&
!STR_ENDSTRING(line, fp->tbl);
Fort_len++)
for (p = (char *)line; (ch = *p); ++p)
{
if (isupper(ch) && isascii(ch))
+ {
*p = 'A' + (ch - 'A' + 13) % 26;
+ }
else if (islower(ch) && isascii(ch))
+ {
*p = 'a' + (ch - 'a' + 13) % 26;
+ }
}
}
if (fp->utf8_charset && (!No_recode))
char line[BUFSIZ];
if (!(Fortfile->tbl.str_flags & (STR_RANDOM | STR_ORDERED)))
+ {
nchar = (Seekpts[1] - Seekpts[0]) - 2; /* for %^J delimiter */
+ }
else
{
open_fp(Fortfile);
nchar = 0;
while (fgets(line, sizeof line, Fortfile->inf) &&
!STR_ENDSTRING(line, Fortfile->tbl))
+ {
nchar += strlen(line);
+ }
}
Fort_len = nchar;
return nchar;
int exit_code = 0;
env_lang = getenv("LC_ALL");
if (!env_lang)
+ {
env_lang = getenv("LC_MESSAGES");
+ }
if (!env_lang)
+ {
env_lang = getenv("LANGUAGE");
+ }
if (!env_lang)
+ {
env_lang = getenv("LANG");
+ }
#ifdef _WIN32
if (!env_lang)
{
{
sum_noprobs(File_list);
if (Equal_probs)
+ {
calc_equal_probs();
+ }
print_list(File_list, 0);
}
else