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 librararies 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 $ */
27 #if !defined(__uxp__) && !defined(USL)
30 #include <strstream.h>
32 #include "Exceptions.hh"
34 #include "BookCaseDB.h"
37 #include "StyleValidate.h"
41 #include "oliasdb/mmdb.h"
42 #include "oliasdb/asciiIn_filters.h"
43 #include "oliasdb/olias_consts.h"
44 #include "oliasdb/stylesheet_hd.h"
47 /* Hash table interfaces */
48 #include "dti_cc/CC_String.h"
49 #include "dti_cc/cc_hdict.h"
50 #include "BTCollectable.h"
57 static unsigned hash_func(const CC_String &str)
62 //-------------------------------------------------------------------------
64 writeStyleSheets(BookCaseDB& db)
66 DBTable *out = db.DB::table(DATABASE_STDIO,
67 STYLESHEET_CODE, BT_NUM_STYLESHEET_FIELDS,
70 DBTable *in = db.table(BookCaseDB::StyleSheet, DB::READ);
83 while(cursor.next(STRING_CODE, &name,
84 -STRING_CODE, &online, &len_o,
85 -STRING_CODE, &print, &len_p,
87 if( statusO=validate_stylesheet( online, len_o, ONLINE )){
88 Token::signalError(Token::User, Token::Continuable, 0, 0,
89 "Online style sheet for `%s' is invalid.", name);
92 if( statusP=validate_stylesheet( print, len_p, PRINT )){
93 Token::signalError(Token::User, Token::Continuable, 0, 0,
94 "Print style sheet for `%s' is invalid.", name);
97 if ( statusO || statusP ) {
98 throw(Unexpected("Style sheet validation failed\n"));
101 out->insert(STRING_CODE, name,
102 -STRING_CODE, online, len_o,
103 -STRING_CODE, print, len_p,
111 //-------------------------------------------------------------------------
113 buildNCF(BookCaseDB& db, const char *base_name, int compressed)
115 DBTable *ncf = db.DB::table(DATABASE_STDIO,
116 OLIAS_NODE_CODE, BT_NUM_OLIAS_NODE_FIELDS,
119 DBTable *nodeMeta = db.table(BookCaseDB::NodeMeta, DB::READ);
120 DBCursor cursor(*nodeMeta);
123 const char *bookLocator;
124 const char *nodeLocator;
125 const char *filename;
132 OLIAS_DB mmdb_handle;
134 mmdb_handle.openInfoLib(getenv("MMDB_PATH"), (char*)base_name);
135 info_base *base_ptr = mmdb->get_info_base(base_name);
137 const int BUFSIZE=30;
139 hashTable<CC_String,BTCollectable> node_dict(hash_func); // Hash table...
143 // 30 will be enough for now.
144 const int COMPRESSED_AGENT_SIZE=30;
146 char comp_agent[COMPRESSED_AGENT_SIZE];
148 // was bzero before, but unable to find bzero on solaris
149 for ( int i = 0; i < COMPRESSED_AGENT_SIZE; i++ ) {
153 ostrstream str_buf( comp_agent,COMPRESSED_AGENT_SIZE);
154 handler *x = (base_ptr->get_obj_dict()).get_handler(
155 form("%s.%s", base_name, "sgml.dict"));
156 x->its_oid().asciiOut(str_buf);
159 while(cursor.next(STRING_CODE, &bookLocator,
160 STRING_CODE, &nodeLocator,
161 STRING_CODE, &filename,
162 INTEGER_CODE, &line_num,
163 SKIP_CODE, /* TOC num */
165 STRING_CODE, &stitle,
170 CC_String *key = new CC_String(nodeLocator);
172 // check for duplicate node locator
173 BTCollectable *val = node_dict.findValue( key );
178 cerr << "(ERROR) Duplicate section ID = " << nodeLocator << endl
179 << " found in file = " << filename << endl
180 << " at line = " << line_num << endl
181 << " is in conflict with " << endl
182 << " section ID = " << nodeLocator << endl
183 << " in file = " << val->filename() << endl
184 << " at line = " << val->linenum() << "\n\n";
190 BTCollectable *val = new BTCollectable( filename,
193 node_dict.insertKeyAndValue( key, val );
197 stylesheet_smart_ptr sheet(base_ptr, style);
198 char oid_buf[BUFSIZE];
199 ostrstream strout(oid_buf,BUFSIZE,ios::out);
200 sheet.its_oid().asciiOut(strout);
201 oid_buf[strout.pcount()] = NULL;
203 ncf->insert(STRING_CODE, nodeLocator,
206 COMPRESSED_STRING_CODE, comp_agent, "",
207 STRING_CODE, bookLocator,
208 OID_CODE, "0.0", /* pointer to Book/CCF/DOC object */
216 while(cursor.next(STRING_CODE, &bookLocator,
217 STRING_CODE, &nodeLocator,
218 STRING_CODE, &filename,
219 INTEGER_CODE, &line_num,
220 SKIP_CODE, /* TOC num */
222 STRING_CODE, &stitle,
226 CC_String *key = new CC_String(nodeLocator);
228 // check for duplicate node locator
229 BTCollectable *val = node_dict.findValue( key );
235 cerr << "(ERROR) Duplicate section ID = " << nodeLocator << endl
236 << " found in file = " << filename << endl
237 << " at line = " << line_num << endl
238 << " is in conflict with " << endl
239 << " section ID = " << nodeLocator << endl
240 << " in file = " << val->filename() << endl
241 << " at line = " << val->linenum() << "\n\n";
246 BTCollectable *val = new BTCollectable( filename,
249 node_dict.insertKeyAndValue( key , val );
254 stylesheet_smart_ptr sheet(base_ptr, style);
255 char oid_buf[BUFSIZE];
256 ostrstream strout(oid_buf,BUFSIZE,ios::out);
257 sheet.its_oid().asciiOut(strout);
258 oid_buf[strout.pcount()] = NULL;
260 ncf->insert(STRING_CODE, nodeLocator,
264 STRING_CODE, bookLocator,
265 OID_CODE, "0.0", /* pointer to Book/CCF/DOC object */
274 form("Number of duplicated section ID found = %d", dupID)
279 node_dict.clearAndDestroy();
282 //-------------------------------------------------------------------------
284 usage(const char *progname)
286 fprintf(stderr, "usage: %s [-compressed] [-load-style] <bookcasename> <bookcasedir>\n", progname);
290 //-------------------------------------------------------------------------
291 main(int argc, char **argv)
295 set_new_handler( FreeStoreException );
298 const char *progname = argv[0];
300 int load_style_only = 0;
303 DBUG_PROCESS(argv[0]);
304 if(getenv("FISH_DBUG")) DBUG_PUSH(getenv("FISH_DBUG"));
310 while(argc > 0 && argv[0][0] == '-'){
311 const char *opt = argv[0];
315 if(strcmp(opt, "-compressed") == 0){
318 else if ( strcmp(opt, "-load-style") == 0 ) {
327 const char *base_name = argv[0];
328 const char *bookcaseDir = argv[1];
331 BookCaseDB db(bookcaseDir);
333 if ( load_style_only ) {
334 writeStyleSheets(db);
337 buildNCF(db, base_name, compressed);
342 catch(PosixError&, pe){
343 fprintf(stderr, "%s: error on %s: %s\n",
344 progname, bookcaseDir, pe.msg());
347 catch(Unexpected&, pe) {
348 fprintf(stderr, "(ERROR) %s\n\n", pe.msg() );
351 catch(mmdbException&, e) {
356 fprintf(stderr, "*** Internal Error ***: unexpected exception\n");