#!/usr/local/bin/perl ;# ;# stripe: make it striped... ;# ;# I don't know how to explain what this program is. Try examples. ;# If you don't have `fold.pl', get it from srawgw.sra.co.jp via ftp. ;# ;# Copyright (c) 1993 Kazumasa Utashiro ;# Software Research Associates, Inc. ;# 1-1-1 Hirakawa-cho, Chiyoda-ku, Tokyo 102, Japan ;# ;# Original version: 29 Mar 1993 ;; $rcsid = q$Id: stripe,v 1.2 1993/10/22 10:53:32 utashiro Exp $; ;; $myname = ('whoami?', split('/', $0)); ;# ;# Example: ;# stripe file ;# stripe -x4 file ;# stripe -x -c'1*' file ;# stripe -c '1,2,3,4,5,6,7,8,9,10,11,12' file ;# stripe -x10 -c80 file ;# df | stripe -x1,100 -c '20,8,8,8,9,*' ;# require 'fold.pl'; $usage = <<" ;"; $myname [-c column_list] [-#] [-w screen_width] [-p] [-x] -c list: column list (e.g. "8*", "1,2,3,4,5,6,7,8", "5{4},6{2},10*") -#: shortcut for "#*" (e.g. -4) -w: set screen width -p: don't put padding spaces -x[#[,#]]: produce checker pattern (# is repeat count) ; $screen_width = 80; $stripe_width = 8; $column_list = '8*'; while ($_ = $ARGV[$[], s/^-(.+)$/$1/ && shift) { next unless length; if (s/^\d+//) { $column_list = "$&*"; redo; } if (s/^c(.*)//) { $column_list = $1 || shift; redo; } if (s/^w(.*)//) { $screen_width = $1 || shift; redo; } if (s/^p//) { $no_padding = 1; redo; } if (s/^x([\d,]*)//) { (@checks = split(',', $1)) || (@checks=(1)); redo; } print STDERR "Usage: ", $usage, "$rcsid\n"; exit(!/^h/); } ($so, $se) = &sose; $w = $screen_width; $_ = $column_list; while (length) { s/^(\d+){(\d+)},?// || s/^(\d+)(\*)?,?// || s/^(\*)// || die "$_: invalid pattern\n"; ($c, $repeat) = ($1, $2); if ($c eq '*') { push(@column_list, $w); last; } if ($repeat eq '*') { push(@column_list, &min($w, $c)), $w -= $c while $w > 0; last; } if ($repeat ne '') { push(@column_list, $c), $w -= $c while $repeat-- > 0; } else { push(@column_list, $c), $w -= $c; } } ($check_status, $check_count) = (0, &nextcheck) if @checks; while (<>) { local($first_column) = 1; chop; $remain = $screen_width; $black = @checks ? $check_status : 0; $column = 0; for $w (@column_list) { ($l, $_) = &fold($_, $w, 1, undef, 't', $column); print $black ? $so : $first_column ? '' : $se; print $l; $black = !$black; last if $no_padding && !length; undef $first_column; $column += $w; } print $se if !$black; print "\n"; if (@checks && (--$check_count == 0)) { $check_status = !$check_status; $check_count = &nextcheck; } } sub sose { do 'ioctl.ph' || do 'sys/ioctl.ph'; require('termcap.pl'); $ospeed = 1 unless $ospeed; &Tgetent; $so = &Tputs($TC{'so'}); $se = &Tputs($TC{'se'}); ($so, $se, $se, $so); } sub nextcheck { @checkbuf = @checks if @checkbuf == 0; return shift(@checkbuf); } sub max { $_[ ($_[$[] < $_[$[+1]) + $[ ]; } sub min { $_[ ($_[$[] > $_[$[+1]) + $[ ]; }