diff options
author | Christian Pointner <equinox@anylike.org> | 2009-12-25 08:10:57 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anylike.org> | 2009-12-25 08:10:57 +0000 |
commit | 8b567ddebb5c4d7e059883249663b7c48fc44480 (patch) | |
tree | 331f938be476f338fa3e18da42c5e46b5f77bc97 /src/anylike.c | |
parent | added main files (diff) |
added options parser
Diffstat (limited to 'src/anylike.c')
-rw-r--r-- | src/anylike.c | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/anylike.c b/src/anylike.c index ae65ef9..50c7d5d 100644 --- a/src/anylike.c +++ b/src/anylike.c @@ -28,7 +28,10 @@ #include <lua50/lua.h> -int main(int argc, char* argv[]) +#include "datatypes.h" +#include "options.h" + +int main_loop(options_t* opt) { lua_State *L; L = lua_open(); @@ -40,5 +43,39 @@ int main(int argc, char* argv[]) lua_close(L); - return 0; + return 0; +} + +int main(int argc, char* argv[]) +{ + options_t opt; + int ret = options_parse(&opt, argc, argv); + if(ret) { + if(ret > 0) { + fprintf(stderr, "syntax error near: %s\n\n", argv[ret]); + } + if(ret == -2) { + fprintf(stderr, "memory error on options_parse, exitting\n"); + } + if(ret == -3) { + options_print_version(); + } + + if(ret != -2 && ret != -3) + options_print_usage(); + + if(ret == -1 || ret == -3) + ret = 0; + + options_clear(&opt); + exit(ret); + } + + options_parse_post(&opt); + + ret = main_loop(&opt); + + options_clear(&opt); + + return ret; } |