Subject: bin/8039: [PATCH] Trek const patch
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm28@cam.ac.uk>
List: netbsd-bugs
Date: 07/20/1999 11:04:23
>Number: 8039
>Category: bin
>Synopsis: [PATCH] Trek const patch
>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 Jul 20 10:05:01 1999
>Last-Modified:
>Originator: Joseph S. Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release: NetBSD-current of 1999-07-18
>Environment:
[
System: Linux decomino 2.2.10 #1 Mon Jun 14 07:48:53 UTC 1999 i686 unknown
Architecture: i686
]
>Description:
This patch makes trek(6) use `const' where appropriate.
>How-To-Repeat:
>Fix:
diff -ruN trek/computer.c trek+/computer.c
--- trek/computer.c Mon Oct 13 11:27:34 1997
+++ trek+/computer.c Tue Jul 20 12:43:50 1999
@@ -118,7 +118,7 @@
int ix, iy;
int i, j;
int tqx, tqy;
- struct cvntab *r;
+ const struct cvntab *r;
int cost;
int course;
double dist, time;
diff -ruN trek/externs.c trek+/externs.c
--- trek/externs.c Mon Oct 13 11:27:41 1997
+++ trek+/externs.c Tue Jul 20 12:44:14 1999
@@ -48,7 +48,7 @@
** global variable definitions
*/
-struct device Device[NDEV] =
+const struct device Device[NDEV] =
{
{ "warp drive", "Scotty" },
{ "S.R. scanners", "Scotty" },
@@ -68,7 +68,7 @@
{ "*ERR 15*", "Nobody" }
};
-char *Systemname[NINHAB] =
+const char *const Systemname[NINHAB] =
{
"ERROR",
"Talos IV",
diff -ruN trek/getpar.c trek+/getpar.c
--- trek/getpar.c Tue Oct 14 11:09:55 1997
+++ trek+/getpar.c Tue Jul 20 12:46:10 1999
@@ -55,7 +55,7 @@
int
getintpar(s)
-char *s;
+ const char *s;
{
int i;
int n;
@@ -79,7 +79,7 @@
**/
double getfltpar(s)
-char *s;
+ const char *s;
{
int i;
double d;
@@ -102,7 +102,7 @@
** get yes/no parameter
**/
-struct cvntab Yntab[] =
+const struct cvntab Yntab[] =
{
{ "y", "es", (cmdfun)1, 1 },
{ "n", "o", (cmdfun)0, 0 },
@@ -111,9 +111,9 @@
int
getynpar(s)
-char *s;
+ const char *s;
{
- struct cvntab *r;
+ const struct cvntab *r;
r = getcodpar(s, Yntab);
return r->value2;
@@ -124,14 +124,14 @@
** get coded parameter
**/
-struct cvntab *getcodpar(s, tab)
-char *s;
-struct cvntab tab[];
+const struct cvntab *getcodpar(s, tab)
+ const char *s;
+ const struct cvntab tab[];
{
char input[100];
- struct cvntab *r;
+ const struct cvntab *r;
int flag;
- char *p, *q;
+ const char *p, *q;
int c;
int f;
@@ -204,10 +204,10 @@
void
getstrpar(s, r, l, t)
-char *s;
-char *r;
-int l;
-char *t;
+ const char *s;
+ char *r;
+ int l;
+ const char *t;
{
int i;
char format[20];
diff -ruN trek/getpar.h trek+/getpar.h
--- trek/getpar.h Mon Oct 13 11:27:43 1997
+++ trek+/getpar.h Tue Jul 20 12:46:47 1999
@@ -44,11 +44,11 @@
int value2;
};
-int getintpar __P((char *));
-double getfltpar __P((char *));
-int getynpar __P((char *));
-struct cvntab *getcodpar __P((char *, struct cvntab[]));
-void getstrpar __P((char *, char *, int, char *));
+int getintpar __P((const char *));
+double getfltpar __P((const char *));
+int getynpar __P((const char *));
+const struct cvntab *getcodpar __P((const char *, const struct cvntab[]));
+void getstrpar __P((const char *, char *, int, const char *));
int testnl __P((void));
void skiptonl __P((int));
int readdelim __P((int));
diff -ruN trek/help.c trek+/help.c
--- trek/help.c Mon Oct 13 11:27:43 1997
+++ trek+/help.c Tue Jul 20 12:47:11 1999
@@ -67,7 +67,7 @@
** to drop you. After that, it's your problem.
*/
-char *Cntvect[3] =
+const char *const Cntvect[3] =
{"first", "second", "third"};
/*ARGSUSED*/
diff -ruN trek/kill.c trek+/kill.c
--- trek/kill.c Sun Aug 30 11:05:25 1998
+++ trek+/kill.c Tue Jul 20 12:47:31 1999
@@ -158,7 +158,7 @@
{
struct quad *q;
struct event *e;
- char *name;
+ const char *name;
if (f)
{
diff -ruN trek/lose.c trek+/lose.c
--- trek/lose.c Mon Oct 13 11:27:47 1997
+++ trek+/lose.c Tue Jul 20 12:47:50 1999
@@ -56,7 +56,7 @@
** actions which need be taken are taken.
*/
-char *Losemsg[] =
+const char *const Losemsg[] =
{
"You ran out of time",
"You ran out of energy",
diff -ruN trek/out.c trek+/out.c
--- trek/out.c Tue Oct 14 11:09:56 1997
+++ trek+/out.c Tue Jul 20 12:48:08 1999
@@ -54,7 +54,7 @@
out(dev)
int dev;
{
- struct device *d;
+ const struct device *d;
d = &Device[dev];
printf("%s reports %s ", d->person, d->name);
diff -ruN trek/phaser.c trek+/phaser.c
--- trek/phaser.c Mon Oct 13 11:27:52 1997
+++ trek+/phaser.c Tue Jul 20 12:48:25 1999
@@ -113,7 +113,7 @@
int n;
int hitreqd[NBANKS];
struct banks bank[NBANKS];
- struct cvntab *ptr;
+ const struct cvntab *ptr;
if (Ship.cond == DOCKED) {
printf("Phasers cannot fire through starbase shields\n");
diff -ruN trek/play.c trek+/play.c
--- trek/play.c Mon Oct 13 11:27:52 1997
+++ trek+/play.c Tue Jul 20 12:48:45 1999
@@ -58,7 +58,7 @@
** on how we are doing after the move.
*/
-struct cvntab Comtab[] =
+const struct cvntab Comtab[] =
{
{ "abandon", "", abandon, 0 },
{ "ca", "pture", capture, 0 },
@@ -99,7 +99,7 @@
void
play()
{
- struct cvntab *r;
+ const struct cvntab *r;
while (1)
{
diff -ruN trek/setup.c trek+/setup.c
--- trek/setup.c Mon Oct 13 11:27:55 1997
+++ trek+/setup.c Tue Jul 20 12:49:01 1999
@@ -61,7 +61,7 @@
** Game restart and tournament games are handled here.
*/
-struct cvntab Lentab[] =
+const struct cvntab Lentab[] =
{
{ "s", "hort", (cmdfun)1, 0 },
{ "m", "edium", (cmdfun)2, 0 },
@@ -70,7 +70,7 @@
{ NULL, NULL, NULL, 0 }
};
-struct cvntab Skitab[] =
+const struct cvntab Skitab[] =
{
{ "n", "ovice", (cmdfun)1, 0 },
{ "f", "air", (cmdfun)2, 0 },
@@ -84,7 +84,7 @@
void
setup()
{
- struct cvntab *r;
+ const struct cvntab *r;
int i, j;
double f;
int d;
diff -ruN trek/shield.c trek+/shield.c
--- trek/shield.c Sun Aug 30 11:05:26 1998
+++ trek+/shield.c Tue Jul 20 12:49:23 1999
@@ -63,7 +63,7 @@
** so you get partial hits.
*/
-struct cvntab Udtab[] =
+const struct cvntab Udtab[] =
{
{ "u", "p", (cmdfun)1, 0 },
{ "d", "own", (cmdfun)0, 0 },
@@ -75,9 +75,9 @@
int f;
{
int i;
- struct cvntab *r;
+ const struct cvntab *r;
char s[100];
- char *device, *dev2, *dev3;
+ const char *device, *dev2, *dev3;
int ind;
char *stat;
diff -ruN trek/srscan.c trek+/srscan.c
--- trek/srscan.c Mon Oct 13 11:27:58 1997
+++ trek+/srscan.c Tue Jul 20 12:49:50 1999
@@ -61,7 +61,7 @@
** The current quadrant is filled in on the computer chart.
*/
-char *Color[4] =
+const char *const Color[4] =
{
"GREEN",
"DOCKED",
@@ -75,10 +75,10 @@
{
int i, j;
int statinfo;
- char *s;
+ const char *s;
int percent;
struct quad *q = NULL;
- struct cvntab *p;
+ const struct cvntab *p;
if (f >= 0 && check_out(SRSCAN))
{
diff -ruN trek/systemname.c trek+/systemname.c
--- trek/systemname.c Mon Oct 13 11:27:58 1997
+++ trek+/systemname.c Tue Jul 20 12:50:07 1999
@@ -55,10 +55,10 @@
** starsystems, etc.
*/
-char *systemname(q1)
-struct quad *q1;
+const char *systemname(q1)
+ const struct quad *q1;
{
- struct quad *q;
+ const struct quad *q;
int i;
q = q1;
diff -ruN trek/trek.h trek+/trek.h
--- trek/trek.h Mon Oct 13 11:28:00 1997
+++ trek+/trek.h Tue Jul 20 12:52:56 1999
@@ -90,7 +90,7 @@
*/
/* ascii names of systems */
-extern char *Systemname[NINHAB];
+extern const char *const Systemname[NINHAB];
/* quadrant definition */
struct quad Quad[NQUADS][NQUADS];
@@ -133,11 +133,11 @@
/* device names */
struct device
{
- char *name; /* device name */
- char *person; /* the person who fixes it */
+ const char *name; /* device name */
+ const char *person; /* the person who fixes it */
};
-struct device Device[NDEV];
+const struct device Device[NDEV];
/*************************** EVENTS ****************************/
@@ -215,8 +215,8 @@
};
-extern struct cvntab Skitab[];
-extern struct cvntab Lentab[];
+extern const struct cvntab Skitab[];
+extern const struct cvntab Lentab[];
/*
* note that much of the stuff in the following structs CAN NOT
@@ -245,7 +245,7 @@
int secty; /* sector y coord */
unsigned char cond; /* condition code */
char sinsbad; /* Space Inertial Navigation System condition */
- char *shipname; /* name of current starship */
+ const char *shipname; /* name of current starship */
char ship; /* current starship */
int distressed; /* number of distress calls */
} Ship;
@@ -516,7 +516,7 @@
void srscan __P((int));
/* systemname.c */
-char *systemname __P((struct quad *));
+const char *systemname __P((const struct quad *));
/* torped.c */
void torped __P((int));
diff -ruN trek/win.c trek+/win.c
--- trek/win.c Mon Oct 13 11:28:02 1997
+++ trek+/win.c Tue Jul 20 12:51:49 1999
@@ -65,7 +65,7 @@
win()
{
long s;
- struct cvntab *p = NULL;
+ const struct cvntab *p = NULL;
extern jmp_buf env;
sleep(1);
>Audit-Trail:
>Unformatted: