source: git/doc/doc2tex.pl @ 8d1432e

fieker-DuValspielwiese
Last change on this file since 8d1432e was 75f460, checked in by Hans Schoenemann <hannes@…>, 9 years ago
format
  • Property mode set to 100755
File size: 18.0 KB
RevLine 
[f36635]1#!/usr/local/bin/perl
2###################################################################
3#  Computer Algebra System SINGULAR
4#
5#  doc2tex: utility to generate the Singular manual
6#
7####
[a70441f]8# @c example [error] [no_comp] [unix_only]
[f36635]9#    -> the text till the next @c example is feed into Singular,
10#       the text is then substituted by
[84dee1]11#       @c computed example $ex_prefix $doc_file:$line
[f36635]12#       <text from the input>
13#       @expansion{} <corresponding output>
14#       ....
[84dee1]15#       @c end computed example $ex_prefix $doc_file:$line
16#       reuse computed examples if ($reuse && -r $ex_prefix.inc)
[75f460]17#       cut absolute directory names from the loaded messages
[f36635]18#       substituted @,{ and } by @@, @{ resp. @}
19#       wrap around output lines  longer than $ex_length = 73;
[75f460]20#       Processing is aborted if error occures in Singular run,
[4b72f6]21#       unless 'error' is specified
22#       if no_comp is given, then computation is not run
[a70441f]23#       if unix_only is given, then computation is only run
24#                              under unix
[75f460]25#
[f36635]26#
27####
28# @c include file
29#    -> copy content of file into output file protecting texi special chars
30#
31####
32# @c ref
33# ....
34# @c ref
35#    -> scans intermediate lines for @ref{..} strings
36#    Creates menu of (sorted) refs for ifinfo
[75f460]37#    Creates comma-separated (sorted) refs for iftex, prepended with
[f36635]38#    the text before first @ref.
39#
40####
[caf1e0]41# @c lib libname.lib[:proc] [no_ex, no_fun, Fun, (\w*)section]
[75f460]42#   --> replaced by @include $texfile where
[6bf987]43#        $texfile = $subdir/libname_lib[_noFun,_noEx].tex
[75f460]44#   --> if $make, calls "make $texfile"
[6bf987]45#   --> Error, if $tex_file does not exist
46#   --> if [:proc] is given, then includes only of respective
47#       proc body
[caf1e0]48#   --> Fun overwrites global no_fun
[013a76]49#   --> if (\w*)section is given, replaces @subsubsection by @$1section
[6bf987]50#       and pastes in content of tex file directly
[75f460]51#
[f36635]52#
53###################################################################
54
[a70441f]55use Config;
56$Win32 = 1 if ($Config{osname} =~ /win/i);
57
[f36635]58#
59# default settings of command-line arguments
60#
61$Singular = "../Singular/Singular"; # should be overwritten
[463f21c]62$Singular_opts = " -teqr12345678 --no-rc";
[f36635]63$clean = 0;
64$verbose = 1;
65$reuse = 1;
66$no_ex = 0;
[9177e3]67%exclude_ex = ();
[65a2bd]68$no_fun = 0;
[f36635]69$doc_subdir = "./d2t_singular";
[c04b94]70$ex_subdir = "./examples";
[f36635]71@include_dirs = (".", "../Singular/LIB");
[65a2bd]72$make = 0;
[84dee1]73$make_opts = " --no-print-directory";
[f36635]74
[a70441f]75
[f36635]76#
77# misc. defaults
78#
79$ex_length = 73;
80$ERROR = "\n**** Error:";
81$WARNING = "\n** Warning:";
82
83#
84# flush stdout and stderr after every write
85#
86select(STDERR);
87$| = 1;
88select(STDOUT);
89$| = 1;
90
91#
92# get file to convert
93#
94$doc_file = pop(@ARGV);
95if ($doc_file =~  /(.+)\..*$/)
96{
[75f460]97  die "*** Error: Need .doc file as input\n" . &Usage
[f36635]98    unless ($doc_file =~ /(.+)\.doc$/);
99}
100else
101{
102  if ($doc_file =~ /^-h(elp)?$/) { print &Usage; exit;}
103  $doc_file .= ".doc";
104}
105
106#
107# parse command line options
108#
109$args = join(" ", @ARGV);
[75f460]110while (@ARGV && $ARGV[0] =~ /^-/)
[f36635]111{
112  $_ = shift(@ARGV);
113  if (/^-S(ingular)?$/)  { $Singular = shift(@ARGV); next;}
[fdbd6d]114  if (/^-o(utput)?$/)    { $tex_file = shift(@ARGV); next;}
[f36635]115  if (/^-no_r(euse)?$/)  { $reuse = 0; next;}
116  if (/^-c(lean)?$/)     { $clean = 1; next;}
117  if (/^-no_e(x)?$/)     { $no_ex = 1; next;}
[9177e3]118  if (/^-exclude$/)      { $exclude_ex{shift(@ARGV)} = 1;next;}
[65a2bd]119  if (/^-no_fu(n)?$/)    { $no_fun = 1;next;}
[84dee1]120  if (/^-m(ake)?$/)      { $make =  shift(@ARGV);next;}
[c04b94]121  if (/^-d(ocdir)?$/)    { $doc_subdir = shift(@ARGV); next;}
122  if (/^-e(xdir)?$/)     { $ex_subdir = shift(@ARGV); next;}
[f36635]123  if (/^-I$/)            { unshift(@include_dirs, shift(@ARGV)); next;}
124  if (/^-v(erbose)?$/)   { $verbose = shift(@ARGV); next;}
125  if (/^-h(elp)?$/)      { print &Usage; exit;}
[65a2bd]126  Error("Unknown Option $_\n" .&Usage);
[f36635]127}
128$verbose = ($verbose < 0 ? 0 : $verbose);
[84dee1]129$make_opts .= " -s" unless $verbose > 1;
[f36635]130
131#
132# construct filenames
[75f460]133#
[f36635]134($doc_dir = $doc_file) =~ s/(.+)\.doc$/$1/;
135if ($doc_dir =~ /(.*)\//)
136{
137  $doc = $';
138  $doc_dir = $1;
139}
140else
141{
142  $doc = $doc_dir;
143  $doc_dir = ".";
144}
[65a2bd]145unless ($tex_file)
146{
147  $tex_file = ($no_ex ? "$doc_dir/${doc}_noEx.tex" : "$doc_dir/$doc.tex");
148}
149
[f36635]150#
151# open files
152#
[75f460]153open(DOC, "<$doc_file")
[acfbb5a]154  || Error("can't open $doc_file for reading: $!\n" . &Usage);
155open(TEX, ">$tex_file") || Error("can't open $tex_file for writing: $!\n");
[84dee1]156print "(d2t $doc_file==>$tex_file" if ($verbose);
[f36635]157if (-d $doc_subdir)
158{
[c04b94]159  print "<docdir:$doc_subdir>"  if ($verbose > 1);
[f36635]160}
161else
162{
[75f460]163  mkdir($doc_subdir, oct(755))
[acfbb5a]164    || Error("can't create directory $doc_subdir: $!\n");
[c04b94]165  print "(docdir:$doc_subdir)"  if ($verbose > 1);
166}
167if (-d $ex_subdir)
168{
169  print "<exdir:$ex_subdir>"  if ($verbose > 1);
170}
171else
172{
[75f460]173  mkdir($ex_subdir, oct(755))
[c04b94]174    || Error("can't create directory $ex_subdir: $!\n");
175  print "(exdir:$ex_subdir)"  if ($verbose > 1);
[f36635]176}
177
178#######################################################################
[75f460]179#
[f36635]180# go !
181#
182while (<DOC>)
183{
184  $line++;
185  if (/^\@c\s*example/)     {&HandleExample; next;}
186  if (/^\@c\s*include\s+/)  {&HandleInclude; next;}
187  if (/^\@c\s*ref\s*$/)     {&HandleRef; next;}
188  if (/^\@c\s*lib\s+/)      {&HandleLib; next;}
189  if (/^\@setfilename/)     {print TEX "\@setfilename $doc.hlp\n"; next;}
[84dee1]190
[c04b94]191  if (/^\@\w*section\s*/ || /^\@\w*chapter\s*/ || /^\@\w*heading\s*/)
[84dee1]192  {
[c04b94]193    $section = $';
194    $section =~ s/^\s*(.*)\s*$/$1/;
[012576]195    if ($section =~ /\(/)
196    {
197      $section =~ s/\(/_/g
198    }
199    if ($section =~ /\)/)
200    {
201      $section =~ s/\)/_/g
202    }
[c04b94]203    if ($section =~ /\w/)
204    {
205      $section =~ s/\s/_/g
206    }
207    else
208    {
209      $section = "unknown";
210    }
[84dee1]211  }
[9ebcbf]212
213  # handle math
214  $in_info = 1 if /^\@ifinfo/;
215  $in_info = 0 if /^\@end\s*ifinfo/;
216  s[\@math\{(.*?)\}][&HandleMath($1)]eg unless $in_info;
217
[f36635]218  print TEX $_;
219
[75f460]220  if (! $printed_header && /^\@c/)
[354f3b]221  {
222    $printed_header = 1;
223    print TEX <<EOT;
224\@comment This file was generated by doc2tex.pl from $doc_file
225\@comment DO NOT EDIT DIRECTLY, BUT EDIT $doc_file INSTEAD
226EOT
227  }
228
[f36635]229  if (/^\@bye$/)            {last;}
230}
231
232#
233# wrap up
234#
235close(TEX);
[84dee1]236print "==>$tex_file)\n" if ($verbose);
[f36635]237
[9ebcbf]238sub HandleMath
239{
240  my $what = shift;
241  return <<EOT;
242
243\@ifinfo
244\@math{$what}
245\@end ifinfo
246\@tex
247\$$what\$
248\@end tex
249EOT
250}
[f36635]251
252######################################################################
[a70441f]253# @c example [error] [no_comp] [unix_only]
[354f3b]254#    -> the text till the next @c example is fed into Singular,
[f36635]255#       the text is then substituted by
[84dee1]256#       @c computed example $ex_prefix $doc_file:$line
[f36635]257#       <text from the input>
258#       @expansion{} <corresponding output>
259#       ....
[84dee1]260#       @c end computed example $ex_prefix $doc_file:$line
261#       reuse computed examples if ($reuse && -r $ex_prefix.inc)
[75f460]262#       cut absolute directory names from the loaded messages
[f36635]263#       substituted @,{ and } by @@, @{ resp. @}
264#       wrap around output lines  longer than $ex_length = 73;
[75f460]265#       Processing is aborted if error occures in Singular run,
[4b72f6]266#       unless 'error' is specified
267#       If [no_comp] is given, actual computation is not run
[a70441f]268#       if [unix_only] is given, then computation is only run
269#                                under unix
270
[f36635]271sub HandleExample
272{
[a70441f]273  my($inc_file, $ex_file, $lline, $thisexample, $error_ok, $cache, $no_comp,
[9177e3]274     $unix_only, $tag);
[75f460]275
[f36635]276  $lline = $line;
[84dee1]277  $section = 'unknown' unless $section;
278  $ex_prefix = $section;
[c04b94]279  $ex_prefix .= "_$examples{$section}" if $examples{$section};
[84dee1]280  $examples{$section}++;
[f36635]281
[9177e3]282  if (/tag:(\w+)/)
283  {
284    $tag = $1;
285  }
286  else
287  {
288    $tag = 'NOTAG';
289  }
[75f460]290
[9177e3]291  if ($no_ex or $exclude_ex{$tag})
[f36635]292  {
[84dee1]293    print "{$ex_prefix}" if ($verbose);
294    print TEX "\@c skipped computation of example $ex_prefix $doc_file:$lline \n";
[75f460]295
[f36635]296  }
[84dee1]297  else
298  {
[c04b94]299    $inc_file = "$ex_subdir/$ex_prefix.inc";
300    $ex_file = "$ex_subdir/$ex_prefix.sing";
[84dee1]301    if (-r $inc_file && -r $ex_file && -s $inc_file && -s $ex_file)
302    {
303      $cache = 1;
[c04b94]304      open(SING, "<$ex_file") || ($cache = 0);
[84dee1]305    }
306  }
[f36635]307
308  $thisexample = '';
309  $error_ok = 1 if /error/;
[4b72f6]310  $no_comp = 1 if /no_comp/;
[a70441f]311  $unix_only = 1 if /unix_only/ && $Win32;
[75f460]312
[a70441f]313  # print content in example file till next @c example
314  print TEX "// only supported on Unix platforms\n"
315    if $unix_only;
[75f460]316
[f36635]317  while (<DOC>)
318  {
319    $line++;
320    last if (/^\@c\s*example\s*$/);
[119b42]321#    s/^\s*//; # remove preceeding white spaces
[9177e3]322    if ($no_ex || $exclude_ex{$tag} || $no_comp || $unix_only)
[f36635]323    {
324      &protect_texi;
325      print TEX $_;
326    }
327    else
328    {
[84dee1]329      $thisexample .= $_;
[c04b94]330      if ($cache && $_ && $_ ne <SING>)
[84dee1]331      {
332        $cache = 0;
[c04b94]333        close(SING);
[84dee1]334      }
[f36635]335    }
336  }
[c04b94]337  close(SING) if $cache;
[acfbb5a]338  Error("no matching '\@c example' found for $doc_file:$lline\n")
[f36635]339    unless (/^\@c\s*example\s*$/);
340
341  # done, if no examples
[9177e3]342  return if ($no_ex || $exclude_ex{$tag} || $no_comp || $unix_only);
[f36635]343
344  # check whether it can be reused
[84dee1]345  if ($reuse && $cache)
[f36635]346  {
[354f3b]347    my $ok = 1;
[84dee1]348    print "<$ex_prefix>" if ($verbose);
349    print TEX "\@c reused example $ex_prefix $doc_file:$lline \n";
350    open(INC, "<$inc_file") || Error("can't open $inc_file for reading: $!\n");
[354f3b]351    while (<INC>)
352    {
353      if (/error occurred/ && $ok && !error_ok)
354      {
355        Warn("Result file $inc_file contains errors. Force re-computation by removing $inc_file");
356        $ok = 0;
357      }
358      print TEX $_;
359    }
[84dee1]360    close(INC);
[f36635]361  }
362  else
363  {
[84dee1]364    print "($ex_prefix" if ($verbose == 1);
365    my ($res_file);
[c04b94]366    $res_file = "$ex_subdir/$ex_prefix.res";
[f36635]367
[84dee1]368    print TEX "\@c computed example $ex_prefix $doc_file:$lline \n";
[f36635]369
370    # run singular
[acfbb5a]371    open(EX, ">$ex_file") || Error("can't open $ex_file for writing: $!\n");
[c04b94]372    print EX "$thisexample";
[f36635]373    close(EX);
374
[a70441f]375    unless ($Singular_OK)
376    {
377      if (system("echo '\$' | $Singular $Singular_opts > $res_file"))
378      {
379        $Singular .= '.exe' if ($Win32 && $Singular !~ /\.exe$/);
380        Error("CanŽt run '$Singular $Singular_opts': $@")
381          if (system("echo '\$' | $Singular $Singular_opts > $res_file"));
382      }
383      $Singular_OK = 1
384    }
385
[c04b94]386    &System("echo '\$' | $Singular $Singular_opts $ex_file > $res_file");
[f36635]387    print ")" if ($verbose == 1);
388
[acfbb5a]389    open(RES, "<$res_file") || Error("can't open $res_file for reading: $!\n");
390    open(INC, ">$inc_file") || Error("can't open $inc_file for writing: $!\n");
[f36635]391
392    # get result, manipulate it and put it into inc file
393    while (<RES>)
394    {
[c04b94]395      last if (/^STDIN\s*([0-9]+)..\$/);
[f36635]396      # check for error
[84dee1]397      Error("while running example $ex_prefix from $doc_file:$lline.\nCall: '$Singular $Singular_opts $ex_file > $res_file'\n")
[f36635]398        if (/error occurred/ && ! $error_ok);
399      # remove stuff from echo
400      if (/^$ex_file\s*([0-9]+)../)
401      {
402        $_ = $';
403        &protect_texi;
404      }
405      else
406      {
407        local($to_do, $done);
408        # remove absolute path names from laoded messages
409        s/^(\/\/ \*\* loaded )(.*)\/(.+).lib(.*)/$1$3.lib$4/;
410        # shorten error occurred in messages
411        s/\? error occurred in [^ ]* line/\? error occurred in line/;
412        # break after $ex_length characters
413        $to_do = $_;
[75f460]414        while (length($to_do) > $ex_length && $to_do =~ /\w/ &&
[1173547]415               substr($to_do, $ex_length) !~ /^\s*$/)
[f36635]416        {
[75f460]417
[f36635]418          $done .= substr($to_do, 0, $ex_length)."\\\n   ";
[1173547]419          $to_do = substr($to_do, $ex_length);
[f36635]420        }
421        $_ = $done.$to_do if($done);
422        &protect_texi;
423        $_ = "\@expansion{} ".$_;
424      }
425      print INC $_;
[84dee1]426      print TEX $_;
[f36635]427    }
428    close(RES);
429    close(INC);
430    unlink $ex_file, $res_file, $inc_file if ($clean);
431  }
[84dee1]432  print TEX "\@c end example $ex_prefix $doc_file:$lline\n";
[f36635]433}
[75f460]434
[f36635]435######################################################################
436# @c include file
437#    -> copy content of file into output file protecting texi special chars
438sub HandleInclude
439{
440  s/^\@c\s*include\s+([^\s]+)\s/$1/;
[460c1e1]441  s/\s*$//;
[f36635]442  unless (&Open(*INC, "<$_"))
443  {
444    warn "$WARNING HandleInclude: can't open $_ for reading\n";
445    print TEX "\@c include file $_ not found\n";
446    return;
447  }
448  print "<$_>" if ($verbose);
449  print TEX "\@c begin included file $_ from $doc_file:$line\n";
450  while (<INC>)
451  {
452    &protect_texi;
453    print TEX $_;
454  }
455  print TEX "\@c end included file from $doc_file:$line\n";
456  close (INC);
457}
458
459######################################################################
460# @c ref
461# ....
462# @c ref
463#    -> scans intermediate lines for @ref{..} strings
464#    Creates menu of (sorted) refs for ifinfo
[75f460]465#    Creates comma-separated (sorted) refs for iftex, prepended with
[f36635]466#    the text before first @ref.
467
468sub HandleRef
469{
470  local(%refs, @refs, $header, $lline, $lref);
[75f460]471
[f36635]472  print TEX "\@c inserted refs from $doc_file:$line\n";
[75f460]473
[f36635]474  # scan lines use %ref to remove duplicates
475  $lline = $line;
476  while (<DOC>)
477  {
478    $line++;
479    last if (/^\@c\s*ref\s*$/);
[75f460]480
[c143315]481    while (/\@ref{(.*?)}[;\.]/)
[f36635]482    {
483      $refs{$1} = 1;
484      $_ = $';
485      unless ($header)
486      {
487        $header = $`;
488        $header = " " unless ($header);
489      }
490    }
[8a0ba8]491    $header = $_ unless ($header)
[f36635]492  }
[8a0ba8]493  chomp $header;
[75f460]494  die "$ERRROR no matching \@c ref found for $doc_file:$lline\n"
[f36635]495    unless (/^\@c\s*ref\s*$/);
496  # sort refs
497  @refs = sort(keys(%refs));
498  # put them out
[8a0ba8]499  print TEX "\@ifinfo\n";
500  print TEX "\@menu\n";
501  if ($header && $header ne " ")
502  {
503    print TEX "$header\n";
504  }
505  else
506  {
507    print TEX "See also:\n";
508  }
[f36635]509  foreach $ref (@refs) {print TEX "* ".$ref."::\n";}
510  print TEX "\@end menu\n\@end ifinfo\n\@iftex\n";
511
512  if ($header ne " ")
513  {
514    print TEX "$header\n" unless ($header eq " ");
515  }
516  else
517  {
[9282f3]518    print TEX "\@strong{See also:}\n";
[f36635]519  }
520  $lref = pop(@refs);
521  foreach $ref (@refs) {print TEX "\@ref{".$ref."};\n";}
[75f460]522  print TEX "\@ref{".$lref."}.\n" if ($lref);
[f36635]523  print TEX "\@end iftex\n\@c end inserted refs from $doc_file:$lline\n";
524}
525
526###################################################################
527#
[caf1e0]528# @c lib libname.lib[:proc] [no_ex, no_fun, Fun, (\w*)section]
[75f460]529#   --> replaced by @include $texfile where
[65a2bd]530#        $texfile = $subdir/libname_lib[_noFun,_noEx].tex
[75f460]531#   --> if $make, calls "make $texfile"
[65a2bd]532#   --> Error, if $tex_file does not exist
533#   --> if [:proc] is given, then includes only of respective
534#       proc body
[caf1e0]535#   --> Fun overwrites global no_fun
[013a76]536#   --> if (\w*)section is given, replaces @subsubsection by @$1section
[65a2bd]537#       and pastes in content of tex file directly
[f36635]538
539sub HandleLib
540{
[522906]541  my($lib, $proc, $n_fun, $n_ex, $section, $tex_file, $tag);
[acfbb5a]542
[f36635]543  if (/^\@c\s*lib\s+([^\.]+)\.lib(.*)/)
544  {
545    $lib = $1;
546    $_ = $2;
547  }
548  else
549  {
550    warn "$WARNING need .lib file to process '$_'\n";
551    print TEX $_;
552    return;
553  }
[522906]554  if (/tag:(\w+)/)
555  {
556    $tag = "TAG='-tag ".$1."'";
557  }
558  else
559  {
560    $tag = '';
561  }
[f36635]562
[65a2bd]563  $proc = $1 if (/^:(.*?) /);
564  $n_fun = 1 if ($no_fun || /no_fun/);
[caf1e0]565  $n_fun = 0 if (/Fun/);
[a70441f]566  $n_ex = 1 if ($no_ex || /no_ex/ || (/unix_only/ && $Win32));
[6bf987]567  $section = $1 if /(\w*)section/;
[75f460]568
[65a2bd]569  # contruct tex file name
570  $tex_file = "$doc_subdir/$lib"."_lib";
571  if ($n_fun)
[460c1e1]572  {
[65a2bd]573    $tex_file .= "_noFun";
[460c1e1]574  }
[65a2bd]575  elsif ($n_ex)
[460c1e1]576  {
[65a2bd]577    $tex_file .= "_noEx";
[460c1e1]578  }
[65a2bd]579  $tex_file .= ".tex";
580
581  if ($make)
[f36635]582  {
[84dee1]583    print "<lib $lib " if ($verbose);
[75f460]584    System("$make $make_opts $tag VERBOSE=$verbose $tex_file");
[f36635]585  }
[75f460]586
[65a2bd]587  # make sure file exists
588  if (-r $tex_file)
[f36635]589  {
[65a2bd]590    if ($verbose)
[acfbb5a]591    {
[84dee1]592      print "<lib $lib " unless $make;
593      print "$proc>";
[acfbb5a]594    }
[f36635]595  }
[acfbb5a]596  else
597  {
[65a2bd]598    Error("Can't read $tex_file\n") unless -r $tex_file;
[f36635]599  }
600
[65a2bd]601  # see whether we have to paste something in
602  if ($proc || $section)
[f36635]603  {
[75f460]604    open(LTEX, "<$tex_file")
[65a2bd]605      || Error("Can't open $tex_file for reading: $!\n");
[f36635]606
[65a2bd]607    print TEX "\@c start include of docu for $lib.lib:$proc\n";
[013a76]608    print TEX "\@c replaced \@subsubsection by \@$section\n" if ($section);
[65a2bd]609    if ($proc)
[f36635]610    {
[65a2bd]611      my $found = 0;
612      while (<LTEX>)
[f36635]613      {
[65a2bd]614        $found = 1 if /c ---content $proc---/;
615        if ($found)
[460c1e1]616        {
[013a76]617          s/subsubsection/${section}section/ if $section;
[75f460]618          print TEX $_;
[460c1e1]619        }
[65a2bd]620        last if $found && /c ---end content $proc---/;
[f36635]621      }
[65a2bd]622      if ($found)
[acfbb5a]623      {
[caf1e0]624        Error("no end content found for lib proc docu for $lib.lib:$proc $doc_file:$line in $tex_file\n")
[65a2bd]625          unless (/c ---end content $proc---/);
626        print TEX "\@c generated lib proc docu for $lib.lib:$proc $doc_file:$line \n";
[acfbb5a]627      }
628      else
629      {
[caf1e0]630        Error("did not find lib proc docu for $lib.lib:$proc $doc_file:$line in $tex_file\n");
[acfbb5a]631      }
632    }
[65a2bd]633    else
[dc3a44]634    {
[65a2bd]635      while (<LTEX>)
636      {
[013a76]637        s/subsubsection/${section}section/;
[65a2bd]638        print TEX $_;
639      }
[dc3a44]640    }
[65a2bd]641    print TEX "\@c end include of docu for $lib.lib:$proc\n";
642    close(LTEX);
[acfbb5a]643  }
644  else
645  {
[65a2bd]646    print TEX "\@c include of docu for $lib.lib\n";
647    print TEX "\@include $tex_file\n";
[dc3a44]648  }
[f36635]649}
650
651####################################################################
652# Auxillary routines
653#
654
655# protect texi special characters
656sub protect_texi
657{
658  s/\@/\@\@/g;
659  s/{/\@{/g;
660  s/}/\@}/g;
[75f460]661}
[f36635]662
663# open w.r.t. include_dirs
664sub Open
665{
666  local(*FH, $file) = @_;
667  local($mode);
668  $file =~ s/^(.{1})(.*)/$2/;
669  $mode = $1;
670
671  foreach $dir (@include_dirs)
672  {
673    return $dir if(open(FH, $mode.$dir."/".$file));
674  }
675}
[75f460]676
[f36635]677# system call with echo on verbose > 1 and die on fail
678sub System
679{
680  local($call) = @_;
[84dee1]681  print " d2t system:\n$call\n" if ($verbose > 1);
[acfbb5a]682  Error("non-zero exit status of system call: '$call': $!\n")
[f36635]683    if (system($call));
684}
685
[acfbb5a]686sub Error
687{
688  print "$ERROR $_[0]";
689  close(TEX);
690  unlink $tex_file if $tex_file && -e $tex_file;
691  exit(1);
692}
693
[354f3b]694sub Warn
695{
696  print "$WARNING $_[0]\n";
697}
[f36635]698#
699# leave this here --otherwise fontification in my emacs gets screwd up
[75f460]700#
[f36635]701sub Usage
702{
703  return <<EOT;
704This is doc2tex: a utility to generate Singular texinfo from doc file
705To convert a doc file to texinfo: $0 [options] input_file.doc
706where options can be (abbreviated to shortest possible prefix):
707  -Singular prog: use 'prog' as Singular program to generate ex output
708                          (default: '../Singular/Singular')
709  -output file  : use 'file' as output file
710                          (default: input_file.tex)
711  -clean        : delete intermediate files
[84dee1]712  -make  cmd    : use cmd as make command to generate tex files for libraries
[f36635]713  -no_reuse     : don't reuse intermediate files
[75f460]714  -no_ex        : skip computation of examples
[65a2bd]715  -no_fun       : don't include help for library functions
[c04b94]716  -docdir  dir  : put intermediate doc/tex files into 'dir'
[f36635]717                          (default: './d2t_singular')
[c04b94]718  -exdir   dir  : put example files into 'dir'
719                          (default: './examples')
[f36635]720  -I dir        : look also into 'dir' for include  and lib files
721                          (default: ".", "../Singular/LIB")
722  -verbose  val : Set verbosity to 'val' (0=quiet, 1=prot, >1=all)
723  -help         : print help and exit
724EOT
725}
726
Note: See TracBrowser for help on using the repository browser.