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