From: Jason S. Ninneman Date: Thu, 3 Aug 2017 15:29:46 +0000 (-0700) Subject: Typedefify command_t; simplify code accordingly. X-Git-Tag: 1.4~8 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F261%2Fhead;p=open-adventure.git Typedefify command_t; simplify code accordingly. --- diff --git a/actions.c b/actions.c index dca01f5..3d03d83 100644 --- a/actions.c +++ b/actions.c @@ -6,7 +6,7 @@ static int fill(verb_t, obj_t); -static int attack(struct command_t command) +static int attack(command_t command) /* Attack. Assume target if unambiguous. "Throw" also links here. * Attackable objects fall into two categories: enemies (snake, * dwarf, etc.) and others (bird, clam, machine). Ambiguous if 2 @@ -1076,7 +1076,7 @@ static int quit(void) return GO_CLEAROBJ; } -static int read(struct command_t command) +static int read(command_t command) /* Read. Print stuff based on objtxt. Oyster (?) is special case. */ { if (command.obj == INTRANSITIVE) { @@ -1141,7 +1141,7 @@ static int rub(verb_t verb, obj_t obj) return GO_CLEAROBJ; } -static int say(struct command_t command) +static int say(command_t command) /* Say. Echo WD2. Magic words override. */ { if (command.word[1].type == MOTION && @@ -1173,7 +1173,7 @@ static int throw_support(vocab_t spk) return GO_MOVE; } -static int throw (struct command_t command) +static int throw (command_t command) /* Throw. Same as discard unless axe. Then same as attack except * ignore bird, and if dwarf is present then one might be killed. * (Only way to do so!) Axe also special for dragon, bear, and @@ -1311,7 +1311,7 @@ static int wave(verb_t verb, obj_t obj) } } -int action(struct command_t command) +int action(command_t command) /* Analyse a verb. Remember what it was, go back for object if second word * unless verb is "say", which snarfs arbitrary second word. */ diff --git a/advent.h b/advent.h index 1e7a096..f5fe672 100644 --- a/advent.h +++ b/advent.h @@ -189,17 +189,17 @@ typedef struct { word_type_t type; } command_word_t; -struct command_t { +typedef struct { enum speechpart part; command_word_t word[2]; verb_t verb; obj_t obj; -}; +} command_t; extern struct game_t game; extern struct settings_t settings; -extern bool get_command_input(struct command_t *); +extern bool get_command_input(command_t *); extern void speak(const char*, ...); extern void sspeak(int msg, ...); extern void pspeak(vocab_t, enum speaktype, int, bool, ...); @@ -224,7 +224,7 @@ extern int suspend(void); extern int resume(void); extern int restore(FILE *); extern long initialise(void); -extern int action(struct command_t command); +extern int action(command_t command); extern void state_change(obj_t, int); diff --git a/main.c b/main.c index caa328d..17a5e43 100644 --- a/main.c +++ b/main.c @@ -968,7 +968,7 @@ static void listobjects(void) static bool do_command() /* Get and execute a command */ { - static struct command_t command; + static command_t command; /* Can't leave cave once it's closing (except by main office). */ if (OUTSID(game.newloc) && game.newloc != 0 && game.closng) { @@ -1051,8 +1051,8 @@ Lclearobj: game.knfloc = 0; /* Preserve state from last command for reuse when required */ - struct command_t preserve; - memcpy(&preserve, &command, sizeof(struct command_t)); + command_t preserve; + memcpy(&preserve, &command, sizeof(command_t)); // Get command input from user if (!get_command_input(&command)) diff --git a/misc.c b/misc.c index a98ce1a..5386ff7 100644 --- a/misc.c +++ b/misc.c @@ -464,9 +464,9 @@ static void get_vocab_metadata(command_word_t* word) return; } -static void tokenize(char* raw, struct command_t *cmd) +static void tokenize(char* raw, command_t *cmd) { - memset(cmd, '\0', sizeof(struct command_t)); + memset(cmd, '\0', sizeof(command_t)); /* Bound prefix on the %s would be needed to prevent buffer * overflow. but we shortstop this more simply by making each @@ -500,7 +500,7 @@ static void tokenize(char* raw, struct command_t *cmd) get_vocab_metadata(&(cmd->word[1])); } -bool get_command_input(struct command_t *command) +bool get_command_input(command_t *command) /* Get user input on stdin, parse and map to command */ { char inputbuf[LINESIZE];