version.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* $Id: version.c,v 4.9 2006/09/24 02:11:16 bkorb Exp $
  2. * Time-stamp: "2006-09-22 18:15:00 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, copyright (c) 1999-2006 Bruce Korb\n";
  9. /* Automated Options is free software.
  10. * You may redistribute it and/or modify it under the terms of the
  11. * GNU General Public License, as published by the Free Software
  12. * Foundation; either version 2, or (at your option) any later version.
  13. *
  14. * Automated Options is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with Automated Options. See the file "COPYING". If not,
  21. * write to: The Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301, USA.
  24. *
  25. * As a special exception, Bruce Korb gives permission for additional
  26. * uses of the text contained in his release of AutoOpts.
  27. *
  28. * The exception is that, if you link the AutoOpts library with other
  29. * files to produce an executable, this does not by itself cause the
  30. * resulting executable to be covered by the GNU General Public License.
  31. * Your use of that executable is in no way restricted on account of
  32. * linking the AutoOpts library code into it.
  33. *
  34. * This exception does not however invalidate any other reasons why
  35. * the executable file might be covered by the GNU General Public License.
  36. *
  37. * This exception applies only to the code released by Bruce Korb under
  38. * the name AutoOpts. If you copy code from other sources under the
  39. * General Public License into a copy of AutoOpts, as the General Public
  40. * License permits, the exception does not apply to the code that you add
  41. * in this way. To avoid misleading anyone as to the status of such
  42. * modified files, you must delete this exception notice from them.
  43. *
  44. * If you write modifications of your own for AutoOpts, it is your choice
  45. * whether to permit this exception to apply to your modifications.
  46. * If you do not wish that, delete this exception notice.
  47. */
  48. /* = = = START-STATIC-FORWARD = = = */
  49. /* static forward declarations maintained by :mkfwd */
  50. static void
  51. printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
  52. /* = = = END-STATIC-FORWARD = = = */
  53. /*=export_func optionVersion
  54. *
  55. * what: return the compiled AutoOpts version number
  56. * ret_type: char const*
  57. * ret_desc: the version string in constant memory
  58. * doc:
  59. * Returns the full version string compiled into the library.
  60. * The returned string cannot be modified.
  61. =*/
  62. char const*
  63. optionVersion( void )
  64. {
  65. static char const zVersion[] =
  66. STR( AO_CURRENT.AO_REVISION );
  67. return zVersion;
  68. }
  69. static void
  70. printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
  71. {
  72. char swCh;
  73. if (pOD->optArg.argString == NULL)
  74. swCh = 'v';
  75. else swCh = pOD->optArg.argString[0];
  76. if (pOpts->pzFullVersion != NULL) {
  77. fputs( pOpts->pzFullVersion, fp );
  78. fputc( '\n', fp );
  79. } else {
  80. char const *pz = pOpts->pzUsageTitle;
  81. do { fputc( *pz, fp ); } while (*(pz++) != '\n');
  82. }
  83. switch (swCh) {
  84. case NUL:
  85. case 'v':
  86. case 'V':
  87. break;
  88. case 'c':
  89. case 'C':
  90. if (pOpts->pzCopyright != NULL) {
  91. fputs( pOpts->pzCopyright, 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. case 'n':
  99. case 'N':
  100. if (pOpts->pzCopyright != NULL) {
  101. fputs( pOpts->pzCopyright, fp );
  102. fputc( '\n', fp );
  103. fputc( '\n', fp );
  104. }
  105. if (pOpts->pzCopyNotice != NULL) {
  106. fputs( pOpts->pzCopyNotice, fp );
  107. fputc( '\n', fp );
  108. }
  109. fprintf( fp, zAOV, optionVersion() );
  110. if (pOpts->pzBugAddr != NULL)
  111. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  112. break;
  113. default:
  114. fprintf( stderr, zBadVerArg, swCh );
  115. exit( EXIT_FAILURE );
  116. }
  117. exit( EXIT_SUCCESS );
  118. }
  119. /*=export_func optionPrintVersion
  120. * private:
  121. *
  122. * what: Print the program version
  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 stdout.
  128. =*/
  129. void
  130. optionPrintVersion( tOptions* pOpts, tOptDesc* pOD )
  131. {
  132. printVersion( pOpts, pOD, stdout );
  133. }
  134. /*=export_func optionVersionStderr
  135. * private:
  136. *
  137. * what: Print the program version to stderr
  138. * arg: + tOptions* + pOpts + program options descriptor +
  139. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  140. *
  141. * doc:
  142. * This routine will print the version to stderr.
  143. =*/
  144. void
  145. optionVersionStderr( tOptions* pOpts, tOptDesc* pOD )
  146. {
  147. printVersion( pOpts, pOD, stderr );
  148. }
  149. /*
  150. * Local Variables:
  151. * mode: C
  152. * c-file-style: "stroustrup"
  153. * indent-tabs-mode: nil
  154. * End:
  155. * end of autoopts/version.c */