- * If we're already at end of line when GETTXT is called, we return -1. */
-
- if(LNPOSN != SPLITTING)SPLITTING = -1;
- GETTXT= -1;
-L10: if(LNPOSN > LNLENG)return(GETTXT);
- if((!SKIP) || INLINE[LNPOSN] != 0) goto L11;
- LNPOSN=LNPOSN+1;
- goto L10;
-
-L11: GETTXT=0;
- /* 15 */ for (I=1; I<=5; I++) {
- GETTXT=GETTXT*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;
- GETTXT=GETTXT+CHAR;
- goto L14;
-
-L12: if(SPLITTING == LNPOSN) goto L13;
- GETTXT=GETTXT+63;
- SPLITTING = LNPOSN;
- goto L15;
-
-L13: GETTXT=GETTXT+CHAR-63;
- SPLITTING = -1;
-L14: LNPOSN=LNPOSN+1;
-L15: /*etc*/ ;
- } /* end loop */
-
- if(HASH)GETTXT=GETTXT+MOD(HASH*13579L+5432L,97531L)*12345L+HASH;
- return(GETTXT);
-}
-
-
-
-#define GETTXT(SKIP,ONEWRD,UPPER,HASH) fGETTXT(SKIP,ONEWRD,UPPER,HASH)
-#undef MAKEWD
-long fMAKEWD(long LETTRS) {
-long I, L, MAKEWD;
-
-/* Combine five uppercase letters (represented by pairs of decimal digits
- * in lettrs) to form a 30-bit value matching the one that GETTXT would
- * return given those characters plus trailing blanks and HASH=0. Caution:
- * lettrs will overflow 31 bits if 5-letter word starts with V-Z. As a
- * kludgey workaround, you can increment a letter by 5 by adding 50 to
- * the next pair of digits. */
-
-
- MAKEWD=0;
- I=1;
- L=LETTRS;
-L10: MAKEWD=MAKEWD+I*(MOD(L,50)+10);
- I=I*64;
- if(MOD(L,100) > 50)MAKEWD=MAKEWD+I*5;
- L=L/100;
- if(L != 0) goto L10;
- I=64L*64L*64L*64L*64L/I;
- MAKEWD=MAKEWD*I;
- return(MAKEWD);
-}
-
-
-
-#define MAKEWD(LETTRS) fMAKEWD(LETTRS)
-#undef PUTTXT
-#define STATE (*sTATE)
-void fPUTTXT(long WORD, long *sTATE, long CASE, long HASH) {
-long ALPH1, ALPH2, BYTE, DIV, I, W;
-
-/* Unpack the 30-bit value in word to obtain up to 5 integer-encoded chars,
- * and store them in inline starting at LNPOSN. If LNLENG>=LNPOSN, shift
- * existing characters to the right to make room. HASH must be the same
- * as it was when gettxt created the 30-bit word. STATE will be zero when
- * puttxt is called with the first of a sequence of words, but is thereafter
- * unchanged by the caller, so PUTTXT can use it to maintain state across
- * calls. LNPOSN and LNLENG are incremented by the number of chars stored.
- * If CASE=1, all letters are made uppercase; if -1, lowercase; if 0, as is.
- * any other value for case is the same as 0 but also causes trailing blanks
- * to be included (in anticipation of subsequent additional text). */
-
-
- ALPH1=13*CASE+24;
- ALPH2=26*IABS(CASE)+ALPH1;
- if(IABS(CASE) > 1)ALPH1=ALPH2;
-/* ALPH1&2 DEFINE RANGE OF WRONG-CASE CHARS, 11-36 OR 37-62 OR EMPTY. */
- DIV=64L*64L*64L*64L;
- W=WORD;
- if(HASH)W=W-MOD(HASH*13579L+5432L,97531L)*12345L-HASH;
- /* 18 */ for (I=1; I<=5; I++) {
- if(W <= 0 && STATE == 0 && IABS(CASE) <= 1)return;
- BYTE=W/DIV;
- if(STATE != 0 || BYTE != 63) goto L12;
- STATE=63;
- goto L18;
-
-L12: SHFTXT(LNPOSN,1);
- STATE=STATE+BYTE;
- if(STATE < ALPH2 && STATE >= ALPH1)STATE=STATE-26*CASE;
- INLINE[LNPOSN]=STATE;
- LNPOSN=LNPOSN+1;
- STATE=0;
-L18: W=(W-BYTE*DIV)*64;
- } /* end loop */
- return;
-}
-
-
-
-#undef STATE
-#define PUTTXT(WORD,STATE,CASE,HASH) fPUTTXT(WORD,&STATE,CASE,HASH)
-#undef SHFTXT
-void fSHFTXT(long FROM, long DELTA) {
-long I, II, JJ;
-
+ * If we're already at end of line when TEXT is called, we return -1. */
+{
+ 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;
+ }
+
+ text=0;
+ for (int I=1; I<=TOKLEN; I++) {
+ text=text*64;
+ if (LNPOSN > LNLENG || (onewrd && INLINE[LNPOSN] == 0))
+ continue;
+ char current=INLINE[LNPOSN];
+ if (current < ascii_to_advent['%']) {
+ splitting = -1;
+ if (upper && current >= ascii_to_advent['a'])
+ current=current-26;
+ text=text+current;
+ ++LNPOSN;
+ continue;
+ }
+ if (splitting != LNPOSN) {
+ text=text+ascii_to_advent['%'];
+ splitting = LNPOSN;
+ continue;
+ }
+
+ text=text+current-ascii_to_advent['%'];
+ splitting = -1;
+ ++LNPOSN;
+ }
+
+ return text;
+}
+
+token_t MAKEWD(long letters)
+/* Combine TOKLEN (currently 5) uppercase letters (represented by
+ * pairs of decimal digits in lettrs) to form a 30-bit value matching
+ * the one that GETTXT would return given those characters plus
+ * trailing blanks. Caution: lettrs will overflow 31 bits if
+ * 5-letter word starts with V-Z. As a kludgey workaround, you can
+ * increment a letter by 5 by adding 50 to the next pair of
+ * digits. */
+{
+ long i = 1, word = 0;
+
+ for (long k=letters; k != 0; k=k/100) {
+ word=word+i*(MOD(k,50)+10);
+ i=i*64;
+ if (MOD(k,100) > 50)word=word+i*5;
+ }
+ i=64L*64L*64L*64L*64L/i;
+ word=word*i;
+ return word;
+}
+
+void PUTTXT(token_t word, long *state, long casemake)
+/* Unpack the 30-bit value in word to obtain up to TOKLEN (currently
+ * 5) integer-encoded chars, and store them in inline starting at
+ * LNPOSN. If LNLENG>=LNPOSN, shift existing characters to the right
+ * to make room. STATE will be zero when puttxt is called with the
+ * first of a sequence of words, but is thereafter unchanged by the
+ * caller, so PUTTXT can use it to maintain state across calls.
+ * LNPOSN and LNLENG are incremented by the number of chars stored.
+ * If CASEMAKE=1, all letters are made uppercase; if -1, lowercase; if 0,
+ * as is. any other value for case is the same as 0 but also causes
+ * trailing blanks to be included (in anticipation of subsequent
+ * additional text). */
+{
+ long alph1, alph2, byte, div, i, w;
+
+ alph1=13*casemake+24;
+ alph2=26*labs(casemake)+alph1;
+ if (labs(casemake) > 1)
+ alph1=alph2;
+ /* alph1&2 define range of wrong-case chars, 11-36 or 37-62 or empty. */
+ div=64L*64L*64L*64L;
+ w=word;
+ for (i=1; i<=TOKLEN; i++)
+ {
+ if (w <= 0 && *state == 0 && labs(casemake) <= 1)
+ return;
+ byte=w/div;
+ w=(w-byte*div)*64;
+ if (!(*state != 0 || byte != ascii_to_advent['%'])) {
+ *state=ascii_to_advent['%'];
+ continue;
+ }
+ SHFTXT(LNPOSN,1);
+ *state=*state+byte;
+ if (*state < alph2 && *state >= alph1)*state=*state-26*casemake;
+ INLINE[LNPOSN]=*state;
+ ++LNPOSN;
+ *state=0;
+ }
+}
+#define PUTTXT(WORD,STATE,CASE) fPUTTXT(WORD,&STATE,CASE)
+
+void SHFTXT(long from, long delta)