summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authoredwin <edwin@FreeBSD.org>2007-11-07 01:14:28 +0000
committeredwin <edwin@FreeBSD.org>2007-11-07 01:14:28 +0000
commit6700ec85203c54a01eaf25052a5c858bd4c4d940 (patch)
treea31129423c51870a2c84fa56a20c50e098371751 /games
parent294e45bcfcd811ae6ff6000709db14870c372d7c (diff)
downloadFreeBSD-src-6700ec85203c54a01eaf25052a5c858bd4c4d940.zip
FreeBSD-src-6700ec85203c54a01eaf25052a5c858bd4c4d940.tar.gz
After discussions with grog@ (mentor):
- When none of the directories in FORTUNE_PATH exist, abort instead of using the default FORTDIR. - Little stylify changes. - Add documentation about the FORTUNE_PATH variable. MFC after: 1 week
Diffstat (limited to 'games')
-rw-r--r--games/fortune/fortune/fortune.69
-rw-r--r--games/fortune/fortune/fortune.c50
2 files changed, 37 insertions, 22 deletions
diff --git a/games/fortune/fortune/fortune.6 b/games/fortune/fortune/fortune.6
index 96aee79..9c616c6 100644
--- a/games/fortune/fortune/fortune.6
+++ b/games/fortune/fortune/fortune.6
@@ -167,6 +167,15 @@ is equivalent to
.Bd -literal -offset indent
fortune 50% funny 50% not-funny
.Ed
+.Sh ENVIRONMENT
+.Bl -tag -width Pa -compact
+.It FORTUNE_PATH
+The search path for the data files. It is a colon-separated list
+of directories in which
+.Nm
+looks for data files. If not set it will default to /usr/games/fortune.
+If none of the directories specified exist, it will print a warning and exit.
+.El
.Sh FILES
.Bl -tag -width Pa -compact
.It Pa /usr/games/fortune
diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c
index 3aa27a4..972d8d4 100644
--- a/games/fortune/fortune/fortune.c
+++ b/games/fortune/fortune/fortune.c
@@ -263,7 +263,7 @@ int
fortlen()
{
int nchar;
- char line[BUFSIZ];
+ char line[BUFSIZ];
if (!(Fortfile->tbl.str_flags & (STR_RANDOM | STR_ORDERED)))
nchar = (int)(Seekpts[1] - Seekpts[0]);
@@ -392,8 +392,8 @@ int file_cnt;
}
Fortunes_only = FALSE;
if (!i) {
- fprintf(stderr, "No fortunes found in %s.\n",
- Fortune_path);
+ fprintf(stderr, "No fortunes found in %s.\n",
+ Fortune_path);
}
return i != 0;
} else {
@@ -404,8 +404,8 @@ int file_cnt;
&File_list, &File_tail, NULL);
}
if (!i) {
- fprintf(stderr, "No fortunes found in %s.\n",
- Fortune_path);
+ fprintf(stderr, "No fortunes found in %s.\n",
+ Fortune_path);
}
return i != 0;
}
@@ -451,9 +451,9 @@ int file_cnt;
&File_list, &File_tail, NULL);
}
if (!i) {
- fprintf(stderr, "No fortunes found in %s.\n",
- Fortune_path);
- return FALSE;
+ fprintf(stderr, "No fortunes found in %s.\n",
+ Fortune_path);
+ return FALSE;
}
} else if (!add_file(percent, sp, NULL, &File_list,
&File_tail, NULL)) {
@@ -470,7 +470,7 @@ int file_cnt;
int
add_file(percent, file, dir, head, tail, parent)
int percent;
-char *file;
+char *file;
char *dir;
FILEDESC **head, **tail;
FILEDESC *parent;
@@ -540,8 +540,8 @@ over:
head, tail, parent);
}
if (!i) {
- fprintf(stderr, "No '%s' found in %s.\n",
- file, Fortune_path);
+ fprintf(stderr, "No '%s' found in %s.\n",
+ file, Fortune_path);
}
return i != 0;
}
@@ -667,7 +667,7 @@ char *file;
void
all_forts(fp, offensive)
FILEDESC *fp;
-char *offensive;
+char *offensive;
{
char *sp;
FILEDESC *scene, *obscene;
@@ -720,8 +720,8 @@ FILEDESC *fp;
{
DIR *dir;
struct dirent *dirent;
- auto FILEDESC *tailp;
- auto char *name;
+ auto FILEDESC *tailp;
+ auto char *name;
(void) close(fp->fd);
fp->fd = -1;
@@ -1427,13 +1427,15 @@ usage()
void
getpath(void)
{
- int nstr;
- char *pch, **ppch, *str, *path;
+ int nstr, foundenv;
+ char *pch, **ppch, *str, *path;
+ foundenv = 1;
Fortune_path = getenv("FORTUNE_PATH");
-
- if (Fortune_path == NULL)
- Fortune_path = "";
+ if (Fortune_path == NULL) {
+ Fortune_path = FORTDIR;
+ foundenv = 0;
+ }
path = strdup(Fortune_path);
for (nstr = 2, pch = path; *pch != '\0'; pch++) {
@@ -1452,11 +1454,15 @@ getpath(void)
}
str = strtok(NULL, ":");
}
+
if (nstr == 0) {
+ if (foundenv == 1) {
+ fprintf(stderr,
+ "fortune: FORTUNE_PATH: None of the specified "
+ "directories found.\n");
+ exit(1);
+ }
free(path);
Fortune_path_arr[0] = FORTDIR;
- if (strlen(Fortune_path))
- fprintf(stderr,
- "Ignoring FORTUNE_PATH; no directories found.\n");
}
}
OpenPOWER on IntegriCloud