Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / UAS / MMDB / MMDB.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $TOG: MMDB.C /main/8 1998/04/17 11:42:22 mgreess $
24 #include <stream.h>
25 #include "MMDB.hh"
26 #include "UAS_Exceptions.hh"
27 #include "UAS_Buffer.hh"
28 #include "UAS_Common.hh"
29 #include "UAS_Msgs.hh"
30 #include "MMDB_Factory.hh"
31
32 #include "Managers/CatMgr.hh"
33 #include "Registration.hh"
34
35 MMDB::MMDB(const UAS_String &infolibPath)
36 : f_initialized (0), fInfoLibPath (infolibPath)
37 {
38   f_oliasDB = &MMDB_Factory::olias_db();
39   f_infoLib =  f_oliasDB->openInfoLib((char *) infolibPath, 0,
40                 MMDB_Factory::genInfolibName());
41 }
42
43 MMDB::~MMDB()
44 {
45     if (f_infoLib) {
46         //f_oliasDB->closeInfoLib (f_infoLib->get_info_lib_name());
47         f_oliasDB->closeInfoLib (f_infoLib->get_info_lib_uid());
48     }
49     f_infoLib = 0;
50 }
51
52 UAS_String
53 MMDB::infoLibPath () {
54     return fInfoLibPath;
55 }
56
57 UAS_String
58 MMDB::infoLibUid()
59 {
60   return UAS_String(f_infoLib->get_info_lib_uid());
61 }
62
63 OLIAS_DB *
64 MMDB::database()
65 {
66   if (!f_initialized)
67     {
68       f_initialized = 1;
69       info_lib *lib = f_infoLib;
70       int bad_count = lib->bad_infobases();
71       if (bad_count > 0)
72         {
73           UAS_ErrorMsg msg;
74           UAS_Buffer buf(256);
75           const char *x =
76                 (char*)UAS_String(CATGETS(Set_UAS_MMDB, 1, "The following bookcases are not valid:"));
77           buf.write (x, sizeof(char), strlen(x));
78           for (int i = 1; i <= bad_count; i++)
79             {
80               buf.write ("\n", sizeof(char), 1);
81               x = lib->get_bad_infobase_path(i);
82               buf.write (x, sizeof(char), strlen(x));
83               buf.write ("/", sizeof(char), 1);
84               x = lib->get_bad_infobase_name(i);
85               buf.write (x, sizeof(char), strlen(x));
86             }
87           buf.write ("\0", sizeof(char), 1);
88           msg.fErrorMsg = buf.data();
89           UAS_Common::send_message (msg);
90         }
91     }
92   return (f_oliasDB);
93 }
94
95 info_base *
96 MMDB::infobase (const char *locator)
97 {
98   info_base *ib = f_infoLib->getInfobaseByComponent((const char *)locator,
99                     info_lib::LOC);
100   if (ib == NULL)
101     throw (CASTEXCEPT Exception());
102   else
103     return (ib);
104 }