void loggerwindow_log(LoggerWindow *lw, char *line) { if (lw->nloglines==lw->logsize) { lw->loglines= memdbl(lw->loglines, &lw->logsize, sizeof(*lw->loglines)); } lw->loglines[lw->nloglines++]= string_dup(line); scrollbar_set_thumbpct(lw->scroll, (float) lw->ndisplines/lw->nloglines); GHOST_InvalidateWindow(lw->win); }
/** * @brief * dup_node_partition - duplicate a node_partition structure * * @param[in] onp - the node_partition structure to duplicate * @param[in] nsinfo - server for the new node partiton (the nodes are needed) * * @return duplicated node_partition * @retval NULL : on error * */ node_partition * dup_node_partition(node_partition *onp, server_info *nsinfo) { node_partition *nnp; if (onp == NULL) return NULL; if ((nnp = new_node_partition()) == NULL) return NULL; if (onp->name != NULL) nnp->name = string_dup(onp->name); if (onp->def != NULL) nnp->def = onp->def; if (onp->res_val != NULL) nnp->res_val = string_dup(onp->res_val); nnp->ok_break = onp->ok_break; nnp->excl = onp->excl; nnp->tot_nodes = onp->tot_nodes; nnp->free_nodes = onp->free_nodes; nnp->res = dup_resource_list(onp->res); #ifdef NAS /* localmod 049 */ nnp->ninfo_arr = copy_node_ptr_array(onp->ninfo_arr, nsinfo->nodes, nsinfo); #else nnp->ninfo_arr = copy_node_ptr_array(onp->ninfo_arr, nsinfo->nodes); #endif nnp->bkts = dup_node_bucket_array(onp->bkts, nsinfo); nnp->rank = onp->rank; /* validity check */ if (onp->name == NULL || onp->res_val == NULL || nnp->res == NULL || nnp->ninfo_arr == NULL) { free_node_partition(nnp); return NULL; } return nnp; }
static void save_pair_data(tg_pair_t *pair) { HacheIter *iter; HacheItem *hi; pair_data *save_pair; string_alloc_t *str_pool; int i = 0, i_max; pair_queue_t *que; if (NULL == (save_pair = (pair_data *)malloc(sizeof(pair_data) * pair->write_size))) { fprintf(stderr, "Can't allocate memory in save_pair_data\n"); return; } str_pool = string_pool_create(1024 * 1024); if (NULL == str_pool) { fprintf(stderr, "Can't allocate string pool memory in save_pair_data\n"); return; } iter = HacheTableIterCreate(); while ((hi = HacheTableIterNext(pair->phache, iter))) { save_pair[i].tname = string_dup(str_pool, hi->key); save_pair[i].data = pair_to_pooled_string(str_pool, (pair_loc_t *)hi->data.p); i++; } i_max = i; HacheTableIterDestroy(iter); qsort(save_pair, pair->count, sizeof(pair_data), cmp_pair); que = add_pair_queue(pair); if (NULL == que) { fprintf(stderr, "Can't create new pair queue\n"); return; } for (i = 0; i < i_max; i++) { fprintf(que->fp, "%s %s\n", save_pair[i].tname, save_pair[i].data); } if (HacheTableEmpty(pair->phache, 1)) { // TEST TEST TEST need to put in proper fail fprintf(stderr, "save_pair_data failed on HacheTableEmpty\n"); } string_pool_destroy(str_pool); free(save_pair); fflush(que->fp); }
void op_strpush(void) { Var s; int symno; symno = frame.m->code[frame.pc++]; s.type = STR; s.v.str = string_dup(sym_get(frame.on, symno)); push(s); }
int new_mfunc(const char *funcname, const char *buf) { if (strlen(funcname) > MAX_MFUN_NAME_LEN) return 1; if (funcc > MPI_MAX_FUNCTIONS) return 2; strcpyn(funcv[funcc].name, sizeof(funcv[funcc].name), funcname); funcv[funcc++].buf = (char *) string_dup(buf); return 0; }
static void store_data( const char *name, const char *type) { MYDATA *p = (MYDATA *) malloc(sizeof(MYDATA)); MYDATA *q; p->link = 0; p->name = string_dup(name); p->type = string_dup(type); if ((q = all_data) == 0) all_data = p; else { while (q->link != 0) q = q->link; q->link = p; } }
str_grid_patch_filler_t* str_grid_patch_filler_new(const char* name, void* context, str_grid_patch_filler_vtable vtable) { ASSERT(vtable.start_filling_cells != NULL); str_grid_patch_filler_t* filler = GC_MALLOC(sizeof(str_grid_patch_filler_t)); filler->name = string_dup(name); filler->context = context; filler->vtable = vtable; GC_register_finalizer(filler, str_grid_patch_filler_free, filler, NULL, NULL); return filler; }
void shell_setenv_root(const char *name, char *value) { struct environment *environment = _environment; char *old; while(environment->previous) { environment = environment->previous; } old = (char *)str2ptr_set(environment->variables, name, (void *)string_dup(value)); if(old) { free(old); } }
int init_game(const char *infile, const char *outfile) { FILE *f; if ((f = fopen(MACRO_FILE, "rb")) == NULL) log_status("INIT: Macro storage file %s is tweaked.", MACRO_FILE); else { macroload(f); fclose(f); } in_filename = (char *) string_dup(infile); if ((input_file = fopen(infile, "rb")) == NULL) return -1; #ifdef DELTADUMPS if ((delta_outfile = fopen(DELTAFILE_NAME, "wb")) == NULL) return -1; if ((delta_infile = fopen(DELTAFILE_NAME, "rb")) == NULL) return -1; #endif db_free(); init_primitives(); /* init muf compiler */ mesg_init(); /* init mpi interpreter */ SRANDOM(getpid()); /* init random number generator */ tune_load_parmsfile(NOTHING); /* load @tune parms from file */ /* ok, read the db in */ log_status("LOADING: %s", infile); fprintf(stderr, "LOADING: %s\n", infile); if (db_read(input_file) < 0) return -1; log_status("LOADING: %s (done)", infile); fprintf(stderr, "LOADING: %s (done)\n", infile); /* set up dumper */ if (dumpfile) free((void *) dumpfile); dumpfile = alloc_string(outfile); if (!db_conversion_flag) { /* initialize the _sys/startuptime property */ add_property((dbref) 0, "_sys/startuptime", NULL, (int) time((time_t *) NULL)); add_property((dbref) 0, "_sys/maxpennies", NULL, tp_max_pennies); add_property((dbref) 0, "_sys/dumpinterval", NULL, tp_dump_interval); add_property((dbref) 0, "_sys/max_connects", NULL, 0); } return 0; }
void copyinst(struct inst *from, struct inst *to) { assert(from && to); int j, varcnt; *to = *from; switch(from->type) { case PROG_FUNCTION: if (from->data.mufproc) { to->data.mufproc = (struct muf_proc_data*)malloc(sizeof(struct muf_proc_data)); to->data.mufproc->procname = string_dup(from->data.mufproc->procname); to->data.mufproc->vars = varcnt = from->data.mufproc->vars; to->data.mufproc->args = from->data.mufproc->args; to->data.mufproc->varnames = (const char**)calloc(varcnt, sizeof(const char*)); for (j = 0; j < varcnt; j++) { to->data.mufproc->varnames[j] = string_dup(from->data.mufproc->varnames[j]); } } break; case PROG_STRING: if (from->data.string) { from->data.string->links++; } break; case PROG_ARRAY: if (from->data.array) { from->data.array->links++; } break; case PROG_ADD: from->data.addr->links++; PROGRAM_INC_INSTANCES(from->data.addr->progref); break; case PROG_LOCK: if (from->data.lock != TRUE_BOOLEXP) { to->data.lock = copy_bool(from->data.lock); } break; } }
void ossfim2map(double **table, const char *name, double s, double S, double b, double B, int dx, int dy) { GRIDMAP *m; TICKS x, y; char str[100]; int i, j; extern int nice_legend; double bs; m = new_map(); m->filename = name; m->rows = dy + 1; m->cols = dx + 1; m->cellsizex = m->cellsizey = 1.0; m->x_ul = m->y_ul = 1.0; alloc_mv_grid(m); for (i = 0; i <= dx; i++) /* row */ for (j = 0; j <= dy; j++) /* col */ map_put_cell(m, dy - j, i, table[i][j]); /* flips */ /* fill ticks */ x.every = y.every = 1; x.n = dx + 1; y.n = dy + 1; x.entries = (char **) emalloc(x.n * sizeof(char *)); for (i = 0; i <= dx; i++) { /* sample spacings: */ sprintf(str, "%3g", s + i * (S - s) / dx); x.entries[i] = string_dup((char *) str); } y.entries = (char **) emalloc(y.n * sizeof(char *)); for (i = 0; i <= dy; i++) { /* sample spacings: */ bs = b + i * (B - b) / dy; sprintf(str, "%g x %g", bs, bs); y.entries[dy - i] = string_dup((char *) str); } nice_legend = 1; one_map2gd(m, name, &y, &x, 1); return; }
void do_abort_interp(dbref player, const char *msg, struct inst *pc, struct inst *arg, int atop, struct frame *fr, struct inst *oper1, struct inst *oper2, struct inst *oper3, struct inst *oper4, int nargs, dbref program, char *file, int line) { char buffer[128]; if (fr->trys.top) { fr->errorstr = string_dup(msg); if (pc) { fr->errorinst = string_dup(insttotext(fr, 0, pc, buffer, sizeof(buffer), 30, program, 1)); fr->errorline = pc->line; } else { fr->errorinst = NULL; fr->errorline = -1; } fr->errorprog = program; err++; } else { fr->pc = pc; calc_profile_timing(program,fr); interp_err(player, program, pc, arg, atop, fr->caller.st[1], insttotext(fr, 0, pc, buffer, sizeof(buffer), 30, program, 1), msg); if (controls(player, program)) muf_backtrace(player, program, STACK_SIZE, fr); } switch (nargs) { case 4: RCLEAR(oper4, file, line); case 3: RCLEAR(oper3, file, line); case 2: RCLEAR(oper2, file, line); case 1: RCLEAR(oper1, file, line); } return; }
int ctrl_k(t_elem *e) { free_string_edit(e->clipboard); e->clipboard = NULL; string_dup(e); my_tputs(e->cap[CD]); if (e->cursor->next) free_end_of_clip(e->cursor->next); e->cursor->c = 0; e->cursor->next = NULL; e->len -= taille_clip(e); return (0); }
void CC FASTQ_error(struct FASTQParseBlock* sb, const char* msg) { if (sb->record->rej == 0) { /* save the error information in the Rejected object */ sb->record->rej = (Rejected*)malloc(sizeof(Rejected)); RejectedInit(sb->record->rej); sb->record->rej->message = string_dup(msg, strlen(msg)); sb->record->rej->line = sb->lastToken->line_no; sb->record->rej->column = sb->lastToken->column_no; } /* subsequent errors in this record will be ignored */ }
polyhedron_integrator_t* polyhedron_integrator_new(const char* name, void* context, polyhedron_integrator_vtable vtable) { ASSERT(vtable.set_domain != NULL); ASSERT(vtable.next_volume_point != NULL); ASSERT(vtable.next_surface_point != NULL); polyhedron_integrator_t* integ = polymec_malloc(sizeof(polyhedron_integrator_t)); integ->name = string_dup(name); integ->context = context; integ->vtable = vtable; return integ; }
token* get_token(char* token_string) { char *colon; token *this_token = (token *) malloc(sizeof(token)); char *work_string = string_dup(token_string); colon = strstr(work_string, ":"); this_token->count = atof(colon + 1); *colon = 0; this_token->identifier = work_string; return this_token; }
neighbor_pairing_t* neighbor_pairing_new(const char* name, int num_pairs, int* pairs, real_t* weights, exchanger_t* ex) { ASSERT(pairs != NULL); ASSERT(ex != NULL); neighbor_pairing_t* p = polymec_malloc(sizeof(neighbor_pairing_t)); p->name = string_dup(name); p->num_pairs = num_pairs; p->pairs = pairs; p->weights = weights; p->ex = ex; return p; }
void exodus_file_close(exodus_file_t* file) { if (file->writing) { // Write a QA record. char* qa_record[1][4]; qa_record[0][0] = string_dup(polymec_executable_name()); qa_record[0][1] = string_dup(polymec_executable_name()); time_t invocation_time = polymec_invocation_time(); struct tm* time_data = localtime(&invocation_time); char date[20], instant[20]; snprintf(date, 19, "%02d/%02d/%02d", time_data->tm_mon, time_data->tm_mday, time_data->tm_year % 100); qa_record[0][2] = string_dup(date); snprintf(instant, 19, "%02d:%02d:%02d", time_data->tm_hour, time_data->tm_min, time_data->tm_sec % 60); qa_record[0][3] = string_dup(instant); ex_put_qa(file->ex_id, 1, qa_record); for (int i = 0; i < 4; ++i) string_free(qa_record[0][i]); } // Clean up. if (file->elem_block_ids != NULL) polymec_free(file->elem_block_ids); if (file->face_block_ids != NULL) polymec_free(file->face_block_ids); if (file->edge_block_ids != NULL) polymec_free(file->edge_block_ids); free_all_variable_names(file); #if POLYMEC_HAVE_MPI MPI_Info_free(&file->mpi_info); #endif ex_close(file->ex_id); }
rng_t* rng_new(const char* name, void* context, uint32_t min, uint32_t max, rng_vtable vtable, bool has_global_state, bool is_thread_safe) { ASSERT(min < max); ASSERT(vtable.get != NULL); rng_t* rng = GC_MALLOC(sizeof(rng_t)); rng->name = string_dup(name); rng->context = context; rng->min = min; rng->max = max; rng->vtable = vtable; rng->has_global_state = has_global_state; rng->is_thread_safe = is_thread_safe; GC_register_finalizer(rng, rng_free, rng, NULL, NULL); return rng; }
/*----------------------------------------------------------------------*/ static int register_test(TestItem *test_items, int maximum_number_of_tests, char *specification_name) { int number_of_tests; for (number_of_tests = 0; test_items[number_of_tests].specification_name != NULL; number_of_tests++) ; if (number_of_tests == maximum_number_of_tests) { fprintf(stderr, "\nERROR: Found too many tests (%d)! Giving up.\nConsider splitting tests between libraries on logical suite boundaries.\n", number_of_tests); return -1; } test_items[number_of_tests].specification_name = string_dup(specification_name); test_items[number_of_tests].context_name = context_name_from_specname(specification_name); test_items[number_of_tests].test_name = test_name_from_specname(specification_name); test_items[number_of_tests+1].specification_name = NULL; return 0; }
void options_parse(int argc, char** argv) { if (argv_singleton != NULL) argv_singleton = NULL; options_t* o = options_new(); // Parse the basic options. o->num_args = argc; o->args = polymec_malloc(sizeof(char*) * o->num_args); int first_named_value = -1; for (int i = 0; i < argc; ++i) { if (string_contains(argv[i], "=") && (first_named_value == -1)) first_named_value = i; o->args[i] = string_dup(argv[i]); } // Now parse parameters. int i = (first_named_value == -1) ? 0 : first_named_value; while (i < argc) { // Parse a key=value pair. int pos = 0, length; char* token; if (string_next_token(argv[i], "=", &pos, &token, &length)) { // We found a key with an '=' after it. What's the value? char key[length+1]; strncpy(key, token, length); key[length] = '\0'; if (string_next_token(argv[i], "=", &pos, &token, &length)) { char value[length+1]; strncpy(value, token, length); value[length] = '\0'; options_set(o, key, value); } } // Next! ++i; } argv_singleton = o; }
/* Current interface: ** argv[0] - module name ** argv[1] - database name ** argv[2] - table name ** argv[3] - tokenizer name (optional, a sensible default is provided) ** argv[4..] - passed to tokenizer (optional based on tokenizer) **/ static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv, sqlite3_vtab **ppVTab){ int rc; fulltext_vtab *v; sqlite3_tokenizer_module *m = NULL; assert( argc>=3 ); v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab)); /* sqlite will initialize v->base */ v->db = db; v->zName = string_dup(argv[2]); v->pTokenizer = NULL; if( argc==3 ){ get_simple_tokenizer_module(&m); } else { /* TODO(shess) For now, add new tokenizers as else if clauses. */ if( !strcmp(argv[3], "simple") ){ get_simple_tokenizer_module(&m); } else { assert( "unrecognized tokenizer"==NULL ); } } /* TODO(shess) Since tokenization impacts the index, the parameters ** to the tokenizer need to be identical when a persistent virtual ** table is re-created. One solution would be a meta-table to track ** such information in the database. Then we could verify that the ** information is identical on subsequent creates. */ /* TODO(shess) Why isn't argv already (const char **)? */ rc = m->xCreate(argc-3, (const char **) (argv+3), &v->pTokenizer); if( rc!=SQLITE_OK ) return rc; v->pTokenizer->pModule = m; /* TODO: verify the existence of backing tables foo_content, foo_term */ rc = sqlite3_declare_vtab(db, "create table x(content text)"); if( rc!=SQLITE_OK ) return rc; memset(v->pFulltextStatements, 0, sizeof(v->pFulltextStatements)); *ppVTab = &v->base; return SQLITE_OK; }
struct String *string_to_struct(char *str){ struct String *string; int length; char *dup_str; length = str_len(str); /* Value is the address of 1st element of space stored in memory for struct String */ string = malloc(sizeof(struct String)); /* Duplicate string and store its value to a variable */ dup_str = string_dup(str); if(string == NULL) /* If function fails, return NULL */ return (NULL); /* Pointer str accesses elements string and length w/its proper assigned value */ string->str = dup_str; string->length = length; /* Return address of structure (pointer to the string)*/ return (string); }
fe_mesh_t* fe_mesh_clone(fe_mesh_t* mesh) { fe_mesh_t* copy = polymec_malloc(sizeof(fe_mesh_t)); copy->comm = mesh->comm; copy->num_nodes = mesh->num_nodes; copy->blocks = ptr_array_new(); for (int i = 0; i < mesh->blocks->size; ++i) copy->blocks->data[i] = fe_block_clone(mesh->blocks->data[i]); copy->block_names = string_array_new(); for (int i = 0; i < mesh->block_names->size; ++i) copy->block_names->data[i] = string_dup(mesh->block_names->data[i]); copy->block_elem_offsets = int_array_new(); for (int i = 0; i < mesh->block_elem_offsets->size; ++i) int_array_append(copy->block_elem_offsets, mesh->block_elem_offsets->data[i]); copy->node_coords = polymec_malloc(sizeof(point_t) * copy->num_nodes); memcpy(copy->node_coords, mesh->node_coords, sizeof(point_t) * copy->num_nodes); return copy; }
st_func_t* st_func_from_func(const char* name, st_eval_func func, st_func_homogeneity_t homogeneity, st_func_constancy_t constancy, int num_comp) { ASSERT(func != NULL); ASSERT(num_comp > 0); st_func_t* f = GC_MALLOC(sizeof(st_func_t)); f->name = string_dup(name); f->context = NULL; f->vtable.eval = func; f->homogeneous = (homogeneity == ST_FUNC_HOMOGENEOUS); f->constant = (constancy == ST_FUNC_CONSTANT); f->num_comp = num_comp; memset(f->derivs, 0, sizeof(st_func_t*)*4); GC_register_finalizer(f, &st_func_free, f, NULL, NULL); return f; }
str_grid_cell_solver_t* str_grid_cell_solver_new(const char* solver_name, MPI_Comm comm, void* context, str_grid_cell_solver_vtable vtable, str_grid_t* grid, int num_comps) { ASSERT(vtable.solve != NULL); ASSERT(num_comps > 0); str_grid_cell_solver_t* solver = polymec_malloc(sizeof(str_grid_cell_solver_t)); solver->name = string_dup(solver_name); solver->comm = comm; solver->context = context; solver->vtable = vtable; solver->grid = grid; solver->num_comps = num_comps; return solver; }
void mcp_package_register(const char *pkgname, McpVer minver, McpVer maxver, McpPkg_CB callback, void *context, ContextCleanup_CB cleanup) { McpPkg *nu = (McpPkg *) malloc(sizeof(McpPkg)); nu->pkgname = string_dup(pkgname); nu->minver = minver; nu->maxver = maxver; nu->callback = callback; nu->context = context; nu->cleanup = cleanup; mcp_package_deregister(pkgname); nu->next = mcp_PackageList; mcp_PackageList = nu; mcp_frame_package_renegotiate(pkgname); }
st_func_t* st_func_from_sp_func(sp_func_t* func) { ASSERT(func != NULL); st_func_t* f = GC_MALLOC(sizeof(st_func_t)); f->name = string_dup(sp_func_name(func)); f->context = func; f->vtable.eval = eval_sp_func; f->homogeneous = sp_func_is_homogeneous(func); f->constant = true; f->num_comp = sp_func_num_comp(func); memset(f->derivs, 0, sizeof(st_func_t*)*4); for (int i = 1; i <= 4; ++i) { if (sp_func_has_deriv(func, i)) st_func_register_deriv(f, i, sp_func_deriv_new(func, i)); } GC_register_finalizer(f, &st_func_free, f, NULL, NULL); return f; }
gmls_functional_t* surface_gmls_functional_new(const char* name, void* context, gmls_functional_vtable vtable, int num_components, surface_integral_t* quad_rule) { ASSERT(vtable.eval_integrands != NULL); ASSERT(num_components > 0); gmls_functional_t* functional = polymec_malloc(sizeof(gmls_functional_t)); functional->name = string_dup(name); functional->context = context; functional->vtable = vtable; functional->num_comp = num_components; functional->volume_quad_rule = NULL; functional->surface_quad_rule = quad_rule; return functional; }
static indel_fragment * make_indel_fragment( const char * bases, uint32_t len ) { indel_fragment * res = malloc( sizeof * res ); if ( res != NULL ) { res->bases = string_dup ( bases, len ); if ( res->bases == NULL ) { free( res ); res = NULL; } else { res->len = len; res->count = 1; } } return res; }