usage.c 21 KB

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