texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texinfo/tp/Texinfo Common.pm Parser.pm Convert/...


From: Patrice Dumas
Subject: texinfo/tp/Texinfo Common.pm Parser.pm Convert/...
Date: Wed, 13 Apr 2011 20:14:30 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/04/13 20:14:29

Modified files:
        tp/Texinfo     : Common.pm Parser.pm 
        tp/Texinfo/Convert: HTML.pm Info.pm Plaintext.pm 

Log message:
        Handle css.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.32&r2=1.33
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.240&r2=1.241
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Info.pm?cvsroot=texinfo&r1=1.52&r2=1.53
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.133&r2=1.134

Patches:
Index: Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -b -r1.32 -r1.33
--- Common.pm   12 Apr 2011 21:29:06 -0000      1.32
+++ Common.pm   13 Apr 2011 20:14:29 -0000      1.33
@@ -127,7 +127,8 @@
   'CSS_LINES', 'RENAMED_NODES_REDIRECTIONS', 'RENAMED_NODES_FILE',
   'TEXI2DVI', 'DUMP_TREE', 'MAX_MACRO_CALL_NESTING',
   'PROGRAM_AND_VERSION', 'PROGRAM_HOMEPAGE', 'PROGRAM',
-  'AFTER_BODY_OPEN', 'EXTRA_HEAD', 'LINKS_BUTTONS', 'DO_ABOUT');
+  'AFTER_BODY_OPEN', 'EXTRA_HEAD', 'LINKS_BUTTONS', 'DO_ABOUT',
+  'CSS_FILES', 'CSS_REFS');
 
 my %valid_options;
 foreach my $var (@document_settable_at_commands, @document_global_at_commands,
@@ -662,6 +663,24 @@
   $encoding_aliases{$eight_bit_encoding_aliases{$encoding}} = $encoding;
 }
 
+sub locate_include_file($$)
+{
+  my $self = shift;
+  my $text = shift;
+  my $file;
+
+  #print STDERR "$self $text @{$self->{'include_directories'}}\n";
+  if ($text =~ m,^(/|\./|\.\./),) {
+    $file = $text if (-e $text and -r $text);
+  } else {
+    foreach my $dir (@{$self->{'include_directories'}}) {
+      $file = "$dir/$text" if (-e "$dir/$text" and -r "$dir/$text");
+      last if (defined($file));
+    }
+  }
+  return $file;
+}
+
 sub open_out ($$;$)
 {
   my $self = shift;

Index: Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.240
retrieving revision 1.241
diff -u -b -r1.240 -r1.241
--- Parser.pm   11 Apr 2011 00:38:44 -0000      1.240
+++ Parser.pm   13 Apr 2011 20:14:29 -0000      1.241
@@ -1912,24 +1912,6 @@
   }
 }
 
-sub _locate_include_file($$)
-{
-  my $self = shift;
-  my $text = shift;
-  my $file;
-
-  #print STDERR "$self $text @{$self->{'include_directories'}}\n";
-  if ($text =~ m,^(/|\./|\.\./),) {
-    $file = $text if (-e $text and -r $text);
-  } else {
-    foreach my $dir (@{$self->{'include_directories'}}) {
-      $file = "$dir/$text" if (-e "$dir/$text" and -r "$dir/$text");
-      last if (defined($file));
-    }
-  }
-  return $file;
-}
-     
 # close constructs and do stuff at end of line (or end of the document)
 sub _end_line($$$);
 sub _end_line($$$)
