Subject: bin/6041: [PATCH] Adventure: patch to use const
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 08/25/1998 20:03:26
>Number: 6041
>Category: bin
>Synopsis: [PATCH] Adventure: patch to use const
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue Aug 25 13:20:01 1998
>Last-Modified:
>Originator: Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release: NetBSD-current of 1998-08-25
>Environment:
[
System: Linux octomino 2.0.35 #1 Wed Aug 12 15:54:21 UTC 1998 i586 unknown
Architecture: i586
]
>Description:
The patch here makes the game adventure use `const' where
appropriate. With this patch it compiles cleanly with -Wwrite-strings
(though it may do so already - certainly the already applied patch to
use standard string functions (bin/6028) fixed most of the warnings).
>How-To-Repeat:
>Fix:
diff -ruN adventure/crc.c adventure+const/crc.c
--- adventure/crc.c Sat Oct 11 11:49:17 1997
+++ adventure+const/crc.c Tue Aug 25 19:50:06 1998
@@ -121,11 +121,11 @@
unsigned long
crc(ptr, nr) /* Process nr bytes at a time; ptr points to them */
- char *ptr;
+ const char *ptr;
int nr;
{
int i;
- char *p;
+ const char *p;
while (nr > 0)
for (p = ptr; nr--; ++p) {
diff -ruN adventure/extern.h adventure+const/extern.h
--- adventure/extern.h Tue Aug 25 11:05:16 1998
+++ adventure+const/extern.h Tue Aug 25 19:51:26 1998
@@ -33,7 +33,7 @@
/* crc.c */
void crc_start __P((void));
-unsigned long crc __P((char *, int));
+unsigned long crc __P((const char *, int));
/* done.c */
int score __P((void));
@@ -66,15 +66,15 @@
void rspeak __P((int));
void mspeak __P((int));
struct text;
-void speak __P((struct text *));
+void speak __P((const struct text *));
void pspeak __P((int, int));
/* main.c */
int main __P((int, char **));
/* save.c */
-int save __P((char *));
-int restore __P((char *));
+int save __P((const char *));
+int restore __P((const char *));
/* setup.c */
int main __P((int, char *[]));
@@ -117,7 +117,7 @@
int put __P((int, int, int));
void carry __P((int, int));
void drop __P((int, int));
-int vocab __P((char *, int, int));
+int vocab __P((const char *, int, int));
/* These three used to be functions in vocab.c */
#define copystr(src, dest) strcpy((dest), (src))
diff -ruN adventure/io.c adventure+const/io.c
--- adventure/io.c Sat Oct 11 11:49:22 1997
+++ adventure+const/io.c Tue Aug 25 19:52:28 1998
@@ -169,8 +169,8 @@
int outsw = 0; /* putting stuff to data file? */
-char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
-char *tape = iotape; /* pointer to encryption tape */
+const char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l";
+const char *tape = iotape; /* pointer to encryption tape */
int
next()
@@ -522,7 +522,7 @@
void
speak(msg) /* read, decrypt, and print a message (not
* ptext) */
- struct text *msg; /* msg is a pointer to seek address and length
+ const struct text *msg; /* msg is a pointer to seek address and length
* of mess */
{
char *s, nonfirst;
diff -ruN adventure/save.c adventure+const/save.c
--- adventure/save.c Sat Oct 11 11:49:24 1997
+++ adventure+const/save.c Tue Aug 25 19:53:06 1998
@@ -126,7 +126,7 @@
int
save(outfile) /* Two passes on data: first to get checksum,
* second */
- char *outfile; /* to output the data using checksum to start
+ const char *outfile; /* to output the data using checksum to start
* random #s */
{
FILE *out;
@@ -158,7 +158,7 @@
int
restore(infile)
- char *infile;
+ const char *infile;
{
FILE *in;
struct savestruct *p;
diff -ruN adventure/vocab.c adventure+const/vocab.c
--- adventure/vocab.c Tue Aug 25 11:05:17 1998
+++ adventure+const/vocab.c Tue Aug 25 19:53:43 1998
@@ -137,13 +137,14 @@
int
vocab(word, type, value) /* look up or store a word */
- char *word;
+ const char *word;
int type; /* -2 for store, -1 for user word, >=0 for
* canned lookup */
int value; /* used for storing only */
{
int adr;
- char *s, *t;
+ const char *s;
+ char *t;
int hash, i;
struct hashtab *h;
>Audit-Trail:
>Unformatted: