#!/usr/local/bin/perl -w
use strict "subs";

# $Id: extractspec,v 1.5 2000/06/26 14:17:40 freek Exp $

print "(* \$I"."d:\$ *)\n\n";
$p = 0;
while (<>)
{
  if (/\(\* End_SpecReals \*\)/)
  {
    print STDERR "dangling \"End_SpecReals\": file \"$ARGV\", line $.\n" if !$p;
    $p = 0;
    $l1 = $.-1;
    $r = $l1 != $l0 ? "$l0-$l1" : "$l0";
    print "(* file \"$ARGV\", line $r *)\n$o\n";
  }
  if ($p)
  {
    $q = 0 if (/\(\* Tex_Prose/);
    if ($q)
    {
      $q = 1 if ($q == 2 && $_ ne "\n");
      $o .= $_ if $q != 2 && !/\(\* (Begin|End)_Tex_Verb \*\)/;
    }
    else
    {
      $q = 2 if (/\*\)/);
    }
  }
  if (/\(\* Begin_SpecReals \*\)/)
  {
    print STDERR "dangling \"Begin_SpecReals\": file \"$ARGV\", line $.\n" if $p;
    $p = 1;
    $q = 1;
    $l0 = $.+1;
    $o = "";
  }
  close(ARGV) if eof;
}
die if $p;
