[comp.sys.amiga] mac to amiga and back.

henning@agnes.uucp (Mark D. Henning) (04/10/89)

Reply-To: Jeff Martens <martens@cis.ohio-state.edu>

:In article <3696@sugar.hackercorp.com> peter@sugar.hackercorp.com (Peter da Silva) writes:
:>In article <8YCefHy00Vsf4=7K5l@andrew.cmu.edu>, mp1u+@andrew.cmu.edu (Michael Portuesi) writes:
::: The Amiga uses LF as a line terminator, while the Mac uses CR.
::
::I wish people wouldn't do that. ASCII defines two alternatives for the
::'new-line' sequence: either CR-LF or (if a single character is to be used)
::just plain LF. The whole point to splitting LF and CR was to allow using
::CR for overstriking, which doesn't work if you do a linefeed when you see
::a CR.
:
:Actually, I'd rather see people use CR than linefeed, for a couple reasons:
:
:1) Until Unix came along, just about everybody used CR for
:end-of-line.  Unix was the renegade, and now a lot of newer systems
:are copying the Unix "standard."
:
:2) Terminals use CR rather than LF to end the line, so somewhere along
:the way, to get a program to think a LF has been typed rather than a
:CR, CR has to be mapped to LF.  Just think, AmigaDOS could be about 3
:words shorter and run imperceptibly faster.

Actually it depends on the terminal.  For instance, you are ignoring
the entire world of hardcopy terminals which DO use CR for
overstriking.  This also goes for most dot matriz printers.

In fact, Most terminals I know (ASNI to ADM all-caps) need BOTH a LF
and CR to advance to the next line first column.  The computer's
software takes care of adding the second signal.

Of the two, LF is perhapse the more logical (except perhapse to those
who are used to a typewriter with automatic carriage return,) reasoning 
being that its name itself denotes a new line: Line Feed; whereas the
carriage return ONLY implys that the carriage is returned to the
initizal column.

That however, is a moot point.  The difference exists, just deal with
it.  Perhapse you could "c" up a quick filter such as:

#include <stdio.h>

#define CR 13
#define LF 10

main (argc,argv)
char **argv;
int argc;

{
FILE *in,*out;
char c;
char direction;

	argc--;
	if (argc!=3){
		printf("Usage: amtoma [m/a] infile outfile\n       where m/a is the destination machine.\n");
		exit(1);
	}
	switch (*argv[1]) {
		case 'm':
			direction =0;
			break;
		case 'a':
			direction =1;
			break;
		default:
			printf("Unrecognized option %s.",argv[1]);
			exit(2);
			break;
	}
	in = fopen(argv[2],"r");
	if (ferror(in)!=NULL){
		printf("Unable to open %s of read",argv[2]);
		exit(3);
	}
	out=fopen(argv[3],"w");
	if (ferror(out)!=NULL){
		printf("Unable to open %s of write",argv[3]);
		exit(4);
	}
	if (direction) {
		while ((c=getc(in))!=EOF){
			if (c==CR)
				c=LF;
			putc(c,out);
 		}
	} else {
		while ((c=getc(in))!=EOF){
			if (c==LF)
				c=CR;
			putc(c,out);
 		}
	}
	fclose (in);
	fclose (out);
}

I tested it and it does what it should, that is converting from CR to
LF and visa versa.

				-henning


---------------------------------------------
All opinions are my own, as are the spellings
any deviation from the norm is just an effect
of my deviance.