1 W [ \t\r\n] 2 Q [\"\'] 3 NQ [^\"\'] 4 F [-a-z0-9$_.!*(),%;/?:@&=+~|] 5 FA [-a-z0-9$_.!*()%;/?:@&=+~|] 6 PA [[] 7 PE []] 8 NP [^]] 9 10 %x VRML1 11 %x VRML1NAME VRML1REF 12 13 %x VRML2 14 %x VRML2URL VRML2REF VRML2REFEND 15 16 %{ 17 /*************************************** 18 WWWOFFLE - World Wide Web Offline Explorer - Version 2.9j. 19 20 Parse the VRML and look for the WWWInline, WWWanchor and other things. 21 ******************/ /****************** 22 Written by Walter Pfannenmueller 23 24 This file Copyright 1997-2016 Walter Pfannenmueller & Andrew M. Bishop 25 It may be distributed under the GNU Public License, version 2, or 26 any higher version. See section COPYING of the GNU Public license 27 for conditions under which this file may be redistributed. 28 ***************************************/ 29 30 31 #include "autoconfig.h" 32 33 #include "wwwoffle.h" 34 #include "io.h" 35 #include "misc.h" 36 #include "errors.h" 37 #include "document.h" 38 39 40 extern int vrml_yylex(void); 41 42 /*+ The file descriptor that we are reading from. +*/ 43 static int vrml_yyfd=-1; 44 45 46 /*++++++++++++++++++++++++++++++++++++++ 47 Parse the VRML and look for references. 48 49 int fd The file descriptor of the file to parse. 50 51 URL *Url The reference URL to use. 52 ++++++++++++++++++++++++++++++++++++++*/ 53 54 void ParseVRML(int fd,URL *Url) 55 { 56 static int first=1; 57 58 PrintMessage(Debug,"Parsing document using VRML parser."); 59 60 vrml_yyfd=fd; 61 62 if(!first) 63 vrml_yyrestart(NULL); 64 65 vrml_yylex(); 66 67 first=0; 68 } 69 70 71 #define YY_NO_INPUT 1 /* Remove annoying gcc warning message */ 72 73 #define YY_SKIP_YYWRAP 1 /* Remove error with prototype of ..._yywrap */ 74 #ifndef vrml_yywrap 75 /*+ Needed in lex but does nothing. +*/ 76 #define vrml_yywrap() 1 77 #endif 78 79 /*+ A macro to read data that can be used by the lexer. +*/ 80 #define YY_INPUT(buf,result,max_size) \ 81 { ssize_t temp=read_data(vrml_yyfd,buf,max_size); result=(temp<0)?0:temp; } 82 83 %} 84 85 %% 86 /* Can use local variables since the parser only returns at EOF. */ 87 RefType type=0; 88 int more=0; 89 90 91 /* Handle comments and other angle brackets */ 92 93 "#VRML"" "+"V1.0" { BEGIN(VRML1); } 94 95 "#VRML"" "+"V2.0" { BEGIN(VRML2); } 96 .|\r|\n { } 97 98 /* 99 * VRML V1.0 100 */ 101 102 /* Comments */ 103 <VRML1>"#".* { BEGIN(VRML1); } 104 /* Strings */ 105 <VRML1>{Q}{NQ}*{Q} { BEGIN(VRML1); } 106 <VRML1>"WWWAnchor" { type = RefLink; BEGIN(VRML1NAME); } 107 <VRML1>"WWWInline" { type = RefInlineObject; BEGIN(VRML1NAME); } 108 <VRML1>"Texture2"{W} { type = RefInlineObject; BEGIN(VRML1NAME); } 109 <VRML1>.|\r|\n { BEGIN(VRML1); } 110 111 /* VRML V1.0 Reference */ 112 <VRML1NAME>"#".* { BEGIN(VRML1NAME); } 113 <VRML1NAME>{Q}{NQ}*{Q} { BEGIN(VRML1NAME); } 114 <VRML1NAME>"file"*"name"{W}*{Q} { BEGIN(VRML1REF); } 115 <VRML1NAME>.|\r|\n { BEGIN(VRML1NAME); } 116 117 <VRML1REF>{F}+ { AddReference(vrml_yytext,type); BEGIN(VRML1REF); } 118 <VRML1REF>{Q} { BEGIN(VRML1); } 119 <VRML1REF>.|\r|\n { } 120 121 /* 122 * VRML V2.0 123 */ 124 125 /* Comments */ 126 <VRML2>"#".* { BEGIN(VRML2); } 127 /* Strings */ 128 <VRML2>{Q}{NQ}*{Q} { BEGIN(VRML2); } 129 <VRML2>"Anchor" { type = RefLink; BEGIN(VRML2); } 130 <VRML2>"AudioClip" { type = RefInlineObject; BEGIN(VRML2); } 131 <VRML2>"BackGround" { type = RefInlineObject; BEGIN(VRML2); } 132 <VRML2>"ImageTexture" { type = RefInlineObject; BEGIN(VRML2); } 133 <VRML2>"Inline" { type = RefInlineObject; BEGIN(VRML2); } 134 <VRML2>"MovieTexture" { type = RefInlineObject; BEGIN(VRML2); } 135 <VRML2>"Script" { type = RefInlineObject; BEGIN(VRML2); } 136 <VRML2>"url" { BEGIN(VRML2URL); } 137 <VRML2>"backUrl" { BEGIN(VRML2URL); } 138 <VRML2>"bottomUrl" { BEGIN(VRML2URL); } 139 <VRML2>"frontUrl" { BEGIN(VRML2URL); } 140 <VRML2>"leftUrl" { BEGIN(VRML2URL); } 141 <VRML2>"rightUrl" { BEGIN(VRML2URL); } 142 <VRML2>"topUrl" { BEGIN(VRML2URL); } 143 <VRML2>"EXTERNPROTO"{NP}*"]" { type = RefInlineObject; BEGIN(VRML2URL); } 144 <VRML2>.|\r|\n { BEGIN(VRML2); } 145 146 /* URLs */ 147 148 <VRML2URL>{PE} { more = 0; BEGIN(VRML2); } 149 <VRML2URL>"#".* { BEGIN(VRML2URL); } 150 <VRML2URL>{W}+ { BEGIN(VRML2URL); } 151 <VRML2URL>{PA} { more = 1; BEGIN(VRML2URL); } 152 <VRML2URL>{Q} { BEGIN(VRML2REF); } 153 <VRML2URL>"," { BEGIN(VRML2URL); } 154 <VRML2URL>.|\r|\n { unput(*vrml_yytext); BEGIN(VRML2); } 155 156 <VRML2REF>"javascript:"{F}* { /* not implemented yet */ 157 /* LoadURL, GrabVrmlFromURL functions 158 could add URLs 159 */ 160 BEGIN(VRML2REFEND); } 161 <VRML2REF>"javabc:"{F}* { /* not implemented yet */ 162 /* parsing java bytecode */ 163 BEGIN(VRML2REFEND); } 164 <VRML2REF>{F}+ { AddReference(vrml_yytext,type); 165 /* printf("AddReference %s %d\n",vrml_yytext,type); */ 166 BEGIN(VRML2REFEND); } 167 <VRML2REF>.|\r|\n { } 168 169 170 <VRML2REFEND>{NQ}*{Q} { BEGIN(more ? VRML2URL : VRML2); } 171 <VRML2REFEND>.|\r|\n { } 172 173 /* End of file */ 174 175 <<EOF>> { BEGIN(INITIAL); return(0); } 176 177 %% 178