diff options
Diffstat (limited to 'src/getoptb.c')
-rw-r--r-- | src/getoptb.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/getoptb.c b/src/getoptb.c index edee6b8..9859102 100644 --- a/src/getoptb.c +++ b/src/getoptb.c @@ -1,6 +1,7 @@ -#include "buffer.h" #include "getoptb.h" +#include "buffer.h" + /** @file getoptb.c @author djb @@ -8,13 +9,13 @@ @brief 'getopt' version w/o stdlib */ -#define optind subgetoptind +#define optind subgetoptind #define optproblem subgetoptproblem int opterr = 1; char *optprogname = 0; -int getopt(int argc,char **argv,char *opts) +int getopt(int argc, char **argv, char *opts) { int c; char *s; @@ -22,25 +23,28 @@ int getopt(int argc,char **argv,char *opts) if (!optprogname) { optprogname = *argv; if (!optprogname) optprogname = ""; - for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1; + for (s = optprogname; *s; ++s) + if (*s == '/') optprogname = s + 1; } - c = subgetopt(argc,argv,opts); + c = subgetopt(argc, argv, opts); if (opterr) if (c == '?') { - char chp[2]; chp[0] = optproblem; chp[1] = '\n'; - buffer_puts(buffer_2,optprogname); + char chp[2]; + chp[0] = optproblem; + chp[1] = '\n'; + buffer_puts(buffer_2, optprogname); if (argv[optind] && (optind < argc)) - buffer_puts(buffer_2,": illegal option -- "); + buffer_puts(buffer_2, ": illegal option -- "); else - buffer_puts(buffer_2,": option requires an argument -- "); - buffer_put(buffer_2,chp,2); + buffer_puts(buffer_2, ": option requires an argument -- "); + buffer_put(buffer_2, chp, 2); buffer_flush(buffer_2); } return c; } -#define optpos subgetoptpos -#define optarg subgetoptarg +#define optpos subgetoptpos +#define optarg subgetoptarg #define optdone subgetoptdone int optind = 1; @@ -49,7 +53,7 @@ char *optarg = 0; int optproblem = 0; int optdone = SUBGETOPTDONE; -int subgetopt(int argc,char **argv,char *opts) +int subgetopt(int argc, char **argv, char *opts) { int c; char *s; @@ -87,7 +91,7 @@ int subgetopt(int argc,char **argv,char *opts) optproblem = c; return '?'; } - ++optind; + ++optind; } } return c; |