Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
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/. */
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"
22 /***********************************************************************
23 ** Includes
24 ***********************************************************************/
25 /* Used to get the command line option */
26 #include "plgetopt.h"
28 #include <stdio.h>
29 #include <stdlib.h>
31 static void PrintVersion(
32 const char *msg, const PRVersion* info, PRIntn tab)
33 {
34 static const len = 20;
35 static const char *tabs = {" "};
37 tab *= 2;
38 if (tab > len) tab = len;
39 printf("%s", &tabs[len - tab]);
40 printf("%s ", msg);
41 printf("%s ", info->id);
42 printf("%d.%d", info->major, info->minor);
43 if (0 != info->patch)
44 printf(".p%d", info->patch);
45 printf("\n");
46 } /* PrintDependency */
48 static void ChaseDependents(const PRVersionInfo *info, PRIntn tab)
49 {
50 PrintVersion("exports", &info->selfExport, tab);
51 if (NULL != info->importEnumerator)
52 {
53 const PRDependencyInfo *dependent = NULL;
54 while (NULL != (dependent = info->importEnumerator(dependent)))
55 {
56 const PRVersionInfo *import = dependent->exportInfoFn();
57 PrintVersion("imports", &dependent->importNeeded, tab);
58 ChaseDependents(import, tab + 1);
59 }
60 }
61 } /* ChaseDependents */
63 static PRVersionInfo hack_export;
64 static PRVersionInfo dummy_export;
65 static PRDependencyInfo dummy_imports[2];
67 static const PRVersionInfo *HackExportInfo(void)
68 {
69 hack_export.selfExport.major = 11;
70 hack_export.selfExport.minor = 10;
71 hack_export.selfExport.patch = 200;
72 hack_export.selfExport.id = "Hack";
73 hack_export.importEnumerator = NULL;
74 return &hack_export;
75 }
77 static const PRDependencyInfo *DummyImports(
78 const PRDependencyInfo *previous)
79 {
80 if (NULL == previous) return &dummy_imports[0];
81 else if (&dummy_imports[0] == previous) return &dummy_imports[1];
82 else if (&dummy_imports[1] == previous) return NULL;
83 } /* DummyImports */
85 static const PRVersionInfo *DummyLibVersion(void)
86 {
87 dummy_export.selfExport.major = 1;
88 dummy_export.selfExport.minor = 0;
89 dummy_export.selfExport.patch = 0;
90 dummy_export.selfExport.id = "Dumbass application";
91 dummy_export.importEnumerator = DummyImports;
93 dummy_imports[0].importNeeded.major = 2;
94 dummy_imports[0].importNeeded.minor = 0;
95 dummy_imports[0].importNeeded.patch = 0;
96 dummy_imports[0].importNeeded.id = "Netscape Portable Runtime";
97 dummy_imports[0].exportInfoFn = PR_ExportInfo;
99 dummy_imports[1].importNeeded.major = 5;
100 dummy_imports[1].importNeeded.minor = 1;
101 dummy_imports[1].importNeeded.patch = 2;
102 dummy_imports[1].importNeeded.id = "Hack Library";
103 dummy_imports[1].exportInfoFn = HackExportInfo;
105 return &dummy_export;
106 } /* DummyLibVersion */
108 int main(int argc, char **argv)
109 {
110 PRIntn tab = 0;
111 const PRVersionInfo *info = DummyLibVersion();
112 const char *buildDate = __DATE__, *buildTime = __TIME__;
114 printf("Depend.c build time is %s %s\n", buildDate, buildTime);
116 if (NULL != info) ChaseDependents(info, tab);
118 return 0;
119 } /* main */
121 /* depend.c */