Back to index

lightning-sunbird  0.9+nobinonly
depend.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /***********************************************************************
00039 **  1996 - Netscape Communications Corporation
00040 **
00041 **
00042 ** Name:             depend.c
00043 ** Description: Test to enumerate the dependencies
00044 *
00045 ** Modification History:
00046 ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
00047 **              The debug mode will print all of the printfs associated with this test.
00048 **                    The regress mode will be the default mode. Since the regress tool limits
00049 **           the output to a one line status:PASS or FAIL,all of the printf statements
00050 **                    have been handled with an if (debug_mode) statement. 
00051 ***********************************************************************/
00052 #include "prinit.h"
00053 
00054 /***********************************************************************
00055 ** Includes
00056 ***********************************************************************/
00057 /* Used to get the command line option */
00058 #include "plgetopt.h"
00059 
00060 #include <stdio.h>
00061 #include <stdlib.h>
00062 
00063 static void PrintVersion(
00064     const char *msg, const PRVersion* info, PRIntn tab)
00065 {
00066     static const len = 20;
00067     static const char *tabs = {"                    "};
00068 
00069     tab *= 2;
00070     if (tab > len) tab = len;
00071     printf("%s", &tabs[len - tab]);
00072     printf("%s ", msg);
00073     printf("%s ", info->id);
00074     printf("%d.%d", info->major, info->minor);
00075     if (0 != info->patch)
00076         printf(".p%d", info->patch);
00077     printf("\n");
00078 }  /* PrintDependency */
00079 
00080 static void ChaseDependents(const PRVersionInfo *info, PRIntn tab)
00081 {
00082     PrintVersion("exports", &info->selfExport, tab);
00083     if (NULL != info->importEnumerator)
00084     {
00085         const PRDependencyInfo *dependent = NULL;
00086         while (NULL != (dependent = info->importEnumerator(dependent)))
00087         {
00088             const PRVersionInfo *import = dependent->exportInfoFn();
00089             PrintVersion("imports", &dependent->importNeeded, tab);
00090             ChaseDependents(import, tab + 1);
00091         }
00092     }
00093 }  /* ChaseDependents */
00094 
00095 static PRVersionInfo hack_export;
00096 static PRVersionInfo dummy_export;
00097 static PRDependencyInfo dummy_imports[2];
00098 
00099 static const PRVersionInfo *HackExportInfo(void)
00100 {
00101     hack_export.selfExport.major = 11;
00102     hack_export.selfExport.minor = 10;
00103     hack_export.selfExport.patch = 200;
00104     hack_export.selfExport.id = "Hack";
00105     hack_export.importEnumerator = NULL;
00106     return &hack_export;
00107 }
00108 
00109 static const PRDependencyInfo *DummyImports(
00110     const PRDependencyInfo *previous)
00111 {
00112     if (NULL == previous) return &dummy_imports[0];
00113     else if (&dummy_imports[0] == previous) return &dummy_imports[1];
00114     else if (&dummy_imports[1] == previous) return NULL;
00115 }  /* DummyImports */
00116 
00117 static const PRVersionInfo *DummyLibVersion(void)
00118 {
00119     dummy_export.selfExport.major = 1;
00120     dummy_export.selfExport.minor = 0;
00121     dummy_export.selfExport.patch = 0;
00122     dummy_export.selfExport.id = "Dumbass application";
00123     dummy_export.importEnumerator = DummyImports;
00124 
00125     dummy_imports[0].importNeeded.major = 2;
00126     dummy_imports[0].importNeeded.minor = 0;
00127     dummy_imports[0].importNeeded.patch = 0;
00128     dummy_imports[0].importNeeded.id = "Netscape Portable Runtime";
00129     dummy_imports[0].exportInfoFn = PR_ExportInfo;
00130 
00131     dummy_imports[1].importNeeded.major = 5;
00132     dummy_imports[1].importNeeded.minor = 1;
00133     dummy_imports[1].importNeeded.patch = 2;
00134     dummy_imports[1].importNeeded.id = "Hack Library";
00135     dummy_imports[1].exportInfoFn = HackExportInfo;
00136 
00137     return &dummy_export;
00138 }  /* DummyLibVersion */
00139 
00140 int main(int argc, char **argv)
00141 {
00142     PRIntn tab = 0;
00143     const PRVersionInfo *info = DummyLibVersion();
00144     const char *buildDate = __DATE__, *buildTime = __TIME__;
00145 
00146     printf("Depend.c build time is %s %s\n", buildDate, buildTime);
00147     
00148     if (NULL != info) ChaseDependents(info, tab);
00149 
00150     return 0;
00151 }  /* main */
00152 
00153 /* depend.c */