Author: eadler
Date: Wed Apr 24 04:21:23 2013
New Revision: 249829
URL: http://svnweb.freebsd.org/changeset/base/249829

Log:
  Merge unmerged commits to fortune(1)

Modified:
  stable/8/games/fortune/datfiles/fortunes
  stable/8/games/fortune/datfiles/freebsd-tips
  stable/8/games/fortune/fortune/Makefile
  stable/8/games/fortune/fortune/fortune.6
  stable/8/games/fortune/fortune/fortune.c
  stable/8/games/fortune/fortune/pathnames.h
  stable/8/games/fortune/strfile/Makefile
  stable/8/games/fortune/strfile/strfile.8
  stable/8/games/fortune/strfile/strfile.c
  stable/8/games/fortune/strfile/strfile.h
  stable/8/games/fortune/unstr/Makefile
  stable/8/games/fortune/unstr/unstr.c
Directory Properties:
  stable/8/games/fortune/   (props changed)

Modified: stable/8/games/fortune/datfiles/fortunes
==============================================================================
--- stable/8/games/fortune/datfiles/fortunes    Wed Apr 24 04:21:19 2013        
(r249828)
+++ stable/8/games/fortune/datfiles/fortunes    Wed Apr 24 04:21:23 2013        
(r249829)
@@ -901,7 +901,7 @@ to add.  This will take at least two wee
        "Even that is too much to expect," insisted the manager, "I will be
 satisfied if you simply tell me when the program is complete."
        The programmer agreed to this.
-       Several years slated, the manager retired.  On the way to his
+       Several years later, the manager retired.  On the way to his
 retirement lunch, he discovered the programmer asleep at his terminal.
 He had been programming all night.
                -- Geoffrey James, "The Tao of Programming"
@@ -1528,6 +1528,13 @@ friends and family, and then justify thi
 for doing it."
                -- Bruce Feirstein, "Nice Guys Sleep Alone"
 %
+       As we know, there are known knowns.  There are things we know we
+know.  We also know there are known unknowns.  That is to say, we know
+there're some things we do not know.  But there're also unknown unknowns;
+the ones we don't know we don't know."
+               -- Defense Secretary Donald Rumsfeld,
+                  about the invasion to Iraq.
+%
        At a recent meeting in Snowmass, Colorado, a participant from
 Los Angeles fainted from hyperoxygenation, and we had to hold his head
 under the exhaust of a bus until he revived.
@@ -7947,7 +7954,7 @@ the same mistake twice without getting n
 A well-known friend is a treasure.
 %
 A well-used door needs no oil on its hinges.
-A swift-flowing steam does no grow stagnant.
+A swift-flowing stream does not grow stagnant.
 Neither sound nor thoughts can travel through a vacuum.
 Software rots if not used.
 
@@ -32844,6 +32851,12 @@ Mistakeholder, n.:
 %
 Mistakes are often the stepping stones to utter failure.
 %
+Mistakeholder, n.:
+       A person who depends on accidental features or 
+       implementation errors and so now has a vested 
+       interest in keeping things from being fixed.
+               -- Chip Morningstar
+%
 Mistrust first impulses; they are always right.
 %
 MIT:
@@ -45636,6 +45649,13 @@ constitutions, displaying the utmost imp
 overturning everything.
                -- Plato, "Republic", 370 B.C.
 %
+The investment community feels very putupon.  They feel there is no
+reason why they shouldn't earn $1 million to $200 million a year,
+and they don't want to be held responsible for the global financial
+meltdown.
+               -- Daniel Fass, chairman of Obama's
+               financial-industry fundraising party
+%
 The IQ of the group is the lowest IQ of a member of
 the group divided by the number of people in the group.
 %
@@ -59051,3 +59071,19 @@ since I first call'd my brother's father
 Zymurgy's Law of Volunteer Labor:
        People are always available for work in the past tense.
 %
+This email and any files transmitted with it are confidential and
+intended solely for the use of the individual or entity to which they
+are addressed. If you are not the intended recipient of this
+transmission, please delete it immediately.
+
+Obviously, I am the idiot who sent it to you by mistake. Furthermore,
+there is no way I can force you to delete it. Worse, by the time you
+have reached this disclaimer you have already read the document.
+Telling you to forget it would seem absurd. In any event, I have no
+legal right to force you to take any action upon this email anyway.
+
+This entire disclaimer is just a waste of everyone's time and
+bandwidth. Therefore, let us just forget the whole thing and enjoy a
+cold beer instead.
+               -- found on the dovecot mailinglist
+%

