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