depend.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. ** 1996 - Netscape Communications Corporation
  7. **
  8. **
  9. ** Name: depend.c
  10. ** Description: Test to enumerate the dependencies
  11. *
  12. ** Modification History:
  13. ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
  14. ** The debug mode will print all of the printfs associated with this test.
  15. ** The regress mode will be the default mode. Since the regress tool limits
  16. ** the output to a one line status:PASS or FAIL,all of the printf statements
  17. ** have been handled with an if (debug_mode) statement.
  18. ***********************************************************************/
  19. #include "prinit.h"
  20. /***********************************************************************
  21. ** Includes
  22. ***********************************************************************/
  23. /* Used to get the command line option */
  24. #include "plgetopt.h"
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. static void PrintVersion(
  28. const char *msg, const PRVersion* info, PRIntn tab)
  29. {
  30. static const len = 20;
  31. static const char *tabs = {" "};
  32. tab *= 2;
  33. if (tab > len) {
  34. tab = len;
  35. }
  36. printf("%s", &tabs[len - tab]);
  37. printf("%s ", msg);
  38. printf("%s ", info->id);
  39. printf("%d.%d", info->major, info->minor);
  40. if (0 != info->patch) {
  41. printf(".p%d", info->patch);
  42. }
  43. printf("\n");
  44. } /* PrintDependency */
  45. static void ChaseDependents(const PRVersionInfo *info, PRIntn tab)
  46. {
  47. PrintVersion("exports", &info->selfExport, tab);
  48. if (NULL != info->importEnumerator)
  49. {
  50. const PRDependencyInfo *dependent = NULL;
  51. while (NULL != (dependent = info->importEnumerator(dependent)))
  52. {
  53. const PRVersionInfo *import = dependent->exportInfoFn();
  54. PrintVersion("imports", &dependent->importNeeded, tab);
  55. ChaseDependents(import, tab + 1);
  56. }
  57. }
  58. } /* ChaseDependents */
  59. static PRVersionInfo hack_export;
  60. static PRVersionInfo dummy_export;
  61. static PRDependencyInfo dummy_imports[2];
  62. static const PRVersionInfo *HackExportInfo(void)
  63. {
  64. hack_export.selfExport.major = 11;
  65. hack_export.selfExport.minor = 10;
  66. hack_export.selfExport.patch = 200;
  67. hack_export.selfExport.id = "Hack";
  68. hack_export.importEnumerator = NULL;
  69. return &hack_export;
  70. }
  71. static const PRDependencyInfo *DummyImports(
  72. const PRDependencyInfo *previous)
  73. {
  74. if (NULL == previous) {
  75. return &dummy_imports[0];
  76. }
  77. else if (&dummy_imports[0] == previous) {
  78. return &dummy_imports[1];
  79. }
  80. else if (&dummy_imports[1] == previous) {
  81. return NULL;
  82. }
  83. } /* DummyImports */
  84. static const PRVersionInfo *DummyLibVersion(void)
  85. {
  86. dummy_export.selfExport.major = 1;
  87. dummy_export.selfExport.minor = 0;
  88. dummy_export.selfExport.patch = 0;
  89. dummy_export.selfExport.id = "Dumbass application";
  90. dummy_export.importEnumerator = DummyImports;
  91. dummy_imports[0].importNeeded.major = 2;
  92. dummy_imports[0].importNeeded.minor = 0;
  93. dummy_imports[0].importNeeded.patch = 0;
  94. dummy_imports[0].importNeeded.id = "Netscape Portable Runtime";
  95. dummy_imports[0].exportInfoFn = PR_ExportInfo;
  96. dummy_imports[1].importNeeded.major = 5;
  97. dummy_imports[1].importNeeded.minor = 1;
  98. dummy_imports[1].importNeeded.patch = 2;
  99. dummy_imports[1].importNeeded.id = "Hack Library";
  100. dummy_imports[1].exportInfoFn = HackExportInfo;
  101. return &dummy_export;
  102. } /* DummyLibVersion */
  103. int main(int argc, char **argv)
  104. {
  105. PRIntn tab = 0;
  106. const PRVersionInfo *info = DummyLibVersion();
  107. const char *buildDate = __DATE__, *buildTime = __TIME__;
  108. printf("Depend.c build time is %s %s\n", buildDate, buildTime);
  109. if (NULL != info) {
  110. ChaseDependents(info, tab);
  111. }
  112. return 0;
  113. } /* main */
  114. /* depend.c */