nsprpub/pr/tests/version.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/version.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "prio.h"
    1.10 +#include "prprf.h"
    1.11 +#include "prlink.h"
    1.12 +#include "prvrsion.h"
    1.13 +
    1.14 +#include "plerror.h"
    1.15 +#include "plgetopt.h"
    1.16 +
    1.17 +PR_IMPORT(const PRVersionDescription *) libVersionPoint(void);
    1.18 +
    1.19 +int main(int argc, char **argv)
    1.20 +{
    1.21 +    PRIntn rv = 1;
    1.22 +    PLOptStatus os;
    1.23 +    PRIntn verbosity = 0;
    1.24 +    PRLibrary *runtime = NULL;
    1.25 +    const char *library_name = NULL;
    1.26 +    const PRVersionDescription *version_info;
    1.27 +	char buffer[100];
    1.28 +	PRExplodedTime exploded;
    1.29 +    PLOptState *opt = PL_CreateOptState(argc, argv, "d");
    1.30 +
    1.31 +    PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
    1.32 +
    1.33 +    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
    1.34 +    {
    1.35 +        if (PL_OPT_BAD == os) continue;
    1.36 +        switch (opt->option)
    1.37 +        {
    1.38 +        case 0:  /* fully qualified library name */
    1.39 +            library_name = opt->value;
    1.40 +            break;
    1.41 +        case 'd':  /* verbodity */
    1.42 +            verbosity += 1;
    1.43 +            break;
    1.44 +         default:
    1.45 +            PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
    1.46 +            return 2;  /* but not a lot else */
    1.47 +        }
    1.48 +    }
    1.49 +    PL_DestroyOptState(opt);
    1.50 +
    1.51 +    if (NULL != library_name)
    1.52 +    {
    1.53 +        runtime = PR_LoadLibrary(library_name);
    1.54 +        if (NULL == runtime) {
    1.55 +			PL_FPrintError(err, "PR_LoadLibrary");
    1.56 +			return 3;
    1.57 +		} else {
    1.58 +            versionEntryPointType versionPoint = (versionEntryPointType)
    1.59 +                PR_FindSymbol(runtime, "libVersionPoint");
    1.60 +            if (NULL == versionPoint) {
    1.61 +				PL_FPrintError(err, "PR_FindSymbol");
    1.62 +				return 4;
    1.63 +			}	
    1.64 +			version_info = versionPoint();
    1.65 +		}
    1.66 +	} else
    1.67 +		version_info = libVersionPoint();	/* NSPR's version info */
    1.68 +
    1.69 +	(void)PR_fprintf(err, "Runtime library version information\n");
    1.70 +	PR_ExplodeTime(
    1.71 +		version_info->buildTime, PR_GMTParameters, &exploded);
    1.72 +	(void)PR_FormatTime(
    1.73 +		buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
    1.74 +	(void)PR_fprintf(err, "  Build time: %s GMT\n", buffer);
    1.75 +	(void)PR_fprintf(
    1.76 +		err, "  Build time: %s\n", version_info->buildTimeString);
    1.77 +	(void)PR_fprintf(
    1.78 +		err, "  %s V%u.%u.%u (%s%s%s)\n",
    1.79 +		version_info->description,
    1.80 +		version_info->vMajor,
    1.81 +		version_info->vMinor,
    1.82 +		version_info->vPatch,
    1.83 +		(version_info->beta ? " beta " : ""),
    1.84 +		(version_info->debug ? " debug " : ""),
    1.85 +		(version_info->special ? " special" : ""));
    1.86 +	(void)PR_fprintf(err, "  filename: %s\n", version_info->filename);
    1.87 +	(void)PR_fprintf(err, "  security: %s\n", version_info->security);
    1.88 +	(void)PR_fprintf(err, "  copyright: %s\n", version_info->copyright);
    1.89 +	(void)PR_fprintf(err, "  comment: %s\n", version_info->comment);
    1.90 +	rv = 0;
    1.91 +    return rv;
    1.92 +}
    1.93 +
    1.94 +/* version.c */

mercurial