michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "prio.h" michael@0: #include "prprf.h" michael@0: #include "prlink.h" michael@0: #include "prvrsion.h" michael@0: michael@0: #include "plerror.h" michael@0: #include "plgetopt.h" michael@0: michael@0: PR_IMPORT(const PRVersionDescription *) libVersionPoint(void); michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRIntn rv = 1; michael@0: PLOptStatus os; michael@0: PRIntn verbosity = 0; michael@0: PRLibrary *runtime = NULL; michael@0: const char *library_name = NULL; michael@0: const PRVersionDescription *version_info; michael@0: char buffer[100]; michael@0: PRExplodedTime exploded; michael@0: PLOptState *opt = PL_CreateOptState(argc, argv, "d"); michael@0: michael@0: PRFileDesc *err = PR_GetSpecialFD(PR_StandardError); michael@0: michael@0: while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) michael@0: { michael@0: if (PL_OPT_BAD == os) continue; michael@0: switch (opt->option) michael@0: { michael@0: case 0: /* fully qualified library name */ michael@0: library_name = opt->value; michael@0: break; michael@0: case 'd': /* verbodity */ michael@0: verbosity += 1; michael@0: break; michael@0: default: michael@0: PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n"); michael@0: return 2; /* but not a lot else */ michael@0: } michael@0: } michael@0: PL_DestroyOptState(opt); michael@0: michael@0: if (NULL != library_name) michael@0: { michael@0: runtime = PR_LoadLibrary(library_name); michael@0: if (NULL == runtime) { michael@0: PL_FPrintError(err, "PR_LoadLibrary"); michael@0: return 3; michael@0: } else { michael@0: versionEntryPointType versionPoint = (versionEntryPointType) michael@0: PR_FindSymbol(runtime, "libVersionPoint"); michael@0: if (NULL == versionPoint) { michael@0: PL_FPrintError(err, "PR_FindSymbol"); michael@0: return 4; michael@0: } michael@0: version_info = versionPoint(); michael@0: } michael@0: } else michael@0: version_info = libVersionPoint(); /* NSPR's version info */ michael@0: michael@0: (void)PR_fprintf(err, "Runtime library version information\n"); michael@0: PR_ExplodeTime( michael@0: version_info->buildTime, PR_GMTParameters, &exploded); michael@0: (void)PR_FormatTime( michael@0: buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded); michael@0: (void)PR_fprintf(err, " Build time: %s GMT\n", buffer); michael@0: (void)PR_fprintf( michael@0: err, " Build time: %s\n", version_info->buildTimeString); michael@0: (void)PR_fprintf( michael@0: err, " %s V%u.%u.%u (%s%s%s)\n", michael@0: version_info->description, michael@0: version_info->vMajor, michael@0: version_info->vMinor, michael@0: version_info->vPatch, michael@0: (version_info->beta ? " beta " : ""), michael@0: (version_info->debug ? " debug " : ""), michael@0: (version_info->special ? " special" : "")); michael@0: (void)PR_fprintf(err, " filename: %s\n", version_info->filename); michael@0: (void)PR_fprintf(err, " security: %s\n", version_info->security); michael@0: (void)PR_fprintf(err, " copyright: %s\n", version_info->copyright); michael@0: (void)PR_fprintf(err, " comment: %s\n", version_info->comment); michael@0: rv = 0; michael@0: return rv; michael@0: } michael@0: michael@0: /* version.c */