More goto elimination in misc.c

This commit is contained in:
Eric S. Raymond 2017-06-07 18:34:08 -04:00
parent 7fa8757ad4
commit da5976dc8c

143
misc.c
View file

@ -142,17 +142,17 @@ void PSPEAK(vocab_t msg,int skip)
* the index of the inventory message for object. (INVEN+N+1 message * the index of the inventory message for object. (INVEN+N+1 message
* is game.prop=N message). */ * is game.prop=N message). */
{ {
long I, M; long i, m;
M=PTEXT[msg]; m=PTEXT[msg];
if(skip >= 0) { if(skip >= 0) {
for (I=0; I<=skip; I++) { for (i=0; i<=skip; i++) {
L1: M=labs(LINES[M]); L1: m=labs(LINES[m]);
if (LINES[M] >= 0) if (LINES[m] >= 0)
goto L1; goto L1;
} }
} }
SPEAK(M); SPEAK(m);
} }
void RSPEAK(vocab_t i) void RSPEAK(vocab_t i)
/* Print the i-th "random" message (section 6 of database). */ /* Print the i-th "random" message (section 6 of database). */
@ -173,7 +173,6 @@ void SETPRM(long first, long p1, long p2)
} }
} }
#undef GETIN
#define WORD1 (*wORD1) #define WORD1 (*wORD1)
#define WORD1X (*wORD1X) #define WORD1X (*wORD1X)
#define WORD2 (*wORD2) #define WORD2 (*wORD2)
@ -208,26 +207,26 @@ L22: JUNK=GETTXT(false,true,true);
RSPEAK(53); RSPEAK(53);
} }
} }
#define GETIN(SRC,WORD1,WORD1X,WORD2,WORD2X) fGETIN(SRC,&WORD1,&WORD1X,&WORD2,&WORD2X)
long YES(FILE *input, vocab_t x, vocab_t y, vocab_t z) long YES(FILE *input, vocab_t x, vocab_t y, vocab_t z)
/* Print message X, wait for yes/no answer. If yes, print Y and return true; /* Print message X, wait for yes/no answer. If yes, print Y and return true;
* if no, print Z and return false. */ * if no, print Z and return false. */
{ {
token_t yeah, reply, junk1, junk2, junk3; token_t reply, junk1, junk2, junk3;
L1: RSPEAK(x); for (;;) {
GETIN(input, reply,junk1,junk2,junk3); RSPEAK(x);
if(reply == MAKEWD(250519) || reply == MAKEWD(25)) goto L10; GETIN(input, reply,junk1,junk2,junk3);
if(reply == MAKEWD(1415) || reply == MAKEWD(14)) goto L20; if(reply == MAKEWD(250519) || reply == MAKEWD(25)) {
RSPEAK(185); RSPEAK(y);
goto L1; return true;
L10: yeah=true; }
RSPEAK(y); if(reply == MAKEWD(1415) || reply == MAKEWD(14)) {
return(yeah); RSPEAK(z);
L20: yeah=false; return false;
RSPEAK(z); }
return(yeah); RSPEAK(185);
}
} }
/* Line-parsing routines (GETTXT, MAKEWD, PUTTXT, SHFTXT, TYPE0) */ /* Line-parsing routines (GETTXT, MAKEWD, PUTTXT, SHFTXT, TYPE0) */
@ -329,11 +328,11 @@ void fPUTTXT(token_t word, long *state, long casemake)
if(w <= 0 && *state == 0 && labs(casemake) <= 1) if(w <= 0 && *state == 0 && labs(casemake) <= 1)
return; return;
byte=w/div; byte=w/div;
if(*state != 0 || byte != 63) goto L12; if (!(*state != 0 || byte != 63)) {
*state=63; *state=63;
goto L18; goto L18;
}
L12: SHFTXT(LNPOSN,1); SHFTXT(LNPOSN,1);
*state=*state+byte; *state=*state+byte;
if(*state < alph2 && *state >= alph1)*state=*state-26*casemake; if(*state < alph2 && *state >= alph1)*state=*state-26*casemake;
INLINE[LNPOSN]=*state; INLINE[LNPOSN]=*state;
@ -408,11 +407,7 @@ void fSAVARR(long arr[], long n)
} }
#define SAVARR(ARR,N) fSAVARR(ARR,N) #define SAVARR(ARR,N) fSAVARR(ARR,N)
#undef SAVWRD void fSAVWRD(long op, long *pword)
#define WORD (*wORD)
void fSAVWRD(long OP, long *wORD) {
static long BUF[250], CKSUM = 0, H1, HASH = 0, N = 0, STATE = 0;
/* If OP<0, start writing a file, using word to initialise encryption; save /* If OP<0, start writing a file, using word to initialise encryption; save
* word in the file. If OP>0, start reading a file; read the file to find * word in the file. If OP>0, start reading a file; read the file to find
* the value with which to decrypt the rest. In either case, if a file is * the value with which to decrypt the rest. In either case, if a file is
@ -420,48 +415,56 @@ static long BUF[250], CKSUM = 0, H1, HASH = 0, N = 0, STATE = 0;
* read/write a single word. Words are buffered in case that makes for more * read/write a single word. Words are buffered in case that makes for more
* efficient disk use. We also compute a simple checksum to catch elementary * efficient disk use. We also compute a simple checksum to catch elementary
* poking within the saved file. When we finish reading/writing the file, * poking within the saved file. When we finish reading/writing the file,
* we store zero into WORD if there's no checksum error, else nonzero. */ * we store zero into *PWORD if there's no checksum error, else nonzero. */
{
static long buf[250], cksum = 0, h1, hash = 0, n = 0, state = 0;
if(OP != 0){long ifvar; ifvar=(STATE); switch (ifvar<0? -1 : ifvar>0? 1 : if (op != 0)
0) { case -1: goto L30; case 0: goto L10; case 1: goto L30; }} {
if(STATE == 0)return; long ifvar = state;
if(N == 250)SAVEIO(1,STATE > 0,BUF); switch (ifvar<0 ? -1 : (ifvar>0 ? 1 : 0))
N=MOD(N,250)+1; {
H1=MOD(HASH*1093L+221573L,1048576L); case -1:
HASH=MOD(H1*1093L+221573L,1048576L); case 1:
H1=MOD(H1,1234)*765432+MOD(HASH,123); if(n == 250)SAVEIO(1,state > 0,buf);
N--; n=MOD(n,250)+1;
if(STATE > 0)WORD=BUF[N]+H1; if(state <= 0) {
BUF[N]=WORD-H1; n--; buf[n]=cksum; n++;
N++; SAVEIO(1,false,buf);
CKSUM=MOD(CKSUM*13+WORD,1000000000L); }
return; n--; *pword=buf[n]-cksum; n++;
SAVEIO(-1,state > 0,buf);
L10: STATE=OP; state=0;
SAVEIO(0,STATE > 0,BUF); break;
N=1; case 0: /* FIXME: Huh? should be impossible */
if(STATE > 0) goto L15; state=op;
HASH=MOD(WORD,1048576L); SAVEIO(0,state > 0,buf);
BUF[0]=1234L*5678L-HASH; n=1;
L13: CKSUM=BUF[0]; if(state <= 0) {
return; hash=MOD(*pword,1048576L);
buf[0]=1234L*5678L-hash;
L15: SAVEIO(1,true,BUF); }
HASH=MOD(1234L*5678L-BUF[0],1048576L); SAVEIO(1,true,buf);
goto L13; hash=MOD(1234L*5678L-buf[0],1048576L);
cksum=buf[0];
L30: if(N == 250)SAVEIO(1,STATE > 0,BUF); return;
N=MOD(N,250)+1; }
if(STATE > 0) goto L32; }
N--; BUF[N]=CKSUM; N++; if(state == 0)
SAVEIO(1,false,BUF);
L32: N--; WORD=BUF[N]-CKSUM; N++;
SAVEIO(-1,STATE > 0,BUF);
STATE=0;
return; return;
if(n == 250)
SAVEIO(1,state > 0,buf);
n=MOD(n,250)+1;
h1=MOD(hash*1093L+221573L,1048576L);
hash=MOD(h1*1093L+221573L,1048576L);
h1=MOD(h1,1234)*765432+MOD(hash,123);
n--;
if(state > 0)
*pword=buf[n]+h1;
buf[n]=*pword-h1;
n++;
cksum=MOD(cksum*13+*pword,1000000000L);
} }
#undef WORD
#define SAVWRD(OP,WORD) fSAVWRD(OP,&WORD)
/* Data structure routines */ /* Data structure routines */