]> granicus.if.org Git - fortune-mod/commitdiff
Get rid of some GCC warnings.
authorShlomi Fish <shlomif@shlomifish.org>
Fri, 30 Dec 2016 19:38:14 +0000 (21:38 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Fri, 30 Dec 2016 19:38:14 +0000 (21:38 +0200)
By inspiration and motivation from
https://github.com/shlomif/fortune-mod/issues/7 .

fortune-mod/CMakeLists.txt
fortune-mod/fortune/fortune.c
fortune-mod/util/strfile.c
fortune-mod/util/unstr.c

index 211dda9e30dc83788fc220e066e2f9037cb8c42b..4550d7820b27f95dc92cb362c83f17d2a0cc2982 100644 (file)
@@ -91,6 +91,8 @@ SET (LOCALODIR "${LOCALDIR}/off" CACHE STRING "offensive fortunes localdir")
 SET (COOKIEDIR "${CMAKE_INSTALL_PREFIX}/share/games/fortunes" CACHE STRING  "cookie dir not under /usr/local")
 SET (OCOOKIEDIR "${COOKIEDIR}/off" CACHE STRING "offensive cookie dir not under /usr/local")
 
+SHLOMIF_ADD_COMMON_C_FLAGS()
+
 FIND_PATH( RECODE_H "recode.h")
 
 MACRO(my_exe exe c_file dir)
index c0a34bcc8a481ef6ddce2d4908829b868e838e3c..f2443bd32aca89037cdcb7774f86ecbac2e1a9f0 100644 (file)
@@ -257,14 +257,14 @@ RECODE_OUTER outer;
 
 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");
@@ -291,7 +291,7 @@ void usage(void)
  *      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;
 
@@ -309,7 +309,7 @@ void calc_equal_probs(void)
  * 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)
     {
@@ -341,7 +341,7 @@ void print_list(register FILEDESC * list, int lev)
  * 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;
@@ -387,7 +387,7 @@ char *conv_pat(register char *orig)
  * do_malloc:
  *      Do a malloc, checking for NULL return.
  */
-void *do_malloc(unsigned int size)
+static void *do_malloc(unsigned int size)
 {
     void *new;
 
@@ -403,7 +403,7 @@ void *do_malloc(unsigned int size)
  * do_free:
  *      Free malloc'ed space, if any.
  */
-void do_free(void *ptr)
+static void do_free(void *ptr)
 {
     if (ptr != NULL)
         free(ptr);
@@ -413,7 +413,7 @@ void do_free(void *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;
 
@@ -431,7 +431,7 @@ char *copy(char *str, unsigned int len)
  * new_fp:
  *      Return a pointer to an initialized new FILEDESC.
  */
-FILEDESC *new_fp(void)
+static FILEDESC *new_fp(void)
 {
     register FILEDESC *fp;
 
@@ -464,7 +464,7 @@ FILEDESC *new_fp(void)
  * 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;
 
@@ -477,7 +477,7 @@ int is_dir(char *file)
  * is_existant:
  *      Return TRUE if the file exists, FALSE otherwise.
  */
-int is_existant(char *file)
+static int is_existant(char *file)
 {
     struct stat staat;
 
@@ -501,12 +501,12 @@ int is_existant(char *file)
  *      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",
@@ -556,7 +556,7 @@ int is_fortfile(char *file, char **datp, char **posp)
  * 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;
@@ -570,8 +570,8 @@ int add_file(int percent, register char *file, char *dir,
 
     if (dir == NULL)
     {
-        path = file;
-        was_malloc = FALSE;
+        path = strdup(file);
+        was_malloc = TRUE;
     }
     else
     {
@@ -802,11 +802,10 @@ int add_dir(register FILEDESC * fp)
  * 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];
 
@@ -949,7 +948,7 @@ int form_file_list(register char **files, register int file_cnt)
             }
         }
 
-        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");
@@ -1015,7 +1014,7 @@ int form_file_list(register char **files, register int file_cnt)
 /*
  *    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;
 
@@ -1023,8 +1022,6 @@ void getargs(int argc, char **argv)
     register char *pat = NULL;
 
 #endif /* NO_REGEX */
-    extern char *optarg;
-    extern int optind;
     int ch;
 
     ignore_case = FALSE;
@@ -1123,7 +1120,7 @@ void getargs(int argc, char **argv)
  * 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;
@@ -1206,7 +1203,7 @@ void init_prob(void)
  * 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;
@@ -1217,7 +1214,7 @@ void zero_tbl(register STRFILE * tp)
  * 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)
@@ -1230,7 +1227,7 @@ void sum_tbl(register STRFILE * t1, register STRFILE * t2)
  * 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;
@@ -1327,7 +1324,7 @@ void get_tbl(FILEDESC * fp)
  * 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;
 
@@ -1350,7 +1347,7 @@ void sum_noprobs(register FILEDESC * fp)
  * 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;
@@ -1388,7 +1385,7 @@ FILEDESC *pick_child(FILEDESC * parent)
  * 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)
     {
@@ -1402,7 +1399,7 @@ void open_dat(FILEDESC * fp)
  *      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)
@@ -1418,7 +1415,7 @@ void get_pos(FILEDESC * fp)
  * 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;
@@ -1492,7 +1489,7 @@ void get_fort(void)
  * 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)
     {
@@ -1506,7 +1503,7 @@ void open_fp(FILEDESC * fp)
  * 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;
@@ -1533,7 +1530,7 @@ int maxlen_in_list(FILEDESC * list)
  * 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 */
@@ -1613,7 +1610,7 @@ void matches_in_list(FILEDESC * list)
  * 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));
@@ -1627,7 +1624,7 @@ int find_matches(void)
 }
 #endif /* NO_REGEX */
 
