Changeset 84dee1 in git for doc/doc2tex.pl


Ignore:
Timestamp:
Jul 22, 1999, 3:35:12 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
71e701495c253cc11e495110cf351fcbf5292bbc
Parents:
0a2ba89accf5ea2b0f3e9b285eb4945f8dad6aba
Message:
*** empty log message ***


git-svn-id: file:///usr/local/Singular/svn/trunk@3327 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/doc2tex.pl

    r0a2ba89 r84dee1  
    11#!/usr/local/bin/perl
    2 # $Id: doc2tex.pl,v 1.13 1999-07-22 07:21:31 wichmann Exp $
     2# $Id: doc2tex.pl,v 1.14 1999-07-22 13:35:12 obachman Exp $
    33###################################################################
    44#  Computer Algebra System SINGULAR
     
    1010#    -> the text till the next @c example is feed into Singular,
    1111#       the text is then substituted by
    12 #       @c computed example $example $doc_file:$line
     12#       @c computed example $ex_prefix $doc_file:$line
    1313#       <text from the input>
    1414#       @expansion{} <corresponding output>
    1515#       ....
    16 #       @c end computed example $example $doc_file:$line
    17 #       reuse computed examples if ($reuse && -r $example.inc)
     16#       @c end computed example $ex_prefix $doc_file:$line
     17#       reuse computed examples if ($reuse && -r $ex_prefix.inc)
    1818#       cut absolute directory names from the loaded messages
    1919#       substituted @,{ and } by @@, @{ resp. @}
     
    6464$doc_subdir = "./d2t_singular";
    6565@include_dirs = (".", "../Singular/LIB");
    66 $doc_examples_db = "$doc_subdir/examples";
    6766$make = 0;
     67$make_opts = " --no-print-directory";
    6868
    6969#
     
    110110  if (/^-no_e(x)?$/)     { $no_ex = 1; next;}
    111111  if (/^-no_fu(n)?$/)    { $no_fun = 1;next;}
    112   if (/^-m(ake)?$/)      { $make = 1;next;}
     112  if (/^-m(ake)?$/)      { $make =  shift(@ARGV);next;}
    113113  if (/^-s(ubdir)?$/)    { $doc_subdir = shift(@ARGV); next;}
    114114  if (/^-I$/)            { unshift(@include_dirs, shift(@ARGV)); next;}
     
    118118}
    119119$verbose = ($verbose < 0 ? 0 : $verbose);
     120$make_opts .= " -s" unless $verbose > 1;
    120121
    121122#
     
    144145  || Error("can't open $doc_file for reading: $!\n" . &Usage);
    145146open(TEX, ">$tex_file") || Error("can't open $tex_file for writing: $!\n");
    146 print "d2t: Generating $tex_file from $doc_file ...\n" if ($verbose > 1);
     147print "(d2t $doc_file==>$tex_file" if ($verbose);
    147148if (-d $doc_subdir)
    148149{
    149   print "d2t: Using $doc_subdir for intermediate files\n" 
    150     if ($verbose > 1);
     150  print "<subdir: $doc_subdir>"  if ($verbose > 1);
    151151}
    152152else
     
    154154  mkdir($doc_subdir, oct(755))
    155155    || Error("can't create directory $doc_subdir: $!\n");
    156   print "d2t: Created $doc_subdir for intermediate files\n" 
    157     if ($verbose > 1);
    158 }
    159 
    160 # dbmopen(%EXAMPLES, $doc_examples_db, oct(755)) || die "$ERROR: can't open examples data base: $!\n";
     156  print "(subdir: $doc_subdir)"  if ($verbose > 1);
     157}
    161158
    162159#######################################################################
     
    173170  if (/^\@c\s*lib\s+/)      {&HandleLib; next;}
    174171  if (/^\@setfilename/)     {print TEX "\@setfilename $doc.hlp\n"; next;}
    175                              
     172
     173  if (/^\@\w*section\s*(\w+)/ || /^\@\w*chapter\s*(\w+)/)
     174  {
     175    $section = lc(substr($1, 0, 6));
     176  }
     177 
    176178  print TEX $_;
    177179
     
    183185#
    184186close(TEX);
    185 #dbmclose(%EXAMPLES);
    186 print "\nd2t: Finished generation of $tex_file \n" if ($verbose > 1);
    187 print "\n" if ($verbose == 1);
     187print "==>$tex_file)\n" if ($verbose);
    188188
    189189
     
    192192#    -> the text till the next @c example is feed into Singular,
    193193#       the text is then substituted by
    194 #       @c computed example $example $doc_file:$line
     194#       @c computed example $ex_prefix $doc_file:$line
    195195#       <text from the input>
    196196#       @expansion{} <corresponding output>
    197197#       ....
    198 #       @c end computed example $example $doc_file:$line
    199 #       reuse computed examples if ($reuse && -r $example.inc)
     198#       @c end computed example $ex_prefix $doc_file:$line
     199#       reuse computed examples if ($reuse && -r $ex_prefix.inc)
    200200#       cut absolute directory names from the loaded messages
    201201#       substituted @,{ and } by @@, @{ resp. @}
     
    205205sub HandleExample
    206206{
    207   my($lline, $thisexample, $include, $error_ok);
     207  my($inc_file, $ex_file, $lline, $thisexample, $error_ok, $cache);
    208208 
    209209  $lline = $line;
    210   $example++;
     210  $section = 'unknown' unless $section;
     211  $ex_prefix = $section;
     212  $ex_prefix .= "$examples{$section}" if $examples{$section};
     213  $examples{$section}++;
    211214
    212215  if ($no_ex)
    213216  {
    214     print "{$example}" if ($verbose);
    215     print TEX "\@c skipped computation of example $example $doc_file:$lline \n";
     217    print "{$ex_prefix}" if ($verbose);
     218    print TEX "\@c skipped computation of example $ex_prefix $doc_file:$lline \n";
    216219   
     220  }
     221  else
     222  {
     223    $inc_file = "$doc_subdir/$doc" . "_$ex_prefix.inc";
     224    $ex_file = "$doc_subdir/$doc" . "_$ex_prefix.tst";
     225    if (-r $inc_file && -r $ex_file && -s $inc_file && -s $ex_file)
     226    {
     227      $cache = 1;
     228      open(TST, "<$ex_file") || ($cache = 0);
     229    }
    217230  }
    218231
     
    232245    else
    233246    {
    234       $thisexample .= $_ unless (/^\s*$/);
    235     }
    236   }
     247      $thisexample .= $_;
     248      if ($cache && $_ && $_ ne <TST>)
     249      {
     250        $cache = 0;
     251        close(TST);
     252      }
     253    }
     254  }
     255  close(TST) if $cache;
    237256  Error("no matching '\@c example' found for $doc_file:$lline\n")
    238257    unless (/^\@c\s*example\s*$/);
     
    242261
    243262  # check whether it can be reused
    244   if ($reuse && ($include = $EXAMPLES{$thisexample}))
    245   {
    246     print "<$example>" if ($verbose);
    247     print TEX "\@c reused example $example $doc_file:$lline \n";
     263  if ($reuse && $cache)
     264  {
     265    print "<$ex_prefix>" if ($verbose);
     266    print TEX "\@c reused example $ex_prefix $doc_file:$lline \n";
     267    open(INC, "<$inc_file") || Error("can't open $inc_file for reading: $!\n");
     268    while (<INC>){ print TEX $_;}
     269    close(INC);
    248270  }
    249271  else
    250272  {
    251     print "($example" if ($verbose == 1);
    252     my ($ex_file, $res_file, $inc_file);
    253     $inc_file = "$doc_subdir/$doc"."_$example.inc";
    254     $ex_file = "$doc_subdir/$doc"."_$example.tst";
    255     $res_file = "$doc_subdir/$doc"."_$example.res";
    256 
    257     print TEX "\@c computed example $example $doc_file:$lline \n";
     273    print "($ex_prefix" if ($verbose == 1);
     274    my ($res_file);
     275    $res_file = "$doc_subdir/$doc" . "_$ex_prefix.res";
     276
     277    print TEX "\@c computed example $ex_prefix $doc_file:$lline \n";
    258278
    259279    # run singular
     
    268288    open(INC, ">$inc_file") || Error("can't open $inc_file for writing: $!\n");
    269289
    270     $include = '';
    271290    # get result, manipulate it and put it into inc file
    272291    while (<RES>)
     
    274293      last if (/^$ex_file\s*([0-9]+)..\$/);
    275294      # check for error
    276       Error("while running example $example from $doc_file:$lline.\nCall: '$Singular $Singular_opts $ex_file > $res_file'\n")
     295      Error("while running example $ex_prefix from $doc_file:$lline.\nCall: '$Singular $Singular_opts $ex_file > $res_file'\n")
    277296        if (/error occurred/ && ! $error_ok);
    278297      # remove stuff from echo
     
    300319        $_ = "\@expansion{} ".$_;
    301320      }
    302       $include .= $_;
    303321      print INC $_;
     322      print TEX $_;
    304323    }
    305324    close(RES);
    306325    close(INC);
    307326    unlink $ex_file, $res_file, $inc_file if ($clean);
    308     $EXAMPLES{$thisexample} = $include;
    309   }
    310   print TEX $include;
    311   print TEX "\@c end example $example $doc_file:$lline\n";
     327  }
     328  print TEX "\@c end example $ex_prefix $doc_file:$lline\n";
    312329}
    313330 
     
    440457  if ($make)
    441458  {
    442     print "<lib $lib" if ($verbose);
    443     if ($verbose <= 1)
    444     {
    445       System("make $tex_file > /dev/null")
    446     }
    447     else
    448     {
    449       System("make $tex_file");
    450     }
     459    print "<lib $lib " if ($verbose);
     460    System("make $make_opts VERBOSE=$verbose $tex_file");
    451461  }
    452462 
     
    456466    if ($verbose)
    457467    {
    458       print "<lib $lib" unless $make;
    459       print ":$proc" if $proc;
    460       print ">";
     468      print "<lib $lib " unless $make;
     469      print "$proc>";
    461470    }
    462471  }
     
    546555{
    547556  local($call) = @_;
    548   print "\nd2t system: $call\n" if ($verbose > 1);
     557  print " d2t system:\n$call\n" if ($verbose > 1);
    549558  Error("non-zero exit status of system call: '$call': $!\n")
    550559    if (system($call));
     
    573582                          (default: input_file.tex)
    574583  -clean        : delete intermediate files
    575   -make         : use make to generate tex files for libraries
     584  -make  cmd    : use cmd as make command to generate tex files for libraries
    576585  -no_reuse     : don't reuse intermediate files
    577586  -no_ex        : skip computation of examples
Note: See TracChangeset for help on using the changeset viewer.