Skip to content

Commit

Permalink
Merge pull request #779 from angstsmurf/plusupdate2
Browse files Browse the repository at this point in the history
Update Plus interpreter
  • Loading branch information
cspiegel committed May 5, 2023
2 parents cc2687b + 046fd13 commit 37e70f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 4 additions & 0 deletions terps/plus/extracommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static void TranscriptOn(void)
glk_put_string_stream(glk_window_get_stream(Bottom),
(char *)sys[TRANSCRIPT_ON]);

glk_window_set_echo_stream(Bottom, Transcript);

Look(1);
}

Expand All @@ -85,6 +87,8 @@ static void TranscriptOff(void)

glk_put_string_stream(Transcript, (char *)sys[TRANSCRIPT_END]);

glk_window_set_echo_stream(Bottom, NULL);

glk_stream_close(Transcript, NULL);
Transcript = NULL;
SystemMessage(TRANSCRIPT_OFF);
Expand Down
5 changes: 0 additions & 5 deletions terps/plus/parseinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,6 @@ static void LineInput(void)
int length = ev.val1;
buf[length] = 0;

if (Transcript) {
glk_put_string_stream(Transcript, buf);
glk_put_string_stream(Transcript, "\n");
}

char *result = StripPunctuation(buf, &length);
debug_print("After stripping punctuation: \"%s\"\n", result);
result = ReplaceSynonyms(result, &length);
Expand Down
25 changes: 15 additions & 10 deletions terps/plus/plusmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ void Display(winid_t w, const char *fmt, ...)
va_end(ap);

glk_put_string_stream(glk_window_get_stream(w), msg);
if (Transcript && w == Bottom)
glk_put_string_stream(Transcript, msg);
}

static const glui32 OptimalPictureSize(glui32 *width, glui32 *height)
Expand Down Expand Up @@ -1407,7 +1405,12 @@ void SetCountersFromInput(void) {

static ActionResultType PerformLine(int ct)
{
debug_print("\nPerforming line %d: ", ct);
debug_print("\nPerforming line %d: (", ct);
if (Actions[ct].Verb) {
debug_print("%s %s) ", Verbs[GetAnyDictWord(Actions[ct].Verb, Verbs)].Word, Nouns[GetAnyDictWord(Actions[ct].NounOrChance, Nouns)].Word);
} else {
debug_print("0, %d) ", Actions[ct].NounOrChance);
}
int continuation = 0, dead = 0, done = 0;
int loop = 0;

Expand Down Expand Up @@ -1836,6 +1839,7 @@ static ActionResultType PerformLine(int ct)
case 120:
debug_print("counter 48: verb, counter 49: noun, counter 50: preposition, counter 51: adverb, counter 52: participle, counter 53: noun 2\n");
SetCountersFromInput();
break;
case 121:
debug_print("Set input words to counters 48 to 53\n");
CurrentVerb = VerbCounter;
Expand Down Expand Up @@ -1924,41 +1928,42 @@ static int IsExtraWordMatch(int ct)
int matchedpartp = 0;
int matchedadverb = 0;

debug_print("Action %d has %d extra words\n", ct, Actions[ct].NumWords);
debug_print("Action %d (%s %s) has %d extra words\n", ct, Verbs[GetAnyDictWord(Actions[ct].Verb, Verbs)].Word, Nouns[GetAnyDictWord(Actions[ct].NounOrChance, Nouns)].Word, Actions[ct].NumWords);

for (int i = 0; i < Actions[ct].NumWords; i++) {
uint8_t word = Actions[ct].Words[i];
debug_print("Extra word %d: %d ", i, word);
uint8_t wordval = word & 63;
switch (word >> 6) {
case 1: /* adverb */
debug_print("(adverb)\n");
debug_print("(adverb \"%s\")\n", Adverbs[GetAnyDictWord(wordval, Adverbs)].Word);
foundadverb = 1;
if (wordval == CurrentAdverb || wordval == 0 || (wordval == 1 && CurrentAdverb == 0))
matchedadverb = 1;
debug_print("Matched adverb %d (%s)\n", wordval, Prepositions[GetAnyDictWord(wordval, Adverbs)].Word);
debug_print("Matched adverb %d\n", wordval);
break;
case 2: /* participle */
debug_print("(participle)\n");
debug_print("(participle \"%s\")\n", Prepositions[GetAnyDictWord(wordval, Prepositions)].Word);
i++;
foundpartp = 1;
uint8_t n2 = Actions[ct].Words[i];
debug_print("(object (word %d) \"%s\")\n", i, Nouns[GetAnyDictWord(n2, Nouns)].Word);
if (CurrentPartp == 0 && wordval > 1 && !IsNextParticiple(wordval, n2)) {
break;
}
if (wordval == CurrentPartp || wordval == 0 || (wordval == 1 && CurrentPartp == 0)) { /* 1 means NONE */
debug_print("Matched participle %d (%s)\n", wordval, Prepositions[GetAnyDictWord(wordval, Prepositions)].Word);
debug_print("Matched participle %d\n", wordval);
if (n2 == CurrentNoun2 || n2 == 0) {
debug_print("Matched object %d (%s)\n", n2, Nouns[GetDictWord(n2)].Word);
matchedpartp = 1;
}
}
break;
case 3: /* preposition */
debug_print("(preposition)\n");
debug_print("(preposition \"%s\")\n", Prepositions[GetAnyDictWord(wordval, Prepositions)].Word);
foundprep = 1;
if (CurrentPrep == wordval || wordval == 0 || (wordval == 1 && CurrentPrep == 0)) {
debug_print("Matched preposition %d (%s)\n", wordval, Prepositions[GetAnyDictWord(wordval, Prepositions)].Word);
debug_print("Matched preposition %d\n", wordval);
matchedprep = 1;
}
break;
Expand Down

0 comments on commit 37e70f5

Please sign in to comment.