usage.c 21 KB

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