@@ -2349,7 +2331,7 @@
             $self->line_error (sprintf($self->__("Bad argument to 
address@hidden: %s"), $command, $line), $line_nr);
           }
         } elsif ($command eq 'include') {
-          my $file = $self->_locate_include_file($text) ;
+          my $file = Texinfo::Common::locate_include_file($self, $text) ;
           if (defined($file)) {
             my $filehandle = do { local *FH };
             if (open ($filehandle, $file)) {
@@ -4408,7 +4390,7 @@
   return $args;
 }
 
-# left here because it uses _locate_include_file
+# FIXME put this in a more suited file
 sub expand_verbatiminclude($$)
 {
   my $self = shift;
@@ -4416,7 +4398,7 @@
 
   return unless ($current->{'extra'} and 
defined($current->{'extra'}->{'text_arg'}));
   my $text = $current->{'extra'}->{'text_arg'};
-  my $file = _locate_include_file($self, $text);
+  my $file = Texinfo::Common::locate_include_file($self, $text);
 
   my $verbatiminclude;
 

Index: Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- Convert/HTML.pm     12 Apr 2011 23:52:53 -0000      1.18
+++ Convert/HTML.pm     13 Apr 2011 20:14:29 -0000      1.19
@@ -817,6 +817,7 @@
   foreach my $formatting_references (
      ['heading_text', \&default_heading_text, $Texinfo::Config::heading_text],
      ['comment', \&default_comment, $Texinfo::Config::comment],
+     ['css_lines', \&default_css_lines, $Texinfo::Config::css_lines],
   ) {
     if (defined($formatting_references->[2])) {
       $self->{$formatting_references->[0]} = $formatting_references->[2];
@@ -875,17 +876,173 @@
   return $id;
 }
 
+sub default_css_lines ($)
+{
+  my $self = shift;
+
+  my $css_refs = $self->get_conf('CSS_REFS');
+
+  return if (address@hidden>{'css_import_lines'}} and 
address@hidden>{'css_rule_lines'}}
+             and !keys(%{$self->{'css_map'}}) and address@hidden);
+
+  my $css_text = "<style type=\"text/css\">\n<!--\n";
+  $css_text .= join('',@{$self->{'css_import_lines'}}) . "\n" 
+    if (@{$self->{'css_import_lines'}});
+  foreach my $css_rule (sort(keys(%{$self->{'css_map'}}))) {
+    next unless ($self->{'css_map'}->{$css_rule});
+    $css_text .= "$css_rule {$self->{'css_map'}->{$css_rule}}\n";
+  }
+  $css_text .= join('',@{$self->{'css_rule_lines'}}) . "\n" 
+    if (@{$self->{'css_rule_lines'}});
+  $css_text .= "-->\n</style>\n";
+  foreach my $ref (@$css_refs) {
+    $css_text .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$ref\">\n";
+  }
+  $self->set_conf('CSS_LINES', $css_text);
+}
+
+sub _process_css_file ($$$)
+{
+  my $self = shift;
+  my $fh =shift;
+  my $file = shift;
+  my $in_rules = 0;
+  my $in_comment = 0;
+  my $in_import = 0;
+  my $in_string = 0;
+  my $rules = [];
+  my $imports = [];
+  my $line_nr = 0;
+  while (my $line = <$fh>) {
+    $line_nr++;
+    #print STDERR "Line: $line";
+    if ($in_rules) {
+      push @$rules, $line;
+      next;
+    }
+    my $text = '';
+    while (1) {
+      #sleep 1;
+      #print STDERR "${text}!in_comment $in_comment in_rules $in_rules 
in_import $in_import in_string $in_string: $line";
+      if ($in_comment) {
+        if ($line =~ s/^(.*?\*\/)//) {
+          $text .= $1;
+          $in_comment = 0;
+        } else {
+          push @$imports, $text . $line;
+          last;
+        }
+      } elsif (!$in_string and $line =~ s/^\///) { # what do '\' do here ?
+        if ($line =~ s/^\*//) {
+          $text .= '/*';
+          $in_comment = 1;
+        } else {
+          push (@$imports, $text. "\n") if ($text ne '');
+          push (@$rules, '/' . $line);
+          $in_rules = 1;
+          last;
+        }
+      } elsif (!$in_string and $in_import and $line =~ s/^([\"\'])//) { 
+        # strings outside of import start rules
+        $text .= "$1";
+        $in_string = quotemeta("$1");
+      } elsif ($in_string and $line =~ s/^(\\$in_string)//) {
+        $text .= $1;
+      } elsif ($in_string and $line =~ s/^($in_string)//) {
+        $text .= $1;
+        $in_string = 0;
+      } elsif ((! $in_string and !$in_import) 
+              and ($line =~ s/^(address@hidden)$// 
+                   or $line =~ s/^(address@hidden)//)) {
+        $text .= $1;
+        $in_import = 1;
+      } elsif (!$in_string and $in_import and $line =~ s/^\;//) {
+        $text .= ';';
+        $in_import = 0;
+      } elsif (($in_import or $in_string) and $line =~ s/^(.)//) {
+        $text .= $1;
+      } elsif (!$in_import and $line =~ s/^([^\s])//) {
+        push (@$imports, $text. "\n") if ($text ne '');
+        push (@$rules, $1 . $line);
+        $in_rules = 1;
+        last;
+      } elsif ($line =~ s/^(\s)//) {
+        $text .= $1;
+      } elsif ($line eq '') {
+        push (@$imports, $text);
+        last;
+      }
+    }
+  }
+  #file_line_warn (__("string not closed in css file"), $file) if ($in_string);
+  #file_line_warn (__("--css-file ended in comment"), $file) if ($in_comment);
+  #file_line_warn (__("address@hidden not finished in css file"), $file)  if 
($in_import and !$in_comment and !$in_string);
+  warn (sprintf($self->__("%s:%d: string not closed in css file"), 
+                $file, $line_nr)) if ($in_string);
+  warn (sprintf($self->__("%s:%d: --css-file ended in comment"), 
+                $file, $line_nr)) if ($in_comment);
+  warn (sprintf($self->__("%s:%d address@hidden not finished in css file"), 
+        $file, $line_nr)) 
+    if ($in_import and !$in_comment and !$in_string);
+  return ($imports, $rules);
+}
+
 sub _prepare_css($)
 {
   my $self = shift;
   
   return if ($self->get_conf('NO_CSS'));
-  # TODO collect_all_css_files in texi2html.pl
-  #  ($Texi2HTML::THISDOC{'css_import_lines'}, 
$Texi2HTML::THISDOC{'css_rule_lines'})
-  #    = collect_all_css_files();
-  # &$Texi2HTML::Config::css_lines($Texi2HTML::THISDOC{'css_import_lines'},
-  #     $Texi2HTML::THISDOC{'css_rule_lines'});
-  # T2H_DEFAULT_css_lines in texi2html.init
+
+  my @css_import_lines;
+  my @css_rule_lines;
+
+  my $css_files = $self->get_conf('CSS_FILES');
+  foreach my $file (@$css_files) {
+    my $css_file_fh;
+    my $css_file;
+    if ($file eq '-') {
+      $css_file_fh = \*STDIN;
+      $css_file = '-';
+    } else {
+      $css_file = locate_include_file ($file);
+      unless (defined($css_file)) {
+        $self->document_warn (sprintf(
+               $self->__("css file %s not found"), $file));
+        next;
+      }
+      unless (open (CSSFILE, "$css_file")) {
+        $self->document_warn (sprintf($self->__(
+             "could not open --css-file %s: %s"), 
+              $css_file, $!));
+        next;
+      }
+      $css_file_fh = \*CSSFILE;
+    }
+    my ($import_lines, $rules_lines);
+    ($import_lines, $rules_lines) 
+      = $self->_process_css_file ($css_file_fh, $css_file);
+    push @css_import_lines, @$import_lines;
+    push @css_rule_lines, @$rules_lines;
+
+  }
+  if ($self->get_conf('DEBUG')) {
+    if (@css_import_lines) {
+      print STDERR "# css import lines\n";
+      foreach my $line (@css_import_lines) {
+        print STDERR "$line";
+      }
+    }
+    if (@css_rule_lines) {
+      print STDERR "# css rule lines\n";
+      foreach my $line (@css_rule_lines) {
+        print STDERR "$line";
+      }
+    }
+  }
+  $self->{'css_import_lines'} = address@hidden;
+  $self->{'css_rule_lines'} = address@hidden;
+
+  &{$self->{'css_lines'}}($self);
 }
 
 sub _node_id_file($$)

Index: Convert/Info.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Info.pm,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- Convert/Info.pm     5 Apr 2011 22:43:36 -0000       1.52
+++ Convert/Info.pm     13 Apr 2011 20:14:29 -0000      1.53
@@ -540,7 +540,7 @@
     }
     my $image_file;
     foreach my $extension (@extensions) {
-      if ($self->Texinfo::Parser::_locate_include_file ($basefile.$extension)) 
{
+      if ($self->Texinfo::Common::locate_include_file ($basefile.$extension)) {
         # use the basename and not the file found.  It is agreed that it is
         # better, since in any case the files are moved.
         $image_file = $basefile.$extension;

Index: Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -b -r1.133 -r1.134
--- Convert/Plaintext.pm        10 Apr 2011 20:36:29 -0000      1.133
+++ Convert/Plaintext.pm        13 Apr 2011 20:14:29 -0000      1.134
@@ -968,7 +968,7 @@
   my $root = shift;
   my $basefile = shift;
 
-  my $txt_file = $self->Texinfo::Parser::_locate_include_file 
($basefile.'.txt');
+  my $txt_file = $self->Texinfo::Common::locate_include_file 
($basefile.'.txt');
   if (!defined($txt_file)) {
     return undef;
   } else {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]