/* import.c -- from McKay's format to the book format */ #include #include #include "ios.h" #define ERR_LINE_LONG 1 #define ERR_LINE_SHORT 2 #define ERR_LINE_END 3 #define LINE_SIZE 80 static char Line_buffer [ LINE_SIZE + 3 ]; static int input_lines_count; void main ( int argc, char * argv [] ) { int n; char c; FILE * infile; FILE * outfile; if ( argc < 3 ) err_command_line ( "import infile outfile" ); infile = open_input_file ( argv [1] ); outfile = open_output_file ( argv [2] ); input_lines_count = 0; while ( NULL != fgets ( Line_buffer, LINE_SIZE+3, infile ) ) { ++ input_lines_count; for ( n=0; n= LINE_SIZE+3 ) { printf ( "input line no. %d is too long (>%d)\n", input_lines_count, LINE_SIZE ); exit ( ERR_LINE_LONG ); } if ( n < 7 ) { printf ( "input line no. %d is too short (<7)\n", input_lines_count ); exit ( ERR_LINE_SHORT ); } c = Line_buffer [ --n ]; if ( (c==10) || (c==13) ) { c = Line_buffer [ --n ]; if ( (c==10) || (c==13) ) --n; } if ( n >= LINE_SIZE ) { printf ( "input line %d is too long (>%d)\n", input_lines_count, LINE_SIZE ); exit ( ERR_LINE_LONG ); } while ( ++n < LINE_SIZE ) Line_buffer [n] = 32; fprintf ( outfile, "[" ); while ( --n >= 2 ) fprintf ( outfile, "%c", Line_buffer [n] ); fprintf ( outfile, "]\n" ); } exit (0); } /* end of import.c */