diff --git a/docopt_c.py b/docopt_c.py index 38bdbbc..40328ed 100755 --- a/docopt_c.py +++ b/docopt_c.py @@ -49,7 +49,10 @@ #include -#else +#elif !defined(_STDBOOL_H) +#define _STDBOOL_H + +#include #ifdef true #undef true @@ -62,8 +65,8 @@ #endif #define true 1 -#define false !true -typedef int bool; +#define false (!true) +typedef size_t bool; #endif @@ -389,7 +392,6 @@ usage_pattern, $help_message }; - struct Tokens ts; struct Command commands[] = {$elems_cmds }; struct Argument arguments[] = {$elems_args @@ -412,9 +414,11 @@ return_code = EXIT_FAILURE; } - ts = tokens_new(argc, argv); - if (parse_args(&ts, &elements)) - exit(EXIT_FAILURE); + { + struct Tokens ts = tokens_new(argc, argv); + if (parse_args(&ts, &elements)) + exit(EXIT_FAILURE); + } if (elems_to_args(&elements, &args, help, version)) exit(return_code); return args; diff --git a/test/docopt.c b/test/docopt.c index f0c2e59..481d92a 100644 --- a/test/docopt.c +++ b/test/docopt.c @@ -324,7 +324,6 @@ struct DocoptArgs docopt(int argc, char *argv[], const bool help, const char *ve " --drifting Drifting mine.", ""} }; - struct Tokens ts; struct Command commands[] = { {"create", 0}, {"mine", 0}, @@ -362,9 +361,11 @@ struct DocoptArgs docopt(int argc, char *argv[], const bool help, const char *ve return_code = EXIT_FAILURE; } - ts = tokens_new(argc, argv); - if (parse_args(&ts, &elements)) - exit(EXIT_FAILURE); + { + struct Tokens ts = tokens_new(argc, argv); + if (parse_args(&ts, &elements)) + exit(EXIT_FAILURE); + } if (elems_to_args(&elements, &args, help, version)) exit(return_code); return args; diff --git a/test/docopt.h b/test/docopt.h index 6f9c4a5..11cf17b 100644 --- a/test/docopt.h +++ b/test/docopt.h @@ -7,7 +7,10 @@ #include -#else +#elif !defined(_STDBOOL_H) +#define _STDBOOL_H + +#include #ifdef true #undef true @@ -20,8 +23,8 @@ #endif #define true 1 -#define false !true -typedef int bool; +#define false (!true) +typedef size_t bool; #endif @@ -55,8 +58,7 @@ typedef int bool; #endif -#elif (defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) \ - || defined(__DragonFly__) || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) +#elif (defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) #include