From: Heng Li Date: Wed, 29 Aug 2018 10:15:17 +0000 (-1000) Subject: for c89 compatibility X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=01117c24349be5486dc23022d3bbd4f4e7c6d227;p=klib.git for c89 compatibility --- diff --git a/ketopt.h b/ketopt.h index 1944b09..8fe2a8a 100644 --- a/ketopt.h +++ b/ketopt.h @@ -1,17 +1,17 @@ #ifndef KETOPT_H #define KETOPT_H -#include // for strchr() and strncmp() +#include /* for strchr() and strncmp() */ -#define ko_no_argument 0 +#define ko_no_argument 0 #define ko_required_argument 1 #define ko_optional_argument 2 typedef struct { - int ind; // equivalent to optind - int opt; // equivalent to optopt - char *arg; // equivalent to optarg - // private variables not intended for external uses + int ind; /* equivalent to optind */ + int opt; /* equivalent to optopt */ + char *arg; /* equivalent to optarg */ + /* private variables not intended for external uses */ int i, pos, n_args; } ketopt_t; @@ -23,7 +23,7 @@ typedef struct { static ketopt_t KETOPT_INIT = { 1, 0, 0, 1, 0, 0 }; -static void ketopt_permute(char *argv[], int j, int n) // move argv[j] over n elements to the left +static void ketopt_permute(char *argv[], int j, int n) /* move argv[j] over n elements to the left */ { int k; char *p = argv[j]; @@ -44,17 +44,17 @@ static int ketopt(ketopt_t *s, int argc, char *argv[], int permute, const char * s->ind = s->i - s->n_args; return -1; } - if (argv[s->i][0] == '-' && argv[s->i][1] == '-') { // "--" or a long option - if (argv[s->i][2] == '\0') { // a bare "--" + if (argv[s->i][0] == '-' && argv[s->i][1] == '-') { /* "--" or a long option */ + if (argv[s->i][2] == '\0') { /* a bare "--" */ ketopt_permute(argv, s->i, s->n_args); ++s->i, s->ind = s->i - s->n_args; return -1; } s->opt = 0, opt = '?', s->pos = -1; - if (longopts) { // parse long options - int k, n_matches = 0, match = -1; + if (longopts) { /* parse long options */ + int k, n_matches = 0; const ko_longopt_t *o = 0; - for (j = 2; argv[s->i][j] != '\0' && argv[s->i][j] != '='; ++j) {} // find the end of the option name + for (j = 2; argv[s->i][j] != '\0' && argv[s->i][j] != '='; ++j) {} /* find the end of the option name */ for (k = 0; longopts[k].name != 0; ++k) if (strncmp(&argv[s->i][2], longopts[k].name, j - 2) == 0) ++n_matches, o = &longopts[k]; @@ -63,28 +63,28 @@ static int ketopt(ketopt_t *s, int argc, char *argv[], int permute, const char * if (argv[s->i][j] == '=') s->arg = &argv[s->i][j + 1]; if (o->has_arg == 1 && argv[s->i][j] == '\0') { if (s->i < argc - 1) s->arg = argv[++s->i]; - else opt = ':'; // missing option argument + else opt = ':'; /* missing option argument */ } } } - } else { // a short option + } else { /* a short option */ char *p; if (s->pos == 0) s->pos = 1; opt = s->opt = argv[s->i][s->pos++]; p = strchr(ostr, opt); if (p == 0) { - opt = '?'; // unknown option + opt = '?'; /* unknown option */ } else if (p[1] == ':') { if (argv[s->i][s->pos] == 0) { if (s->i < argc - 1) s->arg = argv[++s->i]; - else opt = ':'; // missing option argument + else opt = ':'; /* missing option argument */ } else s->arg = &argv[s->i][s->pos]; s->pos = -1; } } if (s->pos < 0 || argv[s->i][s->pos] == 0) { ++s->i, s->pos = 0; - if (s->n_args > 0) // permute + if (s->n_args > 0) /* permute */ for (j = i0; j < s->i; ++j) ketopt_permute(argv, j, s->n_args); }