/** * Print the long options processed with "-W". These options will be the * ones that do *not* have flag characters. * * @param opts the program option descriptor * @param title the title for the options */ static void prt_vendor_opts(tOptions * opts, char const * title) { static unsigned int const not_vended_mask = OPTST_NO_USAGE_MASK | OPTST_DOCUMENT; static char const vfmtfmt[] = "%%-%us %%s\n"; char vfmt[sizeof(vfmtfmt)]; /* * Only handle client specified options. The "vendor option" follows * "presetOptCt", so we won't loop/recurse indefinitely. */ int ct = opts->presetOptCt; tOptDesc * od = opts->pOptDesc; fprintf(option_usage_fp, zTabout + tab_skip_ct, zVendOptsAre); { size_t nmlen = 0; do { size_t l; if ( ((od->fOptState & not_vended_mask) != 0) || IS_GRAPHIC_CHAR(od->optValue)) continue; l = strlen(od->pz_Name); if (l > nmlen) nmlen = l; } while (od++, (--ct > 0)); snprintf(vfmt, sizeof(vfmt), vfmtfmt, (unsigned int)nmlen + 4); } if (tab_skip_ct > 0) tab_skip_ct--; ct = opts->presetOptCt; od = opts->pOptDesc; do { if ( ((od->fOptState & not_vended_mask) != 0) || IS_GRAPHIC_CHAR(od->optValue)) continue; prt_one_vendor(opts, od, &argTypes, vfmt); prt_extd_usage(opts, od, title); } while (od++, (--ct > 0)); /* no need to restore "tab_skip_ct" - options are done now */ }
static void prt_preamble(tOptions * opts, tOptDesc * od, arg_types_t * at) { /* * Flag prefix: IF no flags at all, then omit it. If not printable * (not allowed for this option), then blank, else print it. * Follow it with a comma if we are doing GNU usage and long * opts are to be printed too. */ if ((opts->fOptSet & OPTPROC_SHORTOPT) == 0) fputs(at->pzSpc, option_usage_fp); else if (! IS_GRAPHIC_CHAR(od->optValue)) { if ( (opts->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) fputc(' ', option_usage_fp); fputs(at->pzNoF, option_usage_fp); } else { fprintf(option_usage_fp, " -%c", od->optValue); if ( (opts->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) fputs(", ", option_usage_fp); } }
/** * Print the long options processed with "-W". These options will be the * ones that do *not* have flag characters. * * @param pOptions the program option descriptor * @param pOD the option descriptor * @param pAT names of the option argument types */ static void prt_vendor_opts(tOptions * pOpts, arg_types_t * pAT, char const * pOptTitle) { static unsigned int const not_vended_mask = OPTST_NO_USAGE_MASK | OPTST_DOCUMENT; static char const vfmtfmt[] = "%%-%us %%s\n"; char vfmt[sizeof(vfmtfmt)]; /* * Only handle client specified options. The "vendor option" follows * "presetOptCt", so we won't loop/recurse indefinitely. */ int ct = pOpts->presetOptCt; tOptDesc * pOD = pOpts->pOptDesc; size_t nmlen = 0; fprintf(option_usage_fp, zTabout, zVendOptsAre); do { size_t l; if ( ((pOD->fOptState & not_vended_mask) != 0) || IS_GRAPHIC_CHAR(pOD->optValue)) continue; l = strlen(pOD->pz_Name); if (l > nmlen) nmlen = l; } while (pOD++, (--ct > 0)); sprintf(vfmt, vfmtfmt, (unsigned int)nmlen + 4); ct = pOpts->presetOptCt; pOD = pOpts->pOptDesc; do { if ( ((pOD->fOptState & not_vended_mask) != 0) || IS_GRAPHIC_CHAR(pOD->optValue)) continue; prt_one_vendor(pOpts, pOD, &argTypes, vfmt); prt_extd_usage(pOpts, pOD, &argTypes, pOptTitle); } while (pOD++, (--ct > 0)); }
/** * recognize flag options. These go at the end. * At the end, emit code to handle options we don't recognize. * * @param[in] opts the program options */ static void emit_flag(tOptions * opts) { tOptDesc * od = opts->pOptDesc; int opt_ct = opts->optCt; fputs(zOptionCase, stdout); for (;opt_ct > 0; od++, --opt_ct) { if (SKIP_OPT(od) || ! IS_GRAPHIC_CHAR(od->optValue)) continue; printf(zOptionFlag, od->optValue); emit_action(opts, od); } printf(UNK_OPT_FMT, FLAG_STR, opts->pzPROGNAME); }
static void emitFlag( tOptions* pOpts ) { tOptDesc* pOptDesc = pOpts->pOptDesc; int optionCt = pOpts->optCt; fputs( zOptionCase, stdout ); for (;optionCt > 0; pOptDesc++, --optionCt) { if (SKIP_OPT(pOptDesc)) continue; if (IS_GRAPHIC_CHAR(pOptDesc->optValue)) { printf( zOptionFlag, pOptDesc->optValue ); printOptionAction( pOpts, pOptDesc ); } } printf( zOptionUnknown, "flag", pOpts->pzPROGNAME ); }
static void emit_flag(tOptions * pOpts) { tOptDesc* pOptDesc = pOpts->pOptDesc; int optionCt = pOpts->optCt; fputs(zOptionCase, stdout); for (;optionCt > 0; pOptDesc++, --optionCt) { if (SKIP_OPT(pOptDesc)) continue; if (IS_GRAPHIC_CHAR(pOptDesc->optValue)) { printf(zOptionFlag, pOptDesc->optValue); emit_action(pOpts, pOptDesc); } } printf(UNK_OPT_FMT, FLAG_STR, pOpts->pzPROGNAME); }
/* * Print out the usage information for just the options. */ static void prt_opt_usage(tOptions * opts, int ex_code, char const * title) { int ct = opts->optCt; int optNo = 0; tOptDesc * od = opts->pOptDesc; int docCt = 0; do { /* * no usage --> disallowed on command line (OPTST_NO_COMMAND), or * deprecated -- strongly discouraged (OPTST_DEPRECATED), or * compiled out of current object code (OPTST_OMITTED) */ if ((od->fOptState & OPTST_NO_USAGE_MASK) != 0) { /* * IF this is a compiled-out option * *AND* usage was requested with "omitted-usage" * *AND* this is NOT abbreviated usage * THEN display this option. */ if ( (od->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) && (od->pz_Name != NULL) && (ex_code == EXIT_SUCCESS)) { char const * why_pz = (od->pzText == NULL) ? zDisabledWhy : od->pzText; prt_preamble(opts, od, &argTypes); fprintf(option_usage_fp, zDisabledOpt, od->pz_Name, why_pz); } continue; } if ((od->fOptState & OPTST_DOCUMENT) != 0) { if (ex_code == EXIT_SUCCESS) { fprintf(option_usage_fp, argTypes.pzBrk, od->pzText, title); docCt++; } continue; } /* Skip name only options when we have a vendor option */ if ( ((opts->fOptSet & OPTPROC_VENDOR_OPT) != 0) && (! IS_GRAPHIC_CHAR(od->optValue))) continue; /* * IF this is the first auto-opt maintained option * *AND* we are doing a full help * *AND* there are documentation options * *AND* the last one was not a doc option, * THEN document that the remaining options are not user opts */ if ((docCt > 0) && (ex_code == EXIT_SUCCESS)) { if (opts->presetOptCt == optNo) { if ((od[-1].fOptState & OPTST_DOCUMENT) == 0) fprintf(option_usage_fp, argTypes.pzBrk, zAuto, title); } else if ((ct == 1) && (opts->fOptSet & OPTPROC_VENDOR_OPT)) fprintf(option_usage_fp, argTypes.pzBrk, zVendIntro, title); } prt_one_usage(opts, od, &argTypes); /* * IF we were invoked because of the --help option, * THEN print all the extra info */ if (ex_code == EXIT_SUCCESS) prt_extd_usage(opts, od, title); } while (od++, optNo++, (--ct > 0)); fputc(NL, option_usage_fp); }