#! /bin/sh
# $Id: rcvtty.fixup,v 1.1 92/07/31 08:09:24 jerry book2 $
### rcvtty.fixup - fix rcvtty output for raw-mode ttys
### Usage: rcvtty rcvtty.fixup command [command-args]
##
##  IF YOU GIVE rcvtty A COMMAND NAME TO RUN, IT WILL PIPE THE MESSAGE
##  TO THE INPUT OF THAT COMMAND.  IT WILL WRITE THE OUTPUT OF THE
##  COMMAND TO ALL TERMINALS WHERE YOU'RE LOGGED IN.  IF ANY TERMINALS
##  AREN'T IN THE DEFAULT cooked MODE, THE OUTPUT OF THE COMMAND WILL
##      run down
##               the screen
##                         like this
##  rcvtty.fixup FIXES THAT BY ADDING A CARRIAGE RETURN (CR) CHARACTER
##  TO THE END OF EACH LINE OF OUTPUT.  IT ALSO ADDS A CARRIAGE RETURN
##  BEFORE THE FIRST LINE OUTPUT; THIS MAKES THE FIRST LINE START AT
##  THE LEFT MARGIN INSTEAD OF THE CURSOR POSITION.  THIS DOESN'T HURT
##  cooked DISPLAYS AND IT MAKES OUTPUT EASY TO READ ON raw DISPLAYS.
##
##  rcvtty.fixup ALSO REPLACES EMPTY LINES WITH 70 COLUMNS OF WHITESPACE.
##  THIS MAKES THE MESSAGE A LOT EASIER TO READ ON WINDOWS
##
##  rcvtty.fixup RUNS THE COMMAND GIVEN ON ITS COMMAND LINE, WITH
##  STANDARD INPUT FROM rcvtty, AND STANDARD OUTPUT FILTERED THROUGH sed.
# 
#                             NO WARRANTY
# 
#   BECAUSE THIS PROGRAM IS AVAILABLE FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
# 
#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


# MAKE CR (OCTAL 015) CHARACTER PORTABLY:
cr="`echo x | tr x '\015'`"
# WHITESPACE TO REPLACE EMPTY LINES AND MAKE THEM MORE VISIBLE:
spaces="                                                                      "

# RUN COMMAND AND ARGUMENTS, PIPE TO sed FOR CLEANUP AND OUTPUT TO tty:
"$@" |
sed -e "s/^[    ]*\$/$spaces/" -e "1s/^/$cr/" -e "s/\$/$cr/"

exit    # RETURN EXIT STATUS OF COMMAND TO rcvtty
