2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: EntityApp.C /main/1 1996/07/29 16:49:57 cde-hp $ */
24 // Copyright (c) 1996 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "EntityApp.h"
38 #include "ISO8859InputCodingSystem.h"
41 #include "PosixStorage.h"
42 #include "URLStorage.h"
43 #include "LiteralStorage.h"
44 #include "ExtendEntityManager.h"
45 #include "SOEntityCatalog.h"
46 #include "CodingSystem.h"
49 #ifndef SGML_SEARCH_PATH_DEFAULT
50 #define SGML_SEARCH_PATH_DEFAULT SP_T("")
53 #ifndef SGML_CATALOG_FILES_DEFAULT
54 #define SGML_CATALOG_FILES_DEFAULT SP_T("")
55 #endif /* not SGML_CATALOG_FILES_DEFAULT */
58 namespace SP_NAMESPACE {
61 #ifdef MSDOS_FILENAMES
62 const Char FILE_SEP = ';';
64 const Char FILE_SEP = ':';
68 static ISO8859InputCodingSystem iso8859_2InputCodingSystem(2);
69 static ISO8859InputCodingSystem iso8859_3InputCodingSystem(3);
70 static ISO8859InputCodingSystem iso8859_4InputCodingSystem(4);
71 static ISO8859InputCodingSystem iso8859_5InputCodingSystem(5);
72 static ISO8859InputCodingSystem iso8859_6InputCodingSystem(6);
73 static ISO8859InputCodingSystem iso8859_7InputCodingSystem(7);
74 static ISO8859InputCodingSystem iso8859_8InputCodingSystem(8);
75 static ISO8859InputCodingSystem iso8859_9InputCodingSystem(9);
79 const InputCodingSystem *cs;
80 } inputCodingSystems[] = {
81 { "IS8859-2", &iso8859_2InputCodingSystem },
82 { "IS8859-3", &iso8859_3InputCodingSystem },
83 { "IS8859-4", &iso8859_4InputCodingSystem },
84 { "IS8859-5", &iso8859_5InputCodingSystem },
85 { "IS8859-6", &iso8859_6InputCodingSystem },
86 { "IS8859-7", &iso8859_7InputCodingSystem },
87 { "IS8859-8", &iso8859_8InputCodingSystem },
88 { "IS8859-9", &iso8859_9InputCodingSystem },
91 #endif /* SP_MULTI_BYTE */
94 static UnivCharsetDesc::Range range = { 0, 65536, 0 };
96 static UnivCharsetDesc::Range range = { 0, 256, 0 };
99 EntityApp::EntityApp()
100 : mapCatalogDocument_(0),
101 systemCharset_(UnivCharsetDesc(&range, 1))
103 registerOption('c', SP_T("catalog_sysid"));
105 registerOption('D', SP_T("dir"));
108 void EntityApp::processOption(AppChar opt, const AppChar *arg)
112 catalogSysids_.push_back(arg);
115 mapCatalogDocument_ = 1;
118 searchDirs_.push_back(arg);
121 CmdLineApp::processOption(opt, arg);
126 int EntityApp::processArguments(int argc, AppChar **argv)
129 if (!makeSystemId(argc, argv, sysid))
131 return processSysid(sysid);
134 Boolean EntityApp::makeSystemId(int nFiles, AppChar *const *files,
137 Vector<StringC> filenames(nFiles == 0 ? 1 : nFiles);
139 for (i = 0; i < nFiles; i++)
140 filenames[i] = convertInput(tcscmp(files[i], SP_T("-")) == 0
144 filenames[0] = convertInput(SP_T("<OSFD>0"));
145 return entityManager()->mergeSystemIds(filenames,
153 Ptr<ExtendEntityManager> &EntityApp::entityManager()
155 if (!entityManager_.isNull())
156 return entityManager_;
157 PosixStorageManager *sm
158 = new PosixStorageManager("OSFILE",
159 systemCharset_.desc(),
160 #ifndef SP_WIDE_SYSTEM
165 for (i = 0; i < searchDirs_.size(); i++)
166 sm->addSearchDir(convertInput(searchDirs_[i]));
168 const AppChar *e = tgetenv(SP_T("SGML_SEARCH_PATH"));
170 e = SGML_SEARCH_PATH_DEFAULT;
172 StringC str(convertInput(e));
176 if (i == str.size() || str[i] == FILE_SEP) {
177 sm->addSearchDir(StringC(str.data() + start,
189 entityManager_ = ExtendEntityManager::make(sm, codingSystem());
191 ->registerStorageManager(new PosixFdStorageManager("OSFD",
192 systemCharset_.desc()));
193 entityManager_->registerStorageManager(new URLStorageManager("URL"));
194 entityManager_->registerStorageManager(new LiteralStorageManager("LITERAL"));
197 const CodingSystem *p = codingSystem(i, s);
200 entityManager_->registerCodingSystem(s, p);
203 for (i = 0; i < SIZEOF(inputCodingSystems); i++)
204 entityManager_->registerCodingSystem(inputCodingSystems[i].name,
205 inputCodingSystems[i].cs);
208 for (i = 0; i < catalogSysids_.size(); i++)
209 // filenames specified on command-line must exist
210 v.push_back(convertInput(catalogSysids_[i]));
212 const AppChar *e = tgetenv(SP_T("SGML_CATALOG_FILES"));
214 e = SGML_CATALOG_FILES_DEFAULT;
216 StringC str(convertInput(e));
220 if (i == str.size() || str[i] == FILE_SEP) {
221 v.push_back(StringC(str.data() + start,
232 entityManager_->setCatalogManager(SOCatalogManager::make(v,
233 catalogSysids_.size(),
236 return entityManager_;