Friday 15 May 2015

Insert text in the input file in Lex (with C) -


I am trying to help a friend at a college job, but I like one of the Lex Forgot a lot

That's it, we're trying to parse a HTML and a reporter CSS file and add the style of the tag.

Example:

HTML

& lt; Body & gt; & Lt; / Body & gt;

CSS

  body {color: black;}  

Modified HTML

  & lt; Body style = "color: black;" & Gt; & Lt; / Body & gt;  

All regex is done and the macro also

problem:. Input HTML and the modified HTML will be the same file. We tried to redirect yyin and yyout to the same file ... and then use the files (text, yyout); Where the text is a four * with all style information (and style = "") it does not work.

So ... can you help him?

It is not to lose the perception of space in its important file (hence the style = "" to tag it correctly).

Thanks

The yyin and yyout redirect file will not work for the same (As you already know). My approach will be:

  1. Create a temporary file
  2. Yyout temporary file
  3. writes to finish in parse, backup for the input file
  4. replace the input file with the temporary file

There is no other way, if yyout yyin is the same as your (original input) text will be overlaped .


No comments:

Post a Comment