[comp.sys.atari.st] I/O redirection with Megamax C

braner@batcomputer.tn.cornell.edu (braner) (11/13/86)

[]

Till now I have been frustrated with the inability of doing
I/O redirection when invoking programs compiled with Megamax (MM)
from inside micro-C-Shell (MCS).  Since no one posted any fix,
I had to do it myself...

The problem is that if you, say, include ">outfile" on the command line,
MCS redirects what IT thinks is stdout to the file "outfile".  But MM
has other ideas about what stdout is.  I thought that putting it
in quotes (progname '>outfile') would protect it from MCS, leaving MM
to do its thing.  But then even MM leaves it alone (I guess MCS does
not strip the quotes off!), so no redirection at all.

Solution for now: make MM use other characters instead of '<' and '>'
- characters that MCS ignores.  I chose '_' for input, '^' for output.
This way you gain I/O redirection for YOUR programs from inside MCS -
and it also still works from the desktop - but you have to remember to use
"_infile ^outfile" in BOTH cases.  Akward, since you still have to use
the angle brackets when redirecting MCS programs (as in "ls > file").
But better than nothing! 

The patch (for MM v1.0):

Extract initargcv.o from syslib, using "mmlib X syslib initargcv.o".
Use your favorite debugger or whatever (e.g. bth/htb) to change the
following 3 bytes in the file initargc.o (all these places have a
CMP.W #xx,D0, and we change the xx):

	offset	old	new		notes

	 $1AB	$3C	$5F	'<' --> '_'	(input)
	 $1C3	$3E	$5E	'>' --> '^'	(output)
	 $1D5	$3E	$5E	'>' --> '^'	(append with ^^)

Delete initargcv.o from syslib:    "mmlib D syslib initargcv.o".
Put the new version inside syslib: "mmlib R syslib initargc.o".

(The 'D' step MAY be necessary since the TOS filename is shorter
than the original internal name inside syslib - how did they do it?)

- Moshe Braner