Updated gnulib and added hash-pjw-bare
[gnutls.git] / src / libopts / version.c
blob24041b2013a6f579bb650a0e54398c678a619601
2 /*
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.
7 */
9 /*
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
36 * doc:
37 * Returns the full version string compiled into the library.
38 * The returned string cannot be modified.
39 =*/
40 char const*
41 optionVersion(void)
43 static char const zVersion[] =
44 STR(AO_CURRENT.AO_REVISION);
46 return zVersion;
49 /**
50 * Select among various ways to emit version information.
52 * @param pOpts the option descriptor
53 * @param fp the output stream
55 static void
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);
69 if (pe == NULL)
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
77 else {
78 char const * pe = strchr(pOpts->pzUsageTitle, NL);
79 if (pe == NULL)
80 pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle);
81 fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzUsageTitle, fp);
83 fputc(NL, fp);
86 static void
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);
95 else {
96 char const * pe = strchr(pOpts->pzUsageTitle, NL);
97 if (pe == NULL)
98 pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle);
99 fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzCopyright, fp);
102 fputc(NL, 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);
111 static void
112 emit_copy_note(tOptions * pOpts, FILE * fp)
114 if (pOpts->pzCopyright != NULL) {
115 fputs(pOpts->pzCopyright, fp);
116 fputc(NL, fp);
119 if (pOpts->pzCopyNotice != NULL) {
120 fputs(pOpts->pzCopyNotice, fp);
121 fputc(NL, 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);
133 static void
134 print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp)
136 char ch;
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];
149 else {
150 set_usage_flags(pOpts, NULL);
151 ch = (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
154 switch (ch) {
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;
160 default:
161 fprintf(stderr, zBadVerArg, ch);
162 exit(EXIT_FAILURE);
165 fflush(fp);
166 if (ferror(fp) != 0) {
167 fputs(zOutputFail, stderr);
168 exit(EXIT_FAILURE);
170 exit(EXIT_SUCCESS);
173 /*=export_func optionPrintVersion
174 * private:
176 * what: Print the program version
177 * arg: + tOptions* + pOpts + program options descriptor +
178 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
180 * doc:
181 * This routine will print the version to stdout.
183 void
184 optionPrintVersion(tOptions * pOpts, tOptDesc * pOD)
186 print_ver(pOpts, pOD, stdout);
189 /*=export_func optionVersionStderr
190 * private:
192 * what: Print the program version to stderr
193 * arg: + tOptions* + pOpts + program options descriptor +
194 * arg: + tOptDesc* + pOptDesc + the descriptor for this arg +
196 * doc:
197 * This routine will print the version to stderr.
199 void
200 optionVersionStderr(tOptions * pOpts, tOptDesc * pOD)
202 print_ver(pOpts, pOD, stderr);
206 * Local Variables:
207 * mode: C
208 * c-file-style: "stroustrup"
209 * indent-tabs-mode: nil
210 * End:
211 * end of autoopts/version.c */