Modified: stable/8/games/fortune/datfiles/freebsd-tips
==============================================================================
--- stable/8/games/fortune/datfiles/freebsd-tips        Wed Apr 24 04:21:19 
2013        (r249828)
+++ stable/8/games/fortune/datfiles/freebsd-tips        Wed Apr 24 04:21:23 
2013        (r249829)
@@ -373,16 +373,6 @@ modes.
 %
 You can disable tcsh's terminal beep if you `set nobeep'.
 %
-You can get a good generic server install by using the
-instant-server port/package.  If you have ports installed, you can
-install it by doing
-
-       # cd /usr/ports/misc/instant-server
-       # make install && make clean
-
-as root.  This will install a collection of packages that is appropriate for
-running a "generic" server.
-%
 You can install extra packages for FreeBSD by using the ports system.
 If you have installed it, you can download, compile, and install software by
 just typing

Modified: stable/8/games/fortune/fortune/Makefile
==============================================================================
--- stable/8/games/fortune/fortune/Makefile     Wed Apr 24 04:21:19 2013        
(r249828)
+++ stable/8/games/fortune/fortune/Makefile     Wed Apr 24 04:21:23 2013        
(r249829)
@@ -3,7 +3,6 @@
 
 PROG=  fortune
 MAN=   fortune.6
-WARNS?=        2
 CFLAGS+=-DDEBUG -I${.CURDIR}/../strfile
 
 .include <bsd.prog.mk>

Modified: stable/8/games/fortune/fortune/fortune.6
==============================================================================
--- stable/8/games/fortune/fortune/fortune.6    Wed Apr 24 04:21:19 2013        
(r249828)
+++ stable/8/games/fortune/fortune/fortune.6    Wed Apr 24 04:21:23 2013        
(r249829)
@@ -12,11 +12,7 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\"    must display the following acknowledgement:
-.\"    This product includes software developed by the University of
-.\"    California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
 .\"
@@ -174,6 +170,9 @@ looks for data files.
 If not set it will default to
 .Pa /usr/games/fortune .
 If none of the directories specified exist, it will print a warning and exit.
+.It Ev FORTUNE_SAVESTATE
+If set, fortune will save some state about what fortune
+it was up to on disk.
 .El
 .Sh FILES
 .Bl -tag -width ".Pa /usr/share/games/fortune/*"

Modified: stable/8/games/fortune/fortune/fortune.c
==============================================================================
--- stable/8/games/fortune/fortune/fortune.c    Wed Apr 24 04:21:19 2013        
(r249828)
+++ stable/8/games/fortune/fortune/fortune.c    Wed Apr 24 04:21:23 2013        
(r249829)
@@ -13,11 +13,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -48,49 +44,50 @@ static const char sccsid[] = "@(#)fortun
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-# include      <sys/stat.h>
-# include      <sys/endian.h>
+#include <sys/stat.h>
+#include <sys/endian.h>
 
-# include      <dirent.h>
-# include      <fcntl.h>
-# include      <assert.h>
-# include      <unistd.h>
-# include      <stdio.h>
-# include      <ctype.h>
-# include      <stdlib.h>
-# include      <string.h>
-# include       <locale.h>
-# include       <time.h>
-# include       <regex.h>
-# include      "strfile.h"
-# include      "pathnames.h"
-
-# define       TRUE    1
-# define       FALSE   0
-# 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 */
-
-# define        POS_UNKNOWN     ((uint32_t) -1)        /* pos for file unknown 
*/
-# define       NO_PROB         (-1)            /* no prob specified for file */
-
-# ifdef DEBUG
-# define        DPRINTF(l,x)    { if (Debug >= l) fprintf x; }
-# undef                NDEBUG
-# else
-# define       DPRINTF(l,x)
-# define       NDEBUG  1
-# endif
+#include <assert.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <locale.h>
+#include <regex.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "strfile.h"
+#include "pathnames.h"
+
+#define        TRUE    true
+#define        FALSE   false
+
+#define        MINW    6               /* minimum wait if desired */
+#define        CPERS   20              /* # of chars for each sec */
+#define        SLEN    160             /* # of chars in short fortune */
+
+#define        POS_UNKNOWN     ((uint32_t) -1) /* pos for file unknown */
+#define        NO_PROB         (-1)            /* no prob specified for file */
+
+#ifdef DEBUG
+#define        DPRINTF(l,x)    { if (Debug >= l) fprintf x; }
+#undef NDEBUG
+#else
+#define        DPRINTF(l,x)
+#define        NDEBUG  1
+#endif
 
 typedef struct fd {
        int             percent;
        int             fd, datfd;
        uint32_t        pos;
        FILE            *inf;
-       char            *name;
-       char            *path;
+       const char      *name;
+       const char      *path;
        char            *datfile, *posfile;
        bool            read_tbl;
        bool            was_pos_file;
@@ -100,89 +97,87 @@ typedef struct fd {
        struct fd       *next, *prev;
 } FILEDESC;
 
-bool   Found_one;                      /* did we find a match? */
-bool   Find_files      = FALSE;        /* just find a list of proper fortune 
files */
-bool    Fortunes_only   = FALSE;        /* check only "fortunes" 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 */
+static bool    Found_one;              /* did we find a match? */
+static bool    Find_files = FALSE;     /* just find a list of proper fortune 
files */
+static bool    Fortunes_only = FALSE;  /* check only "fortunes" files */
+static bool    Wait = FALSE;           /* wait desired after fortune */
+static bool    Short_only = FALSE;     /* short fortune desired */
+static bool    Long_only = FALSE;      /* long fortune desired */
+static bool    Offend = FALSE;         /* offensive fortunes only */
+static bool    All_forts = FALSE;      /* any fortune allowed */
+static bool    Equal_probs = FALSE;    /* scatter un-allocted prob equally */
+static bool    Match = FALSE;          /* dump fortunes matching a pattern */
+static bool    WriteToDisk = false;    /* use files on disk to save state */
 #ifdef DEBUG
-bool   Debug = FALSE;                  /* print debug messages */
+static int     Debug = 0;              /* print debug messages */
 #endif
 
-char   *Fortbuf = NULL;                        /* fortune buffer for -m */
+static char    *Fortbuf = NULL;        /* fortune buffer for -m */
 
-int    Fort_len = 0;
+static int     Fort_len = 0;
 
-off_t  Seekpts[2];                     /* seek pointers to fortunes */
+static off_t   Seekpts[2];             /* seek pointers to fortunes */
 
-FILEDESC       *File_list = NULL,      /* Head of file list */
+static FILEDESC        *File_list = NULL,      /* Head of file list */
                *File_tail = NULL;      /* Tail of file list */
-FILEDESC       *Fortfile;              /* Fortune file to use */
+static FILEDESC        *Fortfile;              /* Fortune file to use */
 
-STRFILE                Noprob_tbl;             /* sum of data for all no prob 
files */
+static STRFILE Noprob_tbl;             /* sum of data for all no prob files */
 
-char   *Fortune_path;
-char   **Fortune_path_arr;
+static const char *Fortune_path;
+static char    **Fortune_path_arr;
 
-int     add_dir(FILEDESC *);
-int     add_file __P((int,
-           char *, char *, FILEDESC **, FILEDESC **, FILEDESC *));
-void    all_forts(FILEDESC *, char *);
-char   *copy(char *, u_int);
-void    display(FILEDESC *);
-void    do_free(void *);
-void   *do_malloc(u_int);
-int     form_file_list(char **, int);
-int     fortlen(void);
-void    get_fort(void);
-void    get_pos(FILEDESC *);
-void    get_tbl(FILEDESC *);
-void    getargs(int, char *[]);
-void    getpath(void);
-void    init_prob(void);
-int     is_dir(char *);
-int     is_fortfile(char *, char **, char **, int);
-int     is_off_name(char *);
-int     max(int, int);
-FILEDESC *
-        new_fp(void);
-char   *off_name(char *);
-void    open_dat(FILEDESC *);
-void    open_fp(FILEDESC *);
-FILEDESC *
-        pick_child(FILEDESC *);
-void    print_file_list(void);
-void    print_list(FILEDESC *, int);
-void    sum_noprobs(FILEDESC *);
-void    sum_tbl(STRFILE *, STRFILE *);
-void    usage(void);
-void    zero_tbl(STRFILE *);
-
-char   *conv_pat(char *);
-int     find_matches(void);
-void    matches_in_list(FILEDESC *);
-int     maxlen_in_list(FILEDESC *);
+static int      add_dir(FILEDESC *);
+static int      add_file(int, const char *, const char *, FILEDESC **,
+                    FILEDESC **, FILEDESC *);
+static void     all_forts(FILEDESC *, char *);
+static char    *copy(const char *, u_int);
+static void     display(FILEDESC *);
+static void     do_free(void *);
+static void    *do_malloc(u_int);
+static int      form_file_list(char **, int);
+static int      fortlen(void);
+static void     get_fort(void);
+static void     get_pos(FILEDESC *);
+static void     get_tbl(FILEDESC *);
+static void     getargs(int, char *[]);
+static void     getpath(void);
+static void     init_prob(void);
+static int      is_dir(const char *);
+static int      is_fortfile(const char *, char **, char **, int);
+static int      is_off_name(const char *);
+static int      max(int, int);
+static FILEDESC *new_fp(void);
+static char    *off_name(const char *);
+static void     open_dat(FILEDESC *);
+static void     open_fp(FILEDESC *);
+static FILEDESC *pick_child(FILEDESC *);
+static void     print_file_list(void);
+static void     print_list(FILEDESC *, int);
+static void     sum_noprobs(FILEDESC *);
+static void     sum_tbl(STRFILE *, STRFILE *);
+static void     usage(void);
+static void     zero_tbl(STRFILE *);
+
+static char    *conv_pat(char *);
+static int      find_matches(void);
+static void     matches_in_list(FILEDESC *);
+static int      maxlen_in_list(FILEDESC *);
 
 static regex_t Re_pat;
 
 int
-main(ac, av)
-int    ac;
-char   *av[];
+main(int argc, char *argv[])
 {
-#ifdef OK_TO_WRITE_DISK
        int     fd;
-#endif /* OK_TO_WRITE_DISK */
+
+       if (getenv("FORTUNE_SAVESTATE") != NULL)
+               WriteToDisk = true;
 
        (void) setlocale(LC_ALL, "");
 
        getpath();
-       getargs(ac, av);
+       getargs(argc, argv);
 
        if (Match)
                exit(find_matches() != 0);
@@ -195,45 +190,40 @@ char      *av[];
 
        display(Fortfile);
 
-#ifdef OK_TO_WRITE_DISK
-       if ((fd = creat(Fortfile->posfile, 0666)) < 0) {
-               perror(Fortfile->posfile);
-               exit(1);
+       if (WriteToDisk) {
+               if ((fd = creat(Fortfile->posfile, 0666)) < 0) {
+                       perror(Fortfile->posfile);
+                       exit(1);
+               }
+               /*
+                * if we can, we exclusive lock, but since it isn't very
+                * important, we just punt if we don't have easy locking
+                * available.
+                */
+               flock(fd, LOCK_EX);
+               write(fd, (char *) &Fortfile->pos, sizeof Fortfile->pos);
+               if (!Fortfile->was_pos_file)
+               chmod(Fortfile->path, 0666);
+               flock(fd, LOCK_UN);
        }
-#ifdef LOCK_EX
-       /*
-        * if we can, we exclusive lock, but since it isn't very
-        * important, we just punt if we don't have easy locking
-        * available.
-        */
-       (void) flock(fd, LOCK_EX);
-#endif /* LOCK_EX */
-       write(fd, (char *) &Fortfile->pos, sizeof Fortfile->pos);
-       if (!Fortfile->was_pos_file)
-               (void) chmod(Fortfile->path, 0666);
-#ifdef LOCK_EX
-       (void) flock(fd, LOCK_UN);
-#endif /* LOCK_EX */
-#endif /* OK_TO_WRITE_DISK */
        if (Wait) {
                if (Fort_len == 0)
                        (void) fortlen();
                sleep((unsigned int) max(Fort_len / CPERS, MINW));
        }
+
        exit(0);
-       /* NOTREACHED */
 }
 
-void
-display(fp)
-FILEDESC       *fp;
+static void
+display(FILEDESC *fp)
 {
        char   *p;
        unsigned char ch;
        char    line[BUFSIZ];
 
        open_fp(fp);
-       (void) fseeko(fp->inf, Seekpts[0], 0);
+       fseeko(fp->inf, Seekpts[0], SEEK_SET);
        for (Fort_len = 0; fgets(line, sizeof line, fp->inf) != NULL &&
            !STR_ENDSTRING(line, fp->tbl); Fort_len++) {
                if (fp->tbl.str_flags & STR_ROTATED)
@@ -258,8 +248,8 @@ FILEDESC    *fp;
  * fortlen:
  *     Return the length of the fortune.
  */
-int
-fortlen()
+static int
+fortlen(void)
 {
        int     nchar;
        char    line[BUFSIZ];
@@ -268,34 +258,31 @@ fortlen()
                nchar = (int)(Seekpts[1] - Seekpts[0]);
        else {
                open_fp(Fortfile);
-               (void) fseeko(Fortfile->inf, Seekpts[0], 0);
+               fseeko(Fortfile->inf, Seekpts[0], SEEK_SET);
                nchar = 0;
                while (fgets(line, sizeof line, Fortfile->inf) != NULL &&
                       !STR_ENDSTRING(line, Fortfile->tbl))
                        nchar += strlen(line);
        }
        Fort_len = nchar;
-       return nchar;
+
+       return (nchar);
 }
 
 /*
  *     This routine evaluates the arguments on the command line
  */
-void
-getargs(argc, argv)
-int    argc;
-char   **argv;
+static void
+getargs(int argc, char *argv[])
 {
        int     ignore_case;
        char    *pat;
-       extern char *optarg;
-       extern int optind;
        int ch;
 
        ignore_case = FALSE;
        pat = NULL;
 
-# ifdef DEBUG
+#ifdef DEBUG
        while ((ch = getopt(argc, argv, "aDefilm:osw")) != -1)
 #else
        while ((ch = getopt(argc, argv, "aefilm:osw")) != -1)
@@ -304,11 +291,11 @@ char      **argv;
                case 'a':               /* any fortune */
                        All_forts++;
                        break;
-# ifdef DEBUG
+#ifdef DEBUG
                case 'D':
                        Debug++;
                        break;
-# endif /* DEBUG */
+#endif /* DEBUG */
                case 'e':
                        Equal_probs++;  /* scatter un-allocted prob equally */
                        break;
@@ -362,7 +349,7 @@ char        **argv;
                error = regcomp(&Re_pat, pat, REG_BASIC);
                if (error) {
                        fprintf(stderr, "regcomp(%s) fails\n", pat);
-                       exit (1);
+                       exit(1);
                }
        }
 }
@@ -371,10 +358,8 @@ char       **argv;
  * form_file_list:
  *     Form the file list from the file specifications.
  */
-int
-form_file_list(files, file_cnt)
-char   **files;
-int    file_cnt;
+static int
+form_file_list(char **files, int file_cnt)
 {
        int     i, percent;
        char    *sp;
@@ -386,7 +371,7 @@ int file_cnt;
                        pstr = Fortune_path_arr;
                        i = 0;
                        while (*pstr) {
-                               i += add_file(NO_PROB, *pstr++, NULL, 
+                               i += add_file(NO_PROB, *pstr++, NULL,
                                              &File_list, &File_tail, NULL);
                        }
                        Fortunes_only = FALSE;
@@ -394,7 +379,7 @@ int file_cnt;
                                fprintf(stderr, "No fortunes found in %s.\n",
                                    Fortune_path);
                        }
-                       return i != 0;
+                       return (i != 0);
                } else {
                        pstr = Fortune_path_arr;
                        i = 0;
@@ -406,7 +391,7 @@ int file_cnt;
                                fprintf(stderr, "No fortunes found in %s.\n",
                                    Fortune_path);
                        }
-                       return i != 0;
+                       return (i != 0);
                }
        }
        for (i = 0; i < file_cnt; i++) {
@@ -419,11 +404,11 @@ int       file_cnt;
                                percent = percent * 10 + *sp - '0';
                        if (percent > 100) {
                                fprintf(stderr, "percentages must be <= 100\n");
-                               return FALSE;
+                               return (FALSE);
                        }
                        if (*sp == '.') {
                                fprintf(stderr, "percentages must be 
integers\n");
-                               return FALSE;
+                               return (FALSE);
                        }
                        /*
                         * If the number isn't followed by a '%', then
@@ -437,7 +422,7 @@ int file_cnt;
                        else if (*++sp == '\0') {
                                if (++i >= file_cnt) {
                                        fprintf(stderr, "percentages must 
precede files\n");
-                                       return FALSE;
+                                       return (FALSE);
                                }
                                sp = files[i];
                        }
@@ -446,53 +431,53 @@ int       file_cnt;
                        pstr = Fortune_path_arr;
                        i = 0;
                        while (*pstr) {
-                               i += add_file(NO_PROB, *pstr++, NULL, 
+                               i += add_file(NO_PROB, *pstr++, NULL,
                                              &File_list, &File_tail, NULL);
                        }
                        if (!i) {
                                fprintf(stderr, "No fortunes found in %s.\n",
                                    Fortune_path);
-                               return FALSE;
+                               return (FALSE);
                        }
-               } else if (!add_file(percent, sp, NULL, &File_list, 
+               } else if (!add_file(percent, sp, NULL, &File_list,
                                     &File_tail, NULL)) {
-                       return FALSE;
+                       return (FALSE);
                }
        }
-       return TRUE;
+
+       return (TRUE);
 }
 
 /*
  * add_file:
  *     Add a file to the file list.
  */
-int
-add_file(percent, file, dir, head, tail, parent)
-int            percent;
-char           *file;
-char           *dir;
-FILEDESC       **head, **tail;
-FILEDESC       *parent;
+static int
+add_file(int percent, const char *file, const char *dir, FILEDESC **head,
+    FILEDESC **tail, FILEDESC *parent)
 {
        FILEDESC        *fp;
        int             fd;
-       char            *path, *offensive;
+       const char      *path;
+       char            *tpath, *offensive;
        bool            was_malloc;
        bool            isdir;
 
        if (dir == NULL) {
                path = file;
+               tpath = NULL;
                was_malloc = FALSE;
        }
        else {
-               path = do_malloc((unsigned int) (strlen(dir) + strlen(file) + 
2));
-               (void) strcat(strcat(strcpy(path, dir), "/"), file);
+               tpath = do_malloc((unsigned int)(strlen(dir) + strlen(file) + 
2));
+               strcat(strcat(strcpy(tpath, dir), "/"), file);
+               path = tpath;
                was_malloc = TRUE;
        }
        if ((isdir = is_dir(path)) && parent != NULL) {
                if (was_malloc)
-                       free(path);
-               return FALSE;   /* don't recurse */
+                       free(tpath);
+               return (FALSE); /* don't recurse */
        }
        offensive = NULL;
        if (!isdir && parent == NULL && (All_forts || Offend) &&
@@ -500,7 +485,7 @@ FILEDESC    *parent;
                offensive = off_name(path);
                if (Offend) {
                        if (was_malloc)
-                               free(path);
+                               free(tpath);
                        path = offensive;
                        offensive = NULL;
                        was_malloc = TRUE;
@@ -511,7 +496,7 @@ FILEDESC    *parent;
 
        DPRINTF(1, (stderr, "adding file \"%s\"\n", path));
 over:
-       if ((fd = open(path, 0)) < 0) {
+       if ((fd = open(path, O_RDONLY)) < 0) {
                /*
                 * This is a sneak.  If the user said -a, and if the
                 * file we're given isn't a file, we check to see if
@@ -522,7 +507,7 @@ over:
                 */
                if (All_forts && offensive != NULL) {
                        if (was_malloc)
-                               free(path);
+                               free(tpath);
                        path = offensive;
                        offensive = NULL;
                        was_malloc = TRUE;
@@ -535,22 +520,22 @@ over:
                        char **pstr = Fortune_path_arr;
 
                        while (*pstr) {
-                               i += add_file(percent, file, *pstr++, 
+                               i += add_file(percent, file, *pstr++,
                                              head, tail, parent);
                        }
                        if (!i) {
                                fprintf(stderr, "No '%s' found in %s.\n",
                                    file, Fortune_path);
                        }
-                       return i != 0;
+                       return (i != 0);
                }
                /*
                if (parent == NULL)
                        perror(path);
                */
                if (was_malloc)
-                       free(path);
-               return FALSE;
+                       free(tpath);
+               return (FALSE);
        }
 
        DPRINTF(2, (stderr, "path = \"%s\"\n", path));
@@ -571,12 +556,12 @@ over:
                                "fortune:%s not a fortune file or directory\n",
                                path);
                if (was_malloc)
-                       free(path);
+                       free(tpath);
                do_free(fp->datfile);
                do_free(fp->posfile);
-               free((char *) fp);
+               free(fp);
                do_free(offensive);
-               return FALSE;
+               return (FALSE);
        }
        /*
         * If the user said -a, we need to make this node a pointer to
@@ -598,23 +583,22 @@ over:
                fp->next = *head;
                *head = fp;
        }
-#ifdef OK_TO_WRITE_DISK
-       fp->was_pos_file = (access(fp->posfile, W_OK) >= 0);
-#endif /* OK_TO_WRITE_DISK */
+       if (WriteToDisk)
+               fp->was_pos_file = (access(fp->posfile, W_OK) >= 0);
 
-       return TRUE;
+       return (TRUE);
 }
 
 /*
  * new_fp:
  *     Return a pointer to an initialized new FILEDESC.
  */
-FILEDESC *
-new_fp()
+static FILEDESC *
+new_fp(void)
 {
        FILEDESC        *fp;
 
-       fp = (FILEDESC *) do_malloc(sizeof *fp);
+       fp = do_malloc(sizeof(*fp));
        fp->datfd = -1;
        fp->pos = POS_UNKNOWN;
        fp->inf = NULL;
@@ -627,34 +611,35 @@ new_fp()
        fp->parent = NULL;
        fp->datfile = NULL;
        fp->posfile = NULL;
-       return fp;
+
+       return (fp);
 }
 
 /*
  * off_name:
  *     Return a pointer to the offensive version of a file of this name.
  */
-char *
-off_name(file)
-char   *file;
+static char *
+off_name(const char *file)
 {
        char    *new;
 
        new = copy(file, (unsigned int) (strlen(file) + 2));
-       return strcat(new, "-o");
+
+       return (strcat(new, "-o"));
 }
 
 /*
  * is_off_name:
  *     Is the file an offensive-style name?
  */
-int
-is_off_name(file)
-char   *file;
+static int
+is_off_name(const char *file)
 {
        int     len;
 
        len = strlen(file);
+
        return (len >= 3 && file[len - 2] == '-' && file[len - 1] == 'o');
 }
 
@@ -663,21 +648,19 @@ char      *file;
  *     Modify a FILEDESC element to be the parent of two children if
  *     there are two children to be a parent of.
  */
-void
-all_forts(fp, offensive)
-FILEDESC       *fp;
-char           *offensive;
+static void
+all_forts(FILEDESC *fp, char *offensive)
 {
        char            *sp;
        FILEDESC        *scene, *obscene;
        int             fd;
-       auto char               *datfile, *posfile;
+       char            *datfile, *posfile;
 
        if (fp->child != NULL)  /* this is a directory, not a file */
                return;
        if (!is_fortfile(offensive, &datfile, &posfile, FALSE))
                return;
-       if ((fd = open(offensive, 0)) < 0)
+       if ((fd = open(offensive, O_RDONLY)) < 0)
                return;
        DPRINTF(1, (stderr, "adding \"%s\" because of -a\n", offensive));
        scene = new_fp();
@@ -697,36 +680,34 @@ char              *offensive;
        obscene->fd = fd;
        obscene->inf = NULL;
        obscene->path = offensive;
-       if ((sp = rindex(offensive, '/')) == NULL)
+       if ((sp = strrchr(offensive, '/')) == NULL)
                obscene->name = offensive;
        else
                obscene->name = ++sp;
        obscene->datfile = datfile;
        obscene->posfile = posfile;
-       obscene->read_tbl = FALSE;
-#ifdef OK_TO_WRITE_DISK
-       obscene->was_pos_file = (access(obscene->posfile, W_OK) >= 0);
-#endif /* OK_TO_WRITE_DISK */
+       obscene->read_tbl = false;
+       if (WriteToDisk)
+               obscene->was_pos_file = (access(obscene->posfile, W_OK) >= 0);
 }
 
 /*
  * add_dir:
  *     Add the contents of an entire directory.
  */
-int
-add_dir(fp)
-FILEDESC       *fp;
+static int
+add_dir(FILEDESC *fp)
 {
        DIR             *dir;
        struct dirent   *dirent;
-       auto FILEDESC   *tailp;
-       auto char       *name;
+       FILEDESC        *tailp;
+       char            *name;
 
        (void) close(fp->fd);
        fp->fd = -1;
        if ((dir = opendir(fp->path)) == NULL) {
                perror(fp->path);
-               return FALSE;
+               return (FALSE);
        }
        tailp = NULL;
        DPRINTF(1, (stderr, "adding dir \"%s\"\n", fp->path));
@@ -743,23 +724,24 @@ FILEDESC  *fp;
        if (fp->num_children == 0) {
                (void) fprintf(stderr,
                    "fortune: %s: No fortune files in directory.\n", fp->path);
-               return FALSE;
+               return (FALSE);
        }
-       return TRUE;
+
+       return (TRUE);
 }
 
 /*
  * is_dir:
  *     Return TRUE if the file is a directory, FALSE otherwise.
  */
-int
-is_dir(file)
-char   *file;
+static int
+is_dir(const char *file)
 {
-       auto struct stat        sbuf;
+       struct stat     sbuf;
 
        if (stat(file, &sbuf) < 0)
-               return FALSE;
+               return (FALSE);
+
        return (sbuf.st_mode & S_IFDIR);
 }
 
@@ -771,20 +753,19 @@ char      *file;
  *     suffixes, as contained in suflist[], are ruled out.
  */
 /* ARGSUSED */
-int
-is_fortfile(file, datp, posp, check_for_offend)
-char   *file, **datp, **posp;
-int    check_for_offend;
+static int
+is_fortfile(const char *file, char **datp, char **posp, int check_for_offend)
 {
        int     i;
-       char    *sp;
+       const char      *sp;
        char    *datfile;
-       static char     *suflist[] = {  /* list of "illegal" suffixes" */
-                               "dat", "pos", "c", "h", "p", "i", "f",
-                               "pas", "ftn", "ins.c", "ins,pas",
-                               "ins.ftn", "sml",
-                               NULL
-                       };
+       static const char *suflist[] = {
+               /* list of "illegal" suffixes" */
+               "dat", "pos", "c", "h", "p", "i", "f",
+               "pas", "ftn", "ins.c", "ins,pas",
+               "ins.ftn", "sml",
+               NULL
+       };
 
        DPRINTF(2, (stderr, "is_fortfile(%s) returns ", file));
 
@@ -796,28 +777,28 @@ int       check_for_offend;
                i = strlen(file);
                if (Offend ^ (file[i - 2] == '-' && file[i - 1] == 'o')) {
                        DPRINTF(2, (stderr, "FALSE (offending file)\n"));
-                       return FALSE;
+                       return (FALSE);
                }
        }
 
-       if ((sp = rindex(file, '/')) == NULL)
+       if ((sp = strrchr(file, '/')) == NULL)
                sp = file;
        else
                sp++;
        if (*sp == '.') {
                DPRINTF(2, (stderr, "FALSE (file starts with '.')\n"));
-               return FALSE;
+               return (FALSE);
        }
        if (Fortunes_only && strncmp(sp, "fortunes", 8) != 0) {
                DPRINTF(2, (stderr, "FALSE (check fortunes only)\n"));
-               return FALSE;
+               return (FALSE);
        }
-       if ((sp = rindex(sp, '.')) != NULL) {
+       if ((sp = strrchr(sp, '.')) != NULL) {
                sp++;
                for (i = 0; suflist[i] != NULL; i++)
                        if (strcmp(sp, suflist[i]) == 0) {
                                DPRINTF(2, (stderr, "FALSE (file has suffix 
\".%s\")\n", sp));
-                               return FALSE;
+                               return (FALSE);
                        }
        }
 
@@ -830,67 +811,67 @@ int       check_for_offend;
                        DPRINTF(0, (stderr, "Warning: file \"%s\" 
unreadable\n", datfile));
 #endif
                free(datfile);
-               return FALSE;
+               return (FALSE);
        }
        if (datp != NULL)
                *datp = datfile;
        else
                free(datfile);
        if (posp != NULL) {
-#ifdef OK_TO_WRITE_DISK
-               *posp = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 
for ".dat" */
-               (void) strcat(*posp, ".pos");
-#else
-               *posp = NULL;
-#endif /* OK_TO_WRITE_DISK */
+               if (WriteToDisk) {
+                       *posp = copy(file, (unsigned int) (strlen(file) + 4)); 
/* +4 for ".dat" */
+                       strcat(*posp, ".pos");
+               }
+               else {
+                       *posp = NULL;

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to