005-006.diff.bz2
patches · 4.4 KB · 2010-03-30
Download « Back to the patches list
diff -buraP 005/HACKLOG_1 006/HACKLOG_1
--- 005/HACKLOG_1 1969-12-31 19:00:00.000000000 -0500
+++ 006/HACKLOG_1 2008-10-08 12:33:39.000000000 -0400
@@ -0,0 +1,115 @@
+081006 MacGregor/Nibios
+
+Taking Quixadhal's fixup_081004 src and adapting to compile with g++ 3.4.6.
+First pass: compile dies with these errors and fixes:
+comm.c: In function `void act_new(const char*, CHAR_DATA*, const void*, const void*, int, int)':
+comm.c:2443: warning: cast from `const void*' to `CHAR_DATA*' discards qualifiers from pointer target type
+comm.c:2444: warning: cast from `const void*' to `OBJ_DATA*' discards qualifiers from pointer target type
+comm.c:2445: warning: cast from `const void*' to `OBJ_DATA*' discards qualifiers from pointer target type
+comm.c:2512: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type
+comm.c:2513: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type
+comm.c:2536: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type
+comm.c:2542: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type
+
+The offending lines:
+2443: CHAR_DATA *vch = (CHAR_DATA *) arg2;
+2444: OBJ_DATA *obj1 = (OBJ_DATA *) arg1;
+2445: OBJ_DATA *obj2 = (OBJ_DATA *) arg2;
+2512: case 't': i = (char *) arg1; break;
+2513: case 'T': i = (char *) arg2; break;
+2536: if ( arg2 == NULL || ((char *) arg2)[0] == '\0' )
+2542: one_argument( (char *) arg2, fname );
+
+
+The first six were pretty straightforward to fix, changing them respectively to:
+2443: const CHAR_DATA *vch = (const CHAR_DATA *) arg2;
+2444: const OBJ_DATA *obj1 = (const OBJ_DATA *) arg1;
+2445: const OBJ_DATA *obj2 = (const OBJ_DATA *) arg2;
+2512: case 't': i = (const char *) arg1; break;
+2513: case 'T': i = (const char *) arg2; break;
+2536: if ( arg2 == NULL || ((const char *) arg2)[0] == '\0' )
+
+We'll defer fixing line 2542 for now, and just recompile with what we have.
+We now get:
+comm.c: In function `void act_new(const char*, CHAR_DATA*, const void*, const void*, int, int)':
+comm.c:2515: error: invalid conversion from `const CHAR_DATA*' to `CHAR_DATA*'
+comm.c:2515: error: initializing argument 2 of `bool can_see(CHAR_DATA*, CHAR_DATA*)'
+comm.c:2524: error: invalid conversion from `const OBJ_DATA*' to `OBJ_DATA*'
+comm.c:2524: error: initializing argument 2 of `bool can_see_obj(CHAR_DATA*, OBJ_DATA*)'
+comm.c:2530: error: invalid conversion from `const OBJ_DATA*' to `OBJ_DATA*'
+comm.c:2530: error: initializing argument 2 of `bool can_see_obj(CHAR_DATA*, OBJ_DATA*)'
+comm.c:2542: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type
+
+The offending lines:
+2515: case 'N': i = PERS( vch, to ); break;
+2524: i = can_see_obj( to, obj1 )
+2530: i = can_see_obj( to, obj2 )
+2542: one_argument( (char *) arg2, fname );
+
+The PERS macro takes us to the can_see() function in handler.c.
+We change it from
+bool can_see( CHAR_DATA *ch, CHAR_DATA *victim )
+to
+bool can_see( const CHAR_DATA *ch, const CHAR_DATA *victim )
+
+This in turn requires changing get_trust(), get_skill() and get_curr_stat()
+all to take const CHAR_DATA * arguments instead of CHAR_DATA *.
+
+Fixing can_see_obj() is a bit more straightforward since we only have to change
+its own arguments to const CHAR_DATA * and const OBJ_DATA *.
+
+So now the only problem left is line 2542 and its call to one_argument().
+
+Changing one_argument() to take a const char * as its first argument, and
+returning a const char *, is going to open up a huge can of worms. The
+Right Thing To Do at this point would be to make the function take a const
+char * for its first argument, and return a const char *. This would mean,
+among other things, that every do_fun would have to take a const char * for
+their second argument.
+
+However this would definitely break about 95% of the existing ROM snippets,
+and we'd agreed we didn't want to do that. Furthermore, it already compiles
+just fine with gcc 4.1.x. So pretty much against my better judgement, I
+copied one_argument() to a new function get_argument(), with get_argument()
+taking and returning const char *'s, and changed line 2542 to call the new
+get_argument() function.
+
+Okay, it compiles cleanly now! Let's try compiling as gcc instead of g++.
+
+Whoops! act_comm.c blows up big time, referencing incomplete data types.
+The problem is that g++ has its own bool data type and gcc doesn't. So we
+add a couple lines in merc.h like so:
+
+/*
+ * Accomodate both gcc and g++
+ */
+#if !defined __cplusplus
+typedef unsigned char bool;
+#endif
+
+g++ is still happy, and so is gcc until it gets to act_wiz.c:
+act_wiz.c: In function `do_clone':
+act_wiz.c:2386: warning: declaration of 'new_obj' shadows a global declaration
+recycle.h:81: warning: shadowed declaration is here
+
+Hmm, wonder why this didn't show up earlier? Seems to me it should have.
+Anyway, change the local variable new_obj to cloned_obj and continue.
+
+Uh oh, comm.c blows up again, this time over those declarations of system
+calls at the top of comm.c. Let's extend the comment around the
+declarations for accept, bind et al to include the declarations for read,
+select, etc too. I think it would be safe to just remove them but I'll do
+it conservatively.
+
+Okay, another shadow problem in db.c, the variable 'exit' in the function
+do_dump(). Let's change it to pExit.
+
+Now we're getting, of all things, this error:
+handler.c: In function `unequip_char':
+handler.c:1646: warning: suggest explicit braces to avoid ambiguous `else'
+We add curley braces around the for loop inside the 'if', and also around
+the for-loop itself. Either set resolves the problem, but good practice
+requires both.
+
+Now, finally, it compikes with both g++ and gcc.
+
diff -buraP 005/src/act_wiz.c 006/src/act_wiz.c
--- 005/src/act_wiz.c 2008-10-08 12:32:02.000000000 -0400
+++ 006/src/act_wiz.c 2008-10-08 12:33:39.000000000 -0400
@@ -2383,7 +2383,7 @@
else if (mob != NULL)
{
CHAR_DATA *clone;
- OBJ_DATA *new_obj;
+ OBJ_DATA *cloned_obj;
char buf[MAX_STRING_LENGTH];
if (!IS_NPC(mob))
@@ -2410,11 +2410,11 @@
{
if (obj_check(ch,obj))
{
- new_obj = create_object(obj->pIndexData,0);
- clone_object(obj,new_obj);
- recursive_clone(ch,obj,new_obj);
- obj_to_char(new_obj,clone);
- new_obj->wear_loc = obj->wear_loc;
+ cloned_obj = create_object(obj->pIndexData,0);
+ clone_object(obj,cloned_obj);
+ recursive_clone(ch,obj,cloned_obj);
+ obj_to_char(cloned_obj,clone);
+ cloned_obj->wear_loc = obj->wear_loc;
}
}
char_to_room(clone,ch->in_room);
diff -buraP 005/src/comm.c 006/src/comm.c
--- 005/src/comm.c 2008-10-08 12:32:02.000000000 -0400
+++ 006/src/comm.c 2008-10-08 12:33:39.000000000 -0400
@@ -170,7 +170,6 @@
int getpeername args( ( int s, struct sockaddr *name, int *namelen ) );
int getsockname args( ( int s, struct sockaddr *name, int *namelen ) );
int listen args( ( int s, int backlog ) );
-*/
int close args( ( int fd ) );
int gettimeofday args( ( struct timeval *tp, struct timezone *tzp ) );
@@ -179,6 +178,7 @@
fd_set *exceptfds, struct timeval *timeout ) );
int socket args( ( int domain, int type, int protocol ) );
int write args( ( int fd, char *buf, int nbyte ) );
+*/
#endif
#if defined(macintosh)
@@ -2440,9 +2440,9 @@
char buf[MAX_STRING_LENGTH];
char fname[MAX_INPUT_LENGTH];
CHAR_DATA *to;
- CHAR_DATA *vch = (CHAR_DATA *) arg2;
- OBJ_DATA *obj1 = (OBJ_DATA *) arg1;
- OBJ_DATA *obj2 = (OBJ_DATA *) arg2;
+ const CHAR_DATA *vch = (const CHAR_DATA *) arg2;
+ const OBJ_DATA *obj1 = (const OBJ_DATA *) arg1;
+ const OBJ_DATA *obj2 = (const OBJ_DATA *) arg2;
const char *str;
const char *i;
char *point;
@@ -2509,8 +2509,8 @@
default: bug( "Act: bad code %d.", *str );
i = " <@@@> "; break;
/* Thx alex for 't' idea */
- case 't': i = (char *) arg1; break;
- case 'T': i = (char *) arg2; break;
+ case 't': i = (const char *) arg1; break;
+ case 'T': i = (const char *) arg2; break;
case 'n': i = PERS( ch, to ); break;
case 'N': i = PERS( vch, to ); break;
case 'e': i = he_she [URANGE(0, ch ->sex, 2)]; break;
@@ -2533,13 +2533,13 @@
break;
case 'd':
- if ( arg2 == NULL || ((char *) arg2)[0] == '\0' )
+ if ( arg2 == NULL || ((const char *) arg2)[0] == '\0' )
{
i = "door";
}
else
{
- one_argument( (char *) arg2, fname );
+ get_argument( (const char *) arg2, fname );
i = fname;
}
break;
diff -buraP 005/src/db.c 006/src/db.c
--- 005/src/db.c 2008-10-08 12:32:02.000000000 -0400
+++ 006/src/db.c 2008-10-08 12:33:39.000000000 -0400
@@ -2791,7 +2791,7 @@
OBJ_DATA *obj;
OBJ_INDEX_DATA *pObjIndex;
ROOM_INDEX_DATA *room;
- EXIT_DATA *exit;
+ EXIT_DATA *pExit;
DESCRIPTOR_DATA *d;
AFFECT_DATA *af;
FILE *fp;
@@ -2885,7 +2885,7 @@
/* exits */
fprintf(fp,"Exits %4d (%8d bytes)\n",
- top_exit, top_exit * (sizeof(*exit)));
+ top_exit, top_exit * (sizeof(*pExit)));
fclose(fp);
diff -buraP 005/src/handler.c 006/src/handler.c
--- 005/src/handler.c 2008-10-08 12:32:02.000000000 -0400
+++ 006/src/handler.c 2008-10-08 12:33:39.000000000 -0400
@@ -349,7 +349,7 @@
}
/* for returning skill information */
-int get_skill(CHAR_DATA *ch, int sn)
+int get_skill( const CHAR_DATA *ch, int sn )
{
int skill;
@@ -703,7 +703,7 @@
/*
* Retrieve a character's trusted level for permission checking.
*/
-int get_trust( CHAR_DATA *ch )
+int get_trust( const CHAR_DATA *ch )
{
if ( ch->desc != NULL && ch->desc->original != NULL )
ch = ch->desc->original;
@@ -727,7 +727,7 @@
}
/* command for retrieving stats */
-int get_curr_stat( CHAR_DATA *ch, int stat )
+int get_curr_stat( const CHAR_DATA *ch, int stat )
{
int max;
@@ -1644,7 +1644,9 @@
obj->wear_loc = -1;
if (!obj->enchanted)
+ {
for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )
+ {
if ( paf->location == APPLY_SPELL_AFFECT )
{
for ( lpaf = ch->affected; lpaf != NULL; lpaf = lpaf_next )
@@ -1664,6 +1666,8 @@
affect_modify( ch, paf, FALSE );
affect_check(ch,paf->where,paf->bitvector);
}
+ }
+ }
for ( paf = obj->affected; paf != NULL; paf = paf->next )
if ( paf->location == APPLY_SPELL_AFFECT )
@@ -2439,7 +2443,7 @@
/*
* True if char can see victim.
*/
-bool can_see( CHAR_DATA *ch, CHAR_DATA *victim )
+bool can_see( const CHAR_DATA *ch, const CHAR_DATA *victim )
{
/* RT changed so that WIZ_INVIS has levels */
if ( ch == victim )
@@ -2494,7 +2498,7 @@
/*
* True if char can see obj.
*/
-bool can_see_obj( CHAR_DATA *ch, OBJ_DATA *obj )
+bool can_see_obj( const CHAR_DATA *ch, const OBJ_DATA *obj )
{
if ( !IS_NPC(ch) && IS_SET(ch->act, PLR_HOLYLIGHT) )
return TRUE;
diff -buraP 005/src/interp.c 006/src/interp.c
--- 005/src/interp.c 2008-10-08 12:07:38.000000000 -0400
+++ 006/src/interp.c 2008-10-08 12:33:39.000000000 -0400
@@ -741,6 +741,36 @@
return argument;
}
+const char *get_argument( const char *argument, char *arg_first )
+{
+ char cEnd;
+
+ while ( isspace(*argument) )
+ argument++;
+
+ cEnd = ' ';
+ if ( *argument == '\'' || *argument == '"' )
+ cEnd = *argument++;
+
+ while ( *argument != '\0' )
+ {
+ if ( *argument == cEnd )
+ {
+ argument++;
+ break;
+ }
+ *arg_first = LOWER(*argument);
+ arg_first++;
+ argument++;
+ }
+ *arg_first = '\0';
+
+ while ( isspace(*argument) )
+ argument++;
+
+ return argument;
+}
+
/*
* Contributed by Alander.
*/
diff -buraP 005/src/merc.h 006/src/merc.h
--- 005/src/merc.h 2008-10-08 12:32:02.000000000 -0400
+++ 006/src/merc.h 2008-10-08 12:33:39.000000000 -0400
@@ -43,7 +43,6 @@
#endif
-
/*
* Short scalar types.
* Diavolo reports AIX compiler has bugs with short types.
@@ -68,6 +67,13 @@
#endif
+/*
+ * Accomodate both gcc and g++
+ */
+#if !defined __cplusplus
+typedef unsigned char bool;
+#endif
+
/*
* Structure types.
@@ -2203,13 +2209,13 @@
bool is_clan args( (CHAR_DATA *ch) );
bool is_same_clan args( (CHAR_DATA *ch, CHAR_DATA *victim));
bool is_old_mob args ( (CHAR_DATA *ch) );
-int get_skill args( ( CHAR_DATA *ch, int sn ) );
+int get_skill args( ( const CHAR_DATA *ch, int sn ) );
int get_weapon_sn args( ( CHAR_DATA *ch ) );
int get_weapon_skill args(( CHAR_DATA *ch, int sn ) );
int get_age args( ( CHAR_DATA *ch ) );
void reset_char args( ( CHAR_DATA *ch ) );
-int get_trust args( ( CHAR_DATA *ch ) );
-int get_curr_stat args( ( CHAR_DATA *ch, int stat ) );
+int get_trust args( ( const CHAR_DATA *ch ) );
+int get_curr_stat args( ( const CHAR_DATA *ch, int stat ) );
int get_max_train args( ( CHAR_DATA *ch, int stat ) );
int can_carry_n args( ( CHAR_DATA *ch ) );
int can_carry_w args( ( CHAR_DATA *ch ) );
@@ -2254,8 +2260,8 @@
bool room_is_dark args( ( ROOM_INDEX_DATA *pRoomIndex ) );
bool is_room_owner args( ( CHAR_DATA *ch, ROOM_INDEX_DATA *room) );
bool room_is_private args( ( ROOM_INDEX_DATA *pRoomIndex ) );
-bool can_see args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );
-bool can_see_obj args( ( CHAR_DATA *ch, OBJ_DATA *obj ) );
+bool can_see args( ( const CHAR_DATA *ch, const CHAR_DATA *victim ) );
+bool can_see_obj args( ( const CHAR_DATA *ch, const OBJ_DATA *obj ) );
bool can_see_room args( ( CHAR_DATA *ch, ROOM_INDEX_DATA *pRoomIndex) );
bool can_drop_obj args( ( CHAR_DATA *ch, OBJ_DATA *obj ) );
char * affect_loc_name args( ( int location ) );
@@ -2273,6 +2279,7 @@
/* interp.c */
+const char *get_argument args( ( const char *argument, char *arg_first ) );
void interpret args( ( CHAR_DATA *ch, char *argument ) );
bool is_number args( ( char *arg ) );
int number_argument args( ( char *argument, char *arg ) );