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: NCFGen.C /main/9 1996/08/21 15:47:02 drk $ */
33 #include "Exceptions.hh"
35 #include "BookCaseDB.h"
38 #include "StyleValidate.h"
42 #include "oliasdb/mmdb.h"
43 #include "oliasdb/asciiIn_filters.h"
44 #include "oliasdb/olias_consts.h"
45 #include "oliasdb/stylesheet_hd.h"
48 /* Hash table interfaces */
49 #include "dti_cc/CC_String.h"
50 #include "dti_cc/cc_hdict.h"
51 #include "BTCollectable.h"
58 static unsigned hash_func(const CC_String &str)
63 //-------------------------------------------------------------------------
65 writeStyleSheets(BookCaseDB& db)
67 DBTable *out = db.DB::table(DATABASE_STDIO,
68 STYLESHEET_CODE, BT_NUM_STYLESHEET_FIELDS,
71 DBTable *in = db.table(BookCaseDB::StyleSheet, DB::READ);
84 while(cursor.next(STRING_CODE, &name,
85 -STRING_CODE, &online, &len_o,
86 -STRING_CODE, &print, &len_p,
88 if( (statusO=validate_stylesheet( online, len_o, ONLINE ))){
89 Token::signalError(Token::User, Token::Continuable, 0, 0,
90 "Online style sheet for `%s' is invalid.", name);
93 if( (statusP=validate_stylesheet( print, len_p, PRINT ))){
94 Token::signalError(Token::User, Token::Continuable, 0, 0,
95 "Print style sheet for `%s' is invalid.", name);
98 if ( statusO || statusP ) {
99 throw(Unexpected("Style sheet validation failed\n"));
102 out->insert(STRING_CODE, name,
103 -STRING_CODE, online, (size_t)len_o,
104 -STRING_CODE, print, (size_t)len_p,
112 //-------------------------------------------------------------------------
114 buildNCF(BookCaseDB& db, const char *base_name, int compressed)
116 DBTable *ncf = db.DB::table(DATABASE_STDIO,
117 OLIAS_NODE_CODE, BT_NUM_OLIAS_NODE_FIELDS,
120 DBTable *nodeMeta = db.table(BookCaseDB::NodeMeta, DB::READ);
121 DBCursor cursor(*nodeMeta);
124 const char *bookLocator;
125 const char *nodeLocator;
126 const char *filename;
134 OLIAS_DB mmdb_handle;
136 mmdb_handle.openInfoLib(getenv("MMDB_PATH"), (char*)base_name);
137 info_base *base_ptr = mmdb->get_info_base(base_name);
139 const int BUFSIZE=30;
141 hashTable<CC_String,BTCollectable> node_dict(hash_func); // Hash table...
145 // 30 will be enough for now.
146 const int COMPRESSED_AGENT_SIZE=30;
148 char comp_agent[COMPRESSED_AGENT_SIZE];
150 // was bzero before, but unable to find bzero on solaris
151 for ( int i = 0; i < COMPRESSED_AGENT_SIZE; i++ ) {
155 ostringstream str_buf( comp_agent );
156 handler *x = (base_ptr->get_obj_dict()).get_handler(
157 form("%s.%s", base_name, "sgml.dict"));
158 x->its_oid().asciiOut(str_buf);
159 memcpy(comp_agent, str_buf.str().c_str(), COMPRESSED_AGENT_SIZE);
162 while(cursor.next(STRING_CODE, &bookLocator,
163 STRING_CODE, &nodeLocator,
164 STRING_CODE, &filename,
165 INTEGER_CODE, &line_num,
166 SKIP_CODE, /* TOC num */
168 STRING_CODE, &stitle,
173 CC_String *key = new CC_String(nodeLocator);
175 // check for duplicate node locator
176 BTCollectable *val = node_dict.findValue( key );
181 cerr << "(ERROR) Duplicate section ID = " << nodeLocator << endl
182 << " found in file = " << filename << endl
183 << " at line = " << line_num << endl
184 << " is in conflict with " << endl
185 << " section ID = " << nodeLocator << endl
186 << " in file = " << val->filename() << endl
187 << " at line = " << val->linenum() << "\n\n";
193 BTCollectable *val = new BTCollectable( filename,
196 node_dict.insertKeyAndValue( key, val );
200 stylesheet_smart_ptr sheet(base_ptr, style);
201 ostringstream strout;
202 sheet.its_oid().asciiOut(strout);
203 outstr = strout.str();
205 ncf->insert(STRING_CODE, nodeLocator,
208 COMPRESSED_STRING_CODE, comp_agent, "",
209 STRING_CODE, bookLocator,
210 OID_CODE, "0.0", /* pointer to Book/CCF/DOC object */
211 OID_CODE, (char *)outstr.c_str(),
218 while(cursor.next(STRING_CODE, &bookLocator,
219 STRING_CODE, &nodeLocator,
220 STRING_CODE, &filename,
221 INTEGER_CODE, &line_num,
222 SKIP_CODE, /* TOC num */
224 STRING_CODE, &stitle,
228 CC_String *key = new CC_String(nodeLocator);
230 // check for duplicate node locator
231 BTCollectable *val = node_dict.findValue( key );
237 cerr << "(ERROR) Duplicate section ID = " << nodeLocator << endl
238 << " found in file = " << filename << endl
239 << " at line = " << line_num << endl
240 << " is in conflict with " << endl
241 << " section ID = " << nodeLocator << endl
242 << " in file = " << val->filename() << endl
243 << " at line = " << val->linenum() << "\n\n";
248 BTCollectable *val = new BTCollectable( filename,
251 node_dict.insertKeyAndValue( key , val );
256 stylesheet_smart_ptr sheet(base_ptr, style);
257 char oid_buf[BUFSIZE];
258 ostringstream strout(oid_buf);
259 sheet.its_oid().asciiOut(strout);
261 memcpy(oid_buf, strout.str().c_str(), BUFSIZE);
263 ncf->insert(STRING_CODE, nodeLocator,
267 STRING_CODE, bookLocator,
268 OID_CODE, "0.0", /* pointer to Book/CCF/DOC object */
277 form("Number of duplicated section ID found = %d", dupID)
282 node_dict.clearAndDestroy();
285 //-------------------------------------------------------------------------
287 usage(const char *progname)
289 fprintf(stderr, "usage: %s [-compressed] [-load-style] <bookcasename> <bookcasedir>\n", progname);
293 //-------------------------------------------------------------------------
294 int main(int argc, char **argv)
298 set_new_handler( FreeStoreException );
301 const char *progname = argv[0];
303 int load_style_only = 0;
306 DBUG_PROCESS(argv[0]);
307 if(getenv("FISH_DBUG")) DBUG_PUSH(getenv("FISH_DBUG"));
313 while(argc > 0 && argv[0][0] == '-'){
314 const char *opt = argv[0];
318 if(strcmp(opt, "-compressed") == 0){
321 else if ( strcmp(opt, "-load-style") == 0 ) {
330 const char *base_name = argv[0];
331 const char *bookcaseDir = argv[1];
334 BookCaseDB db(bookcaseDir);
336 if ( load_style_only ) {
337 writeStyleSheets(db);
340 buildNCF(db, base_name, compressed);
345 mcatch(PosixError&, pe){
346 fprintf(stderr, "%s: error on %s: %s\n",
347 progname, bookcaseDir, pe.msg());
350 mcatch(Unexpected&, pe) {
351 fprintf(stderr, "(ERROR) %s\n\n", pe.msg() );
354 mcatch(mmdbException&, e) {
359 fprintf(stderr, "*** Internal Error ***: unexpected exception\n");