t_screen *screen_default(const char *name, void (* draw)(t_screen *s)) { t_context *C=ctx_get(); t_node *node=scene_add(C->scene,dt_screen,name); t_screen *screen=node->data; screen->keymap=keymap_generic; screen->draw=draw; // Add to UI Screens lst_add(C->ui->screens,node,name); // Lst t_node *node_lst = scene_add( C->scene, dt_list, "lst"); t_lst *lst = node_lst->data; screen->viewports = lst; // Viewport t_node *node_viewport = scene_add( C->scene, dt_viewport, name); t_viewport *viewport = node_viewport->data; // Camera t_node *node_camera = scene_add( C->scene, dt_camera, name); t_camera *camera = node_camera->data; viewport->camera = camera; lst_add(screen->viewports, viewport, name); return screen; }
apr_status_t teeterl_exec(const char *m, const char *f, const char *as[]) { process_t *proc; term_t result, retval; term_t args = nil; term_t args1; // [args] term_t cons = nil; lst_add(args, cons, ztol(m, g_xpool), g_xpool); lst_add(args, cons, ztol(f, g_xpool), g_xpool); if (as != 0) { const char **p = as; while (*p) lst_add(args, cons, ztol(*p++, g_xpool), g_xpool); } args1 = make_list(args, g_xpool); proc = proc_spawn(g_base, g_atoms, A_INIT, A_RUN, args1); if (proc == 0) { printf("Unable to spawn init:run()\n"); return APR_ENOPROC; } do { result = proc_main(proc, 1000000, &retval); } while (result == AI_YIELD); if (result == A_ERROR) { proc_print_error(proc, retval); return APR_ENOPROC; } else if (result == A_THROW) { printf("*** not caught: %s\n", stringify_term(retval, g_atoms, g_mempool)); return APR_ENOPROC; } else if (result == A_EXIT) { printf("*** exited: %s\n", stringify_term(retval, g_atoms, g_mempool)); return APR_ENOPROC; } else if (result == AI_DONE) { //normal exit, do nothing } else { proc_print_init_exits_unexpectedly(proc, result, retval); return APR_ENOPROC; } return APR_SUCCESS; }
term_t proc_trace_stack(process_t *self) { term_t r = nil; term_t cons = nil; int ebp = self->ebp; term_t mod, thrice, pair; int saved_ebp, i; term_t avs = nil; //args+vars term_t cons1 = nil; // arity of the current function is unknown // however, it is known that the arity is less // or equal to saved_ebp - cur_ebp - 3 saved_ebp = int_value2(cstack(ebp-1)); for (i = ebp-4; i >= saved_ebp; i--) { term_t av = cstack(i); lst_add(avs, cons1, av, self->gc_cur); } mod = code_base_mod_name(self->base, self->mod_index); thrice = make_tuple3(mod, intnum(self->ip - self->code), avs, self->gc_cur); lst_add(r, cons, thrice, self->gc_cur); while (1) { int ebp1 = int_value2(cstack(ebp-1)); int offset = int_value2(cstack(ebp-2)); int mod_index = int_value2(cstack(ebp-3)); term_t cons = nil; if (mod_index == MOD_INDEX_NONE) break; mod = code_base_mod_name(self->base, mod_index); pair = make_tuple2(mod, intnum(offset), self->gc_cur); lst_add(r, cons, pair, self->gc_cur); ebp = ebp1; } self->stack_trace = r; return self->stack_trace; }
t_module *mode_module_add(t_mode *mode,char *name,void *data) { int is_free=1; t_link *link; if(mode->modules->first) { for(link=mode->modules->first;link;link=link->next) { t_module *module=link->data; if(is(module->name,"name")) { printf("module %s exists\n",name); is_free=0; } } } if(is_free) { t_module *module=module_new(name,data); lst_add(mode->modules,module,module->name); return module; } else { return NULL; } }
term_t bif_spawn0_1(term_t F, process_t *ctx) { process_t *proc; term_t mod, fun, args = nil; term_t cons = nil; term_t fridge; int i, nfree; if (!is_fun(F)) return A_BADARG; fridge = fun_fridge(F); nfree = int_value2(tup_size(fridge)); if (int_value2(fun_arity(F)) != nfree) return A_BADARG; for (i = 0; i < nfree; i++) lst_add(args, cons, tup_elts(fridge)[i], proc_gc_pool(ctx)); mod = fun_amod(F); fun = fun_afun(F); proc = proc_spawn(proc_code_base(ctx), proc_atoms(ctx), mod, fun, args); if (proc == 0) return A_BADARG; result(proc_pid(proc, proc_gc_pool(ctx))); return AI_OK; }
/* * dbg_add_breakpoints(client, name, adr) * * Adds a breakpoint for client "client" with name "name" at address * "adr". Fails if a breakpoint already exists on the same address * * This function expects dbg_client_mtx to be locked and leaves it locked! * * Return value: * 0 Successful * != 0 Error * */ int dbg_add_breakpoint(dbg_client_t *client, const utf8_t *name, uintptr_t adr) { dbg_breaks_t *l__brk; /* Is there any existing breaking point for the same address? */ if (dbg_get_breakpoint(client, adr) != NULL) { dbg_isprintf("Breakpoint already exists for 0x%X at 0x%X.\n", client->client, adr); return 1; } /* Okay, just create one */ l__brk = mem_alloc(sizeof(dbg_breaks_t)); if (l__brk == NULL) { dbg_isprintf("Can't create breaking point 0x%X for client 0x%X, because of %i.\n", adr, client->client, *tls_errno); return 1; } /* Configure it */ str_copy(l__brk->name, name, 32); l__brk->address = adr; l__brk->count = 0; lst_add(client->breakpoints, l__brk); client->breakpoints_n ++; return 0; }
/** Create a list of surfaces. */ list356_t* get_surfaces() { debug("get_surfaces()") ; // Spheres along the negative x, y, and z axes. list356_t* surfaces = make_list() ; list356_t* bbt_surfaces = make_list() ; surface_t* z_sphere ; surface_t* green_sphere; for (float x=0.0; x>=-400.0; x-=1.0) { lst_add(bbt_surfaces, (green_sphere = make_sphere(x, 0.0, 0.0f, 1.0f, &GREEN, &GREEN, &WHITE, 100.0f))) ; // green_sphere->refl_color = &LIGHT_GREY; lst_add(bbt_surfaces, make_sphere(0.0f, x, 0.0f, .25, &PURPLE, &PURPLE, &WHITE, 100.0f)) ; lst_add(bbt_surfaces, (z_sphere = make_sphere(0.0f, 0.0f, x, .25, &PURPLE, &PURPLE, &WHITE, 100.0f))) ; z_sphere->refl_color = &LIGHT_GREY ; } lst_add(bbt_surfaces, make_sphere(-9.0f, 1.0f, -9.0f, 2.0f, &WHITE, &WHITE, &WHITE, 90.0f)); lst_add(bbt_surfaces, make_sphere(-9.0f, 1.0f, -8.0f, 2.0f, &WHITE, &WHITE, &WHITE, 90.0f)); lst_add(bbt_surfaces, make_sphere(-9.0f, 1.0f, -6.0f, 2.0f, &WHITE, &WHITE, &WHITE, 90.0f)); // A rectangle in the y=-1 plane. surface_t* tri1 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, 2}, (point3_t){2, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; surface_t* tri2 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, -20}, (point3_t){-40, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; tri1->refl_color = &DARK_GREY ; tri2->refl_color = &DARK_GREY ; lst_add(surfaces, tri1) ; lst_add(surfaces, tri2) ; // An infinite plane in the y=-2 plane. /* surface_t* plane = make_plane( (point3_t){-40, -2, 2}, (point3_t){2, -2, 2}, (point3_t){2, -2, -20}, &RED, &RED, &BLACK, 10.0f); plane->refl_color = &DARK_GREY; lst_add(surfaces, plane); */ lst_add(surfaces, make_bbt_node(bbt_surfaces)); return surfaces ; }
void engine_process_add(t_engine *engine, t_process *process) { lst_add(engine->processes, process, process->id.name); engine->process_count++; engine->process_id++; process->engine_id = engine->process_id; process->id.id = engine->process_id; }
/** Create a list of lights. */ list356_t* get_lights() { list356_t* lights = make_list() ; light_t* l = malloc(sizeof(light_t)) ; l->position = malloc(sizeof(point3_t)) ; *(l->position) = (point3_t){50.0f, 2.0f, 100.0f} ; l->color = malloc(sizeof(color_t)) ; *(l->color) = (color_t){1.0f, 1.0f, 1.0f} ; lst_add(lights, l) ; light_t* l2 = malloc(sizeof(light_t)) ; l2->position = malloc(sizeof(point3_t)) ; *(l2->position) = (point3_t){4.0f, 12.0f, 20.0f} ; l2->color = malloc(sizeof(color_t)) ; *(l2->color) = (color_t){.2f, .2f, .2f} ; lst_add(lights, l2) ; return lights ; }
void get_all_block_connected( t_block *block, t_lst *lst, int dir) { t_link *l; t_brick *brick; for( l = block->bricks->first; l; l= l->next) { brick = l->data; t_block *b = get_block_connected( brick, dir); if( b) lst_add( lst, b, "b"); } }
/** Create a list of lights. */ list356_t* get_lights() { list356_t* lights = make_list() ; light_t* l = malloc(sizeof(light_t)) ; l->position = malloc(sizeof(point3_t)) ; *(l->position) = (point3_t){50.0f, 50.0f, -50.0f} ; l->color = malloc(sizeof(color_t)) ; *(l->color) = (color_t){.75f, .75f, .75f} ; lst_add(lights, l) ; return lights ; }
int tbl_put(table_t *ct, connection_t *c) { int index = tbl_hash(c->client, c->server); if (ct->curr_size <= MAX_CONNECTIONS) { lst_add(ct->map[index], lst_create(c)); ct->curr_size++; return 0; } return 1; }
void glint_add_module_startup( t_context *C, t_module_method f) { t_module_startup *mod = ( t_module_startup *) malloc( sizeof( t_module_startup)); mod->done = 0; mod->method = f; t_node *node = scene_add( C->scene, dt_module, "startup"); t_module *module = ( t_module *) node->data; module->update = glint_module_startup; module->data = mod; lst_add( C->mode->modules, module, module->id.name); }
t_list *shortest_route(t_room *room) { t_room *tmp; int weight; t_list *route; t_list *name; tmp = room; route = NULL; while (tmp && tmp->end == 0) tmp = tmp->next; if (tmp->weight == 0) ft_error(7); weight = tmp->weight; route = lst_add(route, lst_new(tmp->name)); while (weight-- > 1) { name = tmp->links; tmp = room; tmp = find_next_node(weight, room, name); route = lst_add(route, lst_new(tmp->name)); } return (route); }
term_t proc_trace_locals(process_t *self) { term_t r = nil; term_t cons = nil; int i; for (i = self->ebp; i < self->cstack->nelts; i++) { term_t local = cstack(i); lst_add(r, cons, local, self->gc_cur); } self->locals_trace = r; return self->locals_trace; }
/** Create a list of surfaces. */ list356_t* get_surfaces() { debug("get_surfaces()") ; // Spheres along the negative x, y, and z axes. list356_t* surfaces = make_list() ; surface_t* z_sphere ; for (float x=0.0; x>=-40.0; x-=3.0) { lst_add(surfaces, make_sphere(x, 0.0, 0.0f, 1.0f, &GREEN, &GREEN, &WHITE, 100.0f)) ; lst_add(surfaces, make_sphere(0.0f, x, 0.0f, .25, &PURPLE, &PURPLE, &WHITE, 100.0f)) ; lst_add(surfaces, (z_sphere = make_sphere(0.0f, 0.0f, x, .25, &PURPLE, &PURPLE, &WHITE, 100.0f))) ; z_sphere->refl_color = &LIGHT_GREY ; } // A rectangle in the y=-1 plane. surface_t* tri1 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, 2}, (point3_t){2, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; surface_t* tri2 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, -20}, (point3_t){-40, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; tri1->refl_color = &DARK_GREY ; tri2->refl_color = &DARK_GREY ; lst_add(surfaces, tri1) ; lst_add(surfaces, tri2) ; return surfaces ; }
term_t bif_list_dir1(term_t Dir, process_t *ctx) { apr_status_t rs; apr_pool_t *p; const char *path; apr_dir_t *dir; term_t r = nil; term_t cons = nil; if (!is_string(Dir)) return A_BADARG; apr_pool_create(&p, 0); path = ltoz(Dir, p); rs = apr_dir_open(&dir, path, p); if (rs == 0) { apr_finfo_t fi; for (;;) { rs = apr_dir_read(&fi, APR_FINFO_NAME | APR_FINFO_SIZE, dir); if (rs == 0 || APR_STATUS_IS_INCOMPLETE(rs)) { term_t name = ztol(fi.name, proc_gc_pool(ctx)); lst_add(r, cons, name, proc_gc_pool(ctx)); } if (APR_STATUS_IS_ENOENT(rs)) { rs = APR_SUCCESS; break; } } apr_dir_close(dir); } if (rs != 0 && !APR_STATUS_IS_ENOENT(rs)) result(make_tuple2(A_ERROR, decipher_status(rs), proc_gc_pool(ctx))); else result(make_tuple2(A_OK, r, proc_gc_pool(ctx))); apr_pool_destroy(p); return AI_OK; }
term_t bif_list_dir3_0_1(term_t Dir, process_t *ctx) { apr_status_t rs; apr_pool_t *p; const char *path; apr_dir_t *dir; term_t r = nil; term_t cons = nil; apr_uint32_t wanted = APR_FINFO_MTIME | APR_FINFO_CTIME | APR_FINFO_ATIME | APR_FINFO_NAME | APR_FINFO_SIZE | APR_FINFO_TYPE | APR_FINFO_USER | APR_FINFO_GROUP | APR_FINFO_PROT; if (!is_string(Dir)) return A_BADARG; apr_pool_create(&p, 0); path = ltoz(Dir, p); rs = apr_dir_open(&dir, path, p); if (rs == 0) { apr_finfo_t fi; for (;;) { rs = apr_dir_read(&fi, wanted, dir); if (rs == 0 || APR_STATUS_IS_INCOMPLETE(rs)) { term_t file_info = make_file_info(&fi, proc_gc_pool(ctx)); lst_add(r, cons, file_info, proc_gc_pool(ctx)); } else if (APR_STATUS_IS_ENOENT(rs)) { rs = 0; break; } } apr_dir_close(dir); } if (rs != 0) result(make_tuple2(A_ERROR, decipher_status(rs), proc_gc_pool(ctx))); else result(make_tuple2(A_OK, r, proc_gc_pool(ctx))); apr_pool_destroy(p); return AI_OK; }
/* * dbg_export(name, value) * * Creates a variable "name" and sets its value to "value" * or changes the value of an existing variable "name" to "value". * * Return value: * 0 If successful * 1 If error * */ int dbg_export(const utf8_t *name, const utf8_t *value) { dbg_variable_t *l__vars; if ((name == NULL) || (value == NULL)) return 1; mtx_lock(&dbg_variables_mtx, -1); l__vars = dbg_get_variable(name); /* Is it a new one? */ if (l__vars == NULL) { /* Create it */ l__vars = mem_alloc(sizeof(dbg_variable_t)); if (l__vars == NULL) { mtx_unlock(&dbg_variables_mtx); dbg_isprintf("Can't allocate variable because of %i\n", *tls_errno); *tls_errno = 0; return 1; } /* Set its name / value */ str_copy(l__vars->name, name, 32); str_copy(l__vars->value, value, 32); /* Add it to the list */ lst_add(dbg_variables, l__vars); dbg_isprintf("Store new var to 0x%X, (n: 0x%X, v: 0x%X)\n", l__vars, l__vars->name, l__vars->value); mtx_unlock(&dbg_variables_mtx); return 0; } else /* It is an existing one */ { /* Change its value */ str_copy(l__vars->value, value, 32); dbg_isprintf("Store old var to 0x%X, (n: 0x%X, v: 0x%X)\n", l__vars, l__vars->name, l__vars->value); mtx_unlock(&dbg_variables_mtx); return 0; } }
term_t proc_list_registered(xpool_t *xp) { apr_hash_index_t *hi; term_t r = nil; term_t cons = nil; for (hi = apr_hash_first(0, registry); hi; hi = apr_hash_next(hi)) { process_t *proc; apr_hash_this(hi, 0, 0, (void **)&proc); if (proc->registered_name != A_UNDEFINED) lst_add(r, cons, proc->registered_name, xp); } return r; }
t_lst *block_leaves_get( t_block *block, int dir) { t_lst *branch = lst_new( "branch"); t_lst *bricks = block->bricks; t_link *l; t_block *target; t_brick *brick; for( l = bricks->first; l; l = l->next) { brick = l->data; target = get_block_connected( brick, dir); if( target) lst_add( branch, target, target->id.name); } return branch; }
void obj_add(const char *object_name,int tot_vert,int tot_face,int tot_quad,int tot_tri) { //printf("adding object:%s\n",object_name); t_context *C=ctx_get(); term_print(C->term,"+ obj"); t_obj *obj=obj_new(object_name); obj->tot_vert=tot_vert; obj->tot_face=tot_face; obj->tot_quad=tot_quad; obj->tot_tri=tot_tri; if(tot_vert) obj->verts=(float *)malloc(sizeof(float)*obj->tot_vert*3); if(tot_tri) obj->tris=(int *)malloc(sizeof(int)*obj->tot_tri*3); if(tot_quad) obj->quads=(int *)malloc(sizeof(int)*obj->tot_quad*4); lst_add(OBJECTS,obj,"obj"); }
term_t bif_list_dir2_1(term_t Dir, process_t *ctx) { apr_status_t rs; apr_pool_t *p; const char *path; apr_dir_t *dir; term_t r = nil; if (!is_string(Dir)) return A_BADARG; apr_pool_create(&p, 0); path = ltoz(Dir, p); rs = apr_dir_open(&dir, path, p); if (rs == 0) { term_t cons = nil; apr_finfo_t fi; for (;;) { term_t v; term_t name; rs = apr_dir_read(&fi, APR_FINFO_NAME | APR_FINFO_SIZE, dir); if (rs != 0) break; name = ztol(fi.name, proc_gc_pool(ctx)); if (fi.filetype == APR_DIR) v = make_tuple2(A_DIR, name, proc_gc_pool(ctx)); else if (fi.filetype == APR_REG) v = make_tuple3(A_FILE, name, intnum(fi.size), proc_gc_pool(ctx)); //TODO: large size else v = make_tuple2(A_UNKNOWN, name, proc_gc_pool(ctx)); lst_add(r, cons, v, proc_gc_pool(ctx)); } apr_dir_close(dir); } if (rs != 0 && !APR_STATUS_IS_ENOENT(rs)) result(make_tuple2(A_ERROR, decipher_status(rs), proc_gc_pool(ctx))); else result(make_tuple2(A_OK, r, proc_gc_pool(ctx))); apr_pool_destroy(p); return AI_OK; }
term_t port_get_list(xpool_t *xp) { term_t l = nil; term_t cons = nil; apr_hash_index_t *hi; if (ports == 0) return nil; for (hi = apr_hash_first(0, ports); hi; hi = apr_hash_next(hi)) { port_t *port; apr_hash_this(hi, 0, 0, (void **)&port); lst_add(l, cons, port_id(port, xp), xp); } return l; }
// copy a list t_lst *lst_copy(t_lst *lst) { if(lst->first) { t_lst *copy=lst_new(lst->name); t_link *link; for(link=lst->first;link;link=link->next) { void *data = link->data; lst_add(copy,data,link->name); } return copy; } else { return NULL; } }
void get_branch( t_block *block, t_lst *lst, int dir) { if( !block_in_list( block, lst)) { lst_add( lst, block, block->id.name); t_lst *bricks = block->bricks; t_brick *brick; t_block *target; t_link *l; for( l = bricks->first; l; l = l->next) { brick = l->data; target = get_block_connected( brick, dir); if( target) get_branch( target, lst, dir); } } }
/* * dbg_create_shell * * Creates a new shell. This function creates: * - a new shell structure * - a new shell thread * */ dbg_shell_t* dbg_create_shell(int terminal, sid_t client) { dbg_shell_t *l__shell = NULL; /* Found an existing shell for it? */ if ((l__shell = dbg_find_shell(terminal, client)) != NULL) { mtx_unlock(&dbg_shell_mutex); return l__shell; } /* Create the structure */ l__shell = mem_alloc(sizeof(dbg_shell_t)); if (l__shell == NULL) { dbg_isprintf("Can't create a shell structure for %i %i, because of %i\n", terminal, client, *tls_errno); } l__shell->terminal = terminal; l__shell->client = client; l__shell->cmd_buffer = NULL; l__shell->cmd = NULL; l__shell->pars = NULL; l__shell->n_pars = 0; l__shell->owner = blthr_create(&dbg_shell_thread, 65536); if (l__shell->owner == NULL) { dbg_isprintf("Can't create a shell thread for %i %i, because of %i.\n", terminal, client, *tls_errno); mem_free(l__shell); } mtx_lock(&dbg_shell_mutex, -1); lst_add(dbg_shells, l__shell); /* Start the thread */ blthr_awake(l__shell->owner); mtx_unlock(&dbg_shell_mutex); return l__shell; }
t_screen *screen_add_3d(const char *name, void (* draw)(t_screen *s)) { t_context *C=ctx_get(); t_node *node=scene_add(C->scene,dt_screen,name); t_screen *screen=node->data; screen->keymap=keymap_generic; screen->draw=draw; lst_add(C->ui->screens,node,name); // Lst t_node *node_lst = scene_add( C->scene, dt_list, "lst_screen"); t_lst *lst = node_lst->data; screen->viewports = lst; // Viewport t_node *node_viewport = scene_add( C->scene, dt_viewport, "viewport"); t_viewport *viewport = node_viewport->data; // Camera t_node *node_camera = scene_add( C->scene, dt_camera, name); t_camera *camera = node_camera->data; camera_add_controls( camera); viewport->camera = camera; viewport_add_controls( viewport); screen->width = C->app->window->width; screen->height = C->app->window->height; viewport->width = C->app->window->width; viewport->height = C->app->window->height; list_add_data(screen->viewports, viewport); return screen; }
term_t bif_list_embedded0(process_t *ctx) { term_t l = nil, cons = nil; xmod_bin_t *mp, *me; mp = (xmod_bin_t *)module_bins->elts; me = mp + module_bins->nelts; while (mp < me) { //{Mod,Size,IsPreloaded} term_t mod = atom(atoms_set(proc_atoms(ctx), mp->name)); term_t size = intnum(mp->size); term_t is_preloaded = bool(mp->is_preloaded); term_t triple = make_tuple3(mod, size, is_preloaded, proc_gc_pool(ctx)); lst_add(l, cons, triple, proc_gc_pool(ctx)); mp++; } result(l); return AI_OK; }
static _linkage_block_ * _add_line_to_linkage_block_ (Line *line_to_add, Line *linkage_block_line, List *linkage_block_lst) { _linkage_block_ *linkage_block; assert (line_to_add); assert (linkage_block_line); assert (linkage_block_lst); assert (!lst_is_empty (linkage_block_lst)); assert (line_to_add -> scale < linkage_block_line -> scale); for (linkage_block = lst_first (linkage_block_lst); linkage_block && linkage_block -> line != linkage_block_line; linkage_block = lst_next (linkage_block_lst)); if (linkage_block && linkage_block -> line == linkage_block_line) { lst_add (line_to_add, linkage_block -> candidate_line_lst); linkage_block -> nb_of_candidates ++; } return linkage_block; }