Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / sntp / libopts / version.c
blobe4cc7fa8ca7309853b304f63dec6bccbfca687e6
1 /* $NetBSD$ */
4 /* Id: e21e2bf9958c54e440efbdc7c1026e46ac589f66
5 * Time-stamp: "2008-07-27 10:11:30 bkorb"
7 * This module implements the default usage procedure for
8 * Automated Options. It may be overridden, of course.
9 */
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
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.
20 * The GNU Lesser General Public License, version 3 or later
21 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
23 * The Modified Berkeley Software Distribution License
24 * See the file "COPYING.mbsd"
26 * These files have the following md5sums:
28 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
29 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
30 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
33 /* = = = START-STATIC-FORWARD = = = */
34 /* static forward declarations maintained by mk-fwd */
35 static void
36 printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
37 /* = = = END-STATIC-FORWARD = = = */
39 /*=export_func optionVersion
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 =*/
48 char const*
49 optionVersion( void )
51 static char const zVersion[] =
52 STR( AO_CURRENT.AO_REVISION );
54 return zVersion;
58 static void
59 printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
61 char swCh;
64 * IF the optional argument flag is off, or the argument is not provided,
65 * then just print the version.
67 if ( ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
68 || (pOD->optArg.argString == NULL))
69 swCh = 'v';
70 else swCh = tolower(pOD->optArg.argString[0]);
72 if (pOpts->pzFullVersion != NULL) {
73 fputs( pOpts->pzFullVersion, fp );
74 fputc( '\n', fp );
76 } else {
77 char const *pz = pOpts->pzUsageTitle;
78 do { fputc(*pz, fp); } while (*(pz++) != '\n');
81 switch (swCh) {
82 case NUL: /* arg provided, but empty */
83 case 'v':
84 break;
86 case 'c':
87 if (pOpts->pzCopyright != NULL) {
88 fputs( pOpts->pzCopyright, fp );
89 fputc( '\n', fp );
91 fprintf( fp, zAO_Ver, optionVersion() );
92 if (pOpts->pzBugAddr != NULL)
93 fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
94 break;
96 case 'n':
97 if (pOpts->pzCopyright != NULL) {
98 fputs( pOpts->pzCopyright, fp );
99 fputc( '\n', fp );
100 fputc( '\n', fp );
103 if (pOpts->pzCopyNotice != NULL) {
104 fputs( pOpts->pzCopyNotice, fp );
105 fputc( '\n', fp );
108 fprintf( fp, zAO_Ver, optionVersion() );
109 if (pOpts->pzBugAddr != NULL)
110 fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
111 break;
113 default:
114 fprintf( stderr, zBadVerArg, swCh );
115 exit( EXIT_FAILURE );
118 exit( EXIT_SUCCESS );
121 /*=export_func optionPrintVersion
122 * private:
124 * what: Print the program version
125 * arg: + tOptions* + pOpts + program options descriptor +
126 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
128 * doc:
129 * This routine will print the version to stdout.
131 void
132 optionPrintVersion( tOptions* pOpts, tOptDesc* pOD )
134 printVersion( pOpts, pOD, stdout );
137 /*=export_func optionVersionStderr
138 * private:
140 * what: Print the program version to stderr
141 * arg: + tOptions* + pOpts + program options descriptor +
142 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
144 * doc:
145 * This routine will print the version to stderr.
147 void
148 optionVersionStderr( tOptions* pOpts, tOptDesc* pOD )
150 printVersion( pOpts, pOD, stderr );
154 * Local Variables:
155 * mode: C
156 * c-file-style: "stroustrup"
157 * indent-tabs-mode: nil
158 * End:
159 * end of autoopts/version.c */