xml.l
Upload User: seven77cht
Upload Date: 2007-01-04
Package Size: 486k
Code Size: 3k
Category:

Browser Client

Development Platform:

Unix_Linux

  1. W               [ trn]
  2. Q               ["']
  3. NQ              [^"']
  4. F               [-a-z0-9$_.!*(),%;/?:@&=+~|]
  5. %x ENTITY ENTITY_URL
  6. %x DOCTYPE DOCTYPE_URL
  7. %x COMMENT
  8. %{
  9. /***************************************
  10.   $Header: /home/amb/wwwoffle/RCS/xml.l 1.4 1999/07/11 10:16:23 amb Exp $
  11.   WWWOFFLE - World Wide Web Offline Explorer - Version 2.5.
  12.   Parse the XML and look for external references.
  13.   ******************/ /******************
  14.   Written by Walter Pfannenmueller
  15.   This file Copyright 1997,98,99 Andrew M. Bishop
  16.   It may be distributed under the GNU Public License, version 2, or
  17.   any higher version.  See section COPYING of the GNU Public license
  18.   for conditions under which this file may be redistributed.
  19.   ***************************************/
  20. #include "wwwoffle.h"
  21. #include "errors.h"
  22. #include "document.h"
  23. extern int xml_yylex(void);
  24. #define xml_yywrap() 1
  25. /*+ The file descriptor that we are reading from. +*/
  26. static int xml_yyfd=-1;
  27. /*++++++++++++++++++++++++++++++++++++++
  28.   Parse the XML and look for references.
  29.   int fd The file descriptor of the file to parse.
  30.   URL *Url The reference URL to use.
  31.   ++++++++++++++++++++++++++++++++++++++*/
  32. void ParseXML(int fd,URL *Url)
  33. {
  34.  static int first=1;
  35.  PrintMessage(Debug,"Parsing document using XML parser.");
  36.  xml_yyfd=fd;
  37.  if(!first)
  38.     xml_yyrestart(NULL);
  39.  BEGIN(INITIAL);
  40.  xml_yylex();
  41.  first=0;
  42. }
  43. /*+ A macro to read data that can be used by the lexer. +*/
  44. #define YY_INPUT(buf,result,max_size) 
  45.         if((result=read_data(xml_yyfd,buf,max_size))==-1) 
  46.            result=0;
  47. %}
  48. %%
  49.  /*
  50. Just doctypes and external entities are handled so far.
  51.  */
  52. [^<]+                 { }
  53. "<!--"                { BEGIN(COMMENT); }
  54. "<!ENTITY"            { BEGIN(ENTITY); }
  55. "<!DOCTYPE"           { BEGIN(DOCTYPE); }
  56. .|r|n               { }
  57.  /* ENTITIES */
  58. <ENTITY>{W}*           { }
  59. <ENTITY>"SYSTEM"{W}+{Q} { BEGIN(ENTITY_URL); }
  60. <ENTITY>"PUBLIC"{W}+{Q}{NQ}*{Q}{W}*{Q} { BEGIN(ENTITY_URL); }
  61. <ENTITY>">"            { BEGIN(INITIAL); }
  62. <ENTITY>.              { }
  63.  /* Urls from entities. */
  64. <ENTITY_URL>{F}+       { AddReference(xml_yytext,RefInlineObject); 
  65.                          BEGIN(INITIAL);}
  66.  /* DOCTYPE */
  67. <DOCTYPE>{W}*           { }
  68. <DOCTYPE>"SYSTEM"{W}+{Q} { BEGIN(ENTITY_URL); }
  69. <DOCTYPE>">"            { BEGIN(INITIAL); }
  70. <DOCTYPE>.              { }
  71.  /* Urls from entities. */
  72. <DOCTYPE_URL>{F}+       { AddReference(xml_yytext,RefInlineObject); 
  73.                          BEGIN(INITIAL);}
  74.  /* Comments */
  75. <COMMENT>[^->]+         { }
  76. <COMMENT>"-->"          { BEGIN(INITIAL); }
  77. <COMMENT>.|r|n        { }
  78. %%