Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
catalog.cpp
Go to the documentation of this file.
1
29#define _RWSTD_LIB_SRC
30
31#include <rw/_defs.h>
32
33#if defined (_RWSTD_NO_NL_TYPES_H) || defined (_RWSTD_NO_CATOPEN_CATGETS)
34
35#include <vector>
36#include <stdio.h>
37#include "catalog.h"
38
39
41
42_USING (namespace std);
43
44
45typedef _STD::vector<__rw_cat*> CatVector;
46
47static CatVector __rw_catlist (2);
48
49
50#ifdef _RWSTD_USE_RC
51
52 const char* __rw_cat::catgets(int, int msg_num, const char* s)
53 {
54 __cat_type::iterator it = __msgs.find(msg_num);
55 if (it != __msgs.end())
56 return (*it).second.c_str ();
57 else {
58 char buf[NL_TEXTMAX];
59 if (LoadString(__cat,(UINT)msg_num,buf,NL_TEXTMAX))
60 {
61 pair<__cat_type::iterator,bool> ret =
62 __msgs.insert (__msg_type (msg_num, string(buf)));
63 if (ret.second)
64 return (*ret.first).second.c_str ();
65 }
66 }
67 return s;
68 }
69
70#endif //_RWSTD_USE_RC
71
72 CatVector::size_type __catfind(nl_catd id)
73 {
74 for (CatVector::size_type i = 0;
75 i < __rw_catlist.size() && __rw_catlist[i]; ++i) {
76
77 if (__rw_catlist[i]->id() == id)
78 return i;
79 }
80
81 return __rw_catlist.size();
82 }
83
84
85} // namespace __rw
86
87
88_USING (namespace __rw);
89
90
91nl_catd catopen(const char* name, int oflag)
92{
93 __rw_cat* cat = 0;
94
95 _TRY {
96 cat = new __rw_cat(name,oflag);
97
98 if (cat && cat->good()) {
99 CatVector::size_type i = 0;
100 for (; i < __rw_catlist.size() && __rw_catlist[i]; ++i) ;
101 if (__rw_catlist.size() == i)
102 __rw_catlist.resize(__rw_catlist.size() * 2,0);
103 __rw_catlist[i] = cat;
104 return cat->id();
105 }
106 }
107 _CATCH (...) {
108 }
109
110 delete cat;
111 return (nl_catd)-1;
112}
113
114
115const char * catgets(nl_catd catd, int set_num, int msg_num, const char* s)
116{
117 _TRY {
118
119 CatVector::size_type i = __catfind(catd);
120 if (i < __rw_catlist.size())
121 return __rw_catlist[i]->catgets(set_num,msg_num,s);
122
123 return s;
124 }
125 _CATCH (...) {
126 return s;
127 }
128}
129
130
131int catclose(nl_catd catd)
132{
133 CatVector::size_type i = __catfind(catd);
134 if (i < __rw_catlist.size())
135 {
136 delete __rw_catlist[i];
137 __rw_catlist[i] = 0;
138 CatVector::size_type j;
139 for (j = i+1; j < __rw_catlist.size() && __rw_catlist[j]; j++)
140 __rw_catlist[j-1] = __rw_catlist[j];
141 if (j < __rw_catlist.size())
142 __rw_catlist[j] = 0;
143 else
144 __rw_catlist[__rw_catlist.size () - 1] = 0;
145 return 0;
146 }
147 return -1;
148}
149
150
151#endif // _RWSTD_NO_NL_TYPES_H || _RWSTD_NO_CATOPEN_CATGETS
#define i
Definition 17.names.cpp:126
#define UINT
Definition 17.names.cpp:565
#define buf
Definition 17.names.cpp:452
#define j
Definition 17.names.cpp:127
#define s
#define _TRY
Definition _defs.h:850
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _CATCH(ex)
Definition _defs.h:851
#define _USING(name)
Definition _defs.h:568
nl_catd catopen(const char *, int)
int catclose(nl_catd)
const char * catgets(nl_catd, int, int, const char *)
_RW::__rw_cat * nl_catd
Definition catalog.h:128
const char * name
Definition codecvt1.cpp:72
Definition json.h:5363