Back to index

lightning-sunbird  0.9+nobinonly
version.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "prio.h"
00039 #include "prprf.h"
00040 #include "prlink.h"
00041 #include "prvrsion.h"
00042 
00043 #include "plerror.h"
00044 #include "plgetopt.h"
00045 
00046 PR_IMPORT(const PRVersionDescription *) libVersionPoint(void);
00047 
00048 PRIntn main(PRIntn argc, char **argv)
00049 {
00050     PRIntn rv = 1;
00051     PLOptStatus os;
00052     PRIntn verbosity = 0;
00053     PRLibrary *runtime = NULL;
00054     const char *library_name = NULL;
00055     const PRVersionDescription *version_info;
00056        char buffer[100];
00057        PRExplodedTime exploded;
00058     PLOptState *opt = PL_CreateOptState(argc, argv, "d");
00059 
00060     PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
00061 
00062     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00063     {
00064         if (PL_OPT_BAD == os) continue;
00065         switch (opt->option)
00066         {
00067         case 0:  /* fully qualified library name */
00068             library_name = opt->value;
00069             break;
00070         case 'd':  /* verbodity */
00071             verbosity += 1;
00072             break;
00073          default:
00074             PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
00075             return 2;  /* but not a lot else */
00076         }
00077     }
00078     PL_DestroyOptState(opt);
00079 
00080     if (NULL != library_name)
00081     {
00082         runtime = PR_LoadLibrary(library_name);
00083         if (NULL == runtime) {
00084                      PL_FPrintError(err, "PR_LoadLibrary");
00085                      return 3;
00086               } else {
00087             versionEntryPointType versionPoint = (versionEntryPointType)
00088                 PR_FindSymbol(runtime, "libVersionPoint");
00089             if (NULL == versionPoint) {
00090                             PL_FPrintError(err, "PR_FindSymbol");
00091                             return 4;
00092                      }      
00093                      version_info = versionPoint();
00094               }
00095        } else
00096               version_info = libVersionPoint();  /* NSPR's version info */
00097 
00098        (void)PR_fprintf(err, "Runtime library version information\n");
00099        PR_ExplodeTime(
00100               version_info->buildTime, PR_GMTParameters, &exploded);
00101        (void)PR_FormatTime(
00102               buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
00103        (void)PR_fprintf(err, "  Build time: %s GMT\n", buffer);
00104        (void)PR_fprintf(
00105               err, "  Build time: %s\n", version_info->buildTimeString);
00106        (void)PR_fprintf(
00107               err, "  %s V%u.%u.%u (%s%s%s)\n",
00108               version_info->description,
00109               version_info->vMajor,
00110               version_info->vMinor,
00111               version_info->vPatch,
00112               (version_info->beta ? " beta " : ""),
00113               (version_info->debug ? " debug " : ""),
00114               (version_info->special ? " special" : ""));
00115        (void)PR_fprintf(err, "  filename: %s\n", version_info->filename);
00116        (void)PR_fprintf(err, "  security: %s\n", version_info->security);
00117        (void)PR_fprintf(err, "  copyright: %s\n", version_info->copyright);
00118        (void)PR_fprintf(err, "  comment: %s\n", version_info->comment);
00119        rv = 0;
00120     return rv;
00121 }
00122 
00123 /* version.c */