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: BookTasks.cc /main/5 1996/05/29 12:36:58 rcs $
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1996 Hewlett-Packard Company.
27 * (c) Copyright 1996 International Business Machines Corp.
28 * (c) Copyright 1996 Sun Microsystems, Inc.
29 * (c) Copyright 1996 Novell, Inc.
30 * (c) Copyright 1996 FUJITSU LIMITED.
31 * (c) Copyright 1996 Hitachi.
46 #include "BookCaseDB.h"
48 #include "StringList.h"
49 #include "StyleTask.h"
50 #include "api/utility.h"
53 #include "BookTasks.h"
55 #ifdef LICENSE_MANAGEMENT
56 #include "cryptlib/lterms.h"
60 #include "dbug.h" /* ala Fred Fish's dbug package from uunet */
63 const int A_FEATURE = OLAF::Feature;
64 const int A_VEN_CODE = OLAF::VenCode;
65 const int A_VERSION = OLAF::Version;
66 const int A_GROUPING = OLAF::Grouping;
67 const int A_DEMO_TERMS = OLAF::DemoTerms;
68 const int A_DEFAULT_SECTION = OLAF::DefaultSection;
70 /***********************************
74 ***********************************/
76 BookCaseTask::BookCaseTask(const char *infolib)
78 int len = strlen(infolib);
79 library = new char[len + 1];
80 *((char *) memcpy(library, infolib, len) + len) = '\0';
89 if ( !Dispatch::RunTocGenOnly() ) {
90 style = new StyleTaskDB(this);
96 book = new BookTask(this);
100 f_search_storage = NULL;
104 //--------------------------------------------------------------------
106 BookCaseTask::database()
109 f_db = new BookCaseDB(library);
116 //--------------------------------------------------------------------
118 BookCaseTask::table(int tid)
120 return database()->table(tid);
123 //--------------------------------------------------------------------
125 BookCaseTask::bookcasename()
127 if ( !bookCaseName ) {
128 throw(Unexpected("BookCase name not available yet."));
131 return ( bookCaseName->content() );
135 //--------------------------------------------------------------------
137 BookCaseTask::write_full_text_record( const char *str,
139 const char *nodelocator,
140 const char *node_title
143 const char *BookCaseName = bookcasename();
145 if ( !f_search_storage ) {
146 const char *pathname = database()->path();
148 f_search_storage = new FulcrumStore( pathname , BookCaseName);
149 assert ( f_search_storage );
152 const int BookNum = book->sequencenum();
153 const char *BookShortTitle = book->book_short_title();
155 f_search_storage->insert( BookCaseName,
165 //--------------------------------------------------------------------
167 BookCaseTask::write_full_text_record(DataRepository *store,
168 const char *nodelocator,
169 const char *node_title
173 const char *BookCaseName = bookcasename();
175 if ( !f_search_storage ) {
176 const char *pathname = database()->path();
177 f_search_storage = new AusTextStore( pathname, BookCaseName );
178 assert( f_search_storage );
181 const char *BookShortTitle = book->book_short_title();
182 f_search_storage->insert( BookShortTitle,
191 //--------------------------------------------------------------------
192 void BookCaseTask::markup(const Token &t)
194 ComplexTask::markup(t);
196 if (t.type() == START){
198 if(t.olaf() == OLAF::Bookcase){
200 throw(Unexpected("second (illegal) BookCase element found"));
211 throw(Unexpected("second (illegal) bookcase name element found"));
214 bookCaseName = new OL_Data(t, OLAF::OL_data);
215 addSubTask(bookCaseName);
220 throw(Unexpected("second (illegal) bookcase description element found"));
223 bookCaseDesc = new OL_Data(t, OLAF::OL_data);
224 addSubTask(bookCaseDesc);
229 if(!f_style && t.LookupAttr(OLAF::OL_style)){
230 OL_Data *tmp_style = new OL_Data(t, OLAF::OL_style);
231 if ( tmp_style->DataWillBeAvailable() ) {
242 else if(t.type() == END){
244 if(t.level() == f_base){
249 name = bookCaseName->content();
251 throw(Unexpected("No bookcase name element in Bookcase element."));
255 desc = bookCaseDesc->content();
260 printf("BookCase name: `%s' desc: `%s'\n", name, desc);
263 /* @# warn if no bookcase ever found? */
269 BookCaseTask::styleName()
273 if ( Dispatch::RunTocGenOnly() ) {
278 throw(Unexpected ("No style architectural form defined for bookcase."));
281 ret = f_style->content();
284 DBUG_PRINT("Style", ("bookcase style is: %s", ret));
287 if(!style->exist(ret)){
289 DBUG_PRINT("Error", ("style `%s' not found", ret));
291 Token::signalError(Token::User, Token::Fatal, NULL, 0,
292 "An undeclared style sheet name `%s' was found in the bookcase specification.\n", ret);
305 BookTask::BookTask(BookCaseTask *bc)
321 tabNames = new StringList();
322 tabLocators = new StringList();
323 tabLines = new StringList();
324 tabFiles = new StringList();
326 f_node = new NodeTask(this, NULL);
336 BookTask::~BookTask()
343 KILLSUBTASK(shortTitle);
344 KILLSUBTASK(tabName);
345 KILLSUBTASK(tabLocator);
349 //------------------------------------------------------------------
351 BookTask::encrypt( const Token &t )
354 * Grab all the strings that are required by the encryption API
359 #ifdef LICENSE_MANAGEMENT
364 for ( const AttributeRec *arec = t.GetFirstAttr();
366 arec = t.GetNextAttr( arec ) ) {
368 a_val = ( char * )arec->getAttrValueString();
371 DBUG_PRINT("BookTasks", ("access attribute value %s", a_val) );
374 switch ( arec->getAttrName() ) {
378 if ( lt.add_feature( a_val ) != 0 ) {
379 throw(Unexpected("invalid access feature syntax"));
384 if ( lt.add_ven_code( a_val ) != 0 ) {
385 throw(Unexpected("invalid access ven_code syntax") );
390 if ( lt.add_version( a_val ) != 0 ) {
391 throw(Unexpected("invalid access version syntax"));
396 if ( lt.add_grouping( a_val ) != 0 ) {
397 throw(Unexpected("invalid access grouping syntax"));
403 if ( lt.add_demo_terms( a_val ) != 0 ) {
404 throw(Unexpected("invalid access demo_terms syntax"));
408 case A_DEFAULT_SECTION :
410 if ( lt.add_noaccess_locator( a_val ) != 0 ) {
411 throw(Unexpected("invalid default section ID syntax"));
418 if ( lt.pack( buf, 256 ) ) {
419 throw(Unexpected("Unable to pack the string for encryption"));
423 if ( e_terms( <, buf, len ) ) {
424 throw(Unexpected("Unable to encrypt string for access control"));
428 (void) memset(buf, '\0', len);
431 e_string = (char *)malloc(len);
432 (void)memcpy(e_string, buf, len); // Cannot use strdup - embedded NULs
437 //----------------------------------------------------------------------
438 void BookTask::markup(const Token &t)
440 ComplexTask::markup(t);
442 if(t.type() == START){
444 if(t.olaf() == OLAF::Book){
446 throw(Unexpected("illegal nested BOOK architectural form"));
456 throw(Unexpected("BkSTitle already found"));
459 shortTitle = new OL_Data(t, OLAF::OL_data);
460 addSubTask(shortTitle);
465 throw(Unexpected("BkTitle already found"));
468 title = new OL_Data(t, OLAF::OL_data);
474 tabNames->append(tabName->content());
475 tabLocators->append(tabLocator->content());
476 tabLines->append( form("%d", tabLocator->line_no()) );
477 tabFiles->append( tabLocator->filename() );
479 KILLSUBTASK(tabName);
480 KILLSUBTASK(tabLocator);
483 tabName = new OL_Data(t, OLAF::OL_data);
484 tabLocator = new OL_Data(t, OLAF::OL_idref, REMOVE_SPACES);
486 addSubTask(tabLocator);
489 case OLAF::BookAccess:
494 if ( t.LookupAttr( OLAF::OL_ToC ) ) {
496 throw(Unexpected("An illegal TOC was found.\n"));
499 f_toc = new TOCTask(t, this);
503 if(f_base >= 0 && !f_style && t.LookupAttr(OLAF::OL_style)){
504 OL_Data *tmp_style = new OL_Data(t, OLAF::OL_style);
505 if ( tmp_style->DataWillBeAvailable() ) {
516 else if(t.type() == END){
517 if(t.level() == f_base){ /* found end of book... write out CCF data */
518 if ( !Dispatch::RunTocGenOnly() ) {
527 //----------------------------------------------------------------------
528 void BookTask::write_record(void)
532 /* finish any pending tab */
534 tabNames->append(tabName->content());
535 tabLocators->append(tabLocator->content());
536 tabLines->append( form("%d", tabLocator->line_no()) );
537 tabFiles->append(tabLocator->filename());
540 for(unsigned int i = 0; i < tabNames->qty(); i++){
541 const char *name = tabNames->item(i);
542 const char *loc = tabLocators->item(i);
543 const char *line = tabLines->item(i);
544 const char *file = tabFiles->item(i);
546 int plen = strlen(name) + 1 + strlen(loc) + 1
547 + strlen(line) + 1 + strlen(file) + 1;
548 char *p = new char [plen];
550 snprintf(p, plen, "%s\t%s\t%s\t%s", name, loc, line, file);
556 const char *bk_title;
559 bk_title = title->content();
561 throw(Unexpected("Required Title form missing from Book"));
564 const char *bk_stitle = bk_title;
567 bk_stitle = shortTitle->content();
570 DBTable *tbl = bookcase()->table(BookCaseDB::BookMeta);
572 tbl->insert(STRING_CODE, locator(),
573 STRING_CODE, bk_stitle,
574 STRING_CODE, bk_title,
575 INTEGER_CODE, f_seq_no,
576 SHORT_LIST_CODE, tablines.qty(), STRING_CODE, tablines.array(),
577 -STRING_CODE, e_string , (size_t)e_len,
581 DBUG_PRINT("Book", ("Book... title: `%s' short title: `%s'\n",
588 void BookTask::reset()
590 KILLSUBTASK(shortTitle);
593 KILLSUBTASK(f_style);
595 delete tabNames; tabNames = new StringList();
596 delete tabLocators; tabLocators = new StringList();
598 tabName = tabLocator = NULL;
600 delete tabLines; tabLines = new StringList();
601 delete tabFiles; tabFiles = new StringList();
603 delete [] tocLocator; tocLocator = NULL;
612 const char *BookTask::locator()
615 if ( Dispatch::RunTocGenOnly() ) {
620 /* this is the first time anybody asked for the book's locator...
621 * it must be the TOC node asking for the book locator, which
622 * is the TOC node locator!
624 const char *l = f_node->locator();
626 tocLocator = new char[len + 1];
627 *((char *) memcpy(tocLocator, l, len) + len) = '\0';
635 BookTask::styleName()
637 if ( Dispatch::RunTocGenOnly() ) {
643 ret = f_style->content();
645 if(f_bookcase->styleTask()->exist(ret)){
647 DBUG_PRINT("Style", ("book style is: %s", ret));
650 Token::signalError(Token::User, Token::Continuable, NULL, 0,
651 "no such style `%s'\n", ret);
652 ret = f_bookcase->styleName();
655 ret = f_bookcase->styleName();
661 //--------------------------------------------------------------
663 BookTask::book_title()
666 throw(Unexpected("Book title is not available yet"));
669 return( title->content() );
672 //--------------------------------------------------------------
674 BookTask::book_short_title()
677 return( book_title() );
680 return( shortTitle->content() );