X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=misc.c;h=04792eb9c38fb3955cecaa2f1ce30ff0f65ee909;hp=365d7c88eb21ffba77f6e4f715195c6c7820d81f;hb=0f126b0cb5f8539f456f2d7f2c06d8f32c2491c2;hpb=63f53c026d42fec1ae0421e47b9c68a5ae5e8731 diff --git a/misc.c b/misc.c index 365d7c8..04792eb 100644 --- a/misc.c +++ b/misc.c @@ -257,44 +257,52 @@ L42: NUMBER=NUMBER*SIGN; } long GETTXT(long SKIP,long ONEWRD, long UPPER) { -long CHAR, TEXT, I; static long SPLITTING = -1; - /* Take characters from an input line and pack them into 30-bit words. * Skip says to skip leading blanks. ONEWRD says stop if we come to a * blank. UPPER says to map all letters to uppercase. If we reach the * end of the line, the word is filled up with blanks (which encode as 0's). * If we're already at end of line when TEXT is called, we return -1. */ - if(LNPOSN != SPLITTING)SPLITTING = -1; - TEXT= -1; -L10: if(LNPOSN > LNLENG)return(TEXT); - if((!SKIP) || INLINE[LNPOSN] != 0) goto L11; - LNPOSN=LNPOSN+1; - goto L10; - -L11: TEXT=0; - /* 15 */ for (I=1; I<=5; I++) { - TEXT=TEXT*64; - if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0)) goto L15; - CHAR=INLINE[LNPOSN]; - if(CHAR >= 63) goto L12; - SPLITTING = -1; - if(UPPER && CHAR >= 37)CHAR=CHAR-26; - TEXT=TEXT+CHAR; - goto L14; - -L12: if(SPLITTING == LNPOSN) goto L13; - TEXT=TEXT+63; - SPLITTING = LNPOSN; - goto L15; - -L13: TEXT=TEXT+CHAR-63; - SPLITTING = -1; -L14: LNPOSN=LNPOSN+1; -L15: /*etc*/ ; - } /* end loop */ - - return(TEXT); + long TEXT; + static long SPLITTING = -1; + + if(LNPOSN != SPLITTING) + SPLITTING = -1; + TEXT= -1; + while (true) { + if(LNPOSN > LNLENG) + return(TEXT); + if((!SKIP) || INLINE[LNPOSN] != 0) + break; + LNPOSN=LNPOSN+1; + } + + TEXT=0; + for (int I=1; I<=5; I++) { + TEXT=TEXT*64; + if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0)) + continue; + char current=INLINE[LNPOSN]; + if(current < 63) { + SPLITTING = -1; + if(UPPER && current >= 37) + current=current-26; + TEXT=TEXT+current; + LNPOSN=LNPOSN+1; + continue; + } + if(SPLITTING != LNPOSN) { + TEXT=TEXT+63; + SPLITTING = LNPOSN; + continue; + } + + TEXT=TEXT+current-63; + SPLITTING = -1; + LNPOSN=LNPOSN+1; + } + + return(TEXT); } long MAKEWD(long LETTRS) { @@ -631,26 +639,14 @@ L2: AT=I; /* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value, * randrange, RNDVOC, BUG) */ -long SETBIT(long BIT) { -long I, IND; - +long SETBIT(long bit) { /* Returns 2**bit for use in constructing bit-masks. */ - - IND=1; - if(BIT <= 0)return(IND); - for (I=1; I<=BIT; I++) { - IND=IND+IND; - } /* end loop */ - return(IND); + 2 << bit; } - - -long TSTBIT(long MASK, long BIT) { - +bool TSTBIT(long mask, int bit) { /* Returns true if the specified bit is set in the mask. */ - - return(MOD(MASK/SETBIT(BIT),2) != 0); + return((mask & (1 << bit)) != 0); } void set_seed(long seedval)