#!/usr/local/bin/perl -- # -*- Perl -*-

# 
# texoutline: LaTeX ソースのアウトライン表示 (texcat と組み合わせて使う）
# 
#     Jun.10,'96. OSHIRO Naoki.
# 
#     $Log:$
#
#   [1996/04/02] 小項目の表示を追加
#   [1996/07/29] 小項目の表示形式を変更
#   [1997/02/24] \chapter に対応させた（report オプション '-r'）．
#

#
# ・\(sub)*section の部分を sub の出現回数に応じてインデント表示
# ・次の部分を小項目としてインデント表示
#
#     %
#     % title
#     %
#

require "getopts.pl";
&Getopts("rm"); # r:report type, m:memo-mode type
$opt_r="  " if ($opt_r);

$spar_spc="";
while (<>) {
    chop;
    if (/(section|chapter)[^}]*[\s\]]$/) {
      $_.=<>;
      chop;
      print STDERR "$_\n";
    }
    if (/^%\s*$/) {
	if ($flag==0) {
	    $flag=1;
	} elsif ($flag==2) {
#	    print "$spar_spc" x 3 . "$spar\n";
	    print "$spar_spc" . "$spar\n";
	    $flag=0;
	} else {
	    $flag=0;
	}
	next;
    }
    if (/^% ([^\s].+)$/ && $flag==1) {
	$spar="[$1]";
	$flag=2;
	next;
    }
    $flag=0;
    next unless (/^\s*\\(chapter|.*section){(.+)}/);
    $_="$1$2\n";
    s/chapter//g;
    s/section/$opt_r/g;
    s/sub/  /g;
    print;
    /^(\s+)/; $spar_spc="  $1";
}
