# Sophists Solutions, (c) 1990, 1991, 1992
#
#	$Header: /fuji/lewis/RCS/TranslateNLs,v 1.1 1992/06/20 17:37:55 lewis Exp $
#
# Description:
#
# Translate from CR to NL (ie from UNIX to mac text files).
#
#	Usage:		<<FIX ARGS>>
#		TranslateLNs [-r] [-p] [-t] filename
#
#	-r means recursive
#	-p means show progress
#	-t means show setfile -T TEXT
#
#
# TODO:
#
#
# Notes:
#
#
#
# Changes:
#	$Log: TranslateNLs,v $
#		Revision 1.1  1992/06/20  17:37:55  lewis
#		Initial revision
#
#		Revision 1.1  1992/04/07  09:35:05  lewis
#		Initial revision
#
#
#
#
#
#

Set exit 0
Unset recursive
Unset showProgress
Unset cvtText
Unset sources

# Parse the command line.

For i in {"Parameters"}
	If "{i}" == "-r" || "{i}" == "-recursive"
		Set recursive 1
	Else If "{i}" == "-p" || "{i}" == "-progress"
		Set showProgress 1
	Else If "{i}" == "-t" || "{i}" == "-text"
		Set cvtText 1
	Else
		Set sources "{sources}'{i}' "
	End
End



####### DO THE TRANSLATION

For file in {sources}
	If {showProgress}
		Echo "# Translating {file}..." -n
	End

	if "`Exists -d "{file}"`"
		if {recursive}
			If {cvtText}
				set xxx -t
			Else
				set xxx ""
			End
			if {showProgress}
				Echo Recursive Call
				TranslateNls -r -p {xxx} `files -f "{file}"`
			Else
				TranslateNls -r {xxx} `files -f "{file}"`
			End
		Else
			Echo "Skipping directory "{file}"
		End
	Else If Not Not `Exists -w "{file}"`
		If {cvtText}
			setfile -t TEXT "{file}"
		End
		Open "{file}"
		Find  "{file}"
#		Replace -c  /r/ n "{file}"
		Replace -c  /
/ n "{file}"
		if {status}
			Echo "<Replace failed - perhaps already done?>" -n
		End;
		Find  "{file}"
		Close -y "{file}"
	Else
		Echo "Skipping file "{file}" for unknown reasons (readonly?)
	End;

	Set exit 0
	If {showProgress}
		Echo "done."
	End
End
