From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from wilma.cs.widener.edu ([147.31.254.26]) by archone.tamu.edu with SMTP id <18903>; Thu, 19 Dec 1991 12:10:38 -0600 Received: by wilma.cs.widener.edu id AA02325 (5.65c/Widener-4.0 for rc@archone.tamu.edu); Thu, 19 Dec 1991 13:10:01 -0500 Date: Thu, 19 Dec 1991 12:10:01 -0600 From: Brendan Kehoe Message-Id: <199112191810.AA02325@wilma.cs.widener.edu> To: rc@archone.tamu.edu Subject: zmore with rc Reply-To: brendan@cs.widener.edu Any suggestions or comments on style/whatever before I post this? This is my first "real" rc script, so I don't wanna make any horrendous gaffes before trying to convince others to use it. :) -- cut -- #!/bin/rc # # zmore - my even more souped-up version of the zmore script that # comes with the compress(1) distribution. # # usage: zmore [name ...] # # This version's based on DaviD W. Sanderson's script, and has these # features (those with *'s are added with this version): # # a) knows about $PAGER (but defaults to "more") # b) knows about more kinds of compressed files: # foo.Z, foo.F, foo.z (and it's easy to add more) # c)* will read files that're compressed in more than one way (e.g. # it'll read foo.Z then foo.F then...) # d) works on both SysV and BSD systems # e) is (marginally) commented...have the rc manpage nearby if you're # not comfortable with it # f) written with rc :) # extensions = (.Z .F .z) # Note I haven't checked why yet, but the Gnu stty doesn't work right # with this---the stty of min dies. stty=/bin/stty # Restore the tty on exit fn exit { if ( ! { ~ $icanon () } ) $stty $icanon builtin exit } # Prompt for the next file fn prompt_next { if ( ! { ~ $icanon () } ) { echo -n (Next file: $f) if ( ! { ~ $cbreak () } ) $stty $cbreak answer = `{dd bs'='1 count'='1 >[2] /dev/null} if ( ! { ~ $icanon () } ) $stty $icanon echo ' ' switch ($answer) { case [eEqQ] builtin exit } } } fn read_file { if ( ! { ~ $icanon () } ) echo ------'>' $f '<'------ # There must be a better way to do this; I was fooling around with # something like: # readers=(zcat fcat pcat); list=(1 2 3) # Then somehow using $extensions^' '^$list then a shift, have it # give you the number from list (being foo) to use for $readers($foo). # I gave up after a little while. switch ( $f ) { case *Z eval zcat $f $page case *F eval fcat $f $page case *z eval pcat $f $page case * eval $PAGER $f } } # If we're on a terminal, get ourselves set to ask for a single char # using cbreak mode. if ( test -t 1 ) { if ( ! { ~ `{ $stty -a >> /dev/null >[2=1]} () } ) { icanon = `{ $stty -g} cbreak = (-icanon -echo -echoe -echok -echonl min ^A time ^@) } else { # probably a BSD-based tty system icanon = (-cbreak echo) cbreak = (cbreak -echo) } } # Figure out what pager to use, then do a little trickery. if ( ~ $PAGER "" ) { PAGER=more } page='| '^$PAGER # First check if we were given a file with an explicit extension we # know about; if it has one, don't bother searching through the rest. # This loses some of the functionality we tried to add, but it saves # a lot in speed. got = junk for (file) { if ( ~ $file *^$extensions ) { f = $file if ( ~ $got () ) prompt_next read_file } else { for ( f in $file^$extensions ) { if ( test -f $f ) { if ( ~ $got () ) prompt_next got = 1 read_file } } if ( ~ $got () ) echo ------'>' $file '<'------ '('cannot find')' } got = () } -- cut -- -- Brendan Kehoe, Sun Network Manager brendan@cs.widener.edu Widener University Chester, PA You can help encourage creativity---and stop those who want to stifle it. Join the League for Programming Freedom: write league@prep.ai.mit.edu.