4 * This module implements the default usage procedure for
5 * Automated Options. It may be overridden, of course.
11 * This file is part of AutoOpts, a companion to AutoGen.
12 * AutoOpts is free software.
13 * AutoOpts is Copyright (C) 1992-2015 by Bruce Korb - all rights reserved
15 * AutoOpts is available under any one of two licenses. The license
16 * in use must be one of these two and the choice is under the control
17 * of the user of the license.
19 * The GNU Lesser General Public License, version 3 or later
20 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
22 * The Modified Berkeley Software Distribution License
23 * See the file "COPYING.mbsd"
25 * These files have the following sha256 sums:
27 * 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3
28 * 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3
29 * 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd
32 /*=export_func optionVersion
34 * what: return the compiled AutoOpts version number
35 * ret_type: char const *
36 * ret_desc: the version string in constant memory
38 * Returns the full version string compiled into the library.
39 * The returned string cannot be modified.
44 static char const ver[] = OPTIONS_DOTTED_VERSION;
50 FILE * fp, char const * alt1, char const * alt2, char const * alt3)
52 char const * p = (alt1 != NULL) ? alt1 : ((alt2 != NULL) ? alt2 : alt3);
60 fwrite(p, 1, (e - p), fp);
65 * Select among various ways to emit version information.
67 * @param[in] o the option descriptor
68 * @param[in] fp the output stream
71 emit_simple_ver(tOptions * o, FILE * fp)
73 emit_first_line(fp, o->pzFullVersion, o->pzCopyright, o->pzUsageTitle);
77 * print the version with a copyright notice.
79 * @param[in] o the option descriptor
80 * @param[in] fp the output stream
83 emit_copy_full(tOptions * o, FILE * fp)
85 if (o->pzCopyright != NULL)
86 fputs(o->pzCopyright, fp);
88 else if (o->pzFullVersion != NULL)
89 fputs(o->pzFullVersion, fp);
92 emit_first_line(fp, o->pzUsageTitle, NULL, NULL);
94 if (HAS_pzPkgDataDir(o) && (o->pzPackager != NULL)) {
96 fputs(o->pzPackager, fp);
98 } else if (o->pzBugAddr != NULL) {
100 fprintf(fp, zPlsSendBugs, o->pzBugAddr);
105 * print the version and any copyright notice.
106 * The version with a full copyright and additional notes.
108 * @param[in] opts the option descriptor
109 * @param[in] fp the output stream
112 emit_copy_note(tOptions * opts, FILE * fp)
114 if (opts->pzCopyright != NULL)
115 fputs(opts->pzCopyright, fp);
117 if (opts->pzCopyNotice != NULL)
118 fputs(opts->pzCopyNotice, fp);
121 fprintf(fp, zao_ver_fmt, optionVersion());
123 if (HAS_pzPkgDataDir(opts) && (opts->pzPackager != NULL)) {
125 fputs(opts->pzPackager, fp);
127 } else if (opts->pzBugAddr != NULL) {
129 fprintf(fp, zPlsSendBugs, opts->pzBugAddr);
134 * Handle the version printing. We must see how much information
135 * is being requested and select the correct printing routine.
138 print_ver(tOptions * opts, tOptDesc * od, FILE * fp, bool call_exit)
142 if (opts <= OPTPROC_EMIT_LIMIT)
146 * IF we have an argument for this option, use it
147 * Otherwise, default to version only or copyright note,
148 * depending on whether the layout is GNU standard form or not.
150 if ( (od->fOptState & OPTST_ARG_OPTIONAL)
151 && (od->optArg.argString != NULL)
152 && (od->optArg.argString[0] != NUL))
154 ch = od->optArg.argString[0];
157 set_usage_flags(opts, NULL);
158 ch = (opts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
162 case NUL: /* arg provided, but empty */
163 case 'v': case 'V': emit_simple_ver(opts, fp); break;
164 case 'c': case 'C': emit_copy_full( opts, fp); break;
165 case 'n': case 'N': emit_copy_note( opts, fp); break;
168 fprintf(stderr, zBadVerArg, ch);
169 option_exits(EXIT_FAILURE);
174 fserr_exit(opts->pzProgName, zwriting,
175 (fp == stdout) ? zstdout_name : zstderr_name);
178 option_exits(EXIT_SUCCESS);
181 /*=export_func optionPrintVersion
183 * what: Print the program version
184 * arg: + tOptions * + opts + program options descriptor +
185 * arg: + tOptDesc * + od + the descriptor for this arg +
188 * This routine will print the version to stdout.
191 optionPrintVersion(tOptions * opts, tOptDesc * od)
193 print_ver(opts, od, print_exit ? stderr : stdout, true);
196 /*=export_func optionPrintVersionAndReturn
198 * what: Print the program version
199 * arg: + tOptions * + opts + program options descriptor +
200 * arg: + tOptDesc * + od + the descriptor for this arg +
203 * This routine will print the version to stdout and return
204 * instead of exiting. Please see the source for the
205 * @code{print_ver} funtion for details on selecting how
206 * verbose to be after this function returns.
209 optionPrintVersionAndReturn(tOptions * opts, tOptDesc * od)
211 print_ver(opts, od, print_exit ? stderr : stdout, false);
214 /*=export_func optionVersionStderr
217 * what: Print the program version to stderr
218 * arg: + tOptions * + opts + program options descriptor +
219 * arg: + tOptDesc * + od + the descriptor for this arg +
222 * This routine will print the version to stderr.
225 optionVersionStderr(tOptions * opts, tOptDesc * od)
227 print_ver(opts, od, stderr, true);
234 * c-file-style: "stroustrup"
235 * indent-tabs-mode: nil
237 * end of autoopts/version.c */