home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-18 | 2.6 KB | 104 lines | [TEXT/CWIE] |
- #include "Solution.h"
-
- #include "ProblemUtils.h"
-
- #include <stdio.h>
- #include <string.h>
- #include <Files.h>
- #include <Errors.h>
-
- Handle indata;
- Boolean realcorrect;
-
- static pascal UInt32 GetNextChar( Handle state_machine, UInt32 curstate )
- {
- char line[MAX_LINE_LEN];
- char *linep;
- UInt32 thechar;
-
- linep = line;
- if ( !realcorrect || !ProblemReadLineFromHandle( indata, line, MAX_LINE_LEN )
- || !ProblemGetUInt32( &linep, &thechar ) ) {
- realcorrect = false;
- return 0;
- }
- return thechar;
- }
-
- pascal OSErr CheckStateMachine( const FSSpec* infile, const FSSpec* outfile, Boolean *correct )
- {
- OSErr err;
- char line[MAX_LINE_LEN];
- char *linep;
- char command[MAX_LINE_LEN];
- UInt32 state_count;
- UInt32 char_count;
- UInt32 from,to,start,fin;
- UInt32 stop_state;
- Handle state_machine;
-
- realcorrect = false;
-
- err = ProblemFileRead( infile, &indata );
- ProblemLogError( err, "CheckStateMachine: ProblemFileRead" );
- if ( err == noErr ) {
- linep = line;
- if ( !ProblemReadLineFromHandle( indata, line, MAX_LINE_LEN )
- || !ProblemGetUInt32( &linep, &state_count )
- || !ProblemGetUInt32( &linep, &char_count ) ) {
- err = -1;
- ProblemLogError( err, "CheckStateMachine: state_count,char_count" );
- }
- }
- if ( err == noErr ) {
- StateMachineInit( &state_machine, state_count, char_count );
-
- realcorrect = true;
- while ( (err == noErr) && realcorrect && ProblemReadLineFromHandle( indata, line, MAX_LINE_LEN ) ) {
- linep = line;
- ProblemGetCString( &linep, command, MAX_LINE_LEN );
- if ( strcmp( command, "ADD" ) == 0 ) {
- if ( ProblemGetUInt32( &linep, &from )
- && ProblemGetUInt32( &linep, &to )
- && ProblemGetUInt32( &linep, &start )
- && ProblemGetUInt32( &linep, &fin ) ) {
- AddTransition( state_machine, from, to, start, fin );
- } else {
- err = -1;
- ProblemLogError( err, "CheckStateMachine: ADD?" );
- }
- } else if ( strcmp( command, "RUN" ) == 0 ) {
- ProblemGetUInt32( &linep, &start );
- RunStateMachine( state_machine, start, GetNextChar, &stop_state );
- linep = line;
- realcorrect = false;
- if ( ProblemReadLineFromHandle( indata, line, MAX_LINE_LEN ) ) {
- ProblemGetCString( &linep, command, MAX_LINE_LEN );
- if ( strcmp( command, "STOP" ) == 0 ) {
- if ( ProblemGetUInt32( &linep, &fin ) && (fin == stop_state) ) {
- realcorrect = true;
- }
- }
- }
- } else {
- err = -2;
- ProblemLogError( err, "CheckStateMachine: What?" );
- }
- if ( err != noErr ) break;
- }
-
- DisposeHandle( state_machine );
- }
- *correct = realcorrect;
- return err;
- }
-
- int main()
- {
- printf( "Starting\n" );
-
- ProblemRunSingleFileTests( CheckStateMachine );
-
- return 0;
- }
-