Replace some magic numbers.
This commit is contained in:
parent
eba8015059
commit
87d10f0487
3 changed files with 5 additions and 6 deletions
1
advent.h
1
advent.h
|
@ -65,6 +65,7 @@
|
|||
#define SPECIAL_WORD(n) ((n) + 3000)
|
||||
#define PROMOTE_WORD(n) ((n) + 1000)
|
||||
#define DEMOTE_WORD(n) ((n) - 1000)
|
||||
#define DIM(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
enum bugtype {
|
||||
SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST,
|
||||
|
|
2
main.c
2
main.c
|
@ -23,8 +23,6 @@
|
|||
#include "advent.h"
|
||||
#include "dungeon.h"
|
||||
|
||||
#define DIM(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
// LCOV_EXCL_START
|
||||
// exclude from coverage analysis because it requires interactivity to test
|
||||
static void sig_handler(int signo)
|
||||
|
|
8
misc.c
8
misc.c
|
@ -50,7 +50,7 @@ void packed_to_token(long packed, char token[TOKLEN+1])
|
|||
};
|
||||
|
||||
// Unpack and map back to ASCII.
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
for (int i = 0; i < TOKLEN; ++i) {
|
||||
char advent = (packed >> i * 6) & 63;
|
||||
token[i] = advent_to_ascii[(int) advent];
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ void packed_to_token(long packed, char token[TOKLEN+1])
|
|||
token[5] = '\0';
|
||||
|
||||
// Replace trailing whitespace with \0.
|
||||
for (int i = 4; i >= 0; --i) {
|
||||
for (int i = TOKLEN - 1; i >= 0; --i) {
|
||||
if (token[i] == ' ' ||
|
||||
token[i] == '\t')
|
||||
token[i] = '\0';
|
||||
|
@ -128,12 +128,12 @@ void tokenize(char* raw, long tokens[4])
|
|||
free(words[1]);
|
||||
|
||||
// uppercase all the substrings
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < DIM(chunk_data); ++i)
|
||||
for (unsigned int j = 0; j < strlen(chunk_data[i]); ++j)
|
||||
chunk_data[i][j] = (char) toupper(chunk_data[i][j]);
|
||||
|
||||
// pack the substrings
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (size_t i = 0; i < DIM(chunk_data); ++i)
|
||||
tokens[i] = token_to_packed(chunk_data[i]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue