Subject: bin/6028: [PATCH] Adventure: some functions duplicate standard ones
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 08/24/1998 21:00:50
>Number:         6028
>Category:       bin
>Synopsis:       [PATCH] Adventure: some functions duplicate standard ones
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 24 14:05:00 1998
>Last-Modified:
>Originator:     Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-08-19
>Environment:
[
System: Linux octomino 2.0.35 #1 Wed Aug 12 15:54:21 UTC 1998 i586 unknown
Architecture: i586
]
>Description:

Some of the functions in adventure essentially duplicate the
functionality of standard <string.h> ones.  This patch changes them
into macros defined in terms of the standard functions.  An
alternative approach, especially for copystr() and length(), would be
to change all callers to use the standard functions rather than adding
a macro.

>How-To-Repeat:

>Fix:

diff -ruN adventure/extern.h adventure+2/extern.h
--- adventure/extern.h	Sat Oct 11 11:49:19 1997
+++ adventure+2/extern.h	Mon Aug 24 20:50:11 1998
@@ -29,6 +29,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <string.h>
+
 /* crc.c */
 void crc_start __P((void));
 unsigned long crc __P((char *, int));
@@ -116,9 +118,12 @@
 void carry __P((int, int));
 void drop __P((int, int));
 int vocab __P((char *, int, int));
-void copystr __P((char *, char *));
-int weq __P((char *, char *));
-int length __P((char *));
+
+/* These three used to be functions in vocab.c */
+#define copystr(src, dest)	strcpy((dest), (src))
+#define weq(str1, str2)		(!strncmp((str1), (str2), 5))
+#define length(str)		(strlen((str)) + 1)
+
 void prht __P((void));
 
 /* wizard.c */
diff -ruN adventure/vocab.c adventure+2/vocab.c
--- adventure/vocab.c	Sat Oct 11 11:49:27 1997
+++ adventure+2/vocab.c	Mon Aug 24 20:51:19 1998
@@ -202,44 +202,6 @@
 }
 
 void
-copystr(w1, w2)			/* copy one string to another   */
-	char   *w1, *w2;
-{
-	char   *s, *t;
-	for (s = w1, t = w2; *s;)
-		*t++ = *s++;
-	*t = 0;
-}
-
-int
-weq(w1, w2)			/* compare words                */
-	char   *w1, *w2;	/* w1 is user, w2 is system     */
-{
-	char   *s, *t;
-	int     i;
-	s = w1;
-	t = w2;
-	for (i = 0; i < 5; i++) {	/* compare at most 5 chars      */
-		if (*t == 0 && *s == 0)
-			return (TRUE);
-		if (*s++ != *t++)
-			return (FALSE);
-	}
-	return (TRUE);
-}
-
-int
-length(str)			/* includes 0 at end            */
-	char   *str;
-{
-	char   *s;
-	int     n;
-	for (n = 0, s = str; *s++;)
-		n++;
-	return (n + 1);
-}
-
-void
 prht()
 {				/* print hash table             */
 	int     i, j, l;
>Audit-Trail:
>Unformatted: