123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- char const *
- optionVersion(void)
- {
- static char const ver[] = OPTIONS_DOTTED_VERSION;
- return ver;
- }
- static void
- emit_first_line(
- FILE * fp, char const * alt1, char const * alt2, char const * alt3)
- {
- char const * p = (alt1 != NULL) ? alt1 : ((alt2 != NULL) ? alt2 : alt3);
- char const * e;
- if (p == NULL)
- return;
- e = strchr(p, NL);
- if (e == NULL)
- fputs(p, fp);
- else
- fwrite(p, 1, (e - p), fp);
- fputc(NL, fp);
- }
- static void
- emit_simple_ver(tOptions * o, FILE * fp)
- {
- emit_first_line(fp, o->pzFullVersion, o->pzCopyright, o->pzUsageTitle);
- }
- static void
- emit_copy_full(tOptions * o, FILE * fp)
- {
- if (o->pzCopyright != NULL)
- fputs(o->pzCopyright, fp);
- else if (o->pzFullVersion != NULL)
- fputs(o->pzFullVersion, fp);
- else
- emit_first_line(fp, o->pzUsageTitle, NULL, NULL);
- if (HAS_pzPkgDataDir(o) && (o->pzPackager != NULL)) {
- fputc(NL, fp);
- fputs(o->pzPackager, fp);
- } else if (o->pzBugAddr != NULL) {
- fputc(NL, fp);
- fprintf(fp, zPlsSendBugs, o->pzBugAddr);
- }
- }
- static void
- emit_copy_note(tOptions * opts, FILE * fp)
- {
- if (opts->pzCopyright != NULL)
- fputs(opts->pzCopyright, fp);
- if (opts->pzCopyNotice != NULL)
- fputs(opts->pzCopyNotice, fp);
- fputc(NL, fp);
- fprintf(fp, zao_ver_fmt, optionVersion());
- if (HAS_pzPkgDataDir(opts) && (opts->pzPackager != NULL)) {
- fputc(NL, fp);
- fputs(opts->pzPackager, fp);
- } else if (opts->pzBugAddr != NULL) {
- fputc(NL, fp);
- fprintf(fp, zPlsSendBugs, opts->pzBugAddr);
- }
- }
- static void
- print_ver(tOptions * opts, tOptDesc * od, FILE * fp, bool call_exit)
- {
- char ch;
- if (opts <= OPTPROC_EMIT_LIMIT)
- return;
-
- if ( (od->fOptState & OPTST_ARG_OPTIONAL)
- && (od->optArg.argString != NULL)
- && (od->optArg.argString[0] != NUL))
- ch = od->optArg.argString[0];
- else if (OPTST_GET_ARGTYPE(od->fOptState) == OPARG_TYPE_STATIC) {
- ch = od->optArg.argString[0];
- } else {
- set_usage_flags(opts, NULL);
- ch = (opts->fOptSet & OPTPROC_GNUUSAGE) ? 'c' : 'v';
- }
- switch (ch) {
- case NUL:
- case 'v': case 'V': emit_simple_ver(opts, fp); break;
- case 'c': case 'C': emit_copy_full( opts, fp); break;
- case 'n': case 'N': emit_copy_note( opts, fp); break;
- default:
- fprintf(stderr, zBadVerArg, ch);
- option_exits(EXIT_FAILURE);
- }
- fflush(fp);
- if (ferror(fp))
- fserr_exit(opts->pzProgName, zwriting,
- (fp == stdout) ? zstdout_name : zstderr_name);
- if (call_exit)
- option_exits(EXIT_SUCCESS);
- }
- void
- optionPrintVersion(tOptions * opts, tOptDesc * od)
- {
- print_ver(opts, od, print_exit ? stderr : stdout, true);
- }
- void
- optionPrintVersionAndReturn(tOptions * opts, tOptDesc * od)
- {
- print_ver(opts, od, print_exit ? stderr : stdout, false);
- }
- void
- optionVersionStderr(tOptions * opts, tOptDesc * od)
- {
- print_ver(opts, od, stderr, true);
- }
|