<delete> 
 
// This is a html2html converter. It's highlighting a html for  
// reading it with a browser 
 
<init append scan="macros"> 
  <init scan="html2html"> 
</init> 
 
// suppress a damn warning 
<define name=foo> 
function foo() {} 
</define> 
 
// the main function 
<define name=html2html init="html2html" PAR_1=infile> 
 
function html2html( infile_name ) { 
 
  // try open file 
  var infile = new File( infile_name, "r", true, true ); 
 
  if( !infile.is_valid() ) { 
    message( "ERROR: cannot open file", infile.get_name() ); 
    return; 
  } 
 
  // lex the file 
 
  var tmp = new File( get_tmp_file(), "rwt", false, false ); 
 
  var lexer = new Lexer( infile, tmp ); 
 
  if( ! lexer.is_valid() ) { 
    message( "ERROR: cannot lex file:", lexer.get_error() ); 
    return; 
  } 
 
  lexer.lex(); 
 
  if( ! lexer.is_valid() ) { 
    message( "ERROR: cannot lex file:", lexer.get_error() ); 
    return; 
  } 
 
 
  tmp.clear(); 
  tmp.seekg(0); 
 
  // rebuild informations 
  var lcur = 0;   // cursor pos 
  var lline = 0;  // line number 
  var fline = ""; // current reconstructed line 
 
  while( ! tmp.eof() ) { 
 
    var line = new Line( tmp.getline() ); 
    
    if( line.is_valid() ) { 
 
      var pline = line.tag; 
 
      // substitude special characters  
      pline = pline.replace( "&", "&amp;" ); 
      pline = pline.replace( "<", "&lt;" ); 
      pline = pline.replace( ">", "&gt;" ); 
 
      if( line.tag_type != "" ) { 
 
        // line is a tag 
	// just highlight it  
 
        var i = pline.indexOf( " " ); 
 
        if( i < 0 ) { 
          //   a tag always ends with an >, but this was converted in &lt; 
          //   these are 4 characters. 
          i = pline.length - 4; 
        } 
 
        // highlight the tag name 
        var tag_name = pline.substring( 0, 4 )  
	   + "<b class=\"tag_name\">"  
	   + pline.substring( 4, i )  
	   + "</b>"; 
        var where = tag_name.length; // remember the length 
        pline = tag_name + pline.substring( i, pline.length ); 
 
        var last = -1; 
 
        var npline = ""; 
 
        i = pline.indexOf( " ", where ); 
 
        if( i != -1 )  // does it has options? 
          pline = pline.substring( 0, i )  
	    + "<span class=\"tag_option\">" 
	    + pline.substring( i, pline.length - 4 ) 
	    + "</span>" 
	    + pline.substring( pline.length - 4, pline.length ); 
 
      } else { 
 
	// handle non tags 
	pline = "<i class=\"normal_text\">" + pline + "</i>"; 
      } 
 
 
      // reconstruct line 
      if( line.line_number != lline ) { 
	 
	lcur =  0; 
	lline = line.line_number; 
	 
	print( fline ); // print it out 
	fline = ""; 
      } 
       
      for( var i = 1; i < (line.cursor_pos - lcur); i++ ) { 
	fline = fline + " "; 
      } 
       
      lcur = line.cursor_pos; 
       
      fline = fline + pline; 
      lcur = lcur + pline.length;   
 
    }  
     
  }   
   
} 
 
</define> 
 
</delete> 
 
 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 
<head> 
  <title>Sources of INFILE</title> 
 
<style type="text/css"> 
.tag_option      { color: #009900; } 
.tag_name        { color: #FF0000; } 
.normal_text     { color: #000099; } 
</style> 
 
</head> 
<body> 
 
<pre> 
<html2html infile="INFILE"> 
</pre> 
 
</body>