void SessionRep::extract( const String& arg, const OptionDesc& o, int& i, int argc, char** argv, String& name, String& value ) { int colon; switch (o.style) { case OptionPropertyNext: value = next_arg(i, argc, argv, "missing property after '%s'", arg); colon = value.index(':'); if (colon < 0) { bad_arg("missing ':' in '%s'", value); } else { name = value.left(colon); value = value.right(colon+1); } break; case OptionValueNext: name = o.path; value = next_arg(i, argc, argv, "missing value after '%s'", arg); break; case OptionValueImplicit: name = o.path; value = o.value; break; case OptionValueIsArg: name = o.path; value = arg; break; case OptionValueAfter: bad_arg("missing value in '%s'", arg); break; } }
SEXP check_grouped(RObject data) { static SEXP groups_symbol = Rf_install("groups"); static SEXP vars_symbol = Rf_install("vars"); // compat with old style grouped data frames SEXP vars = Rf_getAttrib(data, vars_symbol); if (!Rf_isNull(vars)) { DataFrame groups = build_index_cpp(data, SymbolVector(vars)); data.attr("groups") = groups; } // get the groups attribute and check for consistency SEXP groups = Rf_getAttrib(data, groups_symbol); // groups must be a data frame if (!is<DataFrame>(groups)) { bad_arg(".data", "is a corrupt grouped_df, the `\"groups\"` attribute must be a data frame"); } // it must have at least 1 column int nc = Rf_length(groups); if (nc <= 1) { bad_arg(".data", "is a corrupt grouped_df, the `\"groups\"` attribute must have at least two columns"); } // the last column must be a list and called `.rows` SEXP names = Rf_getAttrib(groups, R_NamesSymbol); SEXP last = VECTOR_ELT(groups, nc - 1); static String rows = ".rows"; if (TYPEOF(last) != VECSXP || STRING_ELT(names, nc - 1) != rows) { bad_arg(".data", "is a corrupt grouped_df, the `\"groups\"` attribute must have a list column named `.rows` as last column"); } return data ; }
void f_socket_write (void) { int i, fd, port; svalue_t *arg; char addr[ADDR_BUF_SIZE]; int num_arg = st_num_arg; arg = sp - num_arg + 1; if ((num_arg == 3) && (arg[2].type != T_STRING)) { bad_arg(3, F_SOCKET_WRITE); } fd = arg[0].u.number; get_socket_address(fd, addr, &port, 0); if (VALID_SOCKET("write")) { i = socket_write(fd, &arg[1], (num_arg == 3) ? arg[2].u.string : (char *) NULL); pop_n_elems(num_arg - 1); sp->u.number = i; } else { pop_n_elems(num_arg - 1); sp->u.number = EESECURITY; } }
int gpio_request(unsigned num, const char *label /* UNUSED */) { u32 tmplong; int i = 0, j = 0; /* Is the hardware ready? */ if (gpio_init()) return -1; if (bad_arg(num, &i, &j)) return -1; /* * Make sure that the GPIO pin we want isn't already in use for some * built-in hardware function. We have to check this for every * requested pin. */ tmplong = inl(gpiobase + gpio_bank[i].use_sel); if (!(tmplong & (1UL << j))) { debug("%s: gpio %d is reserved for internal use\n", __func__, num); return -1; } return mark_gpio(i, j); }
void f_socket_connect (void) { int i, fd, port; char addr[ADDR_BUF_SIZE]; if (!((sp - 1)->type & (T_FUNCTION | T_STRING))) { bad_arg(3, F_SOCKET_CONNECT); } if (!(sp->type & (T_FUNCTION | T_STRING))) { bad_arg(4, F_SOCKET_CONNECT); } fd = (sp - 3)->u.number; get_socket_address(fd, addr, &port, 0); if (!strcmp(addr, "0.0.0.0") && port == 0) { /* * socket descriptor is not bound yet */ char *s; int start = 0; addr[0] = '\0'; if ((s = strchr((sp - 2)->u.string, ' '))) { /* * use specified address and port */ i = s - (sp - 2)->u.string; if (i > ADDR_BUF_SIZE - 1) { start = i - ADDR_BUF_SIZE - 1; i = ADDR_BUF_SIZE - 1; } strncat(addr, (sp - 2)->u.string + start, i); port = atoi(s + 1); } #ifdef DEBUG } else { fprintf(stderr, "socket_connect: socket already bound to address/port: %s/%d\n", addr, port); fprintf(stderr, "socket_connect: requested on: %s\n", (sp - 2)->u.string); #endif } (sp-3)->u.number = VALID_SOCKET("connect") ? socket_connect(fd, (sp - 2)->u.string, sp - 1, sp) : EESECURITY; pop_3_elems(); }
void f_translate (void) { array_t *matrix; double x, y, z; Matrix current_matrix; Matrix trans_matrix; Matrix final_matrix; int i; if ((sp - 1)->type != T_REAL) { bad_arg(3, F_TRANSLATE); } if (sp->type != T_REAL) { bad_arg(4, F_TRANSLATE); } /* * get arguments from stack. */ matrix = (sp - 3)->u.arr; x = (sp - 2)->u.real; y = (sp - 1)->u.real; z = sp->u.real; sp -= 3; /* * convert vec matrix to float matrix. */ for (i = 0; i < 16; i++) { current_matrix[i] = matrix->item[i].u.real; } /* * create translation matrix. */ translate_matrix(x, y, z, trans_matrix); /* * compute transformed matrix. */ mult_matrix(current_matrix, trans_matrix, final_matrix); /* * convert float matrix to vec matrix. */ for (i = 0; i < 16; i++) { matrix->item[i].u.real = final_matrix[i]; } }
String SessionRep::next_arg( int& i, int argc, char** argv, const char* message, const String& arg ) { ++i; if (i == argc) { bad_arg(message, arg); } return String(argv[i]); }
void f_scale (void) { array_t *matrix; LPC_FLOAT x, y, z; Matrix current_matrix; Matrix scaling_matrix; Matrix final_matrix; int i; if ((sp - 1)->type != T_REAL) { bad_arg(3, F_SCALE); } if (sp->type != T_REAL) { bad_arg(4, F_SCALE); } /* * get arguments from stack. */ matrix = (sp - 3)->u.arr; x = (sp - 2)->u.real; y = (sp - 1)->u.real; z = sp->u.real; sp -= 3; /* * convert vec matrix to float matrix. */ for (i = 0; i < 16; i++) { current_matrix[i] = matrix->item[i].u.real; } /* * create scaling matrix. */ scale_matrix(x, y, z, scaling_matrix); /* * compute transformed matrix. */ mult_matrix(current_matrix, scaling_matrix, final_matrix); /* * convert float matrix to vec matrix. */ for (i = 0; i < 16; i++) { matrix->item[i].u.real = final_matrix[i]; } }
void Gui::setComp(string name, Component* component){ if(comps.find(name) != comps.end() && comps[name] == component) return; else if(comps.find(name) != comps.end()) throw bad_arg("Gui: Error, key already exists"); if(component->getName() != "") // Erase the old entry if it exists. removeComp(component->getName()); component->setName(name); comps.insert(pair<string, Component*>(name, component)); }
void f_socket_acquire (void) { int fd, port; char addr[ADDR_BUF_SIZE]; if (!((sp - 1)->type & (T_FUNCTION | T_STRING))) { bad_arg(3, F_SOCKET_ACQUIRE); } if (!(sp->type & (T_FUNCTION | T_STRING))) { bad_arg(4, F_SOCKET_ACQUIRE); } fd = (sp - 3)->u.number; get_socket_address(fd, addr, &port, 0); (sp-3)->u.number = VALID_SOCKET("acquire") ? socket_acquire((sp - 3)->u.number, (sp - 2), (sp - 1), sp) : EESECURITY; pop_3_elems(); }
void f_lookat_rotate (void) { array_t *matrix; double x, y, z; Matrix current_matrix; Matrix lookat_matrix; int i; if ((sp - 1)->type != T_REAL) { bad_arg(3, F_LOOKAT_ROTATE); } if (sp->type != T_REAL) { bad_arg(4, F_LOOKAT_ROTATE); } /* * get arguments from stack. */ matrix = (sp - 3)->u.arr; x = (sp - 2)->u.real; y = (sp - 1)->u.real; z = sp->u.real; sp -= 3; /* * convert vec matrix to float matrix. */ for (i = 0; i < 16; i++) { current_matrix[i] = matrix->item[i].u.real; } /* * create new viewing transformation matrix. */ lookat_rotate(current_matrix, x, y, z, lookat_matrix); /* * convert float matrix to vec matrix. */ for (i = 0; i < 16; i++) { matrix->item[i].u.real = lookat_matrix[i]; } }
void f_replace_program P2(int, num_arg, int, instruction) { replace_ob_t *tmp; int name_len; char *name, *xname; program_t *new_prog; int var_offset; if (sp->type != T_STRING) bad_arg(1, instruction); #ifdef DEBUG if (d_flag) debug_message("replace_program called\n"); #endif if (!current_object) error("replace_program called with no current object\n"); if (current_object == simul_efun_ob) error("replace_program on simul_efun object\n"); if (current_object->prog->func_ref) error("cannot replace a program with function references.\n"); name_len = strlen(sp->u.string); name = (char *) DMALLOC(name_len + 3, TAG_TEMPORARY, "replace_program"); xname = name; strcpy(name, sp->u.string); if (name[name_len - 2] != '.' || name[name_len - 1] != 'c') strcat(name, ".c"); if (*name == '/') name++; new_prog = search_inherited(name, current_object->prog, &var_offset); FREE(xname); if (!new_prog) { error("program to replace the current with has to be inherited\n"); } if (!(tmp = retrieve_replace_program_entry())) { tmp = ALLOCATE(replace_ob_t, TAG_TEMPORARY, "replace_program"); tmp->ob = current_object; tmp->next = obj_list_replace; obj_list_replace = tmp; } tmp->new_prog = new_prog; tmp->var_offset = var_offset; #ifdef DEBUG if (d_flag) debug_message("replace_program finished\n"); #endif free_string_svalue(sp--); }
GameEngine::GameEngine(Window* main){ if(main == NULL) throw bad_arg("Main window cannot be null"); logger->setToCommand(false); logger->setLogFile("debug.log"); logger->print("Initializing gameengine"); ResourceHandler::init()->loadResourceFile("enginedefault.res"); window = main; action = &dummy; storage = new std::vector<Sprite*>(); container = new std::vector<Component*>(); fpsLimit = 30; fpsClock = new Timer(); }
GroupedDataFrame::GroupedDataFrame(DataFrame x): data_(check_grouped(x)), symbols(group_vars(data_)), groups(data_.attr("groups")), nvars_(symbols.size()) { int rows_in_groups = 0; int ng = ngroups(); List idx = indices(); for (int i = 0; i < ng; i++) rows_in_groups += Rf_length(idx[i]); if (data_.nrows() != rows_in_groups) { bad_arg(".data", "is a corrupt grouped_df, contains {rows} rows, and {group_rows} rows in groups", _["rows"] = data_.nrows(), _["group_rows"] = rows_in_groups); } }
void f_socket_accept (void) { int port, fd; char addr[ADDR_BUF_SIZE]; if (!(sp->type & (T_STRING | T_FUNCTION))) { bad_arg(3, F_SOCKET_ACCEPT); } get_socket_address(fd = (sp-2)->u.number, addr, &port, 0); (sp-2)->u.number = VALID_SOCKET("accept") ? socket_accept(fd, (sp - 1), sp) : EESECURITY; pop_2_elems(); }
void f_lookat_rotate2 (void) { array_t *matrix; double ex, ey, ez, lx, ly, lz; Matrix current_matrix; Matrix lookat_matrix; int i, j; for (j = 4; j >= 0; j--) { if ((sp - j)->type != T_REAL) { bad_arg(7 - j, F_LOOKAT_ROTATE2); } } /* * get arguments from stack. */ matrix = (sp - 6)->u.arr; ex = (sp - 5)->u.real; ey = (sp - 4)->u.real; ez = (sp - 3)->u.real; lx = (sp - 2)->u.real; ly = (sp - 1)->u.real; lz = sp->u.real; sp -= 5; free_array((sp--)->u.arr); /* * convert vec matrix to float matrix. */ for (i = 0; i < 16; i++) { current_matrix[i] = matrix->item[i].u.real; } /* * create new viewing transformation matrix. */ lookat_rotate2(ex, ey, ez, lx, ly, lz, lookat_matrix); /* * convert float matrix to vec matrix. */ for (i = 0; i < 16; i++) { matrix->item[i].u.real = lookat_matrix[i]; } }
void f_socket_release (void) { int fd, port; char addr[ADDR_BUF_SIZE]; if (!(sp->type & (T_STRING | T_FUNCTION))) { bad_arg(3, F_SOCKET_RELEASE); } fd = (sp - 2)->u.number; get_socket_address(fd, addr, &port, 0); (sp-2)->u.number = VALID_SOCKET("release") ? socket_release((sp - 2)->u.number, (sp - 1)->u.ob, sp) : EESECURITY; pop_stack(); /* the object might have been dested an removed from the stack */ if (sp->type == T_OBJECT) free_object(sp->u.ob, "socket_release()"); sp--; }
void f_socket_create (void) { int fd, num_arg = st_num_arg; svalue_t *arg; arg = sp - num_arg + 1; if ((num_arg == 3) && !(arg[2].type & (T_STRING | T_FUNCTION))) { bad_arg(3, F_SOCKET_CREATE); } if (check_valid_socket("create", -1, current_object, "N/A", -1)) { if (num_arg == 2) fd = socket_create(arg[0].u.number, &arg[1], NULL); else { fd = socket_create(arg[0].u.number, &arg[1], &arg[2]); } pop_n_elems(num_arg - 1); sp->u.number = fd; } else { pop_n_elems(num_arg - 1); sp->u.number = EESECURITY; } }
void f_socket_bind (void) { int i, fd, port, num_arg = st_num_arg; svalue_t *arg; char addr[ADDR_BUF_SIZE]; arg = sp - num_arg + 1; if ((num_arg == 3) && (arg[2].type != T_STRING)) { bad_arg(3, F_SOCKET_BIND); } fd = arg[0].u.number; get_socket_address(fd, addr, &port, 0); if (VALID_SOCKET("bind")) { i = socket_bind(fd, arg[1].u.number, (num_arg == 3 ? arg[2].u.string : 0)); pop_n_elems(num_arg - 1); sp->u.number = i; } else { pop_n_elems(num_arg - 1); sp->u.number = EESECURITY; } }
void c_add_eq(int is_void) { DEBUG_CHECK(sp->type != T_LVALUE, "non-lvalue argument to +=\n"); lval = sp->u.lvalue; sp--; /* points to the RHS */ switch (lval->type) { case T_STRING: if (sp->type == T_STRING) { SVALUE_STRING_JOIN(lval, sp, "f_add_eq: 1"); } else if (sp->type == T_NUMBER) { char buff[20]; sprintf(buff, "%d", sp->u.number); EXTEND_SVALUE_STRING(lval, buff, "f_add_eq: 2"); } else if (sp->type == T_REAL) { char buff[40]; sprintf(buff, "%f", sp->u.real); EXTEND_SVALUE_STRING(lval, buff, "f_add_eq: 2"); } else { bad_argument(sp, T_STRING | T_NUMBER | T_REAL, 2, (is_void ? F_VOID_ADD_EQ : F_ADD_EQ)); } break; case T_NUMBER: if (sp->type == T_NUMBER) { lval->u.number += sp->u.number; /* both sides are numbers, no freeing required */ } else if (sp->type == T_REAL) { lval->u.number += sp->u.real; /* both sides are numbers, no freeing required */ } else { error("Left hand side of += is a number (or zero); right side is not a number.\n"); } break; case T_REAL: if (sp->type == T_NUMBER) { lval->u.real += sp->u.number; /* both sides are numerics, no freeing required */ } if (sp->type == T_REAL) { lval->u.real += sp->u.real; /* both sides are numerics, no freeing required */ } else { error("Left hand side of += is a number (or zero); right side is not a number.\n"); } break; #ifndef NO_BUFFER_TYPE case T_BUFFER: if (sp->type != T_BUFFER) { bad_argument(sp, T_BUFFER, 2, (is_void ? F_VOID_ADD_EQ : F_ADD_EQ)); } else { buffer_t *b; b = allocate_buffer(lval->u.buf->size + sp->u.buf->size); memcpy(b->item, lval->u.buf->item, lval->u.buf->size); memcpy(b->item + lval->u.buf->size, sp->u.buf->item, sp->u.buf->size); free_buffer(sp->u.buf); free_buffer(lval->u.buf); lval->u.buf = b; } break; #endif case T_ARRAY: if (sp->type != T_ARRAY) bad_argument(sp, T_ARRAY, 2, (is_void ? F_VOID_ADD_EQ : F_ADD_EQ)); else { /* add_array now frees the arrays */ lval->u.arr = add_array(lval->u.arr, sp->u.arr); } break; case T_MAPPING: if (sp->type != T_MAPPING) bad_argument(sp, T_MAPPING, 2, (is_void ? F_VOID_ADD_EQ : F_ADD_EQ)); else { absorb_mapping(lval->u.map, sp->u.map); free_mapping(sp->u.map); /* free RHS */ /* LHS not freed because its being reused */ } break; case T_LVALUE_BYTE: if (sp->type != T_NUMBER) error("Bad right type to += of char lvalue.\n"); else *global_lvalue_byte.u.lvalue_byte += sp->u.number; break; default: bad_arg(1, (is_void ? F_VOID_ADD_EQ : F_ADD_EQ)); } if (!is_void) { /* not void add_eq */ assign_svalue_no_free(sp, lval); } else { /* * but if (void)add_eq then no need to produce an * rvalue */ sp--; } }
int main(int argc, char** argv) { if (argc < 2) { return print_usage(argv[0], true); } FILE* in_fd = NULL; SerdSyntax input_syntax = SERD_TURTLE; SerdSyntax output_syntax = SERD_NTRIPLES; bool from_file = true; bool bulk_write = false; bool full_uris = false; const uint8_t* in_name = NULL; const uint8_t* add_prefix = NULL; const uint8_t* chop_prefix = NULL; const uint8_t* root_uri = NULL; int a = 1; for (; a < argc && argv[a][0] == '-'; ++a) { if (argv[a][1] == '\0') { in_name = (const uint8_t*)"(stdin)"; in_fd = stdin; break; } else if (argv[a][1] == 'b') { bulk_write = true; } else if (argv[a][1] == 'f') { full_uris = true; } else if (argv[a][1] == 'h') { return print_usage(argv[0], false); } else if (argv[a][1] == 'v') { return print_version(); } else if (argv[a][1] == 's') { in_name = (const uint8_t*)"(string)"; from_file = false; ++a; break; } else if (argv[a][1] == 'i') { if (++a == argc || !set_syntax(&input_syntax, argv[a])) { return bad_arg(argv[0], 'i'); } } else if (argv[a][1] == 'o') { if (++a == argc || !set_syntax(&output_syntax, argv[a])) { return bad_arg(argv[0], 'o'); } } else if (argv[a][1] == 'p') { if (++a == argc) { return bad_arg(argv[0], 'p'); } add_prefix = (const uint8_t*)argv[a]; } else if (argv[a][1] == 'c') { if (++a == argc) { return bad_arg(argv[0], 'c'); } chop_prefix = (const uint8_t*)argv[a]; } else if (argv[a][1] == 'r') { if (++a == argc) { return bad_arg(argv[0], 'r'); } root_uri = (const uint8_t*)argv[a]; } else { fprintf(stderr, "%s: Unknown option `%s'\n", argv[0], argv[a]); return print_usage(argv[0], true); } } if (a == argc) { fprintf(stderr, "%s: Missing input\n", argv[0]); return 1; } const uint8_t* input = (const uint8_t*)argv[a++]; if (from_file) { in_name = in_name ? in_name : input; if (!in_fd) { input = serd_uri_to_path(in_name); if (!input || !(in_fd = serd_fopen((const char*)input, "r"))) { return 1; } } } SerdURI base_uri = SERD_URI_NULL; SerdNode base = SERD_NODE_NULL; if (a < argc) { // Base URI given on command line base = serd_node_new_uri_from_string( (const uint8_t*)argv[a], NULL, &base_uri); } else if (from_file && in_fd != stdin) { // Use input file URI base = serd_node_new_file_uri(input, NULL, &base_uri, false); } FILE* out_fd = stdout; SerdEnv* env = serd_env_new(&base); int output_style = 0; if (output_syntax == SERD_NTRIPLES) { output_style |= SERD_STYLE_ASCII; } else { output_style |= SERD_STYLE_ABBREVIATED; if (!full_uris) { output_style |= SERD_STYLE_CURIED; } } if (input_syntax != SERD_NTRIPLES // Base URI may change (@base) || (output_syntax == SERD_TURTLE)) { output_style |= SERD_STYLE_RESOLVED; } if (bulk_write) { output_style |= SERD_STYLE_BULK; } SerdWriter* writer = serd_writer_new( output_syntax, (SerdStyle)output_style, env, &base_uri, serd_file_sink, out_fd); SerdReader* reader = serd_reader_new( input_syntax, writer, NULL, (SerdBaseSink)serd_writer_set_base_uri, (SerdPrefixSink)serd_writer_set_prefix, (SerdStatementSink)serd_writer_write_statement, (SerdEndSink)serd_writer_end_anon); SerdNode root = serd_node_from_string(SERD_URI, root_uri); serd_writer_set_root_uri(writer, &root); serd_writer_chop_blank_prefix(writer, chop_prefix); serd_reader_add_blank_prefix(reader, add_prefix); const SerdStatus status = (from_file) ? serd_reader_read_file_handle(reader, in_fd, in_name) : serd_reader_read_string(reader, input); serd_reader_free(reader); if (from_file) { fclose(in_fd); } serd_writer_finish(writer); serd_writer_free(writer); serd_env_free(env); serd_node_free(&base); return (status > SERD_FAILURE) ? 1 : 0; }
void GameEngine::addSprite(Sprite* sprite){ if(sprite == NULL) throw bad_arg("Don't add null to the sprite list"); logger->print("Adding sprite"); storage->push_back(sprite); }
void GameEngine::setFPS(int fps){ if(fps < 1) throw bad_arg("Negative FPS"); fpsLimit = fps; }
void Input::setFont(TTF_Font* font){ if(font == NULL) throw bad_arg("Font cannot be null"); this->font = font; render(); }
/* Parse command-line arguments */ void parse_args(int argc, char *argv[], int *first_arg_p) { int i; for (i = 1; i < argc && argv[i][0] == '-'; i++) { if (argv[i][1] == 'j') { if (argv[i][2]) /* '-j<string>' */ slots_string = &argv[i][2]; else if (i + 1 < argc) /* '-j' '<string>' */ slots_string = argv[++i]; else missing_arg (argv[i]); } else if (argv[i][1] == 'k' && !argv[i][2]) continue_on_error = 1; else if (argv[i][1] == 'v' && !argv[i][2]) verbose = 1; else if (argv[i][1] == 'n' && !argv[i][2]) skip_slot_test = 1; else if (argv[i][1] == 't') { const char *trace_name = "-"; if (argv[i][2]) /* '-t<filename>' */ trace_name = &argv[i][2]; else if (i + 1 < argc) /* '-t <filename>' */ trace_name = argv[++i]; else /* '-t' */ missing_arg (argv[i]); if (trace_name[0] == '-' && trace_name[1] == '\0') trace = stderr; else trace = fopen (trace_name, "w"); if (trace_name && !trace) { fprintf (stderr, "Cannot open trace file '%s'\n", trace_name); exit (0); } } else if (argv[i][1] == 'f') { const char *in_arguments_name = "-"; if (argv[i][2]) in_arguments_name = &argv[i][2]; else if (i + 1 < argc) in_arguments_name = argv[++i]; else missing_arg (argv[i]); if (in_arguments_name[0] == '-' && in_arguments_name[1] == '\0') in_arguments = stdin; else in_arguments = fopen(in_arguments_name, "r"); if (!in_arguments) { fprintf (stderr, "Cannot open input file '%s'\n", in_arguments_name); exit (0); } } else if (argv[i][1] == 'h' || (argv[i][1] == '-' && argv[i][2] == 'h')) { help(); exit (0); } else if (!strcmp(argv[i], "sync")) { sync_working_dirs = 1; } else bad_arg (argv[i]); } *first_arg_p = i; }
Component* Gui::getComp(std::string name){ if(comps.find(name) == comps.end()){ throw bad_arg("Gui: Error, no such key"); } return comps[name]; }
P4VOID process_args(int *argc, char **argv) { int i,c,nextarg; FILE *fp; char *s, **a; struct p4_procgroup_entry *pe; if (!argc || !argv) { /* Failure if either argc or argv are null */ p4_error( "Command-line arguments are missing",0 ); } /* Put the name of the called program (according to the args) into pgm */ s = (char *) rindex(*argv, '/'); if (s) strcpy(pgm, s + 1); else strcpy(pgm, *argv); /* Set all command line flags (except procgroup) to their defaults */ p4_debug_level = 0; p4_remote_debug_level = 0; bm_outfile[0] = '\0'; procgroup_file[0] = '\0'; p4_wd[0] = '\0'; strcpy(local_domain, ""); p4_myname_in_procgroup[0] = '\0'; hand_start_remotes = P4_FALSE; execer_starting_remotes = P4_FALSE; execer_id[0] = '\0'; execer_masthost[0] = '\0'; #ifdef OLD_EXECER execer_jobname[0] = '\0'; #endif execer_mynodenum = 0; execer_mastport = 0; execer_pg = NULL; /* Move to last argument, so that we can go backwards. */ a = &argv[*argc - 1]; /* * Loop backwards through arguments, catching the ones that start with * '-'. Backwards is more efficient when you are stripping things out. */ for (c = (*argc); c > 1; c--, a--) { if (**a != '-') continue; if (strcmp(*a, "-execer_id") == 0) { /* * Format of the rest of the args, example job: * node00:1 + node01:3 + node02:1 * Big master: * a.out -execer_id mpiexec -master_host node00 -my_hostname node00 * -my_nodenum 0 -my_numprocs 1 -total_numnodes 3 -mastport 4444 * -remote_info node01 3 node02 1 * Remote masters: * a.out -execer_id mpiexec -master_host node00 -my_hostname node01 * -my_nodenum 1 -my_numprocs 3 -total_numnodes 3 -master_port 5555 * a.out -execer_id mpiexec -master_host node00 -my_hostname node02 * -my_nodenum 2 -my_numprocs 1 -total_numnodes 3 -master_port 5555 * * Master will be started first, then report its listening * socket, then slaves can be started all at once in any order. */ execer_starting_remotes = P4_TRUE; strcpy(execer_id,*(a+1)); strcpy(execer_masthost,*(a+3)); strcpy(execer_myhost,*(a+5)); execer_mynodenum = atoi(*(a+7)); execer_mynumprocs = atoi(*(a+9)); execer_numtotnodes = atoi(*(a+11)); #ifdef OLD_EXECER strcpy(execer_jobname,*(a+13)); #else execer_mastport = atoi(*(a+13)); nextarg = 14; #endif if (execer_mynodenum == 0) { execer_pg = p4_alloc_procgroup(); pe = execer_pg->entries; strcpy(pe->host_name,execer_myhost); pe->numslaves_in_group = execer_mynumprocs - 1; strcpy(pe->slave_full_pathname,argv[0]); pe->username[0] = '\0'; /* unused */ execer_pg->num_entries++; for (i=0; i < (execer_numtotnodes-1); i++) { if (i == 0) ++nextarg; /* "-remote_info" fake arg */ pe++; strcpy(pe->host_name,*(a+nextarg)); nextarg++; #ifdef OLD_EXECER nextarg++; /* skip node num */ #endif pe->numslaves_in_group = atoi(*(a+nextarg)); nextarg++; #ifdef OLD_EXECER strcpy(pe->slave_full_pathname,*(a+nextarg)); /* unused */ nextarg++; #else *pe->slave_full_pathname = 0; #endif pe->username[0] = '\0'; /* unused */ execer_pg->num_entries++; } } #ifdef OLD_EXECER else { execer_mastport = get_execer_port(execer_masthost); } #else strip_out_args(a, argc, &c, nextarg); #endif continue; } if (!strcmp(*a, "-p4pg")) { if (bad_arg(a[1])) usage(); strncpy(procgroup_file, a[1], 256); procgroup_file[255] = 0; strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4wd")) { if (bad_arg(a[1])) usage(); strncpy(p4_wd, a[1], 255); p4_wd[255] = 0; strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4dbg")) { if (bad_arg(a[1])) usage(); p4_debug_level = atoi(a[1]); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4ssport")) { if (bad_arg(a[1])) usage(); sserver_port = atoi(a[1]); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4rdbg")) { if (bad_arg(a[1])) usage(); p4_remote_debug_level = atoi(a[1]); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4gm")) { if (bad_arg(a[1])) usage(); globmemsize = atoi(a[1]); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4dmn")) { if (bad_arg(a[1])) usage(); strcpy(local_domain, a[1]); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4out")) { if (bad_arg(a[1])) usage(); strncpy(bm_outfile, a[1], 100); bm_outfile[99] = 0; strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4rout")) { if (bad_arg(a[1])) usage(); strncpy(rm_outfile_head, a[1], 100); rm_outfile_head[99] = 0; strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4log")) { strip_out_args(a, argc, &c, 1); logging_flag = P4_TRUE; continue; } if (!strcmp(*a, "-p4norem")) { strip_out_args(a, argc, &c, 1); hand_start_remotes = P4_TRUE; continue; } if (!strcmp(*a, "-p4version")) { strip_out_args(a, argc, &c, 1); print_version_info(); continue; } /* Add escape for socket performance controls */ if (!strcmp( *a, "-p4sctrl" )) { if (bad_arg(a[1])) usage(); p4_socket_control( a[1] ); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4yourname")) { /* Capture the name that the master is using in its procgroup file. This really belongs with the various "remote master" arguments, but putting it there will mess up lots of code. Using a separate argument for this makes it easier to make this an optional value */ if (bad_arg(a[1])) usage(); strncpy(p4_myname_in_procgroup, a[1], MAXHOSTNAMELEN); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp( *a, "-p4rmrank")) { /* Capture the base rank for this remote master. That is, the rank of the remote master. */ if (bad_arg(a[1])) usage(); p4_rm_rank = atoi(a[1]); strip_out_args(a, argc, &c, 2); continue; } if (!strcmp(*a, "-p4help")) usage(); } if (!execer_starting_remotes) { if (procgroup_file[0] == '\0') { strncpy(procgroup_file,argv[0],250); procgroup_file[249] = 0; strcat(procgroup_file,".pg"); if ((fp = fopen(procgroup_file,"r")) == NULL) { /* pgm.pg not there */ strcpy(procgroup_file, "procgroup"); } else fclose(fp); } p4_dprintfl(10,"using procgroup file %s\n",procgroup_file); } }
void FunctionListener::setFunction(const Func code){ if(code == NULL) throw bad_arg("Function pointer cannot be null"); action = code; }
void f_debug_info (void) { svalue_t *arg; outbuffer_t out; outbuf_zero(&out); arg = sp - 1; switch (arg[0].u.number) { case 0: { int i, flags; object_t *obj2; ob = arg[1].u.ob; flags = ob->flags; outbuf_addv(&out, "O_HEART_BEAT : %s\n", flags & O_HEART_BEAT ? "TRUE" : "FALSE"); #ifndef NO_WIZARDS outbuf_addv(&out, "O_IS_WIZARD : %s\n", flags & O_IS_WIZARD ? "TRUE" : "FALSE"); #endif #ifdef NO_ADD_ACTION outbuf_addv(&out, "O_LISTENER : %s\n", flags & O_LISTENER ? "TRUE" : "FALSE"); #else outbuf_addv(&out, "O_ENABLE_COMMANDS : %s\n", flags & O_ENABLE_COMMANDS ? "TRUE" : "FALSE"); #endif outbuf_addv(&out, "O_CLONE : %s\n", flags & O_CLONE ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_VIRTUAL : %s\n", flags & O_VIRTUAL ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_DESTRUCTED : %s\n", flags & O_DESTRUCTED ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_ONCE_INTERACTIVE: %s\n", flags & O_ONCE_INTERACTIVE ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_RESET_STATE : %s\n", flags & O_RESET_STATE ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_WILL_CLEAN_UP : %s\n", flags & O_WILL_CLEAN_UP ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_WILL_RESET : %s\n", flags & O_WILL_RESET ? "TRUE" : "FALSE"); #ifdef HAVE_ZLIB if (ob->interactive) { outbuf_addv(&out, "O_COMPRESSED : %s\n", ob->interactive->compressed_stream ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_ZMP : %s\n", ob->interactive->iflags & USING_ZMP ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_GMCP : %s\n", ob->interactive->iflags & USING_GMCP ? "TRUE" : "FALSE"); outbuf_addv(&out, "O_MXP : %s\n", ob->interactive->iflags & USING_MXP ? "TRUE" : "FALSE"); } #endif #ifndef NO_LIGHT outbuf_addv(&out, "total light : %d\n", ob->total_light); #endif #ifndef NO_RESETS outbuf_addv(&out, "next_reset : %d\n", ob->next_reset); #endif outbuf_addv(&out, "time_of_ref : %d\n", ob->time_of_ref); outbuf_addv(&out, "ref : %d\n", ob->ref); #ifdef DEBUG outbuf_addv(&out, "extra_ref : %d\n", ob->extra_ref); #endif outbuf_addv(&out, "name : '/%s'\n", ob->obname); outbuf_addv(&out, "next_all : OBJ(/%s)\n", ob->next_all ? ob->next_all->obname : "NULL"); if (obj_list == ob) outbuf_add(&out, "This object is the head of the object list.\n"); for (obj2 = obj_list, i = 1; obj2; obj2 = obj2->next_all, i++) if (obj2->next_all == ob) { outbuf_addv(&out, "Previous object in object list: OBJ(/%s)\n", obj2->obname); outbuf_addv(&out, "position in object list:%d\n", i); } break; } case 1: ob = arg[1].u.ob; outbuf_addv(&out, "program ref's %d\n", ob->prog->ref); outbuf_addv(&out, "Name /%s\n", ob->prog->filename); outbuf_addv(&out, "program size %d\n", ob->prog->program_size); outbuf_addv(&out, "function flags table %d (%d) \n", ob->prog->last_inherited + ob->prog->num_functions_defined, (ob->prog->last_inherited + ob->prog->num_functions_defined)* sizeof(unsigned short)); outbuf_addv(&out, "compiler function table %d (%d) \n", ob->prog->num_functions_defined, ob->prog->num_functions_defined * sizeof(function_t)); outbuf_addv(&out, "num strings %d\n", ob->prog->num_strings); outbuf_addv(&out, "num vars %d (%d)\n", ob->prog->num_variables_defined, ob->prog->num_variables_defined * (sizeof(char *) + sizeof(short))); outbuf_addv(&out, "num inherits %d (%d)\n", ob->prog->num_inherited, ob->prog->num_inherited * sizeof(inherit_t)); outbuf_addv(&out, "total size %d\n", ob->prog->total_size); break; case 2: { int i; ob = arg[1].u.ob; for (i=0; i<ob->prog->num_variables_total; i++) { /* inefficient, but: */ outbuf_addv(&out, "%s: ", variable_name(ob->prog, i)); svalue_to_string(&ob->variables[i], &out, 2, 0, 0); outbuf_add(&out, "\n"); } break; } default: bad_arg(1, F_DEBUG_INFO); } pop_stack(); pop_stack(); outbuf_push(&out); }
void GameEngine::addComponent(Component* c) { if(c == NULL) throw bad_arg("Don't add null to the component list"); logger->print("Adding component"); container->push_back(c); }