source: git/doc/doc2tex.pl

spielwiese
Last change on this file was 8543cd4, checked in by Matthias Köppe <mkoeppe@…>, 7 weeks ago
doc: Add missing `tag:normaliz`, fix quoting bug, update Sage CI (macOS arm64 testing) (#1205) * doc/singular.doc: sagbiNormaliz.lib needs tag:normaliz * doc/Makefile-docbuild.in: Remove overquoting of PATH * .github/workflows/ci-sage.yml: Add info to singular dependencies * .github/workflows/ci-sage.yml: Shorten workflow name * .github/workflows/ci-sage.yml: Use https://github.com/sagemath/sage/pull/37237 for macOS tests * .github/workflows/ci-sage.yml: Build singular with V=1, timeout=3000 * .github/workflows/ci-sage.yml: Build with longer timeout for the -gcc_spkg platform * doc/doc2tex.pl [GITHUB_ACTIONS]: Print failing .res file * .github/workflows/ci-sage.yml: Set GITHUB_ACTIONS=1 * .github/workflows/ci-sage.yml: Make system readline available
  • Property mode set to 100755
File size: 18.2 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;
[b5d360]20#       Processing is aborted if error occurs 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;}
[a43733]189  if (/^\@setfilename/)     {print TEX "\@setfilename $doc.info\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;
[b5d360]265#       Processing is aborted if error occurs 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*$/);
[b5d360]321#    s/^\s*//; # remove preceding 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$/);
[5a5fb2]380        Error("Can't run '$Singular $Singular_opts': $@")
[a70441f]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
[8543cd4]397      if (/error occurred/ && ! $error_ok)
398      {
399        if ($ENV{GITHUB_ACTIONS})
400        {
401          print STDERR "::group::${$res_file}";
402          &System("cat $res_file >&2");
403          print STDERR "::endgroup::";
404        }
405        Error("while running example $ex_prefix from $doc_file:$lline.\nCall: '$Singular $Singular_opts $ex_file > $res_file'\n");
406      }
[f36635]407      # remove stuff from echo
408      if (/^$ex_file\s*([0-9]+)../)
409      {
410        $_ = $';
411        &protect_texi;
412      }
413      else
414      {
415        local($to_do, $done);
[b5d360]416        # remove absolute path names from loaded messages
[f36635]417        s/^(\/\/ \*\* loaded )(.*)\/(.+).lib(.*)/$1$3.lib$4/;
418        # shorten error occurred in messages
419        s/\? error occurred in [^ ]* line/\? error occurred in line/;
420        # break after $ex_length characters
421        $to_do = $_;
[75f460]422        while (length($to_do) > $ex_length && $to_do =~ /\w/ &&
[1173547]423               substr($to_do, $ex_length) !~ /^\s*$/)
[f36635]424        {
[75f460]425
[f36635]426          $done .= substr($to_do, 0, $ex_length)."\\\n   ";
[1173547]427          $to_do = substr($to_do, $ex_length);
[f36635]428        }
429        $_ = $done.$to_do if($done);
430        &protect_texi;
431        $_ = "\@expansion{} ".$_;
432      }
433      print INC $_;
[84dee1]434      print TEX $_;
[f36635]435    }
436    close(RES);
437    close(INC);
438    unlink $ex_file, $res_file, $inc_file if ($clean);
439  }
[84dee1]440  print TEX "\@c end example $ex_prefix $doc_file:$lline\n";
[f36635]441}
[75f460]442
[f36635]443######################################################################
444# @c include file
445#    -> copy content of file into output file protecting texi special chars
446sub HandleInclude
447{
448  s/^\@c\s*include\s+([^\s]+)\s/$1/;
[460c1e1]449  s/\s*$//;
[f36635]450  unless (&Open(*INC, "<$_"))
451  {
452    warn "$WARNING HandleInclude: can't open $_ for reading\n";
453    print TEX "\@c include file $_ not found\n";
454    return;
455  }
456  print "<$_>" if ($verbose);
457  print TEX "\@c begin included file $_ from $doc_file:$line\n";
458  while (<INC>)
459  {
460    &protect_texi;
461    print TEX $_;
462  }
463  print TEX "\@c end included file from $doc_file:$line\n";
464  close (INC);
465}
466
467######################################################################
468# @c ref
469# ....
470# @c ref
471#    -> scans intermediate lines for @ref{..} strings
472#    Creates menu of (sorted) refs for ifinfo
[75f460]473#    Creates comma-separated (sorted) refs for iftex, prepended with
[f36635]474#    the text before first @ref.
475
476sub HandleRef
477{
478  local(%refs, @refs, $header, $lline, $lref);
[75f460]479
[f36635]480  print TEX "\@c inserted refs from $doc_file:$line\n";
[75f460]481
[f36635]482  # scan lines use %ref to remove duplicates
483  $lline = $line;
484  while (<DOC>)
485  {
486    $line++;
487    last if (/^\@c\s*ref\s*$/);
[75f460]488
[5aebab]489    while (/\@ref\{(.*?)\}[;\.]/)
[f36635]490    {
491      $refs{$1} = 1;
492      $_ = $';
493      unless ($header)
494      {
495        $header = $`;
496        $header = " " unless ($header);
497      }
498    }
[8a0ba8]499    $header = $_ unless ($header)
[f36635]500  }
[8a0ba8]501  chomp $header;
[b5d360]502  die "$ERROR no matching \@c ref found for $doc_file:$lline\n"
[f36635]503    unless (/^\@c\s*ref\s*$/);
504  # sort refs
505  @refs = sort(keys(%refs));
506  # put them out
[8a0ba8]507  print TEX "\@ifinfo\n";
508  print TEX "\@menu\n";
509  if ($header && $header ne " ")
510  {
511    print TEX "$header\n";
512  }
513  else
514  {
515    print TEX "See also:\n";
516  }
[f36635]517  foreach $ref (@refs) {print TEX "* ".$ref."::\n";}
518  print TEX "\@end menu\n\@end ifinfo\n\@iftex\n";
519
520  if ($header ne " ")
521  {
522    print TEX "$header\n" unless ($header eq " ");
523  }
524  else
525  {
[9282f3]526    print TEX "\@strong{See also:}\n";
[f36635]527  }
528  $lref = pop(@refs);
529  foreach $ref (@refs) {print TEX "\@ref{".$ref."};\n";}
[75f460]530  print TEX "\@ref{".$lref."}.\n" if ($lref);
[f36635]531  print TEX "\@end iftex\n\@c end inserted refs from $doc_file:$lline\n";
532}
533
534###################################################################
535#
[caf1e0]536# @c lib libname.lib[:proc] [no_ex, no_fun, Fun, (\w*)section]
[75f460]537#   --> replaced by @include $texfile where
[65a2bd]538#        $texfile = $subdir/libname_lib[_noFun,_noEx].tex
[75f460]539#   --> if $make, calls "make $texfile"
[65a2bd]540#   --> Error, if $tex_file does not exist
541#   --> if [:proc] is given, then includes only of respective
542#       proc body
[caf1e0]543#   --> Fun overwrites global no_fun
[013a76]544#   --> if (\w*)section is given, replaces @subsubsection by @$1section
[65a2bd]545#       and pastes in content of tex file directly
[f36635]546
547sub HandleLib
548{
[522906]549  my($lib, $proc, $n_fun, $n_ex, $section, $tex_file, $tag);
[acfbb5a]550
[f36635]551  if (/^\@c\s*lib\s+([^\.]+)\.lib(.*)/)
552  {
553    $lib = $1;
554    $_ = $2;
555  }
556  else
557  {
558    warn "$WARNING need .lib file to process '$_'\n";
559    print TEX $_;
560    return;
561  }
[522906]562  if (/tag:(\w+)/)
563  {
564    $tag = "TAG='-tag ".$1."'";
565  }
566  else
567  {
568    $tag = '';
569  }
[f36635]570
[65a2bd]571  $proc = $1 if (/^:(.*?) /);
572  $n_fun = 1 if ($no_fun || /no_fun/);
[caf1e0]573  $n_fun = 0 if (/Fun/);
[a70441f]574  $n_ex = 1 if ($no_ex || /no_ex/ || (/unix_only/ && $Win32));
[6bf987]575  $section = $1 if /(\w*)section/;
[75f460]576
[b5d360]577  # construct tex file name
[65a2bd]578  $tex_file = "$doc_subdir/$lib"."_lib";
579  if ($n_fun)
[460c1e1]580  {
[65a2bd]581    $tex_file .= "_noFun";
[460c1e1]582  }
[65a2bd]583  elsif ($n_ex)
[460c1e1]584  {
[65a2bd]585    $tex_file .= "_noEx";
[460c1e1]586  }
[65a2bd]587  $tex_file .= ".tex";
588
589  if ($make)
[f36635]590  {
[84dee1]591    print "<lib $lib " if ($verbose);
[75f460]592    System("$make $make_opts $tag VERBOSE=$verbose $tex_file");
[f36635]593  }
[75f460]594
[65a2bd]595  # make sure file exists
596  if (-r $tex_file)
[f36635]597  {
[65a2bd]598    if ($verbose)
[acfbb5a]599    {
[84dee1]600      print "<lib $lib " unless $make;
601      print "$proc>";
[acfbb5a]602    }
[f36635]603  }
[acfbb5a]604  else
605  {
[65a2bd]606    Error("Can't read $tex_file\n") unless -r $tex_file;
[f36635]607  }
608
[65a2bd]609  # see whether we have to paste something in
610  if ($proc || $section)
[f36635]611  {
[75f460]612    open(LTEX, "<$tex_file")
[65a2bd]613      || Error("Can't open $tex_file for reading: $!\n");
[f36635]614
[65a2bd]615    print TEX "\@c start include of docu for $lib.lib:$proc\n";
[013a76]616    print TEX "\@c replaced \@subsubsection by \@$section\n" if ($section);
[65a2bd]617    if ($proc)
[f36635]618    {
[65a2bd]619      my $found = 0;
620      while (<LTEX>)
[f36635]621      {
[65a2bd]622        $found = 1 if /c ---content $proc---/;
623        if ($found)
[460c1e1]624        {
[013a76]625          s/subsubsection/${section}section/ if $section;
[75f460]626          print TEX $_;
[460c1e1]627        }
[65a2bd]628        last if $found && /c ---end content $proc---/;
[f36635]629      }
[65a2bd]630      if ($found)
[acfbb5a]631      {
[caf1e0]632        Error("no end content found for lib proc docu for $lib.lib:$proc $doc_file:$line in $tex_file\n")
[65a2bd]633          unless (/c ---end content $proc---/);
634        print TEX "\@c generated lib proc docu for $lib.lib:$proc $doc_file:$line \n";
[acfbb5a]635      }
636      else
637      {
[caf1e0]638        Error("did not find lib proc docu for $lib.lib:$proc $doc_file:$line in $tex_file\n");
[acfbb5a]639      }
640    }
[65a2bd]641    else
[dc3a44]642    {
[65a2bd]643      while (<LTEX>)
644      {
[013a76]645        s/subsubsection/${section}section/;
[65a2bd]646        print TEX $_;
647      }
[dc3a44]648    }
[65a2bd]649    print TEX "\@c end include of docu for $lib.lib:$proc\n";
650    close(LTEX);
[acfbb5a]651  }
652  else
653  {
[65a2bd]654    print TEX "\@c include of docu for $lib.lib\n";
655    print TEX "\@include $tex_file\n";
[dc3a44]656  }
[f36635]657}
658
659####################################################################
[b5d360]660# Auxiliary routines
[f36635]661#
662
663# protect texi special characters
664sub protect_texi
665{
666  s/\@/\@\@/g;
667  s/{/\@{/g;
668  s/}/\@}/g;
[75f460]669}
[f36635]670
671# open w.r.t. include_dirs
672sub Open
673{
674  local(*FH, $file) = @_;
675  local($mode);
676  $file =~ s/^(.{1})(.*)/$2/;
677  $mode = $1;
678
679  foreach $dir (@include_dirs)
680  {
681    return $dir if(open(FH, $mode.$dir."/".$file));
682  }
683}
[75f460]684
[f36635]685# system call with echo on verbose > 1 and die on fail
686sub System
687{
688  local($call) = @_;
[84dee1]689  print " d2t system:\n$call\n" if ($verbose > 1);
[acfbb5a]690  Error("non-zero exit status of system call: '$call': $!\n")
[f36635]691    if (system($call));
692}
693
[acfbb5a]694sub Error
695{
696  print "$ERROR $_[0]";
697  close(TEX);
698  unlink $tex_file if $tex_file && -e $tex_file;
699  exit(1);
700}
701
[354f3b]702sub Warn
703{
704  print "$WARNING $_[0]\n";
705}
[f36635]706#
707# leave this here --otherwise fontification in my emacs gets screwd up
[75f460]708#
[f36635]709sub Usage
710{
711  return <<EOT;
712This is doc2tex: a utility to generate Singular texinfo from doc file
713To convert a doc file to texinfo: $0 [options] input_file.doc
714where options can be (abbreviated to shortest possible prefix):
715  -Singular prog: use 'prog' as Singular program to generate ex output
716                          (default: '../Singular/Singular')
717  -output file  : use 'file' as output file
718                          (default: input_file.tex)
719  -clean        : delete intermediate files
[84dee1]720  -make  cmd    : use cmd as make command to generate tex files for libraries
[f36635]721  -no_reuse     : don't reuse intermediate files
[75f460]722  -no_ex        : skip computation of examples
[65a2bd]723  -no_fun       : don't include help for library functions
[c04b94]724  -docdir  dir  : put intermediate doc/tex files into 'dir'
[f36635]725                          (default: './d2t_singular')
[c04b94]726  -exdir   dir  : put example files into 'dir'
727                          (default: './examples')
[f36635]728  -I dir        : look also into 'dir' for include  and lib files
729                          (default: ".", "../Singular/LIB")
730  -verbose  val : Set verbosity to 'val' (0=quiet, 1=prot, >1=all)
731  -help         : print help and exit
732EOT
733}
734
Note: See TracBrowser for help on using the repository browser.