1 /* Convert Color Computer 32 column screens to terminated lines.
\r// Written by Joel Rees, Takino, Hyogo, Japan, May 1997.
\r// Assigned to the public domain.
\r// Since it is in the public domain, it can't be copyrighted.
\r// If you borrow this code directly,
\r// please note the source and the fact that it is public domain in your source code comments.
\r//
\r// Current e-mail (January 2000): joel_rees@sannet.ne.jp, reiisi@nettaxi.com
\r*/
\r\r#include <stdio.h>
\r#include <stdlib.h> /* for EXIT_SUCCESS */
\r#include <ctype.h>
\r/* It's Mac, yess! */
\r#include <console.h>
\r\r\rconst int ScreenWidth = 32;
\rconst int ScreenHeight = 32;
\rconst int BufferWidth = ScreenWidth + 1; /* room for NUL */
\r\r\r\r\rint main(int argc, char * argv[] )
\r{
\r char buffer[ ScreenHeight ][ BufferWidth ];
\r FILE * input = stdin;
\r\r /* Use the pseudo-command-line as simple file interface */
\r argc = ccommand( &argv );
\r if ( argc > 1 )
\r { input = fopen( argv[ 1 ], "rb" );
\r if ( input == NULL )
\r { return EXIT_FAILURE;
\r }
\r }
\r\r while ( !feof( input ) )
\r { int lineCount;
\r for ( lineCount = 0; lineCount < ScreenHeight && !feof( input ); ++lineCount )
\r { int length = fread( buffer[ lineCount ], sizeof (char), ScreenWidth, input );
\r while ( --length >= 0
\r && ( isspace( buffer[ lineCount ][ length ] )
\r || !isprint( buffer[ lineCount ][ length ] ) ) )
\r /* "empty" loop */;
\r buffer[ lineCount ][ ++length ] = '\0';
\r }
\r if ( lineCount > 1
\r || ( lineCount == 1 && buffer[ 0 ][ 0 ] != '\0' ) )
\r { while ( --lineCount > 0 && buffer[ lineCount ][ 0 ] == '\0' )
\r /* "empty" loop */;
\r for ( int line = 0; line <= lineCount; ++line )
\r puts( buffer[ line ] );
\r putchar( '\f' );
\r }
\r }
\r\r return EXIT_SUCCESS;
\r}
\r\r