version.c 4.2 KB

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