-
Notifications
You must be signed in to change notification settings - Fork 1
/
genstdmod.pl
executable file
·51 lines (46 loc) · 1.22 KB
/
genstdmod.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env perl
use warnings;
use strict;
use constant COLUMNS => 2;
use constant COLUMN_WIDTH => 24;
my $list;
my $list_only;
if ($#ARGV >= 0 and $ARGV[0] =~ /^--?l(ist([-_]?only)?)?$/i) {
shift;
$list_only = 1;
}
while (<>) {
if (/^\.(.*)/) {
$list .= "$1\n";
} else {
if (length($list)) {
$list = "" unless defined($list);
if ($list_only) {
print "$_\n" for sort split(/\s+/, $list);
} else {
my $columnated;
my $column = 0;
my $space = "";
for my $id (sort split(/\s+/, $list)) {
my $new_column = $column + 1 + int(length($id) / COLUMN_WIDTH);
if ($new_column > COLUMNS) {
$columnated .= "\n";
$new_column -= $column;
$column = 0;
$space = "";
}
$columnated .= $space . $id;
$space = " " x (($new_column-$column)*COLUMN_WIDTH - length($id));
$space .= " " x ($new_column-$column-1);
$column = $new_column;
}
$columnated =~ s/_/\\_/g;
$columnated =~ s/\? /\?\\ /g;
$columnated =~ s/((?:\\.|\S)+)/{\\cf $1}/g;
print "$columnated\n";
undef $list;
}
}
print unless $list_only;
}
}