Converting Bourne or Korn shell scripts to Hamilton C shell scripts
Copyright (c) 1992, 1993 by Hamilton Laboratories.  All rights reserved.


	> Use TABS = 3 to view this file and any of the sed scripts <


To translate an sh script to csh, run it thru the following pipeline:

	sed -f expr.sed | sed -f if.sed | sed -f proc.sed | sed -f case.sed |
		sed -f for.sed | sed -f misc.sed | sed -f expr2.sed | sed -f quotes.sed

(or just use the sh-2-csh.csh script).

Each stage is using sed to fixup a specific type of language difference
between sh and csh.  Order is important and the stages must be connected
thru pipes rather than simply concatenating the scripts.  But any individual
stage can be run independently for testing or just to see what it does.
These sed scripts were tested with Hamilton sed and may not work perfectly
on a standard Unix sed.  (Hamilton sed has a number of minor enhancements,
e.g., to allow it to process scripts with relaxed spacing rules, etc.)

The result will (hopefully) be fairly good if the input is in clear,
well-formatted style, but with these limitations:

	1.	The output will depend on the C shell being run with use of the
		status variable and the setting for the escape symbol set as
		follows:

			set tailstatus = 1		# The status variable should reflect the
											#	return code for the rightmost process
											#	in a pipeline rather than, by default,
											#	the leftmost.

			set escapesym = \			# Use the Unix-style \, not the OS/2
											#	default ^, as the escape symbol.

	2.	break statements will have to be manually rewritten, since sh
		interprets break to mean break out of loops only, not case
		statements.  Also, break n means break out of n levels, even
		breaking out of loops entered in calling procedures.  The sed
		scripts will turn break into FixBreak in the output.

	3. The Hamilton date command does not support formatting options.

	4. There's no egrep or awk in the Hamilton C shell package, but grep,
		fgrep and sed are provided.

	5. Under the C shell, variables are either shell variable or
		environment variables from the moment they're created.

	6. The scripts do a pretty good job editing most things, but some
		things just don't go thru very well and will require hand tuning.
		E.g., backquoted expr expressions with embedded escaped quotes
		are garbled and escaped newlines may cause trouble.

To really see how the changes have worked out, diff the input and output
with Hamilton diff, using the -! option to generate a merged listing using
color to highlight the changes in context.  Use Hamilton more (hmore.exe)
with the -i (interactive) option to browse the output and search forward
and backward for changes, which will be marked by the ANSI escape sequences
containing "[1;".

	diff -! foo.sh foo.csh | more -i

All Hamilton utilities have online help available with the -h option.  In
addition, Hamilton more has a builtin help screen available during normal
operation when you press H.

Regards,

Doug Hamilton
Hamilton Laboratories
13 Old Farm Road
Wayland, MA  01778-3117

Phone 508-358-5715
FAX   508-358-1113

Internet  3890321@mcimail.com
