CVS commit: src/games/fortune/fortune

2010-01-17 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jan 17 22:52:00 UTC 2010

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
Close two file descriptors after using them. Found by cppcheck.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.62 src/games/fortune/fortune/fortune.c:1.63
--- src/games/fortune/fortune/fortune.c:1.62	Thu Aug 27 03:09:17 2009
+++ src/games/fortune/fortune/fortune.c	Sun Jan 17 22:52:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.62 2009/08/27 03:09:17 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.63 2010/01/17 22:52:00 wiz Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.62 2009/08/27 03:09:17 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.63 2010/01/17 22:52:00 wiz Exp $);
 #endif
 #endif /* not lint */
 
@@ -233,6 +233,7 @@
 #ifdef LOCK_EX
 	(void) flock(fd, LOCK_UN);
 #endif /* LOCK_EX */
+	close(fd);
 #endif /* OK_TO_WRITE_DISK */
 	if (Wait) {
 		if (Fort_len == 0)
@@ -716,6 +717,7 @@
 		else
 			free(name);
 	}
+	(void) closedir(dir);
 	if (fp-num_children == 0) {
 		warnx(`%s': No fortune files in directory., fp-path);
 		return FALSE;



CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 00:40:44 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
remove unnecessary casts


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.52 src/games/fortune/fortune/fortune.c:1.53
--- src/games/fortune/fortune/fortune.c:1.52	Wed Aug 12 06:06:28 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 00:40:44 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.52 2009/08/12 06:06:28 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.53 2009/08/27 00:40:44 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.52 2009/08/12 06:06:28 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.53 2009/08/27 00:40:44 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -514,7 +514,7 @@
 		tpath = NULL;
 	}
 	else {
-		tpath = do_malloc((unsigned int) (strlen(dir) + strlen(file) + 2));
+		tpath = do_malloc(strlen(dir) + strlen(file) + 2);
 		(void) strcat(strcat(strcpy(tpath, dir), /), file);
 		path = tpath;
 	}
@@ -644,7 +644,7 @@
 {
 	FILEDESC	*fp;
 
-	fp = (FILEDESC *) do_malloc(sizeof *fp);
+	fp = do_malloc(sizeof *fp);
 	fp-datfd = -1;
 	fp-pos = POS_UNKNOWN;
 	fp-inf = NULL;
@@ -1319,7 +1319,7 @@
 	Fort_len = maxlen_in_list(File_list);
 	DPRINTF(2, (stderr, Maximum length is %d\n, Fort_len));
 	/* extra length, %\n is appended */
-	Fortbuf = do_malloc((unsigned int) Fort_len + 10);
+	Fortbuf = do_malloc(Fort_len + 10);
 
 	Found_one = FALSE;
 	matches_in_list(File_list);



CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 00:42:11 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
Use correct type for malloc sizes (size_t, not unsigned)


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.53 src/games/fortune/fortune/fortune.c:1.54
--- src/games/fortune/fortune/fortune.c:1.53	Thu Aug 27 00:40:44 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 00:42:11 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.53 2009/08/27 00:40:44 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.54 2009/08/27 00:42:11 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.53 2009/08/27 00:40:44 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.54 2009/08/27 00:42:11 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -130,11 +130,11 @@
 static int add_file(int,
 	const char *, const char *, FILEDESC **, FILEDESC **, FILEDESC *);
 static void all_forts(FILEDESC *, const char *);
-static char *copy(const char *, u_int);
+static char *copy(const char *, size_t);
 static void rot13(char *line, int len);
 static void display(FILEDESC *);
 static void do_free(void *);
-static void *do_malloc(u_int);
+static void *do_malloc(size_t);
 static int form_file_list(char **, int);
 static int fortlen(void);
 static void get_fort(void);
@@ -879,7 +879,7 @@
 static char *
 copy(str, len)
 	const char	*str;
-	unsigned int	len;
+	size_t	len;
 {
 	char	*new, *sp;
 
@@ -896,8 +896,7 @@
  *	Do a malloc, checking for NULL return.
  */
 static void *
-do_malloc(size)
-	unsigned int	size;
+do_malloc(size_t size)
 {
 	void	*new;
 



CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 00:43:31 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
remove more unnecessary casts


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.54 src/games/fortune/fortune/fortune.c:1.55
--- src/games/fortune/fortune/fortune.c:1.54	Thu Aug 27 00:42:11 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 00:43:31 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.54 2009/08/27 00:42:11 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.55 2009/08/27 00:43:31 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.54 2009/08/27 00:42:11 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.55 2009/08/27 00:43:31 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -670,7 +670,7 @@
 {
 	char	*new;
 
-	new = copy(file, (unsigned int) (strlen(file) + 2));
+	new = copy(file, strlen(file) + 2);
 	return strcat(new, -o);
 }
 
@@ -851,7 +851,7 @@
 			}
 	}
 
-	datfile = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for .dat */
+	datfile = copy(file, strlen(file) + 4); /* +4 for .dat */
 	strcat(datfile, .dat);
 	if (access(datfile, R_OK)  0) {
 		free(datfile);
@@ -864,7 +864,7 @@
 		free(datfile);
 #ifdef	OK_TO_WRITE_DISK
 	if (posp != NULL) {
-		*posp = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for .dat */
+		*posp = copy(file, strlen(file) + 4); /* +4 for .dat */
 		(void) strcat(*posp, .pos);
 	}
 #endif	/* OK_TO_WRITE_DISK */



CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 01:19:38 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
Sprinkle some size_t in places where it's better than int.
(Reduces casts.)


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.55 src/games/fortune/fortune/fortune.c:1.56
--- src/games/fortune/fortune/fortune.c:1.55	Thu Aug 27 00:43:31 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 01:19:38 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.55 2009/08/27 00:43:31 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.56 2009/08/27 01:19:38 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.55 2009/08/27 00:43:31 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.56 2009/08/27 01:19:38 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -116,7 +116,7 @@
 
 static char *Fortbuf = NULL;		/* fortune buffer for -m */
 
-static int Fort_len = 0;
+static size_t Fort_len = 0;
 
 static off_t Seekpts[2];		/* seek pointers to fortunes */
 
@@ -136,7 +136,7 @@
 static void do_free(void *);
 static void *do_malloc(size_t);
 static int form_file_list(char **, int);
-static int fortlen(void);
+static size_t fortlen(void);
 static void get_fort(void);
 static void get_pos(FILEDESC *);
 static void get_tbl(FILEDESC *);
@@ -164,7 +164,7 @@
 static char *conv_pat(char *);
 static int find_matches(void);
 static void matches_in_list(FILEDESC *);
-static int maxlen_in_list(FILEDESC *);
+static size_t maxlen_in_list(FILEDESC *);
 #endif
 
 #ifndef NO_REGEX
@@ -265,7 +265,7 @@
 	if (Wait) {
 		if (Fort_len == 0)
 			(void) fortlen();
-		sleep((unsigned int) max(Fort_len / CPERS, MINW));
+		sleep(max(Fort_len / CPERS, MINW));
 	}
 	return(0);
 }
@@ -308,10 +308,10 @@
  * fortlen:
  *	Return the length of the fortune.
  */
-static int
+static size_t
 fortlen()
 {
-	int	nchar;
+	size_t	nchar;
 	char	line[BUFSIZ];
 
 	if (!(Fortfile-tbl.str_flags  (STR_RANDOM | STR_ORDERED)))
@@ -1330,12 +1330,12 @@
  * maxlen_in_list
  *	Return the maximum fortune len in the file list.
  */
-static int
+static size_t
 maxlen_in_list(list)
 	FILEDESC	*list;
 {
 	FILEDESC	*fp;
-	int		 len, maxlen;
+	size_t len, maxlen;
 
 	maxlen = 0;
 	for (fp = list; fp != NULL; fp = fp-next) {
@@ -1345,7 +1345,7 @@
 		}
 		else {
 			get_tbl(fp);
-			if (fp-tbl.str_longlen  (u_int32_t)maxlen)
+			if (fp-tbl.str_longlen  maxlen)
 maxlen = fp-tbl.str_longlen;
 		}
 	}



CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 01:40:27 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
ANSIfy function definitions.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.56 src/games/fortune/fortune/fortune.c:1.57
--- src/games/fortune/fortune/fortune.c:1.56	Thu Aug 27 01:19:38 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 01:40:27 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.56 2009/08/27 01:19:38 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.57 2009/08/27 01:40:27 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.56 2009/08/27 01:19:38 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.57 2009/08/27 01:40:27 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -214,9 +214,7 @@
 #endif
 
 int
-main(ac, av)
-	int	ac;
-	char	*av[];
+main(int ac, char *av[])
 {
 	struct timeval tv;
 #ifdef	OK_TO_WRITE_DISK
@@ -271,9 +269,7 @@
 }
 
 static void
-rot13(line, len)
-	char *line;
-	int len;
+rot13(char *line, int len)
 {
 	char	*p, ch;
 
@@ -288,8 +284,7 @@
 }
 
 static void
-display(fp)
-	FILEDESC	*fp;
+display(FILEDESC *fp)
 {
 	char	line[BUFSIZ];
 
@@ -309,7 +304,7 @@
  *	Return the length of the fortune.
  */
 static size_t
-fortlen()
+fortlen(void)
 {
 	size_t	nchar;
 	char	line[BUFSIZ];
@@ -332,9 +327,7 @@
  *	This routine evaluates the arguments on the command line
  */
 static void
-getargs(argc, argv)
-	int	argc;
-	char	**argv;
+getargs(int argc, char **argv)
 {
 	int	ignore_case;
 # ifndef NO_REGEX
@@ -435,9 +428,7 @@
  *	Form the file list from the file specifications.
  */
 static int
-form_file_list(files, file_cnt)
-	char	**files;
-	int	file_cnt;
+form_file_list(char **files, int file_cnt)
 {
 	int	i, percent;
 	const char	*sp;
@@ -496,12 +487,8 @@
  *	Add a file to the file list.
  */
 static int
-add_file(percent, file, dir, head, tail, parent)
-	int		 percent;
-	const char	*file;
-	const char	*dir;
-	FILEDESC	**head, **tail;
-	FILEDESC	*parent;
+add_file(int percent, const char *file, const char *dir,
+	 FILEDESC **head, FILEDESC **tail, FILEDESC *parent)
 {
 	FILEDESC	*fp;
 	int		fd;
@@ -640,7 +627,7 @@
  *	Return a pointer to an initialized new FILEDESC.
  */
 static FILEDESC *
-new_fp()
+new_fp(void)
 {
 	FILEDESC	*fp;
 
@@ -665,8 +652,7 @@
  *	Return a pointer to the offensive version of a file of this name.
  */
 static char *
-off_name(file)
-	const char	*file;
+off_name(const char *file)
 {
 	char	*new;
 
@@ -679,8 +665,7 @@
  *	Is the file an offensive-style name?
  */
 static int
-is_off_name(file)
-	const char	*file;
+is_off_name(const char *file)
 {
 	int	len;
 
@@ -694,9 +679,7 @@
  *	there are two children to be a parent of.
  */
 static void
-all_forts(fp, offensive)
-	FILEDESC	*fp;
-	const char	*offensive;
+all_forts(FILEDESC *fp, const char *offensive)
 {
 	char		*sp;
 	FILEDESC	*scene, *obscene;
@@ -746,8 +729,7 @@
  *	Add the contents of an entire directory.
  */
 static int
-add_dir(fp)
-	FILEDESC	*fp;
+add_dir(FILEDESC *fp)
 {
 	DIR		*dir;
 	struct dirent	*dirent;
@@ -784,8 +766,7 @@
  *	Return TRUE if the file is a directory, FALSE otherwise.
  */
 static int
-is_dir(file)
-	const char	*file;
+is_dir(const char *file)
 {
 	struct stat	sbuf;
 
@@ -803,14 +784,7 @@
  */
 /* ARGSUSED */
 static int
-is_fortfile(file, datp, posp, check_for_offend)
-	const char	*file;
-	char		**datp, **posp
-# ifndef OK_TO_WRITE_DISK
-	__unused
-# endif
-	;
-	int	check_for_offend;
+is_fortfile(const char *file, char **datp, char **posp, int check_for_offend)
 {
 	int	i;
 	const char	*sp;
@@ -867,6 +841,10 @@
 		*posp = copy(file, strlen(file) + 4); /* +4 for .dat */
 		(void) strcat(*posp, .pos);
 	}
+#else
+	if (posp != NULL) {
+		/*  *posp = NULL; -- not quite yet */
+	}
 #endif	/* OK_TO_WRITE_DISK */
 	DPRINTF(2, (stderr, TRUE\n));
 	return TRUE;
@@ -877,9 +855,7 @@
  *	Return a malloc()'ed copy of the string
  */
 static char *
-copy(str, len)
-	const char	*str;
-	size_t	len;
+copy(const char *str, size_t len)
 {
 	char	*new, *sp;
 
@@ -910,8 +886,7 @@
  *	Free malloc'ed space, if any.
  */
 static void
-do_free(ptr)
-	void	*ptr;
+do_free(void *ptr)
 {
 	if (ptr != NULL)
 		free(ptr);
@@ -922,7 +897,7 @@
  *	Initialize the fortune probabilities.
  */
 static void
-init_prob()
+init_prob(void)
 {
 	FILEDESC	*fp, *last;
 	int		percent, num_noprob, frac;
@@ -985,7 +960,7 @@
  *	Get the fortune data file's seek pointer for the next fortune.
  */
 static void
-get_fort()
+get_fort(void)
 {
 	FILEDESC	*fp;
 	int		choice;
@@ -1048,8 +1023,7 @@
  *	Pick a child from a chosen parent.
  */
 static FILEDESC *
-pick_child(parent)

CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 01:42:08 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
Prevent nasal demons in a case I spotted while preparing the previous.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.57 src/games/fortune/fortune/fortune.c:1.58
--- src/games/fortune/fortune/fortune.c:1.57	Thu Aug 27 01:40:27 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 01:42:08 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.57 2009/08/27 01:40:27 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.58 2009/08/27 01:42:08 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.57 2009/08/27 01:40:27 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.58 2009/08/27 01:42:08 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -843,7 +843,7 @@
 	}
 #else
 	if (posp != NULL) {
-		/*  *posp = NULL; -- not quite yet */
+		*posp = NULL;
 	}
 #endif	/* OK_TO_WRITE_DISK */
 	DPRINTF(2, (stderr, TRUE\n));



CVS commit: src/games/fortune/fortune

2009-08-26 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Aug 27 03:09:17 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.c

Log Message:
Instead of trying to cons up a regexp that ignores case, use REG_ICASE.
This makes fortune -im work; it's been broken since whenever.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/games/fortune/fortune/fortune.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.c
diff -u src/games/fortune/fortune/fortune.c:1.61 src/games/fortune/fortune/fortune.c:1.62
--- src/games/fortune/fortune/fortune.c:1.61	Thu Aug 27 03:04:58 2009
+++ src/games/fortune/fortune/fortune.c	Thu Aug 27 03:09:17 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fortune.c,v 1.61 2009/08/27 03:04:58 dholland Exp $	*/
+/*	$NetBSD: fortune.c,v 1.62 2009/08/27 03:09:17 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1986, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = @(#)fortune.c	8.1 (Berkeley) 5/31/93;
 #else
-__RCSID($NetBSD: fortune.c,v 1.61 2009/08/27 03:04:58 dholland Exp $);
+__RCSID($NetBSD: fortune.c,v 1.62 2009/08/27 03:09:17 dholland Exp $);
 #endif
 #endif /* not lint */
 
@@ -176,9 +176,8 @@
 int main(int, char *[]);
 
 #ifndef NO_REGEX
-static void re_setup(struct re *rx, const char *pattern);
+static void re_setup(struct re *rx, const char *pattern, bool ignore_case);
 static void re_cleanup(struct re *rx);
-static char *conv_pat(char *);
 static int find_matches(void);
 static void matches_in_list(FILEDESC *);
 static size_t maxlen_in_list(FILEDESC *);
@@ -379,11 +378,9 @@
 
 #ifndef NO_REGEX
 	if (pat != NULL) {
-		if (ignore_case)
-			pat = conv_pat(pat);
-		re_setup(Re_pat, pat);
+		re_setup(Re_pat, pat, ignore_case);
 		rot13(pat, 0);
-		re_setup(Re_pat13, pat);
+		re_setup(Re_pat13, pat, ignore_case);
 	}
 #endif /* NO_REGEX */
 }
@@ -1204,13 +1201,18 @@
  *	Initialize regular expression pattern.
  */
 static void
-re_setup(struct re *rx, const char *pattern)
+re_setup(struct re *rx, const char *pattern, bool ignore_case)
 {
-	int code;
+	int code, flags;
 	char errbuf[1024];
 
 	assert(!rx-valid);
-	code = regcomp(rx-regex, pattern, REG_EXTENDED);
+
+	flags = REG_EXTENDED | REG_NOSUB;
+	if (ignore_case) {
+		flags |= REG_ICASE;
+	}
+	code = regcomp(rx-regex, pattern, flags);
 
 	if (code != 0) {
 		regerror(code, rx-regex, errbuf, sizeof(errbuf));
@@ -1241,46 +1243,6 @@
 }
 
 /*
- * conv_pat:
- *	Convert the pattern to an ignore-case equivalent.
- */
-static char *
-conv_pat(char *orig)
-{
-	char *sp;
-	unsigned int  cnt;
-	char *new;
-
-	cnt = 1;	/* allow for '\0' */
-	for (sp = orig; *sp != '\0'; sp++)
-		if (isalpha((unsigned char)*sp))
-			cnt += 4;
-		else
-			cnt++;
-	if ((new = malloc(cnt)) == NULL)
-		err(1, NULL);
-
-	for (sp = new; *orig != '\0'; orig++) {
-		if (islower((unsigned char)*orig)) {
-			*sp++ = '[';
-			*sp++ = *orig;
-			*sp++ = toupper((unsigned char)*orig);
-			*sp++ = ']';
-		}
-		else if (isupper((unsigned char)*orig)) {
-			*sp++ = '[';
-			*sp++ = *orig;
-			*sp++ = tolower((unsigned char)*orig);
-			*sp++ = ']';
-		}
-		else
-			*sp++ = *orig;
-	}
-	*sp = '\0';
-	return new;
-}
-
-/*
  * find_matches:
  *	Find all the fortunes which match the pattern we've been given.
  */



CVS commit: src/games/fortune/fortune

2009-04-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Apr 12 16:58:57 UTC 2009

Modified Files:
src/games/fortune/fortune: fortune.6

Log Message:
Don't nest displays.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/games/fortune/fortune/fortune.6

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/fortune/fortune/fortune.6
diff -u src/games/fortune/fortune/fortune.6:1.11 src/games/fortune/fortune/fortune.6:1.12
--- src/games/fortune/fortune/fortune.6:1.11	Thu Sep  9 22:01:08 2004
+++ src/games/fortune/fortune/fortune.6	Sun Apr 12 16:58:57 2009
@@ -1,4 +1,4 @@
-.\	$NetBSD: fortune.6,v 1.11 2004/09/09 22:01:08 wiz Exp $
+.\	$NetBSD: fortune.6,v 1.12 2009/04/12 16:58:57 joerg Exp $
 .\
 .\ Copyright (c) 1985, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -94,10 +94,10 @@
 we believe in healthy, hearty laughter -- at the expense of
 the whole human race, if needs be.
 Needs be.
+.Ed
 .Bd -filled -offset indent-two -compact
 --H. Allen Smith, Rude Jokes
 .Ed
-.Ed
 .It Fl s
 Short apothegms only.
 .It Fl w