int add_dir(register FILEDESC *);
-char *program_version(void)
+static char *program_version(void)
{
static char buf[BUFSIZ];
(void) sprintf(buf, "%s version %s", PROGRAM_NAME, PROGRAM_VERSION);
return buf;
}
-void usage(void)
+static void usage(void)
{
(void) fprintf(stderr, "%s\n",program_version());
(void) fprintf(stderr, "fortune [-a");
* Set the global values for number of files/children, to be used
* in printing probabilities when listing files
*/
-void calc_equal_probs(void)
+static void calc_equal_probs(void)
{
FILEDESC *fiddlylist;
* print_list:
* Print out the actual list, recursively.
*/
-void print_list(register FILEDESC * list, int lev)
+static void print_list(register FILEDESC * list, int lev)
{
while (list != NULL)
{
* conv_pat:
* Convert the pattern to an ignore-case equivalent.
*/
-char *conv_pat(register char *orig)
+static char *conv_pat(register char *orig)
{
register char *sp;
register unsigned int cnt;
* do_malloc:
* Do a malloc, checking for NULL return.
*/
-void *do_malloc(unsigned int size)
+static void *do_malloc(unsigned int size)
{
void *new;
* do_free:
* Free malloc'ed space, if any.
*/
-void do_free(void *ptr)
+static void do_free(void *ptr)
{
if (ptr != NULL)
free(ptr);
* copy:
* Return a malloc()'ed copy of the string
*/
-char *copy(char *str, unsigned int len)
+static char *copy(char *str, unsigned int len)
{
char *new, *sp;
* new_fp:
* Return a pointer to an initialized new FILEDESC.
*/
-FILEDESC *new_fp(void)
+static FILEDESC *new_fp(void)
{
register FILEDESC *fp;
* is_dir:
* Return TRUE if the file is a directory, FALSE otherwise.
*/
-int is_dir(char *file)
+static int is_dir(char *file)
{
auto struct stat sbuf;
* is_existant:
* Return TRUE if the file exists, FALSE otherwise.
*/
-int is_existant(char *file)
+static int is_existant(char *file)
{
struct stat staat;
* overhead. Files which start with ".", or which have "illegal"
* suffixes, as contained in suflist[], are ruled out.
*/
-int is_fortfile(char *file, char **datp, char **posp)
+static int is_fortfile(char *file, char **datp, char **posp)
{
register int i;
register char *sp;
register char *datfile;
- static char *suflist[] =
+ static const char *suflist[] =
{ /* list of "illegal" suffixes" */
"dat", "pos", "c", "h", "p", "i", "f",
"pas", "ftn", "ins.c", "ins,pas",
* add_file:
* Add a file to the file list.
*/
-int add_file(int percent, register char *file, char *dir,
+static int add_file(int percent, register const char *file, const char *dir,
FILEDESC ** head, FILEDESC ** tail, FILEDESC * parent)
{
register FILEDESC *fp;
if (dir == NULL)
{
- path = file;
- was_malloc = FALSE;
+ path = strdup(file);
+ was_malloc = TRUE;
}
else
{
* form_file_list:
* Form the file list from the file specifications.
*/
-int form_file_list(register char **files, register int file_cnt)
+static int form_file_list(register char **files, register int file_cnt)
{
register int i, percent;
register char *sp;
- char *lang;
char langdir[512];
char fullpathname[512],locpathname[512];
}
}
- lang=getenv("LC_ALL");
+ char * lang=getenv("LC_ALL");
if (!lang) lang=getenv("LC_MESSAGES");
if (!lang) lang=getenv("LANGUAGE");
if (!lang) lang=getenv("LANG");
/*
* This routine evaluates the arguments on the command line
*/
-void getargs(int argc, char **argv)
+static void getargs(int argc, char **argv)
{
register int ignore_case;
register char *pat = NULL;
#endif /* NO_REGEX */
- extern char *optarg;
- extern int optind;
int ch;
ignore_case = FALSE;
* init_prob:
* Initialize the fortune probabilities.
*/
-void init_prob(void)
+static void init_prob(void)
{
register FILEDESC *fp, *last;
register int percent, num_noprob, frac;
* zero_tbl:
* Zero out the fields we care about in a tbl structure.
*/
-void zero_tbl(register STRFILE * tp)
+static void zero_tbl(register STRFILE * tp)
{
tp->str_numstr = 0;
tp->str_longlen = 0;
* sum_tbl:
* Merge the tbl data of t2 into t1.
*/
-void sum_tbl(register STRFILE * t1, register STRFILE * t2)
+static void sum_tbl(register STRFILE * t1, register STRFILE * t2)
{
t1->str_numstr += t2->str_numstr;
if (t1->str_longlen < t2->str_longlen)
* get_tbl:
* Get the tbl data file the datfile.
*/
-void get_tbl(FILEDESC * fp)
+static void get_tbl(FILEDESC * fp)
{
auto int fd;
register FILEDESC *child;
* sum_noprobs:
* Sum up all the noprob probabilities, starting with fp.
*/
-void sum_noprobs(register FILEDESC * fp)
+static void sum_noprobs(register FILEDESC * fp)
{
static bool did_noprobs = FALSE;
* pick_child
* Pick a child from a chosen parent.
*/
-FILEDESC *pick_child(FILEDESC * parent)
+static FILEDESC *pick_child(FILEDESC * parent)
{
register FILEDESC *fp;
register int choice;
* open_dat:
* Open up the dat file if we need to.
*/
-void open_dat(FILEDESC * fp)
+static void open_dat(FILEDESC * fp)
{
if (fp->datfd < 0 && (fp->datfd = open(fp->datfile, O_RDONLY)) < 0)
{
* Get the position from the pos file, if there is one. If not,
* return a random number.
*/
-void get_pos(FILEDESC * fp)
+static void get_pos(FILEDESC * fp)
{
assert(fp->read_tbl);
if (fp->pos == POS_UNKNOWN)
* get_fort:
* Get the fortune data file's seek pointer for the next fortune.
*/
-void get_fort(void)
+static void get_fort(void)
{
register FILEDESC *fp;
register int choice;
* open_fp:
* Assocatiate a FILE * with the given FILEDESC.
*/
-void open_fp(FILEDESC * fp)
+static void open_fp(FILEDESC * fp)
{
if (fp->inf == NULL && (fp->inf = fdopen(fp->fd, "r")) == NULL)
{
* maxlen_in_list
* Return the maximum fortune len in the file list.
*/
-int maxlen_in_list(FILEDESC * list)
+static int maxlen_in_list(FILEDESC * list)
{
register FILEDESC *fp;
register int len, maxlen;
* matches_in_list
* Print out the matches from the files in the list.
*/
-void matches_in_list(FILEDESC * list)
+static void matches_in_list(FILEDESC * list)
{
unsigned char *sp;
unsigned char *p; /* -allover */
* find_matches:
* Find all the fortunes which match the pattern we've been given.
*/
-int find_matches(void)
+static int find_matches(void)
{
Fort_len = maxlen_in_list(File_list);
DPRINTF(2, (stderr, "Maximum length is %d\n", Fort_len));
}
#endif /* NO_REGEX */
-void display(FILEDESC * fp)
+static void display(FILEDESC * fp)
{
register char *p, ch;
unsigned char line[BUFSIZ];
* fortlen:
* Return the length of the fortune.
*/
-int fortlen(void)
+static int fortlen(void)
{
register int nchar;
char line[BUFSIZ];
return nchar;
}
-int max(register int i, register int j)
+static int max(register int i, register int j)
{
return (i >= j ? i : j);
}
int main(int ac, char *av[])
{
- char *ctype, *crequest;
+ const char *ctype;
+ char *crequest;
getargs(ac, av);
outer = recode_new_outer(true);
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <time.h>
#include "strfile.h"
#ifndef MAXPATHLEN
STR *Firstch; /* first chars of each string */
-void usage(void)
+static void usage(void)
{
fprintf(stderr,
"strfile [-iorsx] [-c char] sourcefile [datafile]\n");
/*
* This routine evaluates arguments from the command line
*/
-void getargs(int argc, char **argv)
+static void getargs(int argc, char **argv)
{
- extern char *optarg;
- extern int optind;
int ch;
while ((ch = getopt(argc, argv, "c:iorsx")) != EOF)
* add_offset:
* Add an offset to the list, or write it out, as appropriate.
*/
-void add_offset(FILE * fp, int32_t off)
+static void add_offset(FILE * fp, int32_t off)
{
int32_t net;
* fix_last_offset:
* Used when we have two separators in a row.
*/
-void fix_last_offset(FILE * fp, int32_t off)
+static void fix_last_offset(FILE * fp, int32_t off)
{
int32_t net;
* cmp_str:
* Compare two strings in the file
*/
-int cmp_str(const void *v1, const void *v2)
+static int cmp_str(const void *v1, const void *v2)
{
register int c1, c2;
register int n1, n2;
- register STR *p1, *p2;
+ register const STR *p1, *p2;
#define SET_N(nf,ch) (nf = (ch == '\n'))
#define IS_END(ch,nf) (ch == Delimch && nf)
- p1 = (STR *) v1;
- p2 = (STR *) v2;
+ p1 = (const STR *) v1;
+ p2 = (const STR *) v2;
c1 = p1->first;
c2 = p2->first;
if (c1 != c2)
* do_order:
* Order the strings alphabetically (possibly ignoring case).
*/
-void
+static void
do_order(void)
{
register long i;
Tbl.str_flags |= STR_ORDERED;
}
-char *
+#if 0
+static char *
unctrl(char c)
{
static char buf[3];
}
return buf;
}
+#endif
/*
* randomize:
* not to randomize across delimiter boundaries. All
* randomization is done within each block.
*/
-void randomize(void)
+static void randomize(void)
{
register int cnt, i;
register int32_t tmp;
register int32_t *sp;
- extern time_t time(time_t *);
srandom((int) (time((time_t *) NULL) + getpid()));