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] ); }
int main( int argc, char **argv ) /*******************************/ { if( argc == 1 ) { error( "usage: findhash [-a] [-q] [-i] [-m] [-t] [-e \"text\"] [-s \"name suffix\"] <keyword_file> ..." ); error( "-a: output aligned strings" ); error( "-e \"text\": pick macro extension text" ); error( "-i: allow imperfect hash functions" ); error( "-m: force 2^n mask hash function" ); error( "-q: quiet mode" ); error( "-s \"suffix\": file name suffix" ); error( "-t: tiny mode: generate tiny.gh" ); fatal( "" ); } init_tokens( &argv[1] ); first_scale = 1; last_scale = 1; if( !hash_search() ) { first_scale = 2; if( !hash_search() ) { first_scale = 1; last_scale = 2; if( !hash_search() ) { fatal( "cannot find a hash function" ); } } } return( EXIT_SUCCESS ); }
/** * @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; }
/** * @brief Parses GTP input command into list of tokens. * * The string containing a GTP input command is taken and split into a list of * tokens. The input must go through drop_comment() and trim() before this * function is called! * * @param[in] command_input_buffer GTP input string * @param[out] tokens Array of strings * @return nothing * @note The last token is set to '\\0' to mark the end of the * arguments later on. */ void parse_gtp_input( char * command_input_buffer, char tokens[][MAX_TOKEN_LENGTH] ) { char current_char = '\0'; int i = 0; // Index of input buffer int j = 0; // Counts number of tokens int k = 0; // Index of each token // Get tokens from input: for ( i = 0; i < SIZE_INPUT_BUFFER; i++ ) { current_char = command_input_buffer[i]; if ( ! isspace(current_char) && current_char != '\0' ) { if ( k < MAX_TOKEN_LENGTH ) { tokens[j][k] = current_char; k++; } else { set_output_error(); add_output( "MAX_TOKEN_LENGTH exceeded" ); init_tokens(tokens); return; } } else { tokens[j][k] = '\0'; j++; k = 0; if ( j >= MAX_TOKEN_COUNT ) { set_output_error(); add_output( "MAX_TOKEN_COUNT exceeded" ); init_tokens(tokens); return; } // Set terminating argument: tokens[j][0] = '\0'; } if ( current_char == '\0' ) { break; } } return; }
/* * ---------------------------------------------------------------------- * print_audit_common() - common routine for print_audit* functions. * * Parses the binary audit data, and formats as requested. * The context parameter defines whether the source of the * audit data is a buffer, or a file mapped to stdin, and * whether the output is to a buffer or a file mapped to * stdout. * * inputs: * context - defines the context of the request, including * info about the source and output. * flags - formatting flags as defined in praudit.h * separator - field delimiter (or NULL if the default * delimiter of comma is to be used). * * return codes: -1 - error * 0 - successful * ---------------------------------------------------------------------- */ static int print_audit_common(pr_context_t *context, const int flags, const char *separator) { int retstat = 0; if (!initdone) { init_tokens(); initdone++; } context->format = flags; /* start with default delimiter of comma */ (void) strlcpy(context->SEPARATOR, ",", SEP_SIZE); if (separator != NULL) { if (strlen(separator) < SEP_SIZE) { (void) strlcpy(context->SEPARATOR, separator, SEP_SIZE); } } while ((retstat == 0) && pr_input_remaining(context, 1)) { if (pr_adr_char(context, (char *)&(context->tokenid), 1) == 0) { retstat = token_processing(context); } else break; } /* * For buffer processing, if the entire input buffer was processed * successfully, but the last record in the buffer was incomplete * (according to the length from its header), then reflect an * "incomplete input" error (which will cause partial results to be * returned). */ if ((context->data_mode == BUFMODE) && (retstat == 0) && (context->audit_adr->adr_now < (context->audit_rec_start + context->audit_rec_len))) { retstat = -1; errno = EIO; } /* * If there was a last record that didn't get officially closed * off, do it now. */ if ((retstat == 0) && (context->format & PRF_XMLM) && (context->current_rec)) { retstat = do_newline(context, 1); if (retstat == 0) retstat = close_tag(context, context->current_rec); } return (retstat); }
void Parser_scan_tokens(Parser *parser, const Token *tokens, const size_t token_count) { clear_data(parser); init_tokens(parser, tokens, token_count); init_groups(parser); init_ranges(parser); }
int broker_sys_node_populate(BrokerNode *sysNode) { if (!sysNode) { return 1; } broker_query_create_action(sysNode); init_tokens(sysNode); init_restart(sysNode); init_sys_upstream_node(sysNode); init_sys_static(sysNode); init_clear_conns(sysNode); init_update_permissions_action(sysNode); init_throughput(sysNode); return 0; }
int main(int ac, char **av, char **env) { t_cmd cmd; t_dict *envc; (void)ac; (void)av; signal(SIGINT, sig_handler); envc = envcpy(env); init_tokens(); interpret_command(envc, &cmd); dict_destroy(g_tokens); dict_destroy(envc); cmd_free(&cmd); return (0); }
int main(int ac, char **av, char **env) { t_cmd cmd; t_dict *dicts[DICT_COUNT]; (void)ac; (void)av; init_tokens(&dicts[TOKENS]); init_binaries(&dicts[BIN]); dicts[ENV] = envcpy(env); signals(); interpret_command(dicts, &cmd); destroy_array_dict(dicts, DICT_COUNT); cmd_free(&cmd); return (0); }
END_TEST START_TEST (test_init_tokens_1) { int ok = 1; int i; char tokens[MAX_TOKEN_COUNT][MAX_TOKEN_LENGTH]; init_tokens(tokens); for ( i = 0; i < MAX_TOKEN_COUNT; i++ ) { if ( tokens[i][0] != '\0' ) { ok = 0; break; } } fail_unless( ok == 1, "tokens all null" ); }
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] ); }
int main() { uint32_t w; init_tokens(); printf("\nNo truncate, height = %"PRIu32", width = %"PRIu32"\n", display.height, display.width); init_pp(&pp, &converter, stdout, &display, PP_HMODE, 0); test1(&pp); test2(&pp); test3(&pp); test4(&pp); delete_pp(&pp); display.truncate = true; for (w = 20; w<50; w++) { display.width = w; printf("\n\nTruncate, height = %"PRIu32", width = %"PRIu32"\n", display.height, display.width); init_pp(&pp, &converter, stdout, &display, PP_HMODE, 0); test1(&pp); test2(&pp); test3(&pp); test4(&pp); delete_pp(&pp); } // tests with height = 4 // initial mode = PP_VMODE display.height = 4; display.width = 20; display.truncate = false; printf("\nNo truncate, height = %"PRIu32", width = %"PRIu32"\n", display.height, display.width); init_pp(&pp, &converter, stdout, &display, PP_VMODE, 0); test1(&pp); test2(&pp); test3(&pp); test4(&pp); delete_pp(&pp); display.truncate = true; for (w = 4; w<50; w++) { display.width = w; printf("\n\nTruncate, height = %"PRIu32", width = %"PRIu32"\n", display.height, display.width); init_pp(&pp, &converter, stdout, &display, PP_VMODE, 0); test1(&pp); test2(&pp); test3(&pp); test4(&pp); delete_pp(&pp); } display.truncate = false; for (w = 4; w<50; w++) { display.width = w; printf("\n\nNo truncate, height = %"PRIu32", width = %"PRIu32"\n", display.height, display.width); init_pp(&pp, &converter, stdout, &display, PP_VMODE, 0); test1(&pp); test2(&pp); test3(&pp); test4(&pp); delete_pp(&pp); } return 0; }