#!/bin/sh
# http://www.berklix.com/~jhs/bin/.sh/noquote
echo "$0 is Obsolete, replaced by ~/public_html/src/bsd/jhs/bin/public/mvexp/"
# http://www.berklix.com/~jhs/bin/.sh/noquote
# bourne shell script by Julian H. Stacey
# See Also (and run after or before some of these in):    ~/bin/.sh/
#       nobracket nocolon nolower noquote nospace noupper
#	Run nospace Before noupper Or nolower Or nocolon
#	JJLATER Decide Priority Of nobracket And noquote And nospace

# Syntax	noquote filename[s]
# Purpose:
#	Replaces junk characters in names of file and directory,
#	(quotes, spaces, ampersand etc) that could confuse Unix
#	command line interpreters unless explicitly delimited.  For
#	use after importing nasty file names from MSDOS users.
#
#	Removes a big list of junk chars in case of unexpected extra
#	cruft, perhaps from some berserk MS program.

# Example of Bad usage:
#	find . -type d -depth -exec noquote {} \;
#	find . -type f -exec noquote {} \;
#	find . -type d -depth -exec lower {} \;
#	find . -type f -exec lower {} \;
# The above will fail on deep directory paths with 2 components 
# that need fixing, eg
#	some"quoted"excrement/&spaced path/with'sub'/Julian's apostrophe paths
# So better not to use -depth , and first run 'find -type d' several times
# (as many times as deepest dir. path in tree) letting it fix one level 
# each run, eg:
# Example Of Better Usage:
#	mkdir test ; cd test
# 	mkdir -p 'level One/strata TWO/plateau THREE'
#	touch    'level One/strata TWO/plateau THREE/Ghastly"&File'
#	find . -type d
#		./level One
#		./level One/strata TWO
#		./level One/strata TWO/plateau THREE
#	find . -type d -print -exec noquote {} \;
#		./level One
#		find: ./level One: No such file or directory
#	find . -type d -print -exec noquote {} \;
#		./level_One
#		./level_One/strata TWO
#		find: ./level_One/strata TWO: No such file or directory
#	find . -type d -print -exec noquote {} \;
#		./level_One
#		./level_One/strata_TWO
#		./level_One/strata_TWO/plateau THREE
#		find: ./level_One/strata_TWO/plateau THREE:
#			 No such file or directory
#	find . -type d -print -exec noquote {} \;
#		Not necessary as weve done all 3 levels already.
#		./level_One
#		./level_One/strata_TWO
#		./level_One/strata_TWO/plateau_THREE
#	find . -type d -print -exec lower {} \;
#		./level_One
#		find: ./level_One: No such file or directory
#	find . -type d -print -exec lower {} \;
#		./level_one
#		./level_one/strata_TWO
#		find: ./level_one/strata_TWO: No such file or directory
#	find . -type d -print -exec lower {} \;
#		./level_one
#		./level_one/strata_two
#		./level_one/strata_two/plateau_THREE
#		find: ./level_one/strata_two/plateau_THREE:
#			 No such file or directory
#	find . -type f -print -exec noquote {} \;
#		./level_one/strata_two/plateau_three/Ghastly"&File
#		find . -type f -print
#		./level_one/strata_two/plateau_three/Ghastly__File
#	find . -type f -print -exec lower {} \;
#		./level_one/strata_two/plateau_three/Ghastly__File
#	find . -type f -print
#		./level_one/strata_two/plateau_three/ghastly__file

# 3rd Example - Best:
#       Ideally JJLATER one could use 'find . -type d -depth' and
#	feed output into a for loop, using (man 1) dirname to recurse
#	ever shorter, fixing each leaf back to the (relative) root.

# See `man ascii` for full table
# The list is slower to evaluate than a single pre set string,
# but it allows addition of comments and easy edit enabling/disabling of chars.

cruft=""
cruft="${cruft}\007"	# BEL
cruft="${cruft}\010"	# BS
cruft="${cruft}\011"	# HT

# cruft="${cruft}\012"	# NL
#	Do not uncomment line above, else a trailing _ gets appended to
#	filenames.  I have not worked out why, but no problem
#	as I do not need to strip new line chars from within file names.
#	This NL phenomena probably explains why I earlier failed,
#	experiencing trailing _, when I used [:space:] which I had hoped would 
#	expand to space and HT=tab, but probably also included NL.

cruft="${cruft}\013"	# VT
cruft="${cruft}\014"	# NP
cruft="${cruft}\015"	# CR
cruft="${cruft}\033"	# ESC
cruft="${cruft}\040"	# space	Unix seperates file names.
cruft="${cruft}\041"	# !	Unix find negate
cruft="${cruft}\042"	# "	MS does not allow.
cruft="${cruft}\044"	# $	Unix parameters for shells.
cruft="${cruft}\046"	# &	Unix autonomous background process
cruft="${cruft}\047"	# '	Unix evaluation delimiter/avoider
cruft="${cruft}\052"	# *	MS does not allow.
cruft="${cruft}\072"	# :	MS does not allow.
cruft="${cruft}\073"	# ;	Unix command seperator
cruft="${cruft}\074"	# <	MS does not allow.
cruft="${cruft}\076"	# >	MS does not allow.
cruft="${cruft}\077"	# ?	MS does not allow. Unix single generic.
cruft="${cruft}\133"	# [	Unix command name aliased to test.
cruft="${cruft}\134"	# \	MS directory seperator
cruft="${cruft}\135"	# ]	Matches [
cruft="${cruft}\136"	# ^	Unix vi (and procmail etc) beginning of line
cruft="${cruft}\140"	# `	Unix invoke sub process
cruft="${cruft}\174"	# |	MS does not allow.
cruft="${cruft}\176"	# ~	Unix csh users home dir
cruft="${cruft}\177"	# DEL	Unix shells would find this a pain.
#              \056	# .	MS not more than one. Unix allows multiple.
#              \057	# /	MS and Unix directory seperator.

if [ "$1" = "`echo $1 | tr "$cruft" _`" ]; then
	# echo "No need to convert $1."
else
	# echo "Moving $1 to `echo ${1} | tr "${cruft}" _`"
	mv "$1" "`echo $1 | tr "$cruft" _`"
fi
