#! /usr/bin/perl -s # # This creates an index page for the man pages of a given chapter. # Usage: # ls -1 file_list | mkmandex -sSection -name="maintainter name" \ # -address="maintainer email address" # # Devin Reade, November 1997. # # $Id: mkmandex,v 1.1 1997/11/24 05:07:27 gdr Exp $ # # initialize and check usage $sec=''; defined($s1) && ($num = '1') && ($sec = "Commands and Applications"); defined($s2) && ($num = '2') && ($sec = "System Calls"); defined($s3) && ($num = '3') && ($sec = "Library Routines"); defined($s3f) && ($num = '3f') && ($sec = "Fortran Routines"); defined($s4) && ($num = '4') && ($sec = "Devices"); defined($s5) && ($num = '5') && ($sec = "File Formats"); defined($s6) && ($num = '6') && ($sec = "Games"); defined($s7) && ($num = '7') && ($sec = "Miscellaneous"); defined($s8) && ($num = '8') && ($sec = "System Administration"); ($sec eq '') && die("section number not specified"); defined($name) || die("-name flag not specified"); defined($addr) || die("-addr flag not specified"); defined($hroot) || die("-hroot flag not specified"); # $hdir = $hroot . '/man/man' . $num . '/'; $hdir = $hroot . '/man/'; # print out the head of the page printf("\n" . "\n" . "\n". '' . "\n" . "Chapter %s: %s\n" . "\n" . "\n" . "

Chapter %s: %s

\n" . "
\n",
       $num, $sec, $num, $sec);

# get the list of files
$maxlen = 0;
while(<>) {
    chop;
    $pagename = $file = $_;
    $pagename =~ s/\.\df?$//;
    $filelist{$pagename} = "man$num/$file";
    $len = length($pagename);
    ($len > $maxlen) && ($maxlen = $len);
}


# add in the appropriate .so links
if (defined($mkso)) {
    open(infp, "< $mkso") || die("couldn't open $mkso");
    while ($_ = ) {
	s/\#.*//;
	(/^\s*$/) && next;

	if (/^\s*(\S+)\s+(\S+)\s*$/) {
	    $real = $1;
	    $link = $2;
	    $link =~ s,.*/,,;
	    if ($link =~ /(\df?)$/) {
		$suffix = $1;
		if ($suffix eq $num) {
#		    if ($real =~ m,(.*)/,) {
#			$prefix = $1;
#			if ($prefix eq "man$num") {
#			    $real =~ s,.*/,,;
#			}
#		    }
		    $pagename = $link;
		    $pagename =~ s/\.\df?$//;
		    $filelist{$pagename} = $real;
		    $len = length($pagename);
		    ($len > $maxlen) && ($maxlen = $len);
		}
	    } else {
		printf(stderr "%s corrupt at line %d (1) real=%s\n",
		       $mkso, $., $real);
	    }
	} else {
	    printf(stderr "%s corrupt at line %d (2)\n", $mkso, $.);
	}
    }
    close(infp);
}


$pagewidth = 70;
$colwidth = $maxlen + 3;
$columns = int($pagewidth / $colwidth);
($columns == 0) && ($columns = 1);

# special-case the introduction page
$intro = 'intro';
if (defined($filelist{$intro})) {
    printf("%s (Chapter Introduction)\n\n",
	   $hdir, $filelist{$intro}, $intro);
    undef($filelist{$intro});
}

@keylist = sort(keys(%filelist));

# put everything into neat columns
undef(@rows);
$maxrow = 0;
$entries = scalar(@keylist);
$maxrow = int($entries / $columns);
(($entries % $columns) == 0) || ($maxrow++);
while (scalar(@keylist) > 0) {
    for ($i=0; ($i<$maxrow) && (scalar(@keylist) > 0); $i++) {
	$k = shift(@keylist);
	if ($k eq $intro) {
	    $i--;
	    next;
	}
	$padding = $colwidth - length($k);
	$rows[$i] .= '' 
	    . $k . '';
	for ($j = 0; $j < $padding; $j++) {
	    $rows[$i] .= ' ';
	}
    }
}

# print them out	
for ($i=0; $i<$maxrow; $i++) {
    printf("%s\n", $rows[$i]);
}


if (0) {

    die('oh shit');
while (scalar(@keylist) > 0) {
    for ($i=0; ($i<$columns) && (scalar(@keylist) > 0); $i++) {
	$k = shift(@keylist);
	$padding = $colwidth - length($k);
	printf("%s", $filelist{$k}, $k);
	for ($j = 0; $j < $padding; $j++) {
	    print ' ';
	}
    }
    printf("\n");
}
}

#    printf("%s
\n", $_, $_); # print out the tail of the page printf("
\n" . "
\n". "%s\n" . "<%s>\n" . "\n". "\n", $name, $addr, $addr);