Subject: bin/6150: [PATCH] Atc: patch to use const
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 09/13/1998 15:58:38
>Number:         6150
>Category:       bin
>Synopsis:       [PATCH] Atc: 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:   Sun Sep 13 09:20:01 1998
>Last-Modified:
>Originator:     Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-09-12
>Environment:
[
System: Linux octomino 2.0.35 #1 Wed Aug 12 15:54:21 UTC 1998 i586 unknown
Architecture: i586
]
>Description:

The appended patch makes atc(6) use `const' where appropriate; with
this patch it should compile cleanly with -Wwrite-strings -Wcast-qual.

>How-To-Repeat:

>Fix:

diff -ruN atc/extern.c atc+/extern.c
--- atc/extern.c	Fri Oct 10 11:21:28 1997
+++ atc+/extern.c	Sun Sep 13 15:41:43 1998
@@ -60,7 +60,7 @@
 
 int		clck, safe_planes, start_time, test_mode;
 
-char		*file;
+const char	*file;
 
 FILE		*filein, *fileout;
 
diff -ruN atc/extern.h atc+/extern.h
--- atc/extern.h	Fri Oct 10 11:21:28 1997
+++ atc+/extern.h	Sun Sep 13 15:46:24 1998
@@ -47,7 +47,8 @@
  * For more info on this and all of my stuff, mail edjames@berkeley.edu.
  */
 
-extern char		GAMES[], *file;
+extern char		GAMES[];
+extern const char	*file;
 
 extern int		clck, safe_planes, start_time, test_mode;
 
@@ -76,23 +77,23 @@
 int		dir_no __P((char));
 void		done_screen __P((void));
 void		draw_all __P((void));
-void		draw_line __P((WINDOW *, int, int, int, int, char *));
+void		draw_line __P((WINDOW *, int, int, int, int, const char *));
 void		erase_all __P((void));
 int		getAChar __P((void));
 int		getcommand __P((void));
 int		gettoken __P((void));
 void		init_gr __P((void));
-void		ioaddstr __P((int, char *));
+void		ioaddstr __P((int, const char *));
 void		ioclrtobot __P((void));
 void		ioclrtoeol __P((int));
-void		ioerror __P((int, int, char *));
+void		ioerror __P((int, int, const char *));
 void		iomove __P((int));
 int		list_games __P((void));
 int		log_score __P((int));
 void		log_score_quit __P((int));
-void		loser __P((PLANE *, char *));
+void		loser __P((const PLANE *, const char *));
 int		main __P((int, char *[]));
-char		name __P((PLANE *));
+char		name __P((const PLANE *));
 int		next_plane __P((void));
 void		noise __P((void));
 int		number __P((char));
@@ -100,39 +101,39 @@
 int		pop __P((void));
 void		push __P((int, int));
 void		quit __P((int));
-int		read_file __P((char *));
+int		read_file __P((const char *));
 void		redraw __P((void));
 void		rezero __P((void));
-void		setup_screen __P((C_SCREEN *));
-int		too_close __P((PLANE *p1, PLANE *p2, int));
+void		setup_screen __P((const C_SCREEN *));
+int		too_close __P((const PLANE *p1, const PLANE *p2, int));
 void		update __P((int));
 int		yyerror __P((const char *));
 int		yylex __P((void));
 int		yyparse __P((void));
-char	       *Left __P((char));
-char	       *Right __P((char));
-char	       *airport __P((char));
-char	       *beacon __P((char));
-char	       *benum __P((char));
-char	       *circle __P((char));
-char	       *climb __P((char));
-char	       *command __P((PLANE *));
-char	       *default_game __P((void));
-char	       *delayb __P((char));
-char	       *descend __P((char));
-char	       *ex_it __P((char));
+const char     *Left __P((char));
+const char     *Right __P((char));
+const char     *airport __P((char));
+const char     *beacon __P((char));
+const char     *benum __P((char));
+const char     *circle __P((char));
+const char     *climb __P((char));
+const char     *command __P((const PLANE *));
+const char     *default_game __P((void));
+const char     *delayb __P((char));
+const char     *descend __P((char));
+const char     *ex_it __P((char));
 PLANE	       *findplane __P((int));
-char	       *ignore __P((char));
-char	       *left __P((char));
-char	       *mark __P((char));
+const char     *ignore __P((char));
+const char     *left __P((char));
+const char     *mark __P((char));
 PLANE	       *newplane __P((void));
-char	       *okay_game __P((char *));
-char	       *rel_dir __P((char));
-char	       *right __P((char));
-char	       *setalt __P((char));
-char	       *setplane __P((char));
-char	       *setrelalt __P((char));
-char	       *timestr __P((int));
-char	       *to_dir __P((char));
-char	       *turn __P((char));
-char	       *unmark __P((char));
+const char     *okay_game __P((const char *));
+const char     *rel_dir __P((char));
+const char     *right __P((char));
+const char     *setalt __P((char));
+const char     *setplane __P((char));
+const char     *setrelalt __P((char));
+const char     *timestr __P((int));
+const char     *to_dir __P((char));
+const char     *turn __P((char));
+const char     *unmark __P((char));
diff -ruN atc/graphics.c atc+/graphics.c
--- atc/graphics.c	Fri Oct 10 11:21:39 1997
+++ atc+/graphics.c	Sun Sep 13 15:47:39 1998
@@ -130,10 +130,11 @@
 
 void
 setup_screen(scp)
-	C_SCREEN	*scp;
+	const C_SCREEN	*scp;
 {
 	int	i, j;
-	char	str[3], *airstr;
+	char	str[3];
+	const char *airstr;
 
 	str[2] = '\0';
 
@@ -224,7 +225,7 @@
 draw_line(w, x, y, lx, ly, s)
 	WINDOW	*w;
 	int	 x, y, lx, ly;
-	char	*s;
+	const char	*s;
 {
 	int	dx, dy;
 
@@ -262,7 +263,7 @@
 void
 ioaddstr(pos, str)
 	int	 pos;
-	char	*str;
+	const char	*str;
 {
 	wmove(input, 0, pos);
 	waddstr(input, str);
@@ -281,7 +282,7 @@
 void
 ioerror(pos, len, str)
 	int	 pos, len;
-	char	*str;
+	const char	*str;
 {
 	int	i;
 
@@ -380,8 +381,8 @@
 
 void
 loser(p, s)
-	PLANE	*p;
-	char	*s;
+	const PLANE	*p;
+	const char	*s;
 {
 	int			c;
 #ifdef BSD
diff -ruN atc/input.c atc+/input.c
--- atc/input.c	Tue Jul 28 11:07:14 1998
+++ atc+/input.c	Sun Sep 13 15:49:58 1998
@@ -73,8 +73,8 @@
 typedef struct {
 	int	token;
 	int	to_state;
-	char	*str;
-	char	*(*func) __P((char));
+	const char	*str;
+	const char	*(*func) __P((char));
 } RULE;
 
 typedef struct {
@@ -248,7 +248,7 @@
 getcommand()
 {
 	int	c, i, done;
-	char	*s, *(*func) __P((char));
+	const char	*s, *(*func) __P((char));
 	PLANE	*pp;
 
 	rezero();
@@ -374,7 +374,7 @@
 		return (tval);
 }
 
-char	*
+const char	*
 setplane(c)
 	char c;
 {
@@ -388,7 +388,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 turn(c)
 	char c;
 {
@@ -397,7 +397,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 circle(c)
 	char c;
 {
@@ -407,7 +407,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 left(c)
 	char c;
 {
@@ -418,7 +418,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 right(c)
 	char c;
 {
@@ -429,7 +429,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 Left(c)
 	char c;
 {
@@ -439,7 +439,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 Right(c)
 	char c;
 {
@@ -449,7 +449,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 delayb(c)
 	char c;
 {
@@ -495,7 +495,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 beacon(c)
 	char c;
 {
@@ -503,7 +503,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 ex_it(c)
 	char c;
 {
@@ -511,7 +511,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 airport(c)
 	char c;
 {
@@ -519,7 +519,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 climb(c)
 	char c;
 {
@@ -527,7 +527,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 descend(c)
 	char c;
 {
@@ -535,7 +535,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 setalt(c)
 	char c;
 {
@@ -545,7 +545,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 setrelalt(c)
 	char c;
 {
@@ -570,7 +570,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 benum(c)
 	char c;
 {
@@ -602,7 +602,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 to_dir(c)
 	char c;
 {
@@ -610,7 +610,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 rel_dir(c)
 	char c;
 {
@@ -635,7 +635,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 mark(c)
 	char c;
 {
@@ -647,7 +647,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 unmark(c)
 	char c;
 {
@@ -659,7 +659,7 @@
 	return (NULL);
 }
 
-char	*
+const char	*
 ignore(c)
 	char c;
 {
diff -ruN atc/log.c atc+/log.c
--- atc/log.c	Sat Jul 25 11:06:20 1998
+++ atc+/log.c	Sun Sep 13 15:50:35 1998
@@ -61,10 +61,10 @@
 compar(va, vb)
 	const void *va, *vb;
 {
-	SCORE	*a, *b;
+	const SCORE	*a, *b;
 
-	a = (SCORE *)va;
-	b = (SCORE *)vb;
+	a = (const SCORE *)va;
+	b = (const SCORE *)vb;
 	if (b->planes == a->planes)
 		return (b->time - a->time);
 	else
@@ -81,7 +81,7 @@
 #define MIN(t)		(((t) % SECAHOUR) / SECAMIN)
 #define SEC(t)		((t) % SECAMIN)
 
-char	*
+const char	*
 timestr(t)
 	int t;
 {
diff -ruN atc/main.c atc+/main.c
--- atc/main.c	Sat Oct 11 11:49:42 1997
+++ atc+/main.c	Sun Sep 13 15:51:46 1998
@@ -71,7 +71,7 @@
 	int			seed;
 	int			f_usage = 0, f_list = 0, f_showscore = 0;
 	int			f_printpath = 0;
-	char			*file = NULL;
+	const char		*file = NULL;
 	char			*name, *ptr;
 	struct sigaction	sa;
 #ifdef BSD
@@ -221,7 +221,7 @@
 
 int
 read_file(s)
-	char	*s;
+	const char	*s;
 {
 	extern FILE	*yyin;
 	int		retval;
@@ -241,7 +241,7 @@
 		return (0);
 }
 
-char	*
+const char	*
 default_game()
 {
 	FILE		*fp;
@@ -266,13 +266,14 @@
 	return (file);
 }
 
-char	*
+const char	*
 okay_game(s)
 	char	*s;
 {
 	FILE		*fp;
 	static char	file[256];
-	char		*ret = NULL, line[256], games[256];
+	const char	*ret = NULL;
+	char		line[256], games[256];
 
 	strcpy(games, _PATH_GAMES);
 	strcat(games, GAMES);
diff -ruN atc/update.c atc+/update.c
--- atc/update.c	Sat Sep 12 11:04:37 1998
+++ atc+/update.c	Sun Sep 13 15:53:11 1998
@@ -222,9 +222,9 @@
 #endif
 }
 
-char *
+const char *
 command(pp)
-	PLANE	*pp;
+	const PLANE	*pp;
 {
 	static char	buf[50], *bp, *comm_start;
 
@@ -255,7 +255,7 @@
 
 char
 name(p)
-	PLANE	*p;
+	const PLANE	*p;
 {
 	if (p->plane_type == 0)
 		return ('A' + p->plane_no);
@@ -392,7 +392,7 @@
 
 int
 too_close(p1, p2, dist)
-	PLANE	*p1, *p2;
+	const PLANE	*p1, *p2;
 	int	 dist;
 {
 	if (ABS(p1->altitude - p2->altitude) <= dist &&
>Audit-Trail:
>Unformatted: