home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- #
- # checknews -- pipe to words for formatting.
- # by Tom Christiansen <tchrist@convex.com>
-
- &getwin;
-
- #$ARGV[0] eq '-c' && ($chopit++, shift);
- $chopit++;
-
- $WIDTH = ($cols > 80) ? 20: 13;
-
- die "can't fork: $!" unless defined ($pid = open(WORDS, "|-"));
- if ($pid) {
- select(WORDS);
- open(RN, "rn -t -s750 -c @ARGV|");
- @newsgroups = <RN>;
- $chopit = 0 if @newsgroups < 5;
- for (@newsgroups) {
- next unless ($_, $count) = /^(\S+): (\d+)/;
- 0 while $chopit && $WIDTH < length && s/\b(\w)[^.]+\./$1./;
- $_ = sprintf("%3d %s\n", $count, $_);
- s/ +$//;
- print;
- }
- close WORDS;
- wait;
- exit $?;
- }
-
-
- ##################################################################
- # from here on in is my basic "words" script... included here
- # so that checknews is self-contained. some versions of pr
- # are smart enough to do this. sadly, ours is not one of them.
-
- sub eol { ($elt+1) % $cols == 0; } # is this the last elt on line?
-
- $maxlen = 1; # widest string yet seen
-
-
-
- while (<STDIN>) { # read stdin into $_
- s/\s+$//;
- $maxlen = $mylen if (($mylen = length($_)) > $maxlen);
- push(list, $_);
- }
-
- $maxlen += 1; # spaces
-
- $cols = int($cols / $maxlen);
- $rows = int(($#list+$cols) / $cols);
- $mask = sprintf("%%-%ds ", $maxlen);
-
- for ($elt = 0; $elt < $rows * $cols; $elt++) {
- $target = ($elt%$cols) * $rows + int(($elt/$cols));
- $piece = sprintf($mask, $target < ($#list+1) ? $list[$target] : "");
- $piece =~ s/\s+$// if do eol(); # don't blank pad to eol of line
- print $piece;
- print "\n" if do eol();
- }
-
- print "\n" if do eol();
-
- exit 0;
-
- sub getwin {
- $TIOCGWINSZ = 0x40087468; # should be require sys/ioctl.pl
- if (ioctl(STDOUT, $TIOCGWINSZ, $winsize)) {
- ($rows, $cols, $xpixel, $ypixel) = unpack('S4', $winsize);
- } else {
- $cols = 80;
- }
- }
-