aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@xglobe.in>2020-04-03 15:25:43 +0200
committerOmar Polo <op@xglobe.in>2020-04-03 15:25:43 +0200
commit7f40f3f51cc79bec922438a9fdfd147dac32d08d (patch)
tree38884e34d5ebf9654d6c641eb8de51845f8e0606
parentcc9bbf6125fec1aaa9a7a1a06574a537fc3c3b29 (diff)
downloadtext-adventure-7f40f3f51cc79bec922438a9fdfd147dac32d08d.tar.gz
text-adventure-7f40f3f51cc79bec922438a9fdfd147dac32d08d.tar.bz2
clang-format the code
-rw-r--r--adventure.c4
-rw-r--r--inventory.c6
-rw-r--r--io.c6
-rw-r--r--match.c32
-rw-r--r--misc.c47
-rw-r--r--parseexec.c70
-rw-r--r--toggle.c3
7 files changed, 93 insertions, 75 deletions
diff --git a/adventure.c b/adventure.c
index dd9c4e7..1e0cc5b 100644
--- a/adventure.c
+++ b/adventure.c
@@ -1,9 +1,9 @@
+#include "adventure.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "adventure.h"
-
int
main()
{
diff --git a/inventory.c b/inventory.c
index 77a11f7..ca1f2ed 100644
--- a/inventory.c
+++ b/inventory.c
@@ -14,7 +14,8 @@ move_object(struct param *par, struct object *from, struct object *to)
else if (to == NULL)
printf("There is nobody here to give that to.\n");
else if (obj == to)
- printf("What's the meaning of putting a %s inside itself?\n", obj->tags[0]);
+ printf("What's the meaning of putting a %s inside itself?\n",
+ obj->tags[0]);
else if (from != obj->location) {
/* give the appropriate error message */
switch (dist) {
@@ -36,8 +37,7 @@ move_object(struct param *par, struct object *from, struct object *to)
printf("You have no %s.\n", par->tag);
else
printf("Sorry, %s has no %s.\n",
- from->description,
- par->tag);
+ from->description, par->tag);
break;
case dist_held_contained:
diff --git a/io.c b/io.c
index f66b92f..462d559 100644
--- a/io.c
+++ b/io.c
@@ -1,10 +1,9 @@
#include "adventure.h"
/* this in only needed for readline */
-#include <stdio.h>
-
-#include <readline/readline.h>
#include <readline/history.h>
+#include <readline/readline.h>
+#include <stdio.h>
char *line = NULL;
@@ -16,4 +15,3 @@ getinput()
add_history(line);
return line != NULL;
}
-
diff --git a/match.c b/match.c
index 0da6cc6..8f5a24b 100644
--- a/match.c
+++ b/match.c
@@ -1,8 +1,8 @@
-#include "adventure.h"
-
#include <ctype.h>
#include <string.h>
+#include "adventure.h"
+
struct param params[MAX_PARAMS];
static const char *
@@ -24,9 +24,7 @@ match_terminal(const char *src, char terminal)
{
return terminal == ' '
? match_spaces(src)
- : tolower(*src) == tolower(terminal)
- ? src + 1
- : NULL;
+ : tolower(*src) == tolower(terminal) ? src + 1 : NULL;
}
static const char *
@@ -55,16 +53,20 @@ match_param(const char *src, struct param *par, int loose)
const char *rest_of_src = loose ? src + strlen(src) : NULL;
par->tag = src;
- par->distance = *src == '\0' ? dist_no_obj_specified : dist_unknown_obj;
+ par->distance
+ = *src == '\0' ? dist_no_obj_specified : dist_unknown_obj;
- foreach_obj (obj) {
+ foreach_obj(obj)
+ {
const char **tag;
enum distance dist = distance_to(obj);
for (tag = obj->tags; *tag != NULL; ++tag) {
const char *behind_match = match_tag(src, *tag);
- if (behind_match != NULL &&
- compare_with_param(*tag, dist, par) > 0 &&
- (!loose || *skip_spaces(behind_match) == '\0')) {
+ if (behind_match != NULL
+ && compare_with_param(*tag, dist, par) > 0
+ && (!loose
+ || *skip_spaces(behind_match)
+ == '\0')) {
par->tag = *tag;
par->object = obj;
par->distance = dist;
@@ -90,13 +92,13 @@ match_command(const char *src, const char *pattern)
}
/* actual parsing */
- for (src = skip_spaces(src); src != NULL && *pattern != '\0'; ++pattern) {
+ for (src = skip_spaces(src); src != NULL && *pattern != '\0';
+ ++pattern) {
src = isupper(*pattern)
? match_param(src, param_by_letter(*pattern),
- pattern[1] == '?')
- : *pattern == '?'
- ? src
- : match_terminal(src, *pattern);
+ pattern[1] == '?')
+ : *pattern == '?' ? src
+ : match_terminal(src, *pattern);
}
return src != NULL && *skip_spaces(src) == '\0';
diff --git a/misc.c b/misc.c
index e00c378..91af591 100644
--- a/misc.c
+++ b/misc.c
@@ -9,7 +9,8 @@ list_objs_at_loc(struct object *location)
size_t count = 0;
struct object *obj;
- foreach_obj (obj) {
+ foreach_obj(obj)
+ {
if (obj != player && obj->location == location) {
if (count++ == 0)
printf("%s:\n", location->contents);
@@ -25,7 +26,8 @@ person_here(void)
{
struct object *obj;
- foreach_obj (obj) {
+ foreach_obj(obj)
+ {
if (distance_to(obj) == dist_here && obj->health > 0)
return obj;
}
@@ -38,9 +40,10 @@ get_passage_to(struct object *target)
{
struct object *obj;
- foreach_obj (obj) {
- if (obj->location == player->location &&
- obj->prospect == target)
+ foreach_obj(obj)
+ {
+ if (obj->location == player->location
+ && obj->prospect == target)
return obj;
}
@@ -50,17 +53,26 @@ get_passage_to(struct object *target)
enum distance
distance_to(struct object *obj)
{
- return
- !valid_obj(obj) ? dist_unknown_obj :
- obj == player ? dist_player :
- obj == player->location ? dist_location :
- obj->location == player ? dist_held :
- obj->location == player->location ? dist_here :
- get_passage_to(obj) != NULL ? dist_overthere :
- !valid_obj(obj->location) ? dist_not_here :
- obj->location->location == player ? dist_held_contained :
- obj->location->location == player->location ? dist_here_contained :
- dist_not_here;
+ return !valid_obj(obj) ? dist_unknown_obj
+ : obj == player
+ ? dist_player
+ : obj == player->location ? dist_location
+ : obj->location == player
+ ? dist_held
+ : obj->location == player->location
+ ? dist_here
+ : get_passage_to(obj) != NULL
+ ? dist_overthere
+ : !valid_obj(
+ obj->location)
+ ? dist_not_here
+ : obj->location->location
+ == player
+ ? dist_held_contained
+ : obj->location->location
+ == player->location
+ ? dist_here_contained
+ : dist_not_here;
}
void
@@ -80,7 +92,8 @@ weight_of_contents(struct object *container)
int sum = 0;
struct object *obj;
- foreach_obj (obj) {
+ foreach_obj(obj)
+ {
if (obj->location == container)
sum += obj->weight;
}
diff --git a/parseexec.c b/parseexec.c
index a85a81d..7024675 100644
--- a/parseexec.c
+++ b/parseexec.c
@@ -1,7 +1,7 @@
-#include "adventure.h"
-
#include <stdio.h>
+#include "adventure.h"
+
int
exec_quit(void)
{
@@ -38,7 +38,8 @@ exec_look(void)
else if (dist == dist_not_here)
printf("You don't see any %s here.\n", par->tag);
else if (dist == dist_overthere)
- printf("You squeeze your eyes, but %s is too far away.\n", par->tag);
+ printf("You squeeze your eyes, but %s is too far away.\n",
+ par->tag);
else if (dist == dist_here_contained)
printf("Hard to see, try to get it first.\n");
else {
@@ -75,7 +76,8 @@ exec_go(void)
int
exec_get_from(void)
{
- return move_object(param_by_letter('A'), param_by_letter('B')->object, player);
+ return move_object(
+ param_by_letter('A'), param_by_letter('B')->object, player);
}
int
@@ -105,7 +107,8 @@ exec_ask(void)
int
exec_put_in(void)
{
- return move_object(param_by_letter('A'), player, param_by_letter('B')->object);
+ return move_object(
+ param_by_letter('A'), player, param_by_letter('B')->object);
}
int
@@ -156,34 +159,35 @@ int
parseexec(const char *input)
{
static const struct command commands[] = {
- {&exec_quit, "quit"},
- {&exec_look_around, "look"},
- {&exec_look_around, "look around"},
- {&exec_look, "look at A?"},
- {&exec_look, "look A?"},
- {&exec_go, "go to the A?"},
- {&exec_go, "go to A?"},
- {&exec_go, "go A?"},
- {&exec_get_from, "get A from B?"},
- {&exec_get, "get the A?"},
- {&exec_get, "get A?"},
- {&exec_get, "pick up the A?"},
- {&exec_get, "pick up a A?"},
- {&exec_get, "pick up A?"},
- {&exec_get, "pick the A?"},
- {&exec_get, "pick a A?"},
- {&exec_get, "pick A?"},
- {&exec_put_in, "put A in B?"},
- {&exec_put_in, "drop A in B?"},
- {&exec_drop, "drop A?"},
- {&exec_give, "give A?"},
- {&exec_ask, "ask A?"},
- {&exec_inventory, "inventory"},
- {&exec_open, "open A?"},
- {&exec_close, "close A?"},
- {&exec_lock, "lock A?"},
- {&exec_unlock, "unlock A?"},
- {&exec_no_match, "A?"},
+ { &exec_quit, "quit" },
+ { &exec_quit, "bye" },
+ { &exec_look_around, "look" },
+ { &exec_look_around, "look around" },
+ { &exec_look, "look at A?" },
+ { &exec_look, "look A?" },
+ { &exec_go, "go to the A?" },
+ { &exec_go, "go to A?" },
+ { &exec_go, "go A?" },
+ { &exec_get_from, "get A from B?" },
+ { &exec_get, "get the A?" },
+ { &exec_get, "get A?" },
+ { &exec_get, "pick up the A?" },
+ { &exec_get, "pick up a A?" },
+ { &exec_get, "pick up A?" },
+ { &exec_get, "pick the A?" },
+ { &exec_get, "pick a A?" },
+ { &exec_get, "pick A?" },
+ { &exec_put_in, "put A in B?" },
+ { &exec_put_in, "drop A in B?" },
+ { &exec_drop, "drop A?" },
+ { &exec_give, "give A?" },
+ { &exec_ask, "ask A?" },
+ { &exec_inventory, "inventory" },
+ { &exec_open, "open A?" },
+ { &exec_close, "close A?" },
+ { &exec_lock, "lock A?" },
+ { &exec_unlock, "unlock A?" },
+ { &exec_no_match, "A?" },
};
const struct command *cmd;
diff --git a/toggle.c b/toggle.c
index b058a86..3c0a6f3 100644
--- a/toggle.c
+++ b/toggle.c
@@ -97,6 +97,7 @@ toggle_box_lock(struct object *o)
swap_locations(closed_box, locked_box);
return "OK.";
} else {
- return "You try really hard, but the closed box won't open without a key.";
+ return "You try really hard, but the closed box won't open "
+ "without a key.";
}
}