2 /* $XConsortium: lex.l /main/5 1996/11/19 16:55:12 drk $ */
4 #if !defined(__osf__) && !defined(linux) && !defined(CSRG_BASED)
15 #include "Exceptions.hh"
19 #include "AttributeRec.h"
20 #include "AttributeList.h"
21 #include "FlexBuffer.h"
23 #include "api/utility.h"
25 static SGMLDefn *defn = new SGMLDefn();
26 static FlexBuffer *DataBuffer = new FlexBuffer();
29 unsigned char oct2dec( const char *str )
31 unsigned char value = 0;
32 const char *ptr = str;
33 const char *endptr = str + strlen(str) -1 ;
35 for ( ; *ptr != '\0' ; ptr++ ) {
37 int power = endptr - ptr;
40 for ( int i = 1; i <= power; i++ ) {
44 value = value + ( *ptr - '0' ) * result ;
64 name = strtok ( (char*)yytext+1, "\n\t ");
65 tstr = strtok ( NULL, "\n\t ");
66 value = strtok ( NULL, "\n\t");
67 type = SGMLName::intern(tstr);
69 if ( type != SGMLName::IMPLIED ){
70 if(!value) value = "";
71 Dispatch::tok->StoreAttribute( name, value, type);
76 // An generic identifier is found
77 // Need to determine how to display/return the
78 // information associated with it
80 Dispatch::token(START, (unsigned char *)yytext+1 );
84 ^"L"[0-9]+" "[^ \n]+ { /* file & line num info. */
85 char *p = (char*)yytext+1;
86 Dispatch::line(atoi(p));
92 ^"L"[0-9]+ { /* line num info. */
93 char *p = (char*)yytext+1;
94 Dispatch::line(atoi(p));
99 defn->store_sys_id( (char *)yytext + 1 );
102 /* file name found */
103 defn->store_file_name( (char *)yytext + 1 );
107 * For now, only entity definition is recorded
108 * Eventually Notation, Subdoc....
110 defn->store_defn( ENTITY_TYPE,
111 (char *)yytext + 1 );
113 Dispatch::entity_decl( defn );
118 * external entity reference
120 Dispatch::token(EXTERNAL_ENTITY,
121 (unsigned char *)yytext+1 );
128 Dispatch::subdoc_start();
136 Dispatch::subdoc_end();
140 BEGIN ( ProcessData );
143 <ProcessData>"\\""\\" {
145 DataBuffer->put ('\\');
148 // Replace new line with space
149 DataBuffer->put('\015');
154 // Bypass this entity
157 <ProcessData>"\\|lnfeed\\|" {
158 DataBuffer->put('\n');
161 <ProcessData>"\\"[0-7][0-7][0-7] {
163 unsigned char ch = oct2dec(
164 (const char *)yytext + 1 );
165 DataBuffer->put ( ch );
169 Dispatch::data( DataBuffer );
171 DataBuffer = new FlexBuffer;
176 <ProcessData>[^\n\\]+ {
177 DataBuffer->write( (char*)yytext,
178 strlen((char*)yytext) );
182 throw(Unexpected(form("Bad character '%s' found",
187 Dispatch::token (END, (unsigned char *)yytext+1);
196 //---------------------------------------------------------------------
198 #include "SGMLName.h"
200 static void TestToken( Token *tok )
202 cout << "(" << tok->giName() << endl;
203 for ( const AttributeRec *a = tok->GetFirstAttr(); a; a=tok->GetNextAttr( a ) ) {
204 cout << "AttributeName = " << SGMLName::lookup(a->getAttrName()) << endl;
205 cout << "AttributeValueStr = " << a->getAttrValueString() << endl;
206 cout << "AttributeValue = " << a->getAttValue() << endl;
207 cout << "AttributeType = " << a->getAttrType() << endl;
209 if ( !(strcmp( a->getAttrValueString(), "NODE" ) ) ){
210 if ( tok->AttributeMatch ( OLAF::OLIAS, OLAF::OL_Section ) ) {
211 cout << "AttrMatch Test 1 passed\n";
214 cout << "AttrMatch Test 1 failed\n";
217 if ( !tok->AttributeMatch ( OLAF::OLIAS, OLAF::OL_Graphic ) ) {
218 cout << "AttrMatch Test 2 passed\n";
221 cout << "AttrMatch Test 2 failed\n";
227 #endif /* DBUG_OFF */