Changeset dc3a44 in git for doc/doc2tex.pl
- Timestamp:
- Jul 7, 1999, 6:38:39 PM (24 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 4deddb979be065737d63e926fc05f264a6b1078a
- Parents:
- 6b6f22f3903a15b732ac1ca6615c2387a71ac03b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/doc2tex.pl
r6b6f22 rdc3a44 1 1 #!/usr/local/bin/perl 2 # $Id: doc2tex.pl,v 1. 3 1999-07-06 11:58:09obachman Exp $2 # $Id: doc2tex.pl,v 1.4 1999-07-07 16:38:34 obachman Exp $ 3 3 ################################################################### 4 4 # Computer Algebra System SINGULAR … … 495 495 { 496 496 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); 498 498 # 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); 500 500 501 501 print "(lib $lib: " if ($verbose == 1); … … 539 539 print LDOC "\@c library version: $version\n"; 540 540 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; 542 544 # print menu of available functions 543 545 if ($l_fun) 544 546 { 545 @procs = sort(@procs);546 print LDOC "\@menu\n";547 foreach $proc (@procs) {print LDOC "* $proc"."::\n";}548 print LDOC "\@end menu\n";549 550 547 # print help and example of each function 551 548 for ($i = 0; $i <= $#procs; $i++) … … 563 560 564 561 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; 577 577 print LDOC "\@c ---end content $procs[$i]---\n"; 578 578 } … … 599 599 { 600 600 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 613 sub OutInfo 614 { 615 my ($FH, $info, $l_fun) = @_; 602 616 $info =~ s/^\s*//; 603 617 $info =~ s/\s*$//; 604 618 $info .= "\n"; 605 619 606 print $FH "\@c ---content LibInfo---\n"; 607 print $FH "\@table \@code\n"; 620 my ($item, $text, $line, $ref); 608 621 while ($info =~ m/(.*\n)/g) 609 622 { … … 611 624 if ($1 =~ /^(\w.+?):(.*\n)/) 612 625 { 613 OutLibInfoItem($FH, $item, $text, $l_fun) if $item && $text;626 $ref .= OutInfoItem($FH, $item, $text, $l_fun) if $item && $text; 614 627 $item = $1; 615 628 $text = $2; … … 620 633 } 621 634 } 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 639 sub 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 648 sub OutInfoItem 628 649 { 629 650 my ($FH, $item, $text, $l_fun) = @_; … … 631 652 $item = lc $item; 632 653 $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 } 647 672 $text =~ s/^\s*//; 648 673 $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 652 677 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 } 655 686 while ($text =~ /(.*\n)/g) 656 687 { … … 669 700 } 670 701 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 } 672 723 } 673 724 else 674 725 { 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 680 732 print $FH "$_\n\n"; 681 733 } 734 return ''; 682 735 } 683 736 … … 687 740 local $_ = $pinfo; 688 741 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 757 sub 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 719 775 sub CleanUpExample 720 776 { … … 734 790 # erase EXAMPLE, echo and pause statements 735 791 $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; 738 794 739 795 # prepend LIB command … … 744 800 # erase spaces from beginning of lines 745 801 $example =~ s/\n\s*/\n/g; 802 $example =~ s/\s*$//g; 746 803 return $example; 747 804 } 748 805 806 ################################################################### 807 # 808 # Auxiallary functions 809 # 749 810 sub IsNewer 750 811 { … … 789 850 { 790 851 local($call) = @_; 791 print " d2t system: $call\n" if ($verbose > 1);852 print "\nd2t system: $call\n" if ($verbose > 1); 792 853 Error("non-zero exit status of system call: '$call': $!\n") 793 854 if (system($call));
Note: See TracChangeset
for help on using the changeset viewer.