usage.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*
  2. * usage.c $Id: usage.c,v 4.28 2008/11/02 18:51:27 bkorb Exp $
  3. * Time-stamp: "2008-11-01 20:09:17 bkorb"
  4. *
  5. * This module implements the default usage procedure for
  6. * Automated Options. It may be overridden, of course.
  7. *
  8. * Sort options:
  9. --start=END-[S]TATIC-FORWARD --patt='^/\*($|[^:])' \
  10. --out=xx.c key='^[a-zA-Z0-9_]+\(' --trail='^/\*:' \
  11. --spac=2 --input=usage.c
  12. */
  13. /*
  14. * This file is part of AutoOpts, a companion to AutoGen.
  15. * AutoOpts is free software.
  16. * AutoOpts is copyright (c) 1992-2008 by Bruce Korb - all rights reserved
  17. * AutoOpts is copyright (c) 1992-2008 by Bruce Korb - all rights reserved
  18. *
  19. * AutoOpts is available under any one of two licenses. The license
  20. * in use must be one of these two and the choice is under the control
  21. * of the user of the license.
  22. *
  23. * The GNU Lesser General Public License, version 3 or later
  24. * See the files "COPYING.lgplv3" and "COPYING.gplv3"
  25. *
  26. * The Modified Berkeley Software Distribution License
  27. * See the file "COPYING.mbsd"
  28. *
  29. * These files have the following md5sums:
  30. *
  31. * 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
  32. * fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3
  33. * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  34. */
  35. #define OPTPROC_L_N_S (OPTPROC_LONGOPT | OPTPROC_SHORTOPT)
  36. static arg_types_t argTypes;
  37. FILE* option_usage_fp = NULL;
  38. static char zOptFmtLine[ 16 ];
  39. static ag_bool displayEnum;
  40. /* = = = START-STATIC-FORWARD = = = */
  41. /* static forward declarations maintained by mk-fwd */
  42. static ag_bool
  43. checkGNUUsage( tOptions* pOpts );
  44. static void
  45. printExtendedUsage(
  46. tOptions* pOptions,
  47. tOptDesc* pOD,
  48. arg_types_t* pAT );
  49. static void
  50. printInitList(
  51. tCC* const* papz,
  52. ag_bool* pInitIntro,
  53. tCC* pzRc,
  54. tCC* pzPN );
  55. static void
  56. printOneUsage(
  57. tOptions* pOptions,
  58. tOptDesc* pOD,
  59. arg_types_t* pAT );
  60. static void
  61. printOptionUsage(
  62. tOptions* pOpts,
  63. int ex_code,
  64. tCC* pOptTitle );
  65. static void
  66. printProgramDetails( tOptions* pOptions );
  67. static int
  68. setGnuOptFmts( tOptions* pOpts, tCC** ppT );
  69. static int
  70. setStdOptFmts( tOptions* pOpts, tCC** ppT );
  71. /* = = = END-STATIC-FORWARD = = = */
  72. /*
  73. * Figure out if we should try to format usage text sort-of like
  74. * the way many GNU programs do.
  75. */
  76. static ag_bool
  77. checkGNUUsage( tOptions* pOpts )
  78. {
  79. char* pz = getenv( "AUTOOPTS_USAGE" );
  80. if (pz == NULL)
  81. ;
  82. else if (streqvcmp( pz, "gnu" ) == 0)
  83. pOpts->fOptSet |= OPTPROC_GNUUSAGE;
  84. else if (streqvcmp( pz, "autoopts" ) == 0)
  85. pOpts->fOptSet &= ~OPTPROC_GNUUSAGE;
  86. return (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? AG_TRUE : AG_FALSE;
  87. }
  88. /*=export_func optionOnlyUsage
  89. *
  90. * what: Print usage text for just the options
  91. * arg: + tOptions* + pOpts + program options descriptor +
  92. * arg: + int + ex_code + exit code for calling exit(3) +
  93. *
  94. * doc:
  95. * This routine will print only the usage for each option.
  96. * This function may be used when the emitted usage must incorporate
  97. * information not available to AutoOpts.
  98. =*/
  99. void
  100. optionOnlyUsage(
  101. tOptions* pOpts,
  102. int ex_code )
  103. {
  104. tCC* pOptTitle = NULL;
  105. /*
  106. * Determine which header and which option formatting strings to use
  107. */
  108. if (checkGNUUsage(pOpts)) {
  109. (void)setGnuOptFmts( pOpts, &pOptTitle );
  110. }
  111. else {
  112. (void)setStdOptFmts( pOpts, &pOptTitle );
  113. }
  114. printOptionUsage( pOpts, ex_code, pOptTitle );
  115. }
  116. /*=export_func optionUsage
  117. * private:
  118. *
  119. * what: Print usage text
  120. * arg: + tOptions* + pOptions + program options descriptor +
  121. * arg: + int + exitCode + exit code for calling exit(3) +
  122. *
  123. * doc:
  124. * This routine will print usage in both GNU-standard and AutoOpts-expanded
  125. * formats. The descriptor specifies the default, but AUTOOPTS_USAGE will
  126. * over-ride this, providing the value of it is set to either "gnu" or
  127. * "autoopts". This routine will @strong{not} return.
  128. *
  129. * If "exitCode" is "EX_USAGE" (normally 64), then output will to to stdout
  130. * and the actual exit code will be "EXIT_SUCCESS".
  131. =*/
  132. void
  133. optionUsage(
  134. tOptions* pOptions,
  135. int usage_exit_code )
  136. {
  137. int actual_exit_code =
  138. (usage_exit_code == EX_USAGE) ? EXIT_SUCCESS : usage_exit_code;
  139. displayEnum = AG_FALSE;
  140. /*
  141. * Paged usage will preset option_usage_fp to an output file.
  142. * If it hasn't already been set, then set it to standard output
  143. * on successful exit (help was requested), otherwise error out.
  144. *
  145. * Test the version before obtaining pzFullUsage or pzShortUsage.
  146. * These fields do not exist before revision 30.
  147. */
  148. {
  149. char const * pz;
  150. if (actual_exit_code == EXIT_SUCCESS) {
  151. pz = (pOptions->structVersion >= 30 * 4096)
  152. ? pOptions->pzFullUsage : NULL;
  153. if (option_usage_fp == NULL)
  154. option_usage_fp = stdout;
  155. } else {
  156. pz = (pOptions->structVersion >= 30 * 4096)
  157. ? pOptions->pzShortUsage : NULL;
  158. if (option_usage_fp == NULL)
  159. option_usage_fp = stderr;
  160. }
  161. if (pz != NULL) {
  162. fputs(pz, option_usage_fp);
  163. exit(actual_exit_code);
  164. }
  165. }
  166. fprintf( option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName );
  167. {
  168. tCC* pOptTitle = NULL;
  169. /*
  170. * Determine which header and which option formatting strings to use
  171. */
  172. if (checkGNUUsage(pOptions)) {
  173. int flen = setGnuOptFmts( pOptions, &pOptTitle );
  174. sprintf( zOptFmtLine, zFmtFmt, flen );
  175. fputc( '\n', option_usage_fp );
  176. }
  177. else {
  178. int flen = setStdOptFmts( pOptions, &pOptTitle );
  179. sprintf( zOptFmtLine, zFmtFmt, flen );
  180. /*
  181. * When we exit with EXIT_SUCCESS and the first option is a doc
  182. * option, we do *NOT* want to emit the column headers.
  183. * Otherwise, we do.
  184. */
  185. if ( (usage_exit_code != EXIT_SUCCESS)
  186. || ((pOptions->pOptDesc->fOptState & OPTST_DOCUMENT) == 0) )
  187. fputs( pOptTitle, option_usage_fp );
  188. }
  189. printOptionUsage( pOptions, usage_exit_code, pOptTitle );
  190. }
  191. /*
  192. * Describe the mechanics of denoting the options
  193. */
  194. switch (pOptions->fOptSet & OPTPROC_L_N_S) {
  195. case OPTPROC_L_N_S: fputs( zFlagOkay, option_usage_fp ); break;
  196. case OPTPROC_SHORTOPT: break;
  197. case OPTPROC_LONGOPT: fputs( zNoFlags, option_usage_fp ); break;
  198. case 0: fputs( zOptsOnly, option_usage_fp ); break;
  199. }
  200. if ((pOptions->fOptSet & OPTPROC_NUM_OPT) != 0) {
  201. fputs( zNumberOpt, option_usage_fp );
  202. }
  203. if ((pOptions->fOptSet & OPTPROC_REORDER) != 0) {
  204. fputs( zReorder, option_usage_fp );
  205. }
  206. if (pOptions->pzExplain != NULL)
  207. fputs( pOptions->pzExplain, option_usage_fp );
  208. /*
  209. * IF the user is asking for help (thus exiting with SUCCESS),
  210. * THEN see what additional information we can provide.
  211. */
  212. if (usage_exit_code == EXIT_SUCCESS)
  213. printProgramDetails( pOptions );
  214. if (pOptions->pzBugAddr != NULL)
  215. fprintf( option_usage_fp, zPlsSendBugs, pOptions->pzBugAddr );
  216. fflush( option_usage_fp );
  217. exit( actual_exit_code );
  218. }
  219. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  220. *
  221. * PER OPTION TYPE USAGE INFORMATION
  222. */
  223. static void
  224. printExtendedUsage(
  225. tOptions* pOptions,
  226. tOptDesc* pOD,
  227. arg_types_t* pAT )
  228. {
  229. /*
  230. * IF there are option conflicts or dependencies,
  231. * THEN print them here.
  232. */
  233. if ( (pOD->pOptMust != NULL)
  234. || (pOD->pOptCant != NULL) ) {
  235. fputs( zTabHyp, option_usage_fp );
  236. /*
  237. * DEPENDENCIES:
  238. */
  239. if (pOD->pOptMust != NULL) {
  240. const int* pOptNo = pOD->pOptMust;
  241. fputs( zReqThese, option_usage_fp );
  242. for (;;) {
  243. fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[
  244. *pOptNo ].pz_Name );
  245. if (*++pOptNo == NO_EQUIVALENT)
  246. break;
  247. }
  248. if (pOD->pOptCant != NULL)
  249. fputs( zTabHypAnd, option_usage_fp );
  250. }
  251. /*
  252. * CONFLICTS:
  253. */
  254. if (pOD->pOptCant != NULL) {
  255. const int* pOptNo = pOD->pOptCant;
  256. fputs( zProhib, option_usage_fp );
  257. for (;;) {
  258. fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[
  259. *pOptNo ].pz_Name );
  260. if (*++pOptNo == NO_EQUIVALENT)
  261. break;
  262. }
  263. }
  264. }
  265. /*
  266. * IF there is a disablement string
  267. * THEN print the disablement info
  268. */
  269. if (pOD->pz_DisableName != NULL )
  270. fprintf( option_usage_fp, zDis, pOD->pz_DisableName );
  271. /*
  272. * Check for argument types that have callbacks with magical properties
  273. */
  274. switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  275. case OPARG_TYPE_NUMERIC:
  276. /*
  277. * IF the numeric option has a special callback,
  278. * THEN call it, requesting the range or other special info
  279. */
  280. if ( (pOD->pOptProc != NULL)
  281. && (pOD->pOptProc != optionNumericVal) ) {
  282. (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
  283. }
  284. break;
  285. case OPARG_TYPE_FILE:
  286. (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
  287. break;
  288. }
  289. /*
  290. * IF the option defaults to being enabled,
  291. * THEN print that out
  292. */
  293. if (pOD->fOptState & OPTST_INITENABLED)
  294. fputs( zEnab, option_usage_fp );
  295. /*
  296. * IF the option is in an equivalence class
  297. * AND not the designated lead
  298. * THEN print equivalence and leave it at that.
  299. */
  300. if ( (pOD->optEquivIndex != NO_EQUIVALENT)
  301. && (pOD->optEquivIndex != pOD->optActualIndex ) ) {
  302. fprintf( option_usage_fp, zAlt,
  303. pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name );
  304. return;
  305. }
  306. /*
  307. * IF this particular option can NOT be preset
  308. * AND some form of presetting IS allowed,
  309. * AND it is not an auto-managed option (e.g. --help, et al.)
  310. * THEN advise that this option may not be preset.
  311. */
  312. if ( ((pOD->fOptState & OPTST_NO_INIT) != 0)
  313. && ( (pOptions->papzHomeList != NULL)
  314. || (pOptions->pzPROGNAME != NULL)
  315. )
  316. && (pOD->optIndex < pOptions->presetOptCt)
  317. )
  318. fputs( zNoPreset, option_usage_fp );
  319. /*
  320. * Print the appearance requirements.
  321. */
  322. if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP)
  323. fputs( zMembers, option_usage_fp );
  324. else switch (pOD->optMinCt) {
  325. case 1:
  326. case 0:
  327. switch (pOD->optMaxCt) {
  328. case 0: fputs( zPreset, option_usage_fp ); break;
  329. case NOLIMIT: fputs( zNoLim, option_usage_fp ); break;
  330. case 1: break;
  331. /*
  332. * IF the max is more than one but limited, print "UP TO" message
  333. */
  334. default: fprintf( option_usage_fp, zUpTo, pOD->optMaxCt ); break;
  335. }
  336. break;
  337. default:
  338. /*
  339. * More than one is required. Print the range.
  340. */
  341. fprintf( option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt );
  342. }
  343. if ( NAMED_OPTS( pOptions )
  344. && (pOptions->specOptIdx.default_opt == pOD->optIndex))
  345. fputs( zDefaultOpt, option_usage_fp );
  346. }
  347. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  348. *
  349. * Figure out where all the initialization files might live.
  350. * This requires translating some environment variables and
  351. * testing to see if a name is a directory or a file. It's
  352. * squishy, but important to tell users how to find these files.
  353. */
  354. static void
  355. printInitList(
  356. tCC* const* papz,
  357. ag_bool* pInitIntro,
  358. tCC* pzRc,
  359. tCC* pzPN )
  360. {
  361. char zPath[ AG_PATH_MAX+1 ];
  362. if (papz == NULL)
  363. return;
  364. fputs( zPresetIntro, option_usage_fp );
  365. *pInitIntro = AG_FALSE;
  366. for (;;) {
  367. char const* pzPath = *(papz++);
  368. if (pzPath == NULL)
  369. break;
  370. if (optionMakePath(zPath, (int)sizeof( zPath ), pzPath, pzPN))
  371. pzPath = zPath;
  372. /*
  373. * Print the name of the "homerc" file. If the "rcfile" name is
  374. * not empty, we may or may not print that, too...
  375. */
  376. fprintf( option_usage_fp, zPathFmt, pzPath );
  377. if (*pzRc != NUL) {
  378. struct stat sb;
  379. /*
  380. * IF the "homerc" file is a directory,
  381. * then append the "rcfile" name.
  382. */
  383. if ( (stat( pzPath, &sb ) == 0)
  384. && S_ISDIR( sb.st_mode ) ) {
  385. fputc( DIRCH, option_usage_fp );
  386. fputs( pzRc, option_usage_fp );
  387. }
  388. }
  389. fputc( '\n', option_usage_fp );
  390. }
  391. }
  392. /*
  393. * Print the usage information for a single option.
  394. */
  395. static void
  396. printOneUsage(
  397. tOptions* pOptions,
  398. tOptDesc* pOD,
  399. arg_types_t* pAT )
  400. {
  401. /*
  402. * Flag prefix: IF no flags at all, then omit it. If not printable
  403. * (not allowed for this option), then blank, else print it.
  404. * Follow it with a comma if we are doing GNU usage and long
  405. * opts are to be printed too.
  406. */
  407. if ((pOptions->fOptSet & OPTPROC_SHORTOPT) == 0)
  408. fputs( pAT->pzSpc, option_usage_fp );
  409. else if (! IS_GRAPHIC_CHAR(pOD->optValue)) {
  410. if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  411. == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  412. fputc( ' ', option_usage_fp );
  413. fputs( pAT->pzNoF, option_usage_fp );
  414. } else {
  415. fprintf( option_usage_fp, " -%c", pOD->optValue );
  416. if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  417. == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  418. fputs( ", ", option_usage_fp );
  419. }
  420. {
  421. char z[ 80 ];
  422. tCC* pzArgType;
  423. /*
  424. * Determine the argument type string first on its usage, then,
  425. * when the option argument is required, base the type string on the
  426. * argument type.
  427. */
  428. if (pOD->fOptState & OPTST_ARG_OPTIONAL) {
  429. pzArgType = pAT->pzOpt;
  430. } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  431. case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break;
  432. case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break;
  433. case OPARG_TYPE_FILE : pzArgType = pAT->pzFile; break;
  434. case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break;
  435. case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break;
  436. case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break;
  437. case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break;
  438. case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break;
  439. case OPARG_TYPE_TIME: pzArgType = pAT->pzTime; break;
  440. default: goto bogus_desc;
  441. }
  442. snprintf( z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name,
  443. (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt );
  444. fprintf( option_usage_fp, zOptFmtLine, z, pOD->pzText );
  445. switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  446. case OPARG_TYPE_ENUMERATION:
  447. case OPARG_TYPE_MEMBERSHIP:
  448. displayEnum = (pOD->pOptProc != NULL) ? AG_TRUE : displayEnum;
  449. }
  450. }
  451. return;
  452. bogus_desc:
  453. fprintf( stderr, zInvalOptDesc, pOD->pz_Name );
  454. exit( EX_SOFTWARE );
  455. }
  456. /*
  457. * Print out the usage information for just the options.
  458. */
  459. static void
  460. printOptionUsage(
  461. tOptions* pOpts,
  462. int ex_code,
  463. tCC* pOptTitle )
  464. {
  465. int ct = pOpts->optCt;
  466. int optNo = 0;
  467. tOptDesc* pOD = pOpts->pOptDesc;
  468. int docCt = 0;
  469. do {
  470. if ((pOD->fOptState & OPTST_OMITTED) != 0)
  471. continue;
  472. if ((pOD->fOptState & OPTST_DOCUMENT) != 0) {
  473. if (ex_code == EXIT_SUCCESS) {
  474. fprintf(option_usage_fp, argTypes.pzBrk, pOD->pzText,
  475. pOptTitle);
  476. docCt++;
  477. }
  478. continue;
  479. }
  480. /*
  481. * IF this is the first auto-opt maintained option
  482. * *AND* we are doing a full help
  483. * *AND* there are documentation options
  484. * *AND* the last one was not a doc option,
  485. * THEN document that the remaining options are not user opts
  486. */
  487. if ( (pOpts->presetOptCt == optNo)
  488. && (ex_code == EXIT_SUCCESS)
  489. && (docCt > 0)
  490. && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) )
  491. fprintf( option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle );
  492. printOneUsage( pOpts, pOD, &argTypes );
  493. /*
  494. * IF we were invoked because of the --help option,
  495. * THEN print all the extra info
  496. */
  497. if (ex_code == EXIT_SUCCESS)
  498. printExtendedUsage( pOpts, pOD, &argTypes );
  499. } while (pOD++, optNo++, (--ct > 0));
  500. fputc( '\n', option_usage_fp );
  501. }
  502. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  503. *
  504. * PROGRAM DETAILS
  505. */
  506. static void
  507. printProgramDetails( tOptions* pOptions )
  508. {
  509. ag_bool initIntro = AG_TRUE;
  510. /*
  511. * Display all the places we look for config files
  512. */
  513. printInitList( pOptions->papzHomeList, &initIntro,
  514. pOptions->pzRcName, pOptions->pzProgPath );
  515. /*
  516. * Let the user know about environment variable settings
  517. */
  518. if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) {
  519. if (initIntro)
  520. fputs( zPresetIntro, option_usage_fp );
  521. fprintf( option_usage_fp, zExamineFmt, pOptions->pzPROGNAME );
  522. }
  523. /*
  524. * IF we found an enumeration,
  525. * THEN hunt for it again. Call the handler proc with a NULL
  526. * option struct pointer. That tells it to display the keywords.
  527. */
  528. if (displayEnum) {
  529. int ct = pOptions->optCt;
  530. int optNo = 0;
  531. tOptDesc* pOD = pOptions->pOptDesc;
  532. fputc( '\n', option_usage_fp );
  533. fflush( option_usage_fp );
  534. do {
  535. switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  536. case OPARG_TYPE_ENUMERATION:
  537. case OPARG_TYPE_MEMBERSHIP:
  538. (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD);
  539. }
  540. } while (pOD++, optNo++, (--ct > 0));
  541. }
  542. /*
  543. * If there is a detail string, now is the time for that.
  544. */
  545. if (pOptions->pzDetail != NULL)
  546. fputs( pOptions->pzDetail, option_usage_fp );
  547. }
  548. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  549. *
  550. * OPTION LINE FORMATTING SETUP
  551. *
  552. * The "OptFmt" formats receive three arguments:
  553. * 1. the type of the option's argument
  554. * 2. the long name of the option
  555. * 3. "YES" or "no ", depending on whether or not the option must appear
  556. * on the command line.
  557. * These formats are used immediately after the option flag (if used) has
  558. * been printed.
  559. *
  560. * Set up the formatting for GNU-style output
  561. */
  562. static int
  563. setGnuOptFmts( tOptions* pOpts, tCC** ppT )
  564. {
  565. int flen = 22;
  566. *ppT = zNoRq_ShrtTtl;
  567. argTypes.pzStr = zGnuStrArg;
  568. argTypes.pzReq = zOneSpace;
  569. argTypes.pzNum = zGnuNumArg;
  570. argTypes.pzKey = zGnuKeyArg;
  571. argTypes.pzKeyL = zGnuKeyLArg;
  572. argTypes.pzTime = zGnuTimeArg;
  573. argTypes.pzFile = zGnuFileArg;
  574. argTypes.pzBool = zGnuBoolArg;
  575. argTypes.pzNest = zGnuNestArg;
  576. argTypes.pzOpt = zGnuOptArg;
  577. argTypes.pzNo = zOneSpace;
  578. argTypes.pzBrk = zGnuBreak;
  579. argTypes.pzNoF = zSixSpaces;
  580. argTypes.pzSpc = zThreeSpaces;
  581. switch (pOpts->fOptSet & OPTPROC_L_N_S) {
  582. case OPTPROC_L_N_S: argTypes.pzOptFmt = zGnuOptFmt; break;
  583. case OPTPROC_LONGOPT: argTypes.pzOptFmt = zGnuOptFmt; break;
  584. case 0: argTypes.pzOptFmt = zGnuOptFmt + 2; break;
  585. case OPTPROC_SHORTOPT:
  586. argTypes.pzOptFmt = zShrtGnuOptFmt;
  587. zGnuStrArg[0] = zGnuNumArg[0] = zGnuKeyArg[0] = zGnuBoolArg[0] = ' ';
  588. argTypes.pzOpt = " [arg]";
  589. flen = 8;
  590. break;
  591. }
  592. return flen;
  593. }
  594. /*
  595. * Standard (AutoOpts normal) option line formatting
  596. */
  597. static int
  598. setStdOptFmts( tOptions* pOpts, tCC** ppT )
  599. {
  600. int flen = 0;
  601. argTypes.pzStr = zStdStrArg;
  602. argTypes.pzReq = zStdReqArg;
  603. argTypes.pzNum = zStdNumArg;
  604. argTypes.pzKey = zStdKeyArg;
  605. argTypes.pzKeyL = zStdKeyLArg;
  606. argTypes.pzTime = zStdTimeArg;
  607. argTypes.pzFile = zStdFileArg;
  608. argTypes.pzBool = zStdBoolArg;
  609. argTypes.pzNest = zStdNestArg;
  610. argTypes.pzOpt = zStdOptArg;
  611. argTypes.pzNo = zStdNoArg;
  612. argTypes.pzBrk = zStdBreak;
  613. argTypes.pzNoF = zFiveSpaces;
  614. argTypes.pzSpc = zTwoSpaces;
  615. switch (pOpts->fOptSet & (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT)) {
  616. case (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT):
  617. *ppT = zNoRq_ShrtTtl;
  618. argTypes.pzOptFmt = zNrmOptFmt;
  619. flen = 19;
  620. break;
  621. case OPTPROC_NO_REQ_OPT:
  622. *ppT = zNoRq_NoShrtTtl;
  623. argTypes.pzOptFmt = zNrmOptFmt;
  624. flen = 19;
  625. break;
  626. case OPTPROC_SHORTOPT:
  627. *ppT = zReq_ShrtTtl;
  628. argTypes.pzOptFmt = zReqOptFmt;
  629. flen = 24;
  630. break;
  631. case 0:
  632. *ppT = zReq_NoShrtTtl;
  633. argTypes.pzOptFmt = zReqOptFmt;
  634. flen = 24;
  635. }
  636. return flen;
  637. }
  638. /*:
  639. * Local Variables:
  640. * mode: C
  641. * c-file-style: "stroustrup"
  642. * indent-tabs-mode: nil
  643. * End:
  644. * end of autoopts/usage.c */