version.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* $Id: version.c,v 4.10 2007/04/28 22:19:23 bkorb Exp $
  2. * Time-stamp: "2007-04-28 10:08:34 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-2007 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. /*
  74. * IF the optional argument flag is off, or the argument is not provided,
  75. * then just print the version.
  76. */
  77. if ( ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
  78. || (pOD->optArg.argString == NULL))
  79. swCh = 'v';
  80. else swCh = tolower(pOD->optArg.argString[0]);
  81. if (pOpts->pzFullVersion != NULL) {
  82. fputs( pOpts->pzFullVersion, fp );
  83. fputc( '\n', fp );
  84. } else {
  85. char const *pz = pOpts->pzUsageTitle;
  86. do { fputc(*pz, fp); } while (*(pz++) != '\n');
  87. }
  88. switch (swCh) {
  89. case NUL: /* arg provided, but empty */
  90. case 'v':
  91. break;
  92. case 'c':
  93. if (pOpts->pzCopyright != NULL) {
  94. fputs( pOpts->pzCopyright, fp );
  95. fputc( '\n', fp );
  96. }
  97. fprintf( fp, zAOV, optionVersion() );
  98. if (pOpts->pzBugAddr != NULL)
  99. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  100. break;
  101. case 'n':
  102. if (pOpts->pzCopyright != NULL) {
  103. fputs( pOpts->pzCopyright, fp );
  104. fputc( '\n', fp );
  105. fputc( '\n', fp );
  106. }
  107. if (pOpts->pzCopyNotice != NULL) {
  108. fputs( pOpts->pzCopyNotice, fp );
  109. fputc( '\n', fp );
  110. }
  111. fprintf( fp, zAOV, optionVersion() );
  112. if (pOpts->pzBugAddr != NULL)
  113. fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
  114. break;
  115. default:
  116. fprintf( stderr, zBadVerArg, swCh );
  117. exit( EXIT_FAILURE );
  118. }
  119. exit( EXIT_SUCCESS );
  120. }
  121. /*=export_func optionPrintVersion
  122. * private:
  123. *
  124. * what: Print the program version
  125. * arg: + tOptions* + pOpts + program options descriptor +
  126. * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
  127. *
  128. * doc:
  129. * This routine will print the version to stdout.
  130. =*/
  131. void
  132. optionPrintVersion( tOptions* pOpts, 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( tOptions* pOpts, tOptDesc* pOD )
  148. {
  149. printVersion( pOpts, pOD, stderr );
  150. }
  151. /*
  152. * Local Variables:
  153. * mode: C
  154. * c-file-style: "stroustrup"
  155. * indent-tabs-mode: nil
  156. * End:
  157. * end of autoopts/version.c */