version.c 4.1 KB

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