Add missing license headers on *.hh files and others
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Marks / MarkBase.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 libraries 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 /*
24  * $XConsortium: MarkBase.cc /main/3 1996/06/11 16:29:11 cde-hal $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #define C_xList
52 #define L_Support
53
54 #define C_Mark
55 #define C_MarkBase
56 #define L_Marks
57
58 #include <Prelude.h>
59
60 #include <string.h>
61
62 static xList<MarkBase::open_func_t> *g_open_func_list;
63 static xList<MarkBase::mb_create_func_t> *g_create_func_list;
64 static xList<const char *> *g_create_format_list;
65
66 MarkBase::~MarkBase()
67 {
68 }
69
70
71 // /////////////////////////////////////////////////////////////////
72 // register a MarkBase creation function
73 // /////////////////////////////////////////////////////////////////
74
75 int
76 MarkBase::register_open_func (open_func_t open_func)
77 {
78   ON_DEBUG (printf ("Registered MarkBase open func\n"));
79   static xList<open_func_t> open_func_list;
80   if (g_open_func_list == NULL)
81     g_open_func_list = &open_func_list;
82
83   open_func_list.append (open_func);
84   return (0);
85 }
86
87 int
88 MarkBase::register_create_func (mb_create_func_t create_func, const char *format)
89 {
90   ON_DEBUG (printf ("Registered `%s' creation func\n", format));
91   static xList<mb_create_func_t> create_func_list;
92   static xList<const char *> create_format_list;
93
94   if (g_create_func_list == NULL)
95     {
96       g_create_func_list = &create_func_list;
97       g_create_format_list = &create_format_list;
98     }
99
100   create_func_list.append (create_func);
101   create_format_list.append (format);
102   return (0);
103 }
104
105
106 // /////////////////////////////////////////////////////////////////
107 // create a new mark base by calling the registered functions
108 // /////////////////////////////////////////////////////////////////
109
110 MarkBase *
111 MarkBase::open (const char *filename, bool read_only)
112 {
113   MarkBase *base = NULL;
114   List_Iterator<open_func_t> open_func (g_open_func_list);
115
116   while (open_func)
117     {
118       base = open_func.item() (filename, read_only);
119       if (base != NULL)
120         break;
121       open_func++;
122     }
123   return (base);
124 }
125
126
127 MarkBase *
128 MarkBase::create (const char *filename, bool read_only, const char *format)
129 {
130   MarkBase *base = NULL;
131   List_Iterator<const char *> fmt (g_create_format_list);
132   List_Iterator<mb_create_func_t> create_func (g_create_func_list);
133
134   // Find a matching format creation function.
135   while (fmt)
136     {
137       if (strcmp (fmt.item(), format) == 0)
138         break;
139       fmt++;
140       create_func++;
141     }
142
143   // Create the base if a matching format was found. 
144   if (fmt)
145     base = create_func.item() (filename, read_only);
146
147   return (base);
148 }