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

@ -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;

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);

19
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 */
@ -1021,8 +1021,7 @@ L2600:
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);
} }

33
misc.c
View file

@ -91,8 +91,7 @@ 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));
} }
@ -300,8 +299,7 @@ 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;
} }
@ -453,10 +451,8 @@ 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);
} }
@ -468,10 +464,8 @@ int get_motion_vocab_id(const char* word)
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);
} }
@ -483,10 +477,8 @@ int get_object_vocab_id(const char* word)
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);
} }
@ -498,10 +490,8 @@ int get_action_vocab_id(const char* word)
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);
} }
@ -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