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: OL-Data.C /main/4 1996/08/21 15:47:10 drk $
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.
34 /* exported interfaces */
37 /* imported interfaces */
42 #include <misc/unique_id.h>
43 #include "Expression.h"
44 #include "AttributeRec.h"
53 #include "AttributeData.h"
56 #include "GenericId.h"
58 #include "ConcatTask.h"
63 #define DBG(level) if ( dbgLevel >= level)
65 #define DBG(level) if (0)
68 static int dbgLevel=-1;
70 //---------------------------------------------------------------------------
72 FilteredSpaces( const char *str )
76 char *tail = (char *)str + strlen( str ) - 1;
77 char *ptr = (char *)str;
80 if ( *ptr != ' ' && *ptr != '\n' && *ptr != '\t' ) {
90 if ( *tail != ' ' && *tail != '\n' && *tail != '\t' ) {
99 //-------------------------------------------------------------------------
100 OL_Data::OL_Data( const Token &t,
102 ActionType mode ):BaseData(t,mode)
107 dbgStr = getenv("OL_DEBUG");
108 dbgLevel = ( dbgStr ? atoi ( dbgStr ) : 0 );
110 /* first generate grep all the mode info */
111 istat = mode & IGNORE_ON;
112 removeSpaces = mode & REMOVE_SPACES;
114 f_name = strdup( t.file() );
117 if ( istat && !Dispatch::OutsideIgnoreScope() ) {
122 const AttributeRec *attRec;
123 if ( !(attRec = t.LookupAttr( DataType )) ) {
125 if ( mode & GENERATE_ID ) {
126 const char *str = unique_id();
128 ValueBuffer.writeStr( str );
135 * The default rule kicks in, i.e use #CONTENT
138 addSubTask( new Content( t, mode) );
144 tokContent.Parse( ( char *)attRec->getAttrValueString() );
147 const OL_Expression *eptr = tokContent.exprlist;
148 assert(eptr != NULL);
150 switch ( eptr->type() ) {
154 BaseData *sub_data = new AttributeData(t, eptr->name(), mode );
156 if ( data_avail= sub_data->DataWillBeAvailable() ) {
157 ValueBuffer.write( sub_data->content(),
158 sub_data->content_size() );
168 addSubTask( new Content(t, mode) );
172 addSubTask( new Concat( t,
173 (ExprList *)eptr->data_list(),
178 addSubTask( new FirstOf( t,
179 (ExprList *)eptr->data_list(),
184 addSubTask( new GenericId( t,
192 ValueBuffer.writeStr( ( const char *)eptr->data_list() );
201 //-------------------------------------------------------------------------
203 OL_Data::markup( const Token &t )
206 DBG(80) cerr << "(DEBUG) OL_Data::markup() " << endl;
207 DBG(80) cerr << " t.giName() = " << t.giName() << endl;
209 if ( istat && !Dispatch::OutsideIgnoreScope() ) {
215 ComplexTask::markup( t );
216 if ( t.type() == END ) {
218 if ( f_base == t.level() ) {
222 for ( int i=0; i < ComplexTask::used; i++ ) {
223 BaseData *task = ( BaseData *)ComplexTask::subtask(i);
224 ValueBuffer.write( task->content(), task->content_size() );
228 if ( removeSpaces && ValueBuffer.GetSize() > 0 ) {
229 const char *filtered_string = FilteredSpaces( ValueBuffer.GetBuffer() );
230 /* rewrite ValueBuffer with the filtered string */
232 ValueBuffer.writeStr( filtered_string );
236 DBG(10) printf("Data for <%s> = %s\n", t.giName(),
237 ValueBuffer.GetBuffer() );
247 //-------------------------------------------------------------------------
249 OL_Data::data( const char *str, size_t t )
252 if ( istat && !Dispatch::OutsideIgnoreScope() ) {
257 ComplexTask::data( str, t );
261 //-------------------------------------------------------------------------
266 istat = removeSpaces = 0;