1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #include "prio.h"
7 #include "prprf.h"
8 #include "prlink.h"
9 #include "prvrsion.h"
10 
11 #include "plerror.h"
12 #include "plgetopt.h"
13 
14 PR_IMPORT(const PRVersionDescription *) libVersionPoint(void);
15 
main(int argc,char ** argv)16 int main(int argc, char **argv)
17 {
18     PRIntn rv = 1;
19     PLOptStatus os;
20     PRIntn verbosity = 0;
21     PRLibrary *runtime = NULL;
22     const char *library_name = NULL;
23     const PRVersionDescription *version_info;
24     char buffer[100];
25     PRExplodedTime exploded;
26     PLOptState *opt = PL_CreateOptState(argc, argv, "d");
27 
28     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
29 
30     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
31     {
32         if (PL_OPT_BAD == os) {
33             continue;
34         }
35         switch (opt->option)
36         {
37             case 0:  /* fully qualified library name */
38                 library_name = opt->value;
39                 break;
40             case 'd':  /* verbodity */
41                 verbosity += 1;
42                 break;
43             default:
44                 PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
45                 return 2;  /* but not a lot else */
46         }
47     }
48     PL_DestroyOptState(opt);
49 
50     if (NULL != library_name)
51     {
52         runtime = PR_LoadLibrary(library_name);
53         if (NULL == runtime) {
54             PL_FPrintError(err, "PR_LoadLibrary");
55             return 3;
56         } else {
57             versionEntryPointType versionPoint = (versionEntryPointType)
58                                                  PR_FindSymbol(runtime, "libVersionPoint");
59             if (NULL == versionPoint) {
60                 PL_FPrintError(err, "PR_FindSymbol");
61                 return 4;
62             }
63             version_info = versionPoint();
64         }
65     } else {
66         version_info = libVersionPoint();    /* NSPR's version info */
67     }
68 
69     (void)PR_fprintf(err, "Runtime library version information\n");
70     PR_ExplodeTime(
71         version_info->buildTime, PR_GMTParameters, &exploded);
72     (void)PR_FormatTime(
73         buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
74     (void)PR_fprintf(err, "  Build time: %s GMT\n", buffer);
75     (void)PR_fprintf(
76         err, "  Build time: %s\n", version_info->buildTimeString);
77     (void)PR_fprintf(
78         err, "  %s V%u.%u.%u (%s%s%s)\n",
79         version_info->description,
80         version_info->vMajor,
81         version_info->vMinor,
82         version_info->vPatch,
83         (version_info->beta ? " beta " : ""),
84         (version_info->debug ? " debug " : ""),
85         (version_info->special ? " special" : ""));
86     (void)PR_fprintf(err, "  filename: %s\n", version_info->filename);
87     (void)PR_fprintf(err, "  security: %s\n", version_info->security);
88     (void)PR_fprintf(err, "  copyright: %s\n", version_info->copyright);
89     (void)PR_fprintf(err, "  comment: %s\n", version_info->comment);
90     rv = 0;
91     return rv;
92 }
93 
94 /* version.c */
95