3065 some functions in the tcp module can be static
[unleashed.git] / usr / src / cmd / man / src / util / nsgmls.src / lib / EntityApp.cxx
bloba6b02c332ad4db0a1a94409a834bd07b93ca1ef5
1 // Copyright (c) 1996 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
9 #include "splib.h"
10 #include "EntityApp.h"
11 #include "sptchar.h"
13 #include <stdlib.h>
15 #include "PosixStorage.h"
16 #ifdef SP_WININET
17 #include "WinInetStorage.h"
18 #else
19 #include "URLStorage.h"
20 #endif
21 #include "LiteralStorage.h"
22 #include "NotationStorage.h"
23 #include "ExtendEntityManager.h"
24 #include "SOEntityCatalog.h"
25 #include "CodingSystem.h"
26 #include "macros.h"
28 #ifndef SGML_SEARCH_PATH_DEFAULT
29 #define SGML_SEARCH_PATH_DEFAULT SP_T("")
30 #endif
32 #ifndef SGML_CATALOG_FILES_DEFAULT
33 #define SGML_CATALOG_FILES_DEFAULT SP_T("")
34 #endif /* not SGML_CATALOG_FILES_DEFAULT */
36 #ifdef SP_NAMESPACE
37 namespace SP_NAMESPACE {
38 #endif
40 #ifdef SP_MSDOS_FILENAMES
41 const Char FILE_SEP = ';';
42 #else
43 const Char FILE_SEP = ':';
44 #endif
46 EntityApp::EntityApp(const char *requiredInternalCode)
47 : CmdLineApp(requiredInternalCode),
48 mapCatalogDocument_(0)
50 registerOption('c', SP_T("catalog_sysid"));
51 registerOption('C');
52 registerOption('D', SP_T("dir"));
55 void EntityApp::processOption(AppChar opt, const AppChar *arg)
57 switch (opt) {
58 case 'c':
59 catalogSysids_.push_back(arg);
60 break;
61 case 'C':
62 mapCatalogDocument_ = 1;
63 break;
64 case 'D':
65 searchDirs_.push_back(arg);
66 break;
67 default:
68 CmdLineApp::processOption(opt, arg);
69 break;
73 int EntityApp::processArguments(int argc, AppChar **argv)
75 StringC sysid;
76 if (!makeSystemId(argc, argv, sysid))
77 return 1;
78 return processSysid(sysid);
81 Boolean EntityApp::makeSystemId(int nFiles, AppChar *const *files,
82 StringC &result)
84 Vector<StringC> filenames(nFiles == 0 ? 1 : nFiles);
85 int i;
86 for (i = 0; i < nFiles; i++)
87 filenames[i] = convertInput(tcscmp(files[i], SP_T("-")) == 0
88 ? SP_T("<OSFD>0")
89 : files[i]);
90 if (nFiles == 0)
91 filenames[0] = convertInput(SP_T("<OSFD>0"));
92 return entityManager()->mergeSystemIds(filenames,
93 mapCatalogDocument_,
94 systemCharset(),
95 *this,
96 result);
100 Ptr<ExtendEntityManager> &EntityApp::entityManager()
102 if (!entityManager_.isNull())
103 return entityManager_;
104 PosixStorageManager *sm
105 = new PosixStorageManager("OSFILE",
106 &systemCharset(),
107 #ifndef SP_WIDE_SYSTEM
108 codingSystem(),
109 #endif
111 size_t i;
112 for (i = 0; i < searchDirs_.size(); i++)
113 sm->addSearchDir(convertInput(searchDirs_[i]));
115 const AppChar *e = tgetenv(SP_T("SGML_SEARCH_PATH"));
116 if (!e)
117 e = SGML_SEARCH_PATH_DEFAULT;
118 if (*e) {
119 StringC str(convertInput(e));
120 size_t i = 0;
121 size_t start = 0;
122 for (;;) {
123 if (i == str.size() || str[i] == FILE_SEP) {
124 sm->addSearchDir(StringC(str.data() + start,
125 i - start));
126 if (i == str.size())
127 break;
128 start = ++i;
130 else
131 i++;
136 entityManager_ = ExtendEntityManager::make(sm,
137 codingSystem(),
138 inputCodingSystemKit(),
139 internalCharsetIsDocCharset_);
140 entityManager_
141 ->registerStorageManager(new PosixFdStorageManager("OSFD",
142 &systemCharset()));
143 #ifdef SP_WININET
144 entityManager_->registerStorageManager(new WinInetStorageManager("URL"));
145 #else
146 entityManager_->registerStorageManager(new URLStorageManager("URL"));
147 #endif
148 entityManager_->registerStorageManager(new LiteralStorageManager("LITERAL"));
149 entityManager_->registerStorageManager(new NotationStorageManager("CLSID"));
150 entityManager_->registerStorageManager(new NotationStorageManager("MIMETYPE"));
151 Vector<StringC> v;
152 for (i = 0; i < catalogSysids_.size(); i++)
153 // filenames specified on command-line must exist
154 v.push_back(convertInput(catalogSysids_[i]));
156 const AppChar *e = tgetenv(SP_T("SGML_CATALOG_FILES"));
157 if (!e)
158 e = SGML_CATALOG_FILES_DEFAULT;
159 if (*e) {
160 StringC str(convertInput(e));
161 size_t i = 0;
162 size_t start = 0;
163 for (;;) {
164 if (i == str.size() || str[i] == FILE_SEP) {
165 v.push_back(StringC(str.data() + start,
166 i - start));
167 if (i == str.size())
168 break;
169 start = ++i;
171 else
172 i++;
176 const SP_TCHAR *useDocCatalogStr = tgetenv(SP_T("SP_USE_DOCUMENT_CATALOG"));
177 Boolean useDocCatalog = true;
178 if (useDocCatalogStr
179 && (stringMatches(useDocCatalogStr, "NO")
180 || stringMatches(useDocCatalogStr, "0")))
181 useDocCatalog = false;
182 entityManager_->setCatalogManager(SOCatalogManager::make(v,
183 catalogSysids_.size(),
184 &systemCharset(),
185 &systemCharset(),
186 useDocCatalog));
187 return entityManager_;
190 #ifdef SP_NAMESPACE
192 #endif