#! /usr/bin/perl

# Extract R object INDEX information from Rd files.
# Usage:  Rdindex file_1 ... file_n

# Copyright (C) 1997 Kurt Hornik
#
# This document is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available via WWW at
# http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
# writing to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.

# Bug reports to Kurt.Hornik@ci.tuwien.ac.at

undef $/;
foreach $file (@ARGV) {
  if (!open(FILE, $file)) {
    print STDERR "File $file not found\n";
  } else {
    $_ = <FILE>;
    m/^\\name\{([^\}]*)\}\s*\\title\{\s*([^\}\n]*)\s*\}/s;
    $l = length($1);
    if ($l < 7) {
      print("$1\t\t$2\n");
    } elsif ($l < 15) {
      print("$1\t$2\n");
    } else {
      print("$1\n\t\t$2\n");
    }
    close(FILE);
  }
}

### Local Variables: ***
### perl-indent-level: 2 ***
### End: ***
