From: Eric S. Raymond Date: Thu, 18 May 2017 12:55:38 +0000 (-0400) Subject: Partially ANSIfy C, fix compiler warnings. X-Git-Tag: seed~107 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=c9e9b6457540d1feb7ccd7186ccffa57698dec57;p=open-adventure.git Partially ANSIfy C, fix compiler warnings. --- diff --git a/actions1.c b/actions1.c index 464faff..74598b0 100644 --- a/actions1.c +++ b/actions1.c @@ -1,3 +1,4 @@ +#include #include "misc.h" #include "main.h" #include "share.h" @@ -6,8 +7,6 @@ #define TRUE (0==0) #define FALSE (0!=0) -extern carry(), discard(long), attack(), throw(), feed(), fill(); - /* This stuff was broken off as part of an effort to get the main program * to compile without running out of memory. We're called with a number * that says what label the caller wanted to "goto", and we return a diff --git a/actions2.c b/actions2.c index 98be045..7d931cc 100644 --- a/actions2.c +++ b/actions2.c @@ -10,7 +10,7 @@ * TAKE ONE WITHOUT THE OTHER). LIQUIDS ALSO SPECIAL, SINCE THEY DEPEND ON * STATUS OF BOTTLE. ALSO VARIOUS SIDE EFFECTS, ETC. */ -carry() { +int carry() { if(TOTING(OBJ)) return(2011); SPK=25; if(OBJ == PLANT && PROP[PLANT] <= 0)SPK=115; @@ -60,7 +60,7 @@ L9015: SPK=238; * BIRD (MIGHT ATTACK SNAKE OR DRAGON) AND CAGE (MIGHT CONTAIN BIRD) AND VASE. * DROP COINS AT VENDING MACHINE FOR EXTRA BATTERIES. */ -discard(just_do_it)long just_do_it; { +int discard(just_do_it)long just_do_it; { if(just_do_it) goto L9021; if(TOTING(ROD2) && OBJ == ROD && !TOTING(ROD))OBJ=ROD2; if(!TOTING(OBJ)) return(2011); @@ -134,7 +134,7 @@ L9028: PROP[VASE]=2; * OBJECTS FALL INTO TWO CATEGORIES: ENEMIES (SNAKE, DWARF, ETC.) AND OTHERS * (BIRD, CLAM, MACHINE). AMBIGUOUS IF 2 ENEMIES, OR NO ENEMIES BUT 2 OTHERS. */ -attack() { +int attack() { I=ATDWRF(LOC); if(OBJ != 0) goto L9124; if(I > 0)OBJ=DWARF; @@ -217,7 +217,7 @@ L9129: /*etc*/ ; * AND IF DWARF IS PRESENT THEN ONE MIGHT BE KILLED. (ONLY WAY TO DO SO!) * AXE ALSO SPECIAL FOR DRAGON, BEAR, AND TROLL. TREASURES SPECIAL FOR TROLL. */ -throw() { +int throw() { if(TOTING(ROD2) && OBJ == ROD && !TOTING(ROD))OBJ=ROD2; if(!TOTING(OBJ)) return(2011); if(OBJ >= 50 && OBJ <= MAXTRS && AT(TROLL)) goto L9178; @@ -273,7 +273,7 @@ L9178: SPK=159; /* FEED. IF BIRD, NO SEED. SNAKE, DRAGON, TROLL: QUIP. IF DWARF, MAKE HIM * MAD. BEAR, SPECIAL. */ -feed() { +int feed() { if(OBJ != BIRD) goto L9212; SPK=100; return(2011); @@ -315,7 +315,7 @@ L9216: SPK=14; /* FILL. BOTTLE OR URN MUST BE EMPTY, AND LIQUID AVAILABLE. (VASE IS NASTY.) */ -fill() { +int fill() { if(OBJ == VASE) goto L9222; if(OBJ == URN) goto L9224; if(OBJ != 0 && OBJ != BOTTLE) return(2011); diff --git a/datime.c b/datime.c index 0fa30de..b6a6b65 100644 --- a/datime.c +++ b/datime.c @@ -41,7 +41,7 @@ fDATIME(X,Y)long *X, *Y; { #ifndef _TIME_ #include "sys/time.h" -fDATIME(X,Y)long *X, *Y; { +void fDATIME(X,Y)long *X, *Y; { struct timeval now; gettimeofday(&now, 0); *X = now.tv_sec; diff --git a/funcs.h b/funcs.h index 0daecee..b64bfe2 100644 --- a/funcs.h +++ b/funcs.h @@ -35,6 +35,9 @@ #define OUTSID(LOC) ((LOC) <= 8 || FOREST(LOC) || (LOC) == PLAC[SAPPH] || (LOC) == 180 || (LOC) == 182) #define INDEEP(LOC) ((LOC) >= 15 && !OUTSID(LOC) && (LOC) != 179) +extern int carry(void), discard(long), attack(void), throw(void), feed(void), fill(void); +void score(long); + diff --git a/main.c b/main.c index 0f11fd4..11e940a 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #include #include +#include "main.h" #include "misc.h" #ifdef __MSDOS__ @@ -8,12 +9,13 @@ #define TRUE (0==0) #define FALSE (0!=0) + long ABB[186], ATAB[331], ATLOC[186], BLKLIN = TRUE, DFLAG, DLOC[7], FIXED[101], HOLDNG, KTAB[331], *LINES, LINK[201], LNLENG, LNPOSN, PARMS[26], PLACE[101], PTEXT[101], RTEXT[278], SETUP = 0, TABSIZ = 330; -char INLINE[101], MAP1[129], MAP2[129]; +signed char INLINE[LINESIZE], MAP1[129], MAP2[129]; long ABBNUM, ACTSPK[36], AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2, diff --git a/main.h b/main.h index 575ee97..3de002e 100644 --- a/main.h +++ b/main.h @@ -1,4 +1,6 @@ +#define LINESIZE 101 + extern long ABB[], ATAB[], ATLOC[], BLKLIN, DFLAG, DLOC[], FIXED[], HOLDNG, KTAB[], *LINES, LINK[], LNLENG, LNPOSN, PARMS[], PLACE[], PTEXT[], RTEXT[], TABSIZ; -extern signed char INLINE[], MAP1[], MAP2[]; +extern signed char INLINE[LINESIZE], MAP1[], MAP2[]; diff --git a/misc.c b/misc.c index e3e8320..626bd40 100644 --- a/misc.c +++ b/misc.c @@ -1,10 +1,15 @@ +#include +#include #include "main.h" #include "misc.h" -#include +#include "funcs.h" #define TRUE (0==0) #define FALSE (0!=0) +/* hack to ignore GCC Unused Result */ +#define IGNORE(r) do{if(r){}}while(0) + /* I/O ROUTINES (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */ #undef SPEAK @@ -839,7 +844,7 @@ void fBUG(NUM)long NUM; { * 28 INVALID MONTH RETURNED BY DATE FUNCTION * 29 TOO MANY PARAMETERS GIVEN TO SETPRM */ - printf("Fatal error %d. See source code for interpretation.\n", + printf("Fatal error %ld. See source code for interpretation.\n", NUM); exit(FALSE); } @@ -888,7 +893,7 @@ long I, VAL; static FILE *OPENED = NULL; if(MAP2[1] == 0)MPINIT(); if(FIL) goto L15; - gets(INLINE+1); + IGNORE(fgets(INLINE+1, sizeof(INLINE)-1, stdin)); if(feof(stdin)) score(1); goto L20; @@ -900,7 +905,7 @@ L15: if(!OPENED){ OPENED=fopen("adventure.text","r" /* NOT binary */); if(!OPENED){printf("Can't read adventure.text!\n"); exit(FALSE);} } - fgets(INLINE+1,100,OPENED); + IGNORE(fgets(INLINE+1,100,OPENED)); L20: LNLENG=0; /* 25 */ for (I=1; I<=100 && INLINE[I]!=0; I++) { @@ -1002,12 +1007,12 @@ L10: fclose(F); return; L20: printf("\nFile name: "); - gets(NAME); + IGNORE(fgets(NAME, sizeof(NAME), stdin)); F=fopen(NAME,(IN ? READ_MODE : WRITE_MODE)); if(F == NULL) {printf("Can't open file, try again.\n"); goto L20;} return; -L30: if(IN)fread(ARR,4,250,F); +L30: if(IN)IGNORE(fread(ARR,4,250,F)); if(!IN)fwrite(ARR,4,250,F); return; diff --git a/score.c b/score.c index acda23f..5caef0d 100644 --- a/score.c +++ b/score.c @@ -1,3 +1,4 @@ +#include #include "misc.h" #include "main.h" #include "share.h"