# Perl script to convert info files into text file

while(<STDIN>) {
  if (/^$/) {
    $inmenu=0;
    # Skip lines
    $_=<STDIN>;
    unless(/Node: Top/) {
      $_=<STDIN>;
      $title=<STDIN>;
      $_=<STDIN>;
      if ($title =~ / Index$/) {$inmenu=1;}
      else {
	if (/^\*+$/) {
	  $chapter++; $section=0; $subsection=0;
	  print "$chapter $title";
	  unless ($toc) {
	    print substr("******",0,length("$chapter "));
	    print;
	  }
	}
	if (/^\=+$/) {
	  $section++; $subsection=0;
	  print "$chapter.$section $title";
	  unless ($toc) {
	    print substr("=========",0,length("$chapter.$section "));
	    print;
	  }
	}
	if (/^\-+$/) {
	  $subsection++;
	  print "$chapter.$section.$subsection $title";
	  unless ($toc) {
	    print substr("-------------",0,length("$chapter.$section.$subsection "));
	    print;
	  }
	}
      }
    }
  }
  else {
    if (/^\* Menu:$/) {$inmenu=1;}
    s/\*Note/See Also:/g;
    s/:://g;
    if ((!$toc && $title) || ($toc && !$title)) {
      print unless($inmenu);
    }
  }
}