-void display(FILEDESC * fp)
+static void display(FILEDESC * fp)
 {
     register char *p, ch;
     unsigned char line[BUFSIZ];
@@ -1665,7 +1662,7 @@ void display(FILEDESC * fp)
  * fortlen:
  *      Return the length of the fortune.
  */
-int fortlen(void)
+static int fortlen(void)
 {
     register int nchar;
     char line[BUFSIZ];
@@ -1685,14 +1682,15 @@ int fortlen(void)
     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);
index 4b6c20a06568215b41ca4e786660750b075ba8d6..ef7b72e29bc7b8f5fc9c1ef4f337501b7fc6651a 100644 (file)
@@ -79,6 +79,7 @@
 #include        <stdio.h>
 #include        <ctype.h>
 #include        <string.h>
+#include        <time.h>
 #include        "strfile.h"
 
 #ifndef MAXPATHLEN
@@ -158,7 +159,7 @@ STRFILE Tbl;                    /* statistics table */
 
 STR *Firstch;                   /* first chars of each string */
 
-void usage(void)
+static void usage(void)
 {
     fprintf(stderr,
             "strfile [-iorsx] [-c char] sourcefile [datafile]\n");
@@ -168,10 +169,8 @@ void usage(void)
 /*
  *    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)
@@ -228,7 +227,7 @@ void getargs(int argc, char **argv)
  * 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;
 
@@ -249,7 +248,7 @@ void add_offset(FILE * fp, int32_t off)
  * 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;
 
@@ -267,17 +266,17 @@ void fix_last_offset(FILE * fp, int32_t off)
  * 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)
@@ -320,7 +319,7 @@ int cmp_str(const void *v1, const void *v2)
  * do_order:
  *      Order the strings alphabetically (possibly ignoring case).
  */
-void
+static void
   do_order(void)
 {
     register long i;
@@ -343,7 +342,8 @@ void
     Tbl.str_flags |= STR_ORDERED;
 }
 
-char *
+#if 0
+static char *
   unctrl(char c)
 {
     static char buf[3];
@@ -365,6 +365,7 @@ char *
     }
     return buf;
 }
+#endif
 
 /*
  * randomize:
@@ -372,12 +373,11 @@ char *
  *      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()));
 
index 96e0093e930ed1bada6a3344ac73a395c0e9ad38..eac1731fa8ea6523289b51f6ec8e2d46b92f787c 100644 (file)
@@ -112,10 +112,8 @@ char NewDelch = '\0';           /* a replacement delimiter character */
 FILE *Inf, *Dataf, *Outf;
 
 /* ARGSUSED */
-void getargs(int ac, char *av[])
+static void getargs(int ac, char *av[])
 {
-    extern int optind;
-    extern char *optarg;
     char *extc;
     int ch;
 
@@ -171,8 +169,7 @@ void getargs(int ac, char *av[])
     }
 }
 
-void order_unstr(tbl)
-     register STRFILE *tbl;
+static void order_unstr(register STRFILE *tbl)
 {
     register int i;
     register char *sp;