/** \ingroup dbprim_hash * \brief Find an entry in a hash table. * * This function looks up an entry matching the given \p key. * * \param table A pointer to a #hash_table_t. * \param entry_p * A pointer to a pointer to a #hash_entry_t. This is a * result parameter. If \c NULL is passed, the lookup * will be performed and an appropriate error code * returned. * \param key A pointer to a #db_key_t describing the item to find. * * \retval DB_ERR_BADARGS An argument was invalid. * \retval DB_ERR_NOENTRY No matching entry was found. */ unsigned long ht_find(hash_table_t *table, hash_entry_t **entry_p, db_key_t *key) { unsigned long hash; link_elem_t *elem; initialize_dbpr_error_table(); /* initialize error table */ if (!ht_verify(table) || !key) /* verify arguments */ return DB_ERR_BADARGS; if (!table->ht_count) /* no entries in table... */ return DB_ERR_NOENTRY; hash = (*table->ht_func)(table, key) % table->ht_modulus; /* get hash */ /* walk through each element in that section */ for (elem = ll_first(&table->ht_table[hash]); elem; elem = le_next(elem)) /* compare keys... */ if (!(*table->ht_comp)(table, key, he_key((hash_entry_t *)le_object(elem)))) { /* found one, return it */ if (entry_p) *entry_p = le_object(elem); return 0; } return DB_ERR_NOENTRY; /* couldn't find a matching entry */ }
/** \ingroup dbprim_hash * \brief Iterate over each entry in a hash table. * * This function iterates over every entry in a hash table (in an * unspecified order), executing the given \p iter_func on each entry. * * \param table A pointer to a #hash_table_t. * \param iter_func * A pointer to a callback function used to perform * user-specified actions on an entry in a hash table. \c * NULL is an invalid value. See the documentation for * #hash_iter_t for more information. * \param extra A \c void pointer that will be passed to \p * iter_func. * * \retval DB_ERR_BADARGS An argument was invalid. * \retval DB_ERR_FROZEN The hash table is frozen. */ unsigned long ht_iter(hash_table_t *table, hash_iter_t iter_func, void *extra) { unsigned long retval; int i; link_elem_t *elem; initialize_dbpr_error_table(); /* initialize error table */ if (!ht_verify(table) || !iter_func) /* verify arguments */ return DB_ERR_BADARGS; if (table->ht_flags & HASH_FLAG_FREEZE) /* don't mess with frozen tables */ return DB_ERR_FROZEN; table->ht_flags |= HASH_FLAG_FREEZE; /* freeze the table */ /* walk through all the elements and call the iteration function */ for (i = 0; i < table->ht_modulus; i++) for (elem = ll_first(&table->ht_table[i]); elem; elem = le_next(elem)) if ((retval = (*iter_func)(table, le_object(elem), extra))) { table->ht_flags &= ~HASH_FLAG_FREEZE; /* unfreeze the table */ return retval; } table->ht_flags &= ~HASH_FLAG_FREEZE; /* unfreeze the table */ return 0; }
/* vpf relate structures. */ static int table_in_list( char *tablename, linked_list_type rlist ) { position_type p; vpf_relate_struct rcell; p = ll_first(rlist); while (!ll_end(p)) { ll_element(p,&rcell); if (strcmp(rcell.table1,tablename)==0) return 1; p = ll_next(p); } return 0; }
unsigned int ll_size(t_llist *l) { t_llist_node* next; t_llist_node* sentinel; int size=0; sentinel=ll_sentinel(l); next=ll_first(l); while(next!=sentinel) { next=ll_next(next); size++; } return size; }
void tcp_conn_map_get(t_tcp_conn_map* tcp_conn_map,u16 src_ip,u16 dst_ip,u32 src_port,u32 dst_port) { u32 conn_id; t_tcp_conn_desc* tcp_conn_desc = NULL; t_llist_node* sentinel_node = NULL; t_llist_node* next = NULL; conn_id = dst_port | (src_port << 16); tcp_conn_desc = hashtable_get(tcp_conn_map->conn_map,conn_id); if (tcp_conn_desc == NULL) { return NULL; } if (tcp_conn_desc->is_key_unique == 0) { return tcp_conn_desc; } else if (tcp_conn_desc->src_ip == src_ip && tcp_conn_desc->dst_ip == dst_ip && tcp_conn_desc->src_port == src_port && tcp_conn_desc->dst_port == dst_port) { return tcp_conn_desc; } else { sentinel_node = ll_sentinel(tcp_conn_map->duplicate_conn_list); next=ll_first(tcp_conn_map->duplicate_conn_list); while(next != sentinel_node) { tcp_conn_desc = next->val; if (tcp_conn_desc->conn_id == conn_id) { if (tcp_conn_desc->src_ip == src_ip && tcp_conn_desc->dst_ip == dst_ip && tcp_conn_desc->src_port == src_port && tcp_conn_desc->dst_port == dst_port) { return tcp_conn_desc; } } } } }
//IN THIS CASE REMOVE THE LIST'S CONTENT TOO //BETTER PROVIDE BOTH POSSIBILITY TO DESTROY AND NOT DESTROY //THE CONTENT.EXAMPLE WHAT IF THE SAME OBJECT IS INSIDE TWO DIFFERENT //LISTS? CHECKING C++ LIBRARY CLEAR EMPTY LIST BUT DOESN'T REMOVE //OBJECT.IDEALLY WE COULD ALLOW FREE ON EMPTY LIST ONLY AND //DELETAGE ALL FLUSH JOB TO CALLER.THIS IS IMPRACTICAL BECAUSE LEAD //TO LOT OF DUPLICATE CODE. void free_llist(t_llist *l) { t_llist_node* node; while (!ll_empty(l)) { node=ll_first(l); if (l->data_destructor!=NULL) { (*l->data_destructor)(node->val); } else { kfree(node->val); } ll_delete_node(node); } kfree(l->sentinel_node); kfree(l); }
/************************************************************************* * *N query_table * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function returns the set of selected rows of a VPF table * based upon the evaluation of the given selection expression string. * * The expression is strictly evaluated left to right. No nesting * is supported, so parentheses are not allowed. The expression * must match the form: * <field><log op><value> [ <join> <field><log op><value>] * where, * <field> is a valid field name of the table. * <log op> is one of the following: =, <, >, <=, >=, <> (not equal). * <value> is a valid value for the field. * <join> is either " AND " or " OR ". * Any number of clauses (<field><log op><value>) may be joined * together with AND or OR to form the expression. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * expression <input>==(char *) selection expression string. * table <input>==(vpf_table_type) VPF table structure. * return <output>==(set_type) set of selected rows. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * set_type set_init( rspf_int32 n ) SET.C * void set_insert( rspf_int32 element, set_type set ) SET.C * linked_list_type parse_expression( char *expression, * vpf_table_type table ) VPFQUERY.C * row_type read_next_row( vpf_table_type table ) VPFREAD.C * position_type ll_first( linked_list_type list ) LINKLIST.C * int ll_end( position_type position ) LINKLIST.C * void ll_element( position_type position, void *element ) LINKLIST.C * void *get_table_element( rspf_int32 field_number, * row_type row, * vpf_table_type table, * void *value, * rspf_int32 *count ) VPFREAD.C * void display_message( char *info ) USER DEFINED * static int strcompare( char *val1, char *val2, char op ) VPFQUERY.C * static int icompare( rspf_int32 val1, rspf_int32 val2, char op ) VPFQUERY.C * static int fcompare( float val1, float val2, char op ) VPFQUERY.C * void ll_reset( linked_list_type list ) LINKLIST.C void free_row( row_type row, vpf_table_type table) VPFREAD.C *E *************************************************************************/ set_type query_table( char *expression, vpf_table_type table ) { row_type row; position_type pos; expr_type expr; register rspf_int32 i; int boolval=FALSE, booltemp=0, join = OR; rspf_int32 lval, lval2, count; float fval, fval2; char tval, tval2, *tptr; linked_list_type exprlist; set_type select_set; select_set = set_init(table.nrows+1); if (strcmp(expression,"*")==0) { set_on(select_set); return select_set; } exprlist = parse_expression( expression, table ); if (!exprlist) return select_set; if (table.storage == DISK) fseek( table.fp, index_pos(1,table), SEEK_SET ); for (i=1;i<=table.nrows;i++) { if (table.storage == DISK) row = read_next_row(table); else row = get_row( i, table ); pos = ll_first(exprlist); while (!ll_end(pos)) { ll_element( pos, &expr ); switch (table.header[expr.field].type) { case 'I': if (table.header[expr.field].count == 1) { get_table_element( expr.field, row, table, &lval, &count ); lval2 = atol(expr.value); booltemp = icompare( lval, lval2, expr.op ); } else { display_message( "Selection may not be performed upon arrays"); i=table.nrows+1; } break; case 'T': if (table.header[expr.field].count == 1) { get_table_element( expr.field, row, table, &tval, &count ); tval2 = expr.value[0]; booltemp = comp( &tval, &tval2, sizeof(tval), expr.op ); } else { tptr = (char *)get_table_element( expr.field, row, table, NULL, &count ); booltemp = strcompare( tptr, expr.value, expr.op ); free(tptr); } break; case 'F': if (table.header[expr.field].count == 1) { get_table_element( expr.field, row, table, &fval, &count ); if (!is_vpf_null_float(fval)) { fval2 = (float)atof(expr.value); booltemp = fcompare( fval, fval2, expr.op ); } else booltemp = FALSE; } else { display_message( "Selection may not be performed upon arrays"); i=table.nrows+3; } break; default: display_message("Field type not supported for query"); i=table.nrows+3; break; } if (i>table.nrows) break; if (join==OR) boolval = boolval || booltemp; else boolval = boolval && booltemp; join = expr.join; pos = pos->next; } free_row( row, table ); if (boolval) set_insert(i,select_set); boolval = FALSE; join = OR; if (i==table.nrows+3) break; } ll_reset(exprlist); return select_set; }
/************************************************************************** * *N fc_row_numbers * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Given the starting row of a feature class relationship, return the * list of row numbers of the table at the end of the feature class * relate chain. * If your relate goes from the feature to the primitive, this will * return the primitive ids for the given feature row. * If your relate goes from the primitive to the feature, this will * return the feature ids of the given primitive row. * * Currently only supports relates on 'I' or 'K' fields. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ linked_list_type fc_row_numbers( row_type row, fcrel_type fcrel, long int tile, ThematicIndex *idx ) { row_type relrow; long int count; long int n, rownum, keyval; id_triplet_type triplet_keyval; int KEY1_, KEY_; position_type p, prow, pkey; vpf_relate_struct rcell; linked_list_type rowlist, keylist, templist; p = ll_first(fcrel.relate_list); ll_element(p,&rcell); KEY1_ = table_pos(rcell.key1,fcrel.table[0]); get_table_element(0,row,fcrel.table[0],&rownum,&count); if (KEY1_ == 0) { /* "ID" */ keyval = rownum; } else { switch (fcrel.table[0].header[KEY1_].type) { case 'I': get_table_element(KEY1_,row,fcrel.table[0],&keyval,&count); break; case 'K': get_table_element(KEY1_,row,fcrel.table[0],&triplet_keyval, &count); keyval = triplet_keyval.exid; if (tile != triplet_keyval.tile) { keyval = -2; } break; default: keyval = 0; break; } } keylist = ll_init(); ll_insert(&keyval,sizeof(keyval),keylist); n = 0; p = ll_first(fcrel.relate_list); for (n=1;n<(fcrel.nchain-1);n++) { /* Relate through Join table(s) */ rowlist = ll_init(); pkey = ll_first(keylist); while (!ll_end(pkey)) { ll_element(pkey,&keyval); templist = related_rows(&keyval,fcrel.table[n],rcell.key2,0,NULL); prow = ll_first(templist); while (!ll_end(prow)) { ll_element(prow,&rownum); if (!ll_locate(&rownum,rowlist)) ll_insert(&rownum,sizeof(rownum),ll_last(rowlist)); prow = ll_next(prow); } ll_reset(templist); pkey = ll_next(pkey); } ll_reset(keylist); p = ll_next(p); ll_element(p,&rcell); KEY_ = table_pos(rcell.key1,fcrel.table[n]); keylist = ll_init(); prow = ll_first(rowlist); while (!ll_end(prow)) { ll_element(prow,&rownum); relrow = get_row(rownum,fcrel.table[n]); if (KEY_ == 0) { /* "ID" */ keyval = rownum; } else { switch (fcrel.table[n].header[KEY_].type) { case 'I': get_table_element(KEY_,relrow,fcrel.table[n],&keyval,&count); break; case 'K': get_table_element(KEY_,relrow,fcrel.table[n],&triplet_keyval, &count); keyval = triplet_keyval.exid; if (tile != triplet_keyval.tile) { keyval = -2; } break; default: keyval = 0; break; } } if (keyval > 0) ll_insert(&keyval,sizeof(keyval),ll_last(keylist)); prow = ll_next(prow); free_row(relrow,fcrel.table[n]); } ll_reset(rowlist); } rowlist = ll_init(); p = ll_first(keylist); while (!ll_end(p)) { ll_element(p,&keyval); templist = related_rows(&keyval,fcrel.table[n],rcell.key2,0,idx); prow = ll_first(templist); while (!ll_end(prow)) { ll_element(prow,&rownum); if (!ll_locate(&rownum,rowlist)) ll_insert(&rownum,sizeof(rownum),ll_last(rowlist)); prow = ll_next(prow); } ll_reset(templist); p = ll_next(p); } ll_reset(keylist); return rowlist; }
/************************************************************************** * *N fc_row_number * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Given the starting row of a feature class relationship, return the * row number of the table at the end of the feature class relate * chain. * If your relate goes from the feature to the primitive, this will * return the primitive id for the given feature row. * If your relate goes from the primitive to the feature, this will * return the feature id of the given primitive row. * * Currently only supports relates on 'I' or 'K' fields. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ long int fc_row_number( row_type row, fcrel_type fcrel, long int tile ) { row_type relrow; long int count; long int i, rownum, keyval; id_triplet_type triplet_keyval; int KEY1_, KEY_; position_type p; vpf_relate_struct rcell; p = ll_first(fcrel.relate_list); ll_element(p,&rcell); KEY1_ = table_pos(rcell.key1,fcrel.table[0]); get_table_element(0,row,fcrel.table[0],&rownum,&count); if (KEY1_ == 0) { /* "ID" */ keyval = rownum; } else { switch (fcrel.table[0].header[KEY1_].type) { case 'I': get_table_element(KEY1_,row,fcrel.table[0],&keyval,&count); break; case 'K': get_table_element(KEY1_,row,fcrel.table[0],&triplet_keyval, &count); keyval = triplet_keyval.exid; if (tile != triplet_keyval.tile) { return -2; } break; default: keyval = 0; break; } } p = ll_first(fcrel.relate_list); for (i=1;i<(fcrel.nchain-1);i++) { /* Relate through Join table(s) */ rownum = related_row(&keyval,fcrel.table[i],rcell.key2,0); relrow = get_row(rownum,fcrel.table[i]); p = ll_next(p); ll_element(p,&rcell); KEY_ = table_pos(rcell.key1,fcrel.table[i]); if (KEY_ == 0) { /* "ID" */ keyval = rownum; } else { switch (fcrel.table[i].header[KEY_].type) { case 'I': get_table_element(KEY_,relrow,fcrel.table[i],&keyval,&count); break; case 'K': get_table_element(KEY_,relrow,fcrel.table[i],&triplet_keyval, &count); keyval = triplet_keyval.exid; if (tile != triplet_keyval.tile) { return -2; } break; default: keyval = 0; break; } } free_row(relrow,fcrel.table[i]); } if (ossim_strcasecmp(rcell.key2,"ID")==0) rownum = keyval; else rownum = related_row(&keyval,fcrel.table[i],rcell.key2,0); return rownum; }
/************************************************************************** * *N select_feature_class_relate * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Set up the relationships between features and primitives or between * primitives and features (one way only) for a specified feature class. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ fcrel_type select_feature_class_relate( int fcnum, library_type *library, char *start_table, char *end_table ) { int storage, cov; vpf_table_type fcs; long int i; char path[255], covpath[255]; position_type p; vpf_relate_struct rcell; fcrel_type fcrel; fcrel.nchain = 0; fcrel.table = NULL; fcrel.relate_list = NULL; cov = library->fc[fcnum].coverage; strcpy(covpath,library->cover[cov].path); rightjust(covpath); sprintf( path, "%sfcs", covpath ); /* Feature Class Schema table */ fcs = vpf_open_table( path, disk, "rb", NULL ); fcrel.relate_list = fcs_relate_list( library->fc[fcnum].name, start_table,end_table, fcs ); if (ll_empty(fcrel.relate_list)) { ll_reset(fcrel.relate_list); displaymessage("ERROR in feature class relationship!", start_table,end_table,NULL); return fcrel; } /* Find the number of tables in the relate chain */ p = ll_first(fcrel.relate_list); fcrel.nchain = 0; while (!ll_end(p)) { fcrel.nchain++; p = ll_next(p); } /* Allow for last table2 */ fcrel.nchain++; fcrel.table = (vpf_table_type *) vpfmalloc((fcrel.nchain+1)* sizeof(vpf_table_type)); for (i=0;i<fcrel.nchain+1;i++) vpf_nullify_table( &(fcrel.table[i]) ); p = ll_first(fcrel.relate_list); for (i=0;i<fcrel.nchain-1;i++) { ll_element(p,&rcell); /** Can't open primitive table - may be several under tile **/ /** directories. Open all others **/ if (!is_primitive(rcell.table1)) { sprintf(path,"%s%s",covpath,rcell.table1); if (is_join(rcell.table1)) storage = ram; else storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } if (!ll_end(p)) p = ll_next(p); } /* End of relate chain */ i = fcrel.nchain-1; if (!is_primitive(rcell.table2)) { sprintf(path,"%s%s",covpath,rcell.table2); storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } vpf_close_table( &fcs ); return fcrel; }
static unsigned int _read_write_28_ata(t_io_request* io_request) { int i; struct t_process_context* process_context; struct t_process_context *current_process_context; t_device_desc* device_desc; t_io_request* pending_request; t_llist_node* node; SAVE_IF_STATUS CLI exit_count_7++; io_request->status=REQUEST_WAITING; device_desc=io_request->device_desc; if (device_desc->status==REQUEST_WAITING || test==0) { ll_append(device_desc->pending_request,io_request); test=io_request->process_context->pid; _sleep(); } else { device_desc->status=REQUEST_WAITING; } if (io_request->process_context->pid==test) { i++; } out(0xE0 | (io_request->lba >> 24),0x1F6); out((unsigned char)io_request->sector_count,0x1F2); out((unsigned char)io_request->lba,0x1F3); out((unsigned char)(io_request->lba >> 8),0x1F4); out((unsigned char)(io_request->lba >> 16),0x1F5); out(io_request->command,0x1F7); if (io_request->command==WRITE_28) { for (i=0;i<256;i++) { //out(*(char*)io_request->io_buffer++,0x1F0); outw((unsigned short)57,0x1F0); } } system.device_desc->serving_request=io_request; if (system.process_info.current_process->val!=NULL) { io_request->process_context=system.process_info.current_process->val; _sleep(); } else { while(io_request->status==REQUEST_WAITING); } if (io_request->process_context->pid==test) { i++; } if (io_request->status!=REQUEST_COMPLETED) { panic(); return -1; } if (io_request->command==READ_28) { for (i=0;i<256;i++) { //out(*(char*)io_buffer++,0x1F0); int zz=inw(0x1F0); ((char*)io_request->io_buffer)[i]=zz; } } if (!ll_empty(device_desc->pending_request)) { node=ll_first(device_desc->pending_request); pending_request=(t_io_request*) node->val; ll_delete_node(node); _awake(pending_request->process_context); } RESTORE_IF_STATUS return 0; }
/************************************************************************* * *N get_selected_tile_primitives * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function determines all of the selected primitive rows from * the selected features of a given tile. * * This function expects a feature class relationship structure that * has been successfully created with select_feature_class_relate() * from the feature table to the primitive. The primitive table in * the feature class relate structure must have been successfully * opened for the given tile. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * library <input>==(library_type *) VPF library structure. * fcnum <input>==(int) feature class number of the feature table. * fcrel <input>==(fcrel_type) feature class relate structure. * feature_rows <input>==(set_type) set of selected features. * mapenv <input>==(map_environment_type *) map environment. * tile <input>==(rspf_int32) tile number. * tiledir <input>==(char *) path to the tile directory. * status <output>==(int *) status of the function: * 1 if completed, 0 if user escape. * return <output>==(set_type) set of primitives for the features * in the corresponding tile. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *************************************************************************/ set_type get_selected_tile_primitives( library_type *library, int fcnum, fcrel_type fcrel, set_type feature_rows, map_environment_type *mapenv, rspf_int32 tile, char *tiledir, int *status ) { int cov, degree; int feature, prim; row_type row; char *spxname[] = {"","esi","fsi","tsi","nsi","csi"}; char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"}; set_type primitive_rows, tile_features; set_type primitives; rspf_int32 prim_rownum; register rspf_int32 i,pclass, start,end; char path[255], covpath[255]; linked_list_type primlist; position_type p; vpf_relate_struct rcell; ThematicIndex idx; feature = 0; prim = fcrel.nchain-1; /* Assume that fcrel.table[prim] has been opened */ primitives.size = 0; primitives.buf = NULL; cov = library->fc[fcnum].coverage; strcpy( covpath, library->cover[cov].path ); p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list); ll_element(p,&rcell); degree = rcell.degree; for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) { if ((pclass != library->fc[fcnum].primclass) && (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue; primitives = set_init(fcrel.table[prim].nrows+1); /* Get the set of primitive rows within the map extent */ /* Look for the spatial index file to weed out primitives in the */ /* given tile but outside of the viewing area. If a projection */ /* other than plate-carree (rectangular) is on, or if the extent */ /* crosses the meridian, the quick check is no longer valid. */ primitive_rows.size = 0; if (mapenv->projection == PLATE_CARREE && mapenv->mapextent.x1 < mapenv->mapextent.x2) { sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]); /* 20 (below) is a fairly arbitrary cutoff of the number of */ /* primitives that make a spatial index search worth while. */ if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = spatial_index_search(path, mapenv->mapextent.x1,mapenv->mapextent.y1, mapenv->mapextent.x2,mapenv->mapextent.y2); } else { /* Next best thing - bounding rectangle table */ sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]); if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = bounding_select(path,mapenv->mapextent, library->dec_degrees); } } } if (primitive_rows.size == 0) { /* Search through all the primitives */ primitive_rows=set_init(fcrel.table[prim].nrows+1); set_on(primitive_rows); } if (strcmp(tiledir,"") != 0) { tile_thematic_index_name(fcrel.table[feature], path); if ((strcmp(path,"")!=0) && (access(path,4)==0)) { /* Tile thematic index for feature table present, */ tile_features = read_thematic_index( path, (char *)&tile ); } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } set_delete(0,tile_features); idx.fp = NULL; i = table_pos(rcell.key2,fcrel.table[prim]); if (i >= 0) { if (fcrel.table[prim].header[i].tdx) { sprintf(path,"%s%s",fcrel.table[prim].path, fcrel.table[prim].header[i].tdx); if (access(path,0)==0) idx = open_thematic_index(path); } if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE; if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY; if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE; } start = set_min(tile_features); end = set_max(tile_features); /* It turns out to be MUCH faster off of a CD-ROM to */ /* read each row and discard unwanted ones than to */ /* forward seek past them. It's about the same off */ /* of a hard disk. */ fseek(fcrel.table[feature].fp,index_pos(start,fcrel.table[feature]), SEEK_SET); for (i=start;i<=end;i++) { row = read_next_row(fcrel.table[feature]); if (!set_member( i, feature_rows )) { free_row(row,fcrel.table[feature]); continue; } if (!set_member( i, tile_features )) { free_row(row,fcrel.table[feature]); continue; } if (degree == R_ONE) { prim_rownum = fc_row_number( row, fcrel, tile ); primlist = NULL; p = NULL; } else { primlist = fc_row_numbers( row, fcrel, tile, &idx ); } free_row( row, fcrel.table[feature] ); if (!primlist) { if ((prim_rownum<1)||(prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives); } } else { p = ll_first(primlist); while (!ll_end(p)) { ll_element(p,&prim_rownum); if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives); } p = ll_next(p); } } if (primlist) ll_reset(primlist); if (kbhit()) { if (getch()==27) { *status = 0; break; } } } set_nuke(&primitive_rows); set_nuke(&tile_features); if (idx.fp) close_thematic_index(&idx); *status = 1; if (kbhit()) { if (getch()==27) { *status = 0; break; } } } return primitives; }
/************************************************************************* * *N get_selected_primitives * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function determines all of the selected primitive rows from * the selected features. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * view <input> == (view_type *) view structure. * themenum <input> == (int) theme number. * library <input> == (library_type *) VPF library structure. * mapenv <input> == (map_environment_type *) map environment. * status <output> == (int *) status of the function: * 1 if completed, 0 if user escape. * get_selected_primitives <output> == (set_type *) array of sets, each position * representing the set of primitives for the * corresponding tile in the tileref.aft table. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *************************************************************************/ set_type *get_selected_primitives( view_type *view, int themenum, library_type *library, map_environment_type *mapenv, int *status ) { int fcnum, finished, found, cov, tilecover, TILEPATH_, degree; int feature, prim; vpf_table_type tile_table; row_type row; char *ptable[] = {"","edg","fac","txt","end","cnd"}; char *spxname[] = {"","esi","fsi","tsi","nsi","csi"}; char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"}; set_type feature_rows, primitive_rows, tile_features; set_type *primitives; rspf_int32 prim_rownum, count, tile; register rspf_int32 i,j, pclass, start,end; char path[255], covpath[255], tiledir[255], *buf, str[255]; fcrel_type fcrel; linked_list_type primlist; position_type p; vpf_relate_struct rcell; ThematicIndex idx; primitives = (set_type *)vpfmalloc((library->ntiles+1)*sizeof(set_type)); for (i=0;i<=library->ntiles;i++) { primitives[i].size = 0; primitives[i].buf = NULL; } fcnum = view->theme[themenum].fcnum; feature_rows = get_selected_features( view, themenum, *library ); /* Open the tile reference table, if present */ sprintf(path,"%stileref\\tileref.aft",library->path); if (access(path,0) != 0) { tilecover = FALSE; } else { tile_table = vpf_open_table(path,disk,"rb",NULL); TILEPATH_ = table_pos("TILE_NAME",tile_table); tilecover = TRUE; } for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) { if ((pclass != library->fc[fcnum].primclass) && (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue; /* Set up the feature class table relate chain. */ /* The feature table is fcrel.table[0]. */ /* The primitive table is the last table in the chain: */ /* fcrel.table[ fcrel.nchain-1 ]. */ j = 0; for (i=0;i<strlen(library->fc[fcnum].table);i++) if (library->fc[fcnum].table[i] == '\\') j = i+1; strcpy( str, &(library->fc[fcnum].table[j])); fcrel = select_feature_class_relate(fcnum, library, str, ptable[pclass]); feature = 0; prim = fcrel.nchain-1; p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list); ll_element(p,&rcell); degree = rcell.degree; /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/ for (tile = 2; tile <= library->ntiles; tile++ ) { if (!set_member(tile,library->tile_set)) continue; if (tilecover) { row = get_row(tile,tile_table); buf = (char *)get_table_element(TILEPATH_,row,tile_table, NULL,&count); free_row(row,tile_table); strcpy(tiledir,buf); rightjust(tiledir); strcat(tiledir,"\\"); free(buf); } else { strcpy(tiledir,""); } cov = library->fc[fcnum].coverage; strcpy( covpath, library->cover[cov].path ); finished = 1; found = 0; /* Open primitive table in tile */ sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]); if (access(path,0) != 0) continue; found = 1; fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL); if (primitives[tile].size > 0) { printf("Oops! size = %ld\n",primitives[tile].size); exit(1); } primitives[tile] = set_init(fcrel.table[prim].nrows+1); /* Get the set of primitive rows within the map extent */ /* Look for spatial index file */ primitive_rows.size = 0; if (mapenv->projection == PLATE_CARREE && mapenv->mapextent.x1 < mapenv->mapextent.x2) { sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]); if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = spatial_index_search(path, mapenv->mapextent.x1,mapenv->mapextent.y1, mapenv->mapextent.x2,mapenv->mapextent.y2); } else { /* Next best thing - bounding rectangle table */ sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]); if (access(path,0)==0) { primitive_rows = bounding_select(path,mapenv->mapextent, library->dec_degrees); } } } /* projection check */ if (primitive_rows.size == 0) { /* Search through all the primitives */ primitive_rows=set_init(fcrel.table[prim].nrows+1); set_on(primitive_rows); } tile_thematic_index_name(fcrel.table[feature], path); if ( (strcmp(path,"") != 0) && (access(path,4)==0) ) { /* Tile thematic index for feature table present, */ tile_features = read_thematic_index( path, (char *)&tile ); } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } idx.fp = NULL; i = table_pos(rcell.key2,fcrel.table[prim]); if (i >= 0) { if (fcrel.table[prim].header[i].tdx) { sprintf(path,"%s%s",fcrel.table[prim].path, fcrel.table[prim].header[i].tdx); if (access(path,0)==0) idx = open_thematic_index(path); } if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE; if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY; if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE; } finished = 1; start = set_min(tile_features); end = set_max(tile_features); fseek(fcrel.table[feature].fp, index_pos(start,fcrel.table[feature]), SEEK_SET); for (i=start;i<=end;i++) { row = read_next_row(fcrel.table[feature]); if (!set_member( i, feature_rows )) { free_row(row,fcrel.table[feature]); continue; } if (!set_member( i, tile_features )) { free_row(row,fcrel.table[feature]); continue; } if (degree == R_ONE) { prim_rownum = fc_row_number( row, fcrel, tile ); primlist = NULL; p = NULL; } else { primlist = fc_row_numbers( row, fcrel, tile, &idx ); } free_row( row, fcrel.table[feature] ); if (!primlist) { if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives[tile]); } } else { p = ll_first(primlist); while (!ll_end(p)) { ll_element(p,&prim_rownum); if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives[tile]); } p = ll_next(p); } } if (kbhit()) { if (getch()==27) { *status = 0; finished = 0; break; } } } if (idx.fp) close_thematic_index(&idx); vpf_close_table(&(fcrel.table[prim])); set_nuke(&primitive_rows); set_nuke(&tile_features); if (set_empty(primitives[tile])) { set_nuke(&primitives[tile]); primitives[tile].size = 0; primitives[tile].buf = NULL; } if (!finished) { *status = 0; break; } } if (!finished) { *status = 0; deselect_feature_class_relate( &fcrel ); break; } if (found) *status = 1; if (kbhit()) { if (getch()==27) { *status = 0; deselect_feature_class_relate( &fcrel ); break; } } deselect_feature_class_relate( &fcrel ); } set_nuke(&feature_rows); if (tilecover) { vpf_close_table(&tile_table); } return primitives; }
void tcp_conn_map_remove(t_tcp_conn_map* tcp_conn_map,u16 src_ip,u16 dst_ip,u32 src_ip,u32 dst_ip) { u32 conn_id; t_tcp_conn_desc* tcp_conn_desc = NULL; t_tcp_conn_desc* next_tcp_conn_desc = NULL; t_llist_node* sentinel_node = NULL; t_llist_node* next = NULL; u32 count = 0; conn_id = dst_port | (src_port << 16); tcp_conn_desc = hashtable_get(tcp_conn_map->conn_map,conn_id); if (tcp_conn_desc == NULL) { return; } if (tcp_conn_desc->is_key_unique == 0) { hashtable_remove(tcp_conn_map->conn_map,conn_id); return; } else if (tcp_conn_desc->src_ip == src_ip && tcp_conn_desc->dst_ip == dst_ip && tcp_conn_desc->src_port == src_port && tcp_conn_desc->dst_port == dst_port) { sentinel_node = ll_sentinel(tcp_conn_map->duplicate_conn_list); next=ll_first(tcp_conn_map->duplicate_conn_list); while(next != sentinel_node) { next_tcp_conn_desc = next->val; if (next_tcp_conn_desc->conn_id == conn_id) { count++; } if (count == 1) { remove_node = next; } } if (count == 1) { remove_node->val->is_unique_key = 0; } hashtable_remove(tcp_conn_map->conn_map,conn_id); hashtable_put(tcp_conn_map->conn_map,conn_id,remove_node->val); ll_delete_node(remove_node); } else { sentinel_node = ll_sentinel(tcp_conn_map->duplicate_conn_list); next = ll_first(tcp_conn_map->duplicate_conn_list); while(next != sentinel_node) { next_tcp_conn_desc = next->val; if (next_tcp_conn_desc->src_ip == src_ip && next_tcp_conn_desc->dst_ip == dst_ip && next_tcp_conn_desc->src_port == src_port && next_tcp_conn_desc->dst_port == dst_port) { remove_node = next; } if (next_tcp_conn_desc->conn_id == conn_id) { count++; } } ll_delete_node(remove_node); if (count == 1) { tcp_conn_desc->is_key_unique == 0 } } }