michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /*********************************************************************** michael@0: ** 1996 - Netscape Communications Corporation michael@0: ** michael@0: ** michael@0: ** Name: depend.c michael@0: ** Description: Test to enumerate the dependencies michael@0: * michael@0: ** Modification History: michael@0: ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. michael@0: ** The debug mode will print all of the printfs associated with this test. michael@0: ** The regress mode will be the default mode. Since the regress tool limits michael@0: ** the output to a one line status:PASS or FAIL,all of the printf statements michael@0: ** have been handled with an if (debug_mode) statement. michael@0: ***********************************************************************/ michael@0: #include "prinit.h" michael@0: michael@0: /*********************************************************************** michael@0: ** Includes michael@0: ***********************************************************************/ michael@0: /* Used to get the command line option */ michael@0: #include "plgetopt.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: static void PrintVersion( michael@0: const char *msg, const PRVersion* info, PRIntn tab) michael@0: { michael@0: static const len = 20; michael@0: static const char *tabs = {" "}; michael@0: michael@0: tab *= 2; michael@0: if (tab > len) tab = len; michael@0: printf("%s", &tabs[len - tab]); michael@0: printf("%s ", msg); michael@0: printf("%s ", info->id); michael@0: printf("%d.%d", info->major, info->minor); michael@0: if (0 != info->patch) michael@0: printf(".p%d", info->patch); michael@0: printf("\n"); michael@0: } /* PrintDependency */ michael@0: michael@0: static void ChaseDependents(const PRVersionInfo *info, PRIntn tab) michael@0: { michael@0: PrintVersion("exports", &info->selfExport, tab); michael@0: if (NULL != info->importEnumerator) michael@0: { michael@0: const PRDependencyInfo *dependent = NULL; michael@0: while (NULL != (dependent = info->importEnumerator(dependent))) michael@0: { michael@0: const PRVersionInfo *import = dependent->exportInfoFn(); michael@0: PrintVersion("imports", &dependent->importNeeded, tab); michael@0: ChaseDependents(import, tab + 1); michael@0: } michael@0: } michael@0: } /* ChaseDependents */ michael@0: michael@0: static PRVersionInfo hack_export; michael@0: static PRVersionInfo dummy_export; michael@0: static PRDependencyInfo dummy_imports[2]; michael@0: michael@0: static const PRVersionInfo *HackExportInfo(void) michael@0: { michael@0: hack_export.selfExport.major = 11; michael@0: hack_export.selfExport.minor = 10; michael@0: hack_export.selfExport.patch = 200; michael@0: hack_export.selfExport.id = "Hack"; michael@0: hack_export.importEnumerator = NULL; michael@0: return &hack_export; michael@0: } michael@0: michael@0: static const PRDependencyInfo *DummyImports( michael@0: const PRDependencyInfo *previous) michael@0: { michael@0: if (NULL == previous) return &dummy_imports[0]; michael@0: else if (&dummy_imports[0] == previous) return &dummy_imports[1]; michael@0: else if (&dummy_imports[1] == previous) return NULL; michael@0: } /* DummyImports */ michael@0: michael@0: static const PRVersionInfo *DummyLibVersion(void) michael@0: { michael@0: dummy_export.selfExport.major = 1; michael@0: dummy_export.selfExport.minor = 0; michael@0: dummy_export.selfExport.patch = 0; michael@0: dummy_export.selfExport.id = "Dumbass application"; michael@0: dummy_export.importEnumerator = DummyImports; michael@0: michael@0: dummy_imports[0].importNeeded.major = 2; michael@0: dummy_imports[0].importNeeded.minor = 0; michael@0: dummy_imports[0].importNeeded.patch = 0; michael@0: dummy_imports[0].importNeeded.id = "Netscape Portable Runtime"; michael@0: dummy_imports[0].exportInfoFn = PR_ExportInfo; michael@0: michael@0: dummy_imports[1].importNeeded.major = 5; michael@0: dummy_imports[1].importNeeded.minor = 1; michael@0: dummy_imports[1].importNeeded.patch = 2; michael@0: dummy_imports[1].importNeeded.id = "Hack Library"; michael@0: dummy_imports[1].exportInfoFn = HackExportInfo; michael@0: michael@0: return &dummy_export; michael@0: } /* DummyLibVersion */ michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRIntn tab = 0; michael@0: const PRVersionInfo *info = DummyLibVersion(); michael@0: const char *buildDate = __DATE__, *buildTime = __TIME__; michael@0: michael@0: printf("Depend.c build time is %s %s\n", buildDate, buildTime); michael@0: michael@0: if (NULL != info) ChaseDependents(info, tab); michael@0: michael@0: return 0; michael@0: } /* main */ michael@0: michael@0: /* depend.c */