Unshadowed k2 into k3 in main.c

Reindented everything
This commit is contained in:
NHOrus 2017-06-29 20:11:53 +03:00
parent 5f44fccf4d
commit bf2fa227f0
7 changed files with 323 additions and 342 deletions

View file

@ -51,7 +51,7 @@ static int attack(struct command_t *command)
spk = BIRD_DEAD; spk = BIRD_DEAD;
} else if (obj == VEND) { } else if (obj == VEND) {
state_change(VEND, state_change(VEND,
game.prop[VEND]==VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS); game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
return GO_CLEAROBJ; return GO_CLEAROBJ;
} }
@ -85,13 +85,10 @@ static int attack(struct command_t *command)
* fixed), move rug there (not fixed), and move him there, * fixed), move rug there (not fixed), and move him there,
* too. Then do a null motion to get new description. */ * too. Then do a null motion to get new description. */
rspeak(BARE_HANDS_QUERY); rspeak(BARE_HANDS_QUERY);
if(silent_yes()) if (silent_yes()) {
{
// FIXME: setting wd1 is a workaround for broken logic // FIXME: setting wd1 is a workaround for broken logic
command->wd1 = token_to_packed("Y"); command->wd1 = token_to_packed("Y");
} } else {
else
{
// FIXME: setting wd1 is a workaround for broken logic // FIXME: setting wd1 is a workaround for broken logic
command->wd1 = token_to_packed("N"); command->wd1 = token_to_packed("N");
return GO_CHECKFOO; return GO_CHECKFOO;
@ -1213,7 +1210,7 @@ int action(struct command_t *command)
case RUB: case RUB:
return rub(command->verb, command->obj); return rub(command->verb, command->obj);
case THROW: case THROW:
return throw(command); return throw (command);
case QUIT: { case QUIT: {
rspeak(spk); rspeak(spk);
return GO_CLEAROBJ; return GO_CLEAROBJ;

View file

@ -59,8 +59,7 @@ int main(int argc, char *argv[])
} }
} }
if (savefilename == NULL) if (savefilename == NULL) {
{
fprintf(stderr, fprintf(stderr,
usage, argv[0]); usage, argv[0]);
fprintf(stderr, fprintf(stderr,
@ -90,8 +89,7 @@ int main(int argc, char *argv[])
game.saved = saved; game.saved = saved;
fp = fopen(savefilename, WRITE_MODE); fp = fopen(savefilename, WRITE_MODE);
if (fp == NULL) if (fp == NULL) {
{
fprintf(stderr, fprintf(stderr,
"Can't open file %s. Exiting.\n", savefilename); "Can't open file %s. Exiting.\n", savefilename);
exit(-1); exit(-1);

23
main.c
View file

@ -634,14 +634,14 @@ static bool playermove(token_t verb, int motion)
/* We arrive here on conditional failure. /* We arrive here on conditional failure.
* Skip to next non-matching destination */ * Skip to next non-matching destination */
long k2 = kk; long k3 = kk;
do { do {
if (travel[k2].stop) if (travel[k3].stop)
BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
++k2; ++k3;
} while } while
(T_HIGH(travel[kk]) == T_HIGH(travel[k2])); (T_HIGH(travel[kk]) == T_HIGH(travel[k3]));
kk = k2; kk = k3;
} }
/* Found an eligible rule, now execute it */ /* Found an eligible rule, now execute it */
@ -696,7 +696,7 @@ static bool playermove(token_t verb, int motion)
* entries check for game.prop(TROLL)=0.) Special * entries check for game.prop(TROLL)=0.) Special
* stuff for bear. */ * stuff for bear. */
if (game.prop[TROLL] == 1) { if (game.prop[TROLL] == 1) {
pspeak(TROLL,look, 1); pspeak(TROLL, look, 1);
game.prop[TROLL] = 0; game.prop[TROLL] = 0;
move(TROLL2, 0); move(TROLL2, 0);
move(TROLL2 + NOBJECTS, 0); move(TROLL2 + NOBJECTS, 0);
@ -1020,9 +1020,8 @@ L2600:
for (;;) { for (;;) {
input = get_input(); input = get_input();
if (input == NULL) if (input == NULL)
return(false); return (false);
if (word_count(input) > 2) if (word_count(input) > 2) {
{
rspeak(TWO_WORDS); rspeak(TWO_WORDS);
continue; continue;
} }
@ -1045,10 +1044,8 @@ L2607:
/* If a turn threshold has been met, apply penalties and tell /* If a turn threshold has been met, apply penalties and tell
* the player about it. */ * the player about it. */
for (int i = 0; i < NTHRESHOLDS; ++i) for (int i = 0; i < NTHRESHOLDS; ++i) {
{ if (game.turns == turn_thresholds[i].threshold + 1) {
if (game.turns == turn_thresholds[i].threshold + 1)
{
game.trnluz += turn_thresholds[i].point_loss; game.trnluz += turn_thresholds[i].point_loss;
speak(turn_thresholds[i].message); speak(turn_thresholds[i].message);
} }

75
misc.c
View file

@ -51,7 +51,7 @@ char* xstrdup(const char* s)
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return(ptr); return (ptr);
} }
void* xmalloc(size_t size) void* xmalloc(size_t size)
@ -91,12 +91,11 @@ long token_to_packed(const char token[6])
{ {
size_t t_len = strlen(token); size_t t_len = strlen(token);
long packed = 0; long packed = 0;
for (size_t i = 0; i < t_len; ++i) for (size_t i = 0; i < t_len; ++i) {
{
char mapped = new_ascii_to_advent[(int) token[i]]; char mapped = new_ascii_to_advent[(int) token[i]];
packed |= (mapped << (6 * i)); packed |= (mapped << (6 * i));
} }
return(packed); return (packed);
} }
void tokenize(char* raw, long tokens[4]) void tokenize(char* raw, long tokens[4])
@ -300,13 +299,12 @@ int word_count(char* s)
char* word; char* word;
word = strtok(copy, delims); word = strtok(copy, delims);
while(word != NULL) while (word != NULL) {
{
word = strtok(NULL, delims); word = strtok(NULL, delims);
++count; ++count;
} }
free(copy); free(copy);
return(count); return (count);
} }
char* get_input() char* get_input()
@ -334,11 +332,11 @@ char* get_input()
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
ssize_t numread = getline(&input, &n, stdin); ssize_t numread = getline(&input, &n, stdin);
if (numread == -1) // Got EOF; return with it. if (numread == -1) // Got EOF; return with it.
return(NULL); return (NULL);
} }
if (input == NULL) // Got EOF; return with it. if (input == NULL) // Got EOF; return with it.
return(input); return (input);
else if (input[0] == '#') // Ignore comments. else if (input[0] == '#') // Ignore comments.
continue; continue;
else // We have a 'normal' line; leave the loop. else // We have a 'normal' line; leave the loop.
@ -374,7 +372,7 @@ bool silent_yes()
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }
char* firstword = (char*) xmalloc(strlen(reply)+1); char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword); sscanf(reply, "%s", firstword);
for (int i = 0; i < (int)strlen(firstword); ++i) for (int i = 0; i < (int)strlen(firstword); ++i)
@ -420,7 +418,7 @@ bool yes(const char* question, const char* yes_response, const char* no_response
// LCOV_EXCL_STOP // LCOV_EXCL_STOP
} }
char* firstword = (char*) xmalloc(strlen(reply)+1); char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword); sscanf(reply, "%s", firstword);
for (int i = 0; i < (int)strlen(firstword); ++i) for (int i = 0; i < (int)strlen(firstword); ++i)
@ -453,61 +451,53 @@ bool yes(const char* question, const char* yes_response, const char* no_response
int get_motion_vocab_id(const char* word) int get_motion_vocab_id(const char* word)
// Return the first motion number that has 'word' as one of its words. // Return the first motion number that has 'word' as one of its words.
{ {
for (int i = 0; i < NMOTIONS; ++i) for (int i = 0; i < NMOTIONS; ++i) {
{ for (int j = 0; j < motions[i].words.n; ++j) {
for (int j = 0; j < motions[i].words.n; ++j)
{
if (strcasecmp(word, motions[i].words.strs[j]) == 0) if (strcasecmp(word, motions[i].words.strs[j]) == 0)
return(i); return (i);
} }
} }
// If execution reaches here, we didn't find the word. // If execution reaches here, we didn't find the word.
return(WORD_NOT_FOUND); return (WORD_NOT_FOUND);
} }
int get_object_vocab_id(const char* word) int get_object_vocab_id(const char* word)
// Return the first object number that has 'word' as one of its words. // Return the first object number that has 'word' as one of its words.
{ {
for (int i = 0; i < NOBJECTS + 1; ++i) // FIXME: the + 1 should go when 1-indexing for objects is removed for (int i = 0; i < NOBJECTS + 1; ++i) { // FIXME: the + 1 should go when 1-indexing for objects is removed
{ for (int j = 0; j < objects[i].words.n; ++j) {
for (int j = 0; j < objects[i].words.n; ++j)
{
if (strcasecmp(word, objects[i].words.strs[j]) == 0) if (strcasecmp(word, objects[i].words.strs[j]) == 0)
return(i); return (i);
} }
} }
// If execution reaches here, we didn't find the word. // If execution reaches here, we didn't find the word.
return(WORD_NOT_FOUND); return (WORD_NOT_FOUND);
} }
int get_action_vocab_id(const char* word) int get_action_vocab_id(const char* word)
// Return the first motion number that has 'word' as one of its words. // Return the first motion number that has 'word' as one of its words.
{ {
for (int i = 0; i < NACTIONS; ++i) for (int i = 0; i < NACTIONS; ++i) {
{ for (int j = 0; j < actions[i].words.n; ++j) {
for (int j = 0; j < actions[i].words.n; ++j)
{
if (strcasecmp(word, actions[i].words.strs[j]) == 0) if (strcasecmp(word, actions[i].words.strs[j]) == 0)
return(i); return (i);
} }
} }
// If execution reaches here, we didn't find the word. // If execution reaches here, we didn't find the word.
return(WORD_NOT_FOUND); return (WORD_NOT_FOUND);
} }
int get_special_vocab_id(const char* word) int get_special_vocab_id(const char* word)
// Return the first special number that has 'word' as one of its words. // Return the first special number that has 'word' as one of its words.
{ {
for (int i = 0; i < NSPECIALS; ++i) for (int i = 0; i < NSPECIALS; ++i) {
{ for (int j = 0; j < specials[i].words.n; ++j) {
for (int j = 0; j < specials[i].words.n; ++j)
{
if (strcasecmp(word, specials[i].words.strs[j]) == 0) if (strcasecmp(word, specials[i].words.strs[j]) == 0)
return(i); return (i);
} }
} }
// If execution reaches here, we didn't find the word. // If execution reaches here, we didn't find the word.
return(WORD_NOT_FOUND); return (WORD_NOT_FOUND);
} }
long get_vocab_id(const char* word) long get_vocab_id(const char* word)
@ -517,25 +507,25 @@ long get_vocab_id(const char* word)
ref_num = get_motion_vocab_id(word); ref_num = get_motion_vocab_id(word);
if (ref_num != WORD_NOT_FOUND) if (ref_num != WORD_NOT_FOUND)
return(ref_num + 0); // FIXME: replace with a proper hash return (ref_num + 0); // FIXME: replace with a proper hash
ref_num = get_object_vocab_id(word); ref_num = get_object_vocab_id(word);
if (ref_num != WORD_NOT_FOUND) if (ref_num != WORD_NOT_FOUND)
return(ref_num + 1000); // FIXME: replace with a proper hash return (ref_num + 1000); // FIXME: replace with a proper hash
ref_num = get_action_vocab_id(word); ref_num = get_action_vocab_id(word);
if (ref_num != WORD_NOT_FOUND) if (ref_num != WORD_NOT_FOUND)
return(ref_num + 2000); // FIXME: replace with a proper hash return (ref_num + 2000); // FIXME: replace with a proper hash
ref_num = get_special_vocab_id(word); ref_num = get_special_vocab_id(word);
if (ref_num != WORD_NOT_FOUND) if (ref_num != WORD_NOT_FOUND)
return(ref_num + 3000); // FIXME: replace with a proper hash return (ref_num + 3000); // FIXME: replace with a proper hash
// Check for the reservoir magic word. // Check for the reservoir magic word.
if (strcasecmp(word, game.zzword) == 0) if (strcasecmp(word, game.zzword) == 0)
return(PART + 2000); // FIXME: replace with a proper hash return (PART + 2000); // FIXME: replace with a proper hash
return(WORD_NOT_FOUND); return (WORD_NOT_FOUND);
} }
void juggle(long object) void juggle(long object)
@ -673,8 +663,7 @@ long randrange(long range)
void make_zzword(char zzword[6]) void make_zzword(char zzword[6])
{ {
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i) {
{
zzword[i] = 'A' + randrange(26); zzword[i] = 'A' + randrange(26);
} }
zzword[1] = '\''; // force second char to apostrophe zzword[1] = '\''; // force second char to apostrophe

View file

@ -27,7 +27,7 @@ struct save_t {
struct save_t save; struct save_t save;
int savefile(FILE *fp, long version) int savefile(FILE *fp, long version)
/* Save game to file. No input or output from user. */ /* Save game to file. No input or output from user. */
{ {
long i, k; long i, k;
datime(&i, &k); datime(&i, &k);
@ -39,7 +39,7 @@ int savefile(FILE *fp, long version)
memcpy(&save.game, &game, sizeof(struct game_t)); memcpy(&save.game, &game, sizeof(struct game_t));
IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp)); IGNORE(fwrite(&save, sizeof(struct save_t), 1, fp));
return(0); return (0);
} }
/* Suspend and resume */ /* Suspend and resume */