Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
36
cde/programs/dtinfo/DtMmdb/StyleSheet/Attribute.C
Normal file
36
cde/programs/dtinfo/DtMmdb/StyleSheet/Attribute.C
Normal file
@@ -0,0 +1,36 @@
|
||||
// $XConsortium: Attribute.cc /main/4 1996/06/11 17:05:20 cde-hal $
|
||||
#include "Attribute.h"
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Attribute
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Attribute::Attribute(const Symbol &name, char *value)
|
||||
: f_name(name),
|
||||
f_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Attribute::~Attribute()
|
||||
{
|
||||
delete f_value ;
|
||||
}
|
||||
|
||||
Attribute::operator==(const Attribute &attr) const
|
||||
{
|
||||
/*
|
||||
cerr << "Attribute::operator==\n";
|
||||
cerr << f_name << "\n";
|
||||
cerr << attr.f_name << "\n";
|
||||
cerr << "<" << f_name.name() << ">\n";
|
||||
cerr << "<" << attr.f_name.name() << ">\n";
|
||||
cerr << attr.name().operator==(f_name) << "\n";
|
||||
*/
|
||||
return f_name == attr.name();
|
||||
}
|
||||
|
||||
ostream &
|
||||
Attribute::print(ostream &o) const
|
||||
{
|
||||
return o << f_name << '=' << f_value ;
|
||||
}
|
||||
38
cde/programs/dtinfo/DtMmdb/StyleSheet/Attribute.h
Normal file
38
cde/programs/dtinfo/DtMmdb/StyleSheet/Attribute.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* $XConsortium: Attribute.h /main/3 1996/06/11 17:05:27 cde-hal $ */
|
||||
#ifndef _Attribute_h
|
||||
#define _Attribute_h
|
||||
|
||||
#include "SymTab.h"
|
||||
|
||||
/* **************************************************************
|
||||
class Attribute
|
||||
|
||||
a name/value pairing
|
||||
************************************************************** */
|
||||
|
||||
class Attribute
|
||||
{
|
||||
public:
|
||||
Attribute(const Symbol &name, char *value = 0);
|
||||
~Attribute();
|
||||
|
||||
const Symbol &name() const { return f_name; }
|
||||
operator==(const Attribute &) const ;
|
||||
|
||||
const char *value() const { return f_value ; }
|
||||
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
private:
|
||||
Symbol f_name;
|
||||
char *f_value ;
|
||||
};
|
||||
|
||||
inline
|
||||
ostream &operator<<(ostream &o, const Attribute &a)
|
||||
{
|
||||
return a.print(o);
|
||||
}
|
||||
|
||||
#endif /* _Attribute_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
42
cde/programs/dtinfo/DtMmdb/StyleSheet/AttributeList.C
Normal file
42
cde/programs/dtinfo/DtMmdb/StyleSheet/AttributeList.C
Normal file
@@ -0,0 +1,42 @@
|
||||
// $XConsortium: AttributeList.cc /main/4 1996/06/11 17:05:32 cde-hal $
|
||||
#include "AttributeList.h"
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// AttributeList
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
AttributeList::AttributeList()
|
||||
: CC_TPtrSlist<Attribute> ()
|
||||
{
|
||||
}
|
||||
|
||||
AttributeList::~AttributeList()
|
||||
{
|
||||
clearAndDestroy();
|
||||
}
|
||||
|
||||
const Attribute*
|
||||
AttributeList::lookup(const Symbol &name) const
|
||||
{
|
||||
Attribute attr(name);
|
||||
return find(&attr);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AttributeList::add(Attribute *attr)
|
||||
{
|
||||
append(attr);
|
||||
}
|
||||
|
||||
ostream &
|
||||
AttributeList::print(ostream &o) const
|
||||
{
|
||||
CC_TPtrSlistIterator<Attribute> next(*(CC_TPtrSlist<Attribute>*)this);
|
||||
|
||||
while (++next)
|
||||
o << ' ' << *next.key() ;
|
||||
|
||||
return o;
|
||||
}
|
||||
36
cde/programs/dtinfo/DtMmdb/StyleSheet/AttributeList.h
Normal file
36
cde/programs/dtinfo/DtMmdb/StyleSheet/AttributeList.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* $XConsortium: AttributeList.h /main/3 1996/06/11 17:05:38 cde-hal $ */
|
||||
#ifndef _AttributeList_h
|
||||
#define _AttributeList_h
|
||||
|
||||
#include "Element.h"
|
||||
#include "Attribute.h"
|
||||
|
||||
/* **************************************************************
|
||||
class AttributeList
|
||||
|
||||
A linked list of Attributes
|
||||
************************************************************** */
|
||||
|
||||
|
||||
class AttributeList : private CC_TPtrSlist<Attribute>
|
||||
{
|
||||
public:
|
||||
AttributeList();
|
||||
~AttributeList();
|
||||
|
||||
void add(Attribute *);
|
||||
|
||||
const Attribute *lookup(const Symbol &name) const;
|
||||
|
||||
ostream &print(ostream &) const ;
|
||||
|
||||
};
|
||||
|
||||
inline
|
||||
ostream &operator<<(ostream &o, const AttributeList &attrlist)
|
||||
{
|
||||
return attrlist.print(o);
|
||||
}
|
||||
|
||||
#endif /* _AttributeList_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
174
cde/programs/dtinfo/DtMmdb/StyleSheet/BitVector.C
Normal file
174
cde/programs/dtinfo/DtMmdb/StyleSheet/BitVector.C
Normal file
@@ -0,0 +1,174 @@
|
||||
// $TOG: BitVector.C /main/4 1998/04/17 11:47:51 mgreess $
|
||||
|
||||
|
||||
#include "BitVector.h"
|
||||
#include "Debug.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
|
||||
#define wordWithMSBSet (0x1 << (WORD_SIZE-1))
|
||||
#define BIT_TEST(x, y) ( ((x) & (y)) == (y) )
|
||||
#define RESET_BIT(x, y) x &= (~(y))
|
||||
#define SET_BIT(x, y) x |= (y)
|
||||
|
||||
unsigned int posRecord::operator ==(const posRecord&)
|
||||
{
|
||||
MESSAGE(cerr, "posRecord::operator ==() should not be called");
|
||||
throw(CASTBEEXCEPT badEvaluationException());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BitVector::BitVector(int bits, unsigned int initValue) :
|
||||
f_bits(bits), f_words(bits/WORD_SIZE+1), f_positionArray(0)
|
||||
{
|
||||
f_array = new unsigned int[f_words];
|
||||
setAllBitsTo(initValue);
|
||||
}
|
||||
|
||||
void BitVector::setAllBitsTo(unsigned int initValue)
|
||||
{
|
||||
unsigned int fill = ( initValue == 0 ) ? 0x0 : ~0x0;
|
||||
|
||||
for ( int i=0; i<f_words; i++ )
|
||||
f_array[i]=fill;
|
||||
}
|
||||
|
||||
BitVector::~BitVector()
|
||||
{
|
||||
delete f_array;
|
||||
delete f_positionArray;
|
||||
}
|
||||
|
||||
void BitVector::setTo(BitVector& v)
|
||||
{
|
||||
if ( f_words != v.f_words ) {
|
||||
delete f_array;
|
||||
f_array = new unsigned int[v.f_words];
|
||||
}
|
||||
f_bits = v.f_bits;
|
||||
f_words = v.f_words;
|
||||
|
||||
for ( int i=0; i<f_words; i++ )
|
||||
f_array[i]=v.f_array[i];
|
||||
}
|
||||
|
||||
void BitVector::setBitTo(int i, unsigned int x)
|
||||
{
|
||||
int wordIndex = i / WORD_SIZE;
|
||||
int bitIndex = i % WORD_SIZE;
|
||||
|
||||
if ( x == 1 ) {
|
||||
if ( wordIndex < f_words - 1 )
|
||||
SET_BIT(f_array[wordIndex], (0x1 << bitIndex));
|
||||
else
|
||||
SET_BIT(f_array[wordIndex],
|
||||
(0x1 << (WORD_SIZE - f_bits % WORD_SIZE + bitIndex))
|
||||
);
|
||||
} else {
|
||||
if ( wordIndex < f_words - 1 )
|
||||
RESET_BIT(f_array[wordIndex], (0x1 << bitIndex));
|
||||
else
|
||||
RESET_BIT(f_array[wordIndex],
|
||||
(0x1 << (WORD_SIZE - f_bits % WORD_SIZE + bitIndex))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void BitVector::recordPositions(unsigned int PTPos, unsigned int BITPos)
|
||||
{
|
||||
if ( f_positionArray == 0 )
|
||||
f_positionArray = new positionArrayT;
|
||||
|
||||
f_positionArray -> append(posRecord(PTPos, BITPos));
|
||||
}
|
||||
|
||||
unsigned int BitVector::getBit(int i)
|
||||
{
|
||||
int wordIndex = i / WORD_SIZE;
|
||||
int bitIndex = i % WORD_SIZE;
|
||||
|
||||
if ( wordIndex < f_words - 1 )
|
||||
return BIT_TEST(f_array[wordIndex], (0x1 << bitIndex)) ? 1 : 0;
|
||||
else
|
||||
return BIT_TEST(f_array[wordIndex],
|
||||
(0x1 << (WORD_SIZE - f_bits % WORD_SIZE + bitIndex))
|
||||
) ? 1 : 0;
|
||||
}
|
||||
|
||||
BitVector& BitVector::operator &=(BitVector& b)
|
||||
{
|
||||
for ( int i=0; i<f_words; i++ )
|
||||
f_array[i] &= b.f_array[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector& BitVector::operator ^=(BitVector& b)
|
||||
{
|
||||
for ( int i=0; i<f_words; i++ )
|
||||
f_array[i] ^= b.f_array[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector& BitVector::operator |=(BitVector& b)
|
||||
{
|
||||
for ( int i=0; i<f_words; i++ )
|
||||
f_array[i] |= b.f_array[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector& BitVector::shiftRightOneBit()
|
||||
{
|
||||
unsigned int msb = 0;
|
||||
unsigned int lsb = 0;
|
||||
|
||||
for ( int i=0; i<f_words; i++ ) {
|
||||
lsb = ( BIT_TEST(f_array[i], 0x1) ) ? 0x1 : 0x0;
|
||||
f_array[i] = f_array[i] >> 1;
|
||||
f_array[i] |= msb;
|
||||
msb = lsb;
|
||||
}
|
||||
|
||||
SET_BIT(f_array[0], wordWithMSBSet);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector& BitVector::shiftLeftOneBit()
|
||||
{
|
||||
unsigned int msb = 0;
|
||||
unsigned int lsb = 0;
|
||||
|
||||
|
||||
for ( int i=f_words-1; i>=0; i++ ) {
|
||||
msb = ( BIT_TEST(f_array[i], wordWithMSBSet) ) ? wordWithMSBSet : 0x0;
|
||||
f_array[i] = f_array[i] << 1;
|
||||
f_array[i] |= lsb;
|
||||
lsb = msb;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& out, BitVector& bv)
|
||||
{
|
||||
for ( int i=bv.f_bits-1; i>=0; i-- ) {
|
||||
out << bv.getBit(i) ;
|
||||
}
|
||||
out << "\n";
|
||||
|
||||
posRecord x;
|
||||
if ( bv.f_positionArray ) {
|
||||
positionArrayIteratorT l_positionNext(*bv.f_positionArray);
|
||||
while (++l_positionNext) {
|
||||
x = l_positionNext.key();
|
||||
out << x.pathTermPos << "." << x.bitPos << " ";
|
||||
}
|
||||
}
|
||||
|
||||
out << "\n";
|
||||
|
||||
return out;
|
||||
}
|
||||
72
cde/programs/dtinfo/DtMmdb/StyleSheet/BitVector.h
Normal file
72
cde/programs/dtinfo/DtMmdb/StyleSheet/BitVector.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* $XConsortium: BitVector.h /main/4 1996/08/21 15:49:59 drk $ */
|
||||
|
||||
#ifndef _BitVector_h
|
||||
#define _BitVector_h 1
|
||||
|
||||
#include <stream.h>
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
#else
|
||||
//#include <StyleSheet/cde_next.h>
|
||||
#include "dti_cc/CC_Slist.h"
|
||||
#endif
|
||||
|
||||
#define WORD_SIZE 32
|
||||
|
||||
class posRecord
|
||||
{
|
||||
public:
|
||||
posRecord(unsigned int x = 0, unsigned int y = 0) :
|
||||
pathTermPos(x), bitPos(y) {};
|
||||
~posRecord() {};
|
||||
|
||||
unsigned int operator ==(const posRecord&);
|
||||
|
||||
public:
|
||||
unsigned int pathTermPos;
|
||||
unsigned int bitPos;
|
||||
};
|
||||
|
||||
typedef CC_TValSlist<posRecord> positionArrayT;
|
||||
typedef CC_TValSlistIterator<posRecord> positionArrayIteratorT;
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// A storage/manipulation efficient bit vector class
|
||||
///////////////////////////////////////////////////////
|
||||
class BitVector
|
||||
{
|
||||
positionArrayT *f_positionArray;
|
||||
unsigned int *f_array;
|
||||
unsigned int f_bits;
|
||||
unsigned int f_words;
|
||||
|
||||
public:
|
||||
BitVector(int bits, unsigned int initValue);
|
||||
~BitVector();
|
||||
|
||||
//
|
||||
// bits range: 0 .. bits-1
|
||||
// the 0th bit is LSB, the (bits-1)th bit is MSB
|
||||
//
|
||||
void setAllBitsTo(unsigned int);
|
||||
void setTo(BitVector&);
|
||||
|
||||
void recordPositions(unsigned int pathTermPos, unsigned int BitPos);
|
||||
positionArrayT* positionArray() { return f_positionArray; };
|
||||
|
||||
void setBitTo(int i, unsigned int);
|
||||
unsigned int getBit(int i);
|
||||
|
||||
BitVector& operator &=(BitVector&);
|
||||
BitVector& operator ^=(BitVector&);
|
||||
BitVector& operator |=(BitVector&);
|
||||
|
||||
// Note: the MSB is set to 1 after each shiftRightOneBit() call.
|
||||
BitVector& shiftRightOneBit();
|
||||
BitVector& shiftLeftOneBit();
|
||||
|
||||
friend ostream& operator<<(ostream&, BitVector&);
|
||||
};
|
||||
|
||||
#endif
|
||||
134
cde/programs/dtinfo/DtMmdb/StyleSheet/Const.h
Normal file
134
cde/programs/dtinfo/DtMmdb/StyleSheet/Const.h
Normal file
@@ -0,0 +1,134 @@
|
||||
|
||||
#ifndef _name_consts_h
|
||||
#define _name_consts_h 1
|
||||
|
||||
#define BREAK "BREAK"
|
||||
#define LINE_BREAK "LINE"
|
||||
#define COLUMN_BREAK "COLUMN"
|
||||
#define PAGE_BREAK "PAGE"
|
||||
#define LINE_AFTER_BREAK "LINEAFTER"
|
||||
#define COLUMN_AFTER_BREAK "COLUMNAFTER"
|
||||
#define PAGE_AFTER_BREAK "PAGEAFTER"
|
||||
|
||||
|
||||
#define FONT "FONT"
|
||||
#define FONT_FAMILY "FAMILY"
|
||||
#define FONT_WEIGHT "WEIGHT"
|
||||
#define FONT_SLANT "SLANT"
|
||||
#define FONT_SIZE "SIZE"
|
||||
#define FONT_XLFD "XLFD"
|
||||
#define FONT_SUBSCRIPT "SUBSCRIPT"
|
||||
#define FONT_SUPERSCRIPT "SUPERSCRIPT"
|
||||
|
||||
#define FONT_WEIGHT_MEDIUM "MEDIUM"
|
||||
#define FONT_WEIGHT_BOLD "BOLD"
|
||||
#define FONT_SLANT_ROMAN "ROMAN"
|
||||
#define FONT_SLANT_ITALIC "ITALIC"
|
||||
#define FONT_FAMILY_HELVETICA "HELVETICA"
|
||||
|
||||
|
||||
#define FOOTNOTES "FOOTNOTE"
|
||||
|
||||
#define PARA "PARA"
|
||||
#define COLUMNS "COLUMNS"
|
||||
#define ONE_COLUMN "ONE"
|
||||
#define TWO_COLUMN "TWO"
|
||||
#define LEADING "LEADING"
|
||||
|
||||
#define GRAPHIC "GRAPHIC"
|
||||
#define GRAPHIC_TYPE "GRTYPE"
|
||||
#define GRAPHIC_ALIGN "ALIGN"
|
||||
#define GRAPHIC_ALIGN_MIDDLE "INLINE"
|
||||
#define GRAPHIC_ALIGN_BLOCK "BLOCK"
|
||||
#define GRAPHIC_ALIGN_TOP "TOP"
|
||||
#define GRAPHIC_ALIGN_BOTTOM "BOTTOM"
|
||||
|
||||
#define HEADERS "HEADER"
|
||||
#define FOOTERS "FOOTER"
|
||||
#define HEADER "CONTENT"
|
||||
#define FOOTER "CONTENT"
|
||||
|
||||
|
||||
#define HIGHLIGHT "HIGHLIGHT"
|
||||
#define HIGHLIGHT_BOXED "BOXED"
|
||||
#define HIGHLIGHT_STRIKE "STRIKE-THROUGH"
|
||||
#define HIGHLIGHT_OVERLINE "OVERLINE"
|
||||
#define HIGHLIGHT_UNDERLINE "UNDERLINE"
|
||||
|
||||
#define INDENT "INDENT"
|
||||
|
||||
#define IGNORE "IGNORE"
|
||||
|
||||
#define LAYOUT "LAYOUT"
|
||||
#define LAYOUT_WIDTH "WIDTH"
|
||||
#define LAYOUT_HEIGHT "HEIGHT"
|
||||
#define LAYOUT_LEFT "LEFT"
|
||||
#define LAYOUT_RIGHT "RIGHT"
|
||||
#define LAYOUT_TOP "TOP"
|
||||
#define LAYOUT_BOTTOM "BOTTOM"
|
||||
#define LAYOUT_CENTERED "CENTERED"
|
||||
|
||||
#define LINE_WRAPPING "WRAP"
|
||||
#define WRAP_CHAR "CHAR"
|
||||
#define WRAP_WORD "WORD"
|
||||
#define WRAP_NONE "NONE"
|
||||
#define WRAP_HYPHENATION "HYPHENATION"
|
||||
|
||||
#define LOCATOR "LOCATOR"
|
||||
|
||||
#define MARGIN "MARGIN"
|
||||
#define MARGIN_LEFT "LEFT"
|
||||
#define MARGIN_RIGHT "RIGHT"
|
||||
#define MARGIN_TOP "TOP"
|
||||
#define MARGIN_BOTTOM "BOTTOM"
|
||||
|
||||
#define MEDIA "MEDIUM"
|
||||
|
||||
#define MEDIA_SIZE "SIZE"
|
||||
#define MEDIA_SIZE_USLETTER "LETTER"
|
||||
#define MEDIA_SIZE_USLEGAL "LEGAL"
|
||||
#define MEDIA_SIZE_TABLOID "TABLOID"
|
||||
#define MEDIA_SIZE_LEDGER "LEDGER"
|
||||
#define MEDIA_SIZE_STATEMENT "STATEMENT"
|
||||
#define MEDIA_SIZE_Executive "EXECUTIVE"
|
||||
#define MEDIA_SIZE_A3 "A3"
|
||||
#define MEDIA_SIZE_A4 "A4"
|
||||
#define MEDIA_SIZE_A5 "A5"
|
||||
#define MEDIA_SIZE_B4 "B4"
|
||||
#define MEDIA_SIZE_B5 "B5"
|
||||
#define MEDIA_SIZE_FOLIO "FOLIO"
|
||||
#define MEDIA_SIZE_QUARTO "QUARTO"
|
||||
|
||||
#define MEDIA_ORIENTATION "ORIENTATION"
|
||||
#define MEDIA_ORIENTATION_PORTRAIT "PORTRAIT"
|
||||
#define MEDIA_ORIENTATION_LANDSCAPE "LANDSCAPE"
|
||||
|
||||
|
||||
#define PREFIX "PREFIX"
|
||||
#define PREFIX_CONTENT "CONTENT"
|
||||
#define PREFIX_POSITION "POSITION"
|
||||
|
||||
#define POSTFIX "SUFFIX"
|
||||
#define POSTFIX "SUFFIX"
|
||||
#define POSTFIX_CONTENT "CONTENT"
|
||||
#define POSTFIX_POSITION "POSITION"
|
||||
|
||||
#define QUADDING "QUADDING"
|
||||
#define QUADDING_ASIS "ASIS"
|
||||
#define QUADDING_LEFT "LEFT"
|
||||
#define QUADDING_RIGHT "RIGHT"
|
||||
#define QUADDING_FULL "FULL"
|
||||
#define QUADDING_CENTERED "CENTERED"
|
||||
|
||||
#define TAB "TAB"
|
||||
|
||||
#define AUTO_NUMBER "AUTONUMBER"
|
||||
#define AUTO_NUMBER_NUMERIC "ARABIC"
|
||||
#define AUTO_NUMBER_ALPHABETIC_UPPERCASE "UCALPHA"
|
||||
#define AUTO_NUMBER_ALPHABETIC_LOWERCASE "LCALPHA"
|
||||
#define AUTO_NUMBER_ROMAN_UPPERCASE "UCROMAN"
|
||||
#define AUTO_NUMBER_ROMAN_LOWERCASE "LCROMAN"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
50
cde/programs/dtinfo/DtMmdb/StyleSheet/Debug.h
Normal file
50
cde/programs/dtinfo/DtMmdb/StyleSheet/Debug.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* $XConsortium: Debug.h /main/3 1996/06/11 17:06:00 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _debug_h
|
||||
#define _debug_h 1
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define ON_DEBUG(stmt) stmt
|
||||
#else
|
||||
#define ON_DEBUG(stmt)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#if !defined ( __STDC__) && !defined (hpux)
|
||||
#define debug(s, x) s << "x" << " = " << (x) << "\n"
|
||||
#else
|
||||
#define debug(s, x) s << #x << " = " << (x) << "\n"
|
||||
#endif
|
||||
#define MESSAGE(s, x) s << x << "\n"
|
||||
#else
|
||||
#define debug(s,x)
|
||||
#define MESSAGE(s,x)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
694
cde/programs/dtinfo/DtMmdb/StyleSheet/DocParser.C
Normal file
694
cde/programs/dtinfo/DtMmdb/StyleSheet/DocParser.C
Normal file
@@ -0,0 +1,694 @@
|
||||
/* Copyright (c) 1995 FUJITSU LIMITED */
|
||||
/* All Rights Reserved */
|
||||
|
||||
/* $TOG: DocParser.C /main/16 1998/04/17 11:48:07 mgreess $ */
|
||||
#ifdef DEBUG
|
||||
#include "assert.h"
|
||||
#endif
|
||||
#include "Debug.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "DocParser.h"
|
||||
#include "Resolver.h"
|
||||
#include "Element.h"
|
||||
#include "AttributeList.h"
|
||||
|
||||
#define DATA_BUF_SIZ 4096
|
||||
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
static ostrstream& terminate(ostrstream& ost)
|
||||
{
|
||||
char* string = ost.str();
|
||||
*(string + ost.pcount()) = 0;
|
||||
|
||||
return ost;
|
||||
}
|
||||
#endif
|
||||
|
||||
DocParser::DocParser(Resolver &r)
|
||||
: f_resolver(r),
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
f_buffer(new char[DATA_BUF_SIZ]),
|
||||
f_output(f_buffer, DATA_BUF_SIZ)
|
||||
#else
|
||||
f_streambuf(new strstreambuf(DATA_BUF_SIZ)),
|
||||
f_output(f_streambuf)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
DocParser::~DocParser()
|
||||
{
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
if (f_buffer) delete[] f_buffer;
|
||||
#else
|
||||
// this causes a free memory read when f_output is deleted as part of this
|
||||
// object...nothing we can do about it
|
||||
delete f_streambuf ;
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int
|
||||
DocParser::parse(istream &input)
|
||||
{
|
||||
f_resolver.Begin();
|
||||
unsigned int ok = rawParse(input);
|
||||
f_resolver.End();
|
||||
return ok;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
DocParser::rawParse(istream &input)
|
||||
{
|
||||
input.unsetf(ios::skipws);
|
||||
|
||||
f_ignoring_element = 0 ;
|
||||
|
||||
switch(read_tag(input, f_output))
|
||||
{
|
||||
case StartTag:
|
||||
{
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
Symbol name(gElemSymTab->intern(terminate(f_output).str()));
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *data = f_streambuf->str();
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "StartTag case:");
|
||||
debug(cerr, f_streambuf->pcount());
|
||||
debug(cerr, data);
|
||||
*/
|
||||
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
data[f_streambuf->pcount()] = 0;
|
||||
#endif
|
||||
f_streambuf->freeze(0);
|
||||
Symbol name(gElemSymTab->intern(data));
|
||||
#endif
|
||||
process(input, f_output, name, 1, 1);
|
||||
}
|
||||
break;
|
||||
case EndTag:
|
||||
case AttributeSection:
|
||||
case OliasAttribute:
|
||||
throw(CASTDPUTEXCEPT docParserUnexpectedTag());
|
||||
break;
|
||||
case NoTag:
|
||||
throw(CASTDPUDEXCEPT docParserUnexpectedData());
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
update_last_seen_child_name(Symbol*& last_seen_child_name, unsigned int& child_relative_sibling_number, const Symbol& new_child_name)
|
||||
{
|
||||
if ( last_seen_child_name == 0 ||
|
||||
!(*last_seen_child_name == Symbol(new_child_name))
|
||||
)
|
||||
{
|
||||
delete last_seen_child_name ;
|
||||
last_seen_child_name = new Symbol(new_child_name);
|
||||
child_relative_sibling_number= 1;
|
||||
} else
|
||||
child_relative_sibling_number++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
DocParser::process(istream &input, ostream &output,
|
||||
const Symbol &name,
|
||||
unsigned int sibling_number, unsigned int this_sibling_number)
|
||||
{
|
||||
ON_DEBUG(cerr << "process(" << name << ") -> " << sibling_number << endl);
|
||||
|
||||
Symbol* last_seen_child_name = 0;
|
||||
|
||||
unsigned int child_relative_sibling_number = 0;
|
||||
|
||||
unsigned int child = 1 ; // sibling numbers for child elements
|
||||
|
||||
char c ;
|
||||
while ((input >> c) && (c == '\n'));
|
||||
input.putback(c);
|
||||
|
||||
if (input.eof())
|
||||
throw(CASTDPUEEXCEPT docParserUnexpectedEof());
|
||||
|
||||
int ignore = 0 ;
|
||||
|
||||
try
|
||||
{
|
||||
// process whatever comes right after start tag
|
||||
TagType tt = read_tag(input, output);
|
||||
switch (tt)
|
||||
{
|
||||
case StartTag:
|
||||
{
|
||||
ON_DEBUG(cerr << "beginElement" << endl);
|
||||
// have to begin this element before processing child elements
|
||||
if (!f_ignoring_element)
|
||||
{
|
||||
ignore = f_resolver.beginElement(new Element(name,
|
||||
sibling_number, 0,
|
||||
0,
|
||||
this_sibling_number));
|
||||
f_ignoring_element = ignore ;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// first child of this node
|
||||
/////////////////////////////
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
Symbol name(gElemSymTab->intern(terminate(f_output).str()));
|
||||
|
||||
update_last_seen_child_name(last_seen_child_name,
|
||||
child_relative_sibling_number, name);
|
||||
|
||||
f_output.rdbuf()->freeze(0);
|
||||
|
||||
process(input, output, name, child++, child_relative_sibling_number);
|
||||
#else
|
||||
char *data = f_streambuf->str();
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
data[f_streambuf->pcount()] = 0;
|
||||
#endif
|
||||
Symbol name(gElemSymTab->intern(data));
|
||||
update_last_seen_child_name(last_seen_child_name,
|
||||
child_relative_sibling_number, name);
|
||||
|
||||
f_streambuf->freeze(0);
|
||||
process(input, output, name,
|
||||
child++, child_relative_sibling_number);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case EndTag:
|
||||
// hit an end tag right after start tag
|
||||
#ifdef DEBUG
|
||||
{
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char *data = terminate(f_output).str();
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *data = f_streambuf->str();
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
data[f_streambuf->pcount()] = 0;
|
||||
#endif
|
||||
f_streambuf->freeze(0);
|
||||
#endif
|
||||
cerr << "EndTag: " << data << endl;
|
||||
assert(gElemSymTab->intern(data) == name);
|
||||
}
|
||||
#endif
|
||||
|
||||
// this node
|
||||
if (!f_ignoring_element)
|
||||
{
|
||||
int ignore = f_resolver.beginElement(new Element(name,
|
||||
sibling_number,
|
||||
0, 0, this_sibling_number));
|
||||
if (!ignore)
|
||||
f_resolver.endElement(name);
|
||||
}
|
||||
return ; // EXIT FUNCTION
|
||||
break;
|
||||
case AttributeSection:
|
||||
{
|
||||
#if !defined(SC3) && \
|
||||
!defined(__osf__) && \
|
||||
!defined(_IBMR2) && \
|
||||
!defined(__uxp__) && \
|
||||
!defined(USL) && \
|
||||
!defined(linux)
|
||||
volatile
|
||||
#endif
|
||||
AttributeList *attrs = 0;
|
||||
#if !defined(SC3) && \
|
||||
!defined(__osf__) && \
|
||||
!defined(_IBMR2) && \
|
||||
!defined(__uxp__) && \
|
||||
!defined(USL) && \
|
||||
!defined(linux)
|
||||
volatile
|
||||
#endif
|
||||
AttributeList *olias_attrs = 0;
|
||||
|
||||
try
|
||||
{
|
||||
process_attributes(input, output, attrs, olias_attrs);
|
||||
|
||||
if (!f_ignoring_element)
|
||||
{
|
||||
//////////////////////////////
|
||||
// this node with attributes
|
||||
//////////////////////////////
|
||||
ignore = f_resolver.beginElement(new Element(name,
|
||||
sibling_number,
|
||||
attrs,
|
||||
olias_attrs,
|
||||
this_sibling_number
|
||||
));
|
||||
f_ignoring_element = ignore ;
|
||||
}
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
/*
|
||||
delete attrs ;
|
||||
delete olias_attrs ;
|
||||
*/
|
||||
attrs = 0 ;
|
||||
olias_attrs = 0 ;
|
||||
}
|
||||
end_try;
|
||||
}
|
||||
break;
|
||||
case OliasAttribute:
|
||||
throw(CASTDPUTEXCEPT docParserUnexpectedTag());
|
||||
break;
|
||||
|
||||
case NoTag:
|
||||
{
|
||||
if (!f_ignoring_element)
|
||||
{
|
||||
// this node
|
||||
ignore = f_resolver.beginElement(new Element(name,
|
||||
sibling_number,
|
||||
0, 0, this_sibling_number));
|
||||
f_ignoring_element = ignore ;
|
||||
}
|
||||
// process data
|
||||
read_data(input, output);
|
||||
|
||||
if (!f_ignoring_element)
|
||||
{
|
||||
// the str() call seems to add the null byte to the stream
|
||||
// and increment the pcount, so we must make sure it gets
|
||||
// called first
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char *string = terminate(f_output).str();
|
||||
int size = f_output.pcount();
|
||||
f_resolver.data(string, size);
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *string = f_streambuf->str();
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
string[f_streambuf->pcount()] = 0;
|
||||
int size = f_streambuf->pcount() ;
|
||||
#else
|
||||
int size = f_streambuf->pcount() - 1 ;
|
||||
#endif
|
||||
f_resolver.data(string, size);
|
||||
f_streambuf->freeze(0); // unfreeze buffer frozen by str() call
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
while ((tt = read_tag(input, output)) != EndTag)
|
||||
switch (tt)
|
||||
{
|
||||
case StartTag:
|
||||
{
|
||||
/////////////////////////////
|
||||
// second child and beyond.
|
||||
/////////////////////////////
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char *data = f_output.str();
|
||||
*(data + f_output.pcount()) = 0;
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *data = f_streambuf->str();
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
data[f_streambuf->pcount ()] = 0;
|
||||
#endif
|
||||
f_streambuf->freeze(0);
|
||||
#endif
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "StartTag case2");
|
||||
debug(cerr, data);
|
||||
debug(cerr, f_streambuf->pcount ());
|
||||
*/
|
||||
|
||||
Symbol name(gElemSymTab->intern(data));
|
||||
update_last_seen_child_name(last_seen_child_name,
|
||||
child_relative_sibling_number, name);
|
||||
|
||||
process(input, output, name, child++, child_relative_sibling_number);
|
||||
}
|
||||
break;
|
||||
case EndTag: // should never get this
|
||||
break;
|
||||
// we have already processed these for this tag
|
||||
case AttributeSection:
|
||||
case OliasAttribute:
|
||||
throw(CASTDPUTEXCEPT docParserUnexpectedTag());
|
||||
break;
|
||||
case NoTag:
|
||||
{
|
||||
read_data(input, output);
|
||||
|
||||
if (!f_ignoring_element)
|
||||
{
|
||||
// the str() call seems to add the null byte to the stream
|
||||
// and increment the pcount, so we must make sure it gets
|
||||
// called first
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char *string = f_output.str();
|
||||
int size = f_output.pcount();
|
||||
*(string + size) = 0;
|
||||
f_resolver.data(string, size);
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *string = f_streambuf->str();
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
string[f_streambuf->pcount()] = 0;
|
||||
int size = f_streambuf->pcount() ;
|
||||
#else
|
||||
int size = f_streambuf->pcount() - 1 ;
|
||||
#endif
|
||||
f_resolver.data(string, size);
|
||||
f_streambuf->freeze(0); // unfreeze buffer frozen by str() call
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
{
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char *data = terminate(f_output).str();
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *data = f_streambuf->str();
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
data[f_streambuf->pcount ()] = 0;
|
||||
#endif
|
||||
f_streambuf->freeze(0);
|
||||
#endif
|
||||
cerr << "EndTag: " << data << endl;
|
||||
assert(gElemSymTab->intern(data) == name);
|
||||
}
|
||||
#endif
|
||||
// hit end tag, end processing
|
||||
if (!f_ignoring_element)
|
||||
f_resolver.endElement(name);
|
||||
|
||||
// if we set ignore flag, unset it
|
||||
if (ignore)
|
||||
f_ignoring_element = 0;
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
rethrow;
|
||||
}
|
||||
end_try;
|
||||
ON_DEBUG(cerr << "exit process: " << name << endl);
|
||||
delete last_seen_child_name;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DocParser::process_attributes(istream &input, ostream &output,
|
||||
AttributeList *&attrs,
|
||||
AttributeList *&olias_attrs)
|
||||
{
|
||||
TagType tt ;
|
||||
|
||||
Attribute* newAttribute = 0;
|
||||
|
||||
AttributeList* orig_attrs = attrs;
|
||||
AttributeList* orig_olias_attrs = olias_attrs;
|
||||
|
||||
char *theData = 0;
|
||||
|
||||
try {
|
||||
while ((tt = read_tag(input,output)) != NoTag)
|
||||
{
|
||||
switch (tt)
|
||||
{
|
||||
case StartTag:
|
||||
{
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
theData = f_streambuf->str ();
|
||||
theData[f_streambuf->pcount()] = 0;
|
||||
#endif
|
||||
if (!attrs)
|
||||
attrs = new AttributeList ;
|
||||
|
||||
newAttribute =
|
||||
process_attribute(input, output,
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
gSymTab->intern(terminate(f_output).str()),
|
||||
#else
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
gSymTab->intern(theData),
|
||||
#else
|
||||
gSymTab->intern(f_streambuf->str()),
|
||||
#endif
|
||||
#endif
|
||||
StartTag
|
||||
);
|
||||
attrs->add(newAttribute);
|
||||
break;
|
||||
}
|
||||
case EndTag:
|
||||
return ; // EXIT FUNCTION
|
||||
|
||||
case AttributeSection:
|
||||
throw(CASTDPUTEXCEPT docParserUnexpectedTag());
|
||||
break;
|
||||
case OliasAttribute:
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
theData = f_streambuf->str ();
|
||||
theData[f_streambuf->pcount()] = 0;
|
||||
#endif
|
||||
// mirrors attribute
|
||||
if (!olias_attrs)
|
||||
olias_attrs = new AttributeList ;
|
||||
|
||||
newAttribute =
|
||||
process_attribute(input, output,
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
gSymTab->intern(terminate(f_output).str()),
|
||||
#else
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
gSymTab->intern(theData),
|
||||
#else
|
||||
gSymTab->intern(f_streambuf->str()),
|
||||
#endif
|
||||
#endif
|
||||
OliasAttribute
|
||||
);
|
||||
|
||||
olias_attrs->add(newAttribute);
|
||||
break;
|
||||
case NoTag:
|
||||
throw(CASTDPUDEXCEPT docParserUnexpectedData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
delete newAttribute;
|
||||
|
||||
if ( orig_attrs == 0 ) {
|
||||
delete attrs;
|
||||
attrs = 0;
|
||||
}
|
||||
|
||||
if ( orig_olias_attrs == 0 ) {
|
||||
delete olias_attrs;
|
||||
olias_attrs = 0;
|
||||
}
|
||||
|
||||
rethrow;
|
||||
}
|
||||
end_try;
|
||||
}
|
||||
|
||||
Attribute *
|
||||
DocParser::process_attribute(istream &input, ostream &output,
|
||||
const Symbol &name, TagType tt)
|
||||
{
|
||||
//ON_DEBUG(cerr << "process_attribute: " << name << endl);
|
||||
|
||||
// If the attribute is OLIAS internal, we use DocParser's
|
||||
// read_data(). This is to prevent the attribte value
|
||||
// from change in a call to specific renderer engine's
|
||||
// read_data().
|
||||
//
|
||||
// Example: LoutDocparser::read_data() quotes any '.' char
|
||||
// which changes the graphic locator value if the element
|
||||
// is OLIAS internal attribute #GRAPHIC.
|
||||
|
||||
if ( tt == OliasAttribute ) {
|
||||
DocParser::read_data(input, output);
|
||||
} else
|
||||
(void)read_data(input, output);
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char *data = f_output.str();
|
||||
*(data + f_output.pcount()) = 0;
|
||||
f_output.rdbuf()->freeze(0);
|
||||
#else
|
||||
char *data = f_streambuf->str();
|
||||
//#ifdef _IBMR2
|
||||
#if !defined(SC3) && !defined(__osf__)
|
||||
data[f_streambuf->pcount ()] = 0;
|
||||
#endif
|
||||
f_streambuf->freeze(0);
|
||||
#endif
|
||||
Attribute *attr = new Attribute(name, strdup(data));
|
||||
|
||||
switch (read_tag(input, output))
|
||||
{
|
||||
case StartTag:
|
||||
case AttributeSection:
|
||||
case OliasAttribute:
|
||||
delete attr ;
|
||||
throw(CASTDPUTEXCEPT docParserUnexpectedTag());
|
||||
break;
|
||||
case NoTag:
|
||||
delete attr;
|
||||
throw(CASTDPUDEXCEPT docParserUnexpectedData());
|
||||
break;
|
||||
case EndTag:
|
||||
break;
|
||||
}
|
||||
|
||||
return attr ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
DocParser::TagType
|
||||
DocParser::read_tag(istream &input, ostream &output)
|
||||
{
|
||||
output.seekp(streampos(0));
|
||||
|
||||
TagType tt = StartTag;
|
||||
|
||||
char c ;
|
||||
|
||||
// strip newlines before/after tags
|
||||
while ((input >> c) && (c == '\n'));
|
||||
if (input.eof())
|
||||
throw(CASTDPUEEXCEPT docParserUnexpectedEof());
|
||||
|
||||
if (c != '<')
|
||||
{
|
||||
input.putback(c);
|
||||
return NoTag;
|
||||
}
|
||||
|
||||
|
||||
input >> c ;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '/':
|
||||
tt = EndTag ;
|
||||
break;
|
||||
case '#':
|
||||
input >> c;
|
||||
if (c == '>')
|
||||
return AttributeSection ; // EXIT
|
||||
else
|
||||
{
|
||||
tt = OliasAttribute ;
|
||||
output << c; // keep char we just read
|
||||
}
|
||||
break;
|
||||
case '>':
|
||||
throw(CASTUTEXCEPT unknownTagException());
|
||||
// NOT REACHED
|
||||
break;
|
||||
default:
|
||||
output << c ; // keep char we just read
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// get (remainder of) tag name
|
||||
while ((input >> c) && (c != '>'))
|
||||
output << c ;
|
||||
|
||||
return tt ;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DocParser::read_data(istream &input, ostream &output)
|
||||
{
|
||||
char c ;
|
||||
|
||||
output.seekp(streampos(0));
|
||||
|
||||
while ((input >> c) && (c != '<'))
|
||||
{
|
||||
// handle entities
|
||||
if (c == '&')
|
||||
{
|
||||
char tmpbuf[64];
|
||||
unsigned int tmplen = 0;
|
||||
while ((input >> c ) && (c != ';'))
|
||||
{
|
||||
tmpbuf[tmplen++] = c ;
|
||||
if (tmplen > 63)
|
||||
{
|
||||
cerr << "Temp Buf overflow (ampersand problem)" << endl;
|
||||
throw(CASTEXCEPT Exception());
|
||||
}
|
||||
}
|
||||
if (input.eof())
|
||||
throw(CASTDPUEEXCEPT docParserUnexpectedEof());
|
||||
|
||||
tmpbuf[tmplen] = 0 ;
|
||||
|
||||
#ifdef ENTITY_DEBUG
|
||||
cerr << "Entity: " << tmpbuf << endl;
|
||||
#endif
|
||||
|
||||
if ((!strcmp(tmpbuf, "hardreturn")) ||
|
||||
(!strcmp(tmpbuf, "lnfeed")))
|
||||
c = '\n';
|
||||
else
|
||||
if ((!strcmp(tmpbuf, "lang")) ||
|
||||
(!strcmp(tmpbuf, "lt")))
|
||||
c = '<' ;
|
||||
else
|
||||
if (!strcmp(tmpbuf, "amp"))
|
||||
c = '&' ;
|
||||
else
|
||||
if (!strcmp(tmpbuf, "nbsp")) // non-break space
|
||||
c = (char)0xA0 ;
|
||||
else
|
||||
c = ' ';
|
||||
|
||||
}
|
||||
|
||||
output << c;
|
||||
}
|
||||
|
||||
// can never run out of input while reading data, tags must be balanced
|
||||
if (input.eof())
|
||||
throw(CASTDPUEEXCEPT docParserUnexpectedEof());
|
||||
|
||||
input.putback(c);
|
||||
|
||||
}
|
||||
69
cde/programs/dtinfo/DtMmdb/StyleSheet/DocParser.h
Normal file
69
cde/programs/dtinfo/DtMmdb/StyleSheet/DocParser.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* $XConsortium: DocParser.h /main/6 1996/06/11 17:06:11 cde-hal $ */
|
||||
/* Copyright (c) 1995 FUJITSU LIMITED */
|
||||
/* All Rights Reserved */
|
||||
|
||||
#include <iostream.h>
|
||||
#include <strstream.h>
|
||||
|
||||
#include "SymTab.h"
|
||||
#include "Exceptions.hh"
|
||||
|
||||
class Resolver;
|
||||
class Attribute;
|
||||
class AttributeList;
|
||||
|
||||
// parse SGML like documents
|
||||
|
||||
// attributes follow elements in an olias section
|
||||
|
||||
// <ELEMENT>
|
||||
// <#><attr_1>value</>
|
||||
// <attr_2>value</>
|
||||
// <#olias_attr>value</>
|
||||
// </>
|
||||
// Element data here
|
||||
// </ELEMENT>
|
||||
|
||||
class Element ;
|
||||
|
||||
class DocParser : public Destructable
|
||||
{
|
||||
public:
|
||||
enum TagType { StartTag, EndTag, AttributeSection, OliasAttribute, NoTag };
|
||||
|
||||
DocParser(Resolver &);
|
||||
~DocParser();
|
||||
|
||||
// returns a boolean
|
||||
unsigned int parse(istream &);
|
||||
|
||||
// parse without calling Begin() and End() on the renderer.
|
||||
unsigned int rawParse(istream &);
|
||||
|
||||
protected:
|
||||
virtual void read_data(istream &, ostream &);
|
||||
|
||||
private:
|
||||
|
||||
void process(istream &, ostream &, const Symbol &tagname,
|
||||
unsigned int sibling_number,
|
||||
unsigned int relative_sibling_number);
|
||||
TagType read_tag(istream &, ostream &);
|
||||
void process_entity(istream &, ostream &);
|
||||
|
||||
void process_attributes(istream &, ostream &,
|
||||
AttributeList *&attrs,
|
||||
AttributeList *&olias_attrs);
|
||||
Attribute *process_attribute(istream &, ostream &, const Symbol &name, TagType);
|
||||
|
||||
private:
|
||||
unsigned int f_ignoring_element ;
|
||||
#if defined(SC3) || defined(__osf__)
|
||||
char* const f_buffer;
|
||||
ostrstream f_output;
|
||||
#else
|
||||
strstreambuf *f_streambuf ;
|
||||
ostream f_output;
|
||||
#endif
|
||||
Resolver &f_resolver;
|
||||
};
|
||||
118
cde/programs/dtinfo/DtMmdb/StyleSheet/Element.C
Normal file
118
cde/programs/dtinfo/DtMmdb/StyleSheet/Element.C
Normal file
@@ -0,0 +1,118 @@
|
||||
// $TOG: Element.C /main/5 1998/04/17 11:48:25 mgreess $
|
||||
#include <iostream.h>
|
||||
#include <stdlib.h>
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "Element.h"
|
||||
#include "AttributeList.h"
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Element
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define OLIAS_SIBLING_INFO "LAST"
|
||||
|
||||
|
||||
Element::Element(const Element& element)
|
||||
:
|
||||
f_gi(element.f_gi),
|
||||
f_sibling_number(element.f_sibling_number),
|
||||
f_attributes(element.f_attributes),
|
||||
f_olias_attributes(element.f_olias_attributes),
|
||||
f_freeAttrLists(false),
|
||||
f_relative_sibling_number(element.f_relative_sibling_number),
|
||||
f_last_child(element.f_last_child),
|
||||
f_relatively_last_child(element.f_relatively_last_child)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
Element::Element(const Symbol& gi,
|
||||
unsigned int sibling_number,
|
||||
AttributeList *attlist,
|
||||
AttributeList *olias_attributes,
|
||||
unsigned int relative_sibling_number
|
||||
|
||||
)
|
||||
: f_gi(gi),
|
||||
f_sibling_number(sibling_number),
|
||||
f_attributes(attlist),
|
||||
f_olias_attributes(olias_attributes),
|
||||
f_freeAttrLists(true),
|
||||
f_relative_sibling_number(relative_sibling_number)
|
||||
{
|
||||
f_last_child = 0;
|
||||
f_relatively_last_child = 0;
|
||||
|
||||
Symbol name(gSymTab->intern(OLIAS_SIBLING_INFO));
|
||||
const Attribute* x = get_olias_attribute(name);
|
||||
|
||||
if ( x && x -> value() ) {
|
||||
int code = atoi(x -> value());
|
||||
switch (code) {
|
||||
case 0:
|
||||
f_last_child = 0;
|
||||
f_relatively_last_child = 0;
|
||||
break;
|
||||
case 1:
|
||||
f_last_child = 0;
|
||||
f_relatively_last_child = 1;
|
||||
break;
|
||||
case 2:
|
||||
f_last_child = 1;
|
||||
f_relatively_last_child = 1;
|
||||
break;
|
||||
default:
|
||||
throw(CASTEXCEPT Exception());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Element::~Element()
|
||||
{
|
||||
if ( f_freeAttrLists == true ) {
|
||||
delete f_olias_attributes;
|
||||
delete f_attributes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Attribute *
|
||||
Element::get_attribute(const Symbol &name) const
|
||||
{
|
||||
if (f_attributes)
|
||||
return f_attributes->lookup(name);
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
const Attribute *
|
||||
Element::get_olias_attribute(const Symbol &name) const
|
||||
{
|
||||
if (f_olias_attributes)
|
||||
return f_olias_attributes->lookup(name);
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
ostream &
|
||||
Element::print(ostream &o) const
|
||||
{
|
||||
o << '<' << f_gi ;
|
||||
|
||||
#ifdef SIBLING_DEBUG
|
||||
o << "[" << this->f_sibling_number << "]";
|
||||
o << "[" << this->f_relative_sibling_number<< "]";
|
||||
o << "[" << this-> f_last_child << "]";
|
||||
o << "[" << this-> f_relatively_last_child<< "]";
|
||||
#endif
|
||||
|
||||
if (f_attributes)
|
||||
o << *f_attributes ;
|
||||
|
||||
if (f_olias_attributes)
|
||||
o << " #" << *f_olias_attributes ;
|
||||
|
||||
o << '>' ;
|
||||
|
||||
return o;
|
||||
}
|
||||
71
cde/programs/dtinfo/DtMmdb/StyleSheet/Element.h
Normal file
71
cde/programs/dtinfo/DtMmdb/StyleSheet/Element.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* $XConsortium: Element.h /main/5 1996/08/21 15:50:08 drk $ */
|
||||
#ifndef _Element_h
|
||||
#define _Element_h
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
#else
|
||||
#include "dti_cc/CC_Slist.h"
|
||||
#endif
|
||||
|
||||
#include "SymTab.h"
|
||||
|
||||
/* **************************************************************
|
||||
class Element
|
||||
|
||||
this is the structure passed from the node parser to the Resolver.
|
||||
It contains the Element GI, and the attribute list for the element
|
||||
************************************************************** */
|
||||
|
||||
class Attribute;
|
||||
class AttributeList;
|
||||
|
||||
class Element
|
||||
{
|
||||
public:
|
||||
Element(const Element&);
|
||||
Element(const Symbol &gi,
|
||||
unsigned int sibling_number = 0,
|
||||
AttributeList *attrs = 0,
|
||||
AttributeList *olias_attrs = 0,
|
||||
unsigned int relative_sibling_number = 0
|
||||
);
|
||||
~Element();
|
||||
|
||||
const Symbol &gi() const { return f_gi ; }
|
||||
|
||||
const Attribute *get_attribute(const Symbol &name) const ;
|
||||
const Attribute *get_olias_attribute(const Symbol &name) const;
|
||||
|
||||
unsigned int sibling_number() const { return f_sibling_number ; }
|
||||
unsigned int relative_sibling_number() const
|
||||
{ return f_relative_sibling_number; }
|
||||
|
||||
int last_child() const { return f_last_child; }
|
||||
int relatively_last_child() const
|
||||
{ return f_relatively_last_child; }
|
||||
|
||||
ostream &print(ostream &) const ;
|
||||
|
||||
private:
|
||||
unsigned int f_freeAttrLists;
|
||||
unsigned int f_sibling_number ; // counting all children of a parent
|
||||
unsigned int f_relative_sibling_number ; // counting all
|
||||
// consecutive children
|
||||
// of same types of a
|
||||
// parent
|
||||
int f_last_child;
|
||||
int f_relatively_last_child;
|
||||
Symbol f_gi ;
|
||||
AttributeList *f_attributes;
|
||||
AttributeList *f_olias_attributes;
|
||||
};
|
||||
|
||||
inline
|
||||
ostream &operator<<(ostream &o, const Element &e)
|
||||
{
|
||||
return e.print(o);
|
||||
}
|
||||
|
||||
|
||||
#endif /* _Element_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
407
cde/programs/dtinfo/DtMmdb/StyleSheet/Expression.C
Normal file
407
cde/programs/dtinfo/DtMmdb/StyleSheet/Expression.C
Normal file
@@ -0,0 +1,407 @@
|
||||
// $TOG: Expression.C /main/9 1998/04/17 11:48:40 mgreess $
|
||||
#include "Attribute.h"
|
||||
#include "AttributeList.h"
|
||||
#include "Expression.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "ResolverStack.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "VariableTable.h"
|
||||
#include "Renderer.h"
|
||||
#include "Debug.h"
|
||||
#include <stream.h>
|
||||
|
||||
#include "HardCopy/autoNumberFP.h"
|
||||
|
||||
|
||||
extern const Element *gCurrentElement;
|
||||
extern const FeatureSet *gCurrentLocalSet;
|
||||
extern const FeatureSet *gParentCompleteSet;
|
||||
|
||||
Expression::Expression(TermNode *root)
|
||||
: f_root(root)
|
||||
{
|
||||
}
|
||||
|
||||
Expression::Expression(const Expression &e)
|
||||
: f_root(e.f_root->clone())
|
||||
{
|
||||
}
|
||||
|
||||
ConstantNode::ConstantNode(FeatureValue *v)
|
||||
: f_value(v)
|
||||
{
|
||||
}
|
||||
|
||||
VariableNode::VariableNode(const Symbol &name)
|
||||
: f_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
CompositeVariableNode::CompositeVariableNode()
|
||||
: f_items(4)
|
||||
{
|
||||
}
|
||||
|
||||
CompositeVariableNode::CompositeVariableNode(size_t capac)
|
||||
: f_items(capac)
|
||||
{
|
||||
}
|
||||
|
||||
CompositeVariableNode::~CompositeVariableNode()
|
||||
{
|
||||
f_items.clearAndDestroy();
|
||||
}
|
||||
|
||||
void
|
||||
CompositeVariableNode::prependItem(const Symbol& item)
|
||||
{
|
||||
f_items.prepend(new Symbol(item));
|
||||
}
|
||||
|
||||
void
|
||||
CompositeVariableNode::appendItem(const Symbol& item)
|
||||
{
|
||||
f_items.append(new Symbol(item));
|
||||
}
|
||||
|
||||
const Symbol*
|
||||
CompositeVariableNode::convertableToVariable()
|
||||
{
|
||||
const Symbol* x = 0;
|
||||
if ( f_items.entries() == 1 ) {
|
||||
x = f_items.first();
|
||||
if ( gVariableTable -> exists(*x) )
|
||||
return x;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BinaryOperatorNode::BinaryOperatorNode(operatorType t,
|
||||
TermNode *left, TermNode *right)
|
||||
: f_operator(t), f_left(left), f_right(right)
|
||||
{
|
||||
}
|
||||
|
||||
BinaryOperatorNode::~BinaryOperatorNode()
|
||||
{
|
||||
delete f_left ;
|
||||
delete f_right;
|
||||
}
|
||||
|
||||
SgmlAttributeNode::SgmlAttributeNode(const Symbol &name)
|
||||
: f_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
FeatureValue *
|
||||
Expression::evaluate() const
|
||||
{
|
||||
return f_root->evaluate();
|
||||
}
|
||||
|
||||
Expression::~Expression()
|
||||
{
|
||||
delete f_root ;
|
||||
}
|
||||
|
||||
TermNode::~TermNode()
|
||||
{
|
||||
}
|
||||
|
||||
ConstantNode::~ConstantNode()
|
||||
{
|
||||
delete f_value ;
|
||||
}
|
||||
|
||||
FeatureValue *
|
||||
BinaryOperatorNode::evaluate() const
|
||||
{
|
||||
// calculate children trees and then have feature value do the operation
|
||||
|
||||
#if !defined(SC3) && !defined(_IBMR2) && !defined(__uxp__) && !defined(__osf__) && !defined(USL) && !defined(linux)
|
||||
volatile
|
||||
#endif
|
||||
FeatureValue *left = 0;
|
||||
#if !defined(SC3) && !defined(_IBMR2) && !defined(__uxp__) && !defined(__osf__) && !defined(USL) && !defined(linux)
|
||||
volatile
|
||||
#endif
|
||||
FeatureValue *right = 0;
|
||||
#if !defined(SC3) && !defined(_IBMR2) && !defined(__uxp__) && !defined(__osf__) && !defined(USL) && !defined(linux)
|
||||
volatile
|
||||
#endif
|
||||
FeatureValue *result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
left = f_left->evaluate();
|
||||
right = f_right->evaluate();
|
||||
|
||||
switch (f_operator)
|
||||
{
|
||||
case PLUS:
|
||||
result = *left + *right ;
|
||||
break;
|
||||
case MINUS:
|
||||
result = *left - *right ;
|
||||
break;
|
||||
case TIMES:
|
||||
result = *left * *right ;
|
||||
break;
|
||||
case DIVIDE:
|
||||
result = *left / *right ;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
delete left ;
|
||||
delete right ;
|
||||
delete result ;
|
||||
rethrow;
|
||||
}
|
||||
end_try ;
|
||||
delete left ;
|
||||
delete right ;
|
||||
return result ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
FeatureValue *
|
||||
VariableNode::evaluate() const
|
||||
{
|
||||
// this could be a feature or a variable
|
||||
// first look in the parent feature set
|
||||
|
||||
// NOTE: actual operation should be to look in the local feature set first
|
||||
// before going to the parent unless the inherit operator was used. Not sure
|
||||
// how to do this, because at this point, we are trying to evaluate the
|
||||
// current feature set
|
||||
|
||||
// see if item exists in parent feature hierarchy, and if not, then we go to
|
||||
// the variable table
|
||||
|
||||
//MESSAGE(cerr, "VariableNode::evaluate()");
|
||||
//f_name.print(cerr);
|
||||
|
||||
FeatureValue *variable_value = gVariableTable->lookup(f_name).evaluate();
|
||||
|
||||
//debug(cerr, int(variable_value));
|
||||
|
||||
if (!variable_value)
|
||||
throw(CASTUVEXCEPT undefinedVariableException(f_name));
|
||||
|
||||
// have to evaluate it in case it contains expressions or other variables
|
||||
// etc.
|
||||
FeatureValue *return_variable = 0;
|
||||
|
||||
try
|
||||
{
|
||||
return_variable = variable_value->evaluate() ;
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
delete return_variable;
|
||||
delete variable_value ;
|
||||
rethrow;
|
||||
}
|
||||
end_try;
|
||||
|
||||
//MESSAGE(cerr, "VariableNode::evaluate() completes");
|
||||
|
||||
delete variable_value ;
|
||||
return return_variable;
|
||||
}
|
||||
|
||||
FeatureValue *
|
||||
CompositeVariableNode::evaluate() const
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "CompositeVariableNode::evaluate():");
|
||||
print(cerr);
|
||||
cerr << "\n";
|
||||
f_items[0] -> print(cerr);
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
//debug(cerr, int(gCurrentLocalSet));
|
||||
//debug(cerr, int(gParentCompleteSet));
|
||||
|
||||
const Feature *f = 0;
|
||||
|
||||
if ( gCurrentLocalSet )
|
||||
f = gCurrentLocalSet->deep_lookup(f_items) ;
|
||||
|
||||
//debug(cerr, int(f));
|
||||
|
||||
if (!f && gParentCompleteSet )
|
||||
f = gParentCompleteSet->deep_lookup(f_items);
|
||||
|
||||
//debug(cerr, int(f));
|
||||
|
||||
//if ( f == 0 && gRenderer ) {
|
||||
if ( f == 0 ) {
|
||||
FeatureValue* fv = gAutoNumberFP.evaluate(f_items[0] -> name());
|
||||
if ( fv == 0 ) {
|
||||
//print(cerr);
|
||||
throw(CASTBEEXCEPT badEvaluationException());
|
||||
} else
|
||||
return fv;
|
||||
}
|
||||
|
||||
if (!f) {
|
||||
//print(cerr);
|
||||
throw(CASTBEEXCEPT badEvaluationException());
|
||||
}
|
||||
|
||||
return f->evaluate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FeatureValue *
|
||||
ConstantNode::evaluate() const
|
||||
{
|
||||
//return f_value->clone();
|
||||
return f_value->evaluate();
|
||||
}
|
||||
|
||||
extern unsigned g_validation_mode;
|
||||
|
||||
FeatureValue *
|
||||
SgmlAttributeNode::evaluate() const
|
||||
{
|
||||
if ( g_validation_mode == true ) {
|
||||
throw(CASTUAEXCEPT undefinedAttributeException(f_name));
|
||||
}
|
||||
|
||||
const Attribute *attr = gCurrentElement->get_attribute(f_name);
|
||||
|
||||
if (attr)
|
||||
return new FeatureValueString(attr->value());
|
||||
|
||||
throw(CASTUAEXCEPT undefinedAttributeException(f_name));
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
// Printing
|
||||
// ////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ostream &operator<<(ostream &o, const Expression &e)
|
||||
{
|
||||
return e.print(o);
|
||||
}
|
||||
|
||||
ostream &operator<< (ostream &o, const TermNode &t)
|
||||
{
|
||||
return t.print(o);
|
||||
}
|
||||
|
||||
ostream &
|
||||
Expression::print(ostream &o) const
|
||||
{
|
||||
return o << *f_root ;
|
||||
}
|
||||
|
||||
ostream &
|
||||
VariableNode::print(ostream &o) const
|
||||
{
|
||||
return o << f_name ;
|
||||
}
|
||||
|
||||
ostream &
|
||||
BinaryOperatorNode::print(ostream &o) const
|
||||
{
|
||||
o << "(" << *f_left << ' ';
|
||||
switch (f_operator)
|
||||
{
|
||||
case PLUS:
|
||||
o << '+' ;
|
||||
break;
|
||||
case MINUS:
|
||||
o << '-';
|
||||
break;
|
||||
case TIMES:
|
||||
o << '*' ;
|
||||
break;
|
||||
case DIVIDE:
|
||||
o << '/';
|
||||
break;
|
||||
}
|
||||
|
||||
return o << ' ' << *f_right << ')' ;
|
||||
}
|
||||
|
||||
ostream &
|
||||
SgmlAttributeNode::print(ostream &o) const
|
||||
{
|
||||
return o << '@' << f_name ;
|
||||
}
|
||||
|
||||
ostream &
|
||||
ConstantNode::print(ostream &o) const
|
||||
{
|
||||
return o << *f_value ;
|
||||
}
|
||||
|
||||
|
||||
ostream &
|
||||
CompositeVariableNode::print(ostream &o) const
|
||||
{
|
||||
int length = f_items.entries();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
o << *f_items[i] ;
|
||||
if (i < length - 1)
|
||||
o << "." ;
|
||||
}
|
||||
|
||||
return o ;
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// cloning
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TermNode *
|
||||
VariableNode::clone() const
|
||||
{
|
||||
return new VariableNode(f_name);
|
||||
}
|
||||
|
||||
TermNode *
|
||||
CompositeVariableNode::clone() const
|
||||
{
|
||||
int nitems = f_items.entries();
|
||||
CompositeVariableNode *node = new CompositeVariableNode(nitems);
|
||||
|
||||
for (int i = 0; i < nitems; i++)
|
||||
node->appendItem(*f_items(i));
|
||||
|
||||
return node ;
|
||||
}
|
||||
|
||||
TermNode *
|
||||
BinaryOperatorNode::clone() const
|
||||
{
|
||||
return new BinaryOperatorNode(f_operator, f_left->clone(), f_right->clone());
|
||||
}
|
||||
|
||||
TermNode *
|
||||
SgmlAttributeNode::clone() const
|
||||
{
|
||||
return new SgmlAttributeNode(f_name);
|
||||
}
|
||||
|
||||
TermNode *
|
||||
ConstantNode::clone() const
|
||||
{
|
||||
return new ConstantNode(f_value->clone());
|
||||
}
|
||||
|
||||
154
cde/programs/dtinfo/DtMmdb/StyleSheet/Expression.h
Normal file
154
cde/programs/dtinfo/DtMmdb/StyleSheet/Expression.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/* $XConsortium: Expression.h /main/4 1996/08/21 15:50:17 drk $ */
|
||||
#ifndef _Expression_h
|
||||
#define _Expression_h
|
||||
|
||||
/* **************************************************************
|
||||
Defines the tree for evaluating expressions given as feature values
|
||||
in the Style Sheet
|
||||
* ************************************************************** */
|
||||
|
||||
|
||||
|
||||
#include "SymTab.h"
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
typedef dlist_array<Symbol> f_items_t;
|
||||
#else
|
||||
#include "dti_cc/cc_povec.h"
|
||||
typedef dlist_array<Symbol> f_items_t;
|
||||
#endif
|
||||
|
||||
|
||||
class FeatureValue;
|
||||
class TermNode;
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// class Expression
|
||||
//
|
||||
// holds root of expression tree
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class Expression
|
||||
{
|
||||
public:
|
||||
Expression(TermNode *root);
|
||||
Expression(const Expression&);
|
||||
~Expression();
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
private:
|
||||
TermNode* f_root;
|
||||
};
|
||||
|
||||
class TermNode
|
||||
{
|
||||
public:
|
||||
virtual ~TermNode();
|
||||
virtual FeatureValue *evaluate() const = 0;
|
||||
virtual ostream &print(ostream &) const = 0;
|
||||
virtual TermNode *clone() const = 0;
|
||||
};
|
||||
|
||||
class VariableNode: public TermNode
|
||||
{
|
||||
// for single name variables eg: "DEFAULT_FONT"
|
||||
public:
|
||||
VariableNode(const Symbol& name);
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
virtual TermNode *clone() const;
|
||||
|
||||
private:
|
||||
Symbol f_name;
|
||||
|
||||
};
|
||||
|
||||
class CompositeVariableNode : public TermNode
|
||||
{
|
||||
// for feature path variables (font.size)
|
||||
// eg: font: { size: font.size }
|
||||
public:
|
||||
CompositeVariableNode();
|
||||
CompositeVariableNode(size_t capac); /* if we know how many items to expect */
|
||||
~CompositeVariableNode();
|
||||
|
||||
virtual FeatureValue *evaluate() const ;
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
virtual TermNode *clone() const;
|
||||
|
||||
void prependItem(const Symbol& item);
|
||||
void appendItem(const Symbol& item);
|
||||
|
||||
const Symbol* convertableToVariable();
|
||||
|
||||
private:
|
||||
//dlist_array<Symbol> f_items;
|
||||
f_items_t f_items;
|
||||
};
|
||||
|
||||
|
||||
class BinaryOperatorNode: public TermNode
|
||||
{
|
||||
public:
|
||||
enum operatorType { PLUS, MINUS, TIMES, DIVIDE };
|
||||
|
||||
BinaryOperatorNode(operatorType, TermNode* left, TermNode* right);
|
||||
~BinaryOperatorNode();
|
||||
|
||||
virtual TermNode *clone() const;
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
|
||||
private:
|
||||
operatorType f_operator ;
|
||||
TermNode *f_left;
|
||||
TermNode *f_right;
|
||||
|
||||
};
|
||||
|
||||
class SgmlAttributeNode: public TermNode
|
||||
{
|
||||
public:
|
||||
SgmlAttributeNode(const Symbol& name);
|
||||
SgmlAttributeNode();
|
||||
|
||||
virtual FeatureValue *evaluate() const ;
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
virtual TermNode *clone() const;
|
||||
|
||||
|
||||
private:
|
||||
Symbol f_name;
|
||||
};
|
||||
|
||||
class ConstantNode: public TermNode
|
||||
{
|
||||
public:
|
||||
ConstantNode(FeatureValue*);
|
||||
~ConstantNode();
|
||||
virtual FeatureValue *evaluate() const;
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
virtual TermNode *clone() const;
|
||||
|
||||
private:
|
||||
FeatureValue *f_value;
|
||||
|
||||
};
|
||||
|
||||
ostream &operator <<(ostream &, const Expression &);
|
||||
ostream &operator <<(ostream &, const TermNode &);
|
||||
|
||||
|
||||
#endif /* _Expression_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
68
cde/programs/dtinfo/DtMmdb/StyleSheet/Feature.C
Normal file
68
cde/programs/dtinfo/DtMmdb/StyleSheet/Feature.C
Normal file
@@ -0,0 +1,68 @@
|
||||
// $XConsortium: Feature.cc /main/3 1996/06/11 17:06:39 cde-hal $
|
||||
#include "SymTab.h"
|
||||
#include "Feature.h"
|
||||
#include "FeatureValue.h"
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
Feature::Feature(const Symbol &name, FeatureValue *value)
|
||||
: f_name(name),
|
||||
f_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Feature::Feature(const Feature &orig_feature)
|
||||
: f_name(orig_feature.name()),
|
||||
f_value(orig_feature.value()->clone())
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int Feature::operator==(const Feature &f )
|
||||
{
|
||||
return f.name() == f_name;
|
||||
}
|
||||
|
||||
Feature::~Feature()
|
||||
{
|
||||
delete f_value ;
|
||||
}
|
||||
|
||||
FeatureValue *
|
||||
Feature::evaluate() const
|
||||
{
|
||||
|
||||
return f_value->evaluate();
|
||||
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Printing
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ostream &operator << (ostream &o, const Feature &f)
|
||||
{
|
||||
return f.print(o);
|
||||
}
|
||||
|
||||
ostream &
|
||||
Feature::print(ostream &o) const
|
||||
{
|
||||
return o << f_name << ": " << *f_value ;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Feature::merge(const Feature &feature_to_merge)
|
||||
{
|
||||
assert(f_name == feature_to_merge.name());
|
||||
|
||||
if (*f_value == *feature_to_merge.value())
|
||||
;
|
||||
else
|
||||
{
|
||||
FeatureValue *new_value = f_value->merge(*feature_to_merge.value());
|
||||
delete f_value ;
|
||||
f_value = new_value ;
|
||||
}
|
||||
}
|
||||
|
||||
135
cde/programs/dtinfo/DtMmdb/StyleSheet/Feature.h
Normal file
135
cde/programs/dtinfo/DtMmdb/StyleSheet/Feature.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* $XConsortium: Feature.h /main/4 1996/08/21 15:50:21 drk $ */
|
||||
#ifndef _Feature_h
|
||||
#define _Feature_h
|
||||
|
||||
#include <stream.h>
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
|
||||
#else
|
||||
#include "dti_cc/CC_Slist.h"
|
||||
#include "dti_cc/cc_povec.h"
|
||||
#endif
|
||||
|
||||
#include "SymTab.h"
|
||||
|
||||
class Element;
|
||||
class Expression;
|
||||
class FeatureValue;
|
||||
class VariableTable;
|
||||
class ResolverStackElement ;
|
||||
class Symbol;
|
||||
|
||||
/*
|
||||
#ifndef CDE_NEXT
|
||||
class dlist_array<Symbol> ;
|
||||
#else
|
||||
class dlist_array<Symbol> ;
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
* class Feature
|
||||
|
||||
a symbol, value pairing where symbol is the feature name
|
||||
* ************************************************************** */
|
||||
|
||||
|
||||
class Feature
|
||||
{
|
||||
public:
|
||||
Feature(const Symbol &, FeatureValue *);
|
||||
Feature(const Feature &);
|
||||
~Feature();
|
||||
|
||||
|
||||
const Symbol &name() const { return f_name ; }
|
||||
const FeatureValue *value() const { return f_value ; }
|
||||
|
||||
FeatureValue *evaluate() const;
|
||||
|
||||
// destructively modifies f_value
|
||||
void merge(const Feature &);
|
||||
|
||||
ostream &print(ostream &) const ;
|
||||
|
||||
unsigned int operator==(const Feature&);
|
||||
|
||||
private:
|
||||
void assembleChainFeatures(FeatureValue* x);
|
||||
|
||||
private:
|
||||
Symbol f_name ;
|
||||
FeatureValue *f_value;
|
||||
|
||||
};
|
||||
|
||||
/* **************************************************************
|
||||
* class FeatureSet
|
||||
|
||||
FeatureSet is is a list of features and their values. Features are
|
||||
represented by symbols. Values can be strings, numbers (int or real)
|
||||
or FeatureSet
|
||||
* ************************************************************** */
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
class FeatureSet : public CC_TPtrSlist<Feature>
|
||||
#else
|
||||
class FeatureSet : public CC_TPtrSlist<Feature>
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
FeatureSet();
|
||||
FeatureSet(const FeatureSet &); /* copy */
|
||||
FeatureSet(const FeatureSet &,
|
||||
const FeatureSet &); /* merge */
|
||||
~FeatureSet();
|
||||
|
||||
void add(Feature *);
|
||||
const Feature *lookup(const Symbol *) const ;
|
||||
const Feature *lookup(const Symbol &) const;
|
||||
const Feature *lookup(const char *) const;
|
||||
|
||||
// find a chain, eg for "prefix.font.size" use */
|
||||
// deep_lookup("prefix","font","size", 0);
|
||||
// returns 0 if not found
|
||||
const Feature *deep_lookup(const char * ...) const ;
|
||||
const Feature *deep_lookup(const Symbol * ...) const ;
|
||||
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
const Feature *deep_lookup(const dlist_array<Symbol> &) const ;
|
||||
#else
|
||||
const Feature *deep_lookup(const dlist_array<Symbol> &) const ;
|
||||
#endif
|
||||
|
||||
// remve a feature that is specified by a chain
|
||||
void removeFeature(const char * ...) ;
|
||||
|
||||
// returns new feature set with all unresolved expressions resolved
|
||||
FeatureSet *evaluate() const;
|
||||
// evaluate self and place answers into result_set, returns result set
|
||||
FeatureSet *evaluate(FeatureSet *result_set) const ;
|
||||
|
||||
unsigned int operator == (const FeatureSet &) const ;
|
||||
|
||||
ostream &print(ostream &) const ;
|
||||
|
||||
private:
|
||||
|
||||
static unsigned int f_print_indent_level ;
|
||||
|
||||
};
|
||||
|
||||
/* **************************************************************
|
||||
* Printing
|
||||
* ************************************************************** */
|
||||
|
||||
ostream &operator << (ostream &o, const Feature &f);
|
||||
ostream &operator << (ostream &o, const FeatureSet &f);
|
||||
|
||||
|
||||
#endif /* _Feature_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
566
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureDefDictionary.C
Normal file
566
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureDefDictionary.C
Normal file
@@ -0,0 +1,566 @@
|
||||
// $TOG: FeatureDefDictionary.C /main/4 1998/04/17 11:48:58 mgreess $
|
||||
|
||||
|
||||
#include "StyleSheet/FeatureDefDictionary.h"
|
||||
#include "StyleSheet/Debug.h"
|
||||
#include "StyleSheet/StyleSheetExceptions.h"
|
||||
#include "utility/const.h"
|
||||
#include "utility/funcs.h"
|
||||
#include <iostream.h>
|
||||
|
||||
featureDefDictionary* g_FeatureDefDictionary = 0;
|
||||
|
||||
extern void report_error_location();
|
||||
|
||||
extern def_list_t* g_def_list;
|
||||
extern FILE *defParserin;
|
||||
extern int defParserparse();
|
||||
istream* g_defParserin = 0;
|
||||
|
||||
unsigned g_validation_mode = false;
|
||||
unsigned g_hasSemanticError = false;
|
||||
|
||||
|
||||
ostream& out_tabs(ostream& out, int tabs)
|
||||
{
|
||||
for (int i=0; i<tabs; i++)
|
||||
out << "\t";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
TypeValues::TypeValues(char* t, defv_t* dv) :
|
||||
f_type(t), f_default_values(dv)
|
||||
{
|
||||
}
|
||||
|
||||
TypeValues::~TypeValues()
|
||||
{
|
||||
if ( f_default_values ) {
|
||||
f_default_values -> clearAndDestroy();
|
||||
delete f_default_values;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int TypeValues::operator==(const TypeValues& def)
|
||||
{
|
||||
return !f_type.compareTo(def.f_type, CC_String::ignoreCase);
|
||||
}
|
||||
|
||||
ostream& operator <<(ostream& out, TypeValues& tvs)
|
||||
{
|
||||
return tvs.print(out, 0);
|
||||
}
|
||||
|
||||
unsigned TypeValues::check(const FeatureValue* fv)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "TypeValues::check()");
|
||||
debug(cerr, fv -> type());
|
||||
*/
|
||||
|
||||
// type check
|
||||
switch ( fv -> type() ) {
|
||||
case FeatureValue::real:
|
||||
case FeatureValue::integer:
|
||||
//debug(cerr, f_type.data());
|
||||
if ( strcasecmp(f_type.data(), "REAL") == 0 ||
|
||||
strcasecmp(f_type.data(), "INTEGER") == 0
|
||||
)
|
||||
break;
|
||||
else
|
||||
return false;
|
||||
|
||||
case FeatureValue::string:
|
||||
//debug(cerr, f_type.data());
|
||||
if ( strcasecmp(f_type.data(), "STRING") == 0 ||
|
||||
strcasecmp(f_type.data(), "STRING_PREFIX") == 0
|
||||
)
|
||||
break;
|
||||
else
|
||||
return false;
|
||||
|
||||
case FeatureValue::symbol:
|
||||
case FeatureValue::expression:
|
||||
case FeatureValue::featureset:
|
||||
return false;
|
||||
|
||||
//debug(cerr, f_type.data());
|
||||
case FeatureValue::dimension:
|
||||
if ( strcasecmp(f_type.data(), "DIMENSION") == 0 ||
|
||||
strcasecmp(f_type.data(), "DIMENSION_PIXEL") == 0
|
||||
)
|
||||
break;
|
||||
else
|
||||
return false;
|
||||
|
||||
case FeatureValue::array:
|
||||
//debug(cerr, f_type.data());
|
||||
if ( strcasecmp(f_type.data(), "ARRAY") == 0 )
|
||||
break;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// value check
|
||||
if ( f_default_values == 0 ) {
|
||||
//MESSAGE(cerr, "check() Passed");
|
||||
return true;
|
||||
}
|
||||
|
||||
defv_iterator_t next(*f_default_values);
|
||||
const char* x, *y;
|
||||
|
||||
while (++next) {
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// trap string type as FeatureValueString::operator==() uses
|
||||
// case sensitive comparsion
|
||||
/////////////////////////////////////////////////////////////
|
||||
if ( fv -> type() == FeatureValue::string &&
|
||||
next.key() -> type() == FeatureValue::string )
|
||||
{
|
||||
x = *((FeatureValueString*)next.key());
|
||||
y = *(FeatureValueString*)fv;
|
||||
|
||||
//debug(cerr, x);
|
||||
//debug(cerr, y);
|
||||
|
||||
if ( strcasecmp(f_type.data(), "STRING_PREFIX") == 0 ) {
|
||||
if ( strncasecmp(x, y, strlen(x)) == 0 )
|
||||
return true;
|
||||
} else {
|
||||
if ( strcasecmp(x, y) == 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
} else
|
||||
|
||||
if ( next.key() -> operator==(*fv) == true ) {
|
||||
//MESSAGE(cerr, "check() Passed");
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ostream& TypeValues::print(ostream& out, int tabs) const
|
||||
{
|
||||
out_tabs(out, tabs) << f_type << "\n";
|
||||
|
||||
if ( f_default_values ) {
|
||||
defv_iterator_t NextValue (*f_default_values);
|
||||
while (++NextValue) {
|
||||
out_tabs(out, tabs+1) << *(NextValue.key()) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
unsigned hash(const FeatureDef& key)
|
||||
{
|
||||
return key.name() -> hash();
|
||||
}
|
||||
|
||||
FeatureDef::FeatureDef(const char* name) : f_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
FeatureDef::~FeatureDef()
|
||||
{
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& out, FeatureDef& def)
|
||||
{
|
||||
return def.print(out, 0);
|
||||
}
|
||||
|
||||
unsigned int FeatureDef::operator==(const FeatureDef& def)
|
||||
{
|
||||
//debug(cerr, f_name);
|
||||
//debug(cerr, def.f_name);
|
||||
// unsigned ok = ! f_name.compareTo(def.f_name, CC_String::ignoreCase);
|
||||
//debug(cerr, ok);
|
||||
//return ok;
|
||||
|
||||
return !f_name.compareTo(def.f_name, CC_String::ignoreCase);
|
||||
}
|
||||
|
||||
FeatureDefComposite::FeatureDefComposite(const char* name, def_list_t* dl) :
|
||||
FeatureDef(name), f_components(dl)
|
||||
{
|
||||
}
|
||||
|
||||
FeatureDefComposite::~FeatureDefComposite()
|
||||
{
|
||||
if ( f_components ) {
|
||||
f_components -> clearAndDestroy();
|
||||
delete f_components;
|
||||
}
|
||||
}
|
||||
|
||||
CC_Boolean compareFunc(FeatureDef* fd, void* nm)
|
||||
{
|
||||
if ( strcasecmp( fd -> name() -> data(), (char*)nm ) == 0 )
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// return true:
|
||||
// fv confirms to the spec of a component of this def.
|
||||
// return false:
|
||||
// otherwise
|
||||
unsigned FeatureDefComposite::checkContent(const Feature* fv) const
|
||||
{
|
||||
/*
|
||||
const FeatureDef* def = getComponentDef((fv->name()).name());
|
||||
|
||||
if ( def == 0 )
|
||||
return false;
|
||||
|
||||
if ( def -> type() != FeatureDef::PRIMITIVE )
|
||||
return false;
|
||||
|
||||
return ((FeatureDefPrimitive*)def) -> checkContent(fv);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
const FeatureDef* FeatureDefComposite::getComponentDef(const char* nm) const
|
||||
{
|
||||
if ( f_components == 0 )
|
||||
return 0;
|
||||
else {
|
||||
FeatureDef* def = f_components -> find(compareFunc, (void*)nm);
|
||||
|
||||
if ( def )
|
||||
return def;
|
||||
else {
|
||||
if ( f_components -> first() -> type() == WILDCARD )
|
||||
return f_components -> first();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
//return f_components -> find(compareFunc, "*");
|
||||
}
|
||||
}
|
||||
|
||||
ostream& FeatureDefComposite::print(ostream& out, int tabs) const
|
||||
{
|
||||
out_tabs(out, tabs) << f_name << "\n";
|
||||
|
||||
if ( f_components ) {
|
||||
def_list_iterator_t NextComponent(*f_components);
|
||||
while (++NextComponent) {
|
||||
NextComponent.key() -> print(out, tabs+1) << "\n";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
FeatureDefPrimitive::FeatureDefPrimitive(const char* name, type_values_list_t* tvl) :
|
||||
FeatureDef(name), f_typeValuesList(tvl)
|
||||
{
|
||||
}
|
||||
|
||||
FeatureDefPrimitive::~FeatureDefPrimitive()
|
||||
{
|
||||
if ( f_typeValuesList ) {
|
||||
f_typeValuesList -> clearAndDestroy();
|
||||
delete f_typeValuesList;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned FeatureDefPrimitive::checkContent(const Feature* f) const
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "FeatureDefPrimitive::checkContent");
|
||||
f -> print(cerr);
|
||||
MESSAGE(cerr, "");
|
||||
debug(cerr, *(this -> name()));
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
if ( f_typeValuesList == 0 ) {
|
||||
report_error_location();
|
||||
cerr << "No type definition.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
FeatureValue * fv = 0;
|
||||
try {
|
||||
fv = f -> evaluate();
|
||||
}
|
||||
catch (undefinedAttributeException&, e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (undefinedVariableException&, e) {
|
||||
report_error_location();
|
||||
cerr << "Undefined variable error.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
catch (badCastException&, e) {
|
||||
report_error_location();
|
||||
cerr << "Evaluating expression error.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
catch (badEvaluationException&, e) {
|
||||
report_error_location();
|
||||
cerr << "Evaluating expression error.\n";
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
catch_any() {
|
||||
//report_error_location();
|
||||
//cerr << "There might be an error in the expression.\n";
|
||||
return true;
|
||||
}
|
||||
end_try;
|
||||
|
||||
/*
|
||||
debug(cerr, int(fv));
|
||||
fv -> print(cerr);
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
if ( fv == 0 ) {
|
||||
report_error_location();
|
||||
cerr << "Error in evaluating an expression.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
type_values_list_iterator_t next(*f_typeValuesList);
|
||||
|
||||
while ( ++ next ) {
|
||||
if ( next.key() -> check(fv) == true ) {
|
||||
delete fv;
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
delete fv;
|
||||
report_error_location();
|
||||
cerr << form("Unmatched feature type or illegal feature value: %s.\n",
|
||||
(f -> name()).name()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
ostream& FeatureDefPrimitive::print(ostream& out, int tabs) const
|
||||
{
|
||||
out_tabs(out, tabs) << f_name << "\n";
|
||||
|
||||
if ( f_typeValuesList ) {
|
||||
type_values_list_iterator_t NextValue (*f_typeValuesList);
|
||||
while (++NextValue) {
|
||||
NextValue.key() -> print(out, tabs+1) << "\n";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
unsigned FeatureDefReference::checkContent(const Feature* fv) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ostream& FeatureDefReference::print(ostream& out, int tabs) const
|
||||
{
|
||||
out_tabs(out, tabs) << f_name << "\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
unsigned FeatureDefWildCard::checkContent(const Feature* fv) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ostream& FeatureDefWildCard::print(ostream& out, int tabs) const
|
||||
{
|
||||
out_tabs(out, tabs) << f_name << "\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
featureDefDictionary::featureDefDictionary() : f_def_list(0)
|
||||
{
|
||||
}
|
||||
|
||||
featureDefDictionary::~featureDefDictionary()
|
||||
{
|
||||
if ( f_def_list ) {
|
||||
f_def_list -> clearAndDestroy();
|
||||
delete f_def_list;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
featureDefDictionary::addFeatureDefs(def_list_t* fdefs)
|
||||
{
|
||||
f_def_list = fdefs;
|
||||
|
||||
if ( f_def_list == 0 )
|
||||
throw(CASTEXCEPT Exception());
|
||||
}
|
||||
|
||||
const FeatureDef*
|
||||
featureDefDictionary::getDef(const char* nm)
|
||||
{
|
||||
//debug(cerr, nm);
|
||||
|
||||
FeatureDefReference key((char*)nm);
|
||||
return f_def_list -> find(&key);
|
||||
|
||||
/*
|
||||
FeatureDef* def = 0;
|
||||
def = f_def_list -> find(&key);
|
||||
|
||||
debug(cerr, int(def));
|
||||
return def;
|
||||
*/
|
||||
}
|
||||
|
||||
const FeatureDef*
|
||||
featureDefDictionary::getDef(const Feature* f)
|
||||
{
|
||||
return getDef((f -> name()).name());
|
||||
}
|
||||
|
||||
unsigned
|
||||
featureDefDictionary::checkSemantics(const FeatureSet* fs)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "check feature set:");
|
||||
fs -> print(cerr);
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
const FeatureDef* def = 0;
|
||||
const Feature *f = 0;
|
||||
|
||||
CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*)fs);
|
||||
while (++next) {
|
||||
f = next.key();
|
||||
def = getDef(f);
|
||||
|
||||
if ( def == 0 ) {
|
||||
report_error_location();
|
||||
cerr << form("Unknown feature name %s.\n",
|
||||
((next.key()) -> name()).name());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( _checkSemantics(f, def) == false )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned
|
||||
featureDefDictionary::_checkSemantics(const Feature* f, const FeatureDef* def)
|
||||
{
|
||||
const FeatureSet *featureset = 0;
|
||||
const Feature *child_f= 0;
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "_checkSemantics");
|
||||
f -> print(cerr);
|
||||
MESSAGE(cerr, "");
|
||||
def -> print(cerr, 0);
|
||||
MESSAGE(cerr, "");
|
||||
*/
|
||||
|
||||
|
||||
const FeatureDef* child_def = 0;
|
||||
|
||||
if ( def -> checkContent(f) == false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f -> value()->type() == FeatureValue::featureset &&
|
||||
def -> type() == FeatureDef::COMPOSITE )
|
||||
{
|
||||
//MESSAGE(cerr, "it is a feature set");
|
||||
|
||||
|
||||
featureset =
|
||||
((const FeatureValueFeatureSet *)(f -> value()))->value();
|
||||
|
||||
CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*)featureset);
|
||||
|
||||
const char* nm;
|
||||
|
||||
while ( ++ next ) {
|
||||
|
||||
nm = ((next.key()) -> name()).name();
|
||||
|
||||
/*
|
||||
debug(cerr, nm);
|
||||
report_error_location();
|
||||
*/
|
||||
|
||||
child_def = ((FeatureDefComposite*)def) -> getComponentDef(nm);
|
||||
|
||||
//debug(cerr, int(child_def));
|
||||
if ( child_def == 0 ) {
|
||||
report_error_location();
|
||||
cerr << form("%s is a undefined feature.\n", nm);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ( child_def -> type() ) {
|
||||
case FeatureDef::REFERENCE:
|
||||
child_def = getDef(child_def -> name() -> data());
|
||||
break;
|
||||
case FeatureDef::WILDCARD:
|
||||
child_def = getDef(nm);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
child_f = next.key();
|
||||
|
||||
if ( _checkSemantics(child_f, child_def) == false )
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
istream& operator >>(istream& in, featureDefDictionary& dict)
|
||||
{
|
||||
g_defParserin = ∈
|
||||
|
||||
int ok = defParserparse();
|
||||
if ( ok != 0 ) {
|
||||
MESSAGE(cerr, "bad feature definition file");
|
||||
throw(CASTEXCEPT Exception());
|
||||
}
|
||||
|
||||
dict.addFeatureDefs(g_def_list);
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
ostream& operator <<(ostream& out, featureDefDictionary& dict)
|
||||
{
|
||||
def_list_iterator_t Next(*dict.f_def_list);
|
||||
|
||||
while (++Next) {
|
||||
//debug(cerr, int(Next.key()));
|
||||
out << *Next.key() << "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
193
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureDefDictionary.h
Normal file
193
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureDefDictionary.h
Normal file
@@ -0,0 +1,193 @@
|
||||
/* $XConsortium: FeatureDefDictionary.h /main/4 1996/08/21 15:50:25 drk $ */
|
||||
|
||||
#ifndef _featureNameDictionary_h
|
||||
#define _featureNameDictionary_h
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
|
||||
|
||||
#else
|
||||
//#include "StyleSheet/cde_next.h"
|
||||
#include "dti_cc/CC_Slist.h"
|
||||
#include "dti_cc/cc_hdict.h"
|
||||
#include "dti_cc/CC_String.h"
|
||||
#endif
|
||||
|
||||
#include "StyleSheet/Types.h"
|
||||
#include "StyleSheet/SymTab.h"
|
||||
#include "StyleSheet/FeatureValue.h"
|
||||
#include "StyleSheet/Feature.h"
|
||||
#include "StyleSheet/StyleSheetExceptions.h"
|
||||
|
||||
typedef CC_TPtrSlist<FeatureValue> defv_t;
|
||||
typedef CC_TPtrSlistIterator<FeatureValue> defv_iterator_t;
|
||||
|
||||
class TypeValues : public Destructable
|
||||
{
|
||||
public:
|
||||
|
||||
enum feature_t {real, integer, string, featureset, unit} ;
|
||||
enum unit_t { INCH=0, PICA=1, POINT=2, CM=3, PIXEL=4, NONE=5 };
|
||||
|
||||
TypeValues(char* type, defv_t*);
|
||||
~TypeValues();
|
||||
|
||||
unsigned int operator==(const TypeValues&);
|
||||
|
||||
unsigned check(const FeatureValue*);
|
||||
|
||||
friend ostream& operator <<(ostream&, TypeValues&);
|
||||
ostream& print(ostream&, int tabs) const;
|
||||
|
||||
protected:
|
||||
CC_String f_type;
|
||||
defv_t* f_default_values;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
class FeatureDef;
|
||||
|
||||
typedef CC_TPtrSlist<FeatureDef> def_list_t;
|
||||
typedef CC_TPtrSlistIterator<FeatureDef> def_list_iterator_t;
|
||||
|
||||
typedef CC_TPtrSlist<TypeValues> type_values_list_t;
|
||||
typedef CC_TPtrSlistIterator<TypeValues> type_values_list_iterator_t;
|
||||
|
||||
|
||||
class FeatureDef : public Destructable
|
||||
{
|
||||
public:
|
||||
|
||||
FeatureDef(const char* name);
|
||||
virtual ~FeatureDef();
|
||||
|
||||
unsigned int operator==(const FeatureDef&);
|
||||
|
||||
friend ostream& operator <<(ostream&, FeatureDef&) ;
|
||||
|
||||
enum def_type_t { PRIMITIVE, COMPOSITE, REFERENCE, WILDCARD };
|
||||
virtual unsigned type() const = 0;
|
||||
virtual const CC_String* name() const { return &f_name; };
|
||||
|
||||
virtual ostream& print(ostream&, int tabs) const= 0;
|
||||
virtual unsigned checkContent(const Feature*) const = 0;
|
||||
|
||||
protected:
|
||||
CC_String f_name;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
class FeatureDefComposite : public FeatureDef
|
||||
{
|
||||
public:
|
||||
FeatureDefComposite(const char* name, def_list_t*);
|
||||
~FeatureDefComposite();
|
||||
|
||||
unsigned checkContent(const Feature*)const ;
|
||||
|
||||
const FeatureDef* getComponentDef(const char*) const;
|
||||
|
||||
unsigned type() const { return COMPOSITE; };
|
||||
|
||||
protected:
|
||||
def_list_t* f_components;
|
||||
|
||||
protected:
|
||||
virtual ostream& print(ostream&, int tabs) const;
|
||||
}
|
||||
;
|
||||
|
||||
class FeatureDefPrimitive: public FeatureDef
|
||||
{
|
||||
public:
|
||||
FeatureDefPrimitive(const char* name, type_values_list_t* tvslist);
|
||||
~FeatureDefPrimitive();
|
||||
|
||||
unsigned type() const { return PRIMITIVE; };
|
||||
|
||||
unsigned checkContent(const Feature*)const ;
|
||||
|
||||
protected:
|
||||
type_values_list_t* f_typeValuesList;
|
||||
|
||||
protected:
|
||||
virtual ostream& print(ostream&, int tabs) const;
|
||||
}
|
||||
;
|
||||
|
||||
class FeatureDefReference : public FeatureDef
|
||||
{
|
||||
public:
|
||||
FeatureDefReference(const char* name) : FeatureDef(name) {};
|
||||
~FeatureDefReference() {};
|
||||
|
||||
unsigned type() const { return REFERENCE; };
|
||||
unsigned checkContent(const Feature*)const ;
|
||||
|
||||
protected:
|
||||
|
||||
protected:
|
||||
virtual ostream& print(ostream&, int tabs) const;
|
||||
}
|
||||
;
|
||||
|
||||
class FeatureDefWildCard : public FeatureDef
|
||||
{
|
||||
public:
|
||||
FeatureDefWildCard(const char* name) : FeatureDef(name) {};
|
||||
~FeatureDefWildCard() {};
|
||||
|
||||
unsigned type() const { return WILDCARD; };
|
||||
unsigned checkContent(const Feature*)const ;
|
||||
|
||||
protected:
|
||||
|
||||
protected:
|
||||
virtual ostream& print(ostream&, int tabs) const;
|
||||
}
|
||||
;
|
||||
|
||||
//typedef hashTable<FeatureDef, FeatureDef> featureDefDictionary_t;
|
||||
//typedef hashTableIterator<FeatureDef, FeatureDef> featureDefDictionary_iterator_t;
|
||||
|
||||
class featureDefDictionary : public Destructable
|
||||
{
|
||||
protected:
|
||||
def_list_t* f_def_list;
|
||||
|
||||
protected:
|
||||
const FeatureDef* getDef(const char*);
|
||||
const FeatureDef* getDef(const Feature*);
|
||||
//const FeatureDef* getDef(const Feature*, const Feature*);
|
||||
unsigned _checkSemantics(const Feature* f, const FeatureDef*);
|
||||
|
||||
public:
|
||||
featureDefDictionary();
|
||||
~featureDefDictionary();
|
||||
|
||||
void addFeatureDefs(def_list_t*);
|
||||
|
||||
unsigned checkSemantics(const FeatureSet*);
|
||||
|
||||
//format:
|
||||
//
|
||||
// featureName
|
||||
// ComponentName : Type [: Default Values (',' separated)]
|
||||
// ComponentName : Type [: Default Values (',' separated)]
|
||||
// featureName
|
||||
// ComponentName : Type [: Default Values (',' separated)]
|
||||
// ComponentName : Type [: Default Values (',' separated)]
|
||||
//
|
||||
// Example:
|
||||
// font
|
||||
// size : Unit
|
||||
// weight : String : "medium", "bold"
|
||||
//
|
||||
friend istream& operator >>(istream&, featureDefDictionary&);
|
||||
friend ostream& operator <<(ostream&, featureDefDictionary&);
|
||||
};
|
||||
|
||||
#endif
|
||||
326
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureSet.C
Normal file
326
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureSet.C
Normal file
@@ -0,0 +1,326 @@
|
||||
// $XConsortium: FeatureSet.cc /main/5 1996/08/05 16:18:55 cde-hal $
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include "Feature.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "Debug.h"
|
||||
|
||||
unsigned int FeatureSet::f_print_indent_level = 0 ;
|
||||
|
||||
ostream &operator << (ostream &o, const FeatureSet &f)
|
||||
{
|
||||
return f.print(o);
|
||||
}
|
||||
|
||||
FeatureSet::~FeatureSet()
|
||||
{
|
||||
clearAndDestroy(); // clean up memory
|
||||
}
|
||||
|
||||
FeatureSet::FeatureSet()
|
||||
{
|
||||
}
|
||||
|
||||
FeatureSet::FeatureSet(const FeatureSet &orig_set)
|
||||
{
|
||||
// cast to non const
|
||||
CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*) &orig_set) ;
|
||||
|
||||
// make a copy of each item and add it to our list
|
||||
while (++next)
|
||||
append(new Feature(*next.key()));
|
||||
|
||||
}
|
||||
|
||||
FeatureSet *
|
||||
FeatureSet::evaluate() const
|
||||
{
|
||||
// I do not yet understand how this evaluate is working well. - TK
|
||||
#ifdef FS_EVAL_DEBUG
|
||||
fprintf(stderr, "(DEBUG) FeatureSet::evaluate() called.\n");
|
||||
#endif
|
||||
return evaluate(new FeatureSet);
|
||||
}
|
||||
|
||||
FeatureSet *
|
||||
FeatureSet::evaluate(FeatureSet *result_set) const
|
||||
{
|
||||
|
||||
CC_TPtrSlistIterator<Feature> next(*(FeatureSet*)this);
|
||||
|
||||
// cause each feature to evaluate itself
|
||||
while(++next)
|
||||
{
|
||||
FeatureValue *value ;
|
||||
try
|
||||
{
|
||||
value = next.key()->evaluate();
|
||||
result_set->append(new Feature(next.key()->name(),
|
||||
value));
|
||||
}
|
||||
#ifdef UXPDS
|
||||
catch_any()
|
||||
#else
|
||||
catch_noarg(badEvaluationException)
|
||||
#endif
|
||||
{
|
||||
/* do nothing...we just ignore any that will not evaluate */
|
||||
}
|
||||
end_try;
|
||||
}
|
||||
|
||||
return result_set ;
|
||||
}
|
||||
|
||||
FeatureSet::FeatureSet(const FeatureSet &base,
|
||||
const FeatureSet &mixin)
|
||||
{
|
||||
Feature dummy = Feature(gSymTab->intern("FAMILY"),0);
|
||||
int contains_family = mixin.contains(&dummy);
|
||||
|
||||
// first duplicate the baseline
|
||||
CC_TPtrSlistIterator<Feature> base_i(*(CC_TPtrSlist<Feature>*)&base) ;
|
||||
|
||||
// make a copy of each item and add it to our list
|
||||
while (++base_i) {
|
||||
if (! (contains_family &&
|
||||
base_i.key()->name() == gSymTab->intern("FAMILY")))
|
||||
append(new Feature(*base_i.key()));
|
||||
}
|
||||
|
||||
// now merge in mixin
|
||||
|
||||
CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*)&mixin);
|
||||
|
||||
while (++next)
|
||||
{
|
||||
if (next.key()->name() == gSymTab->intern("FAMILY"))
|
||||
append(new Feature(*next.key()));
|
||||
else {
|
||||
Feature* mfeature = 0;
|
||||
mfeature = find(next.key());
|
||||
#if 0
|
||||
cout << "Merging: \n" << *next.key() << endl << "into:" << endl;
|
||||
if (mfeature)
|
||||
cout << *mfeature << endl;
|
||||
else
|
||||
cout << "(nil)" << endl;
|
||||
#endif
|
||||
if (mfeature)
|
||||
mfeature->merge(*next.key()); // merge it if already exists
|
||||
else
|
||||
append(new Feature(*next.key())); // else add it if not there
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ostream &
|
||||
FeatureSet::print(ostream &o) const
|
||||
{
|
||||
// cast to non-const to get iterator
|
||||
CC_TPtrSlistIterator<Feature> next(*(CC_TPtrSlist<Feature>*)this);
|
||||
|
||||
for (int i = 0 ; i < f_print_indent_level; i++)
|
||||
o << " " ;
|
||||
|
||||
o << "{" << endl;
|
||||
|
||||
f_print_indent_level++;
|
||||
|
||||
while (++next)
|
||||
{
|
||||
for (int i = 0 ; i < f_print_indent_level; i++)
|
||||
o << " " ;
|
||||
o << *next.key() << endl ;
|
||||
}
|
||||
|
||||
--f_print_indent_level;
|
||||
for (i = 0 ; i < f_print_indent_level ; i++)
|
||||
o << " " ;
|
||||
|
||||
o << "}" << endl;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
void
|
||||
FeatureSet::add(Feature *f)
|
||||
{
|
||||
append(f);
|
||||
}
|
||||
|
||||
|
||||
unsigned int
|
||||
FeatureSet::operator==(const FeatureSet &fs) const
|
||||
{
|
||||
return &fs == this ;
|
||||
}
|
||||
|
||||
const Feature*
|
||||
FeatureSet::lookup(const Symbol *symbol) const
|
||||
{
|
||||
return lookup(*symbol);
|
||||
}
|
||||
|
||||
const Feature *
|
||||
FeatureSet::lookup(const Symbol &name) const
|
||||
{
|
||||
Feature tmp(name, 0);
|
||||
return find(&tmp);
|
||||
}
|
||||
|
||||
|
||||
const Feature *
|
||||
FeatureSet::lookup(const char *name) const
|
||||
{
|
||||
Feature tmp(gSymTab->intern(name),0);
|
||||
return find(&tmp);
|
||||
}
|
||||
|
||||
const Feature *
|
||||
FeatureSet::deep_lookup(const char *first_name ...) const
|
||||
{
|
||||
const Feature *feature = lookup(first_name);
|
||||
|
||||
if (!feature)
|
||||
return 0;
|
||||
|
||||
const FeatureSet *featureset = 0;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, first_name);
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const char *p = va_arg(ap, char*);
|
||||
if (p == 0)
|
||||
break;
|
||||
|
||||
if (feature->value()->type() != FeatureValue::featureset)
|
||||
{
|
||||
va_end(ap);
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
featureset = ((const FeatureValueFeatureSet *)feature->value())->value();
|
||||
|
||||
feature = featureset->lookup(p);
|
||||
|
||||
if (!feature)
|
||||
{
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
return feature ;
|
||||
}
|
||||
|
||||
const Feature *
|
||||
FeatureSet::deep_lookup(const Symbol *first_name ...) const
|
||||
{
|
||||
const Feature *feature = lookup(*first_name);
|
||||
|
||||
if (!feature)
|
||||
return 0;
|
||||
|
||||
const FeatureSet *featureset = 0;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, first_name);
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const Symbol *sym = va_arg(ap, const Symbol *);
|
||||
if (sym == 0)
|
||||
break;
|
||||
|
||||
if (feature->value()->type() != FeatureValue::featureset)
|
||||
{
|
||||
va_end(ap);
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
featureset = ((const FeatureValueFeatureSet *)feature->value())->value();
|
||||
|
||||
feature = featureset->lookup(*sym);
|
||||
|
||||
if (!feature)
|
||||
{
|
||||
va_end(ap);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
return feature ;
|
||||
}
|
||||
|
||||
const Feature *
|
||||
FeatureSet::deep_lookup(const dlist_array<Symbol> &vec) const
|
||||
{
|
||||
unsigned int index = 0;
|
||||
const Feature *feature = lookup(*vec[index++]);
|
||||
if (!feature)
|
||||
return 0;
|
||||
|
||||
const FeatureSet *set = 0;
|
||||
|
||||
unsigned int entries = vec.entries();
|
||||
for (; index < entries ; index++ )
|
||||
{
|
||||
if (feature->value()->type() != FeatureValue::featureset)
|
||||
return 0 ;
|
||||
|
||||
set = ((const FeatureValueFeatureSet *)feature->value())->value();
|
||||
feature = set->lookup(*vec[index++]);
|
||||
if (!feature)
|
||||
return 0 ;
|
||||
}
|
||||
return feature ;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FeatureSet::removeFeature(const char *first_name ...)
|
||||
{
|
||||
const Feature *feature = lookup(first_name);
|
||||
|
||||
if (!feature)
|
||||
return ;
|
||||
|
||||
FeatureSet *featureset = this;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, first_name);
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const char *p = va_arg(ap, char*);
|
||||
if (p == 0)
|
||||
break;
|
||||
|
||||
if (feature->value()->type() != FeatureValue::featureset)
|
||||
{
|
||||
va_end(ap);
|
||||
return ;
|
||||
}
|
||||
|
||||
featureset = (FeatureSet*)
|
||||
(((const FeatureValueFeatureSet *)feature->value())->value());
|
||||
|
||||
feature = featureset->lookup(p);
|
||||
|
||||
if (!feature)
|
||||
{
|
||||
va_end(ap);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
delete (featureset -> remove((Feature *)feature));
|
||||
}
|
||||
2386
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureValue.C
Normal file
2386
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureValue.C
Normal file
File diff suppressed because it is too large
Load Diff
634
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureValue.h
Normal file
634
cde/programs/dtinfo/DtMmdb/StyleSheet/FeatureValue.h
Normal file
@@ -0,0 +1,634 @@
|
||||
/* $XConsortium: FeatureValue.h /main/5 1996/08/21 15:50:29 drk $ */
|
||||
#ifndef _FeatureValue_h
|
||||
#define _FeatureValue_h
|
||||
|
||||
//#include "Feature.h"
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
#else
|
||||
#include "dti_cc/cc_pvect.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if 0
|
||||
// SWM -- COMMENT THIS OUT -- MMDB utility/funcs.h defines this
|
||||
#ifdef _IBMR2
|
||||
extern "C" int strcasecmp(const char*, const char*);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class FeatureValue;
|
||||
class FeatureSet;
|
||||
class Expression;
|
||||
|
||||
ostream &operator << (ostream &, const FeatureValue &);
|
||||
|
||||
/* **************************************************************
|
||||
* class FeatureValue
|
||||
* ************************************************************** */
|
||||
|
||||
class FeatureValueDimension;
|
||||
class FeatureValueExpression;
|
||||
class FeatureValueFeatureSet;
|
||||
class FeatureValueInt;
|
||||
class FeatureValueReal;
|
||||
class FeatureValueString;
|
||||
class FeatureValueSymbol;
|
||||
class FeatureValueArray;
|
||||
|
||||
class FeatureValue
|
||||
{
|
||||
public:
|
||||
enum FeatureType { real, integer, string, symbol, expression, featureset, dimension, array } ;
|
||||
enum Unit { INCH=0, PICA=1, POINT=2, CM=3, PIXEL=4, NONE=5 };
|
||||
|
||||
FeatureValue (FeatureType type) : f_type(type) {}
|
||||
virtual ~FeatureValue();
|
||||
|
||||
const FeatureType type() const { return f_type ; }
|
||||
|
||||
virtual FeatureValue *clone() const = 0; /* deep copy */
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
|
||||
virtual unsigned int operator==(const FeatureValue &) const;
|
||||
virtual unsigned int operator==(const FeatureValueInt &) const;
|
||||
virtual unsigned int operator==(const FeatureValueString &) const;
|
||||
virtual unsigned int operator==(const FeatureValueReal &) const;
|
||||
virtual unsigned int operator==(const FeatureValueSymbol &) const;
|
||||
|
||||
// produce a new object which is a merge with this object and the parameter
|
||||
virtual FeatureValue *merge(const FeatureValue &);
|
||||
|
||||
// these should return a FeatureValue of the appropriate type
|
||||
// the operations are resolved vi double dispatching
|
||||
// all non-numeric types will use zero for their value unless they
|
||||
// are the denominator in a division operation, then they will use a
|
||||
// value of 1
|
||||
virtual FeatureValue *operator+(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValue&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueInt&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueReal&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
|
||||
virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
|
||||
virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
|
||||
virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
|
||||
|
||||
virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
|
||||
virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
|
||||
virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
|
||||
virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValue &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValue &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueInt &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueReal &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const int) const ;
|
||||
virtual FeatureValue *rsub(const int) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const float) const ;
|
||||
virtual FeatureValue *rsub(const float) const ;
|
||||
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
virtual operator const FeatureSet * () const ;
|
||||
|
||||
virtual ostream &print(ostream&) const = 0;
|
||||
|
||||
|
||||
virtual FeatureValue *doConvert(Unit) const ;
|
||||
virtual FeatureValue *convertTo(Unit) const ;
|
||||
virtual FeatureValue *convertTo(Unit from,
|
||||
Unit to) const ;
|
||||
|
||||
|
||||
private:
|
||||
FeatureType f_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FeatureValueReal : public FeatureValue
|
||||
{
|
||||
public:
|
||||
FeatureValueReal(float value)
|
||||
: FeatureValue(real), f_value(value)
|
||||
{}
|
||||
|
||||
FeatureValueReal(const FeatureValueReal &);
|
||||
|
||||
virtual FeatureValue *clone() const; /* deep copy */
|
||||
|
||||
// operators
|
||||
virtual unsigned int operator==(const FeatureValue &) const;
|
||||
virtual unsigned int operator==(const FeatureValueInt &) const;
|
||||
virtual unsigned int operator==(const FeatureValueString &) const;
|
||||
virtual unsigned int operator==(const FeatureValueReal &) const;
|
||||
virtual unsigned int operator==(const FeatureValueSymbol &) const;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueInt&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueReal&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValue&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
|
||||
virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
|
||||
virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
|
||||
virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
|
||||
|
||||
virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
|
||||
virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
|
||||
virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
|
||||
virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValue &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValue &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueInt &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueReal &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const int) const ;
|
||||
virtual FeatureValue *rsub(const int) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const float) const ;
|
||||
virtual FeatureValue *rsub(const float) const ;
|
||||
virtual FeatureValue *convertTo(Unit) const ;
|
||||
virtual FeatureValue *convertTo(Unit from,
|
||||
Unit to) const ;
|
||||
virtual FeatureValue *doConvert(Unit) const ;
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
private:
|
||||
float f_value ;
|
||||
|
||||
};
|
||||
|
||||
class FeatureValueInt : public FeatureValue
|
||||
{
|
||||
public:
|
||||
FeatureValueInt(int value)
|
||||
: FeatureValue(integer), f_value(value)
|
||||
{}
|
||||
|
||||
FeatureValueInt(const FeatureValueInt &);
|
||||
|
||||
virtual FeatureValue *clone() const; /* deep copy */
|
||||
|
||||
// operators
|
||||
|
||||
virtual unsigned int operator==(const FeatureValue &) const;
|
||||
virtual unsigned int operator==(const FeatureValueInt &) const;
|
||||
virtual unsigned int operator==(const FeatureValueString &) const;
|
||||
virtual unsigned int operator==(const FeatureValueReal &) const;
|
||||
virtual unsigned int operator==(const FeatureValueSymbol &) const;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValue&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueInt&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueReal&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
|
||||
virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
|
||||
virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
|
||||
virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
|
||||
|
||||
virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
|
||||
virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
|
||||
virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
|
||||
virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValue &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValue &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueInt &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueReal &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const int) const ;
|
||||
virtual FeatureValue *rsub(const int) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const float) const ;
|
||||
virtual FeatureValue *rsub(const float) const ;
|
||||
|
||||
virtual FeatureValue *convertTo(Unit) const ;
|
||||
virtual FeatureValue *convertTo(Unit from, Unit to) const ;
|
||||
virtual FeatureValue *doConvert(Unit) const ;
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
private:
|
||||
int f_value ;
|
||||
|
||||
};
|
||||
|
||||
class FeatureValueString : public FeatureValue
|
||||
{
|
||||
public:
|
||||
FeatureValueString(const char *value)
|
||||
: FeatureValue(string), f_value(value)
|
||||
{}
|
||||
|
||||
FeatureValueString(const FeatureValueString &);
|
||||
~FeatureValueString();
|
||||
|
||||
virtual FeatureValue *clone() const ; /* deep copy */
|
||||
|
||||
virtual unsigned int operator==(const FeatureValue &) const;
|
||||
virtual unsigned int operator==(const FeatureValueInt &) const;
|
||||
virtual unsigned int operator==(const FeatureValueString &) const;
|
||||
virtual unsigned int operator==(const FeatureValueReal &) const;
|
||||
virtual unsigned int operator==(const FeatureValueSymbol &) const;
|
||||
|
||||
// ops for string concatenation
|
||||
// this -> operator+(const FeatureValueExpression&) evaluates
|
||||
// the argument and then call this -> operator+(const FeatureValue&).
|
||||
virtual FeatureValue *operator+(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
|
||||
|
||||
// call FeatureValue::operator+ directly.
|
||||
virtual FeatureValue *operator+(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator+(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const int i) const ;
|
||||
virtual FeatureValue *operator+(const float f) const ;
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
private:
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
CC_String f_value ;
|
||||
#else
|
||||
CC_String f_value ;
|
||||
#endif
|
||||
};
|
||||
|
||||
class FeatureValueSymbol : public FeatureValue
|
||||
{
|
||||
public:
|
||||
FeatureValueSymbol(const Symbol &value)
|
||||
: FeatureValue(symbol), f_value(value)
|
||||
{}
|
||||
FeatureValueSymbol(const FeatureValueSymbol&);
|
||||
|
||||
virtual FeatureValue *clone() const ; /* deep copy */
|
||||
|
||||
virtual unsigned int operator==(const FeatureValue &) const;
|
||||
virtual unsigned int operator==(const FeatureValueInt &) const;
|
||||
virtual unsigned int operator==(const FeatureValueString &) const;
|
||||
virtual unsigned int operator==(const FeatureValueReal &) const;
|
||||
virtual unsigned int operator==(const FeatureValueSymbol &) const;
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
private:
|
||||
Symbol f_value;
|
||||
|
||||
};
|
||||
|
||||
class FeatureValueExpression : public FeatureValue
|
||||
{
|
||||
public:
|
||||
FeatureValueExpression(Expression *);
|
||||
FeatureValueExpression(const FeatureValueExpression&);
|
||||
~FeatureValueExpression();
|
||||
|
||||
virtual FeatureValue *clone() const ; /* deep copy */
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
|
||||
// operators
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValue&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueInt&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueReal&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
|
||||
virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
|
||||
virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
|
||||
virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
|
||||
|
||||
virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
|
||||
virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
|
||||
virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
|
||||
virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValue &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValue &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueInt &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueReal &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const int) const ;
|
||||
virtual FeatureValue *rsub(const int) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const float) const ;
|
||||
virtual FeatureValue *rsub(const float) const ;
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
private:
|
||||
Expression *f_value;
|
||||
};
|
||||
|
||||
class FeatureValueFeatureSet : public FeatureValue
|
||||
{
|
||||
public:
|
||||
FeatureValueFeatureSet(FeatureSet *);
|
||||
FeatureValueFeatureSet(const FeatureValueFeatureSet&);
|
||||
~FeatureValueFeatureSet();
|
||||
|
||||
const FeatureSet *value() const { return f_value ; }
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
|
||||
virtual FeatureValue *clone() const; /* deep copy */
|
||||
|
||||
virtual FeatureValue *merge(const FeatureValue &f);
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
virtual operator const FeatureSet *() const ;
|
||||
|
||||
private:
|
||||
FeatureSet *f_value;
|
||||
};
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
typedef pointer_vector<FeatureValue> ArrayType;
|
||||
#else
|
||||
typedef pointer_vector<FeatureValue> ArrayType;
|
||||
#endif
|
||||
|
||||
class FeatureValueArray: public FeatureValue, public ArrayType
|
||||
{
|
||||
public:
|
||||
FeatureValueArray(const char* array_name, int size);
|
||||
FeatureValueArray(const FeatureValueArray&);
|
||||
~FeatureValueArray();
|
||||
|
||||
virtual FeatureValue *evaluate() const;
|
||||
|
||||
virtual FeatureValue *clone() const
|
||||
{ return new FeatureValueArray(*this); }; /* deep copy */
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
const char* name() { return f_name; };
|
||||
|
||||
private:
|
||||
char* f_name;
|
||||
};
|
||||
|
||||
|
||||
class FeatureValueDimension : public FeatureValue
|
||||
{
|
||||
public:
|
||||
|
||||
FeatureValueDimension(FeatureValue *value, const char* unit_string);
|
||||
FeatureValueDimension(FeatureValue *value, Unit unit);
|
||||
|
||||
FeatureValueDimension(float value, const char* unit_string) ;
|
||||
FeatureValueDimension(float value, Unit unit) :
|
||||
FeatureValue(dimension), f_value(0),
|
||||
f_cachedValue(value), f_unit(unit) {};
|
||||
|
||||
|
||||
|
||||
FeatureValueDimension(const FeatureValueDimension&);
|
||||
~FeatureValueDimension();
|
||||
|
||||
virtual FeatureValue *clone() const; /* deep copy */
|
||||
|
||||
virtual FeatureValue *evaluate() const ;
|
||||
|
||||
// operators
|
||||
virtual FeatureValue *operator+(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValue&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValue&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueInt&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueInt&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueReal&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueReal&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueDimension&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueDimension&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator-(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator*(const FeatureValueExpression&) const ;
|
||||
virtual FeatureValue *operator/(const FeatureValueExpression&) const ;
|
||||
|
||||
virtual FeatureValue *operator+(const int i) const ; /* returns this + i */
|
||||
virtual FeatureValue *operator-(const int i) const ; /* returns this - i */
|
||||
virtual FeatureValue *operator*(const int i) const ; /* returns this * i */
|
||||
virtual FeatureValue *operator/(const int i) const ; /* returns this / i */
|
||||
|
||||
virtual FeatureValue *operator+(const float f) const ; /* returns this + f */
|
||||
virtual FeatureValue *operator-(const float f) const ; /* returns this - f */
|
||||
virtual FeatureValue *operator*(const float f) const ; /* returns this * f */
|
||||
virtual FeatureValue *operator/(const float f) const ; /* returns this / f */
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValue &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValue &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueInt &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueInt &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueReal &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueReal &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueExpression &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueExpression &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const FeatureValueDimension &) const ;
|
||||
virtual FeatureValue *rsub(const FeatureValueDimension &) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const int) const ;
|
||||
virtual FeatureValue *rsub(const int) const ;
|
||||
|
||||
virtual FeatureValue *rdiv(const float) const ;
|
||||
virtual FeatureValue *rsub(const float) const ;
|
||||
|
||||
virtual FeatureValue *convertTo(Unit) const ;
|
||||
virtual FeatureValue *convertTo(Unit from, Unit to) const ;
|
||||
virtual FeatureValue *doConvert(Unit) const ;
|
||||
|
||||
virtual operator float() const;
|
||||
virtual operator int() const;
|
||||
virtual operator const char *() const;
|
||||
|
||||
float getValue(Unit);
|
||||
|
||||
FeatureValue *value() { return f_value ; }
|
||||
Unit unit() { return f_unit ; }
|
||||
|
||||
virtual ostream& print(ostream&) const;
|
||||
|
||||
private:
|
||||
FeatureValue *f_value ;
|
||||
Unit f_unit ;
|
||||
float f_cachedValue;
|
||||
|
||||
private:
|
||||
float convert(float y, Unit dimensionOfy, Unit dimensionOfReturn);
|
||||
Unit convertToUnit(const char*);
|
||||
|
||||
};
|
||||
#endif /* _FeatureValue_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
127
cde/programs/dtinfo/DtMmdb/StyleSheet/PQTest.C
Normal file
127
cde/programs/dtinfo/DtMmdb/StyleSheet/PQTest.C
Normal file
@@ -0,0 +1,127 @@
|
||||
// $XConsortium: PQTest.cc /main/3 1996/06/11 17:07:26 cde-hal $
|
||||
#include <iostream.h>
|
||||
#include "SymTab.h"
|
||||
#include "PathQualifier.h"
|
||||
#include "Element.h"
|
||||
#include "Attribute.h"
|
||||
#include "AttributeList.h"
|
||||
|
||||
void
|
||||
styleerror(char *)
|
||||
{
|
||||
// bogus
|
||||
abort();
|
||||
}
|
||||
|
||||
class Renderer;
|
||||
Renderer *gRenderer = 0;
|
||||
|
||||
main()
|
||||
{
|
||||
SymbolTable symtab ;
|
||||
|
||||
Attribute *attr1a = new Attribute(symtab.intern("attr1a"),"one-a");
|
||||
Attribute *attr1b = new Attribute(symtab.intern("attr1b"),"one-b");
|
||||
|
||||
AttributeList *alist1 = new AttributeList ;
|
||||
alist1->add(attr1a);
|
||||
alist1->add(attr1b);
|
||||
|
||||
Element one(symtab.intern("One"), 1, alist1, 0);
|
||||
Element two(symtab.intern("Two"), 2, 0, 0);
|
||||
|
||||
PQPosition posn_eq(PQEqual, 1);
|
||||
PQPosition posn_neq(PQNotEqual, 1);
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Test Position
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/* -------- Test Position Equal -------- */
|
||||
cout << posn_eq.evaluate (one) << endl; // 1
|
||||
cout << posn_eq.evaluate (two) << endl; // 0
|
||||
cout << "---" << endl;
|
||||
/* -------- Test Position Not Equal -------- */
|
||||
cout << posn_neq.evaluate (one) << endl; // 0
|
||||
cout << posn_neq.evaluate (two) << endl; // 1
|
||||
cout << "---" << endl;
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////
|
||||
// Test Attribute Comparison
|
||||
// ///////////////////////////////////////////////////////////////////////
|
||||
|
||||
PQAttributeSelector pqas_eqa(symtab.intern("attr1a"), PQEqual, "one-a");
|
||||
PQAttributeSelector pqas_eqb(symtab.intern("attr1a"), PQEqual, "one-b");
|
||||
PQAttributeSelector pqas_neqa(symtab.intern("attr1a"), PQNotEqual, "one-a");
|
||||
PQAttributeSelector pqas_neqb(symtab.intern("attr1a"), PQNotEqual, "one-b");
|
||||
|
||||
PQAttributeSelector pqas_eqa2(symtab.intern("attr2a"), PQEqual, "one-a");
|
||||
PQAttributeSelector pqas_eqb2(symtab.intern("attr2a"), PQEqual, "one-b");
|
||||
PQAttributeSelector pqas_neqa2(symtab.intern("attr2a"), PQNotEqual, "one-a");
|
||||
PQAttributeSelector pqas_neqb2(symtab.intern("attr2a"), PQNotEqual, "one-b");
|
||||
|
||||
cout << pqas_eqa.evaluate(one) << endl ; // 1
|
||||
cout << pqas_eqa.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << pqas_eqb.evaluate(one) << endl ; // 0
|
||||
cout << pqas_eqb.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << pqas_neqa.evaluate(one) << endl ; // 0
|
||||
cout << pqas_neqa.evaluate(two) << endl ; // 1
|
||||
|
||||
cout << pqas_neqb.evaluate(one) << endl ; // 1
|
||||
cout << pqas_neqb.evaluate(two) << endl ; // 1
|
||||
|
||||
cout << pqas_eqa2.evaluate(one) << endl ; // 0
|
||||
cout << pqas_eqa2.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << pqas_eqb2.evaluate(one) << endl ; // 0
|
||||
cout << pqas_eqb2.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << pqas_neqa2.evaluate(one) << endl ; // 1
|
||||
cout << pqas_neqa2.evaluate(two) << endl ; // 1
|
||||
|
||||
cout << pqas_neqb2.evaluate(one) << endl ; // 1
|
||||
cout << pqas_neqb2.evaluate(two) << endl ; // 1
|
||||
|
||||
cout << "****" << endl;
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////
|
||||
// composite
|
||||
// ///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// position = 1 and attr(attr1a) == "one-a"
|
||||
|
||||
PQPosition *p1 = new PQPosition(PQEqual, 1);
|
||||
PQAttributeSelector *a1 = new PQAttributeSelector(symtab.intern("attr1a"),
|
||||
PQEqual, "one-a");
|
||||
|
||||
PQAttributeSelector *a2 = new PQAttributeSelector(symtab.intern("attr1a"),
|
||||
PQEqual, "value");
|
||||
|
||||
PQLogExpr l1 (p1, PQand, a1);
|
||||
PQLogExpr l2 (p1, PQor, a1);
|
||||
PQLogExpr l3 (p1, PQand, a2);
|
||||
PQLogExpr l4 (p1, PQor, a2);
|
||||
|
||||
cout << l1.evaluate(one) << endl ; // 1
|
||||
cout << l1.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << l2.evaluate(one) << endl ; // 1
|
||||
cout << l2.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << l3.evaluate(one) << endl ; // 0
|
||||
cout << l3.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << l4.evaluate(one) << endl ; // 1
|
||||
cout << l4.evaluate(two) << endl ; // 0
|
||||
|
||||
cout << "..." << endl;
|
||||
cout << PQNot(&l4).evaluate(one) << endl ; // 0
|
||||
cout << PQNot(&l4).evaluate(two) << endl ; // 1
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
cde/programs/dtinfo/DtMmdb/StyleSheet/ParserConst.h
Normal file
17
cde/programs/dtinfo/DtMmdb/StyleSheet/ParserConst.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $XConsortium: ParserConst.h /main/3 1996/06/11 17:07:41 cde-hal $ */
|
||||
|
||||
#ifndef _parsar_const_h
|
||||
#define _parsar_const_h 1
|
||||
|
||||
#define EQUAL 0
|
||||
#define NOT_EQUAL 1
|
||||
|
||||
#define LESS_OR_EQUAL 0
|
||||
#define LESS 1
|
||||
#define GREATER_OR_EQUAL 2
|
||||
#define GREATER 3
|
||||
|
||||
#define PARSER_TRUE 0
|
||||
#define PARSER_FALSE 1
|
||||
|
||||
#endif
|
||||
167
cde/programs/dtinfo/DtMmdb/StyleSheet/PathQualifier.C
Normal file
167
cde/programs/dtinfo/DtMmdb/StyleSheet/PathQualifier.C
Normal file
@@ -0,0 +1,167 @@
|
||||
// $XConsortium: PathQualifier.cc /main/4 1996/06/11 17:07:46 cde-hal $
|
||||
#include "PathQualifier.h"
|
||||
#include "Element.h"
|
||||
#include "Attribute.h"
|
||||
#include "Debug.h"
|
||||
|
||||
|
||||
PQExpr::~PQExpr()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
PQAttributeSelector::~PQAttributeSelector()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
PQLogExpr::~PQLogExpr()
|
||||
{
|
||||
delete f_left ;
|
||||
delete f_right ;
|
||||
}
|
||||
|
||||
PQNot::PQNot(PQExpr *expr)
|
||||
: f_expr(expr)
|
||||
{
|
||||
}
|
||||
|
||||
PQNot::~PQNot()
|
||||
{
|
||||
delete f_expr;
|
||||
}
|
||||
|
||||
PQBoolean
|
||||
PQNot::evaluate(const Element &element)
|
||||
{
|
||||
return (f_expr->evaluate(element) == PQTrue) ? PQFalse : PQTrue ;
|
||||
}
|
||||
|
||||
PQPosition::PQPosition(PQEqOp optype, int position)
|
||||
: f_optype(optype),
|
||||
f_position(position)
|
||||
{
|
||||
}
|
||||
|
||||
PQBoolean
|
||||
PQPosition::evaluate(const Element &element)
|
||||
{
|
||||
switch ( f_optype ) {
|
||||
case PQEqual:
|
||||
if ( f_position == element.sibling_number() ||
|
||||
( f_position==-1 && element.last_child() )
|
||||
)
|
||||
return PQTrue;
|
||||
else
|
||||
return PQFalse;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( f_position==-1 ) {
|
||||
if ( element.last_child() == 0 )
|
||||
return PQTrue;
|
||||
else
|
||||
return PQFalse;
|
||||
} else
|
||||
if ( f_position != element.sibling_number() )
|
||||
return PQTrue;
|
||||
else
|
||||
return PQFalse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PQSibling::PQSibling(PQEqOp optype, int sib)
|
||||
: f_optype(optype),
|
||||
f_sibling(sib)
|
||||
{
|
||||
}
|
||||
|
||||
PQBoolean
|
||||
PQSibling::evaluate(const Element &element)
|
||||
{
|
||||
switch ( f_optype ) {
|
||||
case PQEqual:
|
||||
if ( f_sibling == element.relative_sibling_number() ||
|
||||
( f_sibling ==-1 && element.relatively_last_child() )
|
||||
)
|
||||
return PQTrue;
|
||||
else
|
||||
return PQFalse;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( f_sibling ==-1 ) {
|
||||
if ( element.relatively_last_child() == 0 )
|
||||
return PQTrue;
|
||||
else
|
||||
return PQFalse;
|
||||
} else
|
||||
if ( f_sibling != element.relative_sibling_number() )
|
||||
return PQTrue;
|
||||
else
|
||||
return PQFalse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PQAttributeSelector::PQAttributeSelector(const Symbol &attrname,
|
||||
PQEqOp op,
|
||||
const CC_String &string)
|
||||
: f_optype(op),
|
||||
f_attribute(attrname),
|
||||
f_string(string)
|
||||
{
|
||||
debug(cerr, op);
|
||||
}
|
||||
|
||||
PQBoolean
|
||||
PQAttributeSelector::evaluate(const Element &element)
|
||||
{
|
||||
PQBoolean return_value = PQFalse ;
|
||||
|
||||
// see if attribute exists first
|
||||
const Attribute *attr = element.get_attribute(f_attribute);
|
||||
|
||||
if (attr)
|
||||
{
|
||||
// comparison value of 0 means strings are equal
|
||||
int comparison = f_string.compareTo(attr->value());
|
||||
|
||||
if (((f_optype == PQEqual) && (comparison == 0)) ||
|
||||
((f_optype == PQNotEqual) && (comparison != 0)))
|
||||
{
|
||||
return_value = PQTrue ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// not attribute, but if operator is not equal, we should return true
|
||||
if (f_optype == PQNotEqual)
|
||||
return_value = PQTrue ;
|
||||
}
|
||||
return return_value ;
|
||||
}
|
||||
|
||||
PQLogExpr::PQLogExpr(PQExpr *left, PQLogOp op, PQExpr *right)
|
||||
: f_optype(op),
|
||||
f_left(left),
|
||||
f_right(right)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PQBoolean
|
||||
PQLogExpr::evaluate(const Element &element)
|
||||
{
|
||||
PQBoolean left_value = f_left->evaluate(element);
|
||||
|
||||
if ((left_value == PQTrue) && (f_optype == PQor))
|
||||
return PQTrue ;
|
||||
|
||||
if ((left_value == PQFalse) && (f_optype == PQand))
|
||||
return PQFalse ;
|
||||
|
||||
return f_right->evaluate(element);
|
||||
}
|
||||
|
||||
104
cde/programs/dtinfo/DtMmdb/StyleSheet/PathQualifier.h
Normal file
104
cde/programs/dtinfo/DtMmdb/StyleSheet/PathQualifier.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/* $XConsortium: PathQualifier.h /main/5 1996/08/21 15:50:33 drk $ */
|
||||
#ifndef _PathQualifier_h
|
||||
#define _PathQualifier_h
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
#else
|
||||
#include "dti_cc/CC_String.h"
|
||||
#endif
|
||||
|
||||
#include "SymTab.h"
|
||||
|
||||
// PathEXPR = PathTERM | PathTERM log PathTERM
|
||||
|
||||
// PathTERM = position | attribute-selector
|
||||
|
||||
// position = posn eqop number
|
||||
// attribute-selector = attribute eqop string
|
||||
|
||||
// log = and | or
|
||||
|
||||
|
||||
class Element;
|
||||
class Symbol ;
|
||||
|
||||
enum PQEqOp { PQEqual, PQNotEqual };
|
||||
enum PQBoolean { PQFalse, PQTrue };
|
||||
enum PQLogOp { PQand, PQor };
|
||||
|
||||
class PQExpr
|
||||
{
|
||||
public:
|
||||
virtual ~PQExpr();
|
||||
virtual PQBoolean evaluate(const Element &) = 0;
|
||||
};
|
||||
|
||||
class PQNot : public PQExpr
|
||||
{
|
||||
public:
|
||||
PQNot(PQExpr *);
|
||||
~PQNot();
|
||||
virtual PQBoolean evaluate(const Element &);
|
||||
private:
|
||||
PQExpr *f_expr;
|
||||
};
|
||||
|
||||
|
||||
class PQPosition : public PQExpr
|
||||
{
|
||||
public:
|
||||
PQPosition(PQEqOp optype, int position);
|
||||
virtual PQBoolean evaluate(const Element &);
|
||||
|
||||
private:
|
||||
int f_position ;
|
||||
PQEqOp f_optype;
|
||||
};
|
||||
|
||||
class PQSibling: public PQExpr
|
||||
{
|
||||
public:
|
||||
PQSibling(PQEqOp optype, int sibling);
|
||||
virtual PQBoolean evaluate(const Element &);
|
||||
|
||||
private:
|
||||
int f_sibling;
|
||||
PQEqOp f_optype;
|
||||
};
|
||||
|
||||
class PQAttributeSelector : public PQExpr
|
||||
{
|
||||
public:
|
||||
PQAttributeSelector(const Symbol &attrname, PQEqOp, const CC_String &string);
|
||||
~PQAttributeSelector();
|
||||
virtual PQBoolean evaluate(const Element &);
|
||||
private:
|
||||
PQEqOp f_optype ;
|
||||
Symbol f_attribute;
|
||||
CC_String f_string ;
|
||||
};
|
||||
|
||||
class PQLogExpr : public PQExpr
|
||||
{
|
||||
public:
|
||||
|
||||
PQLogExpr(PQExpr *left, PQLogOp op, PQExpr *right);
|
||||
~PQLogExpr();
|
||||
|
||||
virtual PQBoolean evaluate(const Element &);
|
||||
|
||||
private:
|
||||
|
||||
PQLogOp f_optype ;
|
||||
PQExpr *f_left ;
|
||||
PQExpr *f_right ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _PathQualifier_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
|
||||
|
||||
583
cde/programs/dtinfo/DtMmdb/StyleSheet/PathTable.C
Normal file
583
cde/programs/dtinfo/DtMmdb/StyleSheet/PathTable.C
Normal file
@@ -0,0 +1,583 @@
|
||||
// $XConsortium: PathTable.cc /main/4 1996/06/11 17:07:57 cde-hal $
|
||||
#include "PathTable.h"
|
||||
#include "Debug.h"
|
||||
#include "Feature.h"
|
||||
#include "utility/debug.h"
|
||||
|
||||
extern SymbolTable* gElemSymTab;
|
||||
|
||||
unsigned int letterHash(const LetterType& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
EncodedPath::~EncodedPath()
|
||||
{
|
||||
delete [] f_array ;
|
||||
f_SVectors.clearAndDestroy();
|
||||
delete f_copyOfS;
|
||||
}
|
||||
|
||||
EncodedPath::EncodedPath(SSPath* p, unsigned int asPattern) :
|
||||
f_size(p -> entries()), f_SVectors(letterHash), f_patternSize(0),
|
||||
f_wildCard(gElemSymTab -> wildCardId()),
|
||||
f_unlimitedWildCard(gElemSymTab -> unlimitedWildCardId()),
|
||||
f_copyOfS(new BitVector(WORD_SIZE, 0))
|
||||
{
|
||||
|
||||
f_array = new LetterType[f_size];
|
||||
|
||||
CC_TPtrDlistIterator<PathTerm> l_pathIter(*p);
|
||||
|
||||
BitVector *l_bv = 0;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (++l_pathIter) {
|
||||
|
||||
//
|
||||
// Count pattern size, excluding "*".
|
||||
//
|
||||
f_array[i] = (LetterType)((l_pathIter.key() -> symbol()).id());
|
||||
if ( f_array[i] != f_unlimitedWildCard )
|
||||
f_patternSize++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if ( asPattern == true ) {
|
||||
|
||||
//
|
||||
// Compute the S arrays.
|
||||
// Examples pat = a b a c
|
||||
// S(a) = 1 0 1 0
|
||||
// S(b) = 0 0 0 0
|
||||
// S(c) = 0 0 0 1
|
||||
//
|
||||
// pat = a ? a c
|
||||
// S(a) = 1 1 1 0
|
||||
// S(c) = 0 1 0 1
|
||||
// S(?) = 0 1 0 0
|
||||
//
|
||||
// pat = a * a c
|
||||
// S(a) = 1 1 0
|
||||
// S(c) = 0 0 1
|
||||
// S(*) = 1 0 0
|
||||
//
|
||||
l_pathIter.reset();
|
||||
int j = patternLength()-1;
|
||||
|
||||
LetterType l_id;
|
||||
|
||||
// i records each PathTerm position in the list
|
||||
int i=0;
|
||||
|
||||
while (++l_pathIter) {
|
||||
l_id = (LetterType)((l_pathIter.key() -> symbol()).id());
|
||||
|
||||
l_bv = f_SVectors.findValue(&l_id);
|
||||
if ( l_bv == 0 ) {
|
||||
l_bv = new BitVector(patternLength(), 0);
|
||||
f_SVectors.insertKeyAndValue(new LetterType(l_id), l_bv);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// reverse the order in the bit vector:
|
||||
// MSB position ==> set LSB bit in the bit vector
|
||||
///////////////////////////////////////////////////
|
||||
if ( l_id != f_unlimitedWildCard ) {
|
||||
l_bv -> setBitTo(j, 1);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// only set position when an expr is attatched
|
||||
// to the term
|
||||
//////////////////////////////////////////////////
|
||||
if ( l_pathIter.key() -> pqexpr() && l_id != f_wildCard ) {
|
||||
/*
|
||||
MESSAGE(cerr, "==========");
|
||||
debug(cerr, (void*)l_bv);
|
||||
debug(cerr, *l_bv);
|
||||
debug(cerr, i);
|
||||
debug(cerr, j);
|
||||
*/
|
||||
l_bv -> recordPositions(i, j);
|
||||
|
||||
}
|
||||
|
||||
j--;
|
||||
|
||||
} else {
|
||||
///////////////////////////////////////////////////
|
||||
// do not set bits for unlimitedWildCards that
|
||||
// begin or end the pattern
|
||||
///////////////////////////////////////////////////
|
||||
if ( j < patternLength() - 1 )
|
||||
l_bv -> setBitTo(j+1, 1);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// special treatment to the ? symbols:
|
||||
// OR S(?) back to each S's.
|
||||
///////////////////////////////////////////////////
|
||||
BitVector* l_BitVectorWildCard = f_SVectors.findValue(&f_wildCard);
|
||||
hashTableIterator<LetterType, BitVector> l_SVIter(f_SVectors);
|
||||
|
||||
if ( l_BitVectorWildCard ) {
|
||||
while (++l_SVIter) {
|
||||
if ( *l_SVIter.key() != f_wildCard &&
|
||||
*l_SVIter.key() != f_unlimitedWildCard
|
||||
)
|
||||
{
|
||||
(*l_SVIter.value()) |= (*l_BitVectorWildCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
#ifdef DEBUG
|
||||
l_SVIter.reset();
|
||||
while (++l_SVIter) {
|
||||
debug(cerr, (*l_SVIter.key()));
|
||||
debug(cerr, (*l_SVIter.value()));
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned int
|
||||
_match(LetterType* pattern, int n,
|
||||
LetterType* text, int m,
|
||||
LetterType wildCard,
|
||||
LetterType unlimitedWildCard
|
||||
)
|
||||
{
|
||||
// A naive (brute force) string matching algorithm that handles
|
||||
// wild card (?) and unlimited wild card (*) symbols.
|
||||
unsigned int findMisMatch = false;
|
||||
|
||||
for ( int i=0; i<n; i++ ) { // over the "text" string
|
||||
|
||||
for ( int j=0; j<m; j++ ) { // over the pattern
|
||||
if ( pattern[j] == wildCard ) {
|
||||
continue;
|
||||
} else
|
||||
if ( pattern[j] == unlimitedWildCard ) {
|
||||
|
||||
for (;;) {
|
||||
|
||||
j++;
|
||||
|
||||
if ( j == m )
|
||||
return true;
|
||||
|
||||
if ( pattern[j] != unlimitedWildCard )
|
||||
break;
|
||||
}
|
||||
|
||||
for ( int x=i+1; x<n; x++ ) {
|
||||
if ( text[x] == pattern[j] )
|
||||
if (
|
||||
_match(
|
||||
&pattern[j], m-j,
|
||||
&text[x], n-x,
|
||||
wildCard, unlimitedWildCard
|
||||
) == true
|
||||
)
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( pattern[j] != text[i] ) {
|
||||
findMisMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( findMisMatch == false )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
unsigned int
|
||||
EncodedPath::match(EncodedPath& text, SSPath* patternPath, SSPath* elementPath)
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// text: the encoded string for the element path
|
||||
// elementPath: the element path
|
||||
//
|
||||
// this: the encoded string for the pattern string
|
||||
// patternPath: the pattern path
|
||||
////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// the unlimited wildcard vector
|
||||
////////////////////////////////////////////////
|
||||
BitVector* l_U = f_SVectors.findValue(&f_unlimitedWildCard);
|
||||
|
||||
if ( l_U && patternLength() == 0 )
|
||||
return true;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// the wildcard vector
|
||||
////////////////////////////////////////////////
|
||||
BitVector* l_W = f_SVectors.findValue(&f_wildCard);
|
||||
|
||||
// the S vector of each Letter, including that for '?'
|
||||
BitVector* l_S = 0;
|
||||
|
||||
// the accumulated result vector
|
||||
BitVector l_R(patternLength(), 0);
|
||||
|
||||
// placeholder for '*''s contribution
|
||||
BitVector l_I(patternLength(), 0);
|
||||
|
||||
// hole position record of each path term in the pattern path
|
||||
posRecord l_pr;
|
||||
|
||||
// expr pointer of each path term in the pattern path
|
||||
PQExpr* expr = 0;
|
||||
|
||||
CC_TPtrDlistIterator<PathTerm>* elementPathNextPtr = 0;
|
||||
|
||||
if ( elementPath )
|
||||
elementPathNextPtr = new CC_TPtrDlistIterator<PathTerm>(*elementPath);
|
||||
|
||||
// loop over text string
|
||||
for ( int i=0; i<text.length(); i++) {
|
||||
|
||||
if ( elementPath )
|
||||
++(*elementPathNextPtr);
|
||||
|
||||
//MESSAGE(cerr, "===================");
|
||||
//debug(cerr, text.f_array[i]);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// get this character's vector, including '?'s
|
||||
////////////////////////////////////////////////
|
||||
l_S = f_SVectors.findValue(&text.f_array[i]);
|
||||
|
||||
if ( l_S ) {
|
||||
//debug(cerr, (void*)l_S);
|
||||
//debug(cerr, *l_S);
|
||||
//MESSAGE(cerr, "checking qualifies");
|
||||
//////////////////////
|
||||
// check qualifies.
|
||||
//////////////////////
|
||||
if ( patternPath && l_S -> positionArray() ) {
|
||||
|
||||
////////////////////
|
||||
// get a copy of S
|
||||
////////////////////
|
||||
f_copyOfS -> setTo(*l_S);
|
||||
|
||||
//debug(cerr, *patternPath);
|
||||
|
||||
positionArrayIteratorT l_positionNext(*(l_S -> positionArray()));
|
||||
while (++ l_positionNext) {
|
||||
|
||||
l_pr = l_positionNext.key();
|
||||
|
||||
//cerr << " calling patternPath -> fastGetAt(): " << (void*)patternPath << "l_pr.pathTermPos= " << l_pr.pathTermPos << endl;
|
||||
|
||||
expr = patternPath -> fastGetAt(l_pr.pathTermPos) -> pqexpr();
|
||||
/*
|
||||
debug(cerr, int(expr));
|
||||
if ( expr ) {
|
||||
MESSAGE(cerr, "qualify checking is needed.");
|
||||
debug(cerr, *(elementPathNext -> key()));
|
||||
}
|
||||
*/
|
||||
|
||||
if ( expr &&
|
||||
expr->evaluate(elementPathNextPtr->key()->element()) == PQFalse )
|
||||
{
|
||||
//MESSAGE(cerr, form("set position %d to 0", l_pr.bitPos));
|
||||
f_copyOfS -> setBitTo(l_pr.bitPos, 0);
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////
|
||||
// make l_S point at its modified copy
|
||||
/////////////////////////////////////////
|
||||
l_S = f_copyOfS;
|
||||
}
|
||||
} else
|
||||
l_S = l_W;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// get unlimited wildcard's vector.
|
||||
////////////////////////////////////////////////
|
||||
if ( l_U ) {
|
||||
l_I.setTo(l_R);
|
||||
l_I &= (*l_U);
|
||||
//MESSAGE(cerr, "l_I");
|
||||
//debug(cerr, l_I);
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// shift the partial result vector right once
|
||||
////////////////////////////////////////////////
|
||||
l_R.shiftRightOneBit();
|
||||
//MESSAGE(cerr, "after l_R >> 1");
|
||||
//debug(cerr, l_R);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// AND in this character's vector
|
||||
////////////////////////////////////////////////
|
||||
if ( l_S ) {
|
||||
l_R &= (*l_S);
|
||||
//debug(cerr, *l_S);
|
||||
//MESSAGE(cerr, "after AND with l_S");
|
||||
//debug(cerr, l_R);
|
||||
} else {
|
||||
///////////////////////////////////////////////
|
||||
// this branch is impossible to reach.
|
||||
///////////////////////////////////////////////
|
||||
//MESSAGE(cerr, "l_R set all bits to 0");
|
||||
l_R.setAllBitsTo(0);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// OR in unlimited wild char's vector.
|
||||
///////////////////////////////////////////////
|
||||
if ( l_U ) {
|
||||
l_R |= l_I;
|
||||
//MESSAGE(cerr, "after OR with l_I");
|
||||
//debug(cerr, l_R);
|
||||
}
|
||||
//debug(cerr, l_R);
|
||||
//MESSAGE(cerr, "===================");
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Use this test to get the first matched position
|
||||
// if ( l_R.getBit(0) == 1 )
|
||||
// return true;
|
||||
///////////////////////////////////////////////
|
||||
|
||||
}
|
||||
delete elementPathNextPtr;
|
||||
|
||||
///////////////////////////////////////////////
|
||||
//
|
||||
// the last symbol must match
|
||||
//
|
||||
///////////////////////////////////////////////
|
||||
if ( l_R.getBit(0) == 1 )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
basePathFeature::~basePathFeature()
|
||||
{
|
||||
delete f_path;
|
||||
delete f_featureSet;
|
||||
}
|
||||
|
||||
PathFeature::~PathFeature()
|
||||
{
|
||||
delete f_encodedPath ;
|
||||
}
|
||||
|
||||
unsigned int basePathFeature::operator==(const basePathFeature& pf) const
|
||||
{
|
||||
cerr << "Warning: basePathFeature::operator==() called\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int PathFeature::operator==(const PathFeature& pf) const
|
||||
{
|
||||
cerr << "Warning: PathFeature::operator==() called\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
void pathSelector(BitVector& bv)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int
|
||||
PathFeature::match(SSPath& p)
|
||||
{
|
||||
EncodedPath l_ep(&p);
|
||||
|
||||
if ( f_path -> containSelector() == false )
|
||||
return f_encodedPath -> match(l_ep, 0, 0);
|
||||
else
|
||||
return f_encodedPath -> match(l_ep, f_path, &p);
|
||||
}
|
||||
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// class PathTable
|
||||
//
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
unsigned symHashFunc(const Symbol& s)
|
||||
{
|
||||
return s.hash();
|
||||
}
|
||||
|
||||
PathTable::PathTable()
|
||||
: f_lastSymIndex(0),
|
||||
f_lastSymIndexCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
PathTable::~PathTable()
|
||||
{
|
||||
f_pathFeatureList.clearAndDestroy();
|
||||
for (unsigned int i = 0 ; i < f_lastSymIndexCount; i++) {
|
||||
//f_lastSymIndex[i].clearAndDestroy();
|
||||
f_lastSymIndex[i] -> clear();
|
||||
delete f_lastSymIndex[i];
|
||||
}
|
||||
delete f_lastSymIndex;
|
||||
}
|
||||
|
||||
LetterType PathTable::findIndex(SSPath& p)
|
||||
{
|
||||
return (LetterType) ((p.last() -> symbol()).id());
|
||||
}
|
||||
|
||||
void PathTable::initLastSymIndex()
|
||||
{
|
||||
f_lastSymIndexCount = gElemSymTab -> IdsAssigned()+1;
|
||||
f_lastSymIndex = new CC_TPtrDlist_PathFeature_Ptr_T[f_lastSymIndexCount];
|
||||
for (int i=0; i<f_lastSymIndexCount; i++)
|
||||
f_lastSymIndex[i] = new CC_TPtrDlist<PathFeature>;
|
||||
|
||||
|
||||
CC_TPtrDlistIterator<PathFeature> l_pfIter(f_pathFeatureList);
|
||||
PathFeature* l_pathFeature = 0;
|
||||
|
||||
LetterType x;
|
||||
|
||||
while ( ++l_pfIter ) {
|
||||
l_pathFeature = l_pfIter.key();
|
||||
x = findIndex( *(l_pathFeature->path()) );
|
||||
//f_lastSymIndex[x] -> prepend(l_pathFeature); // backward order
|
||||
f_lastSymIndex[x] -> append(l_pathFeature); // select the matching rule
|
||||
// in the same order rules
|
||||
// appear in the
|
||||
// stylesheet
|
||||
}
|
||||
}
|
||||
|
||||
FeatureSet* PathTable::getFeatureSet(SSPath& p)
|
||||
{
|
||||
if ( f_lastSymIndex == 0 ) {
|
||||
initLastSymIndex();
|
||||
}
|
||||
|
||||
int pids[3];
|
||||
FeatureSet* fs[3];
|
||||
|
||||
fs[0] = getFeatureSet(findIndex(p), p, pids[0]);
|
||||
fs[1] = getFeatureSet(gElemSymTab -> wildCardId(), p, pids[1]);
|
||||
fs[2] = getFeatureSet(gElemSymTab -> unlimitedWildCardId(), p, pids[2]);
|
||||
|
||||
int index = 0;
|
||||
int x = pids[0];
|
||||
|
||||
for ( int i=1; i<3; i++ ) {
|
||||
if ( pids[i] > x )
|
||||
index = i;
|
||||
}
|
||||
|
||||
return fs[index];
|
||||
}
|
||||
|
||||
FeatureSet*
|
||||
PathTable::getFeatureSet(int bucketIndex, SSPath& p, int& pathId)
|
||||
{
|
||||
CC_TPtrDlistIterator<PathFeature> l_pathFeatureIter(*f_lastSymIndex[bucketIndex]);
|
||||
|
||||
l_pathFeatureIter.reset();
|
||||
|
||||
PathFeature* l_pathFeature = 0;
|
||||
|
||||
while ( ++l_pathFeatureIter ) {
|
||||
|
||||
l_pathFeature = l_pathFeatureIter.key();
|
||||
|
||||
//debug(cerr, *(l_pathFeature->path()));
|
||||
//debug(cerr, *(l_pathFeature->featureSet()));
|
||||
|
||||
if ( l_pathFeature -> match(p) ) {
|
||||
//MESSAGE(cerr, "match");
|
||||
pathId = l_pathFeature -> id();
|
||||
return l_pathFeature -> featureSet();
|
||||
}
|
||||
}
|
||||
|
||||
pathId = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PathTable::addPathFeatureSet(PathFeature* x)
|
||||
{
|
||||
//MESSAGE(cerr, "addPathFeatureSet():");
|
||||
//debug(cerr, *(x->path()));
|
||||
//debug(cerr, *(x->featureSet()));
|
||||
|
||||
if ( x -> path() -> containSelector() )
|
||||
x -> path() -> fastGetIndex();
|
||||
|
||||
EncodedPath* l_epath = new EncodedPath(x -> path(), true);
|
||||
unsigned int id = f_pathFeatureList.entries()+1;
|
||||
|
||||
x -> setEncodedPath(l_epath);
|
||||
x -> setID(id);
|
||||
|
||||
f_pathFeatureList.insert(x);
|
||||
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& out, PathTable& pt)
|
||||
{
|
||||
CC_TPtrDlistIterator<PathFeature> l_pfIter(pt.f_pathFeatureList);
|
||||
PathFeature* l_pathFeature = 0;
|
||||
|
||||
while ( ++l_pfIter ) {
|
||||
l_pathFeature = l_pfIter.key();
|
||||
|
||||
out << *(l_pathFeature)->path() << ' ' << *(l_pathFeature->featureSet())
|
||||
<< endl;
|
||||
|
||||
#ifdef DEBUG
|
||||
// this will cause errors if gTopOfStack is not set properly
|
||||
FeatureSet *set = l_pathFeature->featureSet()->evaluate();
|
||||
out << *set << endl;
|
||||
delete set ;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void PathFeatureList::appendList(PathFeatureList& list)
|
||||
{
|
||||
PathFeatureListIterator l_Iter(list);
|
||||
while ( ++ l_Iter ) {
|
||||
append(l_Iter.key());
|
||||
}
|
||||
}
|
||||
|
||||
PathFeatureList::~PathFeatureList()
|
||||
{
|
||||
clearAndDestroy();
|
||||
}
|
||||
154
cde/programs/dtinfo/DtMmdb/StyleSheet/PathTable.h
Normal file
154
cde/programs/dtinfo/DtMmdb/StyleSheet/PathTable.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/* $XConsortium: PathTable.h /main/4 1996/08/21 15:50:37 drk $ */
|
||||
#ifndef _PathTable_h
|
||||
#define _PathTable_h
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
|
||||
#else
|
||||
#include "dti_cc/CC_Dlist.h"
|
||||
#include "dti_cc/cc_hdict.h"
|
||||
#endif
|
||||
|
||||
#include <stream.h>
|
||||
#include "Types.h"
|
||||
#include "SymTab.h"
|
||||
#include "SSPath.h"
|
||||
#include "BitVector.h"
|
||||
|
||||
class Feature;
|
||||
class FeatureSet;
|
||||
|
||||
#define OP_ONE "?"
|
||||
#define OP_MANY "*"
|
||||
typedef unsigned int LetterType;
|
||||
|
||||
class EncodedPath
|
||||
{
|
||||
int f_patternSize;
|
||||
int f_size;
|
||||
LetterType* f_array;
|
||||
|
||||
LetterType f_wildCard;
|
||||
LetterType f_unlimitedWildCard;
|
||||
|
||||
hashTable<LetterType, BitVector> f_SVectors;
|
||||
|
||||
BitVector* f_copyOfS; // copy of S vector, used in match()
|
||||
|
||||
public:
|
||||
EncodedPath(SSPath* p, unsigned int asPattern = false);
|
||||
~EncodedPath();
|
||||
|
||||
int length() { return f_size; };
|
||||
int patternLength() { return f_patternSize; };
|
||||
|
||||
unsigned int match(EncodedPath& p, SSPath* Pattern, SSPath* Elements);
|
||||
}
|
||||
;
|
||||
|
||||
class basePathFeature
|
||||
{
|
||||
|
||||
protected:
|
||||
SSPath* f_path;
|
||||
FeatureSet* f_featureSet;
|
||||
|
||||
public:
|
||||
|
||||
basePathFeature(SSPath* p=0, FeatureSet* f=0):
|
||||
f_path(p), f_featureSet(f) {};
|
||||
~basePathFeature();
|
||||
|
||||
unsigned int operator==(const basePathFeature&) const;
|
||||
|
||||
SSPath* path() { return f_path; };
|
||||
FeatureSet* featureSet() { return f_featureSet; };
|
||||
|
||||
void setPath(SSPath* p) { f_path = p; };
|
||||
void setFeatureSet(FeatureSet* fs) { f_featureSet = fs; };
|
||||
};
|
||||
|
||||
class PathFeature : public basePathFeature
|
||||
{
|
||||
unsigned int f_id;
|
||||
EncodedPath* f_encodedPath;
|
||||
|
||||
public:
|
||||
PathFeature(SSPath* p,FeatureSet* f,EncodedPath* e=0, unsigned int id=0):
|
||||
f_encodedPath(e), f_id(id), basePathFeature(p, f) {};
|
||||
~PathFeature();
|
||||
|
||||
EncodedPath* encodedPath() { return f_encodedPath; };
|
||||
unsigned int id() { return f_id; };
|
||||
|
||||
void setEncodedPath(EncodedPath* e) { f_encodedPath = e; };
|
||||
void setID(int x) { f_id = x; };
|
||||
|
||||
unsigned int operator==(const PathFeature&) const;
|
||||
|
||||
unsigned int match(SSPath& p);
|
||||
};
|
||||
|
||||
class PathFeatureList : public CC_TPtrDlist<PathFeature>
|
||||
{
|
||||
|
||||
public:
|
||||
PathFeatureList() {};
|
||||
~PathFeatureList();
|
||||
|
||||
void appendList(PathFeatureList&);
|
||||
};
|
||||
|
||||
typedef CC_TPtrDlistIterator<PathFeature> PathFeatureListIterator;
|
||||
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// class PathTable
|
||||
//
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef CC_TPtrDlist<PathFeature>* CC_TPtrDlist_PathFeature_Ptr_T;
|
||||
|
||||
class PathTable
|
||||
{
|
||||
public:
|
||||
PathTable();
|
||||
~PathTable();
|
||||
|
||||
// add a path and associated raw feature set
|
||||
// this should only be called by the style sheet parser to build this internal
|
||||
// table
|
||||
//
|
||||
// Assume that the paths are passed in in left to right order. i.e.,
|
||||
// in the order
|
||||
// "TITLE SECTION"
|
||||
// "TITLE CHAPTER"
|
||||
// with the example shown above.
|
||||
//
|
||||
//void addPathFeatureSet(Path*, FeatureSet *rawFeatureSet);
|
||||
void addPathFeatureSet(PathFeature*);
|
||||
|
||||
// returns a NULL value if no feature set is available at this point
|
||||
// this "new"s a new feature set, and the caller is responsible for
|
||||
// deleting the object
|
||||
FeatureSet* getFeatureSet(SSPath&);
|
||||
|
||||
friend ostream& operator<<(ostream&, PathTable&);
|
||||
|
||||
private:
|
||||
CC_TPtrDlist<PathFeature> f_pathFeatureList;
|
||||
CC_TPtrDlist_PathFeature_Ptr_T *f_lastSymIndex;
|
||||
unsigned int f_lastSymIndexCount ;
|
||||
|
||||
private:
|
||||
void initLastSymIndex();
|
||||
unsigned int findIndex(SSPath&);
|
||||
FeatureSet* getFeatureSet(int bucketIndex, SSPath&, int& pathId);
|
||||
};
|
||||
|
||||
extern PathTable* gPathTab;
|
||||
|
||||
#endif /* _PathTable_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
118
cde/programs/dtinfo/DtMmdb/StyleSheet/Renderer.h
Normal file
118
cde/programs/dtinfo/DtMmdb/StyleSheet/Renderer.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/* $XConsortium: Renderer.h /main/3 1996/06/11 17:08:07 cde-hal $ */
|
||||
|
||||
#ifndef _Renderer_h
|
||||
#define _Renderer_h 1
|
||||
|
||||
#include "Feature.h"
|
||||
#include "Exceptions.hh"
|
||||
|
||||
/* **************************************************************
|
||||
* class Renderer
|
||||
|
||||
the Renderer is responsible for taking the style sheet features
|
||||
matched with an ELEMENT and using them to guide the drawing of the
|
||||
ELEMENT data on the page
|
||||
************************************************************** */
|
||||
|
||||
/* **************************************************************
|
||||
The symbol table supplied is common to the Node Parser,
|
||||
Style Sheet parser and the Renderer.
|
||||
* ************************************************************** */
|
||||
|
||||
//class FeatureSet;
|
||||
|
||||
class Renderer : public Destructable
|
||||
{
|
||||
public:
|
||||
Renderer() {};
|
||||
~Renderer() {};
|
||||
|
||||
virtual FeatureSet *initialize() = 0; /* return default feature set */
|
||||
|
||||
/* -------- Begin Element -------- */
|
||||
/* ************************************************************
|
||||
* called when a new ELEMENT is found in the document
|
||||
* FeatureSet is set of features and values that match with the
|
||||
* ELEMENT as described in the style sheet
|
||||
* ************************************************************ */
|
||||
|
||||
/* returns a non-zero value if element is to be ignored */
|
||||
|
||||
virtual unsigned int
|
||||
BeginElement(const Element &element,
|
||||
const FeatureSet &featureset,
|
||||
const FeatureSet &complete,
|
||||
const FeatureSet &parentComplete) = 0;
|
||||
|
||||
|
||||
/* -------- Data -------- */
|
||||
/* ************************************************************
|
||||
* ELEMENT data passed in (usually text to be displayed)
|
||||
* embedded ELEMENT children are passed in with BeginElement...
|
||||
* ************************************************************ */
|
||||
|
||||
virtual void
|
||||
data(const char *data, unsigned int size) = 0;
|
||||
|
||||
|
||||
/* -------- End Element -------- */
|
||||
/* ************************************************************
|
||||
* End of ELEMENT processing (eg. postfixes, reset pointers etc.)
|
||||
* ************************************************************ */
|
||||
|
||||
virtual void
|
||||
EndElement(const Symbol &element_name) = 0 ;
|
||||
|
||||
/* ************************************************************
|
||||
* Called BEFORE any data processing begins
|
||||
* ************************************************************ */
|
||||
|
||||
virtual void Begin() = 0;
|
||||
|
||||
/* **************************************************************
|
||||
* called after all data has been processed
|
||||
* ************************************************************** */
|
||||
|
||||
virtual void End() = 0;
|
||||
|
||||
|
||||
// These two functions allow a renderer to set up internal variable table.
|
||||
|
||||
/* **************************************************************
|
||||
* pass a variable and a Expression to the renderer and let it decide
|
||||
* whether to accept the variable and the Expression and put them into
|
||||
* the internal variable table.
|
||||
*
|
||||
* non zero return value means that it has been entered into the internal
|
||||
* table
|
||||
*
|
||||
* If gRenderer is set to null while style sheet is parsed, the
|
||||
* accept() function will not be called from style.y.
|
||||
* ************************************************************** */
|
||||
virtual unsigned int accept(const char*, const Expression*) { return 0 ;}
|
||||
|
||||
/* ************************************************************
|
||||
*
|
||||
* evaluate the variable to a FeatureValue
|
||||
*
|
||||
* If gRenderer is set to null while the renderer is running, the
|
||||
* evaluate() function will not be called.
|
||||
* ************************************************************ */
|
||||
virtual FeatureValue* evaluate(const char*) { return 0 ; }
|
||||
|
||||
/* **************************************************************
|
||||
* notifies renderer that the local feature set will be evaluated.
|
||||
* ************************************************************** */
|
||||
virtual void preEvaluate(const Element &) {}
|
||||
|
||||
/* **************************************************************
|
||||
* notifies renderer that the local feature set has been evaluated.
|
||||
* ************************************************************** */
|
||||
virtual void postEvaluate(const Element &) {}
|
||||
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
25
cde/programs/dtinfo/DtMmdb/StyleSheet/RendererHCV.C
Normal file
25
cde/programs/dtinfo/DtMmdb/StyleSheet/RendererHCV.C
Normal file
@@ -0,0 +1,25 @@
|
||||
// $XConsortium: RendererHCV.cc /main/3 1996/06/11 17:08:12 cde-hal $
|
||||
|
||||
#include "RendererHCV.h"
|
||||
|
||||
RendererHCV::~RendererHCV()
|
||||
{
|
||||
f_autoNumberFP.clear();
|
||||
}
|
||||
|
||||
FeatureValue* RendererHCV:: evaluate(const char* variable)
|
||||
{
|
||||
return f_autoNumberFP.evaluate(variable);
|
||||
/*
|
||||
FeatureValue* fv = f_autoNumberFP.evaluate(variable);
|
||||
fv -> print(cerr);
|
||||
return fv;
|
||||
*/
|
||||
}
|
||||
|
||||
unsigned int RendererHCV:: accept(const char* name, const Expression* expr)
|
||||
{
|
||||
return f_autoNumberFP.accept(name, expr);
|
||||
}
|
||||
|
||||
|
||||
44
cde/programs/dtinfo/DtMmdb/StyleSheet/RendererHCV.h
Normal file
44
cde/programs/dtinfo/DtMmdb/StyleSheet/RendererHCV.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/* $XConsortium: RendererHCV.h /main/3 1996/06/11 17:08:17 cde-hal $ */
|
||||
|
||||
#ifndef _RendererHCV_h
|
||||
#define _RendererHCV_h 1
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "HardCopy/autoNumberFP.h"
|
||||
|
||||
// RendererHCV class is a simplified hardcopy renderer responsible
|
||||
// for evaluating feature values specific to hardcopy engine. The
|
||||
// feature values are used by the validator.
|
||||
|
||||
class RendererHCV : public Renderer
|
||||
{
|
||||
public:
|
||||
RendererHCV() {};
|
||||
~RendererHCV() ;
|
||||
|
||||
FeatureSet *initialize() { return 0; };
|
||||
|
||||
unsigned int
|
||||
BeginElement(const Element &element,
|
||||
const FeatureSet &featureset,
|
||||
const FeatureSet &complete,
|
||||
const FeatureSet &parentComplete) { return 0; };
|
||||
|
||||
|
||||
void data(const char *data, unsigned int size) {} ;
|
||||
void EndElement(const Symbol &element_name) {};
|
||||
void Begin() {};
|
||||
void End() {};
|
||||
|
||||
// These two functions allow a renderer to set up internal variable table.
|
||||
unsigned int accept(const char*, const Expression*) ;
|
||||
FeatureValue* evaluate(const char*) ;
|
||||
void preEvaluate(const Element &) {};
|
||||
void postEvaluate(const Element &) {};
|
||||
|
||||
protected:
|
||||
autoNumberFP f_autoNumberFP;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
138
cde/programs/dtinfo/DtMmdb/StyleSheet/Resolver.C
Normal file
138
cde/programs/dtinfo/DtMmdb/StyleSheet/Resolver.C
Normal file
@@ -0,0 +1,138 @@
|
||||
// $XConsortium: Resolver.C /main/5 1996/10/08 19:26:17 cde-hal $
|
||||
#include "Debug.h"
|
||||
#include "Resolver.h"
|
||||
#include "ResolverStack.h"
|
||||
#include "PathTable.h"
|
||||
#include "Renderer.h"
|
||||
#include "Element.h"
|
||||
#include "Feature.h"
|
||||
#include "HardCopy/autoNumberFP.h"
|
||||
|
||||
extern const Element *gCurrentElement ;
|
||||
extern const FeatureSet *gCurrentLocalSet;
|
||||
extern const FeatureSet *gParentCompleteSet;
|
||||
|
||||
Resolver::Resolver(PathTable& pTable, Renderer& r)
|
||||
: f_pathTable(pTable),
|
||||
f_Renderer(r),
|
||||
f_resolverStack()
|
||||
{
|
||||
// have the Renderer install its default values as the bottom item on the
|
||||
// Stack
|
||||
FeatureSet *default_features = f_Renderer.initialize();
|
||||
|
||||
ResolverStackElement *default_element =
|
||||
new ResolverStackElement(new Element(gSymTab->intern("!"),0 , 0, 0),
|
||||
0,
|
||||
default_features);
|
||||
|
||||
f_resolverStack.push(default_element);
|
||||
}
|
||||
|
||||
Resolver::~Resolver()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Resolver::Begin()
|
||||
{
|
||||
// can do any node pre-processing here
|
||||
f_Renderer.Begin();
|
||||
}
|
||||
|
||||
void
|
||||
Resolver::End()
|
||||
{
|
||||
// can do any node post-processing here
|
||||
f_Renderer.End();
|
||||
gAutoNumberFP.resetAllAutoNumbers();
|
||||
}
|
||||
|
||||
unsigned int
|
||||
Resolver::beginElement(Element *element)
|
||||
{
|
||||
//ON_DEBUG(element -> print(cerr));
|
||||
|
||||
// get raw feature set
|
||||
f_path.append(new PathTerm(*element));
|
||||
FeatureSet *rawLocalFeatureSet = f_pathTable.getFeatureSet(f_path);
|
||||
|
||||
// get parent details
|
||||
ResolverStackElement* parent = f_resolverStack.top();
|
||||
|
||||
// qifc:
|
||||
// when rawLocalFeatureSet != 0 to call f_Renderer.preEvaluate is
|
||||
// too restrictive. Comment out
|
||||
//
|
||||
//if (rawLocalFeatureSet)
|
||||
gAutoNumberFP.beginElement(*element);
|
||||
|
||||
FeatureSet *localFeatureSet = new FeatureSet;
|
||||
|
||||
gCurrentElement = element ;
|
||||
gCurrentLocalSet = localFeatureSet ;
|
||||
gParentCompleteSet = &parent->completeFeatureSet() ;
|
||||
|
||||
//ON_DEBUG(cerr << "Path: " << f_path << endl);
|
||||
if (rawLocalFeatureSet)
|
||||
{
|
||||
// ON_DEBUG(cerr << "rawLocalFeatureSet: " << *rawLocalFeatureSet << endl);
|
||||
|
||||
localFeatureSet = rawLocalFeatureSet->evaluate(localFeatureSet);
|
||||
|
||||
// ON_DEBUG(cerr << "localFeatureSet: " << *localFeatureSet << endl);
|
||||
}
|
||||
|
||||
// qifc:
|
||||
// when rawLocalFeatureSet != 0 to call f_Renderer.postEvaluate is
|
||||
// too restrictive. Comment out
|
||||
//
|
||||
//if (rawLocalFeatureSet)
|
||||
|
||||
// need to create a complete feature set for current element
|
||||
// set is Sl U (Spc - Sl)
|
||||
FeatureSet *completeFeatureSet = new
|
||||
FeatureSet(parent->completeFeatureSet(),
|
||||
*localFeatureSet);
|
||||
|
||||
// add current element to top of stack
|
||||
f_resolverStack.push(
|
||||
new ResolverStackElement(element,
|
||||
localFeatureSet,
|
||||
completeFeatureSet)
|
||||
);
|
||||
|
||||
// tell renderer about new element
|
||||
unsigned int ignore = f_Renderer.BeginElement(*element, *localFeatureSet,
|
||||
*completeFeatureSet,
|
||||
parent->completeFeatureSet());
|
||||
|
||||
if (ignore)
|
||||
{
|
||||
gAutoNumberFP.endElement(element->gi());
|
||||
|
||||
// clean up stack and path
|
||||
delete f_resolverStack.pop();
|
||||
delete f_path.removeLast();
|
||||
}
|
||||
|
||||
return ignore;
|
||||
}
|
||||
|
||||
void Resolver::data(const char* data, unsigned int data_length)
|
||||
{
|
||||
// pass through
|
||||
f_Renderer.data(data, data_length);
|
||||
}
|
||||
|
||||
void Resolver::endElement(const Symbol& s)
|
||||
{
|
||||
// NOTE: may want to pass top of stack to renderer for post element
|
||||
// processing?
|
||||
|
||||
gAutoNumberFP.endElement(s);
|
||||
|
||||
f_Renderer.EndElement(s); // pass through
|
||||
delete f_resolverStack.pop(); // pop stack
|
||||
delete f_path.removeLast(); // remove item from path
|
||||
}
|
||||
61
cde/programs/dtinfo/DtMmdb/StyleSheet/Resolver.h
Normal file
61
cde/programs/dtinfo/DtMmdb/StyleSheet/Resolver.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $XConsortium: Resolver.h /main/4 1996/06/11 17:08:28 cde-hal $ */
|
||||
#ifndef _Resolver_h
|
||||
#define _Resolver_h
|
||||
|
||||
class Element;
|
||||
class Symbol;
|
||||
class FeatureSet;
|
||||
class PathTable;
|
||||
class Renderer;
|
||||
class ResolverStack;
|
||||
|
||||
#include "SSPath.h"
|
||||
#include "ResolverStack.h"
|
||||
#include "Exceptions.hh"
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
|
||||
the Resolver is responsible for taking input from the NodeParser,
|
||||
getting a feature set from the Style Sheet and passing it on to a
|
||||
Renderer
|
||||
|
||||
- get Element input from NodeParser
|
||||
- consult Style Sheet PathTable to get raw FeatureSet
|
||||
- evaluate feature set to resolve variables and expressions
|
||||
- merge with parent complete feature set to get complete feature
|
||||
set
|
||||
- pass data to Renderer (Element, localFeatures, completeFeatures)
|
||||
|
||||
* ************************************************************** */
|
||||
|
||||
|
||||
|
||||
class Resolver : public Destructable
|
||||
{
|
||||
public:
|
||||
Resolver(PathTable& pTable, Renderer& r);
|
||||
~Resolver();
|
||||
|
||||
// beginElement returns a non-zero value if element is to be ignored
|
||||
unsigned int beginElement(Element*);
|
||||
void data(const char* data, unsigned int data_length);
|
||||
void endElement(const Symbol&);
|
||||
|
||||
// called before any data
|
||||
virtual void Begin();
|
||||
// called after all data
|
||||
virtual void End();
|
||||
|
||||
private:
|
||||
SSPath f_path ;
|
||||
ResolverStack f_resolverStack;
|
||||
PathTable &f_pathTable;
|
||||
|
||||
// NOTE: this one could be a pointer so we can change them on the fly
|
||||
Renderer &f_Renderer;
|
||||
|
||||
};
|
||||
|
||||
#endif /* _Resolver_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
65
cde/programs/dtinfo/DtMmdb/StyleSheet/ResolverStack.C
Normal file
65
cde/programs/dtinfo/DtMmdb/StyleSheet/ResolverStack.C
Normal file
@@ -0,0 +1,65 @@
|
||||
// $XConsortium: ResolverStack.cc /main/3 1996/06/11 17:08:33 cde-hal $
|
||||
#include "ResolverStack.h"
|
||||
|
||||
#include "Element.h"
|
||||
#include "Feature.h"
|
||||
|
||||
|
||||
// we have the responsibility of deleting these guys
|
||||
|
||||
ResolverStackElement::ResolverStackElement(Element *element,
|
||||
FeatureSet *local,
|
||||
FeatureSet *complete)
|
||||
: f_element(element),
|
||||
f_localFeatureSet(local),
|
||||
f_completeFeatureSet(complete)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ResolverStackElement::~ResolverStackElement()
|
||||
{
|
||||
delete f_element;
|
||||
delete f_localFeatureSet;
|
||||
delete f_completeFeatureSet ;
|
||||
}
|
||||
|
||||
// required by CC_TPtrDlist
|
||||
int
|
||||
ResolverStackElement::operator==(const ResolverStackElement &stack_element)
|
||||
{
|
||||
return
|
||||
stack_element.f_element == f_element &&
|
||||
stack_element.f_localFeatureSet == f_localFeatureSet &&
|
||||
stack_element.f_completeFeatureSet == f_completeFeatureSet ;
|
||||
}
|
||||
|
||||
|
||||
ResolverStack::ResolverStack()
|
||||
: CC_TPtrDlist<ResolverStackElement>()
|
||||
{
|
||||
}
|
||||
|
||||
ResolverStack::~ResolverStack()
|
||||
{
|
||||
// delete all remaining items in stack
|
||||
clearAndDestroy();
|
||||
}
|
||||
|
||||
void
|
||||
ResolverStack::push(ResolverStackElement *item)
|
||||
{
|
||||
prepend(item);
|
||||
}
|
||||
|
||||
ResolverStackElement *
|
||||
ResolverStack::top()
|
||||
{
|
||||
return first();
|
||||
}
|
||||
|
||||
ResolverStackElement *
|
||||
ResolverStack::pop()
|
||||
{
|
||||
return removeFirst();
|
||||
}
|
||||
53
cde/programs/dtinfo/DtMmdb/StyleSheet/ResolverStack.h
Normal file
53
cde/programs/dtinfo/DtMmdb/StyleSheet/ResolverStack.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $XConsortium: ResolverStack.h /main/4 1996/08/21 15:50:41 drk $ */
|
||||
#ifndef _ResolverStack_h
|
||||
#define _ResolverStack_h
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
#else
|
||||
//#include <StyleSheet/cde_next.h>
|
||||
#include "dti_cc/CC_Dlist.h"
|
||||
#endif
|
||||
|
||||
class Element ;
|
||||
class FeatureSet ;
|
||||
|
||||
class ResolverStackElement
|
||||
{
|
||||
public:
|
||||
// note, this object will delete these items in its destructor
|
||||
ResolverStackElement(Element*,
|
||||
FeatureSet *local,
|
||||
FeatureSet *complete);
|
||||
|
||||
~ResolverStackElement();
|
||||
|
||||
int
|
||||
operator==(const ResolverStackElement &);
|
||||
|
||||
// only pass out references because we own these guys
|
||||
FeatureSet &completeFeatureSet() { return *f_completeFeatureSet ; }
|
||||
FeatureSet &localFeatureSet() { return *f_localFeatureSet ; }
|
||||
Element &element() { return *f_element ; }
|
||||
|
||||
private:
|
||||
Element *f_element;
|
||||
FeatureSet *f_localFeatureSet;
|
||||
FeatureSet *f_completeFeatureSet;
|
||||
};
|
||||
|
||||
class ResolverStack : private CC_TPtrDlist<ResolverStackElement>
|
||||
{
|
||||
|
||||
public:
|
||||
ResolverStack();
|
||||
~ResolverStack();
|
||||
|
||||
void push(ResolverStackElement*);
|
||||
ResolverStackElement* pop();
|
||||
ResolverStackElement* top();
|
||||
};
|
||||
|
||||
|
||||
#endif /* _ResolverStack_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
134
cde/programs/dtinfo/DtMmdb/StyleSheet/SSPath.C
Normal file
134
cde/programs/dtinfo/DtMmdb/StyleSheet/SSPath.C
Normal file
@@ -0,0 +1,134 @@
|
||||
// $TOG: SSPath.C /main/5 1998/04/17 11:49:33 mgreess $
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
#else
|
||||
#include "dti_cc/CC_Tokenizer.h"
|
||||
#endif
|
||||
|
||||
#include "SSPath.h"
|
||||
#include "Debug.h"
|
||||
#include "SymTab.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
|
||||
unsigned int GI_CASE_SENSITIVE = false;
|
||||
|
||||
PathTerm::PathTerm(const Element& element) :
|
||||
f_element(element), f_PQExpr(0)
|
||||
{
|
||||
}
|
||||
|
||||
PathTerm::PathTerm(const Symbol& symbol, PQExpr* expr) :
|
||||
f_element(symbol), f_PQExpr(expr)
|
||||
{
|
||||
}
|
||||
|
||||
PathTerm::PathTerm(const char* symbol, PQExpr* expr) :
|
||||
f_element(gElemSymTab -> intern(symbol, true)), f_PQExpr(expr)
|
||||
{
|
||||
}
|
||||
|
||||
PathTerm::~PathTerm()
|
||||
{
|
||||
delete f_PQExpr;
|
||||
}
|
||||
|
||||
unsigned int PathTerm::operator ==(const PathTerm&)
|
||||
{
|
||||
MESSAGE(cerr, "PathTerm::operator ==() should not be called");
|
||||
throw(CASTBEEXCEPT badEvaluationException());
|
||||
return 0;
|
||||
}
|
||||
|
||||
ostream& operator <<(ostream& out, PathTerm& pt)
|
||||
{
|
||||
out << pt.symbol() << " (" << int(pt.f_PQExpr) << ") ";
|
||||
return out;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////
|
||||
//
|
||||
////////////////////////////////////////////
|
||||
|
||||
void SSPath::appendPathTerm(PathTerm* pt)
|
||||
{
|
||||
if ( pt -> pqexpr() )
|
||||
f_containPathQualifier = true;
|
||||
|
||||
append(pt);
|
||||
}
|
||||
|
||||
void SSPath::prependPath(SSPath& p)
|
||||
{
|
||||
if ( p.entries() == 0 )
|
||||
return;
|
||||
|
||||
CC_TPtrDlistIterator<PathTerm> l_Iter(p);
|
||||
l_Iter += p.entries();
|
||||
|
||||
PathTerm* l_pathTerm = 0;
|
||||
|
||||
do {
|
||||
//prepend(new PathTerm(*l_Iter.key()));
|
||||
|
||||
l_pathTerm = l_Iter.key();
|
||||
|
||||
prepend(l_pathTerm);
|
||||
|
||||
if ( l_pathTerm -> pqexpr() )
|
||||
f_containPathQualifier = true;
|
||||
|
||||
|
||||
} while ( --l_Iter );
|
||||
}
|
||||
|
||||
SSPath::SSPath()
|
||||
: f_containPathQualifier(false), f_fastGetIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
SSPath::~SSPath()
|
||||
{
|
||||
// clean up memory
|
||||
clearAndDestroy();
|
||||
delete f_fastGetIndex;
|
||||
}
|
||||
|
||||
SSPath::SSPath(char* str, unsigned int AssignId) :
|
||||
f_containPathQualifier(false), f_fastGetIndex(0)
|
||||
{
|
||||
CC_String a(str);
|
||||
CC_Tokenizer next(a);
|
||||
CC_String token;
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
while ( !(token=next()).isNull() ) {
|
||||
append(new PathTerm(token.data(), 0));
|
||||
}
|
||||
#else
|
||||
while ( next() ) {
|
||||
append(new PathTerm(token.data(), 0));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& out, SSPath& p)
|
||||
{
|
||||
CC_TPtrDlistIterator<PathTerm> l_Iter(p);
|
||||
while ( ++l_Iter ) {
|
||||
out << *l_Iter.key() << ' ';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void SSPath::fastGetIndex()
|
||||
{
|
||||
f_fastGetIndex = new value_vector<PathTermPtr>(entries());
|
||||
|
||||
CC_TPtrDlistIterator<PathTerm> l_Iter(*this);
|
||||
int i=0;
|
||||
while ( ++l_Iter ) {
|
||||
(*f_fastGetIndex)[i++] = l_Iter.key();
|
||||
}
|
||||
}
|
||||
|
||||
80
cde/programs/dtinfo/DtMmdb/StyleSheet/SSPath.h
Normal file
80
cde/programs/dtinfo/DtMmdb/StyleSheet/SSPath.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* $XConsortium: SSPath.h /main/4 1996/08/21 15:50:49 drk $ */
|
||||
#ifndef _Path_h
|
||||
#define _Path_h
|
||||
|
||||
#include "SymTab.h"
|
||||
#include "Element.h"
|
||||
#include "PathQualifier.h"
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
|
||||
#else
|
||||
#include "dti_cc/CC_Dlist.h"
|
||||
#include "dti_cc/cc_vvect.h"
|
||||
#endif
|
||||
|
||||
// path term object class
|
||||
// each term is made up of a SGMLGI and an optional
|
||||
// expression.
|
||||
class PathTerm
|
||||
{
|
||||
public:
|
||||
PathTerm(const Element&);
|
||||
PathTerm(const Symbol&, PQExpr* = 0);
|
||||
PathTerm(const char* symbol, PQExpr* = 0);
|
||||
~PathTerm();
|
||||
|
||||
unsigned int operator ==(const PathTerm&);
|
||||
|
||||
const Element& element() { return f_element; };
|
||||
const Symbol& symbol() { return f_element.gi(); };
|
||||
PQExpr* pqexpr() { return f_PQExpr; };
|
||||
|
||||
friend ostream& operator <<(ostream&, PathTerm&);
|
||||
|
||||
private:
|
||||
const Element f_element;
|
||||
PQExpr* f_PQExpr;
|
||||
};
|
||||
|
||||
typedef PathTerm* PathTermPtr;
|
||||
|
||||
////////////////////////////////////////////
|
||||
// path of path terms
|
||||
////////////////////////////////////////////
|
||||
class SSPath : public CC_TPtrDlist<PathTerm>
|
||||
{
|
||||
|
||||
private:
|
||||
unsigned int f_containPathQualifier;
|
||||
value_vector<PathTermPtr>* f_fastGetIndex;
|
||||
|
||||
public:
|
||||
SSPath(char*, unsigned int assignId); // for test purpose
|
||||
SSPath();
|
||||
~SSPath();
|
||||
|
||||
// this call update f_containPathQualifier field
|
||||
void appendPathTerm(PathTerm*);
|
||||
|
||||
unsigned int containSelector() { return f_containPathQualifier; };
|
||||
|
||||
// prepend p to this. Elements in p are added to this.
|
||||
void prependPath(SSPath& p);
|
||||
|
||||
// Set up an index so that the random access to elements in the list can
|
||||
// be O(1). No range checking is performed.
|
||||
// Set up the index by calling fastGetIndex() before any fastGetAt() call.
|
||||
void fastGetIndex();
|
||||
PathTerm* fastGetAt(unsigned int i) { return (*f_fastGetIndex)[i]; };
|
||||
|
||||
friend ostream& operator<< (ostream&, SSPath&);
|
||||
};
|
||||
|
||||
typedef CC_TPtrDlist<char> charPtrDlist;
|
||||
|
||||
extern unsigned int gGI_CASE_SENSITIVE;
|
||||
|
||||
#endif /* _Path_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
285
cde/programs/dtinfo/DtMmdb/StyleSheet/SSTemplates.C
Normal file
285
cde/programs/dtinfo/DtMmdb/StyleSheet/SSTemplates.C
Normal file
@@ -0,0 +1,285 @@
|
||||
// $XConsortium: SSTemplates.C /main/8 1996/10/09 15:29:50 rcs $
|
||||
/*
|
||||
*
|
||||
* (c) Copyright 1996 Digital Equipment Corporation.
|
||||
* (c) Copyright 1996 Hewlett-Packard Company.
|
||||
* (c) Copyright 1996 International Business Machines Corp.
|
||||
* (c) Copyright 1996 Sun Microsystems, Inc.
|
||||
* (c) Copyright 1996 Novell, Inc.
|
||||
* (c) Copyright 1996 FUJITSU LIMITED.
|
||||
* (c) Copyright 1996 Hitachi.
|
||||
*/
|
||||
#ifndef CDE_NEXT
|
||||
//#include "StyleSheet/cde_next.h"
|
||||
#endif
|
||||
|
||||
#include "Attribute.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "AttributeList.h"
|
||||
#include "SSPath.h"
|
||||
#include "SymTab.h"
|
||||
#include "BitVector.h"
|
||||
#include "PathTable.h"
|
||||
#include "Element.h"
|
||||
#include "Expression.h"
|
||||
#include "Resolver.h"
|
||||
#include "Feature.h"
|
||||
#include "ResolverStack.h"
|
||||
#include "FeatureDefDictionary.h"
|
||||
|
||||
#ifdef CDE_NEXT
|
||||
#include "dti_cc/cc_hdict.h"
|
||||
#include "dti_cc/CC_Slist.h"
|
||||
#include "dti_cc/CC_Dlist.h"
|
||||
#include "dti_cc/cc_povec.h"
|
||||
#include "dti_cc/cc_vvect.h"
|
||||
#include "dti_cc/cc_pvect.h"
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_FEATURES
|
||||
/* for features test program - jbm */
|
||||
|
||||
typedef Stack<FeatureSet*,dlist_array<FeatureSet> > _stack_fs_orvec_fs_;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Update this field whenever an ID is assigned. - qifan
|
||||
// the largest ID used in f's: 59
|
||||
//
|
||||
|
||||
#if defined(sun) || defined(hpux) || defined (__uxp__) || defined (USL)
|
||||
typedef CC_TPtrSlist<Attribute> _f4_;
|
||||
typedef CC_TPtrSlist<Feature> _f5_;
|
||||
typedef CC_TPtrSlist<PathFeature> _f2_;
|
||||
typedef CC_TPtrSlist<FeatureValue> _f55_;
|
||||
typedef CC_TPtrSlist<FeatureDef> _f56_;
|
||||
typedef CC_TPtrSlist<TypeValues> _f57_;
|
||||
typedef CC_TPtrSlist<char> _f44_;
|
||||
|
||||
typedef CC_TPtrDlist<PathFeature> _f1_;
|
||||
typedef CC_TPtrDlist<Symbol> _f6_;
|
||||
typedef CC_TPtrDlist<ResolverStackElement> _f7_;
|
||||
typedef CC_TPtrDlist<char> _f50_;
|
||||
|
||||
typedef hashTable<SymbolName, unsigned int> _f3_;
|
||||
typedef hashTable<Symbol, Expression> _f8_;
|
||||
typedef hashTable<unsigned int,BitVector> _f9_;
|
||||
|
||||
typedef hashTableIterator<SymbolName,unsigned int> _f13_;
|
||||
typedef hashTableIterator<unsigned int,BitVector> _f21_;
|
||||
typedef hashTableIterator<Symbol, Expression> _hash_dict_iter_sym_exp_;
|
||||
typedef hashTableIterator<FeatureDef, FeatureDef> _f59_;
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
typedef CC_TPtrSlistDictionary<SymbolName,unsigned int> _f31_;
|
||||
typedef CC_TPtrSlistDictionary<unsigned int,BitVector> _f32_;
|
||||
typedef CC_TPtrSlistDictionary<Symbol,Expression> _f33_;
|
||||
typedef CC_TPtrSlistDictionary<SymbolName,unsigned int> _f34_;
|
||||
#endif
|
||||
|
||||
typedef dlist_array<CC_String> _ordvec_cstring_ ;
|
||||
typedef CC_TValSlist<posRecord> _f54_;
|
||||
typedef value_vector<PathTermPtr> _PathTermPtrvalue_vector_;
|
||||
typedef pointer_vector<FeatureValue> _pointer_vector_FeatureValue_;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_IBMR2)
|
||||
|
||||
#pragma define( CC_TPtrSlist<Attribute> )
|
||||
#pragma define( CC_TPtrSlist<Feature> )
|
||||
#pragma define( CC_TPtrSlist<PathFeature> )
|
||||
#pragma define( CC_TPtrSlist<FeatureValue> )
|
||||
#pragma define( CC_TPtrSlist<FeatureDef> )
|
||||
#pragma define( CC_TPtrSlist<TypeValues> )
|
||||
#pragma define( CC_TPtrSlist<char> )
|
||||
|
||||
#pragma define( CC_TPtrDlist<PathFeature> )
|
||||
#pragma define( CC_TPtrDlist<Symbol> )
|
||||
#pragma define( CC_TPtrDlist<ResolverStackElement> )
|
||||
#pragma define( CC_TPtrDlist<char> )
|
||||
|
||||
#pragma define( hashTable<Symbol, Expression> )
|
||||
#pragma define( hashTable<SymbolName, unsigned int> )
|
||||
#pragma define( hashTable<unsigned int,BitVector> )
|
||||
|
||||
#pragma define( hashTableIterator<SymbolName,unsigned int> )
|
||||
#pragma define( hashTableIterator<unsigned int,BitVector> )
|
||||
#pragma define( hashTableIterator<Symbol, Expression> )
|
||||
#pragma define( hashTableIterator<FeatureDef, FeatureDef> )
|
||||
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
#pragma define( CC_TPtrSlistDictionary<SymbolName,unsigned int> )
|
||||
#pragma define( CC_TPtrSlistDictionary<unsigned int,BitVector> )
|
||||
#pragma define( CC_TPtrSlistDictionary<Symbol,Expression> )
|
||||
#pragma define( CC_TPtrSlistDictionary<SymbolName,unsigned int> )
|
||||
#endif
|
||||
|
||||
typedef dlist_array<CC_String> _ordvec_cstring_ ;
|
||||
typedef CC_TValSlist<posRecord> _f54_;
|
||||
typedef value_vector<PathTermPtr> _PathTermPtrvalue_vector_;
|
||||
typedef pointer_vector<FeatureValue> _pointer_vector_FeatureValue_;
|
||||
|
||||
#pragma define( dlist_array<CC_String> )
|
||||
#pragma define( CC_TValSlist<posRecord> )
|
||||
#pragma define( value_vector<PathTermPtr> )
|
||||
#pragma define( pointer_vector<FeatureValue> )
|
||||
#endif
|
||||
|
||||
#ifdef __osf__
|
||||
|
||||
// The following are initializations for a static member
|
||||
// function that the DEC compiler wouldn't let me initialize
|
||||
// in the template definition
|
||||
|
||||
|
||||
CC_Boolean kv_pair<SymbolName, unsigned int>::f_needRemove = FALSE;
|
||||
CC_Boolean kv_pair<unsigned int, BitVector>::f_needRemove = FALSE;
|
||||
CC_Boolean kv_pair<Symbol, Expression>::f_needRemove = FALSE;
|
||||
CC_Boolean kv_pair<FeatureDef, FeatureDef>::f_needRemove = FALSE;
|
||||
|
||||
#pragma define_template CC_TPtrSlist<CC_String>
|
||||
#pragma define_template CC_TPtrDlist<CC_String>
|
||||
|
||||
#pragma define_template CC_TPtrSlist<Attribute>
|
||||
#pragma define_template CC_TPtrSlist<Feature>
|
||||
#pragma define_template CC_TPtrSlist<PathFeature>
|
||||
#pragma define_template CC_TPtrSlist<FeatureValue>
|
||||
#pragma define_template CC_TPtrSlist<FeatureDef>
|
||||
#pragma define_template CC_TPtrSlist<TypeValues>
|
||||
#pragma define_template CC_TPtrSlist<char>
|
||||
|
||||
#pragma define_template CC_TPtrDlist<PathFeature>
|
||||
#pragma define_template CC_TPtrDlist<Symbol>
|
||||
#pragma define_template CC_TPtrDlist<ResolverStackElement>
|
||||
#pragma define_template CC_TPtrDlist<char>
|
||||
|
||||
#pragma define_template hashTable<SymbolName, unsigned int>
|
||||
#pragma define_template hashTable<Symbol, Expression>
|
||||
#pragma define_template hashTable<unsigned int,BitVector>
|
||||
|
||||
#pragma define_template hashTableIterator<SymbolName,unsigned int>
|
||||
#pragma define_template hashTableIterator<unsigned int,BitVector>
|
||||
#pragma define_template hashTableIterator<Symbol, Expression>
|
||||
#pragma define_template hashTableIterator<FeatureDef, FeatureDef>
|
||||
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
#pragma define_template CC_TPtrSlistDictionary<SymbolName,unsigned int>
|
||||
#pragma define_template CC_TPtrSlistDictionary<unsigned int,BitVector>
|
||||
#pragma define_template CC_TPtrSlistDictionary<Symbol,Expression>
|
||||
#pragma define_template CC_TPtrSlistDictionary<SymbolName,unsigned int>
|
||||
#endif
|
||||
|
||||
typedef dlist_array<CC_String> _ordvec_cstring_ ;
|
||||
typedef CC_TValSlist<posRecord> _f54_;
|
||||
typedef value_vector<PathTermPtr> _PathTermPtrvalue_vector_;
|
||||
typedef pointer_vector<FeatureValue> _pointer_vector_FeatureValue_;
|
||||
|
||||
#pragma define_template dlist_array<CC_String>
|
||||
#pragma define_template CC_TValSlist<posRecord>
|
||||
#pragma define_template value_vector<PathTermPtr>
|
||||
#pragma define_template pointer_vector<FeatureValue>
|
||||
|
||||
// unresolved references
|
||||
|
||||
#pragma define_template CC_TPtrDlist<PathTerm>
|
||||
#pragma define_template CC_TPtrDlistIterator<PathTerm>
|
||||
#pragma define_template CC_TValSlistIterator<posRecord>
|
||||
#pragma define_template CC_TPtrSlist<Symbol>
|
||||
#pragma define_template dlist_array<Symbol>
|
||||
#pragma define_template CC_TPtrSlist<ResolverStackElement>
|
||||
#pragma define_template kv_pair<SymbolName, unsigned int>
|
||||
#pragma define_template CC_TPtrSlist<kv_pair<SymbolName, unsigned int> >
|
||||
#pragma define_template pointer_vector<CC_TPtrSlist<kv_pair<SymbolName, unsigned int> > >
|
||||
#pragma define_template CC_TPtrSlist<kv_pair<unsigned int, BitVector> >
|
||||
#pragma define_template pointer_vector<CC_TPtrSlist<kv_pair<unsigned int, BitVector> > >
|
||||
#pragma define_template CC_TPtrSlist<Symbol>
|
||||
#pragma define_template kv_pair<Symbol, Expression>
|
||||
#pragma define_template CC_TPtrSlist<kv_pair<Symbol, Expression> >
|
||||
#pragma define_template pointer_vector<CC_TPtrSlist<kv_pair<Symbol, Expression> > >
|
||||
#pragma define_template CC_TPtrSlist<kv_pair<FeatureDef, FeatureDef> >
|
||||
#pragma define_template pointer_vector<CC_TPtrSlist<kv_pair<FeatureDef, FeatureDef> > >
|
||||
#pragma define_template CC_TValSlist<int>
|
||||
#pragma define_template CC_TValSlistIterator<int>
|
||||
#pragma define_template CC_TValSlistIterator<char>
|
||||
// #pragma define_template CC_TValSlistIterator<char*>
|
||||
// #pragma define_template C_TValSlistIterator<TableDefn*>
|
||||
#pragma define_template kv_pair<unsigned int, BitVector>
|
||||
#pragma define_template kv_pair<FeatureDef, FeatureDef>
|
||||
#pragma define_template CC_TPtrSlist<PathTerm>
|
||||
#endif
|
||||
|
||||
#ifdef USL
|
||||
|
||||
#pragma instantiate CC_TPtrSlist<CC_String>
|
||||
#pragma instantiate CC_TPtrDlist<CC_String>
|
||||
|
||||
#pragma instantiate CC_TPtrSlist<Attribute>
|
||||
#pragma instantiate CC_TPtrSlist<Feature>
|
||||
#pragma instantiate CC_TPtrSlist<PathFeature>
|
||||
#pragma instantiate CC_TPtrSlist<FeatureValue>
|
||||
#pragma instantiate CC_TPtrSlist<FeatureDef>
|
||||
#pragma instantiate CC_TPtrSlist<TypeValues>
|
||||
#pragma instantiate CC_TPtrSlist<char>
|
||||
|
||||
#pragma instantiate CC_TPtrDlist<PathFeature>
|
||||
#pragma instantiate CC_TPtrDlist<Symbol>
|
||||
#pragma instantiate CC_TPtrDlist<ResolverStackElement>
|
||||
#pragma instantiate CC_TPtrDlist<char>
|
||||
|
||||
#pragma instantiate hashTable<SymbolName, unsigned int>
|
||||
#pragma instantiate hashTable<Symbol, Expression>
|
||||
#pragma instantiate hashTable<unsigned int,BitVector>
|
||||
|
||||
#pragma instantiate hashTableIterator<SymbolName,unsigned int>
|
||||
#pragma instantiate hashTableIterator<unsigned int,BitVector>
|
||||
#pragma instantiate hashTableIterator<Symbol, Expression>
|
||||
#pragma instantiate hashTableIterator<FeatureDef, FeatureDef>
|
||||
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
#pragma instantiate CC_TPtrSlistDictionary<SymbolName,unsigned int>
|
||||
#pragma instantiate CC_TPtrSlistDictionary<unsigned int,BitVector>
|
||||
#pragma instantiate CC_TPtrSlistDictionary<Symbol,Expression>
|
||||
#pragma instantiate CC_TPtrSlistDictionary<SymbolName,unsigned int>
|
||||
#endif
|
||||
|
||||
typedef dlist_array<CC_String> _ordvec_cstring_ ;
|
||||
typedef CC_TValSlist<posRecord> _f54_;
|
||||
typedef value_vector<PathTermPtr> _PathTermPtrvalue_vector_;
|
||||
typedef pointer_vector<FeatureValue> _pointer_vector_FeatureValue_;
|
||||
|
||||
#pragma instantiate dlist_array<CC_String>
|
||||
#pragma instantiate CC_TValSlist<posRecord>
|
||||
#pragma instantiate value_vector<PathTermPtr>
|
||||
#pragma instantiate pointer_vector<FeatureValue>
|
||||
|
||||
// unresolved references
|
||||
|
||||
#pragma instantiate CC_TPtrDlist<PathTerm>
|
||||
#pragma instantiate CC_TPtrDlistIterator<PathTerm>
|
||||
#pragma instantiate CC_TValSlistIterator<posRecord>
|
||||
#pragma instantiate CC_TPtrSlist<Symbol>
|
||||
#pragma instantiate dlist_array<Symbol>
|
||||
#pragma instantiate CC_TPtrSlist<ResolverStackElement>
|
||||
#pragma instantiate kv_pair<SymbolName, unsigned int>
|
||||
#pragma instantiate CC_TPtrSlist<kv_pair<SymbolName, unsigned int> >
|
||||
#pragma instantiate pointer_vector<CC_TPtrSlist<kv_pair<SymbolName, unsigned int> > >
|
||||
#pragma instantiate CC_TPtrSlist<kv_pair<unsigned int, BitVector> >
|
||||
#pragma instantiate pointer_vector<CC_TPtrSlist<kv_pair<unsigned int, BitVector> > >
|
||||
#pragma instantiate CC_TPtrSlist<Symbol>
|
||||
#pragma instantiate kv_pair<Symbol, Expression>
|
||||
#pragma instantiate CC_TPtrSlist<kv_pair<Symbol, Expression> >
|
||||
#pragma instantiate pointer_vector<CC_TPtrSlist<kv_pair<Symbol, Expression> > >
|
||||
#pragma instantiate CC_TPtrSlist<kv_pair<FeatureDef, FeatureDef> >
|
||||
#pragma instantiate pointer_vector<CC_TPtrSlist<kv_pair<FeatureDef, FeatureDef> > >
|
||||
#pragma instantiate CC_TValSlist<int>
|
||||
#pragma instantiate CC_TValSlistIterator<int>
|
||||
#pragma instantiate CC_TValSlistIterator<char>
|
||||
|
||||
#pragma instantiate kv_pair<unsigned int, BitVector>
|
||||
#pragma instantiate kv_pair<FeatureDef, FeatureDef>
|
||||
#pragma instantiate CC_TPtrSlist<PathTerm>
|
||||
#endif
|
||||
42
cde/programs/dtinfo/DtMmdb/StyleSheet/StyleSheet.C
Normal file
42
cde/programs/dtinfo/DtMmdb/StyleSheet/StyleSheet.C
Normal file
@@ -0,0 +1,42 @@
|
||||
// $XConsortium: StyleSheet.cc /main/3 1996/06/11 17:09:10 cde-hal $
|
||||
|
||||
#include "StyleSheet.h"
|
||||
#include "Types.h"
|
||||
#include "Feature.h"
|
||||
|
||||
PathTable* gPathTab;
|
||||
VariableTable* gVariableTable;
|
||||
SymbolTable* gSymTab;
|
||||
SymbolTable* gElemSymTab;
|
||||
unsigned int gGI_CASE_SENSITIVE;
|
||||
const Element *gCurrentElement ;
|
||||
const FeatureSet *gCurrentLocalSet;
|
||||
const FeatureSet *gParentCompleteSet;
|
||||
|
||||
StyleSheet::StyleSheet(const char* nm)
|
||||
: f_GI_CASE_SENSITIVE(false),
|
||||
f_TopOfStack(0,new FeatureSet(),new FeatureSet())
|
||||
{
|
||||
if (nm==0) {
|
||||
f_name = new char[1];
|
||||
f_name[0] = 0;
|
||||
} else
|
||||
f_name = strdup(nm);
|
||||
|
||||
use();
|
||||
}
|
||||
|
||||
StyleSheet::~StyleSheet()
|
||||
{
|
||||
delete f_name;
|
||||
}
|
||||
|
||||
void
|
||||
StyleSheet::use()
|
||||
{
|
||||
gSymTab = &f_SymTab;
|
||||
gVariableTable = &f_VarTab;
|
||||
gPathTab = &f_PathTab;
|
||||
gElemSymTab = &f_ElemSymTab;
|
||||
gGI_CASE_SENSITIVE = f_GI_CASE_SENSITIVE;
|
||||
}
|
||||
34
cde/programs/dtinfo/DtMmdb/StyleSheet/StyleSheet.h
Normal file
34
cde/programs/dtinfo/DtMmdb/StyleSheet/StyleSheet.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* $XConsortium: StyleSheet.h /main/3 1996/06/11 17:09:16 cde-hal $ */
|
||||
|
||||
#ifndef _StyleSheet_h
|
||||
#define _StyleSheet_h
|
||||
|
||||
#include "SymTab.h"
|
||||
#include "VariableTable.h"
|
||||
#include "PathTable.h"
|
||||
#include "ResolverStack.h"
|
||||
|
||||
class StyleSheet
|
||||
{
|
||||
|
||||
private:
|
||||
SymbolTable f_SymTab;
|
||||
VariableTable f_VarTab;
|
||||
PathTable f_PathTab;
|
||||
SymbolTable f_ElemSymTab;
|
||||
unsigned int f_GI_CASE_SENSITIVE;
|
||||
ResolverStackElement f_TopOfStack;
|
||||
|
||||
char* f_name;
|
||||
|
||||
public:
|
||||
StyleSheet(const char* name = 0);
|
||||
~StyleSheet();
|
||||
|
||||
const char* name() { return f_name; };
|
||||
|
||||
void use();
|
||||
};
|
||||
|
||||
#endif /* _StyleSheet_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
@@ -0,0 +1,9 @@
|
||||
// $XConsortium: StyleSheetExceptions.cc /main/3 1996/06/11 17:09:22 cde-hal $
|
||||
#include "StyleSheetExceptions.h"
|
||||
|
||||
StyleSheetException::~StyleSheetException()
|
||||
{
|
||||
}
|
||||
badEvaluationException::~badEvaluationException()
|
||||
{
|
||||
}
|
||||
136
cde/programs/dtinfo/DtMmdb/StyleSheet/StyleSheetExceptions.h
Normal file
136
cde/programs/dtinfo/DtMmdb/StyleSheet/StyleSheetExceptions.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/* $TOG: StyleSheetExceptions.h /main/4 1998/04/17 11:49:51 mgreess $ */
|
||||
#ifndef _StyleSheetExceptions_h
|
||||
#define _StyleSheetExceptions_h
|
||||
|
||||
#include "Exceptions.hh"
|
||||
#include "SymTab.h"
|
||||
|
||||
#if defined(linux)
|
||||
#define CASTEXCEPT (Exception*)
|
||||
#define CASTBCEXCEPT (badCastException*)
|
||||
#define CASTBEEXCEPT (badEvaluationException*)
|
||||
#define CASTDPEXCEPT (docParserException*)
|
||||
#define CASTDPUCEXCEPT (docParserUnexpectedCharacter*)
|
||||
#define CASTDPUTEXCEPT (docParserUnexpectedTag*)
|
||||
#define CASTDPUDEXCEPT (docParserUnexpectedData*)
|
||||
#define CASTDPUEEXCEPT (docParserUnexpectedEof*)
|
||||
#define CASTSSEXCEPT (StyleSheetException*)
|
||||
#define CASTSSSEEXCEPT (StyleSheetSyntaxError*)
|
||||
#define CASTUAEXCEPT (undefinedAttributeException*)
|
||||
#define CASTUTEXCEPT (unknownTagException*)
|
||||
#define CASTUVEXCEPT (undefinedVariableException*)
|
||||
#else
|
||||
#define CASTEXCEPT
|
||||
#define CASTBCEXCEPT
|
||||
#define CASTBEEXCEPT
|
||||
#define CASTDPEXCEPT
|
||||
#define CASTDPUCEXCEPT
|
||||
#define CASTDPUTEXCEPT
|
||||
#define CASTDPUDEXCEPT
|
||||
#define CASTDPUEEXCEPT
|
||||
#define CASTSSEXCEPT
|
||||
#define CASTSSSEEXCEPT
|
||||
#define CASTUAEXCEPT
|
||||
#define CASTUTEXCEPT
|
||||
#define CASTUVEXCEPT
|
||||
#endif
|
||||
|
||||
class StyleSheetException : public Exception
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(StyleSheetException, Exception);
|
||||
virtual ~StyleSheetException();
|
||||
};
|
||||
|
||||
class StyleSheetSyntaxError : public StyleSheetException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(StyleSheetSyntaxError, StyleSheetException);
|
||||
|
||||
};
|
||||
|
||||
class badEvaluationException : public StyleSheetException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(badEvaluationException, StyleSheetException);
|
||||
|
||||
virtual ~badEvaluationException();
|
||||
};
|
||||
|
||||
class badCastException : public StyleSheetException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(badCastException, StyleSheetException);
|
||||
};
|
||||
|
||||
class undefinedVariableException : public badEvaluationException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(undefinedVariableException, badEvaluationException);
|
||||
|
||||
undefinedVariableException(const Symbol &v)
|
||||
: badEvaluationException(),
|
||||
f_variable_name(v)
|
||||
{}
|
||||
|
||||
private:
|
||||
Symbol f_variable_name;
|
||||
|
||||
};
|
||||
|
||||
class undefinedAttributeException : public badEvaluationException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(undefinedAttributeException, badEvaluationException);
|
||||
|
||||
undefinedAttributeException(const Symbol &a)
|
||||
: badEvaluationException(),
|
||||
f_attribute_name(a)
|
||||
{}
|
||||
|
||||
private:
|
||||
Symbol f_attribute_name;
|
||||
};
|
||||
|
||||
class docParserException : public Exception
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(docParserException, Exception);
|
||||
};
|
||||
|
||||
class unknownTagException : public docParserException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(unknownTagException, docParserException);
|
||||
|
||||
};
|
||||
|
||||
class docParserUnexpectedCharacter : public docParserException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(docParserUnexpectedCharacter, docParserException);
|
||||
|
||||
};
|
||||
class docParserUnexpectedTag : public docParserException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(docParserUnexpectedTag, docParserException);
|
||||
|
||||
};
|
||||
class docParserUnexpectedData : public docParserException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(docParserUnexpectedData, docParserException);
|
||||
|
||||
};
|
||||
class docParserUnexpectedEof : public docParserException
|
||||
{
|
||||
public:
|
||||
DECLARE_EXCEPTION(docParserUnexpectedEof, docParserException);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* _StyleSheetExceptions_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
154
cde/programs/dtinfo/DtMmdb/StyleSheet/SymTab.C
Normal file
154
cde/programs/dtinfo/DtMmdb/StyleSheet/SymTab.C
Normal file
@@ -0,0 +1,154 @@
|
||||
// $XConsortium: SymTab.cc /main/4 1996/06/11 17:09:34 cde-hal $
|
||||
#include "SymTab.h"
|
||||
SymbolName::SymbolName(const char *name)
|
||||
: CC_String(name)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int SymbolName::operator==(const SymbolName &string)
|
||||
{
|
||||
return !compareTo(string, exact);
|
||||
}
|
||||
|
||||
unsigned
|
||||
SymbolTable::hashsym(const SymbolName &string)
|
||||
{
|
||||
return string.hash();
|
||||
}
|
||||
|
||||
|
||||
|
||||
SymbolTable::SymbolTable()
|
||||
: hashTable<SymbolName, unsigned int>(hashsym),
|
||||
f_IDsAssigned(0)
|
||||
{
|
||||
f_wildCardId = intern("?", true).id();
|
||||
f_unlimitedWildCardId = intern("*", true).id();
|
||||
}
|
||||
|
||||
SymbolTable::~SymbolTable()
|
||||
{
|
||||
gSymTab = 0;
|
||||
// cleanup after ourselves
|
||||
clearAndDestroy();
|
||||
}
|
||||
|
||||
|
||||
const Symbol
|
||||
SymbolTable::intern(const char *name, unsigned int assignId)
|
||||
{
|
||||
//cerr << "intern(): name =<" << name << "> " << "this=" << (void*)this << "\n";
|
||||
|
||||
SymbolName sym_name(name);
|
||||
|
||||
unsigned int *id;
|
||||
|
||||
const SymbolName *strptr = findKeyAndValue(&sym_name, id);
|
||||
//cerr << "strptr =" << (void*)strptr << "\n";
|
||||
if (!strptr)
|
||||
{
|
||||
SymbolName *newname = new SymbolName(name);
|
||||
id = new unsigned int((assignId) ? ++f_IDsAssigned : 0);
|
||||
|
||||
insertKeyAndValue(newname, id);
|
||||
strptr = newname;
|
||||
}
|
||||
|
||||
/*
|
||||
#ifdef DEBUG
|
||||
{
|
||||
hashTableIterator<SymbolName,unsigned int> next(*this);
|
||||
|
||||
cout << "intern(" << name << ")" << endl;
|
||||
while (++next)
|
||||
cout << "\tKey: " << *next.key() << "\tValue: " << *next.value() << endl;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
//cerr << "Final strptr used =" << (void*)strptr << "\n";
|
||||
|
||||
return Symbol(strptr, *id);
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// class Symbol
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Symbol::Symbol(const SymbolName *name, unsigned int x)
|
||||
: f_name(name), f_id(x)
|
||||
{
|
||||
}
|
||||
|
||||
Symbol::Symbol(const Symbol &sym)
|
||||
: f_name(sym.f_name), f_id(sym.f_id)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Symbol
|
||||
Symbol::operator=(const Symbol &other)
|
||||
{
|
||||
f_name = other.f_name; return *this ;
|
||||
}
|
||||
|
||||
const char *
|
||||
Symbol::name() const
|
||||
{
|
||||
return *f_name ;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
Symbol::operator==(const Symbol &sym) const
|
||||
{
|
||||
return sym.f_name == f_name ;
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Printing
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
ostream &operator<<(ostream &o, const Symbol &s)
|
||||
{
|
||||
return s.print(o);
|
||||
}
|
||||
ostream &operator<<(ostream &o, const SymbolTable &st)
|
||||
{
|
||||
return st.print(o);
|
||||
}
|
||||
|
||||
ostream &
|
||||
SymbolTable::print(ostream &o) const
|
||||
{
|
||||
hashTableIterator<SymbolName, unsigned int>
|
||||
next(*(hashTable<SymbolName, unsigned int>*)this);
|
||||
|
||||
o << '<' << endl;
|
||||
|
||||
while(++next)
|
||||
o << next.key() << endl;
|
||||
|
||||
o << '>' << endl;
|
||||
|
||||
return o ;
|
||||
|
||||
}
|
||||
|
||||
ostream &
|
||||
Symbol::print(ostream &o) const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
f_name->print(o);
|
||||
return o << '(' << id() << ')';
|
||||
#else
|
||||
return f_name -> print(o);
|
||||
#endif
|
||||
}
|
||||
|
||||
ostream &
|
||||
SymbolName::print(ostream &o) const
|
||||
{
|
||||
return o << data();
|
||||
}
|
||||
|
||||
131
cde/programs/dtinfo/DtMmdb/StyleSheet/SymTab.h
Normal file
131
cde/programs/dtinfo/DtMmdb/StyleSheet/SymTab.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* $XConsortium: SymTab.h /main/5 1996/08/21 15:50:57 drk $ */
|
||||
#ifndef _SymTab_h
|
||||
#define _SymTab_h
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
|
||||
#else
|
||||
#include "dti_cc/CC_String.h"
|
||||
#include "dti_cc/cc_hdict.h"
|
||||
//#include "StyleSheet/cde_next.h"
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/* **************************************************************
|
||||
Creating a Symbol Table Class
|
||||
|
||||
Symbol Table has one user function, intern, which returns a
|
||||
reference to a Symbol
|
||||
|
||||
|
||||
A Symbol can be compared to other symbols using the == operator.
|
||||
Symbols will only be == if they are the same symbol in the same
|
||||
SymbolTable
|
||||
|
||||
* ************************************************************** */
|
||||
|
||||
|
||||
// forward declarations
|
||||
class Symbol;
|
||||
|
||||
/* -------- class SymbolName -------- */
|
||||
// derived from CC_String to give a version of ==
|
||||
|
||||
// should be privately inherited with a few promotions
|
||||
|
||||
class SymbolName : public CC_String
|
||||
{
|
||||
public:
|
||||
SymbolName(const char *);
|
||||
unsigned int operator==(const SymbolName &);
|
||||
ostream &print(ostream &) const ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
SymbolTable derives privately from RWTPtrHashSet so only the
|
||||
SymbolTable has access to internal operations
|
||||
* ************************************************************** */
|
||||
|
||||
class SymbolTable : private hashTable<SymbolName, unsigned int>
|
||||
{
|
||||
public:
|
||||
SymbolTable();
|
||||
~SymbolTable();
|
||||
|
||||
// intern creates symbol if necessary
|
||||
const Symbol intern(const char *name, unsigned int createId = false) ;
|
||||
|
||||
ostream &print(ostream &) const ;
|
||||
|
||||
unsigned int IdsAssigned() {
|
||||
return f_IDsAssigned;
|
||||
};
|
||||
|
||||
unsigned int wildCardId() { return f_wildCardId; };
|
||||
unsigned int unlimitedWildCardId() { return f_unlimitedWildCardId; };
|
||||
|
||||
private:
|
||||
static unsigned hashsym(const SymbolName &);
|
||||
|
||||
unsigned int f_wildCardId;
|
||||
unsigned int f_unlimitedWildCardId;
|
||||
|
||||
unsigned int f_IDsAssigned;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
* class Symbol
|
||||
* ************************************************************** */
|
||||
|
||||
class Symbol
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Symbol(const Symbol &);
|
||||
|
||||
// assignment
|
||||
Symbol operator=(const Symbol &other) ;
|
||||
|
||||
const char *name() const;
|
||||
unsigned int operator==(const Symbol &) const; /* identity operator */
|
||||
|
||||
// some methods need to be public
|
||||
|
||||
ostream &print(ostream &) const ;
|
||||
|
||||
// for path table
|
||||
unsigned int hash() const { return f_name->hash(); }
|
||||
unsigned int id() const { return f_id; }
|
||||
|
||||
protected:
|
||||
// alternate constructor
|
||||
// only SymbolTable::intern can create these
|
||||
Symbol(const SymbolName *name, unsigned int);
|
||||
|
||||
friend const Symbol SymbolTable::intern(const char *, unsigned int assignId);
|
||||
|
||||
private:
|
||||
const SymbolName *f_name ; /* never delete this */
|
||||
unsigned int f_id;
|
||||
};
|
||||
|
||||
|
||||
/* **************************************************************
|
||||
* external declarations
|
||||
* ************************************************************** */
|
||||
|
||||
ostream &operator<<(ostream &, const Symbol&);
|
||||
ostream &operator<<(ostream &, const SymbolTable&);
|
||||
|
||||
|
||||
#endif /* _SymTab_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
19
cde/programs/dtinfo/DtMmdb/StyleSheet/Types.h
Normal file
19
cde/programs/dtinfo/DtMmdb/StyleSheet/Types.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* $XConsortium: Types.h /main/3 1996/06/11 17:09:46 cde-hal $ */
|
||||
#ifndef _Types_h
|
||||
#define _Types_h
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
class VariableTable;
|
||||
class SymbolTable;
|
||||
class ResolverStackElement;
|
||||
class Renderer;
|
||||
|
||||
extern VariableTable *gVariableTable;
|
||||
extern SymbolTable *gSymTab;
|
||||
extern SymbolTable *gElemSymTab;
|
||||
extern Renderer *gRenderer;
|
||||
|
||||
#endif /* _Types_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
61
cde/programs/dtinfo/DtMmdb/StyleSheet/VariableTable.C
Normal file
61
cde/programs/dtinfo/DtMmdb/StyleSheet/VariableTable.C
Normal file
@@ -0,0 +1,61 @@
|
||||
// $XConsortium: VariableTable.cc /main/3 1996/06/11 17:09:55 cde-hal $
|
||||
//
|
||||
#include "Types.h"
|
||||
#include "VariableTable.h"
|
||||
|
||||
static unsigned hash(const Symbol& key)
|
||||
{
|
||||
return key.hash();
|
||||
}
|
||||
|
||||
VariableTable::VariableTable()
|
||||
: hashTable<Symbol,Expression>(hash)
|
||||
{
|
||||
}
|
||||
|
||||
VariableTable::~VariableTable()
|
||||
{
|
||||
clearAndDestroy();
|
||||
}
|
||||
|
||||
unsigned int
|
||||
VariableTable::exists(const Symbol &name) const
|
||||
{
|
||||
return contains(&name);
|
||||
}
|
||||
void
|
||||
VariableTable::enter(const Symbol &name, Expression *value)
|
||||
{
|
||||
Expression *exp = findValue(&name);
|
||||
if (exp)
|
||||
{
|
||||
Symbol *sym = remove(&name);
|
||||
delete sym ;
|
||||
delete exp ;
|
||||
}
|
||||
insertKeyAndValue(new Symbol(name), value);
|
||||
}
|
||||
|
||||
const Expression &
|
||||
VariableTable::lookup(const Symbol &name) const
|
||||
{
|
||||
return *findValue(&name);
|
||||
}
|
||||
|
||||
ostream &
|
||||
VariableTable::print(ostream &o) const
|
||||
{
|
||||
hashTableIterator<Symbol,Expression>
|
||||
next(*(hashTable<Symbol,Expression>*)this); // cast to
|
||||
// non-const
|
||||
|
||||
while (++next)
|
||||
o << *next.key() << "\t" << *next.value() << endl;
|
||||
|
||||
return o << endl;
|
||||
}
|
||||
|
||||
ostream &operator <<(ostream &o, const VariableTable &v)
|
||||
{
|
||||
return v.print(o);
|
||||
}
|
||||
31
cde/programs/dtinfo/DtMmdb/StyleSheet/VariableTable.h
Normal file
31
cde/programs/dtinfo/DtMmdb/StyleSheet/VariableTable.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/* $XConsortium: VariableTable.h /main/4 1996/08/21 15:51:00 drk $ */
|
||||
#ifndef _VariableTable_h
|
||||
#define _VariableTable_h
|
||||
|
||||
#include "SymTab.h"
|
||||
#include "Expression.h"
|
||||
|
||||
#ifndef CDE_NEXT
|
||||
|
||||
#else
|
||||
#include "dti_cc/cc_hdict.h"
|
||||
#endif
|
||||
|
||||
class VariableTable : private hashTable<Symbol, Expression>
|
||||
{
|
||||
public:
|
||||
VariableTable();
|
||||
~VariableTable();
|
||||
|
||||
unsigned int exists(const Symbol &name) const;
|
||||
void enter (const Symbol &name, Expression *value);
|
||||
const Expression &lookup(const Symbol &name) const;
|
||||
|
||||
ostream &print(ostream &) const;
|
||||
|
||||
};
|
||||
|
||||
ostream &operator <<(ostream &o, const VariableTable &v);
|
||||
|
||||
#endif /* _VariableTable_h */
|
||||
/* DO NOT ADD ANY LINES AFTER THIS #endif */
|
||||
2
cde/programs/dtinfo/DtMmdb/StyleSheet/all_tmpls
Normal file
2
cde/programs/dtinfo/DtMmdb/StyleSheet/all_tmpls
Normal file
@@ -0,0 +1,2 @@
|
||||
// all_tmplts - force instantiation of all templates under UXPDS
|
||||
@all
|
||||
502
cde/programs/dtinfo/DtMmdb/StyleSheet/defParser.C
Normal file
502
cde/programs/dtinfo/DtMmdb/StyleSheet/defParser.C
Normal file
@@ -0,0 +1,502 @@
|
||||
// $TOG: defParser.C /main/5 1997/12/23 11:16:25 bill $
|
||||
#ifndef lint
|
||||
static char defParsersccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/90";
|
||||
#endif
|
||||
#define defParserBYACC 1
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stream.h>
|
||||
#include <iostream.h>
|
||||
#include "Debug.h"
|
||||
#include "FeatureDefDictionary.h"
|
||||
|
||||
#ifdef alloca
|
||||
# undef alloca
|
||||
#endif
|
||||
#define alloca(x) (malloc(x))
|
||||
|
||||
def_list_t* g_def_list = 0;
|
||||
|
||||
extern void defParsererror(char*);
|
||||
extern int defParserlex();
|
||||
|
||||
#undef defParserwrap
|
||||
|
||||
typedef union
|
||||
{
|
||||
unsigned char charData;
|
||||
unsigned char* charPtrData;
|
||||
int intData;
|
||||
float realData;
|
||||
FeatureValue* valueData;
|
||||
|
||||
defv_t* valueListPtrData;
|
||||
TypeValues* typeValuesPtrData;
|
||||
type_values_list_t* typeValuesListPtrData;
|
||||
|
||||
def_list_t* defListPtrData;
|
||||
FeatureDef* defPtrData;
|
||||
|
||||
} defParserSTYPE;
|
||||
#define STAR 257
|
||||
#define COMMA 258
|
||||
#define COLON 259
|
||||
#define SEMI_COLON 260
|
||||
#define FSOPEN 261
|
||||
#define FSCLOSE 262
|
||||
#define OPER_parenopen 263
|
||||
#define OPER_parenclose 264
|
||||
#define INTEGER 265
|
||||
#define REAL 266
|
||||
#define NORMAL_STRING 267
|
||||
#define QUOTED_STRING 268
|
||||
#define REF_NAME 269
|
||||
#define TYPE 270
|
||||
#define ValueListOpt 271
|
||||
#define defParserERRCODE 256
|
||||
short defParserlhs[] = { -1,
|
||||
0, 11, 11, 6, 6, 6, 6, 8, 10, 7,
|
||||
9, 1, 5, 5, 4, 4, 3, 3, 2, 2,
|
||||
2,
|
||||
};
|
||||
short defParserlen[] = { 2,
|
||||
1, 2, 1, 1, 1, 1, 1, 4, 4, 2,
|
||||
2, 1, 3, 1, 4, 1, 3, 1, 1, 1,
|
||||
1,
|
||||
};
|
||||
short defParserdefred[] = { 0,
|
||||
0, 12, 0, 0, 3, 6, 4, 7, 5, 0,
|
||||
11, 0, 10, 0, 2, 0, 14, 0, 0, 0,
|
||||
0, 9, 8, 19, 21, 20, 18, 0, 13, 0,
|
||||
15, 17,
|
||||
};
|
||||
short defParserdgoto[] = { 3,
|
||||
4, 27, 28, 17, 18, 5, 6, 7, 8, 9,
|
||||
10,
|
||||
};
|
||||
short defParsersindex[] = { -256,
|
||||
-258, 0, 0, -240, 0, 0, 0, 0, 0, -256,
|
||||
0, -262, 0, -256, 0, -249, 0, -254, -257, -250,
|
||||
-262, 0, 0, 0, 0, 0, 0, -251, 0, -250,
|
||||
0, 0,
|
||||
};
|
||||
short defParserrindex[] = { 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
|
||||
0, 0, 0, 0, 0, -236, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0,
|
||||
};
|
||||
short defParsergindex[] = { 0,
|
||||
0, -13, 0, 2, 0, -7, 0, 0, 0, 0,
|
||||
11,
|
||||
};
|
||||
#define defParserTABLESIZE 25
|
||||
short defParsertable[] = { 1,
|
||||
1, 11, 15, 21, 23, 22, 30, 16, 1, 2,
|
||||
2, 15, 31, 20, 24, 25, 32, 26, 12, 13,
|
||||
14, 16, 29, 16, 19,
|
||||
};
|
||||
short defParsercheck[] = { 257,
|
||||
257, 260, 10, 258, 262, 260, 258, 270, 0, 267,
|
||||
267, 19, 264, 263, 265, 266, 30, 268, 259, 260,
|
||||
261, 258, 21, 260, 14,
|
||||
};
|
||||
#define defParserFINAL 3
|
||||
#ifndef defParserDEBUG
|
||||
#define defParserDEBUG 0
|
||||
#endif
|
||||
#define defParserMAXTOKEN 271
|
||||
#if defParserDEBUG
|
||||
char *defParsername[] = {
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"STAR","COMMA","COLON",
|
||||
"SEMI_COLON","FSOPEN","FSCLOSE","OPER_parenopen","OPER_parenclose","INTEGER",
|
||||
"REAL","NORMAL_STRING","QUOTED_STRING","REF_NAME","TYPE","ValueListOpt",
|
||||
};
|
||||
char *defParserrule[] = {
|
||||
"$accept : featureDef",
|
||||
"featureDef : DefList",
|
||||
"DefList : DefList Def",
|
||||
"DefList : Def",
|
||||
"Def : CompositeDef",
|
||||
"Def : PrimitiveDef",
|
||||
"Def : DefReference",
|
||||
"Def : WildCardDef",
|
||||
"CompositeDef : Name FSOPEN DefList FSCLOSE",
|
||||
"PrimitiveDef : Name COLON TypeValuesList SEMI_COLON",
|
||||
"DefReference : Name SEMI_COLON",
|
||||
"WildCardDef : STAR SEMI_COLON",
|
||||
"Name : NORMAL_STRING",
|
||||
"TypeValuesList : TypeValuesList COMMA TypeValues",
|
||||
"TypeValuesList : TypeValues",
|
||||
"TypeValues : TYPE OPER_parenopen ValueList OPER_parenclose",
|
||||
"TypeValues : TYPE",
|
||||
"ValueList : ValueList COMMA Value",
|
||||
"ValueList : Value",
|
||||
"Value : INTEGER",
|
||||
"Value : QUOTED_STRING",
|
||||
"Value : REAL",
|
||||
};
|
||||
#endif
|
||||
#define defParserclearin (defParserchar=(-1))
|
||||
#define defParsererrok (defParsererrflag=0)
|
||||
#ifdef defParserSTACKSIZE
|
||||
#ifndef defParserMAXDEPTH
|
||||
#define defParserMAXDEPTH defParserSTACKSIZE
|
||||
#endif
|
||||
#else
|
||||
#ifdef defParserMAXDEPTH
|
||||
#define defParserSTACKSIZE defParserMAXDEPTH
|
||||
#else
|
||||
#define defParserSTACKSIZE 500
|
||||
#define defParserMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
int defParserdebug;
|
||||
int defParsernerrs;
|
||||
int defParsererrflag;
|
||||
int defParserchar;
|
||||
short *defParserssp;
|
||||
defParserSTYPE *defParservsp;
|
||||
defParserSTYPE defParserval;
|
||||
defParserSTYPE defParserlval;
|
||||
short defParserss[defParserSTACKSIZE];
|
||||
defParserSTYPE defParservs[defParserSTACKSIZE];
|
||||
#define defParserstacksize defParserSTACKSIZE
|
||||
|
||||
/*
|
||||
void defParsererror(char *errorstr)
|
||||
{
|
||||
cerr << errorstr ;
|
||||
}
|
||||
*/
|
||||
#define defParserABORT goto defParserabort
|
||||
#define defParserACCEPT goto defParseraccept
|
||||
#define defParserERROR goto defParsererrlab
|
||||
#if defParserDEBUG
|
||||
#ifndef __cplusplus
|
||||
extern char *getenv(const char *);
|
||||
#endif
|
||||
#endif
|
||||
int
|
||||
defParserparse()
|
||||
{
|
||||
register int defParserm, defParsern, defParserstate;
|
||||
#if defParserDEBUG
|
||||
register char *defParsers;
|
||||
|
||||
if (defParsers = getenv("defParserDEBUG"))
|
||||
{
|
||||
defParsern = *defParsers;
|
||||
if (defParsern >= '0' && defParsern <= '9')
|
||||
defParserdebug = defParsern - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
defParsernerrs = 0;
|
||||
defParsererrflag = 0;
|
||||
defParserchar = (-1);
|
||||
|
||||
defParserssp = defParserss;
|
||||
defParservsp = defParservs;
|
||||
*defParserssp = defParserstate = 0;
|
||||
|
||||
defParserloop:
|
||||
if (defParsern = defParserdefred[defParserstate]) goto defParserreduce;
|
||||
if (defParserchar < 0)
|
||||
{
|
||||
if ((defParserchar = defParserlex()) < 0) defParserchar = 0;
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
{
|
||||
defParsers = 0;
|
||||
if (defParserchar <= defParserMAXTOKEN) defParsers = defParsername[defParserchar];
|
||||
if (!defParsers) defParsers = "illegal-symbol";
|
||||
printf("defParserdebug: state %d, reading %d (%s)\n", defParserstate,
|
||||
defParserchar, defParsers);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((defParsern = defParsersindex[defParserstate]) && (defParsern += defParserchar) >= 0 &&
|
||||
defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserchar)
|
||||
{
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
printf("defParserdebug: state %d, shifting to state %d\n",
|
||||
defParserstate, defParsertable[defParsern]);
|
||||
#endif
|
||||
if (defParserssp >= defParserss + defParserstacksize - 1)
|
||||
{
|
||||
goto defParseroverflow;
|
||||
}
|
||||
*++defParserssp = defParserstate = defParsertable[defParsern];
|
||||
*++defParservsp = defParserlval;
|
||||
defParserchar = (-1);
|
||||
if (defParsererrflag > 0) --defParsererrflag;
|
||||
goto defParserloop;
|
||||
}
|
||||
if ((defParsern = defParserrindex[defParserstate]) && (defParsern += defParserchar) >= 0 &&
|
||||
defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserchar)
|
||||
{
|
||||
defParsern = defParsertable[defParsern];
|
||||
goto defParserreduce;
|
||||
}
|
||||
if (defParsererrflag) goto defParserinrecovery;
|
||||
#if 0 // Disable for now
|
||||
#ifdef lint
|
||||
goto defParsernewerror;
|
||||
#endif
|
||||
defParsernewerror:
|
||||
#endif /* 0 */
|
||||
defParsererror("syntax error");
|
||||
#if 0 // Disable for now
|
||||
#ifdef lint
|
||||
goto defParsererrlab;
|
||||
#endif
|
||||
defParsererrlab:
|
||||
#endif /* 0 */
|
||||
++defParsernerrs;
|
||||
defParserinrecovery:
|
||||
if (defParsererrflag < 3)
|
||||
{
|
||||
defParsererrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((defParsern = defParsersindex[*defParserssp]) && (defParsern += defParserERRCODE) >= 0 &&
|
||||
defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserERRCODE)
|
||||
{
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
printf("defParserdebug: state %d, error recovery shifting\
|
||||
to state %d\n", *defParserssp, defParsertable[defParsern]);
|
||||
#endif
|
||||
if (defParserssp >= defParserss + defParserstacksize - 1)
|
||||
{
|
||||
goto defParseroverflow;
|
||||
}
|
||||
*++defParserssp = defParserstate = defParsertable[defParsern];
|
||||
*++defParservsp = defParserlval;
|
||||
goto defParserloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
printf("defParserdebug: error recovery discarding state %d\n",
|
||||
*defParserssp);
|
||||
#endif
|
||||
if (defParserssp <= defParserss) goto defParserabort;
|
||||
--defParserssp;
|
||||
--defParservsp;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (defParserchar == 0) goto defParserabort;
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
{
|
||||
defParsers = 0;
|
||||
if (defParserchar <= defParserMAXTOKEN) defParsers = defParsername[defParserchar];
|
||||
if (!defParsers) defParsers = "illegal-symbol";
|
||||
printf("defParserdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
defParserstate, defParserchar, defParsers);
|
||||
}
|
||||
#endif
|
||||
defParserchar = (-1);
|
||||
goto defParserloop;
|
||||
}
|
||||
defParserreduce:
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
printf("defParserdebug: state %d, reducing by rule %d (%s)\n",
|
||||
defParserstate, defParsern, defParserrule[defParsern]);
|
||||
#endif
|
||||
defParserm = defParserlen[defParsern];
|
||||
defParserval = defParservsp[1-defParserm];
|
||||
switch (defParsern)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
g_def_list = defParservsp[0].defListPtrData;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
defParserval.defListPtrData=defParservsp[-1].defListPtrData;
|
||||
|
||||
if ( defParservsp[0].defPtrData -> type() == FeatureDef::WILDCARD )
|
||||
defParserval.defListPtrData -> prepend(defParservsp[0].defPtrData);
|
||||
else
|
||||
defParserval.defListPtrData -> append(defParservsp[0].defPtrData);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
defParserval.defListPtrData=new def_list_t();
|
||||
defParserval.defListPtrData -> append(defParservsp[0].defPtrData);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
defParserval.defPtrData=defParservsp[0].defPtrData;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
{
|
||||
defParserval.defPtrData=defParservsp[0].defPtrData;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
defParserval.defPtrData=defParservsp[0].defPtrData;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
defParserval.defPtrData=defParservsp[0].defPtrData;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
defParserval.defPtrData= new FeatureDefComposite((char*)defParservsp[-3].charPtrData, defParservsp[-1].defListPtrData);
|
||||
delete defParservsp[-3].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
{
|
||||
defParserval.defPtrData= new FeatureDefPrimitive((char*)defParservsp[-3].charPtrData, defParservsp[-1].typeValuesListPtrData);
|
||||
delete defParservsp[-3].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
{
|
||||
defParserval.defPtrData= new FeatureDefReference((char*)defParservsp[-1].charPtrData);
|
||||
delete defParservsp[-1].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
{
|
||||
defParserval.defPtrData= new FeatureDefWildCard("*");
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
{
|
||||
defParserval.charPtrData=defParservsp[0].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
{
|
||||
defParserval.typeValuesListPtrData=defParservsp[-2].typeValuesListPtrData;
|
||||
defParserval.typeValuesListPtrData -> append(defParservsp[0].typeValuesPtrData);
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
{
|
||||
defParserval.typeValuesListPtrData=new type_values_list_t();
|
||||
defParserval.typeValuesListPtrData -> append(defParservsp[0].typeValuesPtrData);
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
{
|
||||
defParserval.typeValuesPtrData=new TypeValues((char*)defParservsp[-3].charPtrData, defParservsp[-1].valueListPtrData);
|
||||
delete defParservsp[-3].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
{
|
||||
defParserval.typeValuesPtrData=new TypeValues((char*)defParservsp[0].charPtrData, 0);
|
||||
delete defParservsp[0].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
{
|
||||
defParservsp[-2].valueListPtrData -> append(defParservsp[0].valueData);
|
||||
defParserval.valueListPtrData=defParservsp[-2].valueListPtrData;
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
{
|
||||
defParserval.valueListPtrData = new defv_t();
|
||||
defParserval.valueListPtrData -> append(defParservsp[0].valueData);
|
||||
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
{
|
||||
defParserval.valueData=new FeatureValueInt(defParservsp[0].intData);
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
{
|
||||
defParserval.valueData=new FeatureValueString((char*)defParservsp[0].charPtrData);
|
||||
delete defParservsp[0].charPtrData;
|
||||
}
|
||||
break;
|
||||
case 21:
|
||||
{
|
||||
defParserval.valueData=new FeatureValueReal(defParservsp[0].realData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
defParserssp -= defParserm;
|
||||
defParserstate = *defParserssp;
|
||||
defParservsp -= defParserm;
|
||||
defParserm = defParserlhs[defParsern];
|
||||
if (defParserstate == 0 && defParserm == 0)
|
||||
{
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
printf("defParserdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", defParserFINAL);
|
||||
#endif
|
||||
defParserstate = defParserFINAL;
|
||||
*++defParserssp = defParserFINAL;
|
||||
*++defParservsp = defParserval;
|
||||
if (defParserchar < 0)
|
||||
{
|
||||
if ((defParserchar = defParserlex()) < 0) defParserchar = 0;
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
{
|
||||
defParsers = 0;
|
||||
if (defParserchar <= defParserMAXTOKEN) defParsers = defParsername[defParserchar];
|
||||
if (!defParsers) defParsers = "illegal-symbol";
|
||||
printf("defParserdebug: state %d, reading %d (%s)\n",
|
||||
defParserFINAL, defParserchar, defParsers);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (defParserchar == 0) goto defParseraccept;
|
||||
goto defParserloop;
|
||||
}
|
||||
if ((defParsern = defParsergindex[defParserm]) && (defParsern += defParserstate) >= 0 &&
|
||||
defParsern <= defParserTABLESIZE && defParsercheck[defParsern] == defParserstate)
|
||||
defParserstate = defParsertable[defParsern];
|
||||
else
|
||||
defParserstate = defParserdgoto[defParserm];
|
||||
#if defParserDEBUG
|
||||
if (defParserdebug)
|
||||
printf("defParserdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", *defParserssp, defParserstate);
|
||||
#endif
|
||||
if (defParserssp >= defParserss + defParserstacksize - 1)
|
||||
{
|
||||
goto defParseroverflow;
|
||||
}
|
||||
*++defParserssp = defParserstate;
|
||||
*++defParservsp = defParserval;
|
||||
goto defParserloop;
|
||||
defParseroverflow:
|
||||
defParsererror("yacc stack overflow");
|
||||
defParserabort:
|
||||
return (1);
|
||||
defParseraccept:
|
||||
return (0);
|
||||
}
|
||||
33
cde/programs/dtinfo/DtMmdb/StyleSheet/defParser.tab.h
Normal file
33
cde/programs/dtinfo/DtMmdb/StyleSheet/defParser.tab.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/* $XConsortium: defParser.tab.h /main/3 1996/06/11 17:46:23 cde-hal $ */
|
||||
#define STAR 257
|
||||
#define COMMA 258
|
||||
#define COLON 259
|
||||
#define SEMI_COLON 260
|
||||
#define FSOPEN 261
|
||||
#define FSCLOSE 262
|
||||
#define OPER_parenopen 263
|
||||
#define OPER_parenclose 264
|
||||
#define INTEGER 265
|
||||
#define REAL 266
|
||||
#define NORMAL_STRING 267
|
||||
#define QUOTED_STRING 268
|
||||
#define REF_NAME 269
|
||||
#define TYPE 270
|
||||
#define ValueListOpt 271
|
||||
typedef union
|
||||
{
|
||||
unsigned char charData;
|
||||
unsigned char* charPtrData;
|
||||
int intData;
|
||||
float realData;
|
||||
FeatureValue* valueData;
|
||||
|
||||
defv_t* valueListPtrData;
|
||||
TypeValues* typeValuesPtrData;
|
||||
type_values_list_t* typeValuesListPtrData;
|
||||
|
||||
def_list_t* defListPtrData;
|
||||
FeatureDef* defPtrData;
|
||||
|
||||
} YYSTYPE;
|
||||
extern YYSTYPE defParserlval;
|
||||
227
cde/programs/dtinfo/DtMmdb/StyleSheet/defParser.y
Normal file
227
cde/programs/dtinfo/DtMmdb/StyleSheet/defParser.y
Normal file
@@ -0,0 +1,227 @@
|
||||
/* $XConsortium: defParser.y /main/2 1996/11/11 11:51:02 drk $ */
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stream.h>
|
||||
#include <iostream.h>
|
||||
#include "Debug.h"
|
||||
#include "FeatureDefDictionary.h"
|
||||
|
||||
#define alloca(x) (malloc(x))
|
||||
|
||||
def_list_t* g_def_list = 0;
|
||||
|
||||
extern void yyerror(char*);
|
||||
extern int yylex();
|
||||
|
||||
#undef yywrap
|
||||
|
||||
%}
|
||||
|
||||
%union
|
||||
{
|
||||
unsigned char charData;
|
||||
unsigned char* charPtrData;
|
||||
int intData;
|
||||
float realData;
|
||||
FeatureValue* valueData;
|
||||
|
||||
defv_t* valueListPtrData;
|
||||
TypeValues* typeValuesPtrData;
|
||||
type_values_list_t* typeValuesListPtrData;
|
||||
|
||||
def_list_t* defListPtrData;
|
||||
FeatureDef* defPtrData;
|
||||
|
||||
}
|
||||
|
||||
%token<charData>
|
||||
STAR
|
||||
COMMA
|
||||
COLON
|
||||
SEMI_COLON
|
||||
FSOPEN
|
||||
FSCLOSE
|
||||
OPER_parenopen
|
||||
OPER_parenclose
|
||||
|
||||
%token<intData>
|
||||
INTEGER
|
||||
|
||||
%token<realData>
|
||||
REAL
|
||||
|
||||
%token<charPtrData>
|
||||
NORMAL_STRING
|
||||
QUOTED_STRING
|
||||
REF_NAME
|
||||
TYPE
|
||||
|
||||
%type<charPtrData>
|
||||
Name
|
||||
|
||||
%type<valueData>
|
||||
Value
|
||||
|
||||
%type<valueListPtrData>
|
||||
ValueList
|
||||
ValueListOpt
|
||||
|
||||
%type<typeValuesPtrData>
|
||||
TypeValues
|
||||
|
||||
%type<typeValuesListPtrData>
|
||||
TypeValuesList
|
||||
|
||||
%type<defPtrData>
|
||||
Def
|
||||
DefReference
|
||||
CompositeDef
|
||||
WildCardDef
|
||||
PrimitiveDef
|
||||
|
||||
|
||||
%type<defListPtrData>
|
||||
DefList
|
||||
|
||||
%start featureDef
|
||||
|
||||
%%
|
||||
|
||||
featureDef : DefList
|
||||
{
|
||||
g_def_list = $1;
|
||||
}
|
||||
;
|
||||
|
||||
DefList : DefList Def
|
||||
{
|
||||
$$=$1;
|
||||
|
||||
if ( $2 -> type() == FeatureDef::WILDCARD )
|
||||
$$ -> prepend($2);
|
||||
else
|
||||
$$ -> append($2);
|
||||
}
|
||||
|
|
||||
Def
|
||||
{
|
||||
$$=new def_list_t();
|
||||
$$ -> append($1);
|
||||
}
|
||||
;
|
||||
|
||||
Def: CompositeDef
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| PrimitiveDef
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| DefReference
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| WildCardDef
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
CompositeDef : Name FSOPEN DefList FSCLOSE
|
||||
{
|
||||
$$= new FeatureDefComposite((char*)$1, $3);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
PrimitiveDef : Name COLON TypeValuesList SEMI_COLON
|
||||
{
|
||||
$$= new FeatureDefPrimitive((char*)$1, $3);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
DefReference : Name SEMI_COLON
|
||||
{
|
||||
$$= new FeatureDefReference((char*)$1);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
WildCardDef : STAR SEMI_COLON
|
||||
{
|
||||
$$= new FeatureDefWildCard("*");
|
||||
}
|
||||
;
|
||||
|
||||
Name : NORMAL_STRING
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
TypeValuesList : TypeValuesList COMMA TypeValues
|
||||
{
|
||||
$$=$1;
|
||||
$$ -> append($3);
|
||||
}
|
||||
| TypeValues
|
||||
{
|
||||
$$=new type_values_list_t();
|
||||
$$ -> append($1);
|
||||
}
|
||||
;
|
||||
|
||||
TypeValues : TYPE OPER_parenopen ValueList OPER_parenclose
|
||||
{
|
||||
$$=new TypeValues((char*)$1, $3);
|
||||
delete $1;
|
||||
}
|
||||
| TYPE
|
||||
{
|
||||
$$=new TypeValues((char*)$1, 0);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
ValueList : ValueList COMMA Value
|
||||
{
|
||||
$1 -> append($3);
|
||||
$$=$1;
|
||||
}
|
||||
| Value
|
||||
{
|
||||
$$ = new defv_t();
|
||||
$$ -> append($1);
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
Value : INTEGER
|
||||
{
|
||||
$$=new FeatureValueInt($1);
|
||||
}
|
||||
| QUOTED_STRING
|
||||
{
|
||||
$$=new FeatureValueString((char*)$1);
|
||||
delete $1;
|
||||
}
|
||||
| REAL
|
||||
{
|
||||
$$=new FeatureValueReal($1);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
%%
|
||||
|
||||
/*
|
||||
void yyerror(char *errorstr)
|
||||
{
|
||||
cerr << errorstr ;
|
||||
}
|
||||
*/
|
||||
1290
cde/programs/dtinfo/DtMmdb/StyleSheet/defToken.C
Normal file
1290
cde/programs/dtinfo/DtMmdb/StyleSheet/defToken.C
Normal file
File diff suppressed because it is too large
Load Diff
218
cde/programs/dtinfo/DtMmdb/StyleSheet/defToken.l
Normal file
218
cde/programs/dtinfo/DtMmdb/StyleSheet/defToken.l
Normal file
@@ -0,0 +1,218 @@
|
||||
|
||||
%a 30000
|
||||
%e 10000
|
||||
%k 10000
|
||||
%n 10000
|
||||
%o 40000
|
||||
%p 20000
|
||||
|
||||
%{
|
||||
/* $XConsortium: defToken.l /main/5 1996/11/19 16:54:10 drk $ */
|
||||
|
||||
#include <string.h>
|
||||
#include "FeatureDefDictionary.h"
|
||||
#include "defParser.tab.h"
|
||||
#include "Debug.h"
|
||||
#include <iostream.h>
|
||||
|
||||
extern istream *g_yyin;
|
||||
|
||||
#define YY_INPUT(buf,result,max_size)\
|
||||
{\
|
||||
if (g_yyin -> eof()) {\
|
||||
result=0;\
|
||||
} else {\
|
||||
g_yyin -> read((char *)buf, max_size-1); \
|
||||
result = g_yyin -> gcount(); \
|
||||
buf[result] = 0; \
|
||||
}\
|
||||
}
|
||||
|
||||
int yylineno=1;
|
||||
|
||||
unsigned char* defToken_string_buf = new unsigned char[1024];
|
||||
int defToken_string_buf_size = 1024;
|
||||
int defToken_string_buf_content_size = 0;
|
||||
|
||||
unsigned char* new_copy(const unsigned char* str, int size)
|
||||
{
|
||||
unsigned char* x = new unsigned char[ ( size <= 0 ) ? 1 : size + 1];
|
||||
memcpy(x, str, size);
|
||||
x[size] = 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
void addToDefTokenStringBuf(const unsigned char* str, int size)
|
||||
{
|
||||
if ( size <= 0 ) return;
|
||||
|
||||
if ( defToken_string_buf_size - defToken_string_buf_content_size < size ) {
|
||||
defToken_string_buf_size = 2*(size+defToken_string_buf_content_size);
|
||||
unsigned char* x = new unsigned char[defToken_string_buf_size];
|
||||
memcpy(x, defToken_string_buf, defToken_string_buf_content_size);
|
||||
delete defToken_string_buf;
|
||||
defToken_string_buf = x;
|
||||
}
|
||||
|
||||
memcpy(defToken_string_buf + defToken_string_buf_content_size, str, size);
|
||||
defToken_string_buf_content_size += size;
|
||||
defToken_string_buf[defToken_string_buf_content_size] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
%}
|
||||
|
||||
stringprefix ([Ss][Tt][Rr][Ii][Nn][Gg][_][Pp][Rr][Ee][Ff][Ii][Xx])
|
||||
string ([Ss][Tt][Rr][Ii][Nn][Gg])
|
||||
integer ([Ii][Nn][Tt][Ee][Gg][Ee][Rr])
|
||||
array([Aa][Rr][Rr][Aa][Yy])
|
||||
real ([Rr][Ee][Aa][Ll])
|
||||
unit ([Dd][Ii][Mm][Ee][Nn][Ss][Ii][Oo][Nn])
|
||||
unitpixel ([Dd][Ii][Mm][Ee][Nn][Ss][Ii][Oo][Nn][_][Pp][Ii][Xx][Ee][Ll])
|
||||
boolean ([Bb][Oo][Oo][Ll][Ee][Aa][Nn])
|
||||
%x quoted_string
|
||||
|
||||
%%
|
||||
|
||||
^"#".* {
|
||||
}
|
||||
|
||||
"," {
|
||||
return(COMMA);
|
||||
}
|
||||
|
||||
"*" {
|
||||
return(STAR);
|
||||
}
|
||||
|
||||
";" {
|
||||
return(SEMI_COLON);
|
||||
}
|
||||
|
||||
":" {
|
||||
return(COLON);
|
||||
}
|
||||
|
||||
"{" {
|
||||
return(FSOPEN);
|
||||
}
|
||||
|
||||
"}" {
|
||||
return(FSCLOSE);
|
||||
}
|
||||
|
||||
"(" {
|
||||
return(OPER_parenopen);
|
||||
}
|
||||
|
||||
")" {
|
||||
return(OPER_parenclose);
|
||||
}
|
||||
|
||||
|
||||
{stringprefix} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{string} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{integer} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{real} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{unit} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{unitpixel} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{array} {
|
||||
yylval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
{boolean} {
|
||||
yylval.charPtrData =
|
||||
new_copy((unsigned char*)"INTEGER", strlen("INTEGER"));
|
||||
return(TYPE);
|
||||
}
|
||||
|
||||
[0-9]+ {
|
||||
yylval.intData = atoi((char*)yytext);
|
||||
return(INTEGER);
|
||||
}
|
||||
|
||||
[0-9]+"."[0-9]+ {
|
||||
yylval.realData = atof((char*)yytext);
|
||||
return(REAL);
|
||||
}
|
||||
|
||||
\" {
|
||||
BEGIN quoted_string;
|
||||
}
|
||||
|
||||
<quoted_string>\" {
|
||||
|
||||
yylval.charPtrData =
|
||||
new unsigned char[defToken_string_buf_content_size+1];
|
||||
memcpy( yylval.charPtrData,
|
||||
defToken_string_buf,
|
||||
defToken_string_buf_content_size+1
|
||||
);
|
||||
|
||||
defToken_string_buf_content_size = 0;
|
||||
BEGIN 0;
|
||||
|
||||
return(QUOTED_STRING);
|
||||
}
|
||||
|
||||
<quoted_string>. {
|
||||
addToDefTokenStringBuf(yytext, yyleng);
|
||||
}
|
||||
|
||||
"&"[^ \t\n\";.=@+*\/\.\*:?\^,{}\[\]()]+ {
|
||||
yylval.charPtrData =
|
||||
(unsigned char*)strdup((const char*)(yytext+1));
|
||||
return(REF_NAME);
|
||||
}
|
||||
|
||||
[^ \t\n\";.=@+*\/\.\*:?\^,{}\[\]()]+ {
|
||||
yylval.charPtrData =
|
||||
(unsigned char*)strdup((const char*)yytext);
|
||||
return(NORMAL_STRING);
|
||||
}
|
||||
|
||||
[\t] {
|
||||
}
|
||||
|
||||
[\n] {
|
||||
yylineno++;
|
||||
}
|
||||
|
||||
. {
|
||||
}
|
||||
|
||||
|
||||
|
||||
%%
|
||||
|
||||
void yyerror(char* msg)
|
||||
{
|
||||
cerr << "line " << yylineno << ": " << msg;
|
||||
}
|
||||
|
||||
111
cde/programs/dtinfo/DtMmdb/StyleSheet/docparser.C
Normal file
111
cde/programs/dtinfo/DtMmdb/StyleSheet/docparser.C
Normal file
@@ -0,0 +1,111 @@
|
||||
// $XConsortium: docparser.C /main/4 1996/08/21 15:51:05 drk $
|
||||
#include "Debug.h"
|
||||
#include "DocParser.h"
|
||||
#include "Element.h"
|
||||
#include "PathTable.h"
|
||||
#include "Renderer.h"
|
||||
#include "Resolver.h"
|
||||
#include "StyleSheet.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "VariableTable.h"
|
||||
#include <iostream.h>
|
||||
|
||||
Renderer *gRenderer = 0;
|
||||
class TestRenderer : public Renderer
|
||||
{
|
||||
public:
|
||||
|
||||
// inherited virtuals
|
||||
|
||||
void Begin() {} ;
|
||||
void End() {} ;
|
||||
|
||||
FeatureSet *initialize();
|
||||
unsigned int BeginElement(const Element &element,
|
||||
const FeatureSet &featureset,
|
||||
const FeatureSet &complete,
|
||||
const FeatureSet &parentComplete);
|
||||
|
||||
void data(const char *data, unsigned int size);
|
||||
|
||||
void EndElement(const Symbol &element_name);
|
||||
};
|
||||
|
||||
FeatureSet *
|
||||
TestRenderer::initialize()
|
||||
{
|
||||
return new FeatureSet;
|
||||
}
|
||||
unsigned int
|
||||
TestRenderer::BeginElement(const Element &element,
|
||||
const FeatureSet &localset,
|
||||
const FeatureSet &complete,
|
||||
const FeatureSet &/* parentComplete */)
|
||||
{
|
||||
ON_DEBUG(cerr << "TestRenderer::BeginElement()" << endl);
|
||||
|
||||
ON_DEBUG(cerr << localset<< endl);
|
||||
ON_DEBUG(cerr << complete << endl);
|
||||
|
||||
if (localset.lookup(gSymTab->intern("ignore")))
|
||||
return 1 ; // ignore
|
||||
|
||||
cout << element << endl;
|
||||
|
||||
return 0 ; // do not ignore
|
||||
}
|
||||
void
|
||||
TestRenderer::data(const char * data, unsigned int /* size */)
|
||||
{
|
||||
ON_DEBUG(cerr << "TestRenderer::data()" << endl);
|
||||
cout << data ;
|
||||
}
|
||||
void
|
||||
TestRenderer::EndElement(const Symbol &name)
|
||||
{
|
||||
ON_DEBUG(cerr << "TestRenderer::EndElement(" << name << ')' << endl);
|
||||
cout << "</" << name << '>';
|
||||
}
|
||||
void
|
||||
styleerror(char *errorstr)
|
||||
{
|
||||
cerr << errorstr ;
|
||||
}
|
||||
|
||||
// extern FILE *stylein;
|
||||
extern int styleparse();
|
||||
|
||||
extern PathTable *gPathTab;
|
||||
extern VariableTable *gVariableTable ;
|
||||
|
||||
extern istream *g_stylein;
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
INIT_EXCEPTIONS();
|
||||
|
||||
StyleSheet ss ;
|
||||
|
||||
ifstream stylestream(argv[1]);
|
||||
g_stylein = &stylestream;
|
||||
g_stylein->unsetf(ios::skipws);
|
||||
styleparse();
|
||||
|
||||
try
|
||||
{
|
||||
TestRenderer renderer ;
|
||||
Resolver resolver(*gPathTab, renderer);
|
||||
DocParser docparser(resolver);
|
||||
docparser.parse(cin);
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
cerr << "docparser.C: exception thrown" << endl;
|
||||
rethrow;
|
||||
}
|
||||
end_try;
|
||||
|
||||
cout << endl;
|
||||
|
||||
exit (0);
|
||||
}
|
||||
399
cde/programs/dtinfo/DtMmdb/StyleSheet/evaluate.C
Normal file
399
cde/programs/dtinfo/DtMmdb/StyleSheet/evaluate.C
Normal file
@@ -0,0 +1,399 @@
|
||||
// $XConsortium: evaluate.cc /main/3 1996/06/11 17:10:18 cde-hal $
|
||||
#include "Types.h"
|
||||
#include "Expression.h"
|
||||
#include "Feature.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "ResolverStack.h"
|
||||
#include "StyleSheet.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "SymTab.h"
|
||||
#include "VariableTable.h"
|
||||
|
||||
extern const Element *gCurrentElement ;
|
||||
extern const FeatureSet *gCurrentLocalSet;
|
||||
extern const FeatureSet *gParentCompleteSet;
|
||||
|
||||
// unused except by HardCopy
|
||||
Renderer *gRenderer = 0 ;
|
||||
|
||||
void
|
||||
styleerror(char *errorstr)
|
||||
{
|
||||
cerr << "Parse Error: " << errorstr << endl;
|
||||
}
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
INIT_EXCEPTIONS();
|
||||
|
||||
StyleSheet ss;
|
||||
|
||||
FeatureSet fs;
|
||||
|
||||
|
||||
FeatureValue *exp ;
|
||||
|
||||
/* -------- String -------- */
|
||||
fs.add(new Feature(gSymTab->intern("string"),
|
||||
new FeatureValueString("this is a string")));
|
||||
|
||||
/* -------- Symbol -------- */
|
||||
fs.add(new Feature(gSymTab->intern("symbol"),
|
||||
new FeatureValueSymbol(gSymTab->intern("Symbol"))));
|
||||
|
||||
/* -------- Integer -------- */
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int"),
|
||||
new FeatureValueInt(17)));
|
||||
|
||||
/* -------- Real -------- */
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("real"),
|
||||
new FeatureValueReal(42.2)));
|
||||
|
||||
|
||||
/* -------- Integer addition -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(new FeatureValueInt(10)),
|
||||
new ConstantNode(new FeatureValueInt(10)))));
|
||||
|
||||
|
||||
// check cloning
|
||||
FeatureValueExpression ep(*(FeatureValueExpression*)exp);
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int + int"), exp));
|
||||
|
||||
/* -------- Integer subtraction -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::MINUS,
|
||||
new ConstantNode(new FeatureValueInt(3)),
|
||||
new ConstantNode(new FeatureValueInt(127)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int - int"), exp));
|
||||
|
||||
/* -------- Integer division -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
|
||||
new ConstantNode(new FeatureValueInt(10)),
|
||||
new ConstantNode(new FeatureValueInt(2)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int / int"), exp));
|
||||
|
||||
/* -------- Real division -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
|
||||
new ConstantNode(new FeatureValueReal(5)),
|
||||
new ConstantNode(new FeatureValueReal(2)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("real / real"), exp));
|
||||
|
||||
/* -------- Real multiplication -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::TIMES,
|
||||
new ConstantNode(new FeatureValueReal(5.1)),
|
||||
new ConstantNode(new FeatureValueReal(8.7)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("real * real"), exp));
|
||||
|
||||
/* -------- int + real -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(new FeatureValueInt(5)),
|
||||
new ConstantNode(new FeatureValueReal(8.7)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int + real"), exp));
|
||||
|
||||
|
||||
/* -------- real + int -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(new FeatureValueReal(8.7)),
|
||||
new ConstantNode(new FeatureValueInt(5)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("real + int"), exp));
|
||||
|
||||
|
||||
/* -------- now do some variable stuff -------- */
|
||||
|
||||
// empty top of stack item
|
||||
// gTopOfStack = new ResolverStackElement(0,new FeatureSet(),new FeatureSet());
|
||||
|
||||
FeatureSet *localSet = new FeatureSet ;
|
||||
gCurrentElement = 0 ;
|
||||
gCurrentLocalSet = localSet ;
|
||||
gParentCompleteSet = new FeatureSet ;
|
||||
|
||||
// add an element for variable lookup
|
||||
localSet->add(new Feature(gSymTab->intern("size"),
|
||||
new FeatureValueInt(10)));
|
||||
|
||||
// make some variable entries
|
||||
// insert a duplicate to check memory leaks
|
||||
|
||||
gVariableTable->enter(gSymTab->intern("DEFAULT_FONT_FAMILY"),
|
||||
new Expression(new ConstantNode(new FeatureValueString("courier"))));
|
||||
gVariableTable->enter(gSymTab->intern("DEFAULT_FONT_FAMILY"),
|
||||
new Expression(new ConstantNode(new FeatureValueString("helvetica"))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("exp"),
|
||||
new FeatureValueExpression
|
||||
(new Expression (new VariableNode(gSymTab->intern("DEFAULT_FONT_FAMILY"))))));
|
||||
|
||||
CompositeVariableNode *cvn = new CompositeVariableNode;
|
||||
cvn->appendItem(gSymTab->intern("size"));
|
||||
fs.add(new Feature(gSymTab->intern("Xsize"),
|
||||
new FeatureValueExpression(new Expression (cvn))));
|
||||
|
||||
/* -------- dimensions -------- */
|
||||
fs.add(new Feature(gSymTab->intern("dim"),
|
||||
new FeatureValueDimension(new FeatureValueInt(10),
|
||||
FeatureValueDimension::INCH)));
|
||||
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(new FeatureValueInt(5)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(25),
|
||||
FeatureValueDimension::INCH)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int + dim"), exp));
|
||||
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(25),
|
||||
FeatureValueDimension::INCH)),
|
||||
new ConstantNode(new FeatureValueInt(5)))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim + int"), exp));
|
||||
|
||||
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(25),
|
||||
FeatureValueDimension::POINT)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(5),
|
||||
FeatureValueDimension::INCH)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim + dim"), exp));
|
||||
|
||||
/* -------- real * dim -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::TIMES,
|
||||
new ConstantNode
|
||||
(new FeatureValueReal(2.2)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("real * dim"), exp));
|
||||
|
||||
|
||||
/* -------- dim * real -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::TIMES,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)),
|
||||
new ConstantNode
|
||||
(new FeatureValueReal(2.1)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim * real"), exp));
|
||||
|
||||
|
||||
/* -------- dim / real -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)),
|
||||
new ConstantNode
|
||||
(new FeatureValueReal(2.0)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim / real"), exp));
|
||||
|
||||
|
||||
/* -------- real / dim -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
|
||||
new ConstantNode
|
||||
(new FeatureValueReal(11)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(2),
|
||||
FeatureValueDimension::POINT)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("real / dim"), exp));
|
||||
|
||||
|
||||
/* -------- dim * int -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::TIMES,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)),
|
||||
new ConstantNode
|
||||
(new FeatureValueInt(2)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim * int"), exp));
|
||||
|
||||
|
||||
/* -------- int * dim -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::TIMES,
|
||||
new ConstantNode
|
||||
(new FeatureValueInt(2)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int * dim"), exp));
|
||||
|
||||
|
||||
/* -------- dim / int -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)),
|
||||
new ConstantNode
|
||||
(new FeatureValueInt(2)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim / int"), exp));
|
||||
|
||||
|
||||
/* -------- int / dim -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::DIVIDE,
|
||||
new ConstantNode
|
||||
(new FeatureValueInt(22)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int / dim"), exp));
|
||||
|
||||
|
||||
|
||||
/* -------- int - dim -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::MINUS,
|
||||
new ConstantNode
|
||||
(new FeatureValueInt(2)),
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("int - dim"), exp));
|
||||
|
||||
|
||||
/* -------- dim - int -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression
|
||||
(new BinaryOperatorNode(BinaryOperatorNode::MINUS,
|
||||
new ConstantNode
|
||||
(new FeatureValueDimension
|
||||
(new FeatureValueInt(11),
|
||||
FeatureValueDimension::POINT)),
|
||||
new ConstantNode
|
||||
(new FeatureValueInt(2)))));
|
||||
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("dim - int"), exp));
|
||||
|
||||
|
||||
/* -------- String + String -------- */
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(new FeatureValueString("foo")),
|
||||
new ConstantNode(new FeatureValueString("bar")))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("String + String"), exp));
|
||||
|
||||
|
||||
|
||||
/* -------- String + String + String-------- */
|
||||
FeatureValueExpression *exp1 =
|
||||
new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(new FeatureValueString("foo")),
|
||||
new ConstantNode(new FeatureValueString("bar")))));
|
||||
|
||||
|
||||
exp = new FeatureValueExpression
|
||||
(new Expression(new BinaryOperatorNode(BinaryOperatorNode::PLUS,
|
||||
new ConstantNode(exp1),
|
||||
new ConstantNode(new FeatureValueString("baz")))));
|
||||
|
||||
fs.add(new Feature(gSymTab->intern("String + String + String"), exp));
|
||||
|
||||
|
||||
|
||||
/* -------- print out our set -------- */
|
||||
|
||||
cout << fs << endl;
|
||||
|
||||
FeatureSet *evaluated = fs.evaluate();
|
||||
|
||||
cout << *evaluated << endl;
|
||||
|
||||
delete evaluated ;
|
||||
|
||||
|
||||
cout << *gVariableTable << endl;
|
||||
|
||||
// write this guy out that we created at the top
|
||||
cout << ep << endl;
|
||||
|
||||
delete gCurrentLocalSet ;
|
||||
delete gParentCompleteSet ;
|
||||
|
||||
FeatureValueDimension *dtest =
|
||||
new FeatureValueDimension
|
||||
(new FeatureValueDimension(new FeatureValueInt(72),
|
||||
FeatureValue::POINT),
|
||||
FeatureValue::INCH);
|
||||
|
||||
cout << *dtest << endl;
|
||||
cout << (float)*dtest << endl;
|
||||
delete dtest ;
|
||||
|
||||
}
|
||||
66
cde/programs/dtinfo/DtMmdb/StyleSheet/evaluate.test.out
Normal file
66
cde/programs/dtinfo/DtMmdb/StyleSheet/evaluate.test.out
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
string: "this is a string"
|
||||
symbol: Symbol
|
||||
int: 17
|
||||
real: 42.2
|
||||
int + int: (10 + 10)
|
||||
int - int: (3 - 127)
|
||||
int / int: (10 / 2)
|
||||
real / real: (5 / 2)
|
||||
real * real: (5.1 * 8.7)
|
||||
int + real: (5 + 8.7)
|
||||
real + int: (8.7 + 5)
|
||||
exp: DEFAULT_FONT_FAMILY
|
||||
Xsize: size
|
||||
dim: <10 inch>
|
||||
int + dim: (5 + <25 inch>)
|
||||
dim + int: (<25 inch> + 5)
|
||||
dim + dim: (<25 point> + <5 inch>)
|
||||
real * dim: (2.2 * <11 point>)
|
||||
dim * real: (<11 point> * 2.1)
|
||||
dim / real: (<11 point> / 2)
|
||||
real / dim: (11 / <2 point>)
|
||||
dim * int: (<11 point> * 2)
|
||||
int * dim: (2 * <11 point>)
|
||||
dim / int: (<11 point> / 2)
|
||||
int / dim: (22 / <11 point>)
|
||||
int - dim: (2 - <11 point>)
|
||||
dim - int: (<11 point> - 2)
|
||||
}
|
||||
|
||||
{
|
||||
string: "this is a string"
|
||||
symbol: Symbol
|
||||
int: 17
|
||||
real: 42.2
|
||||
int + int: 20
|
||||
int - int: -124
|
||||
int / int: 5
|
||||
real / real: 2.5
|
||||
real * real: 44.37
|
||||
int + real: 13.7
|
||||
real + int: 13.7
|
||||
exp: "helvetica"
|
||||
Xsize: 10
|
||||
dim: <10 inch>
|
||||
int + dim: <30 inch>
|
||||
dim + int: <30 inch>
|
||||
dim + dim: <5.34722 inch>
|
||||
real * dim: <24.2 point>
|
||||
dim * real: <23.1 point>
|
||||
dim / real: <5.5 point>
|
||||
real / dim: <5.5 point>
|
||||
dim * int: <22 point>
|
||||
int * dim: <22 point>
|
||||
dim / int: <5.5 point>
|
||||
int / dim: <2 point>
|
||||
int - dim: <-9 point>
|
||||
dim - int: <9 point>
|
||||
}
|
||||
|
||||
DEFAULT_FONT_FAMILY "helvetica"
|
||||
|
||||
|
||||
(10 + 10)
|
||||
<<72 point> inch>
|
||||
1
|
||||
134
cde/programs/dtinfo/DtMmdb/StyleSheet/feature.C
Normal file
134
cde/programs/dtinfo/DtMmdb/StyleSheet/feature.C
Normal file
@@ -0,0 +1,134 @@
|
||||
// $XConsortium: feature.cc /main/3 1996/06/11 17:10:23 cde-hal $
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "SymTab.h"
|
||||
#include "Feature.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "StyleSheet.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
styleerror(char *errorstr)
|
||||
{
|
||||
cerr << "Parse Error: " << errorstr << endl;
|
||||
}
|
||||
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
INIT_EXCEPTIONS();
|
||||
|
||||
Stack<FeatureSet*,dlist_array<FeatureSet> > *stack;
|
||||
Stack<FeatureSet*,dlist_array<FeatureSet> > stack1 ;
|
||||
Stack<FeatureSet*,dlist_array<FeatureSet> > stack2 ;
|
||||
|
||||
stack1.push(new FeatureSet());
|
||||
stack2.push(new FeatureSet());
|
||||
|
||||
stack = &stack1 ;
|
||||
|
||||
StyleSheet ss ;
|
||||
|
||||
// make sure args are balanced
|
||||
|
||||
/*
|
||||
if (!(argc & 1))
|
||||
cout << "feature [<name> <value>]+" << endl;
|
||||
*/
|
||||
|
||||
for (int i = 1 ; i < argc ; )
|
||||
{
|
||||
switch (argv[i][0])
|
||||
{
|
||||
case '-':
|
||||
// start a new feature set
|
||||
stack = &stack2 ;
|
||||
i++ ;
|
||||
break;
|
||||
case '{':
|
||||
{
|
||||
i++ ;
|
||||
FeatureSet *newset = new FeatureSet();
|
||||
stack->top()->add(new Feature(gSymTab->intern(argv[i++]),
|
||||
new FeatureValueFeatureSet(newset)));
|
||||
stack->push(newset);
|
||||
}
|
||||
break;
|
||||
|
||||
case '}':
|
||||
stack->pop();
|
||||
i++;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
char c = argv[i+1][0] ;
|
||||
FeatureValue *value = 0;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
value = new FeatureValueInt(atoi(argv[i+1]));
|
||||
else if ( c == '\'')
|
||||
value = new FeatureValueSymbol(gSymTab->intern(argv[i+1]));
|
||||
else
|
||||
value = new FeatureValueString(argv[i+1]);
|
||||
|
||||
stack->top()->add(new Feature(gSymTab->intern(argv[i++]),
|
||||
value));
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "************** orig ****************" << endl;
|
||||
cout << *stack1.top() << endl;
|
||||
cout << "************** copy ****************" << endl;
|
||||
|
||||
FeatureSet *copy = new FeatureSet(*stack1.top());
|
||||
|
||||
cout << *copy << endl;
|
||||
delete copy;
|
||||
|
||||
// now test merge
|
||||
|
||||
FeatureSet *merged = new FeatureSet(*stack1.top(), *stack2.top());
|
||||
|
||||
// delete these and check for memory leaks
|
||||
delete stack1.pop();
|
||||
delete stack2.pop();
|
||||
|
||||
cout << "************** merged ****************" << endl;
|
||||
cout << *merged << endl;
|
||||
|
||||
|
||||
try {
|
||||
const Feature *f = merged->deep_lookup("font", "size", 0);
|
||||
cout << "deep_lookup(\"font\", \"size\"): " ;
|
||||
if (f)
|
||||
cout << *f << endl;
|
||||
else
|
||||
cout << "(nil)" << endl;
|
||||
|
||||
// now try it with Symbols
|
||||
Symbol font (gSymTab->intern("font"));
|
||||
Symbol size (gSymTab->intern("size"));
|
||||
f = merged->deep_lookup(&font,
|
||||
&size, 0);
|
||||
cout << "deep_lookup(\"font\", \"size\"): " ;
|
||||
if (f)
|
||||
cout << *f << endl;
|
||||
else
|
||||
cout << "(nil)" << endl;
|
||||
|
||||
}
|
||||
catch_any()
|
||||
{
|
||||
cout << "exception thrown" << endl;
|
||||
}
|
||||
end_try;
|
||||
|
||||
delete merged ;
|
||||
|
||||
}
|
||||
153
cde/programs/dtinfo/DtMmdb/StyleSheet/hardcopy.feature.spec
Normal file
153
cde/programs/dtinfo/DtMmdb/StyleSheet/hardcopy.feature.spec
Normal file
@@ -0,0 +1,153 @@
|
||||
#
|
||||
# hardcopy feature set specification
|
||||
# qfc 12-6-94
|
||||
# modified for dtinfo
|
||||
# cso 12-7-95
|
||||
# modified to support tables (especially CALS tables)
|
||||
# cso 3-21-96
|
||||
# removed activecharset
|
||||
# stevew 6-28-96
|
||||
# modified to support vjustify in row
|
||||
# kamiya 7-12-96
|
||||
# modified to support colsep and rowsep in table features
|
||||
# kamiya 7-31-96
|
||||
# table renamed as tgroup
|
||||
# kamiya 8-19-96
|
||||
# add *real* table
|
||||
# kamiya 8-20-96
|
||||
# removed graphic, add charalign to tgroup
|
||||
# kamiya 8-28-96
|
||||
# removed cols of colformat, add colstart/colend in cell
|
||||
# kamiya 8-29-96
|
||||
#
|
||||
|
||||
border {
|
||||
display : string;
|
||||
thickness : integer;
|
||||
}
|
||||
|
||||
cell {
|
||||
charalign : string;
|
||||
colref : string;
|
||||
colstart : string;
|
||||
colend : string;
|
||||
colsep : integer;
|
||||
rowsep : integer;
|
||||
morerows : integer;
|
||||
justify : string;
|
||||
vjustify : string;
|
||||
}
|
||||
|
||||
colformat {
|
||||
charalign : string;
|
||||
colsep : integer;
|
||||
justify : string ("left", "right", "center", "char");
|
||||
name : string;
|
||||
rowsep : integer;
|
||||
width : integer;
|
||||
}
|
||||
|
||||
font {
|
||||
fallback : string;
|
||||
position : string ("sub", "super", "baseline", "subscript",
|
||||
"superscript");
|
||||
size : integer, dimension_pixel;
|
||||
slant: string ("roman", "italic");
|
||||
spacing : string ("char", "prop");
|
||||
style : string;
|
||||
weight : string ("medium", "bold");
|
||||
width : string ("narrow", "normal");
|
||||
family {
|
||||
name : string;
|
||||
charset : string;
|
||||
foundry : string;
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
content : string;
|
||||
*;
|
||||
}
|
||||
|
||||
header {
|
||||
content : string;
|
||||
*;
|
||||
}
|
||||
|
||||
highlight {
|
||||
bgcolor : string;
|
||||
fgcolor : string;
|
||||
overline: boolean;
|
||||
strikethrough: boolean;
|
||||
underline: boolean;
|
||||
}
|
||||
|
||||
ignore : boolean;
|
||||
|
||||
layout {
|
||||
aspace : integer;
|
||||
bspace : integer;
|
||||
leading : integer;
|
||||
findent : integer;
|
||||
lindent : integer;
|
||||
rindent : integer;
|
||||
flow : string ("verbatim", "filled");
|
||||
justify : string ("left", "right", "center");
|
||||
wrap : string ("block", "join", "none");
|
||||
}
|
||||
|
||||
linebreak : string ("before", "after", "both");
|
||||
|
||||
margin {
|
||||
left : integer;
|
||||
right : integer;
|
||||
top : integer;
|
||||
bottom : integer;
|
||||
}
|
||||
|
||||
medium {
|
||||
orientation : string ("landscape", "portrait");
|
||||
size : string ("letter", "legal", "tabloid", "ledger", "statement",
|
||||
"executive", "a3", "a4", "a5", "b4", "b5", "folio",
|
||||
"quarto");
|
||||
}
|
||||
|
||||
pagebreak : string ("before", "after", "both");
|
||||
|
||||
position {
|
||||
horiz : string ("lcorner", "left", "lmargin", "rcorner", "right",
|
||||
"rmargin", "center");
|
||||
vert : string ("top", "bottom", "middle");
|
||||
}
|
||||
|
||||
prefix{
|
||||
content : string;
|
||||
*;
|
||||
}
|
||||
|
||||
row {
|
||||
rowsep : integer;
|
||||
vjustify : string;
|
||||
}
|
||||
|
||||
suffix{
|
||||
content : string;
|
||||
*;
|
||||
}
|
||||
|
||||
table {
|
||||
colsep : integer;
|
||||
rowsep : integer;
|
||||
frame : string;
|
||||
}
|
||||
|
||||
tgroup {
|
||||
charalign : string;
|
||||
cols : integer;
|
||||
colsep : integer;
|
||||
justify : string;
|
||||
rowsep : integer;
|
||||
vjustify : string;
|
||||
}
|
||||
|
||||
|
||||
135
cde/programs/dtinfo/DtMmdb/StyleSheet/online.feature.spec
Normal file
135
cde/programs/dtinfo/DtMmdb/StyleSheet/online.feature.spec
Normal file
@@ -0,0 +1,135 @@
|
||||
|
||||
#
|
||||
# online feature set specification
|
||||
# qfc 12-6-94
|
||||
# modified for dtinfo
|
||||
# cso 12-7-95
|
||||
# modified to support tables (especially CALS tables)
|
||||
# cso 3-21-96
|
||||
# removed activecharset
|
||||
# stevew 6-28-96
|
||||
# modified to support vjustify in row
|
||||
# kamiya 7-12-96
|
||||
# modified to support colsep and rowsep in table features
|
||||
# kamiya 7-31-96
|
||||
# table renamed as tgroup
|
||||
# kamiya 8-19-96
|
||||
# add *real* table
|
||||
# kamiya 8-20-96
|
||||
# removed graphic, add charalign to tgroup
|
||||
# kamiya 8-28-96
|
||||
# removed cols of colformat, add colstart/colend in cell
|
||||
# kamiya 8-29-96
|
||||
#
|
||||
|
||||
border {
|
||||
display : string;
|
||||
thickness : integer;
|
||||
}
|
||||
|
||||
cell {
|
||||
charalign : string;
|
||||
colref : string;
|
||||
colstart : string;
|
||||
colend : string;
|
||||
colsep : integer;
|
||||
rowsep : integer;
|
||||
morerows : integer;
|
||||
justify : string;
|
||||
vjustify : string;
|
||||
}
|
||||
|
||||
colformat {
|
||||
charalign : string;
|
||||
colsep : integer;
|
||||
justify : string ("left", "right", "center", "char");
|
||||
name : string;
|
||||
rowsep : integer;
|
||||
width : integer;
|
||||
}
|
||||
|
||||
font {
|
||||
fallback : string;
|
||||
position : string ("sub", "super", "baseline", "subscript",
|
||||
"superscript");
|
||||
size : integer, dimension_pixel;
|
||||
slant: string ("roman", "italic");
|
||||
spacing : string ("char", "prop");
|
||||
style : string;
|
||||
weight : string ("medium", "bold");
|
||||
width : string ("narrow", "normal");
|
||||
family {
|
||||
name : string;
|
||||
charset : string;
|
||||
foundry : string;
|
||||
}
|
||||
}
|
||||
|
||||
highlight {
|
||||
bgcolor : string;
|
||||
fgcolor : string;
|
||||
overline: boolean;
|
||||
strikethrough: boolean;
|
||||
underline: boolean;
|
||||
}
|
||||
|
||||
ignore : boolean;
|
||||
|
||||
layout {
|
||||
aspace : integer;
|
||||
bspace : integer;
|
||||
leading : integer;
|
||||
findent : integer;
|
||||
lindent : integer;
|
||||
rindent : integer;
|
||||
flow : string ("verbatim", "filled");
|
||||
justify : string ("left", "right", "center");
|
||||
wrap : string ("block", "join", "none");
|
||||
}
|
||||
|
||||
linebreak : string ("before", "after", "both");
|
||||
|
||||
margin {
|
||||
left : integer;
|
||||
right : integer;
|
||||
top : integer;
|
||||
bottom : integer;
|
||||
}
|
||||
|
||||
position {
|
||||
horiz : string ("lcorner", "left", "lmargin", "rcorner", "right",
|
||||
"rmargin", "center");
|
||||
vert : string ("top", "bottom", "middle");
|
||||
}
|
||||
|
||||
prefix{
|
||||
content : string;
|
||||
*;
|
||||
}
|
||||
|
||||
row {
|
||||
rowsep : integer;
|
||||
vjustify : string;
|
||||
}
|
||||
|
||||
suffix{
|
||||
content : string;
|
||||
*;
|
||||
}
|
||||
|
||||
table {
|
||||
colsep : integer;
|
||||
rowsep : integer;
|
||||
frame : string;
|
||||
}
|
||||
|
||||
tgroup {
|
||||
charalign : string;
|
||||
cols : integer;
|
||||
colsep : integer;
|
||||
justify : string;
|
||||
rowsep : integer;
|
||||
vjustify : string;
|
||||
}
|
||||
|
||||
|
||||
1339
cde/programs/dtinfo/DtMmdb/StyleSheet/style.C
Normal file
1339
cde/programs/dtinfo/DtMmdb/StyleSheet/style.C
Normal file
File diff suppressed because it is too large
Load Diff
57
cde/programs/dtinfo/DtMmdb/StyleSheet/style.tab.h
Normal file
57
cde/programs/dtinfo/DtMmdb/StyleSheet/style.tab.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* $XConsortium: style.tab.h /main/3 1996/06/11 17:46:36 cde-hal $ */
|
||||
#define INTEGER 257
|
||||
#define OPER_equality 258
|
||||
#define OPER_relational 259
|
||||
#define BOOLVAL 260
|
||||
#define REAL 261
|
||||
#define OPER_assign 262
|
||||
#define ARRAYOPEN 263
|
||||
#define ARRAYCLOSE 264
|
||||
#define SEPARATOR 265
|
||||
#define FSOPEN 266
|
||||
#define FSCLOSE 267
|
||||
#define OPER_modify 268
|
||||
#define OPER_parent 269
|
||||
#define OPER_attr 270
|
||||
#define OPER_oneof 271
|
||||
#define OPER_star 272
|
||||
#define OPER_or 273
|
||||
#define OPER_and 274
|
||||
#define OPER_div 275
|
||||
#define OPER_parenopen 276
|
||||
#define OPER_parenclose 277
|
||||
#define OPER_logicalnegate 278
|
||||
#define PMEMOPEN 279
|
||||
#define PMEMCLOSE 280
|
||||
#define OPER_period 281
|
||||
#define OPER_plus 282
|
||||
#define OPER_minus 283
|
||||
#define DIMENSION 284
|
||||
#define NORMAL_STRING 285
|
||||
#define UNIT_STRING 286
|
||||
#define QUOTED_STRING 287
|
||||
#define GI_CASE_SENSITIVE 288
|
||||
#define SGMLGI_STRING 289
|
||||
typedef union
|
||||
{
|
||||
unsigned char charData;
|
||||
unsigned char* charPtrData;
|
||||
unsigned int boolData;
|
||||
int intData;
|
||||
float realData;
|
||||
Expression* expPtrData;
|
||||
TermNode* termNodePtrData;
|
||||
FeatureValue* FeatureValuePtrData;
|
||||
FeatureSet* FeatureSetPtrData;
|
||||
Feature* FeaturePtrData;
|
||||
SSPath* PathPtrData;
|
||||
PathTerm* PathTermPtrData;
|
||||
charPtrDlist* charPtrDlistData;
|
||||
PathFeatureList* PathFeatureListPtrData;
|
||||
CompositeVariableNode* CompositeVariableNodePtrData;
|
||||
|
||||
CC_TPtrSlist<FeatureValue>* FeatureValueSlistPtrData;
|
||||
|
||||
PQExpr* PQExprPtrData;
|
||||
} YYSTYPE;
|
||||
extern YYSTYPE stylelval;
|
||||
893
cde/programs/dtinfo/DtMmdb/StyleSheet/style.y
Normal file
893
cde/programs/dtinfo/DtMmdb/StyleSheet/style.y
Normal file
@@ -0,0 +1,893 @@
|
||||
/* $XConsortium: style.y /main/4 1996/11/11 11:51:33 drk $ */
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stream.h>
|
||||
#include <iostream.h>
|
||||
#include <assert.h>
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "VariableTable.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "Expression.h"
|
||||
#include "SSPath.h"
|
||||
#include "PathTable.h"
|
||||
#include "Renderer.h"
|
||||
#include "PathQualifier.h"
|
||||
#include "Debug.h"
|
||||
#include "ParserConst.h"
|
||||
#include "FeatureDefDictionary.h"
|
||||
#include <utility/funcs.h>
|
||||
|
||||
#include "HardCopy/autoNumberFP.h"
|
||||
extern autoNumberFP gAutoNumberFP;
|
||||
|
||||
|
||||
#define alloca(x) (malloc(x))
|
||||
|
||||
extern void yyerror(char*);
|
||||
extern int yylex();
|
||||
|
||||
extern void enter_sgmlgi_context();
|
||||
|
||||
extern featureDefDictionary* g_FeatureDefDictionary;
|
||||
extern unsigned g_validation_mode;
|
||||
extern unsigned g_hasSemanticError;
|
||||
|
||||
static char localCharToCharPtrBuf[2];
|
||||
|
||||
#undef yywrap
|
||||
|
||||
const char* toUpperCase(unsigned char* string)
|
||||
{
|
||||
static char buffer[512];
|
||||
int j=0;
|
||||
for ( int i=0; i<strlen((const char*)string); i++ )
|
||||
{
|
||||
if (islower(string[i]))
|
||||
buffer[j] = toupper(string[i]) ;
|
||||
else
|
||||
buffer[j] = (char)string[i] ;
|
||||
j++;
|
||||
}
|
||||
buffer[j] = 0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%union
|
||||
{
|
||||
unsigned char charData;
|
||||
unsigned char* charPtrData;
|
||||
unsigned int boolData;
|
||||
int intData;
|
||||
float realData;
|
||||
Expression* expPtrData;
|
||||
TermNode* termNodePtrData;
|
||||
FeatureValue* FeatureValuePtrData;
|
||||
FeatureSet* FeatureSetPtrData;
|
||||
Feature* FeaturePtrData;
|
||||
SSPath* PathPtrData;
|
||||
PathTerm* PathTermPtrData;
|
||||
charPtrDlist* charPtrDlistData;
|
||||
PathFeatureList* PathFeatureListPtrData;
|
||||
CompositeVariableNode* CompositeVariableNodePtrData;
|
||||
|
||||
CC_TPtrSlist<FeatureValue>* FeatureValueSlistPtrData;
|
||||
|
||||
PQExpr* PQExprPtrData;
|
||||
}
|
||||
|
||||
%token<intData>
|
||||
INTEGER
|
||||
OPER_equality
|
||||
OPER_relational
|
||||
|
||||
%token<boolData>
|
||||
BOOLVAL
|
||||
|
||||
%token<realData>
|
||||
REAL
|
||||
|
||||
%token<charData>
|
||||
OPER_assign
|
||||
ARRAYOPEN
|
||||
ARRAYCLOSE
|
||||
SEPARATOR
|
||||
FSOPEN
|
||||
FSCLOSE
|
||||
OPER_modify
|
||||
OPER_parent
|
||||
OPER_attr
|
||||
OPER_oneof
|
||||
OPER_star
|
||||
OPER_or
|
||||
OPER_and
|
||||
OPER_div
|
||||
OPER_parenopen
|
||||
OPER_parenclose
|
||||
OPER_logicalnegate
|
||||
PMEMOPEN
|
||||
PMEMCLOSE
|
||||
OPER_period
|
||||
OPER_plus
|
||||
OPER_minus
|
||||
|
||||
%token<charPtrData>
|
||||
DIMENSION
|
||||
NORMAL_STRING
|
||||
UNIT_STRING
|
||||
QUOTED_STRING
|
||||
GI_CASE_SENSITIVE
|
||||
SGMLGI_STRING
|
||||
|
||||
%type<intData>
|
||||
POSITION_VALUE
|
||||
|
||||
%type<charPtrData>
|
||||
SGMLGI
|
||||
STRING
|
||||
array_name
|
||||
SGMLGI_CONTENT
|
||||
|
||||
%type<charData>
|
||||
OPER_mult
|
||||
OPER_binop
|
||||
OPER_add
|
||||
OPER_feature
|
||||
|
||||
%type<expPtrData>
|
||||
multi_expr
|
||||
simple_expr
|
||||
|
||||
%type<termNodePtrData>
|
||||
term
|
||||
symbol
|
||||
parent
|
||||
attr
|
||||
dimension
|
||||
|
||||
%type<FeatureSetPtrData>
|
||||
featureset
|
||||
feature_list
|
||||
|
||||
%type<FeatureValuePtrData>
|
||||
rhs.gp
|
||||
array
|
||||
array_member
|
||||
|
||||
%type<CompositeVariableNodePtrData>
|
||||
string_list
|
||||
|
||||
%type<FeatureValueSlistPtrData>
|
||||
array_member_list
|
||||
|
||||
%type<FeaturePtrData>
|
||||
feature
|
||||
|
||||
%type<PathPtrData>
|
||||
path_term_list
|
||||
|
||||
%type<PathTermPtrData>
|
||||
path_term
|
||||
|
||||
%type<PathFeatureListPtrData>
|
||||
path_expr_list
|
||||
path_expr
|
||||
|
||||
%type<charPtrDlistData>
|
||||
feature_name_list
|
||||
|
||||
%type<PQExprPtrData>
|
||||
boolean_expr
|
||||
logical_and_expr
|
||||
equality_expr
|
||||
path_selectorOPTL
|
||||
path_selector
|
||||
|
||||
%start stylesheet
|
||||
|
||||
%nonassoc OPER_period
|
||||
%nonassoc SGMLGI_STRING
|
||||
|
||||
%%
|
||||
|
||||
stylesheet : sensitivityOPTL statement.gpOPTL
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
sensitivity : GI_CASE_SENSITIVE OPER_assign BOOLVAL
|
||||
{
|
||||
gGI_CASE_SENSITIVE = $3;
|
||||
}
|
||||
;
|
||||
|
||||
statement.gp : var_assignment
|
||||
{
|
||||
}
|
||||
| path_expr
|
||||
{
|
||||
/* copy items form the feature list into the path table */
|
||||
PathFeatureListIterator l_Iter(*($1));
|
||||
|
||||
PathFeature *x = 0;
|
||||
|
||||
while ( ++l_Iter ) {
|
||||
|
||||
x = l_Iter.key();
|
||||
|
||||
if ( g_validation_mode == true )
|
||||
if ( g_FeatureDefDictionary -> checkSemantics(x -> featureSet()) == false )
|
||||
g_hasSemanticError = true;
|
||||
|
||||
gPathTab -> addPathFeatureSet( x );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* clear out the first list so the elements are not deleted
|
||||
with the list because they are still referenced by the
|
||||
path table */
|
||||
|
||||
$1 -> clear();
|
||||
delete $1;
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
var_assignment : STRING OPER_assign rhs.gp
|
||||
{
|
||||
Expression *x = new Expression(new ConstantNode($3));
|
||||
|
||||
if ( gAutoNumberFP.accept((const char*)$1, x) ) {
|
||||
delete $1;
|
||||
delete x;
|
||||
break;
|
||||
}
|
||||
|
||||
gVariableTable -> enter( gSymTab -> intern((const char*)$1), x);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
symbol : attr
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
|
|
||||
parent string_list
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| string_list
|
||||
{
|
||||
const Symbol* x = $1 -> convertableToVariable();
|
||||
if ( x ) {
|
||||
$$=new VariableNode(*x);
|
||||
delete $1;
|
||||
} else
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
string_list : string_list OPER_feature STRING
|
||||
{
|
||||
|
||||
$1->appendItem(gSymTab->intern(toUpperCase($3)));
|
||||
$$=$1;
|
||||
delete $3 ;
|
||||
}
|
||||
| STRING
|
||||
{
|
||||
$$=new CompositeVariableNode;
|
||||
$$ -> appendItem(gSymTab->intern(toUpperCase($1)));
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
parent : OPER_parent SGMLGI
|
||||
{
|
||||
/*
|
||||
$$=new
|
||||
ParentNode(gSymTab->intern((const char*)$1));
|
||||
*/
|
||||
MESSAGE(cerr, "^ operator not supported.");
|
||||
throw(StyleSheetException());
|
||||
}
|
||||
;
|
||||
|
||||
attr : OPER_attr SGMLGI
|
||||
{
|
||||
$$=new
|
||||
SgmlAttributeNode(gSymTab->intern((const char*)$2));
|
||||
delete $2;
|
||||
}
|
||||
;
|
||||
|
||||
rhs.gp : simple_expr
|
||||
{
|
||||
$$=new FeatureValueExpression($1);
|
||||
}
|
||||
| array
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| featureset
|
||||
{
|
||||
$$=new FeatureValueFeatureSet($1);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
simple_expr : simple_expr OPER_add multi_expr
|
||||
{
|
||||
BinaryOperatorNode::operatorType opType;
|
||||
switch ($2) {
|
||||
case '+': opType=BinaryOperatorNode::PLUS; break;
|
||||
case '-': opType=BinaryOperatorNode::MINUS; break;
|
||||
default:
|
||||
throw(badEvaluationException());
|
||||
}
|
||||
|
||||
FeatureValueExpression* FVexprL = new FeatureValueExpression($1);
|
||||
FeatureValueExpression* FVexprR = new FeatureValueExpression($3);
|
||||
|
||||
$$ = new Expression(
|
||||
new BinaryOperatorNode(opType,
|
||||
new ConstantNode(FVexprL),
|
||||
new ConstantNode(FVexprR)
|
||||
)
|
||||
);
|
||||
}
|
||||
| multi_expr
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
multi_expr : multi_expr OPER_mult term
|
||||
{
|
||||
BinaryOperatorNode::operatorType opType;
|
||||
switch ($2) {
|
||||
case '*': opType=BinaryOperatorNode::TIMES; break;
|
||||
case '/': opType=BinaryOperatorNode::DIVIDE; break;
|
||||
default:
|
||||
throw(badEvaluationException());
|
||||
}
|
||||
|
||||
FeatureValueExpression* FVexpr = new FeatureValueExpression($1);
|
||||
|
||||
$$ = new Expression(
|
||||
new BinaryOperatorNode(opType, new ConstantNode(FVexpr), $3)
|
||||
);
|
||||
}
|
||||
| term
|
||||
{
|
||||
$$ = new Expression($1);
|
||||
}
|
||||
;
|
||||
|
||||
OPER_binop : OPER_mult
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| OPER_add
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
OPER_mult : OPER_star
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| OPER_div
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
term : BOOLVAL
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueInt(int($1)));
|
||||
}
|
||||
| symbol UNIT_STRING
|
||||
{
|
||||
FeatureValueExpression* fve =
|
||||
new FeatureValueExpression(new Expression($1));
|
||||
FeatureValueDimension* x =
|
||||
new FeatureValueDimension(fve, (const char*)$2);
|
||||
delete $2 ;
|
||||
$$=new ConstantNode(x);
|
||||
}
|
||||
| symbol
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| dimension
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| QUOTED_STRING
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueString((const char*)$1));
|
||||
delete $1 ;
|
||||
}
|
||||
| INTEGER UNIT_STRING
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueDimension(new FeatureValueInt($1), (const char*)$2));
|
||||
delete $2 ;
|
||||
}
|
||||
| REAL UNIT_STRING
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueDimension(new FeatureValueReal($1), (const char*)$2));
|
||||
delete $2 ;
|
||||
}
|
||||
| INTEGER
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueInt($1));
|
||||
}
|
||||
| REAL
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueReal($1));
|
||||
}
|
||||
| OPER_parenopen simple_expr OPER_parenclose
|
||||
{
|
||||
$$=new ConstantNode(new FeatureValueExpression($2));
|
||||
}
|
||||
;
|
||||
|
||||
array : array_name ARRAYOPEN array_member_list ARRAYCLOSE
|
||||
{
|
||||
FeatureValueArray* x =
|
||||
new FeatureValueArray((const char*)$1, $3 -> entries());
|
||||
CC_TPtrSlistIterator<FeatureValue> iter(*$3);
|
||||
|
||||
int i = 0;
|
||||
while ( ++iter ) {
|
||||
(*x)[i++] = iter.key();
|
||||
}
|
||||
|
||||
delete $1;
|
||||
delete $3;
|
||||
|
||||
$$ = x;
|
||||
}
|
||||
| array_name ARRAYOPEN ARRAYCLOSE
|
||||
{
|
||||
$$ = new FeatureValueArray((const char*)$1, 0);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
array_name : STRING
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
|
|
||||
{
|
||||
$$ = new unsigned char[1];
|
||||
$$[0] = 0;
|
||||
}
|
||||
;
|
||||
|
||||
array_member_list : array_member SEPARATOR array_member_list
|
||||
{
|
||||
$3 -> prepend($1);
|
||||
$$ = $3;
|
||||
}
|
||||
| array_member
|
||||
{
|
||||
$$=new CC_TPtrSlist<FeatureValue>;
|
||||
$$ -> append($1);
|
||||
}
|
||||
;
|
||||
|
||||
array_member : simple_expr
|
||||
{
|
||||
$$ = new FeatureValueExpression($1);
|
||||
}
|
||||
| array
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
featureset : FSOPEN feature_list SEPARATOR_OPTL FSCLOSE
|
||||
{
|
||||
$$=$2;
|
||||
}
|
||||
| FSOPEN FSCLOSE
|
||||
{
|
||||
$$ = new FeatureSet ();
|
||||
}
|
||||
;
|
||||
|
||||
feature_list : feature_list SEPARATOR feature
|
||||
{
|
||||
if ($3 -> name() == Symbol(gSymTab->intern("FAMILY"))) {
|
||||
// the evaluate() call clones $3
|
||||
FeatureValueFeatureSet *fvfs =
|
||||
(FeatureValueFeatureSet*) $3->evaluate();
|
||||
const FeatureSet* fs = fvfs->value();
|
||||
const Feature* charsetF =
|
||||
fs->lookup(gSymTab->intern("CHARSET"));
|
||||
// charsetF is a mandatory entry in fontfamily
|
||||
assert( charsetF );
|
||||
const FeatureValueString* fv_string =
|
||||
(FeatureValueString*)charsetF->value();
|
||||
const char* charset = *fv_string;
|
||||
assert( charset );
|
||||
|
||||
int entries = $1 -> entries();
|
||||
for (int i=0; i<entries; i++) {
|
||||
const Feature* entry = $1->at(i);
|
||||
if (! (entry->name() == Symbol(gSymTab->intern("FAMILY"))))
|
||||
continue;
|
||||
const FeatureSet* entry_fs =
|
||||
((FeatureValueFeatureSet*)(entry->evaluate()))->value();
|
||||
const Feature* entry_charsetF =
|
||||
entry_fs->lookup(gSymTab->intern("CHARSET"));
|
||||
assert( entry_charsetF );
|
||||
const char* entry_charset =
|
||||
*((FeatureValueString*)(entry_charsetF->value()));
|
||||
assert( entry_charset );
|
||||
if (! strcmp(charset, entry_charset)) {
|
||||
delete $1 -> removeAt(i);
|
||||
break; // escape from for-loop
|
||||
}
|
||||
}
|
||||
delete fvfs ;
|
||||
|
||||
$$ = $1;
|
||||
$$ -> add($3);
|
||||
}
|
||||
else {
|
||||
if ( $1 -> find((Feature*)$3) ) {
|
||||
FeatureSet* fs = new FeatureSet();
|
||||
fs -> add($3);
|
||||
|
||||
$$ =new FeatureSet(*$1, *fs);
|
||||
delete $1;
|
||||
delete fs;
|
||||
}
|
||||
else {
|
||||
$$=$1;
|
||||
$$ -> add($3);
|
||||
}
|
||||
}
|
||||
}
|
||||
| feature
|
||||
{
|
||||
$$=new FeatureSet();
|
||||
$$ -> add($1);
|
||||
}
|
||||
;
|
||||
|
||||
SEPARATOR_OPTL : SEPARATOR
|
||||
{
|
||||
}
|
||||
|
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
feature : feature_name_list OPER_modify rhs.gp
|
||||
{
|
||||
CC_TPtrDlistIterator<char> l_Iter(*($1));
|
||||
|
||||
FeatureSet *fs = 0;
|
||||
Feature *f = 0;
|
||||
FeatureValue *fv = $3;
|
||||
const char* cptr = 0;
|
||||
char buffer[256];
|
||||
while (++l_Iter) {
|
||||
cptr = l_Iter.key();
|
||||
int index = 0 ;
|
||||
const char *c = cptr ;
|
||||
while (*c)
|
||||
{
|
||||
if (islower(*c))
|
||||
buffer[index] = toupper(*c) ;
|
||||
else
|
||||
buffer[index] = *c ;
|
||||
c++ ;
|
||||
index++;
|
||||
}
|
||||
buffer[index] = 0;
|
||||
/* fprintf(stderr, "converted: %s to %s\n", cptr, buffer); */
|
||||
f = new Feature(gSymTab -> intern(buffer), fv);
|
||||
|
||||
if ( $1 -> last() != cptr ) {
|
||||
fs = new FeatureSet();
|
||||
fs -> add(f);
|
||||
fv = new FeatureValueFeatureSet(fs);
|
||||
}
|
||||
}
|
||||
|
||||
$1->clearAndDestroy();
|
||||
delete $1 ;
|
||||
$$=f;
|
||||
}
|
||||
;
|
||||
|
||||
feature_name_list : feature_name_list OPER_feature STRING
|
||||
{
|
||||
$1 -> prepend((char *)$3);
|
||||
$$=$1;
|
||||
}
|
||||
|
|
||||
STRING
|
||||
{
|
||||
$$=new CC_TPtrDlist<char>;
|
||||
$$ -> append((char *)$1);
|
||||
}
|
||||
;
|
||||
|
||||
path_expr : path_term_list featureset
|
||||
{
|
||||
$$=new PathFeatureList;
|
||||
$$ -> append(new PathFeature($1, $2));
|
||||
}
|
||||
| path_term_list OPER_parenopen path_expr_list OPER_parenclose
|
||||
{
|
||||
|
||||
PathFeatureListIterator l_Iter(*($3));
|
||||
|
||||
while ( ++l_Iter ) {
|
||||
(l_Iter.key()) -> path() -> prependPath(*$1);
|
||||
}
|
||||
delete $1;
|
||||
$$=$3;
|
||||
}
|
||||
;
|
||||
|
||||
path_expr_list : path_expr_list SEPARATOR path_expr
|
||||
{
|
||||
$$=$1;
|
||||
$$ -> appendList(*$3);
|
||||
delete $3 ;
|
||||
}
|
||||
| path_expr
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
|
||||
path_term_list : path_term_list path_term
|
||||
{
|
||||
$1 -> appendPathTerm($2);
|
||||
$$=$1;
|
||||
}
|
||||
| path_term
|
||||
{
|
||||
$$ = new SSPath;
|
||||
$$ -> appendPathTerm($1);
|
||||
}
|
||||
;
|
||||
|
||||
path_term : SGMLGI path_selectorOPTL
|
||||
{
|
||||
$$=new PathTerm((const char*)$1, $2);
|
||||
delete $1;
|
||||
}
|
||||
| OPER_oneof
|
||||
{
|
||||
localCharToCharPtrBuf[0]=$1; localCharToCharPtrBuf[1]=0;
|
||||
$$=new PathTerm(localCharToCharPtrBuf, 0);
|
||||
}
|
||||
| OPER_star
|
||||
{
|
||||
localCharToCharPtrBuf[0]=$1; localCharToCharPtrBuf[1]=0;
|
||||
$$=new PathTerm(localCharToCharPtrBuf, 0);
|
||||
}
|
||||
;
|
||||
|
||||
OPER_feature : OPER_period
|
||||
{
|
||||
}
|
||||
|
||||
OPER_add : OPER_plus
|
||||
{
|
||||
}
|
||||
| OPER_minus
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
SGMLGI : SGMLGI_CONTENT
|
||||
{
|
||||
// char % can start an OLIAS internal element which
|
||||
// is used only by the browser.
|
||||
// Example %BOGUS within HEAD1 in OLIAS book
|
||||
|
||||
if ( $1[0] != '%' && isalnum($1[0]) == 0 ) {
|
||||
MESSAGE(cerr, form("%s is not a SGMLGI", $1));
|
||||
throw(badEvaluationException());
|
||||
}
|
||||
/* note, should probably be using RCStrings, would make wide */
|
||||
/* char handling better too? */
|
||||
if ( gGI_CASE_SENSITIVE == false )
|
||||
{
|
||||
for (int i=0; i<strlen((const char*)$1); i++)
|
||||
if ( islower($1[i]) )
|
||||
$1[i] = toupper($1[i]);
|
||||
}
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
SGMLGI_CONTENT : STRING OPER_period {enter_sgmlgi_context();} SGMLGI_STRING
|
||||
{
|
||||
int l = strlen((char*)$1) + strlen((char*)$4) + 2;
|
||||
$$=new unsigned char[l];
|
||||
strcpy((char*)$$, (char*)$1);
|
||||
strcat((char*)$$, ".");
|
||||
strcat((char*)$$, (char*)$4);
|
||||
delete $1;
|
||||
delete $4;
|
||||
}
|
||||
| STRING OPER_period
|
||||
{
|
||||
int l = strlen((char*)$1) + 2;
|
||||
$$=new unsigned char[l];
|
||||
strcpy((char*)$$, (char*)$1);
|
||||
strcat((char*)$$, ".");
|
||||
delete $1;
|
||||
}
|
||||
|
||||
| STRING
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
dimension : DIMENSION
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<strlen((const char*)$1); i++) {
|
||||
|
||||
if ( isalpha($1[i]) )
|
||||
break;
|
||||
}
|
||||
|
||||
char c;
|
||||
float x;
|
||||
if ( i > 0 ) {
|
||||
c = $1[i]; $1[i]=0;
|
||||
x = atof((const char*)$1);
|
||||
$1[i]=c;
|
||||
} else
|
||||
x = 1;
|
||||
|
||||
$$=new ConstantNode(new FeatureValueDimension(new FeatureValueReal(x), (const char*)&$1[i]));
|
||||
|
||||
delete $1;
|
||||
}
|
||||
|
||||
STRING : NORMAL_STRING
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| UNIT_STRING
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
;
|
||||
|
||||
path_selector : ARRAYOPEN boolean_expr ARRAYCLOSE
|
||||
{
|
||||
$$=$2;
|
||||
}
|
||||
;
|
||||
|
||||
boolean_expr : logical_and_expr
|
||||
{
|
||||
//////////////////////////////////////////////////////
|
||||
// This portion of the code (up to equality_expr) is
|
||||
// hacked for V1.1 only. Due to the way
|
||||
// PathQualifier.h is written, this code is not
|
||||
// general at all. qfc 8/16/94
|
||||
//////////////////////////////////////////////////////
|
||||
$$=$1;
|
||||
}
|
||||
| boolean_expr OPER_or logical_and_expr
|
||||
{
|
||||
$$ = new PQLogExpr($1, PQor, $3);
|
||||
}
|
||||
;
|
||||
|
||||
logical_and_expr : equality_expr
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| logical_and_expr OPER_and equality_expr
|
||||
{
|
||||
$$ = new PQLogExpr($1, PQand, $3);
|
||||
}
|
||||
;
|
||||
|
||||
equality_expr : OPER_attr SGMLGI OPER_equality QUOTED_STRING
|
||||
{
|
||||
$$ = new PQAttributeSelector(
|
||||
gSymTab->intern((const char*)$2),
|
||||
( $3 == EQUAL ) ? PQEqual : PQNotEqual,
|
||||
(const char*)$4
|
||||
);
|
||||
delete $2;
|
||||
delete $4;
|
||||
}
|
||||
| NORMAL_STRING OPER_equality POSITION_VALUE
|
||||
{
|
||||
if ( strcasecmp((char*)$1, "position") == 0 ) {
|
||||
$$=new PQPosition(
|
||||
( $2 == EQUAL ) ? PQEqual : PQNotEqual,
|
||||
$3
|
||||
);
|
||||
} else
|
||||
if ( strcasecmp((char*)$1, "sibling") == 0 ) {
|
||||
$$=new PQSibling(
|
||||
( $2 == EQUAL ) ? PQEqual : PQNotEqual,
|
||||
$3
|
||||
);
|
||||
} else
|
||||
throw(StyleSheetException());
|
||||
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
POSITION_VALUE : INTEGER
|
||||
{
|
||||
$$ = (int)$1;
|
||||
}
|
||||
| QUOTED_STRING
|
||||
{
|
||||
if ( strcasecmp((char*)$1, "#LAST") != 0 )
|
||||
throw(StyleSheetException());
|
||||
|
||||
$$ = -1;
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
sensitivityOPTL : sensitivity
|
||||
{
|
||||
|
||||
}
|
||||
| /* empty */
|
||||
{
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
statement.gpOPTL : statement.gpPLUS
|
||||
{
|
||||
}
|
||||
| /* empty */
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
statement.gpPLUS : statement.gpPLUS statement.gp
|
||||
{
|
||||
|
||||
}
|
||||
| statement.gp
|
||||
{
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
path_selectorOPTL : path_selector
|
||||
{
|
||||
$$=$1;
|
||||
}
|
||||
| /* empty */
|
||||
{
|
||||
$$=0;
|
||||
}
|
||||
;
|
||||
|
||||
139
cde/programs/dtinfo/DtMmdb/StyleSheet/testparser.C
Normal file
139
cde/programs/dtinfo/DtMmdb/StyleSheet/testparser.C
Normal file
@@ -0,0 +1,139 @@
|
||||
// $XConsortium: testparser.C /main/4 1996/08/21 15:51:08 drk $
|
||||
|
||||
#include "PathTable.h"
|
||||
#include "Debug.h"
|
||||
#include "Const.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "VariableTable.h"
|
||||
#include "StyleSheet.h"
|
||||
#include "Resolver.h"
|
||||
|
||||
Renderer* gRenderer = 0;
|
||||
|
||||
extern int styleparse();
|
||||
extern int stylerestart(FILE*);
|
||||
extern FILE *stylein;
|
||||
|
||||
test1()
|
||||
{
|
||||
BitVector v1(33, 0);
|
||||
v1.setBitTo(0, 1);
|
||||
v1.setBitTo(1, 1);
|
||||
v1.setBitTo(5, 1);
|
||||
v1.setBitTo(32, 1);
|
||||
debug(cerr, v1);
|
||||
v1.shiftRightOneBit();
|
||||
|
||||
BitVector v2(33, 0);
|
||||
v2.setBitTo(3, 1);
|
||||
debug(cerr, v2);
|
||||
|
||||
MESSAGE(cerr, "v2 | v1");
|
||||
v2 |= v1;
|
||||
debug(cerr, v2);
|
||||
|
||||
BitVector v3(33, 0);
|
||||
v3.setBitTo(8, 1);
|
||||
debug(cerr, v3);
|
||||
v3 &= v1;
|
||||
MESSAGE(cerr, "v3 & v1");
|
||||
debug(cerr, v3);
|
||||
|
||||
BitVector v4(33, 0);
|
||||
v4.setBitTo(1, 1);
|
||||
v4.setBitTo(8, 1);
|
||||
debug(cerr, v4);
|
||||
v4 ^= v1;
|
||||
MESSAGE(cerr, "v4 ^ v1");
|
||||
debug(cerr, v4);
|
||||
}
|
||||
|
||||
|
||||
test2( char* argv[] )
|
||||
{
|
||||
SSPath t(argv[1], false);
|
||||
|
||||
SSPath p(argv[2], true);
|
||||
|
||||
|
||||
EncodedPath et(&t);
|
||||
EncodedPath ep(&p, true);
|
||||
|
||||
debug(cerr, ep.match(et, 0, 0));
|
||||
}
|
||||
|
||||
test3( int argc, char* argv[] )
|
||||
{
|
||||
/*
|
||||
PathTable pt;
|
||||
SSPath *px;
|
||||
|
||||
for ( int i=1; i<argc-1; i++ ) {
|
||||
px = new SSPath(argv[i], (FeatureSet*)i);
|
||||
pt.addPathFeatureSet(px);
|
||||
}
|
||||
|
||||
|
||||
SSPath pq(argv[argc-2], false);
|
||||
|
||||
debug(cerr, int(pt.getFeatureSet(pq)));
|
||||
*/
|
||||
}
|
||||
|
||||
test4( int argc, char* argv[] )
|
||||
{
|
||||
if ( argc >= 2 ) {
|
||||
stylein = fopen(argv[1], "r");
|
||||
if ( stylein == 0 ) {
|
||||
MESSAGE(cerr, "open file failed");
|
||||
return 1;
|
||||
}
|
||||
styleparse();
|
||||
|
||||
debug(cerr, *gVariableTable);
|
||||
|
||||
debug(cerr, *gPathTab);
|
||||
|
||||
fclose(stylein);
|
||||
} else
|
||||
MESSAGE(cerr, "no file argument");
|
||||
}
|
||||
|
||||
struct XmappingTable_t {
|
||||
char* FeatureName;
|
||||
char* SubFeatureNameList;
|
||||
char Value; // d: directly from the value()
|
||||
// i: indrectly from the value()
|
||||
char* Source; // l: local FeatureSet
|
||||
// p: parent FeatureSet
|
||||
// c: Combined FeatureSet
|
||||
// can be a list of l, p, c
|
||||
char* LoutBeginTag;
|
||||
};
|
||||
|
||||
main( int argc, char* argv[] )
|
||||
{
|
||||
|
||||
INIT_EXCEPTIONS();
|
||||
|
||||
StyleSheet ss;
|
||||
|
||||
if ( strcmp(argv[1], "test1") == 0 )
|
||||
test1;
|
||||
else
|
||||
if ( strcmp(argv[1], "test2") == 0 )
|
||||
test2(&argv[1]);
|
||||
else
|
||||
if ( strcmp(argv[1], "test3") == 0 )
|
||||
test3(argc-1, &argv[1]);
|
||||
else
|
||||
if ( strcmp(argv[1], "test4") == 0 )
|
||||
test4(argc-1, &argv[1]);
|
||||
}
|
||||
|
||||
void styleerror( char* errorstr )
|
||||
{
|
||||
MESSAGE(cerr, errorstr);
|
||||
return;
|
||||
}
|
||||
|
||||
26
cde/programs/dtinfo/DtMmdb/StyleSheet/testsym.C
Normal file
26
cde/programs/dtinfo/DtMmdb/StyleSheet/testsym.C
Normal file
@@ -0,0 +1,26 @@
|
||||
// $XConsortium: testsym.cc /main/3 1996/06/11 17:10:33 cde-hal $
|
||||
#include "SymTab.h"
|
||||
|
||||
|
||||
SymbolTable *gSymTab = new SymbolTable;
|
||||
SymbolTable *gElemSymTab = 0;
|
||||
|
||||
main()
|
||||
{
|
||||
|
||||
|
||||
Symbol a = gSymTab->intern("a");
|
||||
Symbol b = gSymTab->intern("b");
|
||||
Symbol a2 = gSymTab->intern("a");
|
||||
|
||||
cout << (a == a) << endl;
|
||||
cout << (a == b) << endl;
|
||||
cout << (a == a2) << endl;
|
||||
|
||||
cout << "ids = " << endl;
|
||||
cout << a.name() << "\t" << a.id() << endl;
|
||||
cout << b.name() << "\t" << b.id() << endl;
|
||||
cout << a2.name() << "\t" << a2.id() << endl;
|
||||
|
||||
|
||||
}
|
||||
1556
cde/programs/dtinfo/DtMmdb/StyleSheet/tokenStyle.C
Normal file
1556
cde/programs/dtinfo/DtMmdb/StyleSheet/tokenStyle.C
Normal file
File diff suppressed because it is too large
Load Diff
356
cde/programs/dtinfo/DtMmdb/StyleSheet/tokenStyle.l
Normal file
356
cde/programs/dtinfo/DtMmdb/StyleSheet/tokenStyle.l
Normal file
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* $TOG: tokenStyle.l /main/6 1998/04/17 11:50:07 mgreess $
|
||||
*
|
||||
* Copyright (c) 1993 HAL Computer Systems International, Ltd.
|
||||
* All rights reserved. Unpublished -- rights reserved under
|
||||
* the Copyright Laws of the United States. USE OF A COPYRIGHT
|
||||
* NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
|
||||
* OR DISCLOSURE.
|
||||
*
|
||||
* THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
|
||||
* SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
|
||||
* DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
|
||||
* PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
|
||||
* INTERNATIONAL, LTD.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject
|
||||
* to the restrictions as set forth in subparagraph (c)(l)(ii)
|
||||
* of the Rights in Technical Data and Computer Software clause
|
||||
* at DFARS 252.227-7013.
|
||||
*
|
||||
* HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
|
||||
* 1315 Dell Avenue
|
||||
* Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
%a 30000
|
||||
%e 10000
|
||||
%k 10000
|
||||
%n 10000
|
||||
%o 40000
|
||||
%p 20000
|
||||
|
||||
%{
|
||||
#include <string.h>
|
||||
#include "ParserConst.h"
|
||||
#include "Expression.h"
|
||||
#include "FeatureValue.h"
|
||||
#include "PathTable.h"
|
||||
#include "SSPath.h"
|
||||
#include "PathQualifier.h"
|
||||
#include "StyleSheetExceptions.h"
|
||||
#include "style.tab.h"
|
||||
#include "Debug.h"
|
||||
#include <iostream.h>
|
||||
|
||||
extern istream *g_stylein ;
|
||||
|
||||
#define YY_INPUT(buf,result,max_size)\
|
||||
{\
|
||||
if (g_stylein -> eof()) {\
|
||||
result=0;\
|
||||
} else {\
|
||||
g_stylein -> read((char*)buf, max_size-1); \
|
||||
result = g_stylein -> gcount(); \
|
||||
buf[result] = 0; \
|
||||
}\
|
||||
}
|
||||
|
||||
unsigned char* qstring_buf = new unsigned char[1024];
|
||||
int qstring_buf_size = 1024;
|
||||
int qstring_buf_content_size = 0;
|
||||
|
||||
char* commentBuffer = new char [1024];
|
||||
int commentBufferSize = 1024;
|
||||
int commentBufferContentSize = 0;
|
||||
|
||||
int yylineno=1;
|
||||
|
||||
void addToQstringBuf(const unsigned char* str, int size)
|
||||
{
|
||||
if ( size <= 0 ) return;
|
||||
|
||||
if ( qstring_buf_size - qstring_buf_content_size < size ) {
|
||||
qstring_buf_size = 2*(size+qstring_buf_content_size);
|
||||
unsigned char* x = new unsigned char[qstring_buf_size];
|
||||
memcpy(x, qstring_buf, qstring_buf_content_size);
|
||||
delete qstring_buf;
|
||||
qstring_buf = x;
|
||||
}
|
||||
|
||||
memcpy(qstring_buf + qstring_buf_content_size, str, size);
|
||||
qstring_buf_content_size += size;
|
||||
qstring_buf[qstring_buf_content_size] = 0;
|
||||
}
|
||||
|
||||
|
||||
%}
|
||||
unit ([Ii][Nn]|[Ii][Nn][Cc][Hh]|[Pp][Cc]|[Pp][Ii][Cc][Aa]|[Pp][Tt]|[Pp][Oo][Ii][Nn][Tt]|[Pp][Ii][Xx][Ee][Ll]|[Cc][Mm])
|
||||
|
||||
%x block sgmlgimode quoted_string
|
||||
|
||||
%%
|
||||
|
||||
"#|" BEGIN(block);
|
||||
|
||||
^"#".* {
|
||||
if ( commentBufferSize < yyleng ) {
|
||||
delete commentBuffer;
|
||||
commentBufferSize = 2 * yyleng ;
|
||||
commentBuffer = new char [commentBufferSize];
|
||||
}
|
||||
|
||||
commentBufferContentSize = yyleng-1;
|
||||
memcpy(commentBuffer, yytext+1, commentBufferContentSize); // copy everything except the #
|
||||
commentBuffer[commentBufferContentSize] = 0;
|
||||
}
|
||||
|
||||
"=" {
|
||||
return(OPER_assign);
|
||||
}
|
||||
|
||||
"@" {
|
||||
return(OPER_attr);
|
||||
}
|
||||
|
||||
[+] {
|
||||
yylval.charData = yytext[0];
|
||||
return(OPER_plus);
|
||||
}
|
||||
|
||||
[-] {
|
||||
yylval.charData = yytext[0];
|
||||
return(OPER_minus);
|
||||
}
|
||||
|
||||
"/" {
|
||||
yylval.charData = yytext[0];
|
||||
return(OPER_div);
|
||||
}
|
||||
|
||||
"." {
|
||||
return(OPER_period);
|
||||
}
|
||||
|
||||
"*" {
|
||||
yylval.charData = yytext[0];
|
||||
return(OPER_star);
|
||||
}
|
||||
|
||||
":" {
|
||||
return(OPER_modify);
|
||||
}
|
||||
|
||||
"?" {
|
||||
return(OPER_oneof);
|
||||
}
|
||||
|
||||
"^" {
|
||||
return(OPER_parent);
|
||||
}
|
||||
|
||||
"," {
|
||||
return(SEPARATOR);
|
||||
}
|
||||
|
||||
"{" {
|
||||
return(FSOPEN);
|
||||
}
|
||||
|
||||
"}" {
|
||||
return(FSCLOSE);
|
||||
}
|
||||
|
||||
"[" {
|
||||
return(ARRAYOPEN);
|
||||
}
|
||||
|
||||
"]" {
|
||||
return(ARRAYCLOSE);
|
||||
}
|
||||
|
||||
"(" {
|
||||
return(OPER_parenopen);
|
||||
}
|
||||
|
||||
")" {
|
||||
return(OPER_parenclose);
|
||||
}
|
||||
|
||||
"||" {
|
||||
return(OPER_or);
|
||||
}
|
||||
|
||||
"&&" {
|
||||
return(OPER_and);
|
||||
}
|
||||
|
||||
"=="|"!=" {
|
||||
if ( strcmp((const char*)yytext, "==") == 0 )
|
||||
yylval.intData = EQUAL;
|
||||
else
|
||||
yylval.intData = NOT_EQUAL;
|
||||
|
||||
return(OPER_equality);
|
||||
}
|
||||
|
||||
"!" {
|
||||
return(OPER_logicalnegate);
|
||||
}
|
||||
|
||||
"<="|"<"|">="|">" {
|
||||
if ( strcmp((const char*)yytext, "<=") == 0 )
|
||||
yylval.intData = LESS_OR_EQUAL;
|
||||
else
|
||||
if ( strcmp((const char*)yytext, "<") == 0 )
|
||||
yylval.intData = LESS;
|
||||
else
|
||||
if ( strcmp((const char*)yytext, ">=") == 0 )
|
||||
yylval.intData = GREATER_OR_EQUAL;
|
||||
else
|
||||
yylval.intData = GREATER;
|
||||
|
||||
return(OPER_relational);
|
||||
}
|
||||
|
||||
"GICaseSensitive" {
|
||||
return(GI_CASE_SENSITIVE);
|
||||
}
|
||||
|
||||
[Tt][Rr][Uu][Ee] {
|
||||
yylval.boolData = true;
|
||||
return(BOOLVAL);
|
||||
}
|
||||
|
||||
[Ff][Aa][Ll][Ss][Ee] {
|
||||
yylval.boolData = false;
|
||||
return(BOOLVAL);
|
||||
}
|
||||
|
||||
[On][Nn] {
|
||||
yylval.boolData = true;
|
||||
return(BOOLVAL);
|
||||
}
|
||||
|
||||
[Oo][Ff][Ff] {
|
||||
yylval.boolData = false;
|
||||
return(BOOLVAL);
|
||||
}
|
||||
|
||||
[0-9]+("."[0-9]+)?{unit} {
|
||||
yylval.charPtrData =
|
||||
(unsigned char*)strdup((const char*)yytext);
|
||||
return(DIMENSION);
|
||||
}
|
||||
|
||||
[0-9]+ {
|
||||
yylval.intData = atoi((char*)yytext);
|
||||
return(INTEGER);
|
||||
}
|
||||
|
||||
[0-9]+"."[0-9]+ {
|
||||
yylval.realData = atof((char*)yytext);
|
||||
return(REAL);
|
||||
}
|
||||
|
||||
\" {
|
||||
BEGIN quoted_string;
|
||||
}
|
||||
|
||||
<quoted_string>\" {
|
||||
|
||||
yylval.charPtrData =
|
||||
new unsigned char[qstring_buf_content_size+1];
|
||||
memcpy( yylval.charPtrData,
|
||||
qstring_buf,
|
||||
qstring_buf_content_size+1
|
||||
);
|
||||
|
||||
qstring_buf_content_size = 0;
|
||||
BEGIN 0;
|
||||
|
||||
return(QUOTED_STRING);
|
||||
}
|
||||
|
||||
<quoted_string>\\ {
|
||||
int c = styleinput();
|
||||
switch (c) {
|
||||
case '"':
|
||||
addToQstringBuf((unsigned char*)"\"", 1);
|
||||
break;
|
||||
case '\\':
|
||||
addToQstringBuf((unsigned char*)"\\", 1);
|
||||
break;
|
||||
default:
|
||||
throw(CASTSSEXCEPT StyleSheetException());
|
||||
}
|
||||
}
|
||||
|
||||
<quoted_string>[^\\\"]* {
|
||||
addToQstringBuf((unsigned char*)yytext, yyleng);
|
||||
}
|
||||
|
||||
<quoted_string>. {
|
||||
addToQstringBuf((unsigned char*)yytext, yyleng);
|
||||
}
|
||||
|
||||
{unit} {
|
||||
yylval.charPtrData =
|
||||
(unsigned char*)strdup((const char*)yytext);
|
||||
return(UNIT_STRING);
|
||||
}
|
||||
|
||||
[^ \t\n\".=@+*\/\.\*:?\^,{}\[\]()!]+ {
|
||||
yylval.charPtrData =
|
||||
(unsigned char*)strdup((const char*)yytext);
|
||||
return(NORMAL_STRING);
|
||||
}
|
||||
|
||||
<sgmlgimode>[0-9a-zA-Z\.\-]+ {
|
||||
yylval.charPtrData =
|
||||
(unsigned char*)strdup((const char*)yytext);
|
||||
BEGIN 0;
|
||||
return(SGMLGI_STRING);
|
||||
}
|
||||
|
||||
[\t] {
|
||||
}
|
||||
|
||||
[\n] {
|
||||
yylineno++;
|
||||
}
|
||||
|
||||
. {
|
||||
}
|
||||
|
||||
|
||||
|
||||
<block>"|#" { BEGIN(0); }
|
||||
<block>. ;
|
||||
<block>\n ;
|
||||
%%
|
||||
|
||||
void enter_sgmlgi_context()
|
||||
{
|
||||
BEGIN sgmlgimode;
|
||||
}
|
||||
|
||||
|
||||
void report_error_location()
|
||||
{
|
||||
if ( commentBufferContentSize > 0 ) {
|
||||
cerr << commentBuffer << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void yyerror(char* msg)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
cerr << "line " << yylineno << ": " << msg << "\n";
|
||||
#endif
|
||||
throw(CASTSSSEEXCEPT StyleSheetSyntaxError());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user