1/* $NetBSD: version.c,v 1.1.1.1 2009/12/13 16:55:15 kardel Exp $ */ 2 3 4/* Id: e21e2bf9958c54e440efbdc7c1026e46ac589f66 5 * Time-stamp: "2008-07-27 10:11:30 bkorb" 6 * 7 * This module implements the default usage procedure for 8 * Automated Options. It may be overridden, of course. 9 */ 10 11/* 12 * This file is part of AutoOpts, a companion to AutoGen. 13 * AutoOpts is free software. 14 * AutoOpts is copyright (c) 1992-2009 by Bruce Korb - all rights reserved 15 * 16 * AutoOpts is available under any one of two licenses. The license 17 * in use must be one of these two and the choice is under the control 18 * of the user of the license. 19 * 20 * The GNU Lesser General Public License, version 3 or later 21 * See the files "COPYING.lgplv3" and "COPYING.gplv3" 22 * 23 * The Modified Berkeley Software Distribution License 24 * See the file "COPYING.mbsd" 25 * 26 * These files have the following md5sums: 27 * 28 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 29 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 30 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd 31 */ 32 33/* = = = START-STATIC-FORWARD = = = */ 34/* static forward declarations maintained by mk-fwd */ 35static void 36printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ); 37/* = = = END-STATIC-FORWARD = = = */ 38 39/*=export_func optionVersion 40 * 41 * what: return the compiled AutoOpts version number 42 * ret_type: char const* 43 * ret_desc: the version string in constant memory 44 * doc: 45 * Returns the full version string compiled into the library. 46 * The returned string cannot be modified. 47=*/ 48char const* 49optionVersion( void ) 50{ 51 static char const zVersion[] = 52 STR( AO_CURRENT.AO_REVISION ); 53 54 return zVersion; 55} 56 57 58static void 59printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) 60{ 61 char swCh; 62 63 /* 64 * IF the optional argument flag is off, or the argument is not provided, 65 * then just print the version. 66 */ 67 if ( ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0) 68 || (pOD->optArg.argString == NULL)) 69 swCh = 'v'; 70 else swCh = tolower((unsigned char)pOD->optArg.argString[0]); 71 72 if (pOpts->pzFullVersion != NULL) { 73 fputs( pOpts->pzFullVersion, fp ); 74 fputc( '\n', fp ); 75 76 } else { 77 char const *pz = pOpts->pzUsageTitle; 78 do { fputc(*pz, fp); } while (*(pz++) != '\n'); 79 } 80 81 switch (swCh) { 82 case NUL: /* arg provided, but empty */ 83 case 'v': 84 break; 85 86 case 'c': 87 if (pOpts->pzCopyright != NULL) { 88 fputs( pOpts->pzCopyright, 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 96 case 'n': 97 if (pOpts->pzCopyright != NULL) { 98 fputs( pOpts->pzCopyright, fp ); 99 fputc( '\n', fp ); 100 fputc( '\n', fp ); 101 } 102 103 if (pOpts->pzCopyNotice != NULL) { 104 fputs( pOpts->pzCopyNotice, fp ); 105 fputc( '\n', fp ); 106 } 107 108 fprintf( fp, zAO_Ver, optionVersion() ); 109 if (pOpts->pzBugAddr != NULL) 110 fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr ); 111 break; 112 113 default: 114 fprintf( stderr, zBadVerArg, swCh ); 115 exit( EXIT_FAILURE ); 116 } 117 118 exit( EXIT_SUCCESS ); 119} 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=*/ 131void 132optionPrintVersion( tOptions* pOpts, tOptDesc* pOD ) 133{ 134 printVersion( pOpts, pOD, stdout ); 135} 136 137/*=export_func optionVersionStderr 138 * private: 139 * 140 * what: Print the program version to stderr 141 * arg: + tOptions* + pOpts + program options descriptor + 142 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + 143 * 144 * doc: 145 * This routine will print the version to stderr. 146=*/ 147void 148optionVersionStderr( tOptions* pOpts, tOptDesc* pOD ) 149{ 150 printVersion( pOpts, pOD, stderr ); 151} 152 153/* 154 * Local Variables: 155 * mode: C 156 * c-file-style: "stroustrup" 157 * indent-tabs-mode: nil 158 * End: 159 * end of autoopts/version.c */ 160