#!/usr/local/bin/perl -w &replace_old_contents; open(CONT,">Contents.m") || die "can't open contents file"; $doc = 0; $no_doc_yet = 1; FILE: foreach $mfile (<*.m>) { #loop through mfiles if ($mfile eq "Contents.m") { #skip contents.m next FILE; } open(MFL,"$mfile") || die "can't open $mfile"; print CONT "%$mfile:"; while (($oneln = )&& ($no_doc_yet || $doc) ) { if ($oneln =~ /^%.*/) { #if a comment line $oneln =~ s/%//; #cut the % $doc = 1; #flag - in comment $no_doc_yet = 0; #flag found comment print CONT "$spc$oneln"; #print it to content $spc = "%\t\t"; #start of line } else { #no doc yet or $doc = 0; #finished doc } } if ($no_doc_yet == 1) { # not found any documentation print CONT "\tNo help available.\n"; } $no_doc_yet = 1; $doc = 0; $spc = "\n%\t\t"; close(MFL); } sub replace_old_contents { if (-e "Contents.m") { print STDERR 'Contents file exists! overwrite? (y/n)'; $ans = ; chop($ans); if (($ans ne 'y') && ($ans ne 'Y') && ($ans ne 'ok')){ exit; } } }