arg_list_t *key(arg_list_t *args) { arg_list_t *code, *mod, *event, *cmd; code = symbol(); mod = symbol(); event = symbol(); cmd = symbol(); arg_enforce_type(&code, INT); //arg_enforce_type(&mod, INT); // Call event func here - simulated with printf in tests if (code && mod && event && cmd) { printf("extern \"C\" { key(%i, %s, %s, %s); }\n", get_int(code), get_string(mod), get_string(event), get_string(cmd)); } else { printf("key> Failed to extract strict typed data from script\n"); } delete_arg(&code); delete_arg(&mod); delete_arg(&event); delete_arg(&cmd); return NULL; }
void Resource::Bind(arg_list_t *symbol, arg_list_t *data) { if (!symbol || !data || (symbol->type != CSTRING) || !symbol->data || !((char *)symbol->data)[0]) { Error("BIND receieved invalid symbol"); delete_arg(&symbol); delete_arg(&data); return; } // Mongoose 2002.01.12, String fix for overflow unsigned int len = strlen((char *)symbol->data); data->symbol = new char[len + 4]; strncpy(data->symbol, (char *)symbol->data, len); data->symbol[len] = 0; delete_arg(&symbol); if (!_sym_tab) { _sym_tab = data; } else { arg_list_t* sym_tab = _sym_tab; while (sym_tab->next) { sym_tab = sym_tab->next; } sym_tab->next = data; } }
arg_list_t *color(arg_list_t *args) { arg_list_t *sym = symbol(); arg_list_t *r = symbol(); arg_list_t *g = symbol(); arg_list_t *b = symbol(); arg_enforce_type(&r, FLOAT); arg_enforce_type(&g, FLOAT); arg_enforce_type(&b, FLOAT); // Call event func here - simulated with printf in tests if (sym && r && g && b) { printf("extern \"C\" { color(%s, %f, %f, %f); }\n", get_string(sym), get_float(r), get_float(g), get_float(b)); } else { printf("color> Failed to extract strict typed data from script\n"); } delete_arg(&sym); delete_arg(&r); delete_arg(&g); delete_arg(&b); return NULL; }
void Resource::Flush() { arg_list_t *a; while (_stack) { arg_pop(&_stack); } while (_sym_tab) { a = _sym_tab; _sym_tab = _sym_tab->next; delete_arg(&a); } if (_buffer) { delete [] _buffer; } if (_symbol) { delete [] _symbol; } }
void arg_enforce_type(arg_list_t **a, int type) { if (!(*a)) return; if (type & (*a)->type) return; printf("ERROR: Type mismatch expected '%s', not '%s'\n", (type & INT) ? "int" : (type & FLOAT) ? "float" : (type & FUNC) ? "func" : (type & CSTRING) ? "string" : "adt", ((*a)->type & INT) ? "int" : ((*a)->type & FLOAT) ? "float" : ((*a)->type & FUNC) ? "func" : ((*a)->type & CSTRING) ? "string" : "adt"); if ((*a)->type == CSTRING) { printf("ERROR: string was '%s'\n", (char*)((*a)->data)); } delete_arg(a); }
void arg_enforce_type_assert(arg_list_t **a, int type) { if (!(*a)) return; if (type & (*a)->type) return; MGTK_ASSERTMSG(false, "MLISP %s:%i\n\tType mismatch expected '%s', not '%s'\n\t(%s)\n", mlisp_get_filename(), mlisp_get_line_num(), ((type & INT) ? "int" : (type & FLOAT) ? "float" : (type & FUNC) ? "func" : (type & CSTRING) ? "string" : "adt"), (((*a)->type & INT) ? "int" : ((*a)->type & FLOAT) ? "float" : ((*a)->type & FUNC) ? "func" : ((*a)->type & CSTRING) ? "string" : "adt"), ((*a)->type == CSTRING) ? (char*)((*a)->data) : "?" ); delete_arg(a); }
/** * Recognized arguments are removed from @a argv. The updated array * length is returned in @a argc. */ static void process_args(int *argc, char *argv[], unsigned *force_samples, struct piglit_gl_test_config *config) { int j; piglit_binary_name = argv[0]; piglit_parse_subtest_args(argc, argv, config->subtests, &config->selected_subtests, &config->num_selected_subtests); /* Find/remove "-auto" and "-fbo" from the argument vector. */ for (j = 1; j < *argc; j++) { if (!strcmp(argv[j], "-auto")) { piglit_automatic = 1; delete_arg(argv, *argc, j--); *argc -= 1; } else if (!strcmp(argv[j], "-fbo")) { piglit_use_fbo = true; delete_arg(argv, *argc, j--); *argc -= 1; } else if (!strcmp(argv[j], "-png")) { piglit_dump_png = true; delete_arg(argv, *argc, j--); *argc -= 1; } else if (!strcmp(argv[j], "-rlimit")) { char *ptr; unsigned long lim; int i; j++; if (j >= *argc) { fprintf(stderr, "-rlimit requires an argument\n"); piglit_report_result(PIGLIT_FAIL); } lim = strtoul(argv[j], &ptr, 0); if (ptr == argv[j]) { fprintf(stderr, "-rlimit requires an argument\n"); piglit_report_result(PIGLIT_FAIL); } piglit_set_rlimit(lim); /* Remove 2 arguments (hence the 'i - 2') from the * command line. */ for (i = j + 1; i < *argc; i++) { argv[i - 2] = argv[i]; } *argc -= 2; j -= 2; } else if (!strncmp(argv[j], "-samples=", 9)) { *force_samples = atoi(argv[j]+9); delete_arg(argv, *argc, j--); *argc -= 1; } else if (!strcmp(argv[j], "-khr_no_error")) { piglit_khr_no_error = true; delete_arg(argv, *argc, j--); *argc -= 1; if (config->khr_no_error_support == PIGLIT_UNKNOWN_ERROR_STATUS) { fprintf(stderr, "khr_no_error_support unknown " "skipping test!\n"); piglit_report_result(PIGLIT_SKIP); } else if (config->khr_no_error_support == PIGLIT_HAS_ERRORS) { piglit_report_result(PIGLIT_SKIP); } else { assert(config->khr_no_error_support == PIGLIT_NO_ERRORS); } } } }
void rewrite_command_line (char *override_options_line, int *argc, char ***argv){ int line_pos = 0; read_args (*argc, *argv); if (override_options_line[0] == '#') { confirm_changes = 0; line_pos++; } if (confirm_changes) fprintf (stderr, "### QA_OVERRIDE_GCC3_OPTIONS: %s\n", override_options_line); /* Loop through all commands in the file */ while (override_options_line[line_pos] != '\0') { char first_char; char *searchStr; char *arg; int search_index; int arg_len; /* Any spaces in between options don't count. */ if (override_options_line[line_pos] == ' ') { line_pos++; continue; } /* The first non-space character is the command. */ first_char = override_options_line[line_pos]; line_pos++; arg_len = strcspn(override_options_line+line_pos, " "); switch (first_char) { case '+': /* Add an argument to the end of the arg list */ arg = arg_string (override_options_line, line_pos, arg_len); append_arg (arg); free (arg); break; case 'x': /* Delete a matching argument */ searchStr = arg_string(override_options_line, line_pos, arg_len); if ((search_index = find_arg(searchStr)) != -1) { delete_arg(search_index); } free (searchStr); break; case 'X': /* Delete a matching argument and the argument following. */ searchStr = arg_string(override_options_line, line_pos, arg_len); if ((search_index = find_arg(searchStr)) != -1) { if (search_index >= arg_count -1) { if (confirm_changes) fprintf(stderr,"Not enough arguments to do X\n"); } else { delete_arg(search_index); /* Delete the matching argument */ delete_arg(search_index); /* Delete the following argument */ } } free (searchStr); break; case 'O': /* Change the optimization level to the specified value, and remove any optimization arguments. This is a separate command because we often want is to substitute our favorite optimization level for whatever the project normally wants. As we probably care about this a lot (for things like testing file sizes at different optimization levels) we make a special rewrite clause. */ arg = arg_string (override_options_line, line_pos, arg_len); replace_optimization_level(arg); free (arg); break; case 's': /* Search for the regexp passed in, and replace a matching argument with the provided replacement string */ searchStr = arg_string (override_options_line, line_pos, arg_len); search_and_replace (searchStr); free (searchStr); break; default: fprintf(stderr,"### QA_OVERRIDE_GCC3_OPTIONS: invalid string (pos %d)\n", line_pos); break; } line_pos += arg_len; } *argc = arg_count; *argv = arg_array; }
arg_list_t *Resource::Function(arg_list_t *arg) { arg_list_t *sym_tab; arg_list_t *ret; arg_list_t *func; arg_list_t *(*call)(arg_list_t *); Match('('); func = Symbol(); sym_tab = _sym_tab; ret = NULL; // FIXME: This causes bad things with MULT_EVAL while (sym_tab) { if (sym_tab->type == FUNC && strcmp(_symbol, sym_tab->symbol) == 0) { if (sym_tab->data) { call = (arg_list_t * (*)(arg_list_t *))sym_tab->data; ret = (*call)(arg); break; } } sym_tab = sym_tab->next; } //arg_enforce_type(&sym_tab, FUNC); if (!sym_tab || (sym_tab && sym_tab->type != FUNC)) { Error("Invalid function call"); if (sym_tab && sym_tab->symbol) { printf("Probable unbound function '%s'\n", sym_tab->symbol); } else if (func && func->type == CSTRING && func->data && ((char *)func->data)[0]) { printf("Probable unbound function '%s'\n", (char *)func->data); } } //Mongoose 2001.11.09: For 'empty space' or '(func (func' use Seperator(); // Mongoose 2001.11.09: Best handle for? grouped (func (func while (Is('(')) { //arg_push(&_stack, arg); //arg_peek(&_stack)); Function(ret); //ret = arg_pop(&_stack); #ifdef DEBUG_RESOURCE_EXE printf("Function executed on Line %i\n", _line); #endif Seperator(); } delete_arg(&func); Match(')'); return ret; }
int Resource::Eval(char *buffer) { arg_list_t *a, *b, *c; if (!buffer || !buffer[0]) { return -1; } // Mongoose: Start counting lines at 1, errors at 0 _line = 1; _error = 0; #ifdef MULTI_EVAL _top = 0; _string = 0; while (_stack) { arg_pop(&_stack); } _stack = NULL; #endif Lex(); Seperator(); while (Is('#')) { printf("Resource::Eval> Preprocessor not implemented yet.\n"); Lex(); a = Symbol(); Seperator(); b = Symbol(); Seperator(); c = Symbol(); Seperator(); // #func arg1 arg2 ( eg #define FOOBAR 1 ) // Preprocessor function delete_arg(&a); // Arg 1 delete_arg(&b); // Arg 2 delete_arg(&c); } a = NULL; while (Is('(')) { // FIXME: Handle scope with paren counter and appending to list a a = Function(a); Seperator(); } if (_error) printf("\n\nEval> Encountered %i Errors\n\n", _error); return 0; }
int main(int argc, char *argv[]) { int j; /* Find/remove "-auto" and "-fbo" from the argument vector. */ for (j = 1; j < argc; j++) { if (!strcmp(argv[j], "-auto")) { piglit_automatic = 1; delete_arg(argv, argc--, j--); } else if (!strcmp(argv[j], "-fbo")) { piglit_use_fbo = true; delete_arg(argv, argc--, j--); } else if (!strcmp(argv[j], "-rlimit")) { char *ptr; unsigned long lim; int i; j++; if (j >= argc) { fprintf(stderr, "-rlimit requires an argument\n"); piglit_report_result(PIGLIT_FAIL); } lim = strtoul(argv[j], &ptr, 0); if (ptr == argv[j]) { fprintf(stderr, "-rlimit requires an argument\n"); piglit_report_result(PIGLIT_FAIL); } piglit_set_rlimit(lim); /* Remove 2 arguments (hence the 'i - 2') from the * command line. */ for (i = j + 1; i < argc; i++) { argv[i - 2] = argv[i]; } argc -= 2; j -= 2; } } if (piglit_use_fbo) { if (!piglit_framework_fbo_init()) piglit_use_fbo = false; } if (!piglit_use_fbo) piglit_framework_glut_init(argc, argv); piglit_init(argc, argv); if (piglit_use_fbo) { result = piglit_display(); piglit_framework_fbo_destroy(); } else { glutMainLoop(); } piglit_report_result(result); /* UNREACHED */ return 0; }