From: Eric S. Raymond Date: Mon, 3 Jul 2017 16:52:28 +0000 (-0400) Subject: Use the raw buffer in tr command structure for editing. X-Git-Tag: takebird~67 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=a768555312f0ff1c0ddb11ae5e6212210535110c;p=open-adventure.git Use the raw buffer in tr command structure for editing. This fixes some minor bugs. Unknown words are no longer truncated nor uppercased on echo. --- diff --git a/actions.c b/actions.c index 9ddbb56..fdf2319 100644 --- a/actions.c +++ b/actions.c @@ -983,7 +983,7 @@ static int read(struct command_t command) } if (DARK(game.loc)) { - rspeak(NO_SEE, command.wd1, command.wd1x); + sspeak(NO_SEE, command.raw1); } else if (command.obj == OYSTER && !game.clshnt && game.closed) { game.clshnt = yes(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]); } else if (objects[command.obj].texts[0] == NULL || @@ -1240,7 +1240,7 @@ int action(struct command_t *command) command->verb == INVENTORY) && command->wd2 <= 0) /* FALL THROUGH */; else { - rspeak(NO_SEE, command->wd1, command->wd1x); + sspeak(NO_SEE, command->raw1); return GO_CLEAROBJ; } @@ -1437,7 +1437,7 @@ int action(struct command_t *command) } case unknown: /* Unknown verb, couldn't deduce object - might need hint */ - rspeak(WHAT_DO, command->wd1, command->wd1x); + sspeak(WHAT_DO, command->raw1); return GO_CHECKHINT; default: BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE diff --git a/advent.h b/advent.h index 8ef2f5b..560b150 100644 --- a/advent.h +++ b/advent.h @@ -199,6 +199,7 @@ extern bool wordeq(token_t, token_t); extern bool wordempty(token_t); extern void wordclear(token_t *); extern void speak(const char*, ...); +extern void sspeak(long msg, ...); extern void pspeak(vocab_t, enum speaktype, int, bool, ...); extern void rspeak(vocab_t, ...); extern void echo_input(FILE*, const char*, const char*); diff --git a/adventure.yaml b/adventure.yaml index e35373c..039f4f9 100644 --- a/adventure.yaml +++ b/adventure.yaml @@ -3116,9 +3116,9 @@ arbitrary_messages: !!omap - ONE_HIT: 'One of them gets you!' - NONE_HIT: 'None of them hits you!' - DONT_KNOW: 'Sorry, I don''t know the word "%s".' -- WHAT_DO: 'What do you want to do with the %L%L?' # FIXME: %L%L should become %L once parsing no longer depends on packed tokens -- NO_SEE: 'I see no %L%L here.' # FIXME: %L%L should become %L once parsing no longer depends on packed tokens -- DO_WHAT: '%C what?' +- WHAT_DO: 'What do you want to do with the %s?' +- NO_SEE: 'I see no %s here.' +- DO_WHAT: '%s what?' - OKEY_DOKEY: 'Okay, "%s".' - GARNERED_POINTS: 'You have garnered %d out of a possible %d points, using %d turn%S.' - SUSPEND_WARNING: |- diff --git a/main.c b/main.c index c2c4daa..7cf987a 100644 --- a/main.c +++ b/main.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "advent.h" #include "dungeon.h" @@ -1101,7 +1102,6 @@ L2607: } if (V1 == ENTER && command.wd2 > 0) { command.wd1 = command.wd2; - command.wd1x = command.wd2x; wordclear(&command.wd2); } else { /* FIXME: Magic numbers related to vocabulary */ @@ -1130,7 +1130,7 @@ Lookup: /* Gee, I don't understand. */ if (fallback_handler(inputbuf)) continue; - rspeak(DONT_KNOW, command.wd1, command.wd1x); + sspeak(DONT_KNOW, command.raw1); goto L2600; } /* FIXME: magic numbers related to vocabulary */ @@ -1174,13 +1174,15 @@ Laction: case GO_WORD2: /* Get second word for analysis. */ command.wd1 = command.wd2; - command.wd1x = command.wd2x; + strcpy(command.raw1, command.raw2); wordclear(&command.wd2); + command.raw2[0] = '\0'; goto L2620; case GO_UNKNOWN: /* Random intransitive verbs come here. Clear obj just in case * (see attack()). */ - rspeak(DO_WHAT, command.wd1, command.wd1x); + command.raw1[0] = toupper(command.raw1[0]); + sspeak(DO_WHAT, command.raw1); command.obj = 0; goto L2600; case GO_DWARFWAKE: diff --git a/misc.c b/misc.c index a38c546..c8cf9f1 100644 --- a/misc.c +++ b/misc.c @@ -127,9 +127,7 @@ void tokenize(char* raw, struct command_t *cmd) // pack the substrings cmd->wd1 = token_to_packed(chunk_data[0]); - cmd->wd1x = token_to_packed(chunk_data[1]); cmd->wd2 = token_to_packed(chunk_data[2]); - cmd->wd2x = token_to_packed(chunk_data[3]); } /* Hide the fact that wods are corrently packed longs */ @@ -149,7 +147,7 @@ void wordclear(token_t *v) *v = 0; } -/* I/O routines (speak, pspeak, rspeak, get_input, yes) */ +/* I/O routines (speak, pspeak, rspeak, sspeak, get_input, yes) */ void vspeak(const char* msg, bool blank, va_list ap) { @@ -253,6 +251,16 @@ void speak(const char* msg, ...) va_end(ap); } +void sspeak(const long msg, ...) +{ + va_list ap; + va_start(ap, msg); + fputc('\n', stdout); + vprintf(arbitrary_messages[msg], ap); + fputc('\n', stdout); + va_end(ap); +} + void pspeak(vocab_t msg, enum speaktype mode, int skip, bool blank, ...) /* Find the skip+1st message from msg and print it. Modes are: * feel = for inventory, what you can touch diff --git a/notes.adoc b/notes.adoc index be36ddc..c523cff 100644 --- a/notes.adoc +++ b/notes.adoc @@ -52,6 +52,9 @@ Bug fixes: * Attempting to extinguish an unlit urn caused it to lose its oil. +* Unrecognized words are no longer truncated to 5 characters and + uppercased when they are echoed. + By default, advent issues "> " as a command prompt. This feature became common in many variants after the original 350-point version, but was never backported into Crowther & Woods's main line before now. diff --git a/tests/illformed.chk b/tests/illformed.chk index 3996857..b6c551b 100644 --- a/tests/illformed.chk +++ b/tests/illformed.chk @@ -251,7 +251,7 @@ Nothing happens. > find bar -Sorry, I don't know the word "BAR". +Sorry, I don't know the word "bar". > carry @@ -388,7 +388,7 @@ you come to it. To get the full description, say "look". > frob grate -Sorry, I don't know the word "FROB". +Sorry, I don't know the word "frob". > read grate diff --git a/tests/lockchain.chk b/tests/lockchain.chk index ccb54cf..2c9cd4c 100644 --- a/tests/lockchain.chk +++ b/tests/lockchain.chk @@ -617,7 +617,7 @@ A formidable ogre bars the northern exit. > attack -Attac what? +Attack what? > kill ogre @@ -1606,7 +1606,7 @@ You can't carry anything more. You'll have to drop something first. > pour bottle -Bottl what? +Bottle what? > n diff --git a/tests/mazehint.chk b/tests/mazehint.chk index 02b315d..67c11d6 100644 --- a/tests/mazehint.chk +++ b/tests/mazehint.chk @@ -208,7 +208,7 @@ OK > ew -Sorry, I don't know the word "EW". +Sorry, I don't know the word "ew". > w diff --git a/tests/oldstyle.chk b/tests/oldstyle.chk index d8aa9bb..5deb6f2 100644 --- a/tests/oldstyle.chk +++ b/tests/oldstyle.chk @@ -10,19 +10,19 @@ down a gully. i -Sorry, I don't know the word "I". +Sorry, I don't know the word "i". l -Sorry, I don't know the word "L". +Sorry, I don't know the word "l". x -Sorry, I don't know the word "X". +Sorry, I don't know the word "x". z -Sorry, I don't know the word "Z". +Sorry, I don't know the word "z". quit diff --git a/tests/urntest.chk b/tests/urntest.chk index 8dec2a7..f3c8aa3 100644 --- a/tests/urntest.chk +++ b/tests/urntest.chk @@ -2021,7 +2021,7 @@ The urn is now dark. > extinguish -Extin what? +Extinguish what? > look diff --git a/tests/vending.chk b/tests/vending.chk index 001aa37..229dd89 100644 --- a/tests/vending.chk +++ b/tests/vending.chk @@ -298,7 +298,7 @@ section of wall, revealing a dark passage leading south. > attack -Attac what? +Attack what? > attack machine diff --git a/tests/woodshint.chk b/tests/woodshint.chk index 23263f0..a2104d7 100644 --- a/tests/woodshint.chk +++ b/tests/woodshint.chk @@ -162,11 +162,11 @@ Wake what? > quit nagging -Sorry, I don't know the word "NAGGI". +Sorry, I don't know the word "nagging". > nothing doing -Sorry, I don't know the word "DOING". +Sorry, I don't know the word "doing". > e