head     1.2;
branch   ;
access   ;
symbols  ;
locks    lee:1.2;
comment  @# @;


1.2
date     95.10.09.23.42.57;  author lee;  state Exp;
branches ;
next     1.1;

1.1
date     95.09.10.01.06.42;  author lee;  state Exp;
branches ;
next     ;


desc
@split footnotes into columns..
@


1.2
log
@fixed some bugs yonks ago I s'pose.
@
text
@#! /usr/local/bin/perl -w

# this program reads the footnote file produced by tmac.doc, while it
# is running, sorts the footnotes, and inserts column break requests.

# input:
# .COLS N MaxHeightEach VSPaceBetween
# NAME height
# NAME height
#
# output:
# .+FootCol N
# .FootPrint
# .FootPrint
# .-FootCol N

$Cols = 2; # default is 2 columns
$Height = 300; # default is an inch at 300dpi
$Gap = 0;
$Count = 0;
$TotalHeight = 0;

while (<>) {
    chop($_);
    @@Fields = split(/ /, $_);
    if (/^\.COLS/) {
	$Cols = $Fields[1];
	$Height = $Fields[2];
	$Gap = $Fields[3];
	# print STDERR "footfondler: Cols $Cols, Height $Height, gap $Gap\n";
    } else {
	$Heights{$Fields[0]} = $Fields[1] + 0;
	$TotalHeight += $Fields[1];
	$Count++;
    }
}

# work out the total approximate divided height

@@Names = sort (keys %Heights);
for ($i = 1; $i <= $Cols; $i++) {
    $ColHeights[$i] = 0;
}

$OneEach = 0;
if ($Count <= $Cols) {
    $OneEach = 1;
}

# measure the heights
$ThisCol = 1;

foreach $i (@@Names) {
    if ($ColHeights[$ThisCol] == 0) {
	$AddMe = $Heights{$i};
    } else {
	$AddMe = $Heights{$i} + $Gap;
	if ($OneEach || $AddMe + $ColHeights[$ThisCol] > $Height) {
	    $AddMe = $Heights{$i};
	    $ThisCol++;
	    $ColHeights[$ThisCol] = 0;
	}
    }
    $ColHeights[$ThisCol] += $AddMe;
}

# find the tallest
$Tallest = 0;
for ($ThisCol = 1; $ThisCol <= $Cols; $ThisCol++) {
    if ($ColHeights[$ThisCol] > $Tallest) {
	$Tallest = $ColHeights[$ThisCol];
    }
    if ($ColHeights[$ThisCol] > $Height) {
	print ".tm PAGE \\n% FOOTNOTE OVERFLOW COL ${ThisCol}\n";
    }
    # reset them again:
    $ColHeights[$ThisCol] = 0;
}

# print them:
$ThisCol = 1;
print ".+FootCol $ThisCol $Tallest\n";
foreach $i (@@Names) {
    if ($ColHeights[$ThisCol] == 0) {
	$AddMe = $Heights{$i};
    } else {
	$AddMe = $Heights{$i} + $Gap;
	if ($OneEach || $AddMe + $ColHeights[$ThisCol] > $Height) {
	    print ".-FootCol $ThisCol\n";
	    $ThisCol++;
	    print ".+FootCol $ThisCol $Tallest\n";
	    $ColHeights[$ThisCol] = 0;
	    $AddMe = $Heights{$i};
	}
    }
    print ".FootPrint $i\n";
    $ColHeights[$ThisCol] += $AddMe;
}

print ".-FootCol $ThisCol\n";
@


1.1
log
@Initial revision
@
text
@d12 1
a12 1
# .FootCol N
d15 1
a15 1
# .FootCol N
d30 1
a30 1
	print STDERR "footfondler: Cols $Cols, Height $Height, gap $Gap\n";
d54 9
a62 3
    $AddMe = $Heights{$i};
    if ($ColHeights[$ThisCol] > 0) {
	$AddMe += $Gap;
a63 4
    if ($OneEach || $AddMe + $ColHeights[$ThisCol] > $Height) {
	$ThisCol++;
	$AddMe -= $Gap;
    }
a64 1
    print ".FootPrint $i\n";
d69 1
a69 1
for ($i = 1; $i <= $Cols; $i++) {
d84 11
a94 3
    $AddMe = $Heights{$i};
    if ($ColHeights[$ThisCol] > 0) {
	$AddMe += $Gap;
d96 1
a96 7
    if ($OneEach || $AddMe + $ColHeights[$ThisCol] > $Height) {
	# Note; don't allow a split footnote;
	print ".-FootCol $ThisCol\n";
	$ThisCol++;
	print ".+FootCol $ThisCol $Tallest\n";
	$AddMe -= $Gap;
    }
a97 1
    print ".FootPrint $i\n";
d99 2
a100 1
print "-FootCol $ThisCol\n";
@
