2 #****h* Module/css_to_c.pl
7 # Turns a .css file into a piece of C code.
10 # Frans Slothouber (FSL), <rfsber@xs4all.nl> Gumpu Consulting
12 # 6-7-2006 12:45:01 W. Europe Standard Time
15 #******************************************************************************
16 # $Id: css_to_c.pl,v 1.4 2006/07/27 19:12:18 gumpu Exp $
23 # First preprocess the CSS code.
24 my $robodoc_css_file_name = "robodoc_basic_style.css";
25 my $robodoc_css_file = IO::File->new("<$robodoc_css_file_name") or die;
26 my @css = <$robodoc_css_file>;
27 $robodoc_css_file->close();
32 # wrap inside a " .. \n"
33 @css = map { chomp($_); s/%/%%/g; s/"/\\"/g; "\"$_\\n\"\n" } @css;
35 # Split the whole file into several parts each with
37 # This to avoid compiler warning about string that
39 my @split_css_code = ();
40 my $l = 0; # Length of the string
41 push( @split_css_code, " fprintf( css_file,\n" );
42 foreach my $line ( @css )
44 push( @split_css_code, $line );
45 $l += length( $line );
48 push( @split_css_code, " );\n" );
49 push( @split_css_code, " fprintf( css_file,\n" );
52 push( @split_css_code, " );\n" );
55 # Insert CSS code into html_generator.c
57 # Read the original code.
58 my $html_generator_file = IO::File->new("<html_generator.c") or die;
59 my @code = <$html_generator_file>;
60 $html_generator_file->close();
63 my $html_generator_file_bak = IO::File->new(">html_generator_bak.c") or die;
64 print $html_generator_file_bak @code;
65 $html_generator_file_bak->close();
67 # Merge the C code with the CSS code.
70 foreach my $line ( @code ) {
71 if ( $line =~ m/BEGIN\sBEGIN\s/ ) {
73 push( @new_code, $line );
74 push( @new_code, @split_css_code );
76 } elsif ( $line =~ m/END\sEND\s/ ) {
77 push( @new_code, $line );
83 push( @new_code, $line );
89 $html_generator_file = IO::File->new(">html_generator.c") or die;
91 print $html_generator_file @new_code;
93 $html_generator_file->close();