static void test_exceptions(void) { hashset_t set = hashset_create(); assert(hashset_add(set, (void *)0) == -1); assert(hashset_add(set, (void *)1) == -1); }
void test_hashset_iter_remove() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); HashSetIter iter; hashset_iter_init(&iter, hs); while (hashset_iter_has_next(&iter)) { char const *e = hashset_iter_next(&iter); if (!strcmp(e, "bar")) hashset_iter_remove(&iter); } cc_assert(hashset_size(hs) == 2, cc_msg("hashset_iter: Expected size 2 but got %d ", hashset_size(hs))); cc_assert(!hashset_contains(hs, "bar"), cc_msg("hashset_iter: Element (%s) still pressent " "after removal", "bar")); hashset_destroy(hs); }
static void test_gaps(void) { hashset_t set = hashset_create(); /* fill the hashset */ hashset_add(set, (void *)0xbabe); hashset_add(set, (void *)0xbeef); hashset_add(set, (void *)0xbad); hashset_add(set, (void *)0xf00d); /* 0xf00d (nil) (nil) (nil) (nil) 0xbad 0xbabe 0xbeef */ /* make a gap */ hashset_remove(set, (void *)0xbeef); /* 0xf00d (nil) (nil) (nil) (nil) 0xbad 0xbabe 0x1 */ /* check that 0xf00d is still reachable */ assert(hashset_is_member(set, (void *)0xf00d)); /* add 0xbeef back */ hashset_add(set, (void *)0xbeef); /* 0xf00d (nil) (nil) (nil) (nil) 0xbad 0xbabe 0xbeef */ /* verify */ assert(hashset_is_member(set, (void *)0xbeef)); assert(hashset_is_member(set, (void *)0xf00d)); }
static void trivial(void) { char *missing = "missing"; char *items[] = {"zero", "one", "two", "three", NULL}; char *foo = "foo"; size_t ii, nitems = 4; hashset_t set = hashset_create(); if (set == NULL) { fprintf(stderr, "failed to create hashset instance\n"); abort(); } for (ii = 0; ii < nitems; ++ii) { hashset_add(set, items[ii]); } for (ii = 0; ii < nitems; ++ii) { assert(hashset_is_member(set, items[ii])); } assert(hashset_is_member(set, missing) == 0); assert(hashset_remove(set, items[1]) == 1); assert(hashset_num_items(set) == 3); assert(hashset_remove(set, items[1]) == 0); assert(hashset_add(set, foo) == 1); assert(hashset_add(set, foo) == 0); hashset_destroy(set); }
void test_hashset_add() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; char *d = "foo"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); hashset_add(hs, d); size_t size = hashset_size(hs); cc_assert(size == 3, cc_msg("hashset_add: Expected size was 3, but got %d", size)); cc_assert(hashset_contains(hs, a) && hashset_contains(hs, d), cc_msg("hashset_add: HashSet expected to contain elemnts" " %s and %s", a, d)); hashset_destroy(hs); }
void test_hashset_remove() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; char *d = "foo"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); hashset_add(hs, d); hashset_remove(hs, "bar"); size_t size = hashset_size(hs); cc_assert(size == 2, cc_msg("hashset_add: Expected size was 2, but got %d", size)); cc_assert(!hashset_contains(hs, "bar"), cc_msg("hashset_add: HashSet not expected to contain " "element %s", "foo")); hashset_destroy(hs); }
void test_hashset_iter_remove() { HashSet *hs; hashset_new(&hs); char *a = "foo"; char *b = "bar"; char *c = "baz"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); HashSetIter iter; hashset_iter_init(&iter, hs); char *e; while (hashset_iter_next(&iter, (void*) &e) != CC_ITER_END) { if (!strcmp(e, "bar")) hashset_iter_remove(&iter, NULL); } cc_assert(hashset_size(hs) == 2, cc_msg("hashset_iter: Expected size 2 but got %d ", hashset_size(hs))); cc_assert(!hashset_contains(hs, "bar"), cc_msg("hashset_iter: Element (%s) still pressent " "after removal", "bar")); hashset_destroy(hs); }
void test_hashset_remove_all() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; char *d = "foo"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); hashset_add(hs, d); hashset_remove_all(hs); size_t size = hashset_size(hs); cc_assert(size == 0, cc_msg("hashset_add: Expected size was 0, but got %d", size)); cc_assert(!hashset_contains(hs, "bar") && !hashset_contains(hs, c), cc_msg("hashset_add: HashSet not empty after removing" " all elements")); hashset_destroy(hs); }
void findPid(char* value, int size, hashset_t set) { int i; int string; char token [] = "return !thanks_do("; char *sid = (char*)malloc((20) * sizeof (char)); while (1==1) { if (strstr(value, token)) { char *begin = strstr(value, token); for (i = 0; i < 8; i++) { if (begin[i + 18] == ')') { sid[i] = '\0'; continue; } sid[i] = begin[i + 18]; } string = atoi(sid); hashset_add(set, string); value = begin; value++; }else{ break; } } free(sid); }
void favorites_get(FavoriteItems* favorites) { if(!favorites->loaded) { char* fileName = favorites_get_filename(); char* fileContent = NULL; if(access(fileName, F_OK) != -1) { long inputFileSize; FILE* inputFile = fopen(fileName, "rb"); fseek(inputFile, 0, SEEK_END); inputFileSize = ftell(inputFile); rewind(inputFile); fileContent = malloc((inputFileSize + 1) * (sizeof(char))); if(!fread(fileContent, sizeof(char), inputFileSize, inputFile)) { if(ferror(inputFile)) { exit(EXIT_FAILURE); } } fclose(inputFile); fileContent[inputFileSize] = 0; if(fileContent && strlen(fileContent)) { favorites->count = 0; char* p=strchr(fileContent,'\n'); while (p!=NULL) { favorites->count++; p=strchr(p+1,'\n'); } favorites->items = malloc(sizeof(char*) * favorites->count); favorites->count = 0; char* pb=fileContent, *pe, *s; pe=strchr(fileContent, '\n'); while(pe!=NULL) { *pe=0; if(!hashset_contains(favorites->set,pb)) { if(!favorites->skipComments || !(strlen(pb) && pb[0]=='#')) { s=hstr_strdup(pb); favorites->items[favorites->count++]=s; hashset_add(favorites->set,s); } } pb=pe+1; pe=strchr(pb, '\n'); } free(fileContent); } } else { // favorites file not found > favorites don't exist yet favorites->loaded=true; } free(fileName); } }
void testBlacklist() { const char* commandBlacklist[] = { "a","b","c","d","e" }; HashSet blacklist; int i; hashset_init(&blacklist); for (i = 0; i < 5; i++) { hashset_add(&blacklist, commandBlacklist[i]); } for (i = 0; i < 5; i++) { printf("match %d\n", hashset_contains(&blacklist, hstr_strdup(commandBlacklist[i]))); } }
static void test_iterating(void) { hashset_t set = hashset_create(); hashset_itr_t iter = hashset_iterator(set); int step; /* fill the hashset */ hashset_add(set, (void *)"Bob"); hashset_add(set, (void *)"Steve"); hashset_add(set, (void *)"Karen"); hashset_add(set, (void *)"Ellen"); step = 0; while(hashset_iterator_has_next(iter)) { if(step == 0) { assert(strncmp((char *)hashset_iterator_value(iter), "Karen", 5) == 0); } if(step == 1) { assert(strncmp((char *)hashset_iterator_value(iter), "Steve", 5) == 0); } if(step == 2) { assert(strncmp((char *)hashset_iterator_value(iter), "Bob", 3) == 0); } if(step == 3) { assert(strncmp((char *)hashset_iterator_value(iter), "Ellen", 5) == 0); } hashset_iterator_next(iter); step++; } assert(hashset_iterator_has_next(iter) == 0); assert(hashset_iterator_next(iter) == -1); }
void test_hashset_iter_next() { HashSet *hs = hashset_new(); char *a = "foo"; char *b = "bar"; char *c = "baz"; hashset_add(hs, a); hashset_add(hs, b); hashset_add(hs, c); size_t x = 0; size_t y = 0; size_t z = 0; HashSetIter iter; hashset_iter_init(&iter, hs); while (hashset_iter_has_next(&iter)) { char const *e = hashset_iter_next(&iter); if (!strcmp(e, "foo")) x++; if (!strcmp(e, "bar")) y++; if (!strcmp(e, "baz")) z++; } cc_assert((x == 1) && (y == 1) && (z == 1), cc_msg("hashset_iter: Unexpected number of " "elements returned by the iterator")); hashset_destroy(hs); }
int main(int argc, char *argv[]) { const char *commandBlacklist[] = {"ls", "pwd", "cd", "hh", "mc"}; HashSet blacklist; int i; hashset_init(&blacklist); for(i=0; i<5; i++) { hashset_add(&blacklist, commandBlacklist[i]); } for(i=0; i<5; i++) { printf("match %d\n", hashset_contains(&blacklist, strdup(commandBlacklist[i]))); } }
/* * added by Markus Mohanty */ void hashset_union(hashset_t set, hashset_t toJoin) { int i; for(i = 0;i < toJoin->nitems;i++) { char* value = toJoin->items[i]; if(value != 0 && value != 1) { char * dest = malloc(strlen(value)); strcpy(dest, value); hashset_add(set, value); } } }
void favorites_add(FavoriteItems* favorites, char* newFavorite) { if(favorites->count) { favorites->items=realloc(favorites->items, sizeof(char*) * ++favorites->count); favorites->items[favorites->count-1]=hstr_strdup(newFavorite); favorites_choose(favorites, newFavorite); } else { favorites->items=malloc(sizeof(char*)); favorites->items[0]=hstr_strdup(newFavorite); favorites->count=1; } favorites_save(favorites); hashset_add(favorites->set, newFavorite); }
void testGetKeys() { const char* commandBlacklist[] = { "a","b","c","d","e" }; HashSet blacklist; int i; hashset_init(&blacklist); for (i = 0; i < 5; i++) { hashset_add(&blacklist, commandBlacklist[i]); } char **keys=hashset_keys(&blacklist); if(keys) { for(i=0; i<hashset_size(&blacklist); i++) { printf("\nKey: %s", keys[i]); } } }
static void test_fill_with_deleted_items() { char *s = "some string"; hashset_t set = hashset_create(); if (set == NULL) abort(); /* fill `set` with deleted items */ for (int i = 0; i < 8; ++i) { hashset_add(set, s + i); hashset_remove(set, s + i); } /* this should not cause an infinite loop */ assert(hashset_is_member(set, s) == 0); hashset_destroy(set); }
LIBCOUCHBASE_API libcouchbase_timer_t libcouchbase_timer_create(libcouchbase_t instance, const void *command_cookie, libcouchbase_uint32_t usec, int periodic, libcouchbase_timer_callback callback, libcouchbase_error_t *error) { libcouchbase_timer_t tmr = calloc(1, sizeof(struct libcouchbase_timer_st)); if (!tmr) { *error = libcouchbase_synchandler_return(instance, LIBCOUCHBASE_CLIENT_ENOMEM); return NULL; } if (!callback) { *error = libcouchbase_synchandler_return(instance, LIBCOUCHBASE_EINVAL); return NULL; } tmr->instance = instance; tmr->callback = callback; tmr->cookie = command_cookie; tmr->usec = usec; tmr->periodic = periodic; tmr->event = instance->io->create_timer(instance->io); if (tmr->event == NULL) { free(tmr); *error = libcouchbase_synchandler_return(instance, LIBCOUCHBASE_CLIENT_ENOMEM); return NULL; } instance->io->update_timer(instance->io, tmr->event, tmr->usec, tmr, timer_callback); hashset_add(instance->timers, tmr); *error = libcouchbase_synchandler_return(instance, LIBCOUCHBASE_SUCCESS); return tmr; }
/* Add contents of file to hashset */ int add_file(HashSet *hashset, char *curr) { FILE *f = fopen(curr, "r"); if(!f) { fprintf(stderr, "error opening file %s: %s\n", curr, strerror(errno)); return 1; } char buf[BUF_SIZE]; while(fgets(buf, BUF_SIZE, f)) { char *curr; char *next = buf; next_word(&curr, &next); while(*curr) { if(hashset_add(hashset, (void *)curr)) printf("added \"%s\"\n", curr); next_word(&curr, &next); } } fclose(f); return 0; }
LIBCOUCHBASE_API lcb_error_t lcb_durability_poll(lcb_t instance, const void *cookie, const lcb_durability_opts_t *options, lcb_size_t ncmds, const lcb_durability_cmd_t *const *cmds) { hrtime_t now = gethrtime(); lcb_durability_set_t *dset; lcb_size_t ii; lcb_io_opt_t io = instance->settings.io; if (!ncmds) { return LCB_EINVAL; } dset = calloc(1, sizeof(*dset)); if (!dset) { return LCB_CLIENT_ENOMEM; } dset->opts = *options; dset->instance = instance; if (!DSET_OPTFLD(dset, timeout)) { DSET_OPTFLD(dset, timeout) = instance->settings.durability_timeout; } if (-1 == verify_critera(instance, dset)) { free(dset); return LCB_DURABILITY_ETOOMANY; } /* set our timeouts now */ dset->us_timeout = (lcb_uint32_t)(now / 1000) + DSET_OPTFLD(dset, timeout); dset->timer = io->v.v0.create_timer(io); dset->cookie = cookie; dset->nentries = ncmds; dset->nremaining = ncmds; /** Get the timings */ if (!DSET_OPTFLD(dset, interval)) { DSET_OPTFLD(dset, interval) = LCB_DEFAULT_DURABILITY_INTERVAL; } /* list of observe commands to schedule */ if (dset->nentries == 1) { dset->entries = &dset->single.ent; dset->valid_entries = &dset->single.entp; } else { dset->ht = lcb_hashtable_nc_new(dset->nentries); dset->entries = calloc(dset->nentries, sizeof(*dset->entries)); dset->valid_entries = malloc(dset->nentries * sizeof(*dset->valid_entries)); if (dset->entries == NULL || dset->valid_entries == NULL) { lcb_durability_dset_destroy(dset); return LCB_CLIENT_ENOMEM; } } /* set up the observe commands */ for (ii = 0; ii < dset->nentries; ii++) { lcb_durability_entry_t *ent = dset->entries + ii; ent_init(cmds[ii], ent); ent->parent = dset; if (dset->nentries > 1) { int mt = genhash_update(dset->ht, REQFLD(ent, key), REQFLD(ent, nkey), ent, 0); if (mt != NEW) { lcb_durability_dset_destroy(dset); return LCB_DUPLICATE_COMMANDS; } } } /** * Increase the refcount by one. This will be decremented * when the remaining_total count hits 0 */ dset_ref(dset); hashset_add(instance->durability_polls, dset); timer_schedule(dset, 0, STATE_OBSPOLL); return lcb_synchandler_return(instance, LCB_SUCCESS); }
HistoryItems *get_prioritized_history() { using_history(); char *historyFile = get_history_file_name(); if(read_history(historyFile)!=0) { fprintf(stderr, "\nUnable to read history file from '%s'!\n",historyFile); exit(EXIT_FAILURE); } HISTORY_STATE *historyState=history_get_history_state(); if(historyState->length > 0) { HashSet rankmap; hashset_init(&rankmap); HashSet blacklist; int i; hashset_init(&blacklist); for(i=0; i<4; i++) { hashset_add(&blacklist, commandBlacklist[i]); } RadixSorter rs; radixsort_init(&rs, 100000); RankedHistoryItem *r; RadixItem *radixItem; HIST_ENTRY **historyList=history_list(); char **rawHistory=malloc(sizeof(char*) * historyState->length); int rawOffset=historyState->length-1; char *line; for(i=0; i<historyState->length; i++, rawOffset--) { line=historyList[i]->line; rawHistory[rawOffset]=line; if(hashset_contains(&blacklist, line)) { continue; } if((r=hashset_get(&rankmap, line))==NULL) { r=malloc(sizeof(RankedHistoryItem)); r->rank=HISTORY_RANKING_FUNCTION(0, i, strlen(line)); r->item=historyList[i]->line; hashset_put(&rankmap, line, r); radixItem=malloc(sizeof(RadixItem)); radixItem->key=r->rank; radixItem->data=r; radixItem->next=NULL; radixsort_add(&rs, radixItem); } else { radixItem=radix_cut(&rs, r->rank, r); assert(radixItem); if(radixItem) { r->rank=HISTORY_RANKING_FUNCTION(r->rank, i, strlen(line)); radixItem->key=r->rank; radixsort_add(&rs, radixItem); } } } DEBUG_RADIXSORT(); RadixItem **prioritizedRadix=radixsort_dump(&rs); prioritizedHistory=malloc(sizeof(HistoryItems)); prioritizedHistory->count=rs.size; prioritizedHistory->items=malloc(rs.size * sizeof(char*)); prioritizedHistory->raw=rawHistory; for(i=0; i<rs.size; i++) { if(prioritizedRadix[i]->data) { prioritizedHistory->items[i]=((RankedHistoryItem *)(prioritizedRadix[i]->data))->item; } free(prioritizedRadix[i]->data); free(prioritizedRadix[i]); } radixsort_destroy(&rs); return prioritizedHistory; } else { return NULL; } }
double genHOMFitness(char* srcDir,char*target,char*makeDir,Config *user_config,char*original_source,MResult *mResult,HOMutant *hom){ char **args_combineFOM = malloc(sizeof(char*)*(hom->FOMutants_count+4)); args_combineFOM[0]="bash"; args_combineFOM[1]="combineFOM.sh"; args_combineFOM[2]=original_source; args_combineFOM[hom->FOMutants_count+2]=NULL; //Merge all the FOM source files to generate the HOM int i; for (i=0;i<hom->FOMutants_count;i++){ args_combineFOM[i+3]=hom->FOMutants[i].mutant_source_file; } startprogram(args_combineFOM,NULL,0); free(args_combineFOM); char hom_dir[strlen(srcDir)+strlen("hom_dir.log")+2]; sprintf(hom_dir,"%s/%s", srcDir, "hom_dir.log"); char hom_dir_loc[strlen(srcDir)+20]; char hom_file_name[strlen(srcDir)+20]; FILE* hom_dir_file =fopen(hom_dir,"r"); if(hom_dir_file==NULL){ return -1; } fscanf (hom_dir_file, "%s %s",hom_file_name , hom_dir_loc); fclose(hom_dir_file); copy_file(hom_dir_loc, target); //Evaluate mutant //Run make on the mutated project in order to build it printf("--> Evaluating HOM: %s\n",hom_file_name); //Open log file for recording mutation results mutation_results = fopen(mutation_results_path,"a+"); fprintf(mutation_results, "\n**** Mutant: %s ****\n",hom_file_name); fflush(mutation_results); fclose(mutation_results); mResult->homResult->total_mutants++; //Get mutants killed by tests before new evaluation int prev_killed_by_tests=get_non_trivial_FOM_stats()[0]; if(runMake(makeDir,hom_file_name,user_config->makeTestTarget)==2){ mResult->homResult->mutant_kill_count++; } //Get mutants killed by tests after evaluation int *stats = get_non_trivial_FOM_stats(); if(stats[0]-prev_killed_by_tests==1){ mResult->homResult->mutant_kill_count++; } hom->fragility=((double)stats[1]/(double)stats[2]); //Generate the fragility for all the set of FOMs that makeup this HOM hashset_t test_killed_set = hashset_create(); if (test_killed_set == NULL) { fprintf(stderr, "failed to create hashset instance\n"); abort(); } int mut,c; for(mut=0;mut<hom->FOMutants_count;mut++){ Mutant mutant = hom->FOMutants[mut]; for(c=0;c<mutant.killed_by_tests_count;c++){ hashset_add(test_killed_set, &mutant.killed_by_tests[c]); } } hom->fitness=hom->fragility/(((double)hashset_num_items(test_killed_set)/(double)stats[2])); hashset_destroy(test_killed_set); return hom->fitness; }
static void test_rehashing_items_placed_beyond_nitems(void) { hashset_t set = hashset_create(); assert(hashset_add(set, (void *)20644128) == 1); assert(hashset_add(set, (void *)21747760) == 1); assert(hashset_add(set, (void *)17204864) == 1); assert(hashset_add(set, (void *)22937440) == 1); assert(hashset_add(set, (void *)14734272) == 1); assert(hashset_add(set, (void *)13948320) == 1); assert(hashset_add(set, (void *)18116496) == 1); assert(hashset_add(set, (void *)18229952) == 1); assert(hashset_add(set, (void *)20390128) == 1); assert(hashset_add(set, (void *)23523264) == 1); assert(hashset_add(set, (void *)22866784) == 1); assert(hashset_add(set, (void *)17501248) == 1); assert(hashset_add(set, (void *)17168832) == 1); assert(hashset_add(set, (void *)13389824) == 1); assert(hashset_add(set, (void *)15795136) == 1); assert(hashset_add(set, (void *)15154464) == 1); assert(hashset_add(set, (void *)22507840) == 1); assert(hashset_add(set, (void *)22977920) == 1); assert(hashset_add(set, (void *)20527584) == 1); assert(hashset_add(set, (void *)21557872) == 1); assert(hashset_add(set, (void *)23089952) == 1); assert(hashset_add(set, (void *)21606240) == 1); assert(hashset_add(set, (void *)25168704) == 1); assert(hashset_add(set, (void *)25198096) == 1); assert(hashset_add(set, (void *)25248000) == 1); assert(hashset_add(set, (void *)25260976) == 1); assert(hashset_add(set, (void *)25905520) == 1); assert(hashset_add(set, (void *)25934608) == 1); assert(hashset_add(set, (void *)26015264) == 1); assert(hashset_add(set, (void *)26044352) == 1); assert(hashset_add(set, (void *)24784800) == 1); assert(hashset_add(set, (void *)24813888) == 1); assert(hashset_add(set, (void *)24663936) == 1); assert(hashset_add(set, (void *)24693536) == 1); assert(hashset_add(set, (void *)24743792) == 1); assert(hashset_add(set, (void *)24756480) == 1); assert(hashset_is_member(set, (void *)20644128) == 1); assert(hashset_is_member(set, (void *)21747760) == 1); assert(hashset_is_member(set, (void *)17204864) == 1); assert(hashset_is_member(set, (void *)22937440) == 1); assert(hashset_is_member(set, (void *)14734272) == 1); assert(hashset_is_member(set, (void *)13948320) == 1); assert(hashset_is_member(set, (void *)18116496) == 1); assert(hashset_is_member(set, (void *)18229952) == 1); assert(hashset_is_member(set, (void *)20390128) == 1); assert(hashset_is_member(set, (void *)23523264) == 1); assert(hashset_is_member(set, (void *)22866784) == 1); assert(hashset_is_member(set, (void *)17501248) == 1); assert(hashset_is_member(set, (void *)17168832) == 1); assert(hashset_is_member(set, (void *)13389824) == 1); assert(hashset_is_member(set, (void *)15795136) == 1); assert(hashset_is_member(set, (void *)15154464) == 1); assert(hashset_is_member(set, (void *)22507840) == 1); assert(hashset_is_member(set, (void *)22977920) == 1); assert(hashset_is_member(set, (void *)20527584) == 1); assert(hashset_is_member(set, (void *)21557872) == 1); assert(hashset_is_member(set, (void *)23089952) == 1); assert(hashset_is_member(set, (void *)21606240) == 1); assert(hashset_is_member(set, (void *)25168704) == 1); assert(hashset_is_member(set, (void *)25198096) == 1); assert(hashset_is_member(set, (void *)25248000) == 1); assert(hashset_is_member(set, (void *)25260976) == 1); assert(hashset_is_member(set, (void *)25905520) == 1); assert(hashset_is_member(set, (void *)25934608) == 1); assert(hashset_is_member(set, (void *)26015264) == 1); assert(hashset_is_member(set, (void *)26044352) == 1); assert(hashset_is_member(set, (void *)24784800) == 1); assert(hashset_is_member(set, (void *)24813888) == 1); assert(hashset_is_member(set, (void *)24663936) == 1); assert(hashset_is_member(set, (void *)24693536) == 1); assert(hashset_is_member(set, (void *)24743792) == 1); assert(hashset_is_member(set, (void *)24756480) == 1); }
int main(int argc, char *argv[]) { hashset_t set = hashset_create(); hashset_add(set,"leer"); curl_global_init(CURL_GLOBAL_ALL); CURL * myHandle = curl_easy_init(); char md5Password [32]; struct string s; struct string g; init_string(&s); init_string(&g); int i; /* char password[BUFSIZ]; char name[BUFSIZ]; printf("Enter Username: \n"); fgets(name, BUFSIZ, stdin); printf("Enter Password: \n"); fgets(password,BUFSIZ,stdin); cleaner(name); cleaner(password); */ //temp char password [] = "569dgBAh#6Kv2^e9z^ALFiOq"; char name [] = "Foxi"; //temp hashPassword(password, md5Password); doLogin(name, md5Password, myHandle); sleep(3); getSecretToken(myHandle,&s); sleep(3); char* tokenarray = (char*) malloc((s.len + 3) * sizeof (char)); strcpy(tokenarray, s.ptr); findSecretToken(tokenarray, s.len); //Hier muss die URL hin auf welche Danke gesagt wird! char danke [] = "http://usenet-4all.info/forum/showthread.php?t=637647"; doTanks(danke,&g, myHandle); char* pidarray = (char*) malloc((g.len + 3) * sizeof (char)); strcpy(pidarray, g.ptr); findPid(pidarray, g.len, set); //Ab hier habe ich alle PIDS! pushthanks(tokenarray,danke,set,myHandle); print_cookies(myHandle); curl_easy_cleanup(myHandle); free(s.ptr); free(tokenarray); free(pidarray); free(g.ptr); return 0; }
int main(int argc, char **argv) { char buf[BUF_SIZE]; HashSet *hashset = hashset_new(&string_hashcode, &string_equals, &string_copy, &string_delete); if(!hashset) { fprintf(stderr, "hashset_new() returned NULL\n"); return 1; } while(1) { printf("> "); fflush(stdout); if(fgets(buf, BUF_SIZE, stdin)==NULL) break; char *curr; char *next = buf; next_word(&curr, &next); if(!*curr) { //Blank line -- do nothing continue; } else if(!strcasecmp(curr, "a")) { next_word(&curr, &next); if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { if(hashset_add(hashset, (void *)curr)) printf("Element added\n"); else printf("Element already exists\n"); hashset_print(hashset, stdout, &string_print); printf("\n"); } } else if(!strcasecmp(curr, "c")) { next_word(&curr, &next); if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { printf(hashset_contains(hashset, (void *)curr) ? "true\n" : "false\n"); } } else if(!strcasecmp(curr, "r")) { next_word(&curr, &next); if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { if(hashset_remove(hashset, (void *)curr)) printf("Element removed\n"); else printf("Element not found\n"); hashset_print(hashset, stdout, &string_print); printf("\n"); } } else if(!strcasecmp(curr, "x")) { next_word(&curr, &next); if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { hashset_delete(hashset); hashset = hashset_new(&string_hashcode, &string_equals, &string_copy, &string_delete); if(!hashset) { fprintf(stderr, "hashset_new() returned NULL\n"); return 1; } hashset_print(hashset, stdout, &string_print); printf("\n"); } } else if(!strcasecmp(curr, "s")) { if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { printf("%d\n", hashset_size(hashset)); } } else if(!strcasecmp(curr, "p")) { if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { hashset_print(hashset, stdout, &string_print); printf("\n"); } } else if (!strcasecmp(curr, "fa")) { next_word(&curr, &next); if (*(skip_ws(next))) { printf("Too many arguments\n"); } else { if (add_file(hashset, curr)) printf("error loading file.\n"); else { hashset_print(hashset, stdout, &string_print); printf("\n"); } } } else if (!strcasecmp(curr, "fr")) { next_word(&curr, &next); if (*(skip_ws(next))) { printf("Too many arguments\n"); } else { if (remove_file(hashset, curr)) printf("error loading file.\n"); else { hashset_print(hashset, stdout, &string_print); printf("\n"); } } } else if(!strcasecmp(curr, "quit")) { if(*(skip_ws(next))) { printf("Too many arguments\n"); } else { break; } } else if(!strcasecmp(curr, "h") || !strcasecmp(curr, "help")) { print_help(); } else { printf("Invalid command\n"); } printf("\n"); } if(ferror(stdin)) perror("fgets() failed"); hashset_delete(hashset); return 0; }