projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve documentation if the *most* obscure span of code.
[open-adventure.git]
/
misc.c
diff --git
a/misc.c
b/misc.c
index e7a03984b0fb96739797499247b797e49e984166..be6ec81bb49c6595fb176d098f957660223d750d 100644
(file)
--- a/
misc.c
+++ b/
misc.c
@@
-15,8
+15,11
@@
void* xmalloc(size_t size)
{
void* ptr = malloc(size);
if (ptr == NULL) {
{
void* ptr = malloc(size);
if (ptr == NULL) {
+ // LCOV_EXCL_START
+ // exclude from coverage analysis because we can't simulate an out of memory error in testing
fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
+ // LCOV_EXCL_STOP
}
return (ptr);
}
}
return (ptr);
}
@@
-41,18
+44,6
@@
void packed_to_token(long packed, char token[6])
}
}
}
}
-void token_to_packed(char token[6], long* packed)
-{
- *packed = 0;
- for (size_t i = 0; i < 5; ++i)
- {
- if (token[4 - i] == '\0')
- continue;
- char mapped = ascii_to_advent[(int) token[4 - i]];
- *packed |= (mapped << (6 * i));
- }
-}
-
/* Hide the fact that wods are corrently packed longs */
bool wordeq(token_t a, token_t b)
/* Hide the fact that wods are corrently packed longs */
bool wordeq(token_t a, token_t b)
@@
-175,7
+166,7
@@
void pspeak(vocab_t msg, enum speaktype mode, int skip, ...)
vspeak(objects[msg].inventory, ap);
break;
case look:
vspeak(objects[msg].inventory, ap);
break;
case look:
- vspeak(objects[msg].
long
s[skip], ap);
+ vspeak(objects[msg].
description
s[skip], ap);
break;
case hear:
vspeak(objects[msg].sounds[skip], ap);
break;
case hear:
vspeak(objects[msg].sounds[skip], ap);
@@
-183,6
+174,9
@@
void pspeak(vocab_t msg, enum speaktype mode, int skip, ...)
case study:
vspeak(objects[msg].texts[skip], ap);
break;
case study:
vspeak(objects[msg].texts[skip], ap);
break;
+ case change:
+ vspeak(objects[msg].changes[skip], ap);
+ break;
}
va_end(ap);
}
}
va_end(ap);
}
@@
-261,7
+255,10
@@
char* get_input()
input = NULL;
size_t n = 0;
if (isatty(0))
input = NULL;
size_t n = 0;
if (isatty(0))
+ // LCOV_EXCL_START
+ // Should be unreachable in tests, as they will use a non-interactive shell.
printf("%s", input_prompt);
printf("%s", input_prompt);
+ // LCOV_EXCL_STOP
IGNORE(getline(&input, &n, stdin));
}
IGNORE(getline(&input, &n, stdin));
}
@@
-298,10
+295,13
@@
bool yes(const char* question, const char* yes_response, const char* no_response
speak(question);
reply = get_input();
speak(question);
reply = get_input();
- if (reply == NULL) {
- linenoiseFree(reply);
- exit(EXIT_SUCCESS);
- }
+ if (reply == NULL) {
+ // LCOV_EXCL_START
+ // Should be unreachable. Reply should never be NULL
+ linenoiseFree(reply);
+ exit(EXIT_SUCCESS);
+ // LCOV_EXCL_STOP
+ }
char* firstword = (char*) xmalloc(strlen(reply)+1);
sscanf(reply, "%s", firstword);
char* firstword = (char*) xmalloc(strlen(reply)+1);
sscanf(reply, "%s", firstword);
@@
-420,7
+420,7
@@
long vocab(long id, long init)
lexeme = -1;
if (init < 0)
return (lexeme);
lexeme = -1;
if (init < 0)
return (lexeme);
- BUG(REQUIRED_VOCABULARY_WORD_NOT_FOUND);
+ BUG(REQUIRED_VOCABULARY_WORD_NOT_FOUND);
// LCOV_EXCL_LINE
}
if (init >= 0 && KTAB[i] / 1000 != init)
continue;
}
if (init >= 0 && KTAB[i] / 1000 != init)
continue;
@@
-431,7
+431,7
@@
long vocab(long id, long init)
return (lexeme);
}
}
return (lexeme);
}
}
- BUG(RAN_OFF_END_OF_VOCABULARY_TABLE);
+ BUG(RAN_OFF_END_OF_VOCABULARY_TABLE);
// LCOV_EXCL_LINE
}
void juggle(long object)
}
void juggle(long object)
@@
-538,7
+538,7
@@
long atdwrf(long where)
long setbit(long bit)
/* Returns 2**bit for use in constructing bit-masks. */
{
long setbit(long bit)
/* Returns 2**bit for use in constructing bit-masks. */
{
- return (1 << bit);
+ return (1
L
<< bit);
}
bool tstbit(long mask, int bit)
}
bool tstbit(long mask, int bit)
@@
-699,10
+699,12
@@
void datime(long* d, long* t)
*t = (long) tv.tv_usec;
}
*t = (long) tv.tv_usec;
}
+// LCOV_EXCL_START
void bug(enum bugtype num, const char *error_string)
{
fprintf(stderr, "Fatal error %d, %s.\n", num, error_string);
exit(EXIT_FAILURE);
}
void bug(enum bugtype num, const char *error_string)
{
fprintf(stderr, "Fatal error %d, %s.\n", num, error_string);
exit(EXIT_FAILURE);
}
+// LCOV_EXCL_STOP
/* end */
/* end */