ccf0e6d4b7ba30b4ff024b87508e46ec14edde6e
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / install / valBase.C
1 /*
2  * $XConsortium: valBase.C /main/5 1996/10/29 21:14:58 cde-hal $
3  *
4  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
5  * All rights reserved.  Unpublished -- rights reserved under
6  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
7  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
8  * OR DISCLOSURE.
9  * 
10  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
11  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
12  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
13  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
14  * INTERNATIONAL, LTD.
15  * 
16  *                         RESTRICTED RIGHTS LEGEND
17  * Use, duplication, or disclosure by the Government is subject
18  * to the restrictions as set forth in subparagraph (c)(l)(ii)
19  * of the Rights in Technical Data and Computer Software clause
20  * at DFARS 252.227-7013.
21  *
22  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
23  *                  1315 Dell Avenue
24  *                  Campbell, CA  95008
25  * 
26  */
27
28 #include <iostream.h>
29 #include <assert.h>
30 #include <string.h>
31 #include <stdlib.h>
32
33 // MMDB header file
34 #include "oliasdb/mmdb.h"
35 #include "oliasdb/asciiIn_filters.h"
36
37 // DDK header file
38 #include "olGlobal.h"
39
40 // Debuggging macro
41 int dbgLevel;
42 #ifdef DEBUG
43 #define DBG(level) if ( dbgLevel >= level )
44 #else
45 #define DBG(level) if (0)
46 #endif
47
48 //------------------------------------------------
49 int dbgInit()
50 {
51   char *dbgStr;
52
53   dbgStr = getenv("OL_DEBUG");
54   return ( dbgStr ? atoi ( dbgStr ) : 0 );
55 }
56
57 //------------------------------------------------
58 main(int argc, char **argv)
59 {
60   
61   INIT_EXCEPTIONS();
62
63   OLIAS_DB mmdb_handle;
64   info_lib *InfoLib;
65
66   char checkVersionStr [ 16 ];
67   char installVersionStr [ 16 ];
68   char locatorStr[64];
69   
70   dbgLevel = dbgInit();
71
72   try {
73     
74    if ( argc < 2 ) {
75      cerr << "Usage : valBase checkBase installBase\n";
76      exit (1);
77    }
78
79    char *checkBaseStr = argv[1];
80    char *installBaseStr = argv[2];
81    
82    DBG(10) cerr << "(DEBUG) checkBase = " << checkBaseStr << endl;
83    DBG(10) cerr << "(DEBUG) installBase = " << installBaseStr << endl;
84
85    // first construct the info_base ptr for installBase
86
87    InfoLib = mmdb_handle.openInfoLib(getenv("MMDB_PATH"));
88    assert ( InfoLib != NULL );
89
90    info_base *installBase = InfoLib->get_info_base ( installBaseStr );
91    if ( !installBase ) 
92      throw(stringException("NULL infobase ptr for installation infobase"));
93
94    // construct the info_base ptr for checkBase
95
96    info_base *checkBase = InfoLib->get_info_base ( checkBaseStr );
97    if ( !checkBase ) 
98      throw(stringException("NULL infobase ptr for check infobase"));
99
100    // check the data version number
101
102    mm_version &checkVersion = checkBase->data_version();
103    short major_version_check = checkVersion.major_version();
104    short minor_version_check = checkVersion.minor_version();
105
106    sprintf ( checkVersionStr, "%d%d", major_version_check,
107                                       minor_version_check );
108    
109    int checkVersionNum = atoi ( checkVersionStr );
110
111    DBG(10) cerr << "(DEBUG) checkBaseVersion = " << checkVersionNum << endl;
112    
113    mm_version &installVersion = installBase->data_version();
114    short major_version_install = installVersion.major_version();
115    short minor_version_install = installVersion.minor_version();
116
117    sprintf ( installVersionStr, "%d%d", major_version_install,
118                                         minor_version_install );
119    int installVersionNum = atoi ( installVersionStr );
120
121    DBG(10) cerr << "(DEBUG) installVersionNum = " << installVersionNum << endl;
122
123    // Now perform the version checking
124
125    if ( installVersionNum == 10 ) {
126      if ( checkVersionNum >= 11 ) {
127        cerr << "(ERROR) Data version mismatch\n";
128        cerr << "        " << checkBaseStr << " version = "
129             << major_version_check << "." << minor_version_check << endl;
130        cerr << "        " << installBaseStr << " version = "
131             << major_version_install << "." << minor_version_install << endl;
132        exit ( 1 );
133      }
134    }
135    else if ( checkVersionNum == 10 ) {
136      if ( installVersionNum >= 11 ) {
137        cerr << "(ERROR) Data version mismatch\n";
138        cerr << "        " << checkBaseStr << " version = "
139             << major_version_check << "." << minor_version_check << endl;
140        cerr << "        " << installBaseStr << " version = "
141             << major_version_install << "." << minor_version_install << endl;
142        exit ( 1 );
143      }
144    }
145
146    // Now to check locators
147
148    iterator *it = checkBase->first(LOCATOR_SET_NAME, LOCATOR_CODE );
149
150    int DupLocFound=0;
151    
152    while ( *it ) {
153
154      locator_smart_ptr x(checkBase, checkBase->get_oid(*it));
155
156      strcpy ( locatorStr, x.inside_node_locator_str() );
157
158      DBG(10) cerr << "(DEBUG) locatorStr = " << locatorStr
159                   << endl;
160
161      // check this locator value with the installation infobase
162      locator_smart_ptr loc(installBase, locatorStr);
163
164      if (! strcmp(loc.inside_node_locator_str(), locatorStr))
165      {
166          cerr << "(ERROR) Duplicate locator [ " << locatorStr
167               << " ] found in " << installBaseStr << endl;
168          DupLocFound = 1;
169      }
170     
171      checkBase->next(*it);
172    }
173
174    // clean up phase
175    delete it;
176    delete InfoLib;
177
178    if ( DupLocFound ) {
179      exit ( 1 );
180    }
181
182    exit (0);
183  } 
184
185  catch ( mmdbException &, e )
186  {
187    debug(cerr, e );
188    abort();
189  }
190  end_try;
191
192 }
193