views:

176

answers:

1

Hey!

I'm trying to help a friend in a college assignment, but i kind of forgot a lot of C an Lex.

The thing is, we are trying to parse a HTML and a correspondent CSS file and add to a tag it's style.

Eg:

HTML

<body>
</body>

CSS

body{color:black;}

modified HTML

<body style="color:black;">
</body>


All the regex are done and the Macros too.

Problem: The input HTML and modified HTML gotta be the same file. We tried redirect both yyin and yyout to the same file... and then use the fputs(text, yyout); where text is a char * with all the style information (and style=""). It doesn't work.

So... Can you guys help him?

its important not to lose the notion of location in the file (so the style="" goes to the right tag).

Thanks

+2  A: 

redirect yyin and yyout to the same file will not work.. ( as you already know ) . My approach would be:

  1. Create a temp file
  2. yyout writes to temp file
  3. when parsing is finish, backup input file for safety
  4. replace input file with the temp file

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

empc
Thank you. Other question: can we open the css file for parsing and save the position we are at in the html file? i look for yypos but it doesn't exist...Thanks again
Mario Cesar
yylineno holds the line number..
empc