turns printfs back on
[freebsd-src/fkvm-freebsd.git] / contrib / ntp / libopts / version.c
blob85949d5d3f3b2638cbcc85419e94e418ceca4047
2 /* $Id: version.c,v 4.10 2007/04/28 22:19:23 bkorb Exp $
3 * Time-stamp: "2007-04-28 10:08:34 bkorb"
5 * This module implements the default usage procedure for
6 * Automated Options. It may be overridden, of course.
7 */
9 static char const zAOV[] =
10 "Automated Options version %s, copyright (c) 1999-2007 Bruce Korb\n";
12 /* Automated Options is free software.
13 * You may redistribute it and/or modify it under the terms of the
14 * GNU General Public License, as published by the Free Software
15 * Foundation; either version 2, or (at your option) any later version.
17 * Automated Options is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Automated Options. See the file "COPYING". If not,
24 * write to: The Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA.
28 * As a special exception, Bruce Korb gives permission for additional
29 * uses of the text contained in his release of AutoOpts.
31 * The exception is that, if you link the AutoOpts library with other
32 * files to produce an executable, this does not by itself cause the
33 * resulting executable to be covered by the GNU General Public License.
34 * Your use of that executable is in no way restricted on account of
35 * linking the AutoOpts library code into it.
37 * This exception does not however invalidate any other reasons why
38 * the executable file might be covered by the GNU General Public License.
40 * This exception applies only to the code released by Bruce Korb under
41 * the name AutoOpts. If you copy code from other sources under the
42 * General Public License into a copy of AutoOpts, as the General Public
43 * License permits, the exception does not apply to the code that you add
44 * in this way. To avoid misleading anyone as to the status of such
45 * modified files, you must delete this exception notice from them.
47 * If you write modifications of your own for AutoOpts, it is your choice
48 * whether to permit this exception to apply to your modifications.
49 * If you do not wish that, delete this exception notice.
52 /* = = = START-STATIC-FORWARD = = = */
53 /* static forward declarations maintained by :mkfwd */
54 static void
55 printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
56 /* = = = END-STATIC-FORWARD = = = */
58 /*=export_func optionVersion
60 * what: return the compiled AutoOpts version number
61 * ret_type: char const*
62 * ret_desc: the version string in constant memory
63 * doc:
64 * Returns the full version string compiled into the library.
65 * The returned string cannot be modified.
66 =*/
67 char const*
68 optionVersion( void )
70 static char const zVersion[] =
71 STR( AO_CURRENT.AO_REVISION );
73 return zVersion;
77 static void
78 printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
80 char swCh;
83 * IF the optional argument flag is off, or the argument is not provided,
84 * then just print the version.
86 if ( ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
87 || (pOD->optArg.argString == NULL))
88 swCh = 'v';
89 else swCh = tolower(pOD->optArg.argString[0]);
91 if (pOpts->pzFullVersion != NULL) {
92 fputs( pOpts->pzFullVersion, fp );
93 fputc( '\n', fp );
95 } else {
96 char const *pz = pOpts->pzUsageTitle;
97 do { fputc(*pz, fp); } while (*(pz++) != '\n');
100 switch (swCh) {
101 case NUL: /* arg provided, but empty */
102 case 'v':
103 break;
105 case 'c':
106 if (pOpts->pzCopyright != NULL) {
107 fputs( pOpts->pzCopyright, fp );
108 fputc( '\n', fp );
110 fprintf( fp, zAOV, optionVersion() );
111 if (pOpts->pzBugAddr != NULL)
112 fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
113 break;
115 case 'n':
116 if (pOpts->pzCopyright != NULL) {
117 fputs( pOpts->pzCopyright, fp );
118 fputc( '\n', fp );
119 fputc( '\n', fp );
122 if (pOpts->pzCopyNotice != NULL) {
123 fputs( pOpts->pzCopyNotice, fp );
124 fputc( '\n', fp );
127 fprintf( fp, zAOV, optionVersion() );
128 if (pOpts->pzBugAddr != NULL)
129 fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
130 break;
132 default:
133 fprintf( stderr, zBadVerArg, swCh );
134 exit( EXIT_FAILURE );
137 exit( EXIT_SUCCESS );
140 /*=export_func optionPrintVersion
141 * private:
143 * what: Print the program version
144 * arg: + tOptions* + pOpts + program options descriptor +
145 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
147 * doc:
148 * This routine will print the version to stdout.
150 void
151 optionPrintVersion( tOptions* pOpts, tOptDesc* pOD )
153 printVersion( pOpts, pOD, stdout );
156 /*=export_func optionVersionStderr
157 * private:
159 * what: Print the program version to stderr
160 * arg: + tOptions* + pOpts + program options descriptor +
161 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
163 * doc:
164 * This routine will print the version to stderr.
166 void
167 optionVersionStderr( tOptions* pOpts, tOptDesc* pOD )
169 printVersion( pOpts, pOD, stderr );
173 * Local Variables:
174 * mode: C
175 * c-file-style: "stroustrup"
176 * indent-tabs-mode: nil
177 * End:
178 * end of autoopts/version.c */