/** * @brief Read GTP command from STDIN. * * Reads a GTP command from STDIN. Input which is larger than * SIZE_INPUT_BUFFER is simply ignored. The behaviour \e should be the same as * with "gnugo --mode gtp". * * @param[in] *command_data Pointer to struct command * @return nothing * @sa <a href=@link3>GTP version 2.0</a> */ void read_gtp_input( struct command *command_data ) { int c = '\n'; int i = 0; char tokens[MAX_TOKEN_COUNT][MAX_TOKEN_LENGTH]; init_tokens(tokens); input_empty = false; output_error = false; do { c = getchar(); command_input_buffer[i] = (char) c; i++; } while ( c != '\n' && i < SIZE_INPUT_BUFFER ); // Overwrite last char with newline command_input_buffer[i-1] = '\0'; drop_comment(command_input_buffer); trim(command_input_buffer); if ( strlen(command_input_buffer) == 0 ) { input_empty = true; return; } parse_gtp_input( command_input_buffer, tokens ); identify_tokens( tokens, command_data ); return; }
END_TEST START_TEST (test_identify_tokens_8) { char tokens[MAX_TOKEN_COUNT][MAX_TOKEN_LENGTH]; struct command command_data; init_tokens(tokens); strcpy( tokens[0], "0" ); strcpy( tokens[1], "version" ); strcpy( tokens[2], "arg1" ); strcpy( tokens[3], "arg2" ); strcpy( tokens[4], "arg3" ); identify_tokens( tokens, &command_data ); fail_unless( command_data.id == 0, "id is 0 (%d)", command_data.id ); fail_unless( strcmp( command_data.name, "version" ) == 0 , "name is version (%s)", command_data.name ); fail_unless( command_data.gtp_argc == 3, "three arguments" ); fail_unless( strcmp( command_data.gtp_argv[0], "arg1" ) == 0 , "arg1 is arg1 (%s)", command_data.gtp_argv[0] ); fail_unless( strcmp( command_data.gtp_argv[1], "arg2" ) == 0 , "arg2 is arg2 (%s)", command_data.gtp_argv[1] ); fail_unless( strcmp( command_data.gtp_argv[2], "arg3" ) == 0 , "arg3 is arg3 (%s)", command_data.gtp_argv[2] ); }
/*-------------------------------------------------------------------------*/ void AzTools_text::tokenize(AzByte *buff, int &len, const AzDic *dic, int nn, bool do_lower, bool do_utf8dashes, /*--- output ---*/ AzIntArr *ia_tokno) { const char *eyec = "AzTools_text::tokenize"; AzStrPool sp_tok; tokenize(buff, len, do_utf8dashes, do_lower, &sp_tok); int t_num = sp_tok.size(); if (dic != NULL && ia_tokno != NULL) { identify_tokens(&sp_tok, nn, dic, ia_tokno); if (ia_tokno->size() != t_num) throw new AzException(eyec, "Conflict in uni #tokens"); } }
/*-------------------------------------------------------------------------*/ void AzTools_text::tokenize(AzByte *buff, int &len, const AzDic *dic, AzIntArr &ia_nn, bool do_lower, bool do_utf8dashes, /*--- output ---*/ AzDataArr<AzIntArr> &aia_tokno) { const char *eyec = "AzTools_text::tokenize(multi n)"; AzStrPool sp_tok; tokenize(buff, len, do_utf8dashes, do_lower, &sp_tok); int t_num = sp_tok.size(); aia_tokno.reset(ia_nn.size()); for (int ix = 0; ix < ia_nn.size(); ++ix) { identify_tokens(&sp_tok, ia_nn[ix], dic, aia_tokno(ix)); if (aia_tokno[ix]->size() != t_num) throw new AzException(eyec, "Conflict in #tokens"); } }
END_TEST START_TEST (test_identify_tokens_2) { char tokens[MAX_TOKEN_COUNT][MAX_TOKEN_LENGTH]; struct command command_data; init_tokens(tokens); strcpy( tokens[0], "version" ); identify_tokens( tokens, &command_data ); fail_unless( command_data.id == -1, "id is -1 (%d)", command_data.id ); fail_unless( strcmp( command_data.name, "version" ) == 0 , "name is version (%s)", command_data.name ); fail_unless( command_data.gtp_argc == 0, "no arguments" ); }
END_TEST START_TEST (test_identify_tokens_3) { char tokens[MAX_TOKEN_COUNT][MAX_TOKEN_LENGTH]; struct command command_data; init_tokens(tokens); strcpy( tokens[0], "1" ); strcpy( tokens[1], "version" ); strcpy( tokens[2], "arg1" ); identify_tokens( tokens, &command_data ); fail_unless( command_data.id == 1, "id is 1 (%d)", command_data.id ); fail_unless( strcmp( command_data.name, "version" ) == 0 , "name is version (%s)", command_data.name ); fail_unless( command_data.gtp_argc == 1, "one argument" ); fail_unless( strcmp( command_data.gtp_argv[0], "arg1" ) == 0 , "arg1 is arg1 (%s)", command_data.gtp_argv[0] ); }