home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / depend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.6 KB  |  135 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /***********************************************************************
  20. **  1996 - Netscape Communications Corporation
  21. **
  22. **
  23. ** Name:        depend.c
  24. ** Description: Test to enumerate the dependencies
  25. *
  26. ** Modification History:
  27. ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
  28. **             The debug mode will print all of the printfs associated with this test.
  29. **             The regress mode will be the default mode. Since the regress tool limits
  30. **           the output to a one line status:PASS or FAIL,all of the printf statements
  31. **             have been handled with an if (debug_mode) statement. 
  32. ***********************************************************************/
  33. #include "prinit.h"
  34.  
  35. /***********************************************************************
  36. ** Includes
  37. ***********************************************************************/
  38. /* Used to get the command line option */
  39. #include "plgetopt.h"
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43.  
  44. static void PrintVersion(
  45.     const char *msg, const PRVersion* info, PRIntn tab)
  46. {
  47.     static const len = 20;
  48.     static const char *tabs = {"                    "};
  49.  
  50.     tab *= 2;
  51.     if (tab > len) tab = len;
  52.     printf("%s", &tabs[len - tab]);
  53.     printf("%s ", msg);
  54.     printf("%s ", info->id);
  55.     printf("%d.%d", info->major, info->minor);
  56.     if (0 != info->patch)
  57.         printf(".p%d", info->patch);
  58.     printf("\n");
  59. }  /* PrintDependency */
  60.  
  61. static void ChaseDependents(const PRVersionInfo *info, PRIntn tab)
  62. {
  63.     PrintVersion("exports", &info->selfExport, tab);
  64.     if (NULL != info->importEnumerator)
  65.     {
  66.         const PRDependencyInfo *dependent = NULL;
  67.         while (NULL != (dependent = info->importEnumerator(dependent)))
  68.         {
  69.             const PRVersionInfo *import = dependent->exportInfoFn();
  70.             PrintVersion("imports", &dependent->importNeeded, tab);
  71.             ChaseDependents(import, tab + 1);
  72.         }
  73.     }
  74. }  /* ChaseDependents */
  75.  
  76. static PRVersionInfo hack_export;
  77. static PRVersionInfo dummy_export;
  78. static PRDependencyInfo dummy_imports[2];
  79.  
  80. static const PRVersionInfo *HackExportInfo(void)
  81. {
  82.     hack_export.selfExport.major = 11;
  83.     hack_export.selfExport.minor = 10;
  84.     hack_export.selfExport.patch = 200;
  85.     hack_export.selfExport.id = "Hack";
  86.     hack_export.importEnumerator = NULL;
  87.     return &hack_export;
  88. }
  89.  
  90. static const PRDependencyInfo *DummyImports(
  91.     const PRDependencyInfo *previous)
  92. {
  93.     if (NULL == previous) return &dummy_imports[0];
  94.     else if (&dummy_imports[0] == previous) return &dummy_imports[1];
  95.     else if (&dummy_imports[1] == previous) return NULL;
  96. }  /* DummyImports */
  97.  
  98. static const PRVersionInfo *DummyLibVersion(void)
  99. {
  100.     dummy_export.selfExport.major = 1;
  101.     dummy_export.selfExport.minor = 0;
  102.     dummy_export.selfExport.patch = 0;
  103.     dummy_export.selfExport.id = "Dumbass application";
  104.     dummy_export.importEnumerator = DummyImports;
  105.  
  106.     dummy_imports[0].importNeeded.major = 2;
  107.     dummy_imports[0].importNeeded.minor = 0;
  108.     dummy_imports[0].importNeeded.patch = 0;
  109.     dummy_imports[0].importNeeded.id = "Netscape Portable Runtime";
  110.     dummy_imports[0].exportInfoFn = PR_ExportInfo;
  111.  
  112.     dummy_imports[1].importNeeded.major = 5;
  113.     dummy_imports[1].importNeeded.minor = 1;
  114.     dummy_imports[1].importNeeded.patch = 2;
  115.     dummy_imports[1].importNeeded.id = "Hack Library";
  116.     dummy_imports[1].exportInfoFn = HackExportInfo;
  117.  
  118.     return &dummy_export;
  119. }  /* DummyLibVersion */
  120.  
  121. int main(int argc, char **argv)
  122. {
  123.     PRIntn tab = 0;
  124.     const PRVersionInfo *info = DummyLibVersion();
  125.     const char *buildDate = __DATE__, *buildTime = __TIME__;
  126.  
  127.     printf("Depend.c build time is %s %s\n", buildDate, buildTime);
  128.     
  129.     if (NULL != info) ChaseDependents(info, tab);
  130.  
  131.     return 0;
  132. }  /* main */
  133.  
  134. /* depend.c */
  135.