/** Release a Strophe connection object. * Decrement the reference count by one for a connection, freeing the * connection object if the count reaches 0. * * @param conn a Strophe connection object * * @return TRUE if the connection object was freed and FALSE otherwise * * @ingroup Connections */ int xmpp_conn_release(xmpp_conn_t * const conn) { xmpp_ctx_t *ctx; xmpp_connlist_t *item, *prev; xmpp_handlist_t *hlitem, *thli; hash_iterator_t *iter; const char *key; int released = 0; if (conn->ref > 1) conn->ref--; else { ctx = conn->ctx; /* remove connection from context's connlist */ if (ctx->connlist->conn == conn) { item = ctx->connlist; ctx->connlist = item->next; xmpp_free(ctx, item); } else { prev = NULL; item = ctx->connlist; while (item && item->conn != conn) { prev = item; item = item->next; } if (!item) { xmpp_error(ctx, "xmpp", "Connection not in context's list\n"); } else { prev->next = item->next; xmpp_free(ctx, item); } } _conn_reset(conn); /* free handler stuff * note that userdata is the responsibility of the client * and the handler pointers don't need to be freed since they * are pointers to functions */ hlitem = conn->timed_handlers; while (hlitem) { thli = hlitem; hlitem = hlitem->next; xmpp_free(ctx, thli); } /* id handlers * we have to traverse the hash table freeing list elements * then release the hash table */ iter = hash_iter_new(conn->id_handlers); while ((key = hash_iter_next(iter))) { hlitem = (xmpp_handlist_t *)hash_get(conn->id_handlers, key); while (hlitem) { thli = hlitem; hlitem = hlitem->next; xmpp_free(conn->ctx, thli->id); xmpp_free(conn->ctx, thli); } } hash_iter_release(iter); hash_release(conn->id_handlers); hlitem = conn->handlers; while (hlitem) { thli = hlitem; hlitem = hlitem->next; if (thli->ns) xmpp_free(ctx, thli->ns); if (thli->name) xmpp_free(ctx, thli->name); if (thli->type) xmpp_free(ctx, thli->type); xmpp_free(ctx, thli); } parser_free(conn->parser); if (conn->jid) xmpp_free(ctx, conn->jid); if (conn->pass) xmpp_free(ctx, conn->pass); if (conn->lang) xmpp_free(ctx, conn->lang); xmpp_free(ctx, conn); released = 1; } return released; }
queue_driver_type * site_config_get_queue_driver(const site_config_type * site_config, const char * driver_name) { return hash_get(site_config->queue_drivers, driver_name); }
Value eval_list(Value expression, Environment *environment) { w_assert(expression.type == CONS); Bool lambda_call = false; Value function_symbol = NEXT(expression); Value lambda; Function *function; if (function_symbol.type == CONS) { if (CAR(function_symbol).type == SYMBOL && CAR(function_symbol).val.symbol_val == symbols_lambda.val.symbol_val) { lambda = eval(function_symbol, environment); lambda_call = true; } else { return VALUE_ERROR; } } else if (function_symbol.type == LAMBDA) { lambda = function_symbol; lambda_call = true; } else if (function_symbol.type == SYMBOL) { Value function_value; Bool found = hash_get(environment -> functions, function_symbol, &function_value); if (!found) { /* TODO: log error */ /* TODO: "Did you mean?" */ debug_value(function_symbol); log_error("Function XXX not found"); return VALUE_ERROR; } w_assert(function_value.type == FUNCTION); function = function_value.val.function_val; } else { return VALUE_ERROR; } Value args; if (lambda_call || function -> eval) { args = VALUE_NIL; while (expression.type == CONS) { Value arg = NEXT(expression); args = CONS(eval(arg, environment), args); } args = list_reverse(args); w_assert(expression.type == NIL); /* TODO: benchmark, which approach is better, the above or below? */ /* if (expression.type == CONS) { */ /* args = CONS1(VALUE_NIL); */ /* } else { */ /* args = expression; */ /* } */ /* Cons *top = args.val.cons_val; */ /* while (true) { */ /* Value arg = NEXT(expression); */ /* top -> car = eval(arg, environment); */ /* if (expression.type == CONS) { */ /* top -> cdr = CONS1(VALUE_NIL); */ /* top = top -> cdr.val.cons_val; */ /* } else { */ /* top -> cdr = expression; */ /* break; */ /* } */ /* } */ } else { /* To ensure we avoid mutation in altering code the list is copied If we guaranteed that no function with eval = false modifies the list we could give it directly This would be an obvious performance optimization. But needs tests. We can only guarantee this for c_code, not for userdefined macros. TODO: Do this */ args = list_copy(expression); } Value result; if (lambda_call) { result = eval_lambda(lambda, args, environment); } else { result = eval_apply(function_symbol, function, args, environment); } list_destroy(args); return result; }
static int shell_cmd_show(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { const char *help = "show - Display simulation objects\n" "\n" "Usage: show LIST...\n" "\n" "Prints a representation of each simulation object in LIST. Typically\n" "this will be a list of signal names and the output will show their\n" "current value.\n" "\n" "Examples:\n" " show {:top:foo} Print value of signal :top_foo\n" " show [signals] Print value of all signals\n"; if (show_help(objc, objv, help)) return TCL_OK; if (objc == 1) { warnf("nothing to show (try -help for usage)"); return TCL_OK; } hash_t *decl_hash = (hash_t *)cd; for (int i = 1; i < objc; i++) { int length; if (Tcl_ListObjLength(interp, objv[i], &length) != TCL_OK) return TCL_ERROR; for (int j = 0; j < length; j++) { Tcl_Obj *obj; if (Tcl_ListObjIndex(interp, objv[i], j, &obj) != TCL_OK) return TCL_ERROR; const char *str = Tcl_GetString(obj); tree_t t = hash_get(decl_hash, ident_new(str)); if (t == NULL) return tcl_error(interp, "object not found: %s", str); tree_kind_t kind = tree_kind(t); switch (kind) { case T_SIGNAL_DECL: { const size_t len = tree_nets(t); uint64_t *values LOCAL = xmalloc(len * sizeof(uint64_t)); rt_signal_value(t, values, len); const char *type_str = type_pp(tree_type(t)); const char *short_name = strrchr(type_str, '.'); LOCAL_TEXT_BUF values_tb = pprint(t, values, len); printf("%-30s%-20s%s\n", str, (short_name != NULL ? short_name + 1 : type_str), tb_get(values_tb)); } break; default: return tcl_error(interp, "cannot show tree kind %s", tree_kind_str(kind)); } } } return TCL_OK; }
ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index) { const int_vector_type * index_vector = hash_get(rft_file->well_index , well); return ecl_rft_file_iget_node( rft_file , int_vector_iget(index_vector , index)); }
void ensemble_config_init_FIELD( ensemble_config_type * ensemble_config , const config_type * config , ecl_grid_type * grid) { const config_content_item_type * item = config_get_content_item( config , FIELD_KEY ); if (item != NULL) { int i; for (i=0; i < config_content_item_get_size( item ); i++) { const config_content_node_type * node = config_content_item_iget_node( item , i ); const char * key = config_content_node_iget( node , 0 ); const char * var_type_string = config_content_node_iget( node , 1 ); enkf_config_node_type * config_node; { hash_type * options = hash_alloc(); int truncation = TRUNCATE_NONE; double value_min = -1; double value_max = -1; config_content_node_init_opt_hash( node , options , 2 ); if (hash_has_key( options , MIN_KEY)) { truncation |= TRUNCATE_MIN; value_min = atof(hash_get( options , MIN_KEY)); } if (hash_has_key( options , MAX_KEY)) { truncation |= TRUNCATE_MAX; value_max = atof(hash_get( options , MAX_KEY)); } if (strcmp(var_type_string , DYNAMIC_KEY) == 0) { config_node = ensemble_config_add_field( ensemble_config , key , grid , false); enkf_config_node_update_state_field( config_node , truncation , value_min , value_max ); } else if (strcmp(var_type_string , PARAMETER_KEY) == 0) { const char * ecl_file = config_content_node_iget( node , 2 ); const char * init_file_fmt = hash_safe_get( options , INIT_FILES_KEY ); const char * init_transform = hash_safe_get( options , INIT_TRANSFORM_KEY ); const char * output_transform = hash_safe_get( options , OUTPUT_TRANSFORM_KEY ); const char * min_std_file = hash_safe_get( options , MIN_STD_KEY ); const char * forward_string = hash_safe_get( options , FORWARD_INIT_KEY ); bool forward_init = false; if (forward_string) { if (!util_sscanf_bool( forward_string , &forward_init)) fprintf(stderr,"** Warning: parsing %s as bool failed - using FALSE \n",forward_string); } config_node = ensemble_config_add_field( ensemble_config , key , grid , forward_init); enkf_config_node_update_parameter_field( config_node, ecl_file , init_file_fmt , min_std_file , truncation , value_min , value_max , init_transform , output_transform ); } else if (strcmp(var_type_string , GENERAL_KEY) == 0) { /* General - not really interesting .. */ const char * ecl_file = config_content_node_iget( node , 2 ); const char * enkf_infile = config_content_node_iget( node , 3 ); const char * init_file_fmt = hash_safe_get( options , INIT_FILES_KEY ); const char * init_transform = hash_safe_get( options , INIT_TRANSFORM_KEY ); const char * output_transform = hash_safe_get( options , OUTPUT_TRANSFORM_KEY ); const char * input_transform = hash_safe_get( options , INPUT_TRANSFORM_KEY ); const char * min_std_file = hash_safe_get( options , MIN_STD_KEY ); const char * forward_string = hash_safe_get( options , FORWARD_INIT_KEY ); bool forward_init = false; if (forward_string) { if (!util_sscanf_bool( forward_string , &forward_init)) fprintf(stderr,"** Warning: parsing %s as bool failed - using FALSE \n",forward_string); } config_node = ensemble_config_add_field( ensemble_config , key , grid , forward_init); enkf_config_node_update_general_field( config_node, ecl_file , enkf_infile , init_file_fmt , min_std_file , truncation , value_min , value_max , init_transform , input_transform , output_transform); } else util_abort("%s: field type: %s is not recognized\n",__func__ , var_type_string); hash_free( options ); } } } }
int main(int argc, char **argv) { int r, op = 'p', method = 'c'; const char *path; if (argc < 2) { fprintf(stderr, "usage: kv dbpath [put|get] [col|table|hash|pat|ql] [value_size]\n"); return -1; } path = *argv[1] ? argv[1] : NULL; if (argc > 2) { op = *argv[2]; } if (argc > 3) { method = *argv[3]; } if (argc > 4) { value_size = atoi(argv[4]); } if (argc > 5) { nloops = atoi(argv[5]); } if (grn_init()) { fprintf(stderr, "grn_init() failed\n"); return -1; } if (grn_ctx_init(&ctx, (method == 'q' ? GRN_CTX_USE_QL|GRN_CTX_BATCH_MODE : 0))) { fprintf(stderr, "grn_ctx_init() failed\n"); return -1; } srand(0); if (method == 'h' || method == 'p') { switch (method) { case 'h' : r = (op == 'p') ? hash_put(path) : hash_get(path); break; case 'p' : r = (op == 'p') ? pat_put(path) : pat_get(path); break; default : r = -1; fprintf(stderr, "invalid method\n"); break; } } else { if (path) { db = grn_db_open(&ctx, path); } if (!db) { db = grn_db_create(&ctx, path, NULL); } if (!db) { fprintf(stderr, "db initialize failed\n"); return -1; } value_type = grn_type_create(&ctx, "<value_type>", 12, 0, value_size); switch (method) { case 'q' : r = (op == 'p') ? ql_put() : ql_get(); break; case 'c' : r = (op == 'p') ? column_put() : column_get(); break; case 't' : r = (op == 'p') ? table_put() : table_get(); //r = (op == 'p') ? table_put_allocate() : table_get(); //r = (op == 'p') ? table_put2() : table_get(); break; default : r = -1; fprintf(stderr, "invalid method\n"); break; } if (grn_obj_close(&ctx, db)) { fprintf(stderr, "grn_obj_close() failed\n"); return -1; } } if (grn_ctx_fin(&ctx)) { fprintf(stderr, "grn_ctx_fin() failed\n"); return -1; } if (grn_fin()) { fprintf(stderr, "grn_fin() failed\n"); return -1; } return r; }
int main( int argc, char ** argv) { if (argc == 1) util_exit("block_node node1 node2 node3:2 \n"); /* Initialize lsf environment */ util_setenv( "LSF_BINDIR" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/bin" ); util_setenv( "LSF_LINDIR" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib" ); util_setenv( "XLSF_UIDDIR" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib/uid" ); util_setenv( "LSF_SERVERDIR" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/etc"); util_setenv( "LSF_ENVDIR" , "/prog/LSF/conf"); util_update_path_var( "PATH" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/bin" , false); util_update_path_var( "LD_LIBRARY_PATH" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib" , false); lsf_driver = lsf_driver_alloc(); if (lsf_driver_get_submit_method( lsf_driver ) != LSF_SUBMIT_INTERNAL) util_exit("Sorry - the block_node program must be invoked on a proper LSF node \n"); { int iarg; int total_blocked_target = 0; nodes = hash_alloc(); for (iarg = 1; iarg < argc; iarg++) { char *node_name; int num_slots; { char * num_slots_string; util_binary_split_string( argv[iarg] , ":" , true , &node_name , &num_slots_string); if (num_slots_string) util_sscanf_int( num_slots_string , &num_slots); else num_slots = 1; } if (!hash_has_key( nodes , node_name)) hash_insert_hash_owned_ref( nodes , node_name , count_pair_alloc() , free); { count_pair_type * pair = hash_get( nodes , node_name); pair->target += num_slots; } total_blocked_target += num_slots; } signal(SIGINT , block_node_exit ); { const int sleep_time = 5; const int chunk_size = 10; /* We submit this many at a time. */ const int max_pool_size = 1000; /* The absolute total maximum of jobs we will submit. */ bool cont = true; int pending = 0; bool all_blocked; job_pool = vector_alloc_new(); while (cont) { printf("[Ctrl-C to give up] "); fflush( stdout ); if (cont) sleep( sleep_time ); if (pending == 0) { if (vector_get_size( job_pool ) < max_pool_size) add_jobs( chunk_size ); } update_pool_status( &all_blocked , &pending); print_status(); if (all_blocked) cont = false; } if (!all_blocked) printf("Sorry - failed to block all the nodes \n"); block_node_exit( 0 ); hash_free( nodes ); } } }
/** If command to complete is short enough, substitute the description with the whatis information for the executable. */ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp ) { int i; const wchar_t *cmd_start; int cmd_len; wchar_t *lookup_cmd=0; array_list_t list; hash_table_t lookup; wchar_t *esc; int skip; if( !cmd ) return; cmd_start=wcsrchr(cmd, L'/'); if( cmd_start ) cmd_start++; else cmd_start = cmd; cmd_len = wcslen(cmd_start); /* Using apropos with a single-character search term produces far to many results - require at least two characters if we don't know the location of the whatis-database. */ if(cmd_len < 2 ) return; if( wildcard_has( cmd_start, 0 ) ) { return; } skip = 1; for( i=0; i<al_get_count( comp ); i++ ) { completion_t *c = (completion_t *)al_get( comp, i ); if( !wcslen( c->completion) || (c->completion[wcslen(c->completion)-1] != L'/' )) { skip = 0; break; } } if( skip ) { return; } esc = escape( cmd_start, 1 ); lookup_cmd = wcsdupcat( L"__fish_describe_command ", esc ); free(esc); al_init( &list ); hash_init( &lookup, &hash_wcs_func, &hash_wcs_cmp ); /* First locate a list of possible descriptions using a single call to apropos or a direct search if we know the location of the whatis database. This can take some time on slower systems with a large set of manuals, but it should be ok since apropos is only called once. */ if( exec_subshell( lookup_cmd, &list ) != -1 ) { /* Then discard anything that is not a possible completion and put the result into a hashtable with the completion as key and the description as value. Should be reasonably fast, since no memory allocations are needed. */ for( i=0; i<al_get_count( &list); i++ ) { wchar_t *el = (wchar_t *)al_get( &list, i ); wchar_t *key, *key_end, *val_begin; if( !el ) continue; key = el+wcslen(cmd_start); key_end = wcschr( key, L'\t' ); if( !key_end ) continue; *key_end = 0; val_begin = key_end+1; /* And once again I make sure the first character is uppercased because I like it that way, and I get to decide these things. */ val_begin[0]=towupper(val_begin[0]); hash_put( &lookup, key, val_begin ); } /* Then do a lookup on every completion and if a match is found, change to the new description. This needs to do a reallocation for every description added, but there shouldn't be that many completions, so it should be ok. */ for( i=0; i<al_get_count(comp); i++ ) { completion_t *c = (completion_t *)al_get( comp, i ); const wchar_t *el = c->completion; wchar_t *new_desc; new_desc = (wchar_t *)hash_get( &lookup, el ); if( new_desc ) { c->description = halloc_wcsdup( comp, new_desc ); } } } hash_destroy( &lookup ); al_foreach( &list, &free ); al_destroy( &list ); free( lookup_cmd ); }
well_history_type * sched_history_get_well( const sched_history_type * sched_history , const char * well_name ) { return hash_get( sched_history->well_history , well_name ); }
group_history_type * sched_history_get_group( const sched_history_type * sched_history , const char * group_name ) { return hash_get( sched_history->group_history , group_name ); }
void sched_history_install_index( sched_history_type * sched_history ) { /*1: Installing well based keys like WOPRH. */ { hash_iter_type * well_iter = hash_iter_alloc( sched_history->well_history ); while (!hash_iter_is_complete( well_iter )) { const char * well_name = hash_iter_get_next_key( well_iter ); const well_history_type * well = hash_get( sched_history->well_history , well_name ); /* WOPR */ { well_index_type * well_index = well_index_alloc( well_name , "WOPRH" , well , WCONHIST , wconhist_state_iget_WOPRH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WOPR" , "WOPRH") , well_name); } /* WGPR */ { well_index_type * well_index = well_index_alloc( well_name , "WGPRH" , well , WCONHIST , wconhist_state_iget_WGPRH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WGPR" , "WGPRH") , well_name); } /* WWPR */ { well_index_type * well_index = well_index_alloc( well_name , "WWPRH" , well , WCONHIST , wconhist_state_iget_WWPRH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WWPR" , "WWPRH") , well_name); } /* WWCT */ { well_index_type * well_index = well_index_alloc( well_name , "WWCTH" , well , WCONHIST , wconhist_state_iget_WWCTH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WWCT" , "WWCTH") , well_name); } /* WGOR */ { well_index_type * well_index = well_index_alloc( well_name , "WGORH" , well , WCONHIST , wconhist_state_iget_WGORH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WGOR" , "WGORH") , well_name); } /* WGPT */ { well_index_type * well_index = well_index_alloc( well_name , "WGPTH" , well , WCONHIST , wconhist_state_iget_WGPTH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WGPT" , "WGPTH") , well_name); } /* WOPT */ { well_index_type * well_index = well_index_alloc( well_name , "WOPTH" , well , WCONHIST , wconhist_state_iget_WOPTH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WOPT" , "WOPTH") , well_name); } /* WWPT */ { well_index_type * well_index = well_index_alloc( well_name , "WWPTH" , well , WCONHIST , wconhist_state_iget_WWPTH ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("WWPT" , "WWPTH") , well_name); } /* STAT */ { well_index_type * well_index = well_index_alloc( well_name , "STAT" , well , WCONHIST , wconhist_state_iget_STAT ); sched_history_install_well_index( sched_history , well_index , VAR_LIST("STAT" ) , well_name); } /* WWIRH - this can be got from _either_ the WCONINJH keyowrord or the WCONINJE keyword (provided the latter is in rate controlled mode. ) */ { well_index_type * well_index = well_index_alloc( well_name , "WWIRH" , well , WCONINJH , wconinjh_state_iget_WWIRH ); /* The first type */ well_index_add_type( well_index , WCONINJE , wconinje_state_iget_WWIRH ); /* The second type */ sched_history_install_well_index( sched_history , well_index , VAR_LIST("WWIRH" , "WWIR") , well_name); } /* WGIRH - this can be got from _either_ the WCONINJH keyowrord or the WCONINJE keyword (provided the latter is in rate controlled mode. ) */ { well_index_type * well_index = well_index_alloc( well_name , "WGIRH" , well , WCONINJH , wconinjh_state_iget_WGIRH ); /* The first type */ well_index_add_type( well_index , WCONINJE , wconinje_state_iget_WGIRH ); /* The second type */ sched_history_install_well_index( sched_history , well_index , VAR_LIST("WGIRH" , "WGIR") , well_name); } } hash_iter_free( well_iter ); } /*2: Installing group based indices */ { hash_iter_type * group_iter = hash_iter_alloc( sched_history->group_history ); while (!hash_iter_is_complete( group_iter )) { const char * group_name = hash_iter_get_next_key( group_iter ); const group_history_type * group = hash_get( sched_history->group_history , group_name ); /* GOPR */ { group_index_type * group_index = group_index_alloc( group_name , "GOPRH" , group , group_history_iget_GOPRH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GOPR" , "GOPRH") , group_name); } /* GGPR */ { group_index_type * group_index = group_index_alloc( group_name , "GGPRH" , group , group_history_iget_GGPRH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GGPR" , "GGPRH") , group_name); } /* GWPR */ { group_index_type * group_index = group_index_alloc( group_name , "GWPRH" , group , group_history_iget_GWPRH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GWPR" , "GWPRH") , group_name); } /* GWCT */ { group_index_type * group_index = group_index_alloc( group_name , "GWCTH" , group , group_history_iget_GWCTH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GWCT" , "GWCTH") , group_name); } /* GGOR */ { group_index_type * group_index = group_index_alloc( group_name , "GGORH" , group , group_history_iget_GGORH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GGOR" , "GGORH") , group_name); } /* GOPT */ { group_index_type * group_index = group_index_alloc( group_name , "GOPTH" , group , group_history_iget_GOPTH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GOPT" , "GOPTH") , group_name); } /* GGPT */ { group_index_type * group_index = group_index_alloc( group_name , "GGPTH" , group , group_history_iget_GGPTH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GGPT" , "GGPTH") , group_name); } /* GWPT */ { group_index_type * group_index = group_index_alloc( group_name , "GWPTH" , group , group_history_iget_GWPTH ); sched_history_install_group_index( sched_history , group_index , VAR_LIST("GWPT" , "GWPTH") , group_name); } } hash_iter_free( group_iter ); } /*3: Installing field based indices (which is just an alias to the FIELD group); */ { const group_history_type * group = hash_get( sched_history->group_history , FIELD_GROUP ); const char * group_name = FIELD_GROUP; /* FWPRH */ { group_index_type * group_index = group_index_alloc( group_name , "GWPRH" , group , group_history_iget_GWPRH ); hash_insert_hash_owned_ref( sched_history->index , "FWPRH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FWPR" , group_index); } /* FOPRH */ { group_index_type * group_index = group_index_alloc( group_name , "GOPRH" , group , group_history_iget_GOPRH ); hash_insert_hash_owned_ref( sched_history->index , "FOPRH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FOPR" , group_index); } /* FGPRH */ { group_index_type * group_index = group_index_alloc( group_name , "GGPRH" , group , group_history_iget_GGPRH ); hash_insert_hash_owned_ref( sched_history->index , "FGPRH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FGPR" , group_index); } /* FWPTH */ { group_index_type * group_index = group_index_alloc( group_name , "GWPTH" , group , group_history_iget_GWPTH ); hash_insert_hash_owned_ref( sched_history->index , "FWPTH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FWPT" , group_index); } /* FOPTH */ { group_index_type * group_index = group_index_alloc( group_name , "GOPTH" , group , group_history_iget_GOPTH ); hash_insert_hash_owned_ref( sched_history->index , "FOPTH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FOPT" , group_index); } /* FGPTH */ { group_index_type * group_index = group_index_alloc( group_name , "GGPTH" , group , group_history_iget_GGPTH ); hash_insert_hash_owned_ref( sched_history->index , "FGPTH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FGPT" , group_index); } /* FGORH */ { group_index_type * group_index = group_index_alloc( group_name , "GGORH" , group , group_history_iget_GGORH ); hash_insert_hash_owned_ref( sched_history->index , "FGORH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FGOR" , group_index); } /* FWCTH */ { group_index_type * group_index = group_index_alloc( group_name , "GWCTH" , group , group_history_iget_GWCTH ); hash_insert_hash_owned_ref( sched_history->index , "FWCTH" , group_index , group_index_free__ ); hash_insert_ref( sched_history->index , "FWCT" , group_index); } } }
int main(int argc, char **argv) { hash_t h; elt *elts, *p; int nelts = 0; char *c; int i; do { hash_zero(&h); if( argc>1 ) { nelts = strtoul(argv[1], &c, 0); } if( nelts == 0 ) { nelts = 1000; } elts = (elt*)calloc(nelts*sizeof(*elts),1); test_string(nelts); hash_init(&h, hash_hash_int, hash_cmp_int, 0, 0, 1); // put everything in for(i=0, p=elts; i<nelts; i++, p++) { p->in_hash = 1; hash_put(&h, p, p); } verify(&h, elts, nelts, "put"); verify(&h, elts, nelts, "put"); // delete every even element for(i=0, p=elts; i<nelts; i+=2, p+=2) { p->in_hash = 0; hash_free(&h, hash_get(&h, p)); } verify(&h, elts, nelts, "delete even"); // delete every odd element for(i=1, p=elts+1; i<nelts; i+=2, p+=2) { p->in_hash = 0; hash_free(&h, hash_get(&h, p)); } verify(&h, elts, nelts, "delete odd"); // randomly insert and delete stuff for(i=0; i<3*nelts; i++) { int j = (int)(1.0*nelts*rand()/RAND_MAX); p = elts + j; if( (int)(10.0*rand()/RAND_MAX)+1 > 1 ) { p->in_hash = 1; hash_put(&h, p, p); } else { p->in_hash = 0; hash_free(&h, hash_get(&h, p)); } } verify(&h, elts, nelts, "random insert/delete"); hash_clear(&h); /* loop forever looking for memory leak */ if( 0 ) { hash_init(&h, hash_hash_int, hash_cmp_int, 0, 0, 1); for(i=0; ;i++) { hash_node_t *node; hash_remove(&h, (void*)(intptr_t)(i-1)); hash_put(&h, (void*)(intptr_t)i, (void*)(intptr_t)i); node = hash_get(&h, (void*)(intptr_t)(i-1)); assertb(!node); node = hash_get(&h, (void*)(intptr_t)i); assertb(node); assertb((intptr_t)node->node_val == i); } } } while(0); return 0; }
/** * generate a response from a request */ int srv_resp_generate(resp_t * resp, const char *root, const char *req, const char *index, struct req_param *params, unsigned int param_cnt, hash_t * hide, hash_t * mps) { struct stat st, ind; file_t *list; resp_t *cache; struct _modfunc *mf; unsigned int res, cnt; unsigned int i, size; struct tm *tm; time_t blah; char *path, *ext; char *ind_path; char date[30]; struct _respptr *pt; struct srv_mod_trans mt; #ifdef DEBUG assert(NULL != resp); assert(NULL != req); assert(NULL != root); assert(NULL != index); #endif time(&blah); tm = gmtime(&blah); mf = NULL; /* clear the filename */ if (resp->file) free(resp->file); /* clear the pre-existing data */ if (resp->pregen && resp->data) free(resp->data); memset(&mt, 0, sizeof mt); memset(resp, 0, sizeof *resp); strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", tm); path = srv_fix_req_path(root, (char *)req); if (NULL != (mf = (struct _modfunc *)hash_get(mps, req))) { DEBUGF(__FILE__, __LINE__, "checking if %s needs a handler...\n", path); /* gotta handle this bitch with the function */ if (NULL != (resp->data = mf->func(path, &mt, params, param_cnt))) { resp->pregen = 1; resp->len = mt.len; resp->type = mt.ftype; resp->code = (mt.status) ? RESP_HTTP_200 : RESP_HTTP_404; snprintf(resp->header, sizeof resp->header, "HTTP/1.1 %s %s\r\n" "Connection: close\r\n" "Date: %s\r\n" "Server: srv/0.1.1\r\n" "Content-Length: %lu\r\n" "Content-Type: %s\r\n" "\r\n", resp_status[resp->code][0], resp_status[resp->code][1], date, (long unsigned)resp->len, mime_types[resp->type][1]); } else { /* TODO: gotta add error handling */ srv_resp_404(resp); } return 1; } if (stat(path, &st)) { /* something happened */ switch (errno) { case EACCES: srv_resp_403(resp); free(path); return 1; default: srv_resp_404(resp); free(path); return 1; } } /* check if this file is cached, and if so, what's the deal */ if (NULL != (pt = (struct _respptr *)hash_get(hide, path))) { /* get the goodies */ resp = pt->r; #if 0 if (RESP_HTTP_403 == cache->code) { /* we're done! */ fprintf(stderr, "zoom!\n"); resp = cache; free(path); return 1; } else if (st.st_mtime > cache->mtime) { /* been updated since last cache */ if (srv_resp_cache(cache, path)) { resp = cache; resp->mtime = st.st_mtime; } fprintf(stderr, "sching!\n"); free(path); return 1; } #endif } if (S_ISDIR(st.st_mode)) { ind_path = srv_fix_req_path(path, (char *)index); if (!stat(ind_path, &ind)) { /* the index exists in this directory */ resp->len = ind.st_size; resp->file = ind_path; /* keep the name around */ ext = srv_get_extension(ind_path); if (NULL == ext) { resp->type = 0; } else { for (i = 1; i < MIME_TYPE_CNT; i++) { if (!strcmp(ext, mime_types[i][0])) { /* found it! */ resp->type = i; break; } } } } else { /* it's a directory so lets list that shiiit */ list = srv_list_dir(path, &cnt); if (NULL == list) { /* couldn't build it? */ return 0; } resp->pregen = 1; resp->data = srv_build_dir_index(req, list, cnt); resp->len = strlen(resp->data); resp->type = 9; /* text/html */ srv_filelist_free(list, cnt); free(ind_path); /* lose the path */ } } else { resp->len = st.st_size; #if 0 /* should we cache? */ if (resp->len <= 512000) resp->cache = 1; #endif resp->file = strdup(path); ext = srv_get_extension(path); if (NULL == ext) { resp->type = 0; } else { for (i = 1; i < MIME_TYPE_CNT; i++) { if (!strcmp(ext, mime_types[i][0])) { /* found it! */ resp->type = i; break; } } } } resp->code = RESP_HTTP_200; snprintf(resp->header, sizeof resp->header, "HTTP/1.1 %s %s\r\n" "Connection: close\r\n" "Date: %s\r\n" "Server: srv/0.1.1\r\n" "Content-Length: %lu\r\n" "Content-Type: %s\r\n" "\r\n", resp_status[RESP_HTTP_200][0], resp_status[RESP_HTTP_200][1], date, (long unsigned)resp->len, mime_types[resp->type][1]); #if 0 /* cache it */ if (resp->cache) { srv_resp_cache(resp, path); hash_insert(hide, path, resp); fprintf(stderr, "foop!\n"); } #endif free(path); return 1; }
int main(int argc, char **argv) { char buf[1024]; char *string[1024]; char *ptr, *chkstr; int loop, ctr = 0; hash_t *hash; testinfo("creating hash table"); if(!(hash = hash_create(0, strkey, free))) errkill(-1, "failed (%s)", strerror(errno)); passed(); /* load strings */ printf("\nloading strings from stdin:\n"); while(fgets(buf, sizeof(buf), stdin)) { printf("reading %i:", ctr); fflush(stdout); /* chomp newline */ ptr = ((buf + strlen(buf)) - 1); if((ptr >= buf) && (*ptr == '\n')) *ptr = 0; if(!ctr && !(chkstr = strdup(buf))) errkill(-1, "error loading strings"); if(!(string[ctr++] = strdup(buf))) errkill(-1, "error loading strings"); printf("[%s]\n", string[ctr - 1]); if(ctr >= 1024) break; } /* store strings in hash */ printf("\nstoring strings in hash:\n"); for(loop=0; loop<ctr; loop++) { testinfo("storing [%s]...", string[loop]); if(hash_set(hash, string[loop], string[loop])) errkill(-1, "failed"); passed(); } /* test values */ printf("\nlooking up stored values:\n"); for(loop=0; loop<ctr; loop++) { testinfo("testing [%s]", string[loop]); if(!(ptr = hash_get(hash, string[loop]))) errkill(-1, "failed"); if(strcmp(ptr, string[loop])) errkill(-1, "error"); passed(); } testinfo("\ntesting hash reset"); hash_reset(hash); if(hash_get(hash, chkstr)) errkill(-1, "reset failed"); free(chkstr); passed(); testinfo("\nfreeing hash table"); hash_free(hash); passed(); printf("\n-- all tests passed --\n\n"); return(0); }
/** * Need doxygen comment */ int cmd_workspace() { revmjob_t *job; u_int idx; u_int index; char logbuf[BUFSIZ]; char *nl; char *time; elfshobj_t *obj; char **keys; int keynbr; char **loadedkeys; int loadedkeynbr; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); //printf("workspace argc %u \n", world.curjob->curcmd->argc); switch (world.curjob->curcmd->argc) { /* $ workspace */ case 0: revm_output(" .::. Workspaces .::. \n"); keys = hash_get_keys(&world.jobs, &keynbr); for (index = 0; index < keynbr; index++) { job = (revmjob_t *) hash_get(&world.jobs, keys[index]); if (revm_own_job(job)) { time = ctime(&job->ws.createtime); nl = strchr(time, '\n'); if (nl) *nl = 0x00; snprintf(logbuf, BUFSIZ - 1, " [%s] %s %c \n", keys[index], time, (job->ws.active ? '*' : ' ')); revm_output(logbuf); if (hash_size(&job->loaded)) { loadedkeys = hash_get_keys(&job->loaded, &loadedkeynbr); for (idx = 0; idx < loadedkeynbr; idx++) { obj = hash_get(&job->loaded, loadedkeys[idx]); snprintf(logbuf, BUFSIZ - 1, " \t %c %s \n", (job->curfile == obj ? '*' : ' '), obj->name); revm_output(logbuf); } } else { snprintf(logbuf, BUFSIZ - 1, " \t No files\n"); revm_output(logbuf); } } } revm_output("\n"); PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0); /* $ workspace name */ case 1: PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, revm_create_new_workspace(revm_get_cur_job_parameter(0))); /* Unknown command format */ default: PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Wrong arg number", -1); } }
void ensemble_config_add_obs_key(ensemble_config_type * ensemble_config , const char * key, const char * obs_key) { enkf_config_node_type * config_node = hash_get(ensemble_config->config_nodes , key); enkf_config_node_add_obs_key(config_node , obs_key); }
/** Main function. Parses options and calls helper function for any heavy lifting. */ int main (int argc, char *argv[]) { int input_type=FILEDATA; int output_type=MIMETYPE; const char *mimetype; char *output=0; int i; hash_table_t launch_hash; locale_init(); /* Parse options */ while( 1 ) { static struct option long_options[] = { { "input-file-data", no_argument, 0, 't' } , { "input-filename", no_argument, 0, 'f' } , { "input-mime", no_argument, 0, 'i' } , { "output-mime", no_argument, 0, 'm' } , { "output-description", no_argument, 0, 'd' } , { "output-action", no_argument, 0, 'a' } , { "help", no_argument, 0, 'h' } , { "version", no_argument, 0, 'v' } , { "launch", no_argument, 0, 'l' } , { 0, 0, 0, 0 } } ; int opt_index = 0; int opt = getopt_long( argc, argv, GETOPT_STRING, long_options, &opt_index ); if( opt == -1 ) break; switch( opt ) { case 0: break; case 't': input_type=FILEDATA; break; case 'f': input_type=FILENAME; break; case 'i': input_type=MIMETYPE; break; case 'm': output_type=MIMETYPE; break; case 'd': output_type=DESCRIPTION; break; case 'a': output_type=ACTION; break; case 'l': output_type=LAUNCH; break; case 'h': print_help( argv[0], 1 ); exit(0); case 'v': printf( _("%s, version %s\n"), MIMEDB, PACKAGE_VERSION ); exit( 0 ); case '?': return 1; } } if( ( output_type == LAUNCH )&&(input_type==MIMETYPE)) { fprintf( stderr, _("%s: Can not launch a mimetype\n"), MIMEDB ); print_help( argv[0], 2 ); exit(1); } if( output_type == LAUNCH ) hash_init( &launch_hash, &hash_str_func, &hash_str_cmp ); /* Loop over all non option arguments and do the specified lookup */ //fprintf( stderr, "Input %d, output %d\n", input_type, output_type ); for (i = optind; (i < argc)&&(!error); i++) { /* Convert from filename to mimetype, if needed */ if( input_type == FILENAME ) { mimetype = xdg_mime_get_mime_type_from_file_name(argv[i]); } else if( input_type == FILEDATA ) { mimetype = xdg_mime_get_mime_type_for_file(argv[i]); } else mimetype = xdg_mime_is_valid_mime_type(argv[i])?argv[i]:0; mimetype = xdg_mime_unalias_mime_type (mimetype); if( !mimetype ) { fprintf( stderr, _( "%s: Could not parse mimetype from argument '%s'\n"), MIMEDB, argv[i] ); error=1; return 1; } /* Convert from mimetype to whatever, if needed */ switch( output_type ) { case MIMETYPE: { output = (char *)mimetype; break; } case DESCRIPTION: { output = get_description( mimetype ); if( !output ) output = strdup( _("Unknown") ); break; } case ACTION: { output = get_action( mimetype ); break; } case LAUNCH: { /* There may be more files using the same launcher, we add them all up in little array_list_ts and launched them together after all the arguments have been parsed. */ array_list_t *l= (array_list_t *)hash_get( &launch_hash, mimetype ); output = 0; if( !l ) { l = my_malloc( sizeof( array_list_t ) ); if( l == 0 ) { break; } al_init( l ); hash_put( &launch_hash, mimetype, l ); } al_push( l, argv[i] ); } } /* Print the glorious result */ if( output ) { printf( "%s\n", output ); if( output != mimetype ) free( output ); } output = 0; } /* Perform the actual launching */ if( output_type == LAUNCH && !error ) { int i; array_list_t mimes; al_init( &mimes ); hash_get_keys( &launch_hash, &mimes ); for( i=0; i<al_get_count( &mimes ); i++ ) { char *mimetype = (char *)al_get( &mimes, i ); array_list_t *files = (array_list_t *)hash_get( &launch_hash, mimetype ); if( !files ) { fprintf( stderr, _( "%s: Unknown error\n"), MIMEDB ); error=1; break; } char *launcher = get_action( mimetype ); if( launcher ) { launch( launcher, files, 0 ); free( launcher ); } } hash_foreach( &launch_hash, &clear_entry ); hash_destroy( &launch_hash ); al_destroy( &mimes ); } if( launch_buff ) free( launch_buff ); if( start_re ) { regfree( start_re ); regfree( stop_re ); free( start_re ); free( stop_re ); } xdg_mime_shutdown(); return error; }
/* * Program entry point. */ int main(int argc, char** argv) { /* * Standard command-line parsing. */ const HASH_T *options = parse_cmdline(argc, argv, arg_opts); if(options == NULL || hash_get(options, "help") != NULL) { show_usage(argc, argv, arg_opts); return EXIT_FAILURE; } const char *url = hash_get(options, "url"); const char *principal = hash_get(options, "principal"); CREDENTIALS_T *credentials = NULL; const char *password = hash_get(options, "credentials"); if(password != NULL) { credentials = credentials_create_password(password); } const char *topic_name = hash_get(options, "topic"); const long seconds = atol(hash_get(options, "seconds")); /* * Setup for condition variable. */ apr_initialize(); apr_pool_create(&pool, NULL); apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool); apr_thread_cond_create(&cond, pool); /* * Create a session with the Diffusion server. */ SESSION_T *session; DIFFUSION_ERROR_T error = { 0 }; session = session_create(url, principal, credentials, NULL, NULL, &error); if(session == NULL) { fprintf(stderr, "TEST: Failed to create session\n"); fprintf(stderr, "ERR : %s\n", error.message); return EXIT_FAILURE; } /* * Create a topic holding simple string content. */ TOPIC_DETAILS_T *string_topic_details = create_topic_details_single_value(M_DATA_TYPE_STRING); const ADD_TOPIC_PARAMS_T add_topic_params = { .topic_path = topic_name, .details = string_topic_details, .on_topic_added = on_topic_added, .on_topic_add_failed = on_topic_add_failed, .on_discard = on_topic_add_discard, }; apr_thread_mutex_lock(mutex); add_topic(session, add_topic_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); topic_details_free(string_topic_details); /* * Define the handlers for add_update_source() */ const UPDATE_SOURCE_REGISTRATION_PARAMS_T update_reg_params = { .topic_path = topic_name, .on_init = on_update_source_init, .on_registered = on_update_source_registered, .on_active = on_update_source_active, .on_standby = on_update_source_standby, .on_close = on_update_source_closed }; /* * Register an updater. */ apr_thread_mutex_lock(mutex); CONVERSATION_ID_T *updater_id = register_update_source(session, update_reg_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); /* * Define default parameters for an update source. */ UPDATE_SOURCE_PARAMS_T update_source_params_base = { .updater_id = updater_id, .topic_path = topic_name, .on_success = on_update_success, .on_failure = on_update_failure }; time_t end_time = time(NULL) + seconds; while(time(NULL) < end_time) { if(active) { /* * Create an update structure containing the current time. */ BUF_T *buf = buf_create(); const time_t time_now = time(NULL); buf_write_string(buf, ctime(&time_now)); CONTENT_T *content = content_create(CONTENT_ENCODING_NONE, buf); UPDATE_T *upd = update_create(UPDATE_ACTION_REFRESH, UPDATE_TYPE_CONTENT, content); UPDATE_SOURCE_PARAMS_T update_source_params = update_source_params_base; update_source_params.update = upd; /* * Update the topic. */ update(session, update_source_params); content_free(content); update_free(upd); buf_free(buf); } sleep(1); } if(active) { UPDATE_SOURCE_DEREGISTRATION_PARAMS_T update_dereg_params = { .updater_id = updater_id, .on_deregistered = on_update_source_deregistered }; apr_thread_mutex_lock(mutex); deregister_update_source(session, update_dereg_params); apr_thread_cond_wait(cond, mutex); apr_thread_mutex_unlock(mutex); } /* * Close session and free resources. */ session_close(session, NULL); session_free(session); conversation_id_free(updater_id); credentials_free(credentials); apr_thread_mutex_destroy(mutex); apr_thread_cond_destroy(cond); apr_pool_destroy(pool); apr_terminate(); return EXIT_SUCCESS; }
/* StructSpecifier semantic handle function */ TypePtr sem_structspecifier_handle(NodePtr node) { uint_32 rule = node->content.rule; symbol **mlist; symbol *current_node, *new_stype, *struct_node; TypePtr type; NodePtr opttag; char *struct_name; int count, i; if (STRUCTSPECIFIER__STRUCT_OPTTAG_LC_DEFLIST_RC == rule) { new_stype = (symbol *)malloc(sizeof(symbol)); type = (TypePtr)malloc(sizeof(Type)); type->kind = STRUCTURE; type->array_status = -1; mlist = (symbol **)malloc(20 * sizeof(symbol *)); count = sem_deflist_handle(get_child(node, 3), mlist, 0); if (count > 0) { type->u.structure = mlist[0]; current_node = type->u.structure; for (i = 1; i < count; ++i) { current_node->tail = mlist[i]; current_node = current_node->tail; } } new_stype->name = (char *)malloc(strlen("struct:") \ + 20); /* solve the name of struct, * 2012 05 26 - 12:30 * */ opttag = get_child(node, 1); if (iNULL != opttag->content.id) sprintf(new_stype->name, "struct:%s", \ get_child(opttag, 0)->content.str_value); else sprintf(new_stype->name, "struct:%d", current_id + 1); JDEBUG_OUT_COM("new_stype->name: %s\n", new_stype->name); new_stype->type = type; new_stype->tail = NULL; //free(mlist); /* insert the struct type into the symbolic table */ hash_insert(&symbol_table, new_stype); /* printf("--------------test----------------\n"); current_node = new_stype; printf("[Struct Detail] name: %s\n", current_node->name); current_node = current_node->type->u.structure; while (current_node != NULL) { JDEBUG_OUT_COM("name: %s type: %d \n", current_node->name, current_node->type->kind); current_node = current_node->tail; } printf("--------------------test end-----------------------\n"); */ return new_stype->type; //to change } else if (STRUCTSPECIFIER__STRUCT_TAG == rule) { JDEBUG_OUT_COM("sem_STRUCTSPECIFIER__STRUCT_TAG\n"); struct_name = (char *)malloc(strlen("struct:")+20); sprintf(struct_name, "struct:%s", \ get_child(get_child(node, 1), 0)->content.str_value); JDEBUG_OUT_COM("%s, %s\n", get_child(get_child(node, 1), 0)->content.str_value, struct_name); struct_node = hash_get(symbol_table, struct_name); assert(NULL != struct_node); return struct_node->type; } else { printf("Unknown STRUCT SPECIFIER\n"); exit(-1); } }
void hash_insert(hash_table *t, char *key, void *val) { int idx = hash(t, key); node *n = t->table[idx]; node *prev = NULL; int cols=0; while( n!=NULL && n->key != NULL && strcmp(key, n->key) > 0 ) { prev = n; n = n->next; cols++; } if( n!=NULL && n->key != NULL && strcmp(key, n->key)==0 ) { free(n->value); n->value = val; } else { numElems++; if(cols>0) numCollisions++; node *newnode = malloc(sizeof(node)); newnode->key = strdup(key); newnode->value = val; newnode->next = NULL; if(n==t->table[idx]) { newnode->next = n; t->table[idx]=newnode; } else if(n==NULL) { prev->next = newnode; } else { newnode->next = n; prev->next = newnode; } } // RESIZING OF HASH TABLE IF MORE COLLISIONS START HAPPENING double ratio = ((double)numCollisions)/((double)numElems); if( ratio > 1.5 ) { int curSize = t->size; hash_table * new_table = create_hash_table(curSize*3); int i; struct node_* head = NULL; for(i=0;i<t->size;i++) { head = (struct node_ *)t->table[i]; while(head!=NULL) { void *ret = hash_get(t, head->key); // inserting elements into new bigger hash table basic_hash_insert(new_table,head->key, *((int *)ret)); head=head->next; } } t = new_table; // pointing current table pointer to new bigger table } }
int test_create_label2node_list_map() { const char *test_name = "test_create_label2node_list_map"; struct rnode *a1, *a2, *a3, *b1, *b2, *c1, *d1, *d2; struct llist *node_list; struct hash *map; struct llist *nodes_of_label; struct list_elem *el; a1 = create_rnode("a", ""); a2 = create_rnode("a", ""); a3 = create_rnode("a", ""); b1 = create_rnode("b", ""); b2 = create_rnode("b", ""); c1 = create_rnode("c", ""); d1 = create_rnode("d", ""); d2 = create_rnode("d", ""); node_list = create_llist(); /* The order in which the nodes appear is unimportant, but it should be * preserved among nodes of the same label - which is why we test them * below in the same order (in a given label) */ append_element(node_list, d2); append_element(node_list, b2); append_element(node_list, a2); append_element(node_list, a3); append_element(node_list, c1); append_element(node_list, d1); append_element(node_list, b1); append_element(node_list, a1); map = create_label2node_list_map(node_list); if (NULL == map) { printf ("%s: map must not be NULL.\n", test_name); return 1; } if (NULL != hash_get(map, "not there")) { printf ("%s: inexistent label should return NULL.\n", test_name); return 1; } nodes_of_label = hash_get(map, "a"); if (NULL == nodes_of_label) { printf ("%s: there should be a list of nodes with label 'a'.\n", test_name); return 1; } if (nodes_of_label->count != 3) { printf ("%s: list of nodes with label 'a' should" " have length 3\n", test_name); return 1; } el = nodes_of_label->head; if (el->data != a2) { printf ("%s: expected node a2\n", test_name); return 1; } el = el->next; if (el->data != a3) { printf ("%s: expected node a3\n", test_name); return 1; } el = el->next; if (el->data != a1) { printf ("%s: expected node a1\n", test_name); return 1; } el = el->next; if (NULL != el) { printf ("%s: list of nodes with label 'a' is not terminated.\n",test_name); return 1; } nodes_of_label = hash_get(map, "b"); if (NULL == nodes_of_label) { printf ("%s: there should be a list of nodes with label 'b'.\n", test_name); return 1; } if (nodes_of_label->count != 2) { printf ("%s: list of nodes with label 'b' should" " have length 2\n", test_name); return 1; } el = nodes_of_label->head; if (el->data != b2) { printf ("%s: expected node b2\n", test_name); return 1; } el = el->next; if (el->data != b1) { printf ("%s: expected node b1\n", test_name); return 1; } el = el->next; if (NULL != el) { printf ("%s: list of nodes with label 'b' is not terminated.\n",test_name); return 1; } nodes_of_label = hash_get(map, "c"); if (NULL == nodes_of_label) { printf ("%s: there should be a list of nodes with label 'c'.\n", test_name); return 1; } if (nodes_of_label->count != 1) { printf ("%s: list of nodes with label 'c' should" " have length 1\n", test_name); return 1; } el = nodes_of_label->head; if (el->data != c1) { printf ("%s: expected node c1\n", test_name); return 1; } el = el->next; if (NULL != el) { printf ("%s: list of nodes with label 'b' is not terminated.\n",test_name); return 1; } nodes_of_label = hash_get(map, "d"); if (NULL == nodes_of_label) { printf ("%s: there should be a list of nodes with label 'd'.\n", test_name); return 1; } if (nodes_of_label->count != 2) { printf ("%s: list of nodes with label 'd' should" " have length 2\n", test_name); return 1; } el = nodes_of_label->head; if (el->data != d2) { printf ("%s: expected node d2\n", test_name); return 1; } el = el->next; if (el->data != d1) { printf ("%s: expected node d1\n", test_name); return 1; } el = el->next; if (NULL != el) { printf ("%s: list of nodes with label 'b' is not terminated.\n",test_name); return 1; } printf("%s ok.\n", test_name); return 0; }
/** * Print a specific type * * @param type * @param mode * @return */ int revm_type_print(char *type, char mode) { aspectype_t *cur; aspectype_t *child; char buf[BUFSIZ]; char prefix[128]; int len; char *size; char offset[128]; int idx; int sz; char *pad; PROFILER_IN(__FILE__, __FUNCTION__, __LINE__); cur = hash_get(&types_hash, type); if (!cur) PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "Unknown type", 0); /* Set up things */ revm_endline(); /* Setup first part of the line */ snprintf(prefix, sizeof(prefix), "%s%s%s", revm_colorfieldstr("{"), revm_colornumber("%u", cur->size), revm_colorfieldstr("}")); len = snprintf(buf, sizeof(buf), " %s %s %-20s %s %-10s", revm_colornumber("id:%-10u", cur->type), revm_colorfieldstr("Type"), revm_colortypestr_fmt("%-20s", type), revm_colorfieldstr("size"), prefix); size = alloca(20); /* If the type is a structure */ if (cur->childs) { len += snprintf(buf + len, sizeof(buf) - len, "%s", revm_colorfieldstr(" = {")); /* Prepare the padding after each field name */ sz = len - revm_color_size(buf) - 16; /* -16 is dirty: some bug in colors */ pad = alloca(sz + 1); memset(pad, ' ', sz); pad[sz] = 0x00; /* For each child field type */ for (child = cur->childs; child; child = child->next) { /* Compute the size field */ if (child->type == ASPECT_TYPE_RAW) snprintf(size, sizeof(size), "%s%s%s", revm_colorfieldstr("["), revm_colornumber("%u", child->size), revm_colorfieldstr("]")); else if (child->dimnbr && child->elemnbr) { for (sz = idx = 0; idx < child->dimnbr; idx++) sz += 20; size = alloca(sz); for (sz = idx = 0; idx < child->dimnbr; idx++) sz += snprintf(size + sz, sz, "%s%s%s", revm_colorfieldstr("["), revm_colornumber("%u", child->elemnbr[idx]), revm_colorfieldstr("]")); } else *size = 0x00; /* Format the whole thing */ if (mode) *offset = 0x00; else snprintf(offset, sizeof(offset), "%s%s", revm_colornumber("%u", child->off), revm_colorfieldstr(":")); len += snprintf(buf + len, sizeof(buf) - len, "%s%s%s%s%s%s%s", offset, revm_colorstr(child->fieldname), revm_colorfieldstr(":"), revm_colortypestr((child->isptr ? "*" : "")), revm_colortypestr(child->name), size, revm_colorfieldstr((child->next ? ",\n" : "}\n\n"))); /* Print field and next padding */ revm_output(buf); revm_endline(); if (child->next) revm_output(pad); *buf = 0x00; len = 0; } } /* Print non-structures types */ else { revm_output(buf); revm_output("\n"); } /* Return success */ PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 1); }
/* always returns number of bytes written or that would have been * written if the buffer was large enough * return values < 0 indicate some error occured, * and return values > buflen indicate buffer was not large enough */ static int _render_stanza_recursive(xmpp_stanza_t *stanza, char * const buf, size_t const buflen) { char *ptr = buf; size_t left = buflen; int ret, written; xmpp_stanza_t *child; hash_iterator_t *iter; const char *key; assert(stanza); written = 0; if (stanza->type == XMPP_STANZA_UNKNOWN) return XMPP_EINVOP; if (stanza->type == XMPP_STANZA_TEXT) { if (!stanza->data) return XMPP_EINVOP; assert(stanza->data); ret = xmpp_snprintf(ptr, left, "%s", stanza->data); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); } else { /* stanza->type == XMPP_STANZA_TAG */ if (!stanza->data) return XMPP_EINVOP; /* write begining of tag and attributes */ assert(stanza->data); ret = xmpp_snprintf(ptr, left, "<%s", stanza->data); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); if (stanza->attributes && hash_num_keys(stanza->attributes) > 0) { iter = hash_iter_new(stanza->attributes); while ((key = hash_iter_next(iter))) { assert(hash_get(stanza->attributes, key)); ret = xmpp_snprintf(ptr, left, " %s=\"%s\"", key, (char *)hash_get(stanza->attributes, key)); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); } hash_iter_release(iter); } if (!stanza->children) { /* write end if singleton tag */ ret = xmpp_snprintf(ptr, left, "/>"); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); } else { /* this stanza has child stanzas */ /* write end of start tag */ ret = xmpp_snprintf(ptr, left, ">"); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); /* iterate and recurse over child stanzas */ child = stanza->children; while (child) { ret = _render_stanza_recursive(child, ptr, left); if (ret < 0) return ret; _render_update(&written, buflen, ret, &left, &ptr); child = child->next; } /* write end tag */ assert(stanza->data); ret = xmpp_snprintf(ptr, left, "</%s>", stanza->data); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); } } return written; }
int ecl_rft_file_get_well_occurences( const ecl_rft_file_type * rft_file , const char * well) { const int_vector_type * index_vector = hash_get(rft_file->well_index , well); return int_vector_size( index_vector ); }
active_list_type * local_dataset_get_node_active_list(const local_dataset_type * dataset , const char * node_key ) { return hash_get( dataset->nodes , node_key ); /* Fails hard if you do not have the key ... */ }
void site_config_fprintf_config(const site_config_type * site_config, FILE * stream) { fprintf(stream, CONFIG_COMMENTLINE_FORMAT); fprintf(stream, CONFIG_COMMENT_FORMAT, "Here comes system related information - which typically"); fprintf(stream, CONFIG_COMMENT_FORMAT, "overrides information from the site-wide configuration file."); /* Starting with the user defined jobs. */ { stringlist_type * joblist = ext_joblist_alloc_list(site_config->joblist); char * fmt_key = util_alloc_sprintf(CONFIG_KEY_FORMAT, INSTALL_JOB_KEY); char * install_fmt = util_alloc_sprintf("%s%s%s", fmt_key, CONFIG_VALUE_FORMAT, CONFIG_ENDVALUE_FORMAT); for (int i = 0; i < stringlist_get_size(joblist); i++) { ext_job_type * ext_job = ext_joblist_get_job(site_config->joblist, stringlist_iget(joblist, i)); if (ext_job_is_private(ext_job)) ext_job_fprintf_config(ext_job, install_fmt, stream); } free(install_fmt); free(fmt_key); } /* Storing the env variables set with SETENV */ { hash_iter_type * iter = hash_iter_alloc(site_config->env_variables_user); while (!hash_iter_is_complete(iter)) { const char * var = hash_iter_get_next_key(iter); const char * user_value = hash_get(site_config->env_variables_user, var); const char * site_value = hash_safe_get(site_config->env_variables_site, var); if (!util_string_equal(user_value, site_value)) { fprintf(stream, CONFIG_KEY_FORMAT, SETENV_KEY); fprintf(stream, CONFIG_VALUE_FORMAT, var); fprintf(stream, CONFIG_ENDVALUE_FORMAT, user_value); } } } /* Storing the driver type setting: */ if (site_config->driver_type != site_config->driver_type_site) { fprintf(stream, CONFIG_KEY_FORMAT, QUEUE_SYSTEM_KEY); fprintf(stream, CONFIG_ENDVALUE_FORMAT, site_config_get_queue_name(site_config)); } /* Storing UMASK setting */ if (site_config->umask != site_config->umask_site) { fprintf(stream, CONFIG_KEY_FORMAT, UMASK_KEY); fprintf(stream, "%o\n", site_config->umask); } /* Storing MAX_SUBMIT setting */ if (site_config->max_submit != site_config->max_submit_site) { fprintf(stream, CONFIG_KEY_FORMAT, MAX_SUBMIT_KEY); fprintf(stream, "%d\n", site_config->max_submit); } /* Storing LICENSE_ROOT_PATH */ if (!util_string_equal(site_config->license_root_path, site_config->license_root_path_site)) { fprintf(stream, CONFIG_KEY_FORMAT, LICENSE_PATH_KEY); fprintf(stream, CONFIG_ENDVALUE_FORMAT, site_config->license_root_path); } /* Storing jobscript */ if (!util_string_equal(site_config->job_script, site_config->job_script_site)) { fprintf(stream, CONFIG_KEY_FORMAT, LICENSE_PATH_KEY); fprintf(stream, CONFIG_ENDVALUE_FORMAT, site_config->job_script); } /* Storing local settings. */ if (site_config_get_max_running_local(site_config) != site_config->max_running_local_site) { fprintf(stream, CONFIG_KEY_FORMAT, MAX_RUNNING_LOCAL_KEY); fprintf(stream, CONFIG_INT_FORMAT, site_config_get_max_running_local(site_config)); fprintf(stream, "\n"); } /* Storing LSF settings. */ { if (site_config_get_max_running_lsf(site_config) != site_config->max_running_lsf_site) { fprintf(stream, CONFIG_KEY_FORMAT, MAX_RUNNING_LSF_KEY); fprintf(stream, CONFIG_INT_FORMAT, site_config_get_max_running_lsf(site_config)); fprintf(stream, "\n"); } if (!util_string_equal(site_config_get_lsf_queue(site_config), site_config->lsf_queue_name_site)) { fprintf(stream, CONFIG_KEY_FORMAT, LSF_QUEUE_KEY); fprintf(stream, CONFIG_ENDVALUE_FORMAT, site_config_get_lsf_queue(site_config)); } if (!util_string_equal(site_config_get_lsf_request(site_config), site_config->lsf_request_site)) { fprintf(stream, CONFIG_KEY_FORMAT, LSF_RESOURCES_KEY); fprintf(stream, CONFIG_ENDVALUE_FORMAT, site_config_get_lsf_request(site_config)); } } /* Storing RSH settings. */ { if (site_config_get_max_running_rsh(site_config) != site_config->max_running_rsh_site) { fprintf(stream, CONFIG_KEY_FORMAT, MAX_RUNNING_RSH_KEY); fprintf(stream, CONFIG_INT_FORMAT, site_config_get_max_running_rsh(site_config)); fprintf(stream, "\n"); } if (!util_string_equal(site_config_get_rsh_command(site_config), site_config->rsh_command_site)) { fprintf(stream, CONFIG_KEY_FORMAT, LICENSE_PATH_KEY); fprintf(stream, CONFIG_ENDVALUE_FORMAT, site_config_get_rsh_command(site_config)); } { queue_driver_type * rsh_driver = site_config_get_queue_driver(site_config, RSH_DRIVER_NAME); hash_type * host_list = hash_safe_cast((void *) queue_driver_get_option(rsh_driver, RSH_HOSTLIST)); hash_iter_type * iter = hash_iter_alloc(host_list); while (!hash_iter_is_complete(iter)) { const char * host_name = hash_iter_get_next_key(iter); fprintf(stream, CONFIG_KEY_FORMAT, RSH_HOST_KEY); fprintf(stream, "%s:%d\n", host_name, hash_get_int(host_list, host_name)); } hash_iter_free(iter); } } fprintf(stream, "\n\n"); }
/* read the command-line options and set the global_config_filename and * local_config_filename fields accordingly */ int libconf_phase1(libconf_t * handle) { int argc = handle->argc; char ** argv = handle->argv; libconf_phase_error_t have_error; libconf_optparam_t * param; libconf_do_on_error_t error_action = DOE_ERROR; int have_param; char * param_name; char * tmp_str; libconf_opt_t * option; libconf_opt_t t_option; handle->argv0 = *argv; argv++; argc--; while (argc > 0) { have_error = PT_NONE; param = NULL; have_param = 0; tmp_str = NULL; switch (argv[0][0]) { case '-' : switch (argv[0][1]) { case '-' : /* we have a long option */ option = hash_get(handle->options, argv[0] + 2); if (option != NULL) { /* we've found the option */ param_name = option->co_name; error_action = option->do_on_error; if (option->co_long_takes_param != TP_NO) { if (argc > 1 && argv[1][0] && argv[1][0] != '-') { /* we have our option's param */ switch (option->co_long_param_type) { case PT_NUMERIC_LIST : case PT_STRING_LIST : case PT_FILENAME_LIST : param = hash_get(handle->tmp_hash, option->co_name); if (param != NULL) vector_push_back(param->val.vector_val, strdup(argv[1])); default : if (param == NULL) param = libconf_optparam_new(option->co_name, option->co_long_param_type, argv[1]); } if (param == NULL) have_error = ET_PARAM_MALFORMED; else if (param->have_error) have_error = ET_PARAM_MALFORMED; have_param = 1; } else if (option->co_long_takes_param == TP_YES) { /* we should have had a param, but we don't */ have_error = ET_EXPECTED_PARAM_TP_NOT_FOUND; } } hash_put(handle->tmp_hash, strdup(option->co_name), param); } else { have_error = ET_UNKNOWN_OPTION; } break; case 0 : /* we should stop treating command-line options and * concatenate the rest of the command-line, separated by * spaces. */ argv++; argc--; while (argc) { argv++; argc--; tmp_str = catstr(tmp_str, argv[0]); } param = libconf_optparam_new("-", PT_STRING, tmp_str); free(tmp_str); hash_put(handle->tmp_hash, strdup("-"), param); break; default : /* we have a short option */ t_option.co_short_opt = argv[0][1]; option = hash_search(handle->options, &t_option, libconf_phase1_helper1); if (option != NULL) { /* we have our option */ param_name = option->co_name; error_action = option->do_on_error; if (option->co_short_takes_param != TP_NO) { if (argv[0][2]) { /* we have a parameter directly following */ switch (option->co_short_param_type) { case PT_NUMERIC_LIST : case PT_STRING_LIST : case PT_FILENAME_LIST : param = hash_get(handle->tmp_hash, option->co_name); if (param != NULL) vector_push_back(param->val.vector_val, strdup(argv[0] + 2)); default : if (param == NULL) param = libconf_optparam_new(option->co_name, option->co_short_param_type, argv[0] + 2); } if (param == NULL) have_error = ET_PARAM_MALFORMED; else if (param->have_error) have_error = ET_PARAM_MALFORMED; // have_param = 1; we don't count these } else if (argc > 1 && argv[1][0] && argv[1][0] != '-' ) { /* we have a parameter */ switch (option->co_short_param_type) { case PT_NUMERIC_LIST : case PT_STRING_LIST : case PT_FILENAME_LIST : param = hash_get(handle->tmp_hash, option->co_name); if (param != NULL) vector_push_back(param->val.vector_val, strdup(argv[1])); default : if (param == NULL) param = libconf_optparam_new(option->co_name, option->co_short_param_type, argv[1]); } if (param == NULL) have_error = ET_PARAM_MALFORMED; else if (param->have_error) have_error = ET_PARAM_MALFORMED; have_param = 1; } else if (option->co_short_takes_param == TP_YES) { /* we should have had a param, but we don't */ have_error = ET_EXPECTED_PARAM_TP_NOT_FOUND; } } hash_put(handle->tmp_hash, strdup(option->co_name), param); } else { have_error = ET_UNKNOWN_OPTION; } break; } break; default : /* no option? */ have_error = ET_EXPECTED_OPTION_TP_NOT_FOUND; break; } if ((have_error != ET_NONE) && (error_action != DOE_NOTHING)) { switch (error_action) { case DOE_WARNING : fprintf(stderr, "%s: Warning: ", handle->argv0); break; case DOE_ERROR : fprintf(stderr, "%s: Error: ", handle->argv0); break; default : break; } switch (have_error) { case ET_EXPECTED_PARAM_TP_NOT_FOUND : fprintf(stderr, "expected parameter not found for option %s\n", argv[0]); break; case ET_PARAM_MALFORMED : fprintf(stderr, "parameter malformed for option %s\n", argv[0]); break; case ET_EXPECTED_OPTION_TP_NOT_FOUND : fprintf(stderr, "not an option %s\n", argv[0]); break; case ET_UNKNOWN_OPTION : fprintf(stderr, "unknown option %s\n", argv[0]); break; default : break; } if (error_action == DOE_ERROR) exit(1); } if (have_param) { argv++; argc--; } argv++; argc--; } return 0; }
u64 __ts_string_to_tyid(ast_t* node) { fl_assert(node != 0); fl_assert(node->type == AST_TYPE); // empty var_decl for example if (!node->ty.id) { return 0; } // once set do not modify, unless you want it // like when implementing a struct templated if (node->ty_id) { return node->ty_id; } string* t_str = node->ty.id->identifier.string; char* tcstr = t_str->value; // built-in if (strcmp(tcstr, "auto") == 0) { return node->ty.id->ty_id = node->ty_id = 0; // inference } if (strcmp(tcstr, "bool") == 0) { return node->ty.id->ty_id = node->ty_id = TS_BOOL; } if (strcmp(tcstr, "void") == 0) { return node->ty.id->ty_id = node->ty_id = TS_VOID; } if (strcmp(tcstr, "i8") == 0) { return node->ty.id->ty_id = node->ty_id = TS_I8; } if (strcmp(tcstr, "u8") == 0) { return node->ty.id->ty_id = node->ty_id = TS_U8; } if (strcmp(tcstr, "i16") == 0) { return node->ty.id->ty_id = node->ty_id = TS_I16; } if (strcmp(tcstr, "u16") == 0) { return node->ty.id->ty_id = node->ty_id = TS_U16; } if (strcmp(tcstr, "i32") == 0) { return node->ty.id->ty_id = node->ty_id = TS_I32; } if (strcmp(tcstr, "u32") == 0) { return node->ty.id->ty_id = node->ty_id = TS_U32; } if (strcmp(tcstr, "i64") == 0) { return node->ty.id->ty_id = node->ty_id = TS_I64; } if (strcmp(tcstr, "u64") == 0) { return node->ty.id->ty_id = node->ty_id = TS_U64; } if (strcmp(tcstr, "f32") == 0) { return node->ty.id->ty_id = node->ty_id = TS_F32; } if (strcmp(tcstr, "f64") == 0) { return node->ty.id->ty_id = node->ty_id = TS_F64; } if (strcmp(tcstr, "string") == 0) { // return node->ty.id->ty_id = node->ty_id = TS_CSTR; // TODO TS_STRING // return node->ty.id->ty_id = node->ty_id = TS_STRING; return node->ty.id->ty_id = node->ty_id = 16; } if (strcmp(tcstr, "ptrdiff") == 0) { return node->ty.id->ty_id = node->ty_id = TS_PTRDIFF; } // type below are wrappers, this means they can appear inside a struct // pointing to themself, so if our parent is a struct, we should use auto // an in the second pass auto will be replaced with the struct type if (strcmp(tcstr, "ptr") == 0) { fl_assert(node->ty.children != 0); fl_assert(node->ty.children->list.length == 1); // TODO raise ts_register_types_pass(node->ty.children); u64 t = __ts_string_to_tyid(node->ty.children->list.values[0]); if (!t && !ast_has_parent(node, AST_DECL_STRUCT)) return 0; return node->ty.id->ty_id = node->ty_id = ty_create_wrapped(TY_POINTER, t); } if (strcmp(tcstr, "vector") == 0) { fl_assert(node->ty.children != 0); fl_assert(node->ty.children->list.length == 1); // TODO raise ts_register_types_pass(node->ty.children); u64 t = __ts_string_to_tyid(node->ty.children->list.values[0]); if (!t && !ast_has_parent(node, AST_DECL_STRUCT)) return 0; return node->ty.id->ty_id = node->ty_id = ty_create_wrapped(TY_VECTOR, t); } if (strcmp(tcstr, "ref") == 0) { fl_assert(node->ty.children != 0); fl_assert(node->ty.children->list.length == 1); // TODO raise ts_register_types_pass(node->ty.children); u64 t = __ts_string_to_tyid(node->ty.children->list.values[0]); if (!t && !ast_has_parent(node, AST_DECL_STRUCT)) return 0; return node->ty.id->ty_id = node->ty_id = ty_create_wrapped(TY_REFERENCE, t); } log_silly("search type for '%s'", tcstr); ast_t* scope = node; ast_t* el = node; array* scopes = ast_get_scopes(node); if (!scopes) { log_warning("delayed type '%s'", tcstr); return 0; } for (u64 i = 0; i < scopes->length; ++i) { scope = ((ast_t*)scopes->values[i]); el = hash_get(scope->block.types, tcstr); if (el != 0) { // check if it's a struct with templates, in wich case, we need to // implement / reuse if (el->type == AST_DECL_STRUCT && el->structure.tpls != 0) { // if it has children defined, then implement // TODO check there is no template type in the list if (node->ty.children) { // register children-types first ts_register_types_pass(node->ty.children); // check that there is no template children bool templated = false; for (int i = 0; i < node->ty.children->list.length; ++i) { if (ty_is_templated(node->ty.children->list.values[i]->ty_id)) { templated = true; } } if (templated) { ast_raise_error(node, "type error, try to implement a template " "using another template"); } // implement el = ast_implement_struct(node->ty.children, el, 0); // enjoy :) } else { // if not it just is just a reference, get the type and wait to // be implemented later } } return node->ty.id->ty_id = node->ty_id = el->ty_id; } } log_warning("delayed type '%s'", tcstr); return 0; }
void output_run_line( const output_type * output , ensemble_type * ensemble) { const int data_columns = vector_get_size( output->keys ); const int data_rows = time_t_vector_size( ensemble->interp_time ); double ** data; int row_nr, column_nr; data = util_calloc( data_rows , sizeof * data ); /* time-direction, i.e. the row index is the first index and the column number (i.e. the different keys) is the second index. */ for (row_nr=0; row_nr < data_rows; row_nr++) data[row_nr] = util_calloc( data_columns , sizeof * data[row_nr] ); printf("Creating output file: %s \n",output->file ); /* Go through all the cases and check that they have this key; exit if missing. Could also ignore the missing keys and just continue; and even defer the checking to the inner loop. */ for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); { bool OK = true; for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) { const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens ); if (!ecl_sum_has_general_var(sum_case->ecl_sum , qkey->sum_key)) { OK = false; fprintf(stderr,"** Sorry: the case:%s does not have the summary key:%s \n", ecl_sum_get_case( sum_case->ecl_sum ), qkey->sum_key); } } if (!OK) util_exit("Exiting due to missing summary vector(s).\n"); } } /* The main loop - outer loop is running over time. */ { /** In the quite typical case that we are asking for several quantiles of the quantity, i.e. WWCT:OP_1:0.10 WWCT:OP_1:0.50 WWCT:OP_1:0.90 the interp_data_cache construction will ensure that the underlying ecl_sum object is only queried once; and also the sorting will be performed once. */ hash_type * interp_data_cache = hash_alloc(); for (row_nr = 0; row_nr < data_rows; row_nr++) { time_t interp_time = time_t_vector_iget( ensemble->interp_time , row_nr); for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); double_vector_type * interp_data; /* Check if we have the vector in the cache table - if not create it. */ if (!hash_has_key( interp_data_cache , qkey->sum_key)) { interp_data = double_vector_alloc(0 , 0); hash_insert_hash_owned_ref( interp_data_cache , qkey->sum_key , interp_data , double_vector_free__); } interp_data = hash_get( interp_data_cache , qkey->sum_key ); /* Check if the vector has data - if not initialize it. */ if (double_vector_size( interp_data ) == 0) { for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) { const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens ); if ((interp_time >= sum_case->start_time) && (interp_time <= sum_case->end_time)) /* We allow the different simulations to have differing length */ double_vector_append( interp_data , ecl_sum_get_general_var_from_sim_time( sum_case->ecl_sum , interp_time , qkey->sum_key)) ; double_vector_sort( interp_data ); } } data[row_nr][column_nr] = statistics_empirical_quantile__( interp_data , qkey->quantile ); } hash_apply( interp_data_cache , double_vector_reset__ ); } hash_free( interp_data_cache ); } output_save( output , ensemble , (const double **) data); for (row_nr=0; row_nr < data_rows; row_nr++) free( data[row_nr] ); free( data ); }