123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925 |
- #include "system.h"
- #define POPT_USE_TIOCGWINSZ
- #ifdef POPT_USE_TIOCGWINSZ
- #include <sys/ioctl.h>
- #endif
- #define POPT_WCHAR_HACK
- #ifdef POPT_WCHAR_HACK
- #include <wchar.h> /* for mbsrtowcs */
- #endif
- #include "poptint.h"
- static void displayArgs(poptContext con,
- UNUSED(enum poptCallbackReason foo),
- struct poptOption * key,
- UNUSED(const char * arg),
- UNUSED(void * data))
-
-
- {
- if (key->shortName == '?')
- poptPrintHelp(con, stdout, 0);
- else
- poptPrintUsage(con, stdout, 0);
- #if !defined(__LCLINT__)
- con = poptFreeContext(con);
- #endif
- exit(0);
- }
- #ifdef NOTYET
- static int show_option_defaults = 0;
- #endif
-
- struct poptOption poptAliasOptions[] = {
- POPT_TABLEEND
- };
-
- struct poptOption poptHelpOptions[] = {
- { NULL, '\0', POPT_ARG_CALLBACK, (void *)displayArgs, 0, NULL, NULL },
- { "help", '?', 0, NULL, (int)'?', N_("Show this help message"), NULL },
- { "usage", '\0', 0, NULL, (int)'u', N_("Display brief usage message"), NULL },
- POPT_TABLEEND
- } ;
-
- static struct poptOption poptHelpOptions2[] = {
- { NULL, '\0', POPT_ARG_INTL_DOMAIN, PACKAGE, 0, NULL, NULL},
- { NULL, '\0', POPT_ARG_CALLBACK, (void *)displayArgs, 0, NULL, NULL },
- { "help", '?', 0, NULL, (int)'?', N_("Show this help message"), NULL },
- { "usage", '\0', 0, NULL, (int)'u', N_("Display brief usage message"), NULL },
- #ifdef NOTYET
- { "defaults", '\0', POPT_ARG_NONE, &show_option_defaults, 0,
- N_("Display option defaults in message"), NULL },
- #endif
- { "", '\0', 0, NULL, 0, N_("Terminate options"), NULL },
- POPT_TABLEEND
- } ;
-
- struct poptOption * poptHelpOptionsI18N = poptHelpOptions2;
- #define _POPTHELP_MAXLINE ((size_t)79)
- typedef struct columns_s {
- size_t cur;
- size_t max;
- } * columns_t;
-
- static size_t maxColumnWidth(FILE *fp)
-
- {
- size_t maxcols = _POPTHELP_MAXLINE;
- #if defined(TIOCGWINSZ)
- struct winsize ws;
- int fdno = fileno(fp ? fp : stdout);
- memset(&ws, 0, sizeof(ws));
- if (fdno >= 0 && !ioctl(fdno, (unsigned long)TIOCGWINSZ, &ws)) {
- size_t ws_col = (size_t)ws.ws_col;
- if (ws_col > maxcols && ws_col < (size_t)256)
- maxcols = ws_col - 1;
- }
- #endif
- return maxcols;
- }
- static inline size_t stringDisplayWidth(const char *s)
-
- {
- size_t n = strlen(s);
- #ifdef POPT_WCHAR_HACK
- mbstate_t t;
- memset ((void *)&t, 0, sizeof (t));
-
- n = mbsrtowcs (NULL, &s, n, &t);
- #else
- n = 0;
- for (; *s; s = POPT_next_char(s))
- n++;
- #endif
- return n;
- }
- static const char *
- getTableTranslationDomain( const struct poptOption *opt)
-
- {
- if (opt != NULL)
- for (; opt->longName || opt->shortName || opt->arg; opt++) {
- if (opt->argInfo == POPT_ARG_INTL_DOMAIN)
- return opt->arg;
- }
- return NULL;
- }
- static const char *
- getArgDescrip(const struct poptOption * opt,
-
- const char * translation_domain)
-
-
- {
- if (!poptArgType(opt)) return NULL;
- if (poptArgType(opt) == POPT_ARG_MAINCALL)
- return opt->argDescrip;
- if (poptArgType(opt) == POPT_ARG_ARGV)
- return opt->argDescrip;
- if (opt->argDescrip) {
-
- if (opt == (poptHelpOptions + 1)
- || opt == (poptHelpOptions + 2)
- || !strcmp(opt->argDescrip, N_("Help options:"))
- || !strcmp(opt->argDescrip, N_("Options implemented via popt alias/exec:")))
- return POPT_(opt->argDescrip);
-
- return D_(translation_domain, opt->argDescrip);
- }
- switch (poptArgType(opt)) {
- case POPT_ARG_NONE: return POPT_("NONE");
- #ifdef DYING
- case POPT_ARG_VAL: return POPT_("VAL");
- #else
- case POPT_ARG_VAL: return NULL;
- #endif
- case POPT_ARG_INT: return POPT_("INT");
- case POPT_ARG_SHORT: return POPT_("SHORT");
- case POPT_ARG_LONG: return POPT_("LONG");
- case POPT_ARG_LONGLONG: return POPT_("LONGLONG");
- case POPT_ARG_STRING: return POPT_("STRING");
- case POPT_ARG_FLOAT: return POPT_("FLOAT");
- case POPT_ARG_DOUBLE: return POPT_("DOUBLE");
- case POPT_ARG_MAINCALL: return NULL;
- case POPT_ARG_ARGV: return NULL;
- default: return POPT_("ARG");
- }
- }
- static char *
- singleOptionDefaultValue(size_t lineLength,
- const struct poptOption * opt,
-
- const char * translation_domain)
-
-
- {
- const char * defstr = D_(translation_domain, "default");
- char * le = malloc(4*lineLength + 1);
- char * l = le;
- if (le == NULL) return NULL;
- *le = '\0';
- *le++ = '(';
- le = stpcpy(le, defstr);
- *le++ = ':';
- *le++ = ' ';
- if (opt->arg) {
- poptArg arg = { .ptr = opt->arg };
- switch (poptArgType(opt)) {
- case POPT_ARG_VAL:
- case POPT_ARG_INT:
- le += sprintf(le, "%d", arg.intp[0]);
- break;
- case POPT_ARG_SHORT:
- le += sprintf(le, "%hd", arg.shortp[0]);
- break;
- case POPT_ARG_LONG:
- le += sprintf(le, "%ld", arg.longp[0]);
- break;
- case POPT_ARG_LONGLONG:
- le += sprintf(le, "%lld", arg.longlongp[0]);
- break;
- case POPT_ARG_FLOAT:
- { double aDouble = (double) arg.floatp[0];
- le += sprintf(le, "%g", aDouble);
- } break;
- case POPT_ARG_DOUBLE:
- le += sprintf(le, "%g", arg.doublep[0]);
- break;
- case POPT_ARG_MAINCALL:
- le += sprintf(le, "%p", opt->arg);
- break;
- case POPT_ARG_ARGV:
- le += sprintf(le, "%p", opt->arg);
- break;
- case POPT_ARG_STRING:
- { const char * s = arg.argv[0];
- if (s == NULL)
- le = stpcpy(le, "null");
- else {
- size_t limit = 4*lineLength - (le - l) - sizeof("\"\")");
- size_t slen;
- *le++ = '"';
- strncpy(le, s, limit); le[limit] = '\0'; le += (slen = strlen(le));
- if (slen == limit && s[limit])
- le[-1] = le[-2] = le[-3] = '.';
- *le++ = '"';
- }
- } break;
- case POPT_ARG_NONE:
- default:
- l = _free(l);
- return NULL;
- break;
- }
- }
- *le++ = ')';
- *le = '\0';
- return l;
- }
- static void singleOptionHelp(FILE * fp, columns_t columns,
- const struct poptOption * opt,
- const char * translation_domain)
-
-
- {
- size_t maxLeftCol = columns->cur;
- size_t indentLength = maxLeftCol + 5;
- size_t lineLength = columns->max - indentLength;
- const char * help = D_(translation_domain, opt->descrip);
- const char * argDescrip = getArgDescrip(opt, translation_domain);
-
- int prtshort = (int)(isprint((int)opt->shortName) && opt->shortName != ' ');
- size_t helpLength;
- char * defs = NULL;
- char * left;
- size_t nb = maxLeftCol + 1;
- int displaypad = 0;
- int xx;
-
- if (opt->longName) nb += strlen(opt->longName);
- if (F_ISSET(opt, TOGGLE)) nb += sizeof("[no]") - 1;
- if (argDescrip) nb += strlen(argDescrip);
- left = malloc(nb);
- if (left == NULL) return;
- left[0] = '\0';
- left[maxLeftCol] = '\0';
- #define prtlong (opt->longName != NULL)
- if (!(prtshort || prtlong))
- goto out;
- if (prtshort && prtlong) {
- char *dash = F_ISSET(opt, ONEDASH) ? "-" : "--";
- left[0] = '-';
- left[1] = opt->shortName;
- (void) stpcpy(stpcpy(stpcpy(left+2, ", "), dash), opt->longName);
- } else if (prtshort) {
- left[0] = '-';
- left[1] = opt->shortName;
- left[2] = '\0';
- } else if (prtlong) {
-
- char *dash = poptArgType(opt) == POPT_ARG_MAINCALL ? ""
- : (F_ISSET(opt, ONEDASH) ? "-" : "--");
- const char *longName = opt->longName;
- const char *toggle;
- if (F_ISSET(opt, TOGGLE)) {
- toggle = "[no]";
- if (longName[0] == 'n' && longName[1] == 'o') {
- longName += sizeof("no") - 1;
- if (longName[0] == '-')
- longName++;
- }
- } else
- toggle = "";
- (void) stpcpy(stpcpy(stpcpy(stpcpy(left, " "), dash), toggle), longName);
- }
- #undef prtlong
- if (argDescrip) {
- char * le = left + strlen(left);
- if (F_ISSET(opt, OPTIONAL))
- *le++ = '[';
-
- if (F_ISSET(opt, SHOW_DEFAULT)) {
- defs = singleOptionDefaultValue(lineLength, opt, translation_domain);
- if (defs) {
- char * t = malloc((help ? strlen(help) : 0) +
- strlen(defs) + sizeof(" "));
- if (t) {
- char * te = t;
- if (help)
- te = stpcpy(te, help);
- *te++ = ' ';
- strcpy(te, defs);
- defs = _free(defs);
- defs = t;
- }
- }
- }
- if (opt->argDescrip == NULL) {
- switch (poptArgType(opt)) {
- case POPT_ARG_NONE:
- break;
- case POPT_ARG_VAL:
- #ifdef NOTNOW
- { long aLong = opt->val;
- int ops = F_ISSET(opt, LOGICALOPS);
- int negate = F_ISSET(opt, NOT);
-
- if (!ops && (aLong == 0L || aLong == 1L || aLong == -1L))
- break;
- *le++ = '[';
- switch (ops) {
- case POPT_ARGFLAG_OR:
- *le++ = '|';
- break;
- case POPT_ARGFLAG_AND:
- *le++ = '&';
- break;
- case POPT_ARGFLAG_XOR:
- *le++ = '^';
- break;
- default:
- break;
- }
- *le++ = (opt->longName != NULL ? '=' : ' ');
- if (negate) *le++ = '~';
-
- le += sprintf(le, (ops ? "0x%lx" : "%ld"), aLong);
-
- *le++ = ']';
- }
- #endif
- break;
- case POPT_ARG_INT:
- case POPT_ARG_SHORT:
- case POPT_ARG_LONG:
- case POPT_ARG_LONGLONG:
- case POPT_ARG_FLOAT:
- case POPT_ARG_DOUBLE:
- case POPT_ARG_STRING:
- *le++ = (opt->longName != NULL ? '=' : ' ');
- le = stpcpy(le, argDescrip);
- break;
- default:
- break;
- }
- } else {
- char *leo;
-
- if (!strchr(" =(", argDescrip[0]))
- *le++ = ((poptArgType(opt) == POPT_ARG_MAINCALL) ? ' ' :
- (poptArgType(opt) == POPT_ARG_ARGV) ? ' ' : '=');
- le = stpcpy(leo = le, argDescrip);
-
- displaypad = (int)((le - leo) - stringDisplayWidth(argDescrip));
- }
- if (F_ISSET(opt, OPTIONAL))
- *le++ = ']';
- *le = '\0';
- }
- if (help)
- xx = POPT_fprintf(fp," %-*s ", (int)(maxLeftCol+displaypad), left);
- else {
- xx = POPT_fprintf(fp," %s\n", left);
- goto out;
- }
- left = _free(left);
- if (defs)
- help = defs;
- helpLength = strlen(help);
- while (helpLength > lineLength) {
- const char * ch;
- char format[16];
- ch = help + lineLength - 1;
- while (ch > help && !_isspaceptr(ch))
- ch = POPT_prev_char(ch);
- if (ch == help) break;
- while (ch > (help + 1) && _isspaceptr(ch))
- ch = POPT_prev_char (ch);
- ch = POPT_next_char(ch);
-
- { char * fmthelp = xstrdup(help);
- if (fmthelp) {
- fmthelp[ch - help] = '\0';
- sprintf(format, "%%s\n%%%ds", (int) indentLength);
-
- xx = POPT_fprintf(fp, format, fmthelp, " ");
-
- free(fmthelp);
- }
- }
- help = ch;
- while (_isspaceptr(help) && *help)
- help = POPT_next_char(help);
- helpLength = strlen(help);
- }
- if (helpLength) fprintf(fp, "%s\n", help);
- help = NULL;
- out:
-
- defs = _free(defs);
-
- left = _free(left);
- }
- static size_t maxArgWidth(const struct poptOption * opt,
- const char * translation_domain)
-
- {
- size_t max = 0;
- size_t len = 0;
- const char * argDescrip;
-
- if (opt != NULL)
- while (opt->longName || opt->shortName || opt->arg) {
- if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
- if (opt->arg)
- len = maxArgWidth(opt->arg, translation_domain);
- if (len > max) max = len;
- } else if (!F_ISSET(opt, DOC_HIDDEN)) {
- len = sizeof(" ")-1;
-
- len += sizeof("-X, ")-1;
- if (opt->longName) {
- len += (F_ISSET(opt, ONEDASH) ? sizeof("-") : sizeof("--")) - 1;
- len += strlen(opt->longName);
- }
- argDescrip = getArgDescrip(opt, translation_domain);
- if (argDescrip) {
-
- if (!strchr(" =(", argDescrip[0])) len += sizeof("=")-1;
-
- len += stringDisplayWidth(argDescrip);
- }
- if (F_ISSET(opt, OPTIONAL)) len += sizeof("[]")-1;
- if (len > max) max = len;
- }
- opt++;
- }
-
- return max;
- }
- static void itemHelp(FILE * fp,
- poptItem items, int nitems,
- columns_t columns,
- const char * translation_domain)
-
-
- {
- poptItem item;
- int i;
- if (items != NULL)
- for (i = 0, item = items; i < nitems; i++, item++) {
- const struct poptOption * opt;
- opt = &item->option;
- if ((opt->longName || opt->shortName) && !F_ISSET(opt, DOC_HIDDEN))
- singleOptionHelp(fp, columns, opt, translation_domain);
- }
- }
- static void singleTableHelp(poptContext con, FILE * fp,
- const struct poptOption * table,
- columns_t columns,
- const char * translation_domain)
-
-
- {
- const struct poptOption * opt;
- const char *sub_transdom;
- int xx;
- if (table == poptAliasOptions) {
- itemHelp(fp, con->aliases, con->numAliases, columns, NULL);
- itemHelp(fp, con->execs, con->numExecs, columns, NULL);
- return;
- }
- if (table != NULL)
- for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
- if ((opt->longName || opt->shortName) && !F_ISSET(opt, DOC_HIDDEN))
- singleOptionHelp(fp, columns, opt, translation_domain);
- }
- if (table != NULL)
- for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
- if (poptArgType(opt) != POPT_ARG_INCLUDE_TABLE)
- continue;
- sub_transdom = getTableTranslationDomain(opt->arg);
- if (sub_transdom == NULL)
- sub_transdom = translation_domain;
-
-
- if (opt->arg == poptAliasOptions && !(con->numAliases || con->numExecs))
- continue;
- if (opt->descrip)
- xx = POPT_fprintf(fp, "\n%s\n", D_(sub_transdom, opt->descrip));
- singleTableHelp(con, fp, opt->arg, columns, sub_transdom);
- }
- }
- static size_t showHelpIntro(poptContext con, FILE * fp)
-
-
- {
- size_t len = (size_t)6;
- int xx;
- xx = POPT_fprintf(fp, POPT_("Usage:"));
- if (!(con->flags & POPT_CONTEXT_KEEP_FIRST)) {
- struct optionStackEntry * os = con->optionStack;
- const char * fn = (os->argv ? os->argv[0] : NULL);
- if (fn == NULL) return len;
- if (strchr(fn, '/')) fn = strrchr(fn, '/') + 1;
-
- fprintf(fp, " %s", fn);
- len += strlen(fn) + 1;
- }
- return len;
- }
- void poptPrintHelp(poptContext con, FILE * fp, UNUSED(int flags))
- {
- columns_t columns = calloc((size_t)1, sizeof(*columns));
- int xx;
- (void) showHelpIntro(con, fp);
- if (con->otherHelp)
- xx = POPT_fprintf(fp, " %s\n", con->otherHelp);
- else
- xx = POPT_fprintf(fp, " %s\n", POPT_("[OPTION...]"));
- if (columns) {
- columns->cur = maxArgWidth(con->options, NULL);
- columns->max = maxColumnWidth(fp);
- singleTableHelp(con, fp, con->options, columns, NULL);
- free(columns);
- }
- }
- static size_t singleOptionUsage(FILE * fp, columns_t columns,
- const struct poptOption * opt,
- const char *translation_domain)
-
-
- {
- size_t len = sizeof(" []")-1;
- const char * argDescrip = getArgDescrip(opt, translation_domain);
-
- int prtshort = (int)(isprint((int)opt->shortName) && opt->shortName != ' ');
- #define prtlong (opt->longName != NULL)
- if (!(prtshort || prtlong))
- return columns->cur;
- len = sizeof(" []")-1;
- if (prtshort)
- len += sizeof("-c")-1;
- if (prtlong) {
- if (prtshort) len += sizeof("|")-1;
- len += (F_ISSET(opt, ONEDASH) ? sizeof("-") : sizeof("--")) - 1;
- len += strlen(opt->longName);
- }
- if (argDescrip) {
-
- if (!strchr(" =(", argDescrip[0])) len += sizeof("=")-1;
-
- len += stringDisplayWidth(argDescrip);
- }
- if ((columns->cur + len) > columns->max) {
- fprintf(fp, "\n ");
- columns->cur = (size_t)7;
- }
- fprintf(fp, " [");
- if (prtshort)
- fprintf(fp, "-%c", opt->shortName);
- if (prtlong)
- fprintf(fp, "%s%s%s",
- (prtshort ? "|" : ""),
- (F_ISSET(opt, ONEDASH) ? "-" : "--"),
- opt->longName);
- #undef prtlong
- if (argDescrip) {
-
- if (!strchr(" =(", argDescrip[0])) fprintf(fp, "=");
- fprintf(fp, "%s", argDescrip);
- }
- fprintf(fp, "]");
- return columns->cur + len + 1;
- }
- static size_t itemUsage(FILE * fp, columns_t columns,
- poptItem item, int nitems,
- const char * translation_domain)
-
-
- {
- int i;
- if (item != NULL)
- for (i = 0; i < nitems; i++, item++) {
- const struct poptOption * opt;
- opt = &item->option;
- if (poptArgType(opt) == POPT_ARG_INTL_DOMAIN) {
- translation_domain = (const char *)opt->arg;
- } else
- if ((opt->longName || opt->shortName) && !F_ISSET(opt, DOC_HIDDEN)) {
- columns->cur = singleOptionUsage(fp, columns, opt, translation_domain);
- }
- }
- return columns->cur;
- }
- typedef struct poptDone_s {
- int nopts;
- int maxopts;
- const void ** opts;
- } * poptDone;
- static size_t singleTableUsage(poptContext con, FILE * fp, columns_t columns,
- const struct poptOption * opt,
- const char * translation_domain,
- poptDone done)
-
-
- {
- if (opt != NULL)
- for (; (opt->longName || opt->shortName || opt->arg) ; opt++) {
- if (poptArgType(opt) == POPT_ARG_INTL_DOMAIN) {
- translation_domain = (const char *)opt->arg;
- } else
- if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
- if (done) {
- int i = 0;
- if (done->opts != NULL)
- for (i = 0; i < done->nopts; i++) {
- const void * that = done->opts[i];
- if (that == NULL || that != opt->arg)
- continue;
- break;
- }
-
- if (opt->arg == NULL || i < done->nopts)
- continue;
- if (done->opts != NULL && done->nopts < done->maxopts)
- done->opts[done->nopts++] = (const void *) opt->arg;
- }
- columns->cur = singleTableUsage(con, fp, columns, opt->arg,
- translation_domain, done);
- } else
- if ((opt->longName || opt->shortName) && !F_ISSET(opt, DOC_HIDDEN)) {
- columns->cur = singleOptionUsage(fp, columns, opt, translation_domain);
- }
- }
- return columns->cur;
- }
- static size_t showShortOptions(const struct poptOption * opt, FILE * fp,
- char * str)
-
-
-
- {
-
- size_t nb = (size_t)300;
- char * s = (str != NULL ? str : calloc((size_t)1, nb));
- size_t len = (size_t)0;
- if (s == NULL)
- return 0;
- if (opt != NULL)
- for (; (opt->longName || opt->shortName || opt->arg); opt++) {
- if (!F_ISSET(opt, DOC_HIDDEN) && opt->shortName && !poptArgType(opt))
- {
-
- if (!strchr(s, opt->shortName) && isprint((int)opt->shortName)
- && opt->shortName != ' ')
- s[strlen(s)] = opt->shortName;
- } else if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE)
- if (opt->arg)
- len = showShortOptions(opt->arg, fp, s);
- }
-
- if (s != str && *s != '\0') {
- fprintf(fp, " [-%s]", s);
- len = strlen(s) + sizeof(" [-]")-1;
- }
-
- if (s != str)
- free(s);
- return len;
- }
- void poptPrintUsage(poptContext con, FILE * fp, UNUSED(int flags))
- {
- columns_t columns = calloc((size_t)1, sizeof(*columns));
- struct poptDone_s done_buf;
- poptDone done = &done_buf;
- memset(done, 0, sizeof(*done));
- done->nopts = 0;
- done->maxopts = 64;
- if (columns) {
- columns->cur = done->maxopts * sizeof(*done->opts);
- columns->max = maxColumnWidth(fp);
- done->opts = calloc((size_t)1, columns->cur);
-
- if (done->opts != NULL)
- done->opts[done->nopts++] = (const void *) con->options;
-
- columns->cur = showHelpIntro(con, fp);
- columns->cur += showShortOptions(con->options, fp, NULL);
- columns->cur = singleTableUsage(con, fp, columns, con->options, NULL, done);
- columns->cur = itemUsage(fp, columns, con->aliases, con->numAliases, NULL);
- columns->cur = itemUsage(fp, columns, con->execs, con->numExecs, NULL);
- if (con->otherHelp) {
- columns->cur += strlen(con->otherHelp) + 1;
- if (columns->cur > columns->max) fprintf(fp, "\n ");
- fprintf(fp, " %s", con->otherHelp);
- }
- fprintf(fp, "\n");
- if (done->opts != NULL)
- free(done->opts);
- free(columns);
- }
- }
- void poptSetOtherOptionHelp(poptContext con, const char * text)
- {
- con->otherHelp = _free(con->otherHelp);
- con->otherHelp = xstrdup(text);
- }
|