[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: add LINEFEEDS?
Swamp Ratte (sratte@mindvox.phantom.com) wrote:
: Hi. I'm wondering if there's a utiliy I could leech w/ftp which adds
: linefeeds to CR-only text files to make 'em MS-DOS compatible?
I asked a similar question a week ago, here's the best reply I got.
Follow it's instructions, then use the atom command to add LFs. (Note:
Works on Unix, if you wanted an A2 program, you should have specified.)
-----START OF FILE (CUT HERE)
#!/bin/sh
########################################################################
# atou (convert apple to unix)
# Version: 1.0.1
# Copyright (C) 1993 by Sean Dockery.
#
# History:
# 93.12.04: Correction of mtou and mtoa conversion bug.
# 93.11.22: Inception of the script.
#
# Description:
# This script will convert the following files when invoked with a given
# command name:
#
# atou: Apple newlines to UNIX newlines
# utoa: UNIX newlines to Apple newlines
# atom: Apple newlines to MS-DOS newlines
# mtoa: MS-DOS newlines to Apple newlines
# utom: UNIX newlines to MS-DOS newlines
# mtou: MS-DOS newlines to UNIX newlines
# maketext: binary characters to text characters
#
# Installation:
# You require the following commands to be present on your UNIX
# system to use this script:
# -basename
# -find
# -mv
# -sh
# -tr
#
# Install this script in your own $HOME/bin directory--make sure that
# $HOME/bin is part of your $PATH variable (preferably located early
# in the $PATH priority,) under the name 'atou'. Create soft links
# to this script by using the 'ln' command.
#
# Example:
# $ ln -s atou utoa
#
# Do this for all of the above named commands (utoa, atom, etc ...)
# If your UNIX system does not have a link command, use 'cp' instead.
#
# Syntax:
# $ atou [-v] [-c] <filespec>
# or
# $ cat foo | atou [-v] -
#
# Primary Options:
# -v: Give terse diagnostic output.
# default: Normally no diagnostic output is given.
#
# Secondary Options:
# -: Input will be taken from stdin and output directed to stdout.
# No files may be declared when this option is used.
# -c: Input will be taken from files and output directed to stdout.
# Files must also be declared with this option.
#
# Bugs and Limitations:
# This script will reset the file permissions of the file(s) that it
# acts upon to the user's umask value.
#
# This script also has no way to know if a file that it is dealing with
# is binary in nature; such files will always be corrupted as a result.
#
########################################################################
# Determine the base command name.
command=`basename $0`
# Determine (based on the command name) which type of conversion that
# we will be undertaking.
case $command in
atou) # Apple to UNIX
oct1='\015'
oct2='\012'
;;
utoa) # UNIX to Apple
oct1='\012'
oct2='\015'
;;
atom) # Apple to MS-DOS
oct1='\015'
oct2='\015\012'
;;
mtoa) # MS-DOS to Apple
oct1='\015\012'
oct2=' \015'
;;
utom) # UNIX to MS-DOS
oct1='\012'
oct2='\015\012'
;;
mtou) # MS-DOS to UNIX
oct1='\015\012'
oct2=' \012'
;;
maketext) # binary to text
oct1='[\201-\377]'
oct2='[\001-\177]'
;;
*) # unknown
echo "$command: unknown function \"$command\""
exit 1
;;
esac
# Determine if we are to be quiet or loud.
verbose=0
case $1 in
-v) # verbose mode
verbose=1
shift
;;
esac
# Determine if we are in stdin, stdout, or file mode.
if ( [ $# -ne 0 ] && [ $1 = '-c' ] )
then
stdin=0
stdout=1
shift
elif ( [ $# -ne 0 ] && [ $1 = '-' ] )
then
stdin=1
stdout=1
shift
else
stdin=0
stdout=0
fi
# Make sure we have the correct number of arguements for the mode we are in.
if ( [ $stdin -eq 1 ] && [ $# -gt 0 ] ) || ( [ $stdin -eq 0 ] && [ $# -eq 0 ] )
then
echo "usage: $command [-v] [-c] <filespec>, or cat <filespec> | $command [-v] -"
exit 1
fi
if [ $stdin -eq 0 ]
then
for file in $*
do
if [ `find . -name $file -print` ]
then
if [ -f $file ]
then
if [ $stdout -eq 0 ]
then
mv $file "$command_$$"
[ $verbose -eq 1 ] && echo -n "$command: $file..."
tr "$oct1" "$oct2" < "$command_$$" > $file
rm "$command_$$"
[ $verbose -eq 1 ] && echo "done."
else
tr "$oct1" "$oct2" < $file
fi
else
[ $verbose -eq 1 ] && echo "$command: $file is a directory."
fi
else
[ $verbose -eq 1 ] && echo "$command: $file does not exist."
fi
done
else
tr "$oct1" "$oct2"
fi
---------END OF FILE (CUT HERE)
--
For my cooler signature: finger moxie@panix2.panix.com
Mark Mentovai - MOXMAN - moxie@panix.com