/** * 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 */ }
/** * 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)); }
/* * 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); }
/* * Print out the usage information for just the options. */ static void prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) { int ct = pOpts->optCt; int optNo = 0; tOptDesc * pOD = pOpts->pOptDesc; int docCt = 0; do { if ((pOD->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 ( (pOD->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) && (pOD->pz_Name != NULL) && (ex_code == EXIT_SUCCESS)) { char const * why_pz = (pOD->pzText == NULL) ? zDisabledWhy : pOD->pzText; prt_preamble(pOpts, pOD, &argTypes); fprintf(option_usage_fp, zDisabledOpt, pOD->pz_Name, why_pz); } continue; } if ((pOD->fOptState & OPTST_DOCUMENT) != 0) { if (ex_code == EXIT_SUCCESS) { fprintf(option_usage_fp, argTypes.pzBrk, pOD->pzText, pOptTitle); docCt++; } 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 ( (pOpts->presetOptCt == optNo) && (ex_code == EXIT_SUCCESS) && (docCt > 0) && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) ) fprintf(option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle); prt_one_usage(pOpts, pOD, &argTypes); /* * IF we were invoked because of the --help option, * THEN print all the extra info */ if (ex_code == EXIT_SUCCESS) prt_extd_usage(pOpts, pOD, &argTypes); } while (pOD++, optNo++, (--ct > 0)); fputc('\n', option_usage_fp); }