1
0

version.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* $Id: version.c,v 4.7 2006/03/25 19:24:57 bkorb Exp $
  2. * Time-stamp: "2005-12-13 10:29:09 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-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: 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. fputc( '\n', fp );
  79. } else {
  80. const char *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( pOpts, pOD )
  131. tOptions* pOpts;
  132. tOptDesc* pOD;
  133. {
  134. printVersion( pOpts, pOD, stdout );
  135. }
  136. /*=export_func optionVersionStderr
  137. * private:
  138. *
  139. * what: Print the program version to stderr
  140. * arg: + tOptions* + pOpts + program options descriptor +
  141. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  142. *
  143. * doc:
  144. * This routine will print the version to stderr.
  145. =*/
  146. void
  147. optionVersionStderr( pOpts, pOD )
  148. tOptions* pOpts;
  149. tOptDesc* pOD;
  150. {
  151. printVersion( pOpts, pOD, stderr );
  152. }
  153. /*
  154. * Local Variables:
  155. * mode: C
  156. * c-file-style: "stroustrup"
  157. * tab-width: 4
  158. * indent-tabs-mode: nil
  159. * End:
  160. * end of autoopts/version.c */