Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Marks / MarkBase.C
1 /*
2  * $XConsortium: MarkBase.cc /main/3 1996/06/11 16:29:11 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
29 #define C_xList
30 #define L_Support
31
32 #define C_Mark
33 #define C_MarkBase
34 #define L_Marks
35
36 #include <Prelude.h>
37
38 #include <string.h>
39
40 static xList<MarkBase::open_func_t> *g_open_func_list;
41 static xList<MarkBase::mb_create_func_t> *g_create_func_list;
42 static xList<const char *> *g_create_format_list;
43
44 MarkBase::~MarkBase()
45 {
46 }
47
48
49 // /////////////////////////////////////////////////////////////////
50 // register a MarkBase creation function
51 // /////////////////////////////////////////////////////////////////
52
53 int
54 MarkBase::register_open_func (open_func_t open_func)
55 {
56   ON_DEBUG (printf ("Registered MarkBase open func\n"));
57   static xList<open_func_t> open_func_list;
58   if (g_open_func_list == NULL)
59     g_open_func_list = &open_func_list;
60
61   open_func_list.append (open_func);
62   return (0);
63 }
64
65 int
66 MarkBase::register_create_func (mb_create_func_t create_func, const char *format)
67 {
68   ON_DEBUG (printf ("Registered `%s' creation func\n", format));
69   static xList<mb_create_func_t> create_func_list;
70   static xList<const char *> create_format_list;
71
72   if (g_create_func_list == NULL)
73     {
74       g_create_func_list = &create_func_list;
75       g_create_format_list = &create_format_list;
76     }
77
78   create_func_list.append (create_func);
79   create_format_list.append (format);
80   return (0);
81 }
82
83
84 // /////////////////////////////////////////////////////////////////
85 // create a new mark base by calling the registered functions
86 // /////////////////////////////////////////////////////////////////
87
88 MarkBase *
89 MarkBase::open (const char *filename, bool read_only)
90 {
91   MarkBase *base = NULL;
92   List_Iterator<open_func_t> open_func (g_open_func_list);
93
94   while (open_func)
95     {
96       base = open_func.item() (filename, read_only);
97       if (base != NULL)
98         break;
99       open_func++;
100     }
101   return (base);
102 }
103
104
105 MarkBase *
106 MarkBase::create (const char *filename, bool read_only, const char *format)
107 {
108   MarkBase *base = NULL;
109   List_Iterator<const char *> fmt (g_create_format_list);
110   List_Iterator<mb_create_func_t> create_func (g_create_func_list);
111
112   // Find a matching format creation function.
113   while (fmt)
114     {
115       if (strcmp (fmt.item(), format) == 0)
116         break;
117       fmt++;
118       create_func++;
119     }
120
121   // Create the base if a matching format was found. 
122   if (fmt)
123     base = create_func.item() (filename, read_only);
124
125   return (base);
126 }