X-Git-Url: http://pileus.org/git/?p=lackey;a=blobdiff_plain;f=src%2Fargs.c;fp=src%2Fargs.c;h=afc0b481870c01f488edc21e16e195c3fa65fbe6;hp=0000000000000000000000000000000000000000;hb=a10db2328b82791a75bf7d8a97273e6402e62f17;hpb=8a25ed009d64fc7a49a3e4d0e44ea2ee91ddf01d diff --git a/src/args.c b/src/args.c new file mode 100644 index 0000000..afc0b48 --- /dev/null +++ b/src/args.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2016 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "args.h" +#include "util.h" + +/* Setup info */ +static int argc; +static char **argv; + +/* Options */ +const char *short_options = "h"; + +struct option long_options[] = { + {"help", 0, NULL, 'h'}, +}; + +/* Usage */ +static void usage(char *name) +{ + printf("Usage:\n"); + printf(" %s [OPTION...]\n", name); + printf("\n"); + printf("Options:\n"); + printf(" -h, --help Print usage information\n"); +} + +/* Initialize */ +void args_setup(int _argc, char **_argv) +{ + argc = _argc; + argv = _argv; +} + +/* Initialize */ +void args_init(void) +{ + while (1) { + int c = getopt_long(argc, argv, + short_options, long_options, NULL); + if (c == -1) + break; + switch (c) { + case 'h': + usage(argv[0]); + exit(0); + break; + } + } +}