changeset 233:0990adf580ee

Declare some function arguments as const. Some functions, mostly in fight.c, declared variables as pointers to const char but passed them to functions that took pointers to ordinary char. The strings did not actually get modified, so adding 'const' to the function definitions removed the warnings.
author John "Elwin" Edwards
date Sun, 06 Mar 2016 19:32:47 -0500
parents 50b89f165a34
children c10fe421b8fb
files arogue5/fight.c rogue4/fight.c rogue4/misc.c rogue4/rogue.h
diffstat 4 files changed, 23 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/arogue5/fight.c	Sun Mar 06 14:45:18 2016 -0500
+++ b/arogue5/fight.c	Sun Mar 06 19:32:47 2016 -0500
@@ -20,17 +20,18 @@
 
 bool roll_em(struct thing *att_er, struct thing *def_er, struct object *weap, 
              bool hurl, struct object *cur_weapon, bool back_stab);
-void hit(struct object *weapon, struct thing *tp, char *er, char *ee, 
-         bool back_stab);
-void miss(struct object *weapon, struct thing *tp, char *er, char *ee);
+void hit(struct object *weapon, struct thing *tp, const char *er,
+         const char *ee, bool back_stab);
+void miss(struct object *weapon, struct thing *tp, const char *er, 
+          const char *ee);
 int dext_plus(int dexterity);
 int str_plus(short str);
 int add_dam(short str);
 int hung_dam(void);
-void thunk(struct object *weap, struct thing *tp, char *mname);
-void m_thunk(struct object *weap, struct thing *tp, char *mname);
-void bounce(struct object *weap, struct thing *tp, char *mname);
-void m_bounce(struct object *weap, struct thing *tp, char *mname);
+void thunk(struct object *weap, struct thing *tp, const char *mname);
+void m_thunk(struct object *weap, struct thing *tp, const char *mname);
+void bounce(struct object *weap, struct thing *tp, const char *mname);
+void m_bounce(struct object *weap, struct thing *tp, const char *mname);
 struct object *wield_weap(struct object *thrown, struct thing *mp);
 void explode(struct thing *tp);
 
@@ -1037,7 +1038,7 @@
  */
 
 char *
-prname(char *who, bool upper)
+prname(const char *who, bool upper)
 {
     static char tbuf[LINELEN];
 
@@ -1062,7 +1063,8 @@
  */
 
 void
-hit(struct object *weapon, struct thing *tp, char *er, char *ee, bool back_stab)
+hit(struct object *weapon, struct thing *tp, const char *er, const char *ee, 
+    bool back_stab)
 {
     register char *s = NULL;
     char 
@@ -1119,7 +1121,7 @@
  */
 
 void
-miss(struct object *weapon, struct thing *tp, char *er, char *ee)
+miss(struct object *weapon, struct thing *tp, const char *er, const char *ee)
 {
     register char *s = NULL;
     char
@@ -1226,7 +1228,7 @@
  */
 
 void
-thunk(struct object *weap, struct thing *tp, char *mname)
+thunk(struct object *weap, struct thing *tp, const char *mname)
 {
     /* tp: Defender */
     char *def_name;	/* Name of defender */
@@ -1254,7 +1256,7 @@
  */
 
 void
-m_thunk(struct object *weap, struct thing *tp, char *mname)
+m_thunk(struct object *weap, struct thing *tp, const char *mname)
 {
     char *att_name;	/* Name of attacker */
 
@@ -1281,7 +1283,7 @@
  */
 
 void
-bounce(struct object *weap, struct thing *tp, char *mname)
+bounce(struct object *weap, struct thing *tp, const char *mname)
 {
     /* tp: Defender */
     char *def_name;	/* Name of defender */
@@ -1309,7 +1311,7 @@
  */
 
 void
-m_bounce(struct object *weap, struct thing *tp, char *mname)
+m_bounce(struct object *weap, struct thing *tp, const char *mname)
 {
     char *att_name;	/* Name of attacker */
 
--- a/rogue4/fight.c	Sun Mar 06 14:45:18 2016 -0500
+++ b/rogue4/fight.c	Sun Mar 06 19:32:47 2016 -0500
@@ -22,8 +22,8 @@
 };
 
 bool roll_em(THING *thatt, THING *thdef, THING *weap, bool hurl);
-void hit(char *er, char *ee);
-void miss(char *er, char *ee);
+void hit(const char *er, const char *ee);
+void miss(const char *er, const char *ee);
 int str_plus(str_t str);
 int add_dam(str_t str);
 void thunk(THING *weap, const char *mname);
@@ -446,7 +446,7 @@
  *	The print name of a combatant
  */
 char *
-prname(char *who, bool upper)
+prname(const char *who, bool upper)
 {
     static char tbuf[MAXSTR];
 
@@ -470,7 +470,7 @@
  *	Print a message to indicate a succesful hit
  */
 void
-hit(char *er, char *ee)
+hit(const char *er, const char *ee)
 {
     register char *s = "";
 
@@ -496,7 +496,7 @@
  *	Print a message to indicate a poor swing
  */
 void
-miss(char *er, char *ee)
+miss(const char *er, const char *ee)
 {
     register char *s = "";
 
--- a/rogue4/misc.c	Sun Mar 06 14:45:18 2016 -0500
+++ b/rogue4/misc.c	Sun Mar 06 19:32:47 2016 -0500
@@ -345,7 +345,7 @@
  *	"an".
  */
 char *
-vowelstr(char *str)
+vowelstr(const char *str)
 {
     switch (*str)
     {
--- a/rogue4/rogue.h	Sun Mar 06 14:45:18 2016 -0500
+++ b/rogue4/rogue.h	Sun Mar 06 19:32:47 2016 -0500
@@ -619,7 +619,7 @@
 char   *unctrol(char ch);
 void    unlock_sc(void);
 void    unsee(void);
-char   *vowelstr(char *str);
+char   *vowelstr(const char *str);
 char   *xcrypt(const char *key, const char *setting);
 void    w_wait_for(WINDOW *win, char ch);
 void    wait_for(char ch);