1 // Copyright (c) 1996 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
10 #include "EntityApp.h"
15 #include "PosixStorage.h"
17 #include "WinInetStorage.h"
19 #include "URLStorage.h"
21 #include "LiteralStorage.h"
22 #include "NotationStorage.h"
23 #include "ExtendEntityManager.h"
24 #include "SOEntityCatalog.h"
25 #include "CodingSystem.h"
28 #ifndef SGML_SEARCH_PATH_DEFAULT
29 #define SGML_SEARCH_PATH_DEFAULT SP_T("")
32 #ifndef SGML_CATALOG_FILES_DEFAULT
33 #define SGML_CATALOG_FILES_DEFAULT SP_T("")
34 #endif /* not SGML_CATALOG_FILES_DEFAULT */
37 namespace SP_NAMESPACE
{
40 #ifdef SP_MSDOS_FILENAMES
41 const Char FILE_SEP
= ';';
43 const Char FILE_SEP
= ':';
46 EntityApp::EntityApp(const char *requiredInternalCode
)
47 : CmdLineApp(requiredInternalCode
),
48 mapCatalogDocument_(0)
50 registerOption('c', SP_T("catalog_sysid"));
52 registerOption('D', SP_T("dir"));
55 void EntityApp::processOption(AppChar opt
, const AppChar
*arg
)
59 catalogSysids_
.push_back(arg
);
62 mapCatalogDocument_
= 1;
65 searchDirs_
.push_back(arg
);
68 CmdLineApp::processOption(opt
, arg
);
73 int EntityApp::processArguments(int argc
, AppChar
**argv
)
76 if (!makeSystemId(argc
, argv
, sysid
))
78 return processSysid(sysid
);
81 Boolean
EntityApp::makeSystemId(int nFiles
, AppChar
*const *files
,
84 Vector
<StringC
> filenames(nFiles
== 0 ? 1 : nFiles
);
86 for (i
= 0; i
< nFiles
; i
++)
87 filenames
[i
] = convertInput(tcscmp(files
[i
], SP_T("-")) == 0
91 filenames
[0] = convertInput(SP_T("<OSFD>0"));
92 return entityManager()->mergeSystemIds(filenames
,
100 Ptr
<ExtendEntityManager
> &EntityApp::entityManager()
102 if (!entityManager_
.isNull())
103 return entityManager_
;
104 PosixStorageManager
*sm
105 = new PosixStorageManager("OSFILE",
107 #ifndef SP_WIDE_SYSTEM
112 for (i
= 0; i
< searchDirs_
.size(); i
++)
113 sm
->addSearchDir(convertInput(searchDirs_
[i
]));
115 const AppChar
*e
= tgetenv(SP_T("SGML_SEARCH_PATH"));
117 e
= SGML_SEARCH_PATH_DEFAULT
;
119 StringC
str(convertInput(e
));
123 if (i
== str
.size() || str
[i
] == FILE_SEP
) {
124 sm
->addSearchDir(StringC(str
.data() + start
,
136 entityManager_
= ExtendEntityManager::make(sm
,
138 inputCodingSystemKit(),
139 internalCharsetIsDocCharset_
);
141 ->registerStorageManager(new PosixFdStorageManager("OSFD",
144 entityManager_
->registerStorageManager(new WinInetStorageManager("URL"));
146 entityManager_
->registerStorageManager(new URLStorageManager("URL"));
148 entityManager_
->registerStorageManager(new LiteralStorageManager("LITERAL"));
149 entityManager_
->registerStorageManager(new NotationStorageManager("CLSID"));
150 entityManager_
->registerStorageManager(new NotationStorageManager("MIMETYPE"));
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"));
158 e
= SGML_CATALOG_FILES_DEFAULT
;
160 StringC
str(convertInput(e
));
164 if (i
== str
.size() || str
[i
] == FILE_SEP
) {
165 v
.push_back(StringC(str
.data() + start
,
176 const SP_TCHAR
*useDocCatalogStr
= tgetenv(SP_T("SP_USE_DOCUMENT_CATALOG"));
177 Boolean useDocCatalog
= true;
179 && (stringMatches(useDocCatalogStr
, "NO")
180 || stringMatches(useDocCatalogStr
, "0")))
181 useDocCatalog
= false;
182 entityManager_
->setCatalogManager(SOCatalogManager::make(v
,
183 catalogSysids_
.size(),
187 return entityManager_
;