static guint wcap_url_hash (gconstpointer key) { const CamelURL *u = (CamelURL *)key; guint hash = 0; add_hash (&hash, u->user); add_hash (&hash, u->host); return hash; }
static guint pop3_url_hash (gconstpointer key) { const CamelURL *u = (CamelURL *) key; guint hash = 0; add_hash (&hash, u->user); add_hash (&hash, u->host); hash ^= u->port; return hash; }
int insert_queue( all_queues *aq, pbs_queue *pque) { int rc; lock_allques_mutex(aq, __func__, NULL, LOGLEVEL); if ((rc = insert_thing(aq->ra,pque)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array"); } else { add_hash(aq->ht,rc,pque->qu_qs.qu_name); rc = PBSE_NONE; } unlock_allques_mutex(aq, __func__, NULL, LOGLEVEL); return(rc); } /* END insert_queue() */
/* Make sure the hash table is big enough. */ static int check_hash_size( void ) { int i; Map* m; /* Are we just starting out? */ if ( hash_table == (Map**) 0 ) hash_size = INITIAL_HASH_SIZE; /* Is it at least three times bigger than the number of entries? */ else if ( hash_size >= map_count * 3 ) return 0; else { /* No, got to expand. */ free( (void*) hash_table ); /* Find a prime at least six times bigger. */ for ( hash_size = map_count * 6; ! is_prime( hash_size ); ++hash_size ) continue; } /* Make the new table. */ hash_table = (Map**) malloc( hash_size * sizeof(Map*) ); if ( hash_table == (Map**) 0 ) return -1; /* Clear it. */ for ( i = 0; i < hash_size; ++i ) hash_table[i] = (Map*) 0; /* And rehash all entries. */ for ( m = maps; m != (Map*) 0; m = m->next ) if ( add_hash( m ) < 0 ) return -1; return 0; }
int insert_batch_request( batch_request *preq) { int rc; pthread_mutex_lock(brh.brh_mutex); if ((rc = insert_thing(brh.brh_ra, preq)) < 0) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE\n"); } else { add_hash(brh.brh_ht, rc, preq->rq_id); rc = PBSE_NONE; } pthread_mutex_unlock(brh.brh_mutex); return(rc); } /* END insert_batch_request() */
int add_to_hash_map( hash_map *hm, void *obj, char *key) { int index; int rc = PBSE_NONE; pthread_mutex_lock(hm->hm_mutex); if (get_value_hash(hm->hm_ht, key) >= 0) { rc = ALREADY_IN_HASH_MAP; } else { if ((index = insert_thing(hm->hm_ra, obj)) == -1) { rc = ENOMEM; log_err(rc, __func__, "Memory failure"); } else add_hash(hm->hm_ht, index, key); } pthread_mutex_unlock(hm->hm_mutex); return(rc); } /* END add_to_hash_map() */
int insert_job_first( struct all_jobs *aj, job *pjob) { int rc; pthread_mutex_lock(aj->alljobs_mutex); if ((rc = insert_thing_after(aj->ra,pjob,ALWAYS_EMPTY_INDEX)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE"); } else { add_hash(aj->ht,rc,pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job_first () */
/* * insert a new job into the array after a previous one * * @param already_in - the job this job should follow * @param pjob - the job to be inserted * @return PBSE_NONE if the job is inserted correctly */ int insert_job_after( struct all_jobs *aj, job *already_in, job *pjob) { int rc; int i; pthread_mutex_lock(aj->alljobs_mutex); i = get_value_hash(aj->ht,already_in->ji_qs.ji_jobid); if (i < 0) rc = THING_NOT_FOUND; else { if ((rc = insert_thing_after(aj->ra,pjob,i)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE"); } else { add_hash(aj->ht,rc,pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job_after() */
/* * insert a new job into the array * * @param pjob - the job to be inserted * @return PBSE_NONE on success */ int insert_job( struct all_jobs *aj, job *pjob) { int rc; pthread_mutex_lock(aj->alljobs_mutex); if ((rc = insert_thing(aj->ra,pjob)) == -1) { rc = ENOMEM; log_err(rc, __func__, (char *)"No memory to resize the array...SYSTEM FAILURE\n"); } else { add_hash(aj->ht, rc, pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job() */
int insert_queue( all_queues *aq, pbs_queue *pque) { int rc; pthread_mutex_lock(aq->allques_mutex); if ((rc = insert_thing(aq->ra,pque)) == -1) { rc = ENOMEM; log_err(rc, __func__, (char *)"No memory to resize the array"); } else { add_hash(aq->ht,rc,pque->qu_qs.qu_name); rc = PBSE_NONE; } pthread_mutex_unlock(aq->allques_mutex); return(rc); } /* END insert_queue() */
void apply_charm (CHAR_DATA *caster, CHAR_DATA *victim, char *name, int duration, int source) { CHARM_DATA *tmp, *charm; CREATE (charm, CHARM_DATA, 1); charm->name = add_hash (name); charm->original_hours = duration; charm->current_hours = charm->original_hours; charm->power_source = source; charm->next = NULL; if ( !victim->charms ) { CREATE (victim->charms, CHARM_DATA, 1); victim->charms = charm; } else for ( tmp = victim->charms; tmp; tmp = tmp->next ) { if ( !str_cmp (tmp->name, charm->name) ) { /* Recharge.*/ tmp->current_hours = charm->current_hours; break; } if ( !tmp->next ) { CREATE (tmp->next, CHARM_DATA, 1); tmp->next = charm; break; } } }
void insert_mfn(const char *name, int i) { hash_data hd; (void) free_hash(name, msghash, MSGHASHSIZE); hd.ival = i; (void) add_hash(name, hd, msghash, MSGHASHSIZE); }
void initialize_universes() { int i; dhcp_universe.name = "dhcp"; dhcp_universe.hash = new_hash (); if (!dhcp_universe.hash) error ("Can't allocate dhcp option hash table."); for (i = 0; i < 256; i++) { dhcp_universe.options [i] = &dhcp_options [i]; add_hash (dhcp_universe.hash, (unsigned char *)dhcp_options [i].name, 0, (unsigned char *)&dhcp_options [i]); } universe_hash.hash_count = DEFAULT_HASH_SIZE; add_hash (&universe_hash, (unsigned char *)dhcp_universe.name, 0, (unsigned char *)&dhcp_universe); }
void add_player(dbref who) { hash_data hd; hd.dbval = who; if (add_hash(NAME(who), hd, player_list, PLAYER_HASH_SIZE) == NULL) panic("Out of memory"); else return; }
/* * Move a successfully used entry to level2. If already at level2, * move it to the end of the LRU queue.. */ static inline void move_to_level2(struct dir_cache_entry * old_de, struct hash_list * hash) { struct dir_cache_entry * de; if (old_de->lru_head == &level2_head) { update_lru(old_de); return; } de = level2_head; level2_head = de->next_lru; remove_hash(de); COPYDATA(old_de, de); add_hash(de, hash); }
int insert_addr_name_info( char *hostname, char *full_hostname, struct sockaddr_in *sai) { int rc = PBSE_NONE; int index; network_info *ni; char s_addr_key[65]; if (cache.nc_mutex == NULL) return(-1); pthread_mutex_lock(cache.nc_mutex); /* only insert if it isn't already there */ if (get_value_hash(cache.nc_namekey, hostname) < 0) { ni = get_network_info_holder(hostname, full_hostname, sai); if ((index = insert_thing(cache.nc_ra, ni)) < 0) rc = ENOMEM; else { /* store the key in both hash tables so we can look things up either way */ add_hash(cache.nc_namekey, index, ni->hostname); sprintf (s_addr_key, "%d", sai->sin_addr.s_addr); add_hash(cache.nc_saikey, index, strdup(s_addr_key)); } } pthread_mutex_unlock(cache.nc_mutex); return(rc); } /* END insert_addr_name_info() */
int insert_alps_reservation( alps_reservation *ar) { int index; int rc; pthread_mutex_lock(alps_reservations.rh_mutex); if ((index = insert_thing(alps_reservations.rh_alps_rsvs, ar)) >= 0) rc = add_hash(alps_reservations.rh_ht, index, ar->rsv_id); else rc = ENOMEM; pthread_mutex_unlock(alps_reservations.rh_mutex); return(rc); } /* insert_alps_reservation() */
int increment_queued_jobs( user_info_holder *uih, char *user_name, job *pjob) { int rc = PBSE_NONE; user_info *ui; int index; unsigned int num_submitted = count_jobs_submitted(pjob); pthread_mutex_lock(uih->ui_mutex); /* get the user if there is one */ if ((index = get_value_hash(uih->ui_ht, user_name)) > 0) { ui = uih->ui_ra->slots[index].item; ui->num_jobs_queued += num_submitted; } else { /* user doesn't exist, create a new one and insert */ ui = calloc(1, sizeof(user_info)); ui->user_name = strdup(user_name); ui->num_jobs_queued = num_submitted; if ((index = insert_thing(uih->ui_ra, ui)) == -1) { rc = ENOMEM; log_err(rc, __func__, (char *)"Can't resize the user info array"); } else { add_hash(uih->ui_ht, index, ui->user_name); } } pthread_mutex_unlock(uih->ui_mutex); return(rc); } /* END increment_queued_jobs() */
void add_player(dbref who) { hash_data hd; hd.dbval = who; if (add_hash(NAME(who), hd, player_list, PLAYER_HASH_SIZE) == NULL) panic("Out of memory"); if(who != lookup_player(NAME(who))) { log_status(HASH1_MSG); wall_wizards(MARK HASH1_MSG); refresh_players(); if(who != lookup_player(NAME(who))) { log_status(HASH2_MSG); wall_wizards(MARK HASH2_MSG); } } return; }
int insert_job_after_index( struct all_jobs *aj, int index, job *pjob) { int rc = -1; if (aj == NULL) { rc = PBSE_BAD_PARAMETER; log_err(rc, __func__, "null job array input"); return(rc); } if (pjob == NULL) { rc = PBSE_BAD_PARAMETER; log_err(rc, __func__, "null job input"); return(rc); } pthread_mutex_lock(aj->alljobs_mutex); rc = insert_thing_after(aj->ra, pjob, index); if (rc == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE"); } else { add_hash(aj->ht, rc, pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job_after_index() */
/* Make sure the hash table is big enough. */ static int check_hash_size( void ) { int i; Map* m; /* Are we just starting out? */ if ( hash_table == (Map**) 0 ) { hash_size = INITIAL_HASH_SIZE; hash_mask = hash_size - 1; } /* Is it at least three times bigger than the number of entries? */ else if ( hash_size >= map_count * 3 ) return 0; else { /* No, got to expand. */ free( (void*) hash_table ); /* Double the hash size until it's big enough. */ do { hash_size = hash_size << 1; } while ( hash_size < map_count * 6 ); hash_mask = hash_size - 1; } /* Make the new table. */ hash_table = (Map**) malloc( hash_size * sizeof(Map*) ); if ( hash_table == (Map**) 0 ) return -1; /* Clear it. */ for ( i = 0; i < hash_size; ++i ) hash_table[i] = (Map*) 0; /* And rehash all entries. */ for ( m = maps; m != (Map*) 0; m = m->next ) if ( add_hash( m ) < 0 ) return -1; return 0; }
FileRecordNumber :: frn_record * FileRecordNumber :: _get_record( int recno ) { frn_record * x; x = find_hash( recno ); if ( x != NULL ) { delete_lru( x ); return x; } x = new( record_length) frn_record( recno ); if ( __get_record( x ) != 0 ) { delete x; return NULL; } add_hash( x ); return x; }
UCHAR * FileRecordNumber :: get_empty_record( int recno, UINT32& magic ) { frn_record * x; x = find_hash( recno ); if ( x != NULL ) { delete_lru( x ); } else { x = new( record_length ) frn_record( recno ); add_hash( x ); } x->dirty = 1; x->clean = -1; magic = (UINT32)x; return x->dat; }
void dcache_add(struct inode * dir, const char * name, int len, unsigned long ino) { struct hash_list * hash; struct dir_cache_entry *de; if (len > DCACHE_NAME_LEN) return; hash = hash_table + hash_fn(dir->i_dev, dir->i_ino, namehash(name,len)); if ((de = find_entry(dir, name, len, hash)) != NULL) { de->ino = ino; update_lru(de); return; } de = level1_head; level1_head = de->next_lru; remove_hash(de); de->dev = dir->i_dev; de->dir = dir->i_ino; de->version = dir->i_version; de->ino = ino; de->name_len = len; memcpy(de->name, name, len); add_hash(de, hash); }
static int process_command_line(state *s, int argc, char **argv) { int i; while ((i = getopt(argc, argv, "I:i:M:X:x:m:o:A:a:tnwzsSp:erhvV0lbkqU")) != -1) { switch (i) { case 'I': s->mode |= mode_size_all; // Note that there is no break here case 'i': s->mode |= mode_size; s->size_threshold = find_block_size(s,optarg); if (0 == s->size_threshold) { print_error(s,"%s: Requested size threshold implies not hashing anything", __progname); exit(STATUS_USER_ERROR); } break; case 'p': s->mode |= mode_piecewise; s->piecewise_size = find_block_size(s, optarg); if (0 == s->piecewise_size) { print_error(s,"%s: Piecewise blocks of zero bytes are impossible", __progname); exit(STATUS_USER_ERROR); } break; case 'q': s->mode |= mode_quiet; break; case 't': s->mode |= mode_timestamp; MD5DEEP_ALLOC(char,s->time_str,MAX_TIME_STRING_LENGTH); break; case 'n': s->mode |= mode_not_matched; break; case 'w': s->mode |= mode_which; break; case 'a': s->mode |= mode_match; check_matching_modes(s); add_hash(s,optarg,optarg); s->hashes_loaded = TRUE; break; case 'A': s->mode |= mode_match_neg; check_matching_modes(s); add_hash(s,optarg,optarg); s->hashes_loaded = TRUE; break; case 'l': s->mode |= mode_relative; break; case 'b': s->mode |= mode_barename; break; case 'o': s->mode |= mode_expert; setup_expert_mode(s,optarg); break; case 'M': s->mode |= mode_display_hash; case 'm': s->mode |= mode_match; check_matching_modes(s); if (load_match_file(s,optarg)) s->hashes_loaded = TRUE; break; case 'X': s->mode |= mode_display_hash; case 'x': s->mode |= mode_match_neg; check_matching_modes(s); if (load_match_file(s,optarg)) s->hashes_loaded = TRUE; break; case 'z': s->mode |= mode_display_size; break; case '0': s->mode |= mode_zero; break; case 'S': s->mode |= mode_warn_only; s->mode |= mode_silent; break; case 's': s->mode |= mode_silent; break; case 'e': s->mode |= mode_estimate; break; case 'r': s->mode |= mode_recursive; break; case 'k': s->mode |= mode_asterisk; break; case 'h': usage(); exit (STATUS_OK); case 'v': print_status("%s",VERSION); exit (STATUS_OK); case 'V': // COPYRIGHT is a format string, complete with newlines print_status(COPYRIGHT); exit (STATUS_OK); default: try_msg(); exit (STATUS_USER_ERROR); } } check_flags_okay(s); return STATUS_OK; }
void* mmc_map( char* filename, struct stat* sbP, struct timeval* nowP ) { time_t now; struct stat sb; Map* m; int fd; /* Stat the file, if necessary. */ if ( sbP != (struct stat*) 0 ) sb = *sbP; else { if ( stat( filename, &sb ) != 0 ) { syslog( LOG_ERR, "stat - %m" ); return (void*) 0; } } /* Get the current time, if necessary. */ if ( nowP != (struct timeval*) 0 ) now = nowP->tv_sec; else now = time( (time_t*) 0 ); /* See if we have it mapped already, via the hash table. */ if ( check_hash_size() < 0 ) { syslog( LOG_ERR, "check_hash_size() failure" ); return (void*) 0; } m = find_hash( sb.st_ino, sb.st_dev, sb.st_size, sb.st_ctime ); if ( m != (Map*) 0 ) { /* Yep. Just return the existing map */ ++m->refcount; m->reftime = now; return m->addr; } /* Open the file. */ fd = open( filename, O_RDONLY ); if ( fd < 0 ) { syslog( LOG_ERR, "open - %m" ); return (void*) 0; } /* Find a free Map entry or make a new one. */ if ( free_maps != (Map*) 0 ) { m = free_maps; free_maps = m->next; --free_count; } else { m = (Map*) malloc( sizeof(Map) ); if ( m == (Map*) 0 ) { (void) close( fd ); syslog( LOG_ERR, "out of memory allocating a Map" ); return (void*) 0; } ++alloc_count; } /* Fill in the Map entry. */ m->ino = sb.st_ino; m->dev = sb.st_dev; m->size = sb.st_size; m->ctime = sb.st_ctime; m->refcount = 1; m->reftime = now; /* Avoid doing anything for zero-length files; some systems don't like ** to mmap them, other systems dislike mallocing zero bytes. */ if ( m->size == 0 ) m->addr = (void*) 1; /* arbitrary non-NULL address */ else { size_t size_size = (size_t) m->size; /* loses on files >2GB */ #ifdef HAVE_MMAP /* Map the file into memory. */ m->addr = mmap( 0, size_size, PROT_READ, MAP_PRIVATE, fd, 0 ); if ( m->addr == (void*) -1 && errno == ENOMEM ) { /* Ooo, out of address space. Free all unreferenced maps ** and try again. */ panic(); m->addr = mmap( 0, size_size, PROT_READ, MAP_PRIVATE, fd, 0 ); } if ( m->addr == (void*) -1 ) { syslog( LOG_ERR, "mmap - %m" ); (void) close( fd ); free( (void*) m ); --alloc_count; return (void*) 0; } #else /* HAVE_MMAP */ /* Read the file into memory. */ m->addr = (void*) malloc( size_size ); if ( m->addr == (void*) 0 ) { /* Ooo, out of memory. Free all unreferenced maps ** and try again. */ panic(); m->addr = (void*) malloc( size_size ); } if ( m->addr == (void*) 0 ) { syslog( LOG_ERR, "out of memory storing a file" ); (void) close( fd ); free( (void*) m ); --alloc_count; return (void*) 0; } if ( httpd_read_fully( fd, m->addr, size_size ) != size_size ) { syslog( LOG_ERR, "read - %m" ); (void) close( fd ); free( (void*) m ); --alloc_count; return (void*) 0; } #endif /* HAVE_MMAP */ } (void) close( fd ); /* Put the Map into the hash table. */ if ( add_hash( m ) < 0 ) { syslog( LOG_ERR, "add_hash() failure" ); free( (void*) m ); --alloc_count; return (void*) 0; } /* Put the Map on the active list. */ m->next = maps; maps = m; ++map_count; /* Update the total byte count. */ mapped_bytes += m->size; /* And return the address. */ return m->addr; }
void build_sub_file(char *sname, Boolean embed) /****************************************************************** * go look for lines of format : * in|out * to tell us what to substitute * in| * is ok if embed is false, and will delete all ins. * * if embed is true, we'll skip all white space. * ******************************************************************/ { FILE *sfile; int line; char buf[256]; char *s; char word1[256]; char word2[256]; char *d; char c; Sub *sub; sfile = must_open(sname, "r"); line = 0; for (;;) { if (fgets(buf, sizeof(buf)-1, sfile) == NULL) break; line++; s = buf; if (!embed) s = skip_space(s); d = word1; for (;;) { c = *s++; if (c == 0) { fatal("%s %d - Line with no separator", sname, line); } if (!embed) { if (isspace(c)) break; } else if (c == separator) break; *d++ = c; } *d++ = 0; d = word2; if (!embed) s = skip_space(s); for (;;) { c = *s++; if (!embed) { if (isspace(c) || c == 0) break; } else { if (c == 0 || c == '\r' || c == '\n') break; } *d++ = c; } *d++ = 0; if (!embed && (word2[0] == 0)) fatal("%s %d - Line with no substitution", sname, line); sub = begmem(sizeof(*sub)); sub->in = clone_string(word1); sub->insize = strlen(word1); sub->out = clone_string(word2); sub->outsize = strlen(word2); add_hash(global_hash, sub); } fclose(sfile); }
//////////////////////////////////////////////////////////////////////////////////////////////// // // @tsv - Utility to convert export list to different required format // // USAGE: makeexport module_exportlist.c module_exportlist.h exportlist.txt module_hashlist.h // /////////////////////////////////////////////////////////////////////////////////////////////// int main( int argc, char **argv ) { if ( argc < 5 ) { printf("#error Not enough arguments for export list maker.\n"); exit(-1); } char* file1 = load_from_file( argv[1]); FILE* out_h = fopen(argv[2],"wb"); FILE* out_txt = fopen(argv[3],"wb"); FILE* out_hash = fopen(argv[4],"wb"); if (!out_h) { printf("#error Error creation exportlist.h.\n"); exit(-1); } if (!out_txt) { printf("#error Error creation exportlist.txt.\n"); exit(-1); } fprintf(out_h,"//Auto generated file. Do not edit the contents of this file.\n"); fprintf(out_h,"//Update the core/module_exportlist.c\n\n"); fprintf(out_h,"#ifndef MODULE_EXPORTLIST_H\n"); fprintf(out_h,"#define MODULE_EXPORTLIST_H\n\n"); // Separate CHDK build num char* build = BUILD_NUMBER; char* e; int build_num=0; int mult=10000; for ( ; *build; build++) { if ( *build<'0' || *build>'9') continue; build_num += mult*strtol(build, &e, 0/*autodetect base oct-dec-hex*/); if ( mult==1 ) break; build=e; mult/=100; } if ( *build ) fprintf(out_h,"#define CHDK_BUILD_NUM %d\n\n",build_num); num_lines=0; char* cur, *cursym; cur = file1; const char* exp_def_tag="/* EXPORTED_DEFINES_"; int flag_section_defines = 0; fprintf(out_h,"#ifndef THIS_IS_CHDK_CORE\n"); for(; *cur && *cur!='{'; cur++) { if ( !strncmp(cur,exp_def_tag,strlen(exp_def_tag)) ) { cur+=strlen(exp_def_tag); if (*cur=='B' ) { fprintf(out_h,"\n//Section: exported defines\n"); flag_section_defines=1; } else if (*cur=='E' ) { flag_section_defines=0;} for(; *cur && *cur!=10; cur++); } if (flag_section_defines) { cursym=cur; for(; *cur && *cur!=10 && *cur!='='; cur++); if ( *cur=='=' ) { *cur=0; cur++; cut_export_token(cursym); char *symbol = find_last_token(cursym); fprintf(out_h,"#undef %s\n",symbol); fprintf(out_h,"extern %s;\n",cursym); for(; *cur && *cur!=10; cur++); //goto eol } } } fprintf(out_h,"#endif\n"); fprintf(out_h,"\n\n"); fprintf(out_h,"\n//Section: ids of exported symbols\n"); for(; *cur && *cur!=10; cur++); //get eol // Main cycle for(;*cur; ) { for(; *cur==9 || *cur==' '; cur++); if (*cur=='(') { for(cur++; *cur && *cur!=')'; cur++); for(; *cur==9 || *cur==' ' || *cur==')'; cur++); } //printf("%x [%c]\n",cur-file1,*cur); if ( *cur=='}') {break;} int is_address = 0; if (*cur=='&') { is_address = 1; for(cur++; *cur==9 || *cur==' '; cur++); } cursym=cur; for(; (*cur>='A' && *cur<='Z') || (*cur>='a' && *cur<='z') || (*cur>='0' && *cur<='9') || *cur=='_'; cur++); if (cursym!=cur) { char symbol[256], full_symbol[257]; int size=cur-cursym; if ( size>255) {size=255;} memcpy(symbol,cursym,size); symbol[size]=0; full_symbol[0] = 0; if (is_address) strcpy(full_symbol,"&"); strcat(full_symbol,symbol); cut_export_token(symbol); unsigned int hash_val = hash((unsigned char*)symbol); add_hash(hash_val,full_symbol); fprintf(out_txt,"%08x %s\n",hash_val,symbol); for(; size>=0; size--) { if ( symbol[size]>='a' && symbol[size]<='z') symbol[size]-=0x20; } fprintf(out_h,"#define MODULESYM_%-32s 0x%08x\n",symbol,hash_val); num_lines++; } for(; *cur && *cur!=10; cur++); for(; *cur==10; cur++); } sort_hash(); fprintf(out_hash,"// This is an automatically generated file. DO NOT EDIT!\n"); int n; for (n=0; n<hash_idx; n++) { fprintf(out_hash,"{ 0x%08x, %s },\n",hash_vals[n].hash,hash_vals[n].symbol); } if (num_lines>=1) fprintf(out_h,"\n#define EXPORTLIST_LAST_IDX %d\n\n",num_lines); else { fprintf(out_h,"#error Malformed export list. Only %d valid records\n\n",num_lines); exit(-2); } fprintf(out_h,"#endif\n"); fclose(out_h); fclose(out_txt); fclose(out_hash); return 0; }
int main(int argc, char *argv[]) { try { po::variables_map vm; po::options_description generic("options"); generic.add_options() ("help,h", "show this help") ("trees,t", po::value<uint32_t>(), "the number of trees"); po::options_description cmdline_options; cmdline_options.add(generic); po::store(po::command_line_parser(argc, argv). options(cmdline_options).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << generic << std::endl; return 0; } if (vm.count("trees")) { uint32_t trees = vm["trees"].as<uint32_t>(); forest.init(trees); } else { std::cout << "error: the number of tree is required" << std::endl; return -1; } } catch (std::exception &e) { std::cout << e.what() << std::endl; return -1; } std::string str1, str2; while (std::cin) { std::string line; std::getline(std::cin, line); if (line.empty()) continue; switch (state) { case SIM_OP: read_op(line); break; case SIM_ADD_STR: str1 = line; state = SIM_ADD_HASH; std::cout << "input the hash file" << std::endl; break; case SIM_ADD_HASH: str2 = line; state = SIM_ADD_HIST; std::cout << "input the histogram file" << std::endl; break; case SIM_ADD_HIST: add_hash(str1, str2, line); state = SIM_OP; break; case SIM_DEL: forest.remove_hash(line); std::cout << "true" << std::endl; state = SIM_OP; break; case SIM_GET_HASH: str1 = line; state = SIM_GET_FEAT; std::cout << "input the histogram file" << std::endl; break; case SIM_GET_FEAT: get_similar(str1, line); state = SIM_OP; break; case SIM_THRESHOLD: try { forest.set_threshold(boost::lexical_cast<float>(line)); std::cout << "true" << std::endl; } catch (...) { std::cout << "false" << std::endl; } state = SIM_OP; break; } } return 0; }
void* mmc_map( char* filename, struct stat* sbP ) { struct stat sb; Map* m; int fd; /* Stat the file if necessary. */ if ( sbP != (struct stat*) 0 ) sb = *sbP; else { if ( stat( filename, &sb ) != 0 ) { syslog( LOG_ERR, "stat - %m" ); return (void*) 0; } } /* See if we have it mapped already, via the hash table. */ if ( check_hash_size() < 0 ) { syslog( LOG_ERR, "check_hash_size() failure" ); return (void*) 0; } m = find_hash( sb.st_ino, sb.st_dev, sb.st_size, sb.st_mtime ); if ( m != (Map*) 0 ) { /* Yep. */ ++m->refcount; return m->addr; } /* Nope. Open the file. */ fd = open( filename, O_RDONLY ); if ( fd < 0 ) { syslog( LOG_ERR, "open - %m" ); return (void*) 0; } /* Find a free Map entry or make a new one. */ if ( free_maps != (Map*) 0 ) { m = free_maps; free_maps = m->next; --free_count; } else { m = (Map*) malloc( sizeof(Map) ); if ( m == (Map*) 0 ) { (void) close( fd ); return (void*) 0; } } /* Fill in the Map entry. */ m->ino = sb.st_ino; m->dev = sb.st_dev; m->size = sb.st_size; m->mtime = sb.st_mtime; m->refcount = 1; /* Avoid doing anything for zero-length files; some systems don't like ** to mmap them, other systems dislike mallocing zero bytes. */ if ( m->size == 0 ) m->addr = (void*) 1; /* arbitrary non-NULL address */ else { #ifdef HAVE_MMAP /* Map the file into memory. */ m->addr = mmap( 0, m->size, PROT_READ, MAP_SHARED, fd, 0 ); if ( m->addr == (void*) -1 ) { syslog( LOG_ERR, "mmap - %m" ); (void) close( fd ); free( (void*) m ); return (void*) 0; } #else /* HAVE_MMAP */ /* Read the file into memory. */ m->addr = (void*) malloc( m->size ); if ( m->addr == (void*) 0 ) { syslog( LOG_ERR, "not enough memory" ); (void) close( fd ); free( (void*) m ); return (void*) 0; } if ( read( fd, m->addr, m->size ) != m->size ) { syslog( LOG_ERR, "read - %m" ); (void) close( fd ); free( (void*) m ); return (void*) 0; } #endif /* HAVE_MMAP */ } (void) close( fd ); /* Put the Map into the hash table. */ if ( add_hash( m ) < 0 ) { syslog( LOG_ERR, "add_hash() failure" ); free( (void*) m ); return (void*) 0; } /* Put the Map on the active list. */ m->next = maps; maps = m; ++map_count; /* And return the address. */ return m->addr; }