Changeset dc3a44 in git for doc/doc2tex.pl


Ignore:
Timestamp:
Jul 7, 1999, 6:38:39 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
4deddb979be065737d63e926fc05f264a6b1078a
Parents:
6b6f22f3903a15b732ac1ca6615c2387a71ac03b
Message:
* generation of library docu


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

Legend:

Unmodified
Added
Removed
  • doc/doc2tex.pl

    r6b6f22 rdc3a44  
    11#!/usr/local/bin/perl
    2 # $Id: doc2tex.pl,v 1.3 1999-07-06 11:58:09 obachman Exp $
     2# $Id: doc2tex.pl,v 1.4 1999-07-07 16:38:34 obachman Exp $
    33###################################################################
    44#  Computer Algebra System SINGULAR
     
    495495{
    496496  my($lib, $tex_file, $l_fun, $l_ex) = @_;
    497   my($lib_dir, $scall, $pl_file, $doc_file, $i, $example,$largs);
     497  my($lib_dir, $scall, $pl_file, $doc_file, $i, $example,$largs, $ref);
    498498  # vars from executing the library perl scrip
    499   local($info, $libary, $version, @procs, %example, %help);
     499  local($info, $libary, $version, @procs, %example, %help, $table_is_open);
    500500 
    501501  print "(lib $lib: " if ($verbose == 1);
     
    539539    print LDOC "\@c library version: $version\n";
    540540    print LDOC "\@c library file: $library\n";
    541     OutLibInfo(\*LDOC, $info, $l_fun);
     541    undef @procs;
     542    $ref = OutLibInfo(\*LDOC, $info, $l_fun);
     543    OutRef(\*LDOC, $ref) if $ref;
    542544    # print menu of available functions
    543545    if ($l_fun)
    544546    {
    545       @procs = sort(@procs);
    546       print LDOC "\@menu\n";
    547       foreach $proc (@procs) {print LDOC "* $proc"."::\n";}
    548       print LDOC "\@end menu\n";
    549      
    550547      # print help and example of each function
    551548      for ($i = 0; $i <= $#procs; $i++)
     
    563560
    564561        print LDOC "\@c ---content $procs[$i]---\n";
    565         # print help section
    566         print LDOC "\@strong{Info:}\n";
    567         print LDOC "\@example\n";
    568         print LDOC &CleanUpHelp($help{$procs[$i]});
    569         print LDOC "\n\@end example\n";
    570        
    571         # print example section
    572         next unless ($example = &CleanUpExample($lib, $example{$procs[$i]}));
    573         print LDOC "\@strong{Example:}\n";
    574         print LDOC "\@example\n\@c example\n";
    575         print LDOC $example;
    576         print LDOC "\n\@c example\n\@end example\n";
     562        print LDOC "\@table \@asis\n";
     563        $table_is_open = 1;
     564        # print help
     565        $ref = OutInfo(\*LDOC, $help{$procs[$i]});
     566        print LDOC "\@end table\n";
     567        $table_is_open = 0;
     568        # print example
     569        if ($example = &CleanUpExample($lib, $example{$procs[$i]}))
     570        {
     571          print LDOC "\@strong{Example:}\n";
     572          print LDOC "\@example\n\@c example\n";
     573          print LDOC $example;
     574          print LDOC "\n\@c example\n\@end example\n";
     575        }
     576        OutRef(\*LDOC, $ref) if $ref;
    577577        print LDOC "\@c ---end content $procs[$i]---\n";
    578578      }
     
    599599{
    600600  my ($FH, $info, $l_fun) = @_;
    601   my ($item, $text, $line);
     601  print $FH "\@c ---content LibInfo---\n";
     602  print $FH "\@table \@asis\n";
     603  $table_is_open = 1;
     604 
     605  my ($ref) = OutInfo($FH, $info, $l_fun);
     606
     607  print $FH "\@end table\n" if $table_is_open;
     608  print $FH "\@c ---end content LibInfo---\n";
     609  $table_is_open = 0;
     610  return $ref;
     611}
     612
     613sub OutInfo
     614{
     615  my ($FH, $info, $l_fun) = @_;
    602616  $info =~ s/^\s*//;
    603617  $info =~ s/\s*$//;
    604618  $info .= "\n";
    605619
    606   print $FH "\@c ---content LibInfo---\n";
    607   print $FH "\@table \@code\n";
     620  my ($item, $text, $line, $ref);
    608621  while ($info =~ m/(.*\n)/g)
    609622  {
     
    611624    if ($1 =~ /^(\w.+?):(.*\n)/)
    612625    {
    613       OutLibInfoItem($FH, $item, $text, $l_fun) if $item && $text;
     626      $ref .= OutInfoItem($FH, $item, $text, $l_fun) if $item && $text;
    614627      $item = $1;
    615628      $text = $2;
     
    620633    }
    621634  }
    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 
    627 sub OutLibInfoItem
     635  $ref .= OutInfoItem($FH, $item, $text, $l_fun) if $item && $text;
     636  return $ref;
     637}
     638
     639sub FormatInfoText
     640{
     641  s/^\s*//; # remove whitespaces from beginning and end
     642  s/\s*$//;
     643  s/ +/ /g;  # replace double whitespeces by one
     644  &protect_texi; # protect texinfo special chars
     645  s/\n/\n\@*/g; # replace newline by forced newline
     646}
     647
     648sub OutInfoItem
    628649{
    629650  my ($FH, $item, $text, $l_fun) = @_;
     
    631652  $item = lc $item;
    632653  $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   {
     654
     655  if ($item =~ /see also/i)
     656  {
     657    # return references
     658    return $text;
     659  }
     660  elsif ($item =~ m/example/i)
     661  {
     662    # forget about example, since it comes explicitely
     663    return '';
     664  }
     665  elsif ($item =~ m/procedure/i)
     666  {
     667    if ($l_fun && $table_is_open)
     668    {
     669      print $FH "\@end table\n\n";
     670      $table_is_open = 0;
     671    }
    647672    $text =~ s/^\s*//;
    648673    $text =~ s/\s*$//;
    649     $text =~ s/.*$//
    650       if ($text =~ /parameters.*brackets\*are optional.*$/);
    651 
     674    $text =~ s/.*$// if ($text=~/parameters.*brackets.*are.*optional.*$/);
     675    $text .= "\n";
     676   
    652677    my ($proc, $pargs, $pinfo, $line);
    653     print $FH "\@table \@asis\n";
    654     $text .= "\n";
     678    if ($l_fun)
     679    {
     680      print $FH "\@strong{$item}\n\@menu\n";
     681    }
     682    else
     683    {
     684      print $FH "\@item \@strong{$item}\n\@table \@asis\n";
     685    }
    655686    while ($text =~ /(.*\n)/g)
    656687    {
     
    669700    }
    670701    OutProcInfo($FH, $proc, $procargs, $pinfo, $l_fun) if $proc && $pinfo;
    671     print $FH "\@end table\n\n";
     702    print $FH ($l_fun ? "\@end menu\n" : "\@end table\n");
     703    return '';
     704  }
     705
     706  if (! $table_is_open)
     707  {
     708    print $FH "\@table \@asis\n";
     709    $table_is_open = 1;
     710  }
     711  print $FH '@item @strong{'. "$item:}\n";
     712  # prepare text:
     713  local $_ = $text;
     714  if (($item =~ m/^library/i)  && m/\s*(\w*)\.lib/)
     715  {
     716    print $FH "$1.lib\n";
     717    $text = $';
     718    if ($text =~ /\w/)
     719    {
     720      print $FH "\n" . '@item @strong{Purpose:'."}\n";
     721      print $FH lc $text;
     722    }
    672723  }
    673724  else
    674725  {
    675     local $_ = $text;
    676     s/^\s*//;
    677     s/\s*$//;
    678     s/ +/ /;
    679     &protect_texi;
     726    # just print the text
     727    &FormatInfoText;
     728    # if functions are in text, then make it in code
     729    s/(\w+\(.*?\))/\@code{$1}/g
     730      if ($item =~ /usage/i || $item =~ /Return/i);
     731
    680732    print $FH "$_\n\n";
    681733  }
     734  return '';
    682735}
    683736
     
    687740  local $_ = $pinfo;
    688741  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";
    697 }
    698 
    699 ###################################################################
    700 #
    701 # Auxiallary functions
    702 #
    703 sub CleanUpHelp
    704 {
    705   local($_) = @_;
    706  
    707   # remove spaces quotations, etc from beginning and end
    708   s/^[^\w]*//;
    709   s/[\s\n"]*$//; #"
    710   # replace
    711   s/\\\\/\\/g;
    712   s/\\"/"/g;
    713   # remove line beginning with example
    714   s/\nEXAMPLE.*//;
    715   &protect_texi;
    716   return ($_);
    717 }
    718  
     742  s/\n/ /g;
     743  &FormatInfoText;
     744 
     745  if ($l_fun)
     746  {
     747    print $FH "* ${proc}:: $_\n";
     748    push @procs, $proc;
     749  }
     750  else
     751  {
     752    print $FH "\@item \@code{$proc($procargs)}  ";
     753    print $FH "\n\@findex $proc\n$_\n";
     754  }
     755}
     756
     757sub OutRef
     758{
     759  my ($FH, $refs) = @_;
     760  $refs =~ s/^\s*//;
     761  $refs =~ s/\s*$//;
     762  my @refs = split (/[\s,]+/, $refs);
     763  my $ref;
     764
     765  print $FH "\@c ref\nSee\n";
     766  $ref = shift @refs;
     767  print $FH "\@ref{$ref}";
     768  for $ref (@refs)
     769  {
     770    print $FH ", \@ref{$ref}";
     771  }
     772  print $FH "\n\@c ref\n";
     773}
     774
    719775sub CleanUpExample
    720776{
     
    734790  # erase EXAMPLE, echo and pause statements
    735791  $example =~ s/"EXAMPLE.*"[^;]*;//g;
    736   $example =~ s/echo[^;]*;//g;
    737   $example =~ s/pause[^;]*;//g;
     792  $example =~ s/echo[^;\n]*;//g;
     793  $example =~ s/pause\(.*?\)[^;]*;//g;
    738794 
    739795  # prepend LIB command
     
    744800  # erase spaces from beginning of lines
    745801  $example =~ s/\n\s*/\n/g;
     802  $example =~ s/\s*$//g;
    746803  return $example;
    747804}
    748805
     806###################################################################
     807#
     808# Auxiallary functions
     809#
    749810sub IsNewer
    750811{
     
    789850{
    790851  local($call) = @_;
    791   print "d2t system: $call\n" if ($verbose > 1);
     852  print "\nd2t system: $call\n" if ($verbose > 1);
    792853  Error("non-zero exit status of system call: '$call': $!\n")
    793854    if (system($call));
Note: See TracChangeset for help on using the changeset viewer.