Changeset acfbb5a in git for doc/doc2tex.pl


Ignore:
Timestamp:
Jul 6, 1999, 1:58:18 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
472f39ab0b89934d33bab9f90e3d8c81263ba84e
Parents:
f34c37c0f30bac8eb447294a36d841edfed9711e
Message:
* as we go along


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

Legend:

Unmodified
Added
Removed
  • doc/doc2tex.pl

    rf34c37c racfbb5a  
    11#!/usr/local/bin/perl
    2 # $Id: doc2tex.pl,v 1.2 1999-07-01 12:48:00 obachman Exp $
     2# $Id: doc2tex.pl,v 1.3 1999-07-06 11:58:09 obachman Exp $
    33###################################################################
    44#  Computer Algebra System SINGULAR
     
    3636#
    3737####
    38 # @c lib libname.lib [no_ex, lib_fun, lib_ex]
     38# @c lib libname.lib[:proc] [no_ex, lib_fun, lib_ex]
     39#   Without :proc
    3940#   --> includes info of libname.lib in output file
    4041#   --> includes function names of info into function index
     
    4243#                      their help into output file
    4344#   --> if lib_ex is given, includes computed examples of functions, as well
    44 #
     45#   With :proc
     46#   --> includes content of procedure 'proc' from library libname:lib
     47#
    4548#   Optional no_ex, lib_fun, lib_ex arguments overwrite respective
    4649#    command-line arguments
     
    138141#
    139142open(DOC, "<$doc_file")
    140   || die "$ERROR can't open $doc_file for reading: $!\n" . &Usage;
    141 open(TEX, ">$tex_file") || die "$ERROR can't open $tex_file for writing: $!\n";
     143  || Error("can't open $doc_file for reading: $!\n" . &Usage);
     144open(TEX, ">$tex_file") || Error("can't open $tex_file for writing: $!\n");
    142145print "d2t: Generating $tex_file from $doc_file ...\n" if ($verbose > 1);
    143146print "d2t: $doc_file ==> $tex_file\n" if ($verbose == 1);
     
    150153{
    151154  mkdir($doc_subdir, oct(755))
    152     || die "$ERROR can't create directory $doc_subdir: $!\n";
     155    || Error("can't create directory $doc_subdir: $!\n");
    153156  print "d2t: Created $doc_subdir for intermediate files\n" 
    154157    if ($verbose > 1);
     
    232235    }
    233236  }
    234   die "$ERROR no matching '\@c example' found for $doc_file:$lline\n"
     237  Error("no matching '\@c example' found for $doc_file:$lline\n")
    235238    unless (/^\@c\s*example\s*$/);
    236239
     
    256259
    257260    # run singular
    258     open(EX, ">$ex_file") || die "$ERROR can't open $ex_file for writing: $!\n";
     261    open(EX, ">$ex_file") || Error("can't open $ex_file for writing: $!\n");
    259262    print EX "$thisexample\$\n";
    260263    close(EX);
     
    263266    print ")" if ($verbose == 1);
    264267
    265     open(RES, "<$res_file") || die "$ERROR can't open $res_file for reading: $!\n";
    266     open(INC, ">$inc_file") || die "$ERROR can't open $inc_file for writing: $!\n";
     268    open(RES, "<$res_file") || Error("can't open $res_file for reading: $!\n");
     269    open(INC, ">$inc_file") || Error("can't open $inc_file for writing: $!\n");
    267270
    268271    $include = '';
     
    272275      last if (/^$ex_file\s*([0-9]+)..\$/);
    273276      # check for error
    274       die "$ERROR while running example $example from $doc_file:$lline.\nCall: '$Singular $Singular_opts $ex_file > $res_file'\n"
     277      Error("while running example $example from $doc_file:$lline.\nCall: '$Singular $Singular_opts $ex_file > $res_file'\n")
    275278        if (/error occurred/ && ! $error_ok);
    276279      # remove stuff from echo
     
    405408{
    406409  local($lib, $lib_name, $ltex_file, $l_ex, $l_fun);
    407  
     410  my ($func);
     411
    408412  if (/^\@c\s*lib\s+([^\.]+)\.lib(.*)/)
    409413  {
     
    419423  }
    420424
     425  $func = $1 if (/^:(.*?) /);
    421426  $l_fun = 1 if (($lib_fun || (/lib_fun/)) && !/no_fun/);
    422427  $l_ex = 1 if (($lib_ex || /lib_ex/) && !/no_ex/ && $l_fun);
     
    436441  $ltex_file .= ".tex";
    437442 
    438   die "$ERROR can't open $lib.lib for reading: $!\n"
     443  Error("can't open $lib.lib for reading: $!\n")
    439444    unless  ($lib_dir = &Open(*LIB, "<$lib.lib"));
    440445  close (LIB);
     
    442447      IsNewer($ltex_file, "$lib_dir/$lib.lib"))
    443448  {
    444     print "<lib $lib>" if ($verbose);
    445     $reuse_this = 1;
    446     print TEX "\@c reused lib docu for $lib_name $doc_file:$line \n";
     449    unless ($func)
     450    {
     451      print "<lib $lib>" if ($verbose);
     452      print TEX "\@c reused lib docu for $lib_name $doc_file:$line \n";
     453    }
    447454  }
    448455  elsif (&GenerateLibDoc($lib, $ltex_file, $l_fun, $l_ex))
    449456  {
    450     print TEX "\@c generated lib docu for $lib_name $doc_file:$line \n";
     457    print TEX "\@c generated lib docu for $lib_name $doc_file:$line \n"
     458      unless $func;
    451459    open(LTEX, "<$ltex_file")
    452       || die "$ERROR can't open $ltex_file for reading: $!\n";
    453   }
    454   while (<LTEX>) {print TEX $_;}
     460      || Error("can't open $ltex_file for reading: $!\n");
     461  }
     462  if ($func)
     463  {
     464    print "<$lib:$func" if $verbose;
     465    print TEX "\@c generated lib proc docu for $lib_name:$func $doc_file:$line \n";
     466    my $found = 0;
     467    while (<LTEX>)
     468    {
     469      $found = 1 if /c ---content $func---/;
     470      print TEX $_ if $found;
     471      last if $found && /c ---end content $func---/;
     472    }
     473    if ($found)
     474    {
     475      Error("no end content found for lib proc docu for $lib_name:$func $doc_file:$line \n")
     476        unless (/c ---end content $func---/);
     477      print TEX "\@c generated lib proc docu for $lib_name:$func $doc_file:$line \n";
     478    }
     479    else
     480    {
     481      Error("did not find lib proc docu for $lib_name:$func $doc_file:$line \n");
     482    }
     483    print ">" if $verbose;
     484  }
     485  else
     486  {
     487    while (<LTEX>) {print TEX $_;}
     488    print TEX "\@c end generated lib docu for $lib_name $doc_file:$line \n";
     489  }
    455490  close(LTEX);
    456   print TEX "\@c end generated lib docu for $lib_name $doc_file:$line \n";
    457491  unlink $ltex_file if ($clean);
    458492}
     
    471505  $doc_file .= ".doc";
    472506
    473   die "$ERROR can't open $lib.lib for reading: $!\n"
     507  Error("can't open $lib.lib for reading: $!\n")
    474508    unless  ($lib_dir = &Open(*LIB, "<$lib.lib"));
    475509  close (LIB);
     
    477511  {
    478512    print "<doc>" if ($verbose == 1);
    479     print TEX "\@c reused file $doc_file\n";
    480513  }
    481514  else
     
    486519    {
    487520      print "<pl>" if ($verbose == 1);
    488       print TEX "\@c reused file $pl_file\n";
    489521    }
    490522    else
     
    493525      &System("$libparse -i $lib_dir/$lib.lib > $pl_file");
    494526      print ")" if ($verbose == 1);
    495       print TEX "\@c generated file $pl_file\n";
    496527    }
    497528
    498529    print "(doc" if ($verbose == 1);
    499     print TEX "\@c generated file $doc_file\n";
    500530   
    501531    do $pl_file;
    502     die "$ERROR error while executing $pl_file: $@\n" if ($@);
     532    Error("error while executing $pl_file: $@\n") if ($@);
    503533    unlink ($pl_file) if ($clean);
    504534   
     
    507537   
    508538    # print header
    509     $info = &CleanUpHelp($info);
    510539    print LDOC "\@c library version: $version\n";
    511540    print LDOC "\@c library file: $library\n";
    512     print LDOC "\@strong{Overview:}\n\@example\n";
    513     print LDOC $info;
    514     print LDOC "\n\@end example\n";
    515     # generate findex for every routine mentioned
    516     while ($info =~ /^(.*)\n/)
    517     {
    518       $info = $';
    519       if ($1 =~ /^\s*(\w{1}[\w\d]*)\(.*\)/)
    520       {
    521         print LDOC "\@findex $1\n";
    522         print LDOC "\@cindex $1\n" if ($lib eq "standard");
    523       }
    524     }
    525    
     541    OutLibInfo(\*LDOC, $info, $l_fun);
    526542    # print menu of available functions
    527543    if ($l_fun)
     
    545561        print LDOC "\@findex ". $procs[$i] . "\n";
    546562        print LDOC "\@cindex ". $procs[$i] . "\n" if ($lib eq "standard");
    547        
     563
     564        print LDOC "\@c ---content $procs[$i]---\n";
    548565        # print help section
    549566        print LDOC "\@strong{Info:}\n";
     
    558575        print LDOC $example;
    559576        print LDOC "\n\@c example\n\@end example\n";
     577        print LDOC "\@c ---end content $procs[$i]---\n";
    560578      }
    561579    }
     
    574592  unlink($doc_file) if ($clean);
    575593  return 1;
     594}
     595
     596###########################################################################
     597# parse and print-out libinfo
     598sub OutLibInfo
     599{
     600  my ($FH, $info, $l_fun) = @_;
     601  my ($item, $text, $line);
     602  $info =~ s/^\s*//;
     603  $info =~ s/\s*$//;
     604  $info .= "\n";
     605
     606  print $FH "\@c ---content LibInfo---\n";
     607  print $FH "\@table \@code\n";
     608  while ($info =~ m/(.*\n)/g)
     609  {
     610    $line = $1;
     611    if ($1 =~ /^(\w.+?):(.*\n)/)
     612    {
     613      OutLibInfoItem($FH, $item, $text, $l_fun) if $item && $text;
     614      $item = $1;
     615      $text = $2;
     616    }
     617    else
     618    {
     619      $text .= $line;
     620    }
     621  }
     622  OutLibInfoItem($FH, $item, $text, $l_fun) if $item && $text;
     623  print $FH "\@end table\n";
     624  print $FH "\@c ---end content LibInfo---\n";
     625}
     626
     627sub OutLibInfoItem
     628{
     629  my ($FH, $item, $text, $l_fun) = @_;
     630
     631  $item = lc $item;
     632  $item = ucfirst $item;
     633  print $FH '@item @strong{'. "$item:}\n";
     634
     635  if (($item =~ m/^Library/)  && ($text =~ m/\s*(\w*)\.lib/))
     636  {
     637    print $FH "$1.lib\n";
     638    $text = $';
     639    if ($text =~ /\w/)
     640    {
     641      print $FH "\n" . '@item @strong{Purpose:'."}\n";
     642      print $FH lc $text;
     643    }
     644  }
     645  elsif ($item =~ m/rocedure/)
     646  {
     647    $text =~ s/^\s*//;
     648    $text =~ s/\s*$//;
     649    $text =~ s/.*$//
     650      if ($text =~ /parameters.*brackets\*are optional.*$/);
     651
     652    my ($proc, $pargs, $pinfo, $line);
     653    print $FH "\@table \@asis\n";
     654    $text .= "\n";
     655    while ($text =~ /(.*\n)/g)
     656    {
     657      $line = $1;
     658      if ($1 =~ /^\s*(\w+)\((.*?)\)/)
     659      {
     660        OutProcInfo($FH, $proc, $procargs, $pinfo, $l_fun) if $proc && $pinfo;
     661        $proc = $1;
     662        $procargs = $2;
     663        $pinfo = $';
     664      }
     665      else
     666      {
     667        $pinfo .= $line;
     668      }
     669    }
     670    OutProcInfo($FH, $proc, $procargs, $pinfo, $l_fun) if $proc && $pinfo;
     671    print $FH "\@end table\n\n";
     672  }
     673  else
     674  {
     675    local $_ = $text;
     676    s/^\s*//;
     677    s/\s*$//;
     678    s/ +/ /;
     679    &protect_texi;
     680    print $FH "$_\n\n";
     681  }
     682}
     683
     684sub OutProcInfo
     685{
     686  my($FH, $proc, $procargs, $pinfo, $l_fun) = @_;
     687  local $_ = $pinfo;
     688  s/^[;\s]*//;
     689  s/\s*$//;
     690  s/ +/ /g;
     691  s/\n */\n/g;
     692  &protect_texi;
     693 
     694  print $FH "\@item \@code{$proc($procargs)}  ";
     695  print $FH "\@ref{$proc}" if ($l_fun);
     696  print $FH "\n$_\n";
    576697}
    577698
     
    669790  local($call) = @_;
    670791  print "d2t system: $call\n" if ($verbose > 1);
    671   die "$ERROR non-zero exit status of system call: '$call': $!\n"
     792  Error("non-zero exit status of system call: '$call': $!\n")
    672793    if (system($call));
    673794}
    674795
    675    
     796sub Error
     797{
     798  print "$ERROR $_[0]";
     799  close(TEX);
     800  unlink $tex_file if $tex_file && -e $tex_file;
     801  exit(1);
     802}
     803
    676804#
    677805# leave this here --otherwise fontification in my emacs gets screwd up
Note: See TracChangeset for help on using the changeset viewer.