/* Title : CBM2IBM.C LastEdit: 02/05/89 Author : Kim Moser System : Turbo-C 2.0, MS DOS Descrip : Filter which copies stdin to stdout, converting CBM "PETASCII" to IBM PC [MS DOS] format, or vice versa, depending on command line switch used. Notes : If using Turbo-C, compile in the "Small" memory model. Usage: CBM2IBM -c | -i Options: -c = stdin assumed to be in CBM format (CR becomes CR/LF) -i = stdin assumed to be in IBM format (CR/LF becomes CR) */ #include #include /* exit() */ #include /* toupper() */ #include /* setmode() */ #include /* O_BINARY */ #define CR 13 #define LF 10 void usage(void) /* Shows CBM2IBM usage and credits */ { printf( "CBM2IBM v1.0 (C) 1988 Kim Moser All Rights Reserved\n" ); printf( " Converts text files between CBM and IBM format\n\n" ); printf( " Usage:\n" ); printf( " CBM2IBM -c | -i\n\n" ); printf( " Options:\n" ); printf( " -c = stdin assumed to be in CBM format (CR becomes CR/LF)\n" ); printf( " -i = stdin assumed to be in IBM format (CR/LF becomes CR)\n" ); } void main(argc,argv) int argc; char *argv[]; { register int ch; /* Must be signed so that EOF (probably -1) can be represented */ switch ( toupper(argv[1][1]) ) { /* Should be '-i' or '-c' */ case 'I': /* IBM -> CBM */ while ( (ch=getchar()) != EOF ) { if ( ch == '\n' ) /* CBM expects just CR for new line */ ch = CR; else if ( (ch>64) && (ch<91) ) ch += 128; else if ( (ch>96) && (ch<123) ) ch -= 32; putchar(ch); } break; case 'C': /* CBM -> IBM */ setmode( fileno(stdin), O_BINARY ); /* So that input stream is not prefiltered */ while ( (ch=getchar()) != EOF ) { if ( (ch>64) && (ch<91) ) ch += 32; else if ( (ch>192) && (ch<219) ) ch -= 128; if (ch != LF) { /* Ignore lone linefeeds */ if (ch == CR) /* CR -> CR/LF */ ch = '\n'; putchar(ch); } } break; default: /* Missing or invalid command line param(s) */ usage(); if (argc == 2) printf( "\nInvalid command line switch: '%s'\n", argv[1] ); exit(1); } }