version.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* $Id: version.c,v 4.15 2008/07/28 04:51:30 bkorb Exp $
  2. * Time-stamp: "2008-07-27 10:11:30 bkorb"
  3. *
  4. * This module implements the default usage procedure for
  5. * Automated Options. It may be overridden, of course.
  6. */
  7. /*
  8. * This file is part of AutoOpts, a companion to AutoGen.
  9. * AutoOpts is free software.
  10. * AutoOpts is copyright (c) 1992-2008 by Bruce Korb - all rights reserved
  11. * AutoOpts is copyright (c) 1992-2008 by Bruce Korb - all rights reserved
  12. *
  13. * AutoOpts is available under any one of two licenses. The license
  14. * in use must be one of these two and the choice is under the control
  15. * of the user of the license.
  16. *
  17. * The GNU Lesser General Public License, version 3 or later
  18. * See the files "COPYING.lgplv3" and "COPYING.gplv3"
  19. *
  20. * The Modified Berkeley Software Distribution License
  21. * See the file "COPYING.mbsd"
  22. *
  23. * These files have the following md5sums:
  24. *
  25. * 239588c55c22c60ffe159946a760a33e pkg/libopts/COPYING.gplv3
  26. * fa82ca978890795162346e661b47161a pkg/libopts/COPYING.lgplv3
  27. * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
  28. */
  29. /* = = = START-STATIC-FORWARD = = = */
  30. /* static forward declarations maintained by mk-fwd */
  31. static void
  32. printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
  33. /* = = = END-STATIC-FORWARD = = = */
  34. /*=export_func optionVersion
  35. *
  36. * what: return the compiled AutoOpts version number
  37. * ret_type: char const*
  38. * ret_desc: the version string in constant memory
  39. * doc:
  40. * Returns the full version string compiled into the library.
  41. * The returned string cannot be modified.
  42. =*/
  43. char const*
  44. optionVersion( void )
  45. {
  46. static char const zVersion[] =
  47. STR( AO_CURRENT.AO_REVISION );
  48. return zVersion;
  49. }
  50. static void
  51. printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
  52. {
  53. char swCh;
  54. /*
  55. * IF the optional argument flag is off, or the argument is not provided,
  56. * then just print the version.
  57. */
  58. if ( ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
  59. || (pOD->optArg.argString == NULL))
  60. swCh = 'v';
  61. else swCh = tolower(pOD->optArg.argString[0]);
  62. if (pOpts->pzFullVersion != NULL) {
  63. fputs( pOpts->pzFullVersion, fp );
  64. fputc( '\n', fp );
  65. } else {
  66. char const *pz = pOpts->pzUsageTitle;
  67. do { fputc(*pz, fp); } while (*(pz++) != '\n');
  68. }
  69. switch (swCh) {
  70. case NUL: /* arg provided, but empty */
  71. case 'v':
  72. break;
  73. case 'c':
  74. if (pOpts->pzCopyright != NULL) {
  75. fputs( pOpts->pzCopyright, fp );
  76. fputc( '\n', fp );
  77. }
  78. fprintf( fp, zAO_Ver, optionVersion() );
  79. if (pOpts->pzBugAddr != NULL)
  80. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  81. break;
  82. case 'n':
  83. if (pOpts->pzCopyright != NULL) {
  84. fputs( pOpts->pzCopyright, fp );
  85. fputc( '\n', fp );
  86. fputc( '\n', fp );
  87. }
  88. if (pOpts->pzCopyNotice != NULL) {
  89. fputs( pOpts->pzCopyNotice, fp );
  90. fputc( '\n', fp );
  91. }
  92. fprintf( fp, zAO_Ver, optionVersion() );
  93. if (pOpts->pzBugAddr != NULL)
  94. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  95. break;
  96. default:
  97. fprintf( stderr, zBadVerArg, swCh );
  98. exit( EXIT_FAILURE );
  99. }
  100. exit( EXIT_SUCCESS );
  101. }
  102. /*=export_func optionPrintVersion
  103. * private:
  104. *
  105. * what: Print the program version
  106. * arg: + tOptions* + pOpts + program options descriptor +
  107. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  108. *
  109. * doc:
  110. * This routine will print the version to stdout.
  111. =*/
  112. void
  113. optionPrintVersion( tOptions* pOpts, tOptDesc* pOD )
  114. {
  115. printVersion( pOpts, pOD, stdout );
  116. }
  117. /*=export_func optionVersionStderr
  118. * private:
  119. *
  120. * what: Print the program version to stderr
  121. * arg: + tOptions* + pOpts + program options descriptor +
  122. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  123. *
  124. * doc:
  125. * This routine will print the version to stderr.
  126. =*/
  127. void
  128. optionVersionStderr( tOptions* pOpts, tOptDesc* pOD )
  129. {
  130. printVersion( pOpts, pOD, stderr );
  131. }
  132. /*
  133. * Local Variables:
  134. * mode: C
  135. * c-file-style: "stroustrup"
  136. * indent-tabs-mode: nil
  137. * End:
  138. * end of autoopts/version.c */