Annotation of embedaddon/ntp/sntp/libopts/version.c, revision 1.1.1.1

1.1       misho       1: 
                      2: /*
                      3:  * Time-stamp:      "2011-04-22 12:54:28 bkorb"
                      4:  *
                      5:  *  This module implements the default usage procedure for
                      6:  *  Automated Options.  It may be overridden, of course.
                      7:  */
                      8: 
                      9: /*
                     10:  *  This file is part of AutoOpts, a companion to AutoGen.
                     11:  *  AutoOpts is free software.
                     12:  *  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
                     13:  *
                     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.
                     17:  *
                     18:  *   The GNU Lesser General Public License, version 3 or later
                     19:  *      See the files "COPYING.lgplv3" and "COPYING.gplv3"
                     20:  *
                     21:  *   The Modified Berkeley Software Distribution License
                     22:  *      See the file "COPYING.mbsd"
                     23:  *
                     24:  *  These files have the following md5sums:
                     25:  *
                     26:  *  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
                     27:  *  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
                     28:  *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
                     29:  */
                     30: 
                     31: /*=export_func  optionVersion
                     32:  *
                     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)
                     42: {
                     43:     static char const zVersion[] =
                     44:         STR(AO_CURRENT.AO_REVISION);
                     45: 
                     46:     return zVersion;
                     47: }
                     48: 
                     49: static void
                     50: emit_simple_ver(tOptions * pOpts, FILE * fp)
                     51: {
                     52:     if (pOpts->pzFullVersion != NULL)
                     53:         fputs(pOpts->pzFullVersion, fp);
                     54: 
                     55:     else if (pOpts->pzCopyright != NULL) {
                     56:         char const * pe = strchr(pOpts->pzCopyright, '\n');
                     57:         if (pe == NULL)
                     58:             pe = pOpts->pzCopyright + strlen(pOpts->pzCopyright);
                     59:         fwrite(pOpts->pzCopyright, 1, pe - pOpts->pzCopyright, fp);
                     60:     }
                     61: 
                     62:     else {
                     63:         char const * pe = strchr(pOpts->pzUsageTitle, '\n');
                     64:         if (pe == NULL)
                     65:             pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle);
                     66:         fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzCopyright, fp);
                     67:     }
                     68:     fputc('\n', fp);
                     69: }
                     70: 
                     71: static void
                     72: emit_copy_ver(tOptions * pOpts, FILE * fp)
                     73: {
                     74:     if (pOpts->pzCopyright != NULL)
                     75:         fputs(pOpts->pzCopyright, fp);
                     76: 
                     77:     else if (pOpts->pzFullVersion != NULL)
                     78:         fputs(pOpts->pzFullVersion, fp);
                     79: 
                     80:     else {
                     81:         char const * pe = strchr(pOpts->pzUsageTitle, '\n');
                     82:         if (pe == NULL)
                     83:             pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle);
                     84:         fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzCopyright, fp);
                     85:     }
                     86: 
                     87:     fputc('\n', fp);
                     88: 
                     89:     if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL))
                     90:         fputs(pOpts->pzPackager, fp);
                     91: 
                     92:     else if (pOpts->pzBugAddr != NULL)
                     93:         fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr);
                     94: }
                     95: 
                     96: static void
                     97: emit_copy_note(tOptions * pOpts, FILE * fp)
                     98: {
                     99:     if (pOpts->pzCopyright != NULL) {
                    100:         fputs(pOpts->pzCopyright, fp);
                    101:         fputc('\n', fp);
                    102:     }
                    103: 
                    104:     if (pOpts->pzCopyNotice != NULL) {
                    105:         fputs(pOpts->pzCopyNotice, fp);
                    106:         fputc('\n', fp);
                    107:     }
                    108: 
                    109:     fprintf(fp, zAO_Ver, optionVersion());
                    110: 
                    111:     if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL))
                    112:         fputs(pOpts->pzPackager, fp);
                    113: 
                    114:     else if (pOpts->pzBugAddr != NULL)
                    115:         fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr);
                    116: }
                    117: 
                    118: static void
                    119: print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp)
                    120: {
                    121:     char ch;
                    122: 
                    123:     /*
                    124:      *  IF the optional argument flag is off, or the argument
                    125:      *  is not provided, then just print the version.
                    126:      */
                    127:     if (  ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0)
                    128:        || (pOD->optArg.argString == NULL))
                    129:          ch = 'v';
                    130:     else ch = pOD->optArg.argString[0];
                    131: 
                    132:     switch (ch) {
                    133:     case NUL: /* arg provided, but empty */
                    134:     case 'v': case 'V': emit_simple_ver(pOpts, fp); break;
                    135:     case 'c': case 'C': emit_copy_ver(pOpts, fp);   break;
                    136:     case 'n': case 'N': emit_copy_note(pOpts, fp);  break;
                    137: 
                    138:     default:
                    139:         fprintf(stderr, zBadVerArg, ch);
                    140:         exit(EXIT_FAILURE);
                    141:     }
                    142: 
                    143:     fflush(fp);
                    144:     if (ferror(fp) != 0) {
                    145:         fputs(zOutputFail, stderr);
                    146:         exit(EXIT_FAILURE);
                    147:     }
                    148:     exit(EXIT_SUCCESS);
                    149: }
                    150: 
                    151: /*=export_func  optionPrintVersion
                    152:  * private:
                    153:  *
                    154:  * what:  Print the program version
                    155:  * arg:   + tOptions* + pOpts    + program options descriptor +
                    156:  * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
                    157:  *
                    158:  * doc:
                    159:  *  This routine will print the version to stdout.
                    160: =*/
                    161: void
                    162: optionPrintVersion(tOptions * pOpts, tOptDesc * pOD)
                    163: {
                    164:     print_ver(pOpts, pOD, stdout);
                    165: }
                    166: 
                    167: /*=export_func  optionVersionStderr
                    168:  * private:
                    169:  *
                    170:  * what:  Print the program version to stderr
                    171:  * arg:   + tOptions* + pOpts    + program options descriptor +
                    172:  * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
                    173:  *
                    174:  * doc:
                    175:  *  This routine will print the version to stderr.
                    176: =*/
                    177: void
                    178: optionVersionStderr(tOptions * pOpts, tOptDesc * pOD)
                    179: {
                    180:     print_ver(pOpts, pOD, stderr);
                    181: }
                    182: 
                    183: /*
                    184:  * Local Variables:
                    185:  * mode: C
                    186:  * c-file-style: "stroustrup"
                    187:  * indent-tabs-mode: nil
                    188:  * End:
                    189:  * end of autoopts/version.c */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>