Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / LcfTask.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: LcfTask.C /main/3 1996/10/26 18:17:58 cde-hal $
24  *
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.
32  */
33
34 /* exported interfaces */
35 #include "LcfTask.h"
36
37 /* imported interfaces */
38 #include <assert.h>
39 #include "Token.h"
40 #include "NodeTask.h"
41 #include "DataBase.h"
42 #include "OL-Data.h"
43 #include "OLAF.h"
44 #include "BookTasks.h"
45 #include "BookCaseDB.h"
46
47 //--------------------------------------------------------------------
48 LcfTask::LcfTask( NodeTask *f_parent, const Token &t )
49 {
50   assert( f_parent != NULL );
51   f_node = f_parent;
52   f_base = t.level();
53 }
54
55 //--------------------------------------------------------------------
56 void
57 LcfTask::markup( const Token &t )
58 {
59   
60   ComplexTask::markup(t);
61   
62   if ( t.type() == START ) {
63     if ( t.LookupAttr( OLAF::OL_id ) ) {
64       OL_Data *LocData = new OL_Data ( t, OLAF::OL_id, REMOVE_SPACES );
65       
66       /*
67        * Add subtask only if I know Data will be available
68        */
69       
70       if ( LocData->DataWillBeAvailable() ) {
71         addSubTask( LocData );
72
73         OL_Data *RefData = new OL_Data(t, OLAF::OL_XRefLabel, IGNORE_ON);
74         addSubTask( RefData );
75       }
76       else { delete LocData; }
77     }
78   }
79   else if ( t.type() == END ) {
80     /* only write out all the locator if I am at the end f_node */
81     if ( t.level() == f_base ) {
82       write_record();
83       reset();
84     }
85   }
86 }
87
88 //--------------------------------------------------------------------
89 void
90 LcfTask::reset()
91 {
92   ComplexTask::removeAllSubTasks();
93 }
94   
95 //--------------------------------------------------------------------
96 void
97 LcfTask::write_record()
98 {
99   const char *NodeLocator = f_node->locator();
100 #if 0
101   for ( int i = 0; i < ComplexTask::used; i++ ) {
102     OL_Data *task = (OL_Data * )subtask(i);
103     if ( !task->ContentIsEmpty() ) {
104       DBTable *tbl = f_node->book()->bookcase()->table(BookCaseDB::Locator);
105       tbl->insert( STRING_CODE, task->content(),
106                    STRING_CODE, NodeLocator,
107                    STRING_CODE, task->filename(),
108                    INTEGER_CODE, task->line_no(),
109                    NULL);
110     }
111   }
112 #else
113   for ( int i = 0; i < ComplexTask::used; i+=2 ) {
114     OL_Data* task    = (OL_Data * )subtask(i);
115     OL_Data* reftask = (OL_Data * )subtask(i+1);
116
117     if ( !task->ContentIsEmpty() ) {
118       DBTable *tbl = f_node->book()->bookcase()->table(BookCaseDB::Locator);
119
120       const char* reflabel = "";
121       if ( !reftask->ContentIsEmpty() ) {
122         const char* content = reftask->content();
123         if (strlen(content) < 256)
124           reflabel = content;
125       }
126
127       tbl->insert( STRING_CODE, task->content(),
128                    STRING_CODE, NodeLocator,
129                    STRING_CODE, reflabel,
130                    STRING_CODE, task->filename(),
131                    INTEGER_CODE, task->line_no(),
132                    NULL);
133     }
134   }
135 #endif
136 }