1181834Sroberto
2181834Sroberto/*  $Id: version.c,v 4.10 2007/04/28 22:19:23 bkorb Exp $
3181834Sroberto * Time-stamp:      "2007-04-28 10:08:34 bkorb"
4181834Sroberto *
5181834Sroberto *  This module implements the default usage procedure for
6181834Sroberto *  Automated Options.  It may be overridden, of course.
7181834Sroberto */
8181834Sroberto
9181834Srobertostatic char const zAOV[] =
10181834Sroberto    "Automated Options version %s, copyright (c) 1999-2007 Bruce Korb\n";
11181834Sroberto
12181834Sroberto/*  Automated Options is free software.
13181834Sroberto *  You may redistribute it and/or modify it under the terms of the
14181834Sroberto *  GNU General Public License, as published by the Free Software
15181834Sroberto *  Foundation; either version 2, or (at your option) any later version.
16181834Sroberto *
17181834Sroberto *  Automated Options is distributed in the hope that it will be useful,
18181834Sroberto *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19181834Sroberto *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20181834Sroberto *  GNU General Public License for more details.
21181834Sroberto *
22181834Sroberto *  You should have received a copy of the GNU General Public License
23181834Sroberto *  along with Automated Options.  See the file "COPYING".  If not,
24181834Sroberto *  write to:  The Free Software Foundation, Inc.,
25181834Sroberto *             51 Franklin Street, Fifth Floor,
26181834Sroberto *             Boston, MA  02110-1301, USA.
27181834Sroberto *
28181834Sroberto * As a special exception, Bruce Korb gives permission for additional
29181834Sroberto * uses of the text contained in his release of AutoOpts.
30181834Sroberto *
31181834Sroberto * The exception is that, if you link the AutoOpts library with other
32181834Sroberto * files to produce an executable, this does not by itself cause the
33181834Sroberto * resulting executable to be covered by the GNU General Public License.
34181834Sroberto * Your use of that executable is in no way restricted on account of
35181834Sroberto * linking the AutoOpts library code into it.
36181834Sroberto *
37181834Sroberto * This exception does not however invalidate any other reasons why
38181834Sroberto * the executable file might be covered by the GNU General Public License.
39181834Sroberto *
40181834Sroberto * This exception applies only to the code released by Bruce Korb under
41181834Sroberto * the name AutoOpts.  If you copy code from other sources under the
42181834Sroberto * General Public License into a copy of AutoOpts, as the General Public
43181834Sroberto * License permits, the exception does not apply to the code that you add
44181834Sroberto * in this way.  To avoid misleading anyone as to the status of such
45181834Sroberto * modified files, you must delete this exception notice from them.
46181834Sroberto *
47181834Sroberto * If you write modifications of your own for AutoOpts, it is your choice
48181834Sroberto * whether to permit this exception to apply to your modifications.
49181834Sroberto * If you do not wish that, delete this exception notice.
50181834Sroberto */
51181834Sroberto
52181834Sroberto/* = = = START-STATIC-FORWARD = = = */
53181834Sroberto/* static forward declarations maintained by :mkfwd */
54181834Srobertostatic void
55181834SrobertoprintVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp );
56181834Sroberto/* = = = END-STATIC-FORWARD = = = */
57181834Sroberto
58181834Sroberto/*=export_func  optionVersion
59181834Sroberto *
60181834Sroberto * what:     return the compiled AutoOpts version number
61181834Sroberto * ret_type: char const*
62181834Sroberto * ret_desc: the version string in constant memory
63181834Sroberto * doc:
64181834Sroberto *  Returns the full version string compiled into the library.
65181834Sroberto *  The returned string cannot be modified.
66181834Sroberto=*/
67181834Srobertochar const*
68181834SrobertooptionVersion( void )
69181834Sroberto{
70181834Sroberto    static char const zVersion[] =
71181834Sroberto        STR( AO_CURRENT.AO_REVISION );
72181834Sroberto
73181834Sroberto    return zVersion;
74181834Sroberto}
75181834Sroberto
76181834Sroberto
77181834Srobertostatic void
78181834SrobertoprintVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp )
79181834Sroberto{
80181834Sroberto    char swCh;
81181834Sroberto
82181834Sroberto    /*
83181834Sroberto     *  IF the optional argument flag is off, or the argument is not provided,
84181834Sroberto     *  then just print the version.
85181834Sroberto     */
86181834Sroberto    if (  ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
87181834Sroberto       || (pOD->optArg.argString == NULL))
88181834Sroberto         swCh = 'v';
89181834Sroberto    else swCh = tolower(pOD->optArg.argString[0]);
90181834Sroberto
91181834Sroberto    if (pOpts->pzFullVersion != NULL) {
92181834Sroberto        fputs( pOpts->pzFullVersion, fp );
93181834Sroberto        fputc( '\n', fp );
94181834Sroberto
95181834Sroberto    } else {
96181834Sroberto        char const *pz = pOpts->pzUsageTitle;
97181834Sroberto        do { fputc(*pz, fp); } while (*(pz++) != '\n');
98181834Sroberto    }
99181834Sroberto
100181834Sroberto    switch (swCh) {
101181834Sroberto    case NUL: /* arg provided, but empty */
102181834Sroberto    case 'v':
103181834Sroberto        break;
104181834Sroberto
105181834Sroberto    case 'c':
106181834Sroberto        if (pOpts->pzCopyright != NULL) {
107181834Sroberto            fputs( pOpts->pzCopyright, fp );
108181834Sroberto            fputc( '\n', fp );
109181834Sroberto        }
110181834Sroberto        fprintf( fp, zAOV, optionVersion() );
111181834Sroberto        if (pOpts->pzBugAddr != NULL)
112181834Sroberto            fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
113181834Sroberto        break;
114181834Sroberto
115181834Sroberto    case 'n':
116181834Sroberto        if (pOpts->pzCopyright != NULL) {
117181834Sroberto            fputs( pOpts->pzCopyright, fp );
118181834Sroberto            fputc( '\n', fp );
119181834Sroberto            fputc( '\n', fp );
120181834Sroberto        }
121181834Sroberto
122181834Sroberto        if (pOpts->pzCopyNotice != NULL) {
123181834Sroberto            fputs( pOpts->pzCopyNotice, fp );
124181834Sroberto            fputc( '\n', fp );
125181834Sroberto        }
126181834Sroberto
127181834Sroberto        fprintf( fp, zAOV, optionVersion() );
128181834Sroberto        if (pOpts->pzBugAddr != NULL)
129181834Sroberto            fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr );
130181834Sroberto        break;
131181834Sroberto
132181834Sroberto    default:
133181834Sroberto        fprintf( stderr, zBadVerArg, swCh );
134181834Sroberto        exit( EXIT_FAILURE );
135181834Sroberto    }
136181834Sroberto
137181834Sroberto    exit( EXIT_SUCCESS );
138181834Sroberto}
139181834Sroberto
140181834Sroberto/*=export_func  optionPrintVersion
141181834Sroberto * private:
142181834Sroberto *
143181834Sroberto * what:  Print the program version
144181834Sroberto * arg:   + tOptions* + pOpts    + program options descriptor +
145181834Sroberto * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
146181834Sroberto *
147181834Sroberto * doc:
148181834Sroberto *  This routine will print the version to stdout.
149181834Sroberto=*/
150181834Srobertovoid
151181834SrobertooptionPrintVersion( tOptions*  pOpts, tOptDesc*  pOD )
152181834Sroberto{
153181834Sroberto    printVersion( pOpts, pOD, stdout );
154181834Sroberto}
155181834Sroberto
156181834Sroberto/*=export_func  optionVersionStderr
157181834Sroberto * private:
158181834Sroberto *
159181834Sroberto * what:  Print the program version to stderr
160181834Sroberto * arg:   + tOptions* + pOpts    + program options descriptor +
161181834Sroberto * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
162181834Sroberto *
163181834Sroberto * doc:
164181834Sroberto *  This routine will print the version to stderr.
165181834Sroberto=*/
166181834Srobertovoid
167181834SrobertooptionVersionStderr( tOptions*  pOpts, tOptDesc*  pOD )
168181834Sroberto{
169181834Sroberto    printVersion( pOpts, pOD, stderr );
170181834Sroberto}
171181834Sroberto
172181834Sroberto/*
173181834Sroberto * Local Variables:
174181834Sroberto * mode: C
175181834Sroberto * c-file-style: "stroustrup"
176181834Sroberto * indent-tabs-mode: nil
177181834Sroberto * End:
178181834Sroberto * end of autoopts/version.c */
179