1
0

usage.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * usage.c $Id: usage.c,v 4.20 2007/07/16 00:17:31 bkorb Exp $
  3. * Time-stamp: "2007-07-15 09:43:04 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-2007 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. * 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
  31. * fa82ca978890795162346e661b47161a 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 :mkfwd */
  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. * IF the numeric option has a special callback,
  272. * THEN call it, requesting the range or other special info
  273. */
  274. if ( (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC)
  275. && (pOD->pOptProc != NULL)
  276. && (pOD->pOptProc != optionNumericVal) ) {
  277. (*(pOD->pOptProc))( pOptions, NULL );
  278. }
  279. /*
  280. * IF the option defaults to being enabled,
  281. * THEN print that out
  282. */
  283. if (pOD->fOptState & OPTST_INITENABLED)
  284. fputs( zEnab, option_usage_fp );
  285. /*
  286. * IF the option is in an equivalence class
  287. * AND not the designated lead
  288. * THEN print equivalence and leave it at that.
  289. */
  290. if ( (pOD->optEquivIndex != NO_EQUIVALENT)
  291. && (pOD->optEquivIndex != pOD->optActualIndex ) ) {
  292. fprintf( option_usage_fp, zAlt,
  293. pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name );
  294. return;
  295. }
  296. /*
  297. * IF this particular option can NOT be preset
  298. * AND some form of presetting IS allowed,
  299. * AND it is not an auto-managed option (e.g. --help, et al.)
  300. * THEN advise that this option may not be preset.
  301. */
  302. if ( ((pOD->fOptState & OPTST_NO_INIT) != 0)
  303. && ( (pOptions->papzHomeList != NULL)
  304. || (pOptions->pzPROGNAME != NULL)
  305. )
  306. && (pOD->optIndex < pOptions->presetOptCt)
  307. )
  308. fputs( zNoPreset, option_usage_fp );
  309. /*
  310. * Print the appearance requirements.
  311. */
  312. if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP)
  313. fputs( zMembers, option_usage_fp );
  314. else switch (pOD->optMinCt) {
  315. case 1:
  316. case 0:
  317. switch (pOD->optMaxCt) {
  318. case 0: fputs( zPreset, option_usage_fp ); break;
  319. case NOLIMIT: fputs( zNoLim, option_usage_fp ); break;
  320. case 1: break;
  321. /*
  322. * IF the max is more than one but limited, print "UP TO" message
  323. */
  324. default: fprintf( option_usage_fp, zUpTo, pOD->optMaxCt ); break;
  325. }
  326. break;
  327. default:
  328. /*
  329. * More than one is required. Print the range.
  330. */
  331. fprintf( option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt );
  332. }
  333. if ( NAMED_OPTS( pOptions )
  334. && (pOptions->specOptIdx.default_opt == pOD->optIndex))
  335. fputs( zDefaultOpt, option_usage_fp );
  336. }
  337. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  338. *
  339. * Figure out where all the initialization files might live.
  340. * This requires translating some environment variables and
  341. * testing to see if a name is a directory or a file. It's
  342. * squishy, but important to tell users how to find these files.
  343. */
  344. static void
  345. printInitList(
  346. tCC* const* papz,
  347. ag_bool* pInitIntro,
  348. tCC* pzRc,
  349. tCC* pzPN )
  350. {
  351. char zPath[ AG_PATH_MAX+1 ];
  352. if (papz == NULL)
  353. return;
  354. fputs( zPresetIntro, option_usage_fp );
  355. *pInitIntro = AG_FALSE;
  356. for (;;) {
  357. char const* pzPath = *(papz++);
  358. if (pzPath == NULL)
  359. break;
  360. if (optionMakePath(zPath, (int)sizeof( zPath ), pzPath, pzPN))
  361. pzPath = zPath;
  362. /*
  363. * Print the name of the "homerc" file. If the "rcfile" name is
  364. * not empty, we may or may not print that, too...
  365. */
  366. fprintf( option_usage_fp, zPathFmt, pzPath );
  367. if (*pzRc != NUL) {
  368. struct stat sb;
  369. /*
  370. * IF the "homerc" file is a directory,
  371. * then append the "rcfile" name.
  372. */
  373. if ( (stat( pzPath, &sb ) == 0)
  374. && S_ISDIR( sb.st_mode ) ) {
  375. fputc( DIRCH, option_usage_fp );
  376. fputs( pzRc, option_usage_fp );
  377. }
  378. }
  379. fputc( '\n', option_usage_fp );
  380. }
  381. }
  382. /*
  383. * Print the usage information for a single option.
  384. */
  385. static void
  386. printOneUsage(
  387. tOptions* pOptions,
  388. tOptDesc* pOD,
  389. arg_types_t* pAT )
  390. {
  391. /*
  392. * Flag prefix: IF no flags at all, then omit it. If not printable
  393. * (not allowed for this option), then blank, else print it.
  394. * Follow it with a comma if we are doing GNU usage and long
  395. * opts are to be printed too.
  396. */
  397. if ((pOptions->fOptSet & OPTPROC_SHORTOPT) == 0)
  398. fputs( pAT->pzSpc, option_usage_fp );
  399. else if (! isgraph( pOD->optValue)) {
  400. if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  401. == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  402. fputc( ' ', option_usage_fp );
  403. fputs( pAT->pzNoF, option_usage_fp );
  404. } else {
  405. fprintf( option_usage_fp, " -%c", pOD->optValue );
  406. if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  407. == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT))
  408. fputs( ", ", option_usage_fp );
  409. }
  410. {
  411. char z[ 80 ];
  412. tCC* pzArgType;
  413. /*
  414. * Determine the argument type string first on its usage, then,
  415. * when the option argument is required, base the type string on the
  416. * argument type.
  417. */
  418. if (pOD->fOptState & OPTST_ARG_OPTIONAL) {
  419. pzArgType = pAT->pzOpt;
  420. } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  421. case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break;
  422. case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break;
  423. case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break;
  424. case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break;
  425. case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break;
  426. case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break;
  427. case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break;
  428. default: goto bogus_desc;
  429. }
  430. snprintf( z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name,
  431. (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt );
  432. fprintf( option_usage_fp, zOptFmtLine, z, pOD->pzText );
  433. switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  434. case OPARG_TYPE_ENUMERATION:
  435. case OPARG_TYPE_MEMBERSHIP:
  436. displayEnum = (pOD->pOptProc != NULL) ? AG_TRUE : displayEnum;
  437. }
  438. }
  439. return;
  440. bogus_desc:
  441. fprintf( stderr, zInvalOptDesc, pOD->pz_Name );
  442. exit( EX_SOFTWARE );
  443. }
  444. /*
  445. * Print out the usage information for just the options.
  446. */
  447. static void
  448. printOptionUsage(
  449. tOptions* pOpts,
  450. int ex_code,
  451. tCC* pOptTitle )
  452. {
  453. int ct = pOpts->optCt;
  454. int optNo = 0;
  455. tOptDesc* pOD = pOpts->pOptDesc;
  456. int docCt = 0;
  457. do {
  458. if ((pOD->fOptState & OPTST_OMITTED) != 0)
  459. continue;
  460. if ((pOD->fOptState & OPTST_DOCUMENT) != 0) {
  461. if (ex_code == EXIT_SUCCESS) {
  462. fprintf(option_usage_fp, argTypes.pzBrk, pOD->pzText,
  463. pOptTitle);
  464. docCt++;
  465. }
  466. continue;
  467. }
  468. /*
  469. * IF this is the first auto-opt maintained option
  470. * *AND* we are doing a full help
  471. * *AND* there are documentation options
  472. * *AND* the last one was not a doc option,
  473. * THEN document that the remaining options are not user opts
  474. */
  475. if ( (pOpts->presetOptCt == optNo)
  476. && (ex_code == EXIT_SUCCESS)
  477. && (docCt > 0)
  478. && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) )
  479. fprintf( option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle );
  480. printOneUsage( pOpts, pOD, &argTypes );
  481. /*
  482. * IF we were invoked because of the --help option,
  483. * THEN print all the extra info
  484. */
  485. if (ex_code == EXIT_SUCCESS)
  486. printExtendedUsage( pOpts, pOD, &argTypes );
  487. } while (pOD++, optNo++, (--ct > 0));
  488. fputc( '\n', option_usage_fp );
  489. }
  490. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  491. *
  492. * PROGRAM DETAILS
  493. */
  494. static void
  495. printProgramDetails( tOptions* pOptions )
  496. {
  497. ag_bool initIntro = AG_TRUE;
  498. /*
  499. * Display all the places we look for config files
  500. */
  501. printInitList( pOptions->papzHomeList, &initIntro,
  502. pOptions->pzRcName, pOptions->pzProgPath );
  503. /*
  504. * Let the user know about environment variable settings
  505. */
  506. if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) {
  507. if (initIntro)
  508. fputs( zPresetIntro, option_usage_fp );
  509. fprintf( option_usage_fp, zExamineFmt, pOptions->pzPROGNAME );
  510. }
  511. /*
  512. * IF we found an enumeration,
  513. * THEN hunt for it again. Call the handler proc with a NULL
  514. * option struct pointer. That tells it to display the keywords.
  515. */
  516. if (displayEnum) {
  517. int ct = pOptions->optCt;
  518. int optNo = 0;
  519. tOptDesc* pOD = pOptions->pOptDesc;
  520. fputc( '\n', option_usage_fp );
  521. fflush( option_usage_fp );
  522. do {
  523. switch (OPTST_GET_ARGTYPE(pOD->fOptState)) {
  524. case OPARG_TYPE_ENUMERATION:
  525. case OPARG_TYPE_MEMBERSHIP:
  526. (*(pOD->pOptProc))( NULL, pOD );
  527. }
  528. } while (pOD++, optNo++, (--ct > 0));
  529. }
  530. /*
  531. * If there is a detail string, now is the time for that.
  532. */
  533. if (pOptions->pzDetail != NULL)
  534. fputs( pOptions->pzDetail, option_usage_fp );
  535. }
  536. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  537. *
  538. * OPTION LINE FORMATTING SETUP
  539. *
  540. * The "OptFmt" formats receive three arguments:
  541. * 1. the type of the option's argument
  542. * 2. the long name of the option
  543. * 3. "YES" or "no ", depending on whether or not the option must appear
  544. * on the command line.
  545. * These formats are used immediately after the option flag (if used) has
  546. * been printed.
  547. *
  548. * Set up the formatting for GNU-style output
  549. */
  550. static int
  551. setGnuOptFmts( tOptions* pOpts, tCC** ppT )
  552. {
  553. int flen = 22;
  554. *ppT = zNoRq_ShrtTtl;
  555. argTypes.pzStr = zGnuStrArg;
  556. argTypes.pzReq = zOneSpace;
  557. argTypes.pzNum = zGnuNumArg;
  558. argTypes.pzKey = zGnuKeyArg;
  559. argTypes.pzKeyL = zGnuKeyLArg;
  560. argTypes.pzBool = zGnuBoolArg;
  561. argTypes.pzNest = zGnuNestArg;
  562. argTypes.pzOpt = zGnuOptArg;
  563. argTypes.pzNo = zOneSpace;
  564. argTypes.pzBrk = zGnuBreak;
  565. argTypes.pzNoF = zSixSpaces;
  566. argTypes.pzSpc = zThreeSpaces;
  567. switch (pOpts->fOptSet & OPTPROC_L_N_S) {
  568. case OPTPROC_L_N_S: argTypes.pzOptFmt = zGnuOptFmt; break;
  569. case OPTPROC_LONGOPT: argTypes.pzOptFmt = zGnuOptFmt; break;
  570. case 0: argTypes.pzOptFmt = zGnuOptFmt + 2; break;
  571. case OPTPROC_SHORTOPT:
  572. argTypes.pzOptFmt = zShrtGnuOptFmt;
  573. zGnuStrArg[0] = zGnuNumArg[0] = zGnuKeyArg[0] = zGnuBoolArg[0] = ' ';
  574. argTypes.pzOpt = " [arg]";
  575. flen = 8;
  576. break;
  577. }
  578. return flen;
  579. }
  580. /*
  581. * Standard (AutoOpts normal) option line formatting
  582. */
  583. static int
  584. setStdOptFmts( tOptions* pOpts, tCC** ppT )
  585. {
  586. int flen = 0;
  587. argTypes.pzStr = zStdStrArg;
  588. argTypes.pzReq = zStdReqArg;
  589. argTypes.pzNum = zStdNumArg;
  590. argTypes.pzKey = zStdKeyArg;
  591. argTypes.pzKeyL = zStdKeyLArg;
  592. argTypes.pzBool = zStdBoolArg;
  593. argTypes.pzNest = zStdNestArg;
  594. argTypes.pzOpt = zStdOptArg;
  595. argTypes.pzNo = zStdNoArg;
  596. argTypes.pzBrk = zStdBreak;
  597. argTypes.pzNoF = zFiveSpaces;
  598. argTypes.pzSpc = zTwoSpaces;
  599. switch (pOpts->fOptSet & (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT)) {
  600. case (OPTPROC_NO_REQ_OPT | OPTPROC_SHORTOPT):
  601. *ppT = zNoRq_ShrtTtl;
  602. argTypes.pzOptFmt = zNrmOptFmt;
  603. flen = 19;
  604. break;
  605. case OPTPROC_NO_REQ_OPT:
  606. *ppT = zNoRq_NoShrtTtl;
  607. argTypes.pzOptFmt = zNrmOptFmt;
  608. flen = 19;
  609. break;
  610. case OPTPROC_SHORTOPT:
  611. *ppT = zReq_ShrtTtl;
  612. argTypes.pzOptFmt = zReqOptFmt;
  613. flen = 24;
  614. break;
  615. case 0:
  616. *ppT = zReq_NoShrtTtl;
  617. argTypes.pzOptFmt = zReqOptFmt;
  618. flen = 24;
  619. }
  620. return flen;
  621. }
  622. /*:
  623. * Local Variables:
  624. * mode: C
  625. * c-file-style: "stroustrup"
  626. * indent-tabs-mode: nil
  627. * End:
  628. * end of autoopts/usage.c */