int8_t parse_command( uint8_t *pszCommandString, tUserState *pState ) { uint32_t i; int32_t index; int8_t iRetVal = -1; // Find command! for ( i = 0; ; i++ ) { if ( g_cmdTable[i].pCmdHandler == NULL ) break; if ( (index = stringbeg( pszCommandString, g_cmdTable[i].szCommand )) > 0 ) { if ( (g_cmdTable[i].flags & CMD_FLAG_AUTH) && pState->state == USER_STATE_NOAUTH ) { printf( "Authentication required. Try login\n" ); return -1; } // Call cmd fptr return (*g_cmdTable[i].pCmdHandler)( pszCommandString+index, pState ); } } printf( "Command not found.\n" ); return -1; }
uint stringmatch(char *s,char a[][20],uint n) /* Check string s against n options in string array a If matches ith element return i+1 else return 0 */ { uint i=0; while(i<n) { if(stringbeg(s,a[i])) return i+1; i++; } return 0; }
planetnum matchsys(char *s) /* Return id of the planet whose name matches passed strinmg closest to currentplanet - if none return currentplanet */ { planetnum syscount; planetnum p=currentplanet; uint d=9999; for(syscount=0;syscount<galsize;++syscount) { if (stringbeg(s,galaxy[syscount].name)) { if (distance(galaxy[syscount],galaxy[currentplanet])<d) { d=distance(galaxy[syscount],galaxy[currentplanet]); p=syscount; } } } return p; }