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