/* ECP: FILEname=fig9_23.c */ /* 1*/ #include /* 2*/ void Help( void ); /* 3*/ void Quit( void ); /* 4*/ void Reset( void ); /* 5*/ void Undo( void ); /* 6*/ typedef struct /* 7*/ { /* 8*/ char *Command; /* 9*/ void ( *Func )( void ); /*10*/ } CommStruct; /*11*/ static const CommStruct TheCommands[ ] = /*12*/ { /*13*/ "exit", Quit, /*14*/ "help", Help, /*15*/ "quit", Quit, /*16*/ "reset", Reset, /*17*/ "undo", Undo, /*18*/ NULL, NULL /* Place Last; No Match */ /*19*/ }; /*20*/ void /*21*/ DoCommand( const char *Comm ) /*22*/ { /*23*/ const CommStruct *Ptr; /*24*/ for( Ptr = TheCommands; Ptr->Command != NULL; Ptr++ ) /*25*/ if( strcmp( Comm, Ptr->Command ) == 0 ) /*26*/ { /*27*/ ( *Ptr->Func )( ); /*28*/ return; /*29*/ } /*30*/ printf( "Error: unrecognized command\n" ); /*31*/ }