version.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "prio.h"
  6. #include "prprf.h"
  7. #include "prlink.h"
  8. #include "prvrsion.h"
  9. #include "plerror.h"
  10. #include "plgetopt.h"
  11. PR_IMPORT(const PRVersionDescription *) libVersionPoint(void);
  12. int main(int argc, char **argv)
  13. {
  14. PRIntn rv = 1;
  15. PLOptStatus os;
  16. PRIntn verbosity = 0;
  17. PRLibrary *runtime = NULL;
  18. const char *library_name = NULL;
  19. const PRVersionDescription *version_info;
  20. char buffer[100];
  21. PRExplodedTime exploded;
  22. PLOptState *opt = PL_CreateOptState(argc, argv, "d");
  23. PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
  24. while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  25. {
  26. if (PL_OPT_BAD == os) {
  27. continue;
  28. }
  29. switch (opt->option)
  30. {
  31. case 0: /* fully qualified library name */
  32. library_name = opt->value;
  33. break;
  34. case 'd': /* verbodity */
  35. verbosity += 1;
  36. break;
  37. default:
  38. PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
  39. return 2; /* but not a lot else */
  40. }
  41. }
  42. PL_DestroyOptState(opt);
  43. if (NULL != library_name)
  44. {
  45. runtime = PR_LoadLibrary(library_name);
  46. if (NULL == runtime) {
  47. PL_FPrintError(err, "PR_LoadLibrary");
  48. return 3;
  49. } else {
  50. versionEntryPointType versionPoint = (versionEntryPointType)
  51. PR_FindSymbol(runtime, "libVersionPoint");
  52. if (NULL == versionPoint) {
  53. PL_FPrintError(err, "PR_FindSymbol");
  54. return 4;
  55. }
  56. version_info = versionPoint();
  57. }
  58. } else {
  59. version_info = libVersionPoint(); /* NSPR's version info */
  60. }
  61. (void)PR_fprintf(err, "Runtime library version information\n");
  62. PR_ExplodeTime(
  63. version_info->buildTime, PR_GMTParameters, &exploded);
  64. (void)PR_FormatTime(
  65. buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
  66. (void)PR_fprintf(err, " Build time: %s GMT\n", buffer);
  67. (void)PR_fprintf(
  68. err, " Build time: %s\n", version_info->buildTimeString);
  69. (void)PR_fprintf(
  70. err, " %s V%u.%u.%u (%s%s%s)\n",
  71. version_info->description,
  72. version_info->vMajor,
  73. version_info->vMinor,
  74. version_info->vPatch,
  75. (version_info->beta ? " beta " : ""),
  76. (version_info->debug ? " debug " : ""),
  77. (version_info->special ? " special" : ""));
  78. (void)PR_fprintf(err, " filename: %s\n", version_info->filename);
  79. (void)PR_fprintf(err, " security: %s\n", version_info->security);
  80. (void)PR_fprintf(err, " copyright: %s\n", version_info->copyright);
  81. (void)PR_fprintf(err, " comment: %s\n", version_info->comment);
  82. rv = 0;
  83. return rv;
  84. }
  85. /* version.c */