1
0

version.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* $Id: version.c,v 4.4 2005/03/13 19:52:00 bkorb Exp $
  2. * Time-stamp: "2005-02-14 08:19:54 bkorb"
  3. *
  4. * This module implements the default usage procedure for
  5. * Automated Options. It may be overridden, of course.
  6. */
  7. static const char zAOV[] =
  8. "Automated Options version %s, copyright (c) 1999-2005 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. * 59 Temple Place - Suite 330,
  23. * Boston, MA 02111-1307, 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: const char*
  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. const char*
  63. optionVersion( void )
  64. {
  65. static const char 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->pzLastArg == NULL)
  74. swCh = 'v';
  75. else swCh = pOD->pzLastArg[0];
  76. if (pOpts->pzFullVersion != NULL)
  77. fputs( pOpts->pzFullVersion, fp );
  78. else fputs( pOpts->pzProgName, fp );
  79. fputc( '\n', fp );
  80. switch (swCh) {
  81. case NUL:
  82. case 'v':
  83. case 'V':
  84. break;
  85. case 'c':
  86. case 'C':
  87. if (pOpts->pzCopyright != NULL) {
  88. fputs( pOpts->pzCopyright, fp );
  89. fputc( '\n', fp );
  90. }
  91. fprintf( fp, zAOV, optionVersion() );
  92. if (pOpts->pzBugAddr != NULL)
  93. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  94. break;
  95. case 'n':
  96. case 'N':
  97. if (pOpts->pzCopyright != NULL) {
  98. fputs( pOpts->pzCopyright, fp );
  99. fputc( '\n', fp );
  100. fputc( '\n', fp );
  101. }
  102. if (pOpts->pzCopyNotice != NULL) {
  103. fputs( pOpts->pzCopyNotice, fp );
  104. fputc( '\n', fp );
  105. }
  106. fprintf( fp, zAOV, optionVersion() );
  107. if (pOpts->pzBugAddr != NULL)
  108. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  109. break;
  110. default:
  111. fprintf( stderr, zBadVerArg, swCh );
  112. exit( EXIT_FAILURE );
  113. }
  114. exit( EXIT_SUCCESS );
  115. }
  116. /*=export_func optionPrintVersion
  117. * private:
  118. *
  119. * what: Print the program version
  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 stdout.
  125. =*/
  126. void
  127. optionPrintVersion( pOpts, pOD )
  128. tOptions* pOpts;
  129. tOptDesc* pOD;
  130. {
  131. printVersion( pOpts, pOD, stdout );
  132. }
  133. /*=export_func optionVersionStderr
  134. * private:
  135. *
  136. * what: Print the program version to stderr
  137. * arg: + tOptions* + pOpts + program options descriptor +
  138. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  139. *
  140. * doc:
  141. * This routine will print the version to stderr.
  142. =*/
  143. void
  144. optionVersionStderr( pOpts, pOD )
  145. tOptions* pOpts;
  146. tOptDesc* pOD;
  147. {
  148. printVersion( pOpts, pOD, stderr );
  149. }
  150. /*
  151. * Local Variables:
  152. * mode: C
  153. * c-file-style: "stroustrup"
  154. * tab-width: 4
  155. * indent-tabs-mode: nil
  156. * End:
  157. * end of autoopts/version.c */