void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ int flags) { poptDone done = (poptDone)memset(alloca(sizeof(*done)), 0, sizeof(*done)); int cursor; done->nopts = 0; done->maxopts = 64; cursor = done->maxopts * sizeof(*done->opts); /*@-boundswrite@*/ done->opts = (const void **)memset(alloca(cursor), 0, cursor); done->opts[done->nopts++] = (const void *) con->options; /*@=boundswrite@*/ cursor = showHelpIntro(con, fp); cursor += showShortOptions(con->options, fp, NULL); cursor = singleTableUsage(con, fp, cursor, con->options, NULL, done); cursor = itemUsage(fp, cursor, con->aliases, con->numAliases, NULL); cursor = itemUsage(fp, cursor, con->execs, con->numExecs, NULL); if (con->otherHelp) { cursor += strlen(con->otherHelp) + 1; if (cursor > 79) fprintf(fp, "\n "); fprintf(fp, " %s", con->otherHelp); } fprintf(fp, "\n"); }
void poptPrintUsage(poptContext con, FILE * f, int flags) { int cursor; cursor = showHelpIntro(con, f); cursor += showShortOptions(con->options, f, NULL); singleTableUsage(f, cursor, con->options); if (con->otherHelp) { cursor += strlen(con->otherHelp) + 1; if (cursor > 79) fprintf(f, "\n "); fprintf(f, " %s", con->otherHelp); } fprintf(f, "\n [LIBRARIES]\n"); }
int singleTableUsage(FILE * f, int cursor, const struct poptOption * table) { const struct poptOption * opt; opt = table; while (opt->longName || opt->shortName || opt->arg) { if ((opt->longName || opt->shortName) && !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) cursor = singleOptionUsage(f, cursor, opt); else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) cursor = singleTableUsage(f, cursor, opt->arg); opt++; } return cursor; }
/** * Display usage text for a table of options. * @param con context * @param fp output file handle * @param cursor * @param opt option(s) * @param translation_domain translation domain * @param done tables already processed * @return */ static int singleTableUsage(poptContext con, FILE * fp, int cursor, /*@null@*/ const struct poptOption * opt, /*@null@*/ const char * translation_domain, /*@null@*/ poptDone done) /*@globals fileSystem @*/ /*@modifies *fp, done, fileSystem @*/ { /*@-branchstate@*/ /* FIX: W2DO? */ if (opt != NULL) for (; (opt->longName || opt->shortName || opt->arg) ; opt++) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) { translation_domain = (const char *)opt->arg; } else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) { if (done) { int i = 0; for (i = 0; i < done->nopts; i++) { /*@-boundsread@*/ const void * that = done->opts[i]; /*@=boundsread@*/ if (that == NULL || that != opt->arg) /*@innercontinue@*/ continue; /*@innerbreak@*/ break; } /* Skip if this table has already been processed. */ if (opt->arg == NULL || i < done->nopts) continue; /*@-boundswrite@*/ if (done->nopts < done->maxopts) done->opts[done->nopts++] = (const void *) opt->arg; /*@=boundswrite@*/ } cursor = singleTableUsage(con, fp, cursor, (const struct poptOption *)opt->arg, translation_domain, done); } else if ((opt->longName || opt->shortName) && !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) { cursor = singleOptionUsage(fp, cursor, opt, translation_domain); } } /*@=branchstate@*/ return cursor; }
static int singleTableUsage(FILE * f, int cursor, const struct poptOption * table, const char *translation_domain) { const struct poptOption * opt; opt = table; while (opt->longName || opt->shortName || opt->arg) { if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INTL_DOMAIN) translation_domain = (const char *)opt->arg; else if ((opt->argInfo & POPT_ARG_MASK) == POPT_ARG_INCLUDE_TABLE) cursor = singleTableUsage(f, cursor, opt->arg, translation_domain); else if ((opt->longName || opt->shortName) && !(opt->argInfo & POPT_ARGFLAG_DOC_HIDDEN)) cursor = singleOptionUsage(f, cursor, opt, translation_domain); opt++; } return cursor; }
void poptPrintUsage(poptContext con, FILE * fp, /*@unused@*/ UNUSED(int flags)) { columns_t columns = (columns_t) xcalloc((size_t)1, sizeof(*columns)); struct poptDone_s done_buf; poptDone done = &done_buf; assert(columns); /* XXX can't happen */ 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 = (const void**) xcalloc((size_t)1, columns->cur); assert(done->opts); /* XXX can't happen */ /*@-keeptrans@*/ if (done->opts != NULL) done->opts[done->nopts++] = (const void *) con->options; /*@=keeptrans@*/ 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); } }
/** * Display usage text for a table of options. * @param con context * @param fp output file handle * @param columns output display width control * @param opt option(s) * @param translation_domain translation domain * @param done tables already processed * @return */ static size_t singleTableUsage(poptContext con, FILE * fp, columns_t columns, /*@null@*/ const struct poptOption * opt, /*@null@*/ const char * translation_domain, /*@null@*/ poptDone done) /*@globals fileSystem @*/ /*@modifies fp, columns->cur, done, fileSystem @*/ { 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) /*@innercontinue@*/ continue; /*@innerbreak@*/ break; } /* Skip if this table has already been processed. */ 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; }