aboutsummaryrefslogtreecommitdiff
path: root/mkslackdesc
blob: 4795a746171d0f09d66e6950c3b574b7ed3a9d76 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl -w

# mkslackdesc

# Convert a README into a valid slack-desc.

# Usage: mkslackdesc [input]

# If input not given, reads the file README in the current dir.
# To read from standard input, give - as the input file.

# Output: a slack-desc, including the "how to edit" comments
# and the "handy ruler" line. If the input text won't fit into
# 11 72-characters lines, the output will not be a valid slack-desc,
# and you'll get a warning to that effect.

# Output is to slack-desc in the current directory, and is also echoed
# to standard output.

if(-e "slack-desc") {
	die "slack-desc already exists in current directory!\n";
}

chomp ($pkg = `pwd`);
$pkg =~ s,.*/,,;

if(!@ARGV) {
	push @ARGV, "README";
}

open my $f, ">slack-desc" or die $!;
print "Writing to slack-desc:\n\n";

$ruler = <<EOF;
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.
# Line up the first '|' above the ':' following the base package name, and
# the '|' on the right side marks the last column you can put a character in.
# You must make exactly 11 lines for the formatting to be correct.  It's also
# customary to leave one space after the ':' except on otherwise blank lines.

EOF

$ruler .= (' ' x length($pkg)) . <<EOF;
|-----handy-ruler------------------------------------------------------|
EOF

print $ruler;
print $f $ruler;

$lines = 11;
open my $pipe, "fmt -s -w 71 < $ARGV[0] |" or die $!;
while($_ = <$pipe>) {
	--$lines;
	chomp;
	my $outline = "$pkg:";
	$outline .= " $_" if $_;
	$outline .= "\n";
	print $outline;
	print $f $outline;
}

close $pipe;

if($lines < 0) {
	warn "slack-desc is too long (should be 11 lines), output not valid\n";
} else {
	print "$pkg:\n" for 1..$lines;
	print $f "$pkg:\n" for 1..$lines;
}

close $f;