Changeset acfbb5a in git for doc/doc2tex.pl
- Timestamp:
- Jul 6, 1999, 1:58:18 PM (24 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 472f39ab0b89934d33bab9f90e3d8c81263ba84e
- Parents:
- f34c37c0f30bac8eb447294a36d841edfed9711e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/doc2tex.pl
rf34c37c racfbb5a 1 1 #!/usr/local/bin/perl 2 # $Id: doc2tex.pl,v 1. 2 1999-07-01 12:48:00obachman Exp $2 # $Id: doc2tex.pl,v 1.3 1999-07-06 11:58:09 obachman Exp $ 3 3 ################################################################### 4 4 # Computer Algebra System SINGULAR … … 36 36 # 37 37 #### 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 39 40 # --> includes info of libname.lib in output file 40 41 # --> includes function names of info into function index … … 42 43 # their help into output file 43 44 # --> 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 # 45 48 # Optional no_ex, lib_fun, lib_ex arguments overwrite respective 46 49 # command-line arguments … … 138 141 # 139 142 open(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); 144 open(TEX, ">$tex_file") || Error("can't open $tex_file for writing: $!\n"); 142 145 print "d2t: Generating $tex_file from $doc_file ...\n" if ($verbose > 1); 143 146 print "d2t: $doc_file ==> $tex_file\n" if ($verbose == 1); … … 150 153 { 151 154 mkdir($doc_subdir, oct(755)) 152 || die "$ERROR can't create directory $doc_subdir: $!\n";155 || Error("can't create directory $doc_subdir: $!\n"); 153 156 print "d2t: Created $doc_subdir for intermediate files\n" 154 157 if ($verbose > 1); … … 232 235 } 233 236 } 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") 235 238 unless (/^\@c\s*example\s*$/); 236 239 … … 256 259 257 260 # 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"); 259 262 print EX "$thisexample\$\n"; 260 263 close(EX); … … 263 266 print ")" if ($verbose == 1); 264 267 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"); 267 270 268 271 $include = ''; … … 272 275 last if (/^$ex_file\s*([0-9]+)..\$/); 273 276 # 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") 275 278 if (/error occurred/ && ! $error_ok); 276 279 # remove stuff from echo … … 405 408 { 406 409 local($lib, $lib_name, $ltex_file, $l_ex, $l_fun); 407 410 my ($func); 411 408 412 if (/^\@c\s*lib\s+([^\.]+)\.lib(.*)/) 409 413 { … … 419 423 } 420 424 425 $func = $1 if (/^:(.*?) /); 421 426 $l_fun = 1 if (($lib_fun || (/lib_fun/)) && !/no_fun/); 422 427 $l_ex = 1 if (($lib_ex || /lib_ex/) && !/no_ex/ && $l_fun); … … 436 441 $ltex_file .= ".tex"; 437 442 438 die "$ERROR can't open $lib.lib for reading: $!\n"443 Error("can't open $lib.lib for reading: $!\n") 439 444 unless ($lib_dir = &Open(*LIB, "<$lib.lib")); 440 445 close (LIB); … … 442 447 IsNewer($ltex_file, "$lib_dir/$lib.lib")) 443 448 { 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 } 447 454 } 448 455 elsif (&GenerateLibDoc($lib, $ltex_file, $l_fun, $l_ex)) 449 456 { 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; 451 459 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 } 455 490 close(LTEX); 456 print TEX "\@c end generated lib docu for $lib_name $doc_file:$line \n";457 491 unlink $ltex_file if ($clean); 458 492 } … … 471 505 $doc_file .= ".doc"; 472 506 473 die "$ERROR can't open $lib.lib for reading: $!\n"507 Error("can't open $lib.lib for reading: $!\n") 474 508 unless ($lib_dir = &Open(*LIB, "<$lib.lib")); 475 509 close (LIB); … … 477 511 { 478 512 print "<doc>" if ($verbose == 1); 479 print TEX "\@c reused file $doc_file\n";480 513 } 481 514 else … … 486 519 { 487 520 print "<pl>" if ($verbose == 1); 488 print TEX "\@c reused file $pl_file\n";489 521 } 490 522 else … … 493 525 &System("$libparse -i $lib_dir/$lib.lib > $pl_file"); 494 526 print ")" if ($verbose == 1); 495 print TEX "\@c generated file $pl_file\n";496 527 } 497 528 498 529 print "(doc" if ($verbose == 1); 499 print TEX "\@c generated file $doc_file\n";500 530 501 531 do $pl_file; 502 die "$ERROR error while executing $pl_file: $@\n"if ($@);532 Error("error while executing $pl_file: $@\n") if ($@); 503 533 unlink ($pl_file) if ($clean); 504 534 … … 507 537 508 538 # print header 509 $info = &CleanUpHelp($info);510 539 print LDOC "\@c library version: $version\n"; 511 540 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); 526 542 # print menu of available functions 527 543 if ($l_fun) … … 545 561 print LDOC "\@findex ". $procs[$i] . "\n"; 546 562 print LDOC "\@cindex ". $procs[$i] . "\n" if ($lib eq "standard"); 547 563 564 print LDOC "\@c ---content $procs[$i]---\n"; 548 565 # print help section 549 566 print LDOC "\@strong{Info:}\n"; … … 558 575 print LDOC $example; 559 576 print LDOC "\n\@c example\n\@end example\n"; 577 print LDOC "\@c ---end content $procs[$i]---\n"; 560 578 } 561 579 } … … 574 592 unlink($doc_file) if ($clean); 575 593 return 1; 594 } 595 596 ########################################################################### 597 # parse and print-out libinfo 598 sub 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 627 sub 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 684 sub 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"; 576 697 } 577 698 … … 669 790 local($call) = @_; 670 791 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") 672 793 if (system($call)); 673 794 } 674 795 675 796 sub Error 797 { 798 print "$ERROR $_[0]"; 799 close(TEX); 800 unlink $tex_file if $tex_file && -e $tex_file; 801 exit(1); 802 } 803 676 804 # 677 805 # leave this here --otherwise fontification in my emacs gets screwd up
Note: See TracChangeset
for help on using the changeset viewer.