3 * Time-stamp: "2012-01-29 19:44:24 bkorb"
5 * This module implements the default usage procedure for
6 * Automated Options. It may be overridden, of course.
10 * This file is part of AutoOpts, a companion to AutoGen.
11 * AutoOpts is free software.
12 * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
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.
18 * The GNU Lesser General Public License, version 3 or later
19 * See the files "COPYING.lgplv3" and "COPYING.gplv3"
21 * The Modified Berkeley Software Distribution License
22 * See the file "COPYING.mbsd"
24 * These files have the following md5sums:
26 * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
27 * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
28 * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
31 /*=export_func optionVersion
33 * what: return the compiled AutoOpts version number
34 * ret_type: char const*
35 * ret_desc: the version string in constant memory
37 * Returns the full version string compiled into the library.
38 * The returned string cannot be modified.
43 static char const zVersion
[] =
44 STR(AO_CURRENT
.AO_REVISION
);
50 * Select among various ways to emit version information.
52 * @param pOpts the option descriptor
53 * @param fp the output stream
56 emit_simple_ver(tOptions
* pOpts
, FILE * fp
)
59 * Use the supplied string
61 if (pOpts
->pzFullVersion
!= NULL
)
62 fputs(pOpts
->pzFullVersion
, fp
);
65 * Extract the interesting part of the copyright string
67 else if (pOpts
->pzCopyright
!= NULL
) {
68 char const * pe
= strchr(pOpts
->pzCopyright
, NL
);
70 pe
= pOpts
->pzCopyright
+ strlen(pOpts
->pzCopyright
);
71 fwrite(pOpts
->pzCopyright
, 1, pe
- pOpts
->pzCopyright
, fp
);
75 * Extract the interesting part of the usage title string
78 char const * pe
= strchr(pOpts
->pzUsageTitle
, NL
);
80 pe
= pOpts
->pzUsageTitle
+ strlen(pOpts
->pzUsageTitle
);
81 fwrite(pOpts
->pzUsageTitle
, 1, pe
- pOpts
->pzUsageTitle
, fp
);
87 emit_copy_ver(tOptions
* pOpts
, FILE * fp
)
89 if (pOpts
->pzCopyright
!= NULL
)
90 fputs(pOpts
->pzCopyright
, fp
);
92 else if (pOpts
->pzFullVersion
!= NULL
)
93 fputs(pOpts
->pzFullVersion
, fp
);
96 char const * pe
= strchr(pOpts
->pzUsageTitle
, NL
);
98 pe
= pOpts
->pzUsageTitle
+ strlen(pOpts
->pzUsageTitle
);
99 fwrite(pOpts
->pzUsageTitle
, 1, pe
- pOpts
->pzCopyright
, fp
);
104 if (HAS_pzPkgDataDir(pOpts
) && (pOpts
->pzPackager
!= NULL
))
105 fputs(pOpts
->pzPackager
, fp
);
107 else if (pOpts
->pzBugAddr
!= NULL
)
108 fprintf(fp
, zPlsSendBugs
, pOpts
->pzBugAddr
);
112 emit_copy_note(tOptions
* pOpts
, FILE * fp
)
114 if (pOpts
->pzCopyright
!= NULL
) {
115 fputs(pOpts
->pzCopyright
, fp
);
119 if (pOpts
->pzCopyNotice
!= NULL
) {
120 fputs(pOpts
->pzCopyNotice
, fp
);
124 fprintf(fp
, zAO_Ver
, optionVersion());
126 if (HAS_pzPkgDataDir(pOpts
) && (pOpts
->pzPackager
!= NULL
))
127 fputs(pOpts
->pzPackager
, fp
);
129 else if (pOpts
->pzBugAddr
!= NULL
)
130 fprintf(fp
, zPlsSendBugs
, pOpts
->pzBugAddr
);
134 print_ver(tOptions
* pOpts
, tOptDesc
* pOD
, FILE * fp
)
139 * IF we have an argument for this option, use it
140 * Otherwise, default to version only or copyright note,
141 * depending on whether the layout is GNU standard form or not.
143 if ( (pOD
->fOptState
& OPTST_ARG_OPTIONAL
)
144 && (pOD
->optArg
.argString
!= NULL
)
145 && (pOD
->optArg
.argString
[0] != NUL
))
147 ch
= pOD
->optArg
.argString
[0];
150 set_usage_flags(pOpts
, NULL
);
151 ch
= (pOpts
->fOptSet
& OPTPROC_GNUUSAGE
) ? 'c' : 'v';
155 case NUL
: /* arg provided, but empty */
156 case 'v': case 'V': emit_simple_ver(pOpts
, fp
); break;
157 case 'c': case 'C': emit_copy_ver(pOpts
, fp
); break;
158 case 'n': case 'N': emit_copy_note(pOpts
, fp
); break;
161 fprintf(stderr
, zBadVerArg
, ch
);
166 if (ferror(fp
) != 0) {
167 fputs(zOutputFail
, stderr
);
173 /*=export_func optionPrintVersion
176 * what: Print the program version
177 * arg: + tOptions* + pOpts + program options descriptor +
178 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
181 * This routine will print the version to stdout.
184 optionPrintVersion(tOptions
* pOpts
, tOptDesc
* pOD
)
186 print_ver(pOpts
, pOD
, stdout
);
189 /*=export_func optionVersionStderr
192 * what: Print the program version to stderr
193 * arg: + tOptions* + pOpts + program options descriptor +
194 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
197 * This routine will print the version to stderr.
200 optionVersionStderr(tOptions
* pOpts
, tOptDesc
* pOD
)
202 print_ver(pOpts
, pOD
, stderr
);
208 * c-file-style: "stroustrup"
209 * indent-tabs-mode: nil
211 * end of autoopts/version.c */