Exemplo n.º 1
0
Arquivo: main.c Projeto: dakov/ifj-13
int main(int argc, char** argv) {
  if (argc != 2) { // ocekavame PRAVE JEDEN argument (+ nazev souboru)
    fprintf(stderr, "Nespravny pocet argumentu testovaciho programu.\n");
    return -1; //!! predelat na spravnou konstantu
  }

  FILE * f = fopen(argv[1], "r");
  if (f == NULL ) {
    fprintf(stderr, "Testovacimu souboru se nepodarilo otevrit soubor s aplikaci.\n");
    return internalError();
  }

  initGarbageCollector();

  //nastav soubor, ze ktereho scanner cte
  setSourceFile(f);

  htable_t* fT;
  tIlist iL;
  listInit(&iL);
  fT = htable_init(HTABLE_SIZE);

  htableStack *sS = gcMalloc(sizeof(htableStack));
  if (sS == NULL) return internalError();
  sS = htable_stack_init();

  htable_t *mainTable ;
  mainTable = htable_init(HTABLE_SIZE);
  htable_stack_push(sS,mainTable);

  int result = parse(fT, &iL,sS);

  if (result != EOK)
    {
      fclose(f);
      freeGarbage();
      return result;
      // jinak probehlo vse v poradku, muzeme provadet kod
    }


  result = (interpret(&iL,fT,sS));

  freeGarbage();
  fclose(f);

  if(result != EOK){
    return result;
    }


  return EOK;
}
Exemplo n.º 2
0
int kmscon_hashtable_new(struct kmscon_hashtable **out,
			 kmscon_hash_cb hash_cb,
			 kmscon_equal_cb equal_cb,
			 kmscon_free_cb free_key,
			 kmscon_free_cb free_value)
{
	struct kmscon_hashtable *tbl;

	if (!out || !hash_cb || !equal_cb)
		return -EINVAL;

	tbl = malloc(sizeof(*tbl));
	if (!tbl)
		return -ENOMEM;
	memset(tbl, 0, sizeof(*tbl));
	tbl->hash_cb = hash_cb;
	tbl->equal_cb = equal_cb;
	tbl->free_key = free_key;
	tbl->free_value = free_value;

	htable_init(&tbl->tbl, rehash, tbl);

	*out = tbl;
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  struct htable ht;
  foobar_t *foo;
  foobar_t *ret;
  
  htable_init(&ht, rehash, NULL);
  foo = malloc(sizeof(foobar_t));
  foo->name = strdup("fumier");
  foo->blah = 123;

  htable_add(&ht, hash_string(foo->name), foo);

  ret = (foobar_t *)htable_get(&ht, hash_string("gugus"), streq, "gugus");
  if (ret) {
    printf("Found\n");
  } else {
    printf("Not found\n");
  }
  
  free(foo->name);
  free(foo);
  
  return 0;
}
Exemplo n.º 4
0
int main() {
	FILE *f = stdin;
	// f = fopen("/home/Ondra/ahoj1.txt", "r"); // smazat
	char string[MAX_LEN];
	int len;

	htable_t* table = htable_init(HTABLE_SIZE);
	htable_listitem *item;

	while ( (len = fgetword(string, MAX_LEN, f)) != 0 ) {
		if((item = htable_lookup(table, string)) == NULL) {
			fprintf(stderr, "Chyba pri alokaci pameti.\n");
			return EXIT_FAILURE;
		}
	}

	// fclose(f);	//smazat

	htable_iterator b = htable_begin(table);
	htable_iterator *bg = &b;
	htable_iterator end = htable_end(table);

	while( !htable_iter_eq(bg, &end) ) {
		if(htable_iter_deref(bg) == NULL)
			break;
		printf("%s\t%d\n", bg->ptr->key, bg->ptr->data);
		bg = htable_iter_next(bg);
	}
	if(end.ptr != NULL)
		printf("%s\t%d\n", end.ptr->key, end.ptr->data);
	// Uklid haldu
	htable_free(table);

	return EXIT_SUCCESS;
}
Exemplo n.º 5
0
void  opt_init(){
	ReferItem r;
	scan_htable=htable_init((char*)&r.next-(char*)&r,4,32); // 32 ¸öcontainer
	max_factor=1.0/G_CAPPING_T; 
	cur_factor=max_factor;
	rewrite_size=0;
	memset(factor_buckets,0,sizeof(factor_buckets));
	printf("max_factor:%f , cur_factor:%f \n",max_factor,cur_factor);
}
Exemplo n.º 6
0
void *sec_mod_client_db_init(sec_mod_st *sec)
{
	struct htable *db = talloc(sec, struct htable);
	if (db == NULL)
		return NULL;

	htable_init(db, rehash, NULL);
	sec->client_db = db;

	return db;
}
Exemplo n.º 7
0
int main(void) {
 char line[MAXLINE];
 node *hashtable;

 hashtable = (node *)malloc(HASHSIZE * sizeof(node));

 htable_init(hashtable);

 while((fgets(line, MAXLINE, stdin)) != NULL)
  htable_insert(hashtable, line);

 htable_display(hashtable);

 return 0;
}
/**
 * Zaciatok programu
 */
int main(void)
{	
	Th_table *htable = htable_init(TABLESIZE);
	if (htable == NULL)
		printError("Nepodarilo sa alokovat pamet pre hash table!", htable);
	
	//alokujem si do ktoreho budem ukladat slova z funkcie fgetword
	char *word = (char *)calloc(WORDLENGTHMAX, sizeof(char));	
	if (word == NULL)
		printError("Nepodarilo sa alokovat pamet pre pole!", htable);
	
	Thtable_listitem *item = NULL;
	
	//nacitanie slov do hash table
	while(fgetword(word, WORDLENGTHMAX, stdin) != 0)
	{
		item = htable_lookup(htable, word);
		if (item == NULL)
		{
			free(word);
			printError("Nepodarilo sa alokovat pamet pre novu polozku!", htable);
		}
		
		//pocita vyskity slova
		item->data++;
	}
	//vypis slovo pocetVyskitov
	/////////////////////////////////////////////
	//nastavim iterator na prvu polozku
	Thtable_iterator iteratorBegin = htable_begin(htable);
	//nastavim iterator na poslednu polozku
	Thtable_iterator iteratorEnd = htable_end(htable);
	//vypis key  data
	while (htable_iter_eq(iteratorBegin, iteratorEnd) == false)
	{
		item = htable_iter_deref(iteratorBegin);
		printf("%s\t%d\n", item->key, item->data);
		iteratorBegin = htable_iter_next(iteratorBegin);
	}
	
	//uvolnit alokovane polia..
	htable_free(htable);
	free(word);
	
	return EXIT_SUCCESS;
}
Exemplo n.º 9
0
faup_snapshot_item_t *faup_snapshot_item_new(char *key)
{
  faup_snapshot_item_t *item;

  item = malloc(sizeof(faup_snapshot_item_t));
  if (!item) {
    fprintf(stderr, "Cannot allocatate a snapshot_item item!\n");
    return NULL;
  }

  item->length = 0;
  item->key = strdup(key);
  htable_init(&item->values, rehash, NULL);
  
  return item;

}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
	/* Initializations */
	output = fopen("trace.out", "w");
	instr_count = 0;
	max_instr_count = 0;
	htable_init(&addresses, addr_hash, NULL);
	PIN_InitSymbols();
	PIN_Init(argc, argv);

	/* Instrumentation */
	RTN_AddInstrumentFunction(Routine, 0);
	INS_AddInstrumentFunction(Instruction, 0);
	PIN_AddFiniFunction(fini, 0);
	PIN_StartProgram();

	return 0;
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
	struct htable ht;
	uint64_t val[NUM_VALS];
	unsigned int i;

	plan_tests((NUM_VALS) * 2);
	for (i = 0; i < NUM_VALS; i++)
		val[i] = i;

	htable_init(&ht, hash, NULL);
	for (i = 0; i < NUM_VALS; i++) {
		ok1(ht.max >= i);
		ok1(ht.max <= i * 2);
		htable_add(&ht, hash(&val[i], NULL), &val[i]);
	}
	htable_clear(&ht);

	return exit_status();
}
Exemplo n.º 12
0
static void tracer_init(pid_t pid) {
  PAGESIZE = sysconf(_SC_PAGESIZE);
  event_t e = wait_event(pid);
  assert(e.signo == SIGSTOP);
  follow_threads(pid);
  create_dump_dir();

  debug_print("%s\n", "Tracer initialized");

  if (firsttouch_active) {
    htable_init(&firsttouch, rehash, NULL);
    stop_all_except(pid);
    tracer_lock_mem(pid);
    debug_print("%s\n", "******* TRACER_FIRSTTOUCH");
    tracer_state = TRACER_FIRSTTOUCH;
  } else {
    debug_print("%s\n", "******* TRACER_UNLOCKED");
    tracer_state = TRACER_UNLOCKED;
  }

  continue_all();
}
Exemplo n.º 13
0
htable* htable_new(size_t estimated_size) { // {{{
	return htable_init(calloc(1, sizeof(htable)), estimated_size);
} // }}}
Exemplo n.º 14
0
static void plain_group_list(void *pool, void *additional, char ***groupname, unsigned *groupname_size)
{
    FILE *fp;
    char line[512];
    ssize_t ll;
    char *p, *sp;
    unsigned i;
    size_t hval;
    struct htable_iter iter;
    char *tgroup[MAX_GROUPS];
    unsigned tgroup_size;
    struct htable hash;
    struct plain_cfg_st *config = additional;

    htable_init(&hash, rehash, NULL);

    pool = talloc_init("plain");
    fp = fopen(config->passwd, "r");
    if (fp == NULL) {
        syslog(LOG_AUTH,
               "error in plain authentication; cannot open: %s",
               (char*)config->passwd);
        return;
    }

    line[sizeof(line)-1] = 0;
    while ((p=fgets(line, sizeof(line)-1, fp)) != NULL) {
        ll = strlen(p);

        if (ll <= 4)
            continue;

        if (line[ll - 1] == '\n') {
            ll--;
            line[ll] = 0;
        }
        if (line[ll - 1] == '\r') {
            ll--;
            line[ll] = 0;
        }

#ifdef HAVE_STRSEP
        sp = line;
        p = strsep(&sp, ":");

        if (p != NULL) {
            p = strsep(&sp, ":");
#else
        p = strtok_r(line, ":", &sp);

        if (p != NULL) {
            p = strtok_r(NULL, ":", &sp);
#endif
            if (p != NULL) {
                break_group_list(pool, p, tgroup, &tgroup_size);

                for (i=0; i<tgroup_size; i++) {
                    hval = rehash(tgroup[i], NULL);

                    if (htable_get(&hash, hval, str_cmp, tgroup[i]) == NULL) {
                        if (strlen(tgroup[i]) > 1)
                            htable_add(&hash, hval, tgroup[i]);
                    }
                }
            }
        }
    }

    *groupname_size = 0;
    *groupname = talloc_size(pool, sizeof(char*)*MAX_GROUPS);
    if (*groupname == NULL) {
        goto exit;
    }

    p = htable_first(&hash, &iter);
    while (p != NULL && (*groupname_size) < MAX_GROUPS) {
        (*groupname)[(*groupname_size)] = talloc_strdup(*groupname, p);
        p = htable_next(&hash, &iter);
        (*groupname_size)++;
    }

    /* always succeed */
exit:
    htable_clear(&hash);
    safe_memset(line, 0, sizeof(line));
    fclose(fp);
    return;
}

const struct auth_mod_st plain_auth_funcs = {
    .type = AUTH_TYPE_PLAIN | AUTH_TYPE_USERNAME_PASS,
    .allows_retries = 1,
    .global_init = plain_global_init,
    .auth_init = plain_auth_init,
    .auth_deinit = plain_auth_deinit,
    .auth_msg = plain_auth_msg,
    .auth_pass = plain_auth_pass,
    .auth_user = plain_auth_user,
    .auth_group = plain_auth_group,
    .group_list = plain_group_list
};
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
	unsigned int i;
	uintptr_t perfect_bit;
	struct htable ht;
	uint64_t val[NUM_VALS];
	uint64_t dne;
	void *p;
	struct htable_iter iter;

	plan_tests(29);
	for (i = 0; i < NUM_VALS; i++)
		val[i] = i;
	dne = i;

	htable_init(&ht, hash, NULL);
	ok1(ht.max == 0);
	ok1(ht.bits == 0);

	/* We cannot find an entry which doesn't exist. */
	ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));

	/* This should increase it once. */
	add_vals(&ht, val, 0, 1);
	ok1(ht.bits == 1);
	ok1(ht.max == 1);
	ok1(ht.common_mask == -1);

	/* Mask should be set. */
	ok1(check_mask(&ht, val, 1));

	/* This should increase it again. */
	add_vals(&ht, val, 1, 1);
	ok1(ht.bits == 2);
	ok1(ht.max == 3);

	/* Mask should be set. */
	ok1(ht.common_mask != 0);
	ok1(ht.common_mask != -1);
	ok1(check_mask(&ht, val, 2));

	/* Now do the rest. */
	add_vals(&ht, val, 2, NUM_VALS - 2);

	/* Find all. */
	find_vals(&ht, val, NUM_VALS);
	ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));

	/* Walk once, should get them all. */
	i = 0;
	for (p = htable_first(&ht,&iter); p; p = htable_next(&ht, &iter))
		i++;
	ok1(i == NUM_VALS);

	/* Delete all. */
	del_vals(&ht, val, NUM_VALS);
	ok1(!htable_get(&ht, hash(&val[0], NULL), objcmp, &val[0]));

	/* Worst case, a "pointer" which doesn't have any matching bits. */
	htable_add(&ht, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]);
	htable_add(&ht, hash(&val[NUM_VALS-1], NULL), &val[NUM_VALS-1]);
	ok1(ht.common_mask == 0);
	ok1(ht.common_bits == 0);
	/* Get rid of bogus pointer before we trip over it! */
	htable_del(&ht, 0, (void *)~(uintptr_t)&val[NUM_VALS-1]);

	/* Add the rest. */
	add_vals(&ht, val, 0, NUM_VALS-1);

	/* Check we can find them all. */
	find_vals(&ht, val, NUM_VALS);
	ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne));

	/* Corner cases: wipe out the perfect bit using bogus pointer. */
	htable_clear(&ht);
	htable_add(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1]));
	ok1(ht.perfect_bit);
	perfect_bit = ht.perfect_bit;
	htable_add(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1]
				   | perfect_bit));
	ok1(ht.perfect_bit == 0);
	htable_del(&ht, 0, (void *)((uintptr_t)&val[NUM_VALS-1] | perfect_bit));

	/* Enlarging should restore it... */
	add_vals(&ht, val, 0, NUM_VALS-1);

	ok1(ht.perfect_bit != 0);
	htable_clear(&ht);

	return exit_status();
}
Exemplo n.º 16
0
int main(int argc, char **argv)
{
    const char *dictfilename = "diceware.txt";
    const char *randomdevice = NULL;

    int words = 6;
    int i = 0;
    struct htable dict;
    struct randgen *randgen = NULL;
    int rc = 0;

    memset(&dict, 0, sizeof(dict));

    for (i = 1; i < argc; ++i)
    {
        if (!strcmp(argv[i], "-d") && i+1 < argc)
        {
            dictfilename = argv[++i];
        }
        else if (!strcmp(argv[i], "-n") && i+1 < argc)
        {
            words = atoi(argv[++i]);
        }
#ifndef _WIN32
        else if (!strcmp(argv[i], "-r") && i+1 < argc)
        {
            randomdevice = argv[++i];
        }
#endif
        else if (!strcmp(argv[i], "-h"))
        {
            usage(argv[0]);
        }
        else
        {
            usage(argv[0]);
        }
    }

    if ((randgen = randgen_open(randomdevice)) == NULL)
        goto error;

    htable_init(&dict, 11000);

    if (load_dictionary(dictfilename, &dict) == -1)
        goto error;

    for (i = 0; i < words; ++i)
    {
        char *word = get_random_word(randgen, &dict);
        if (!word)
        {
            goto error;
        }
        printf("%s%s", i ? " " : "", word);
    }

    printf("\n");

    goto finally;

error:

    rc = 1;

finally:

    randgen_close(randgen);

    htable_deinit(&dict);

    return rc;
}
Exemplo n.º 17
0
void ip_lease_init(struct ip_lease_db_st* db)
{
	htable_init(&db->ht, rehash, NULL);
}
Exemplo n.º 18
0
Arquivo: php_set.c Projeto: Driky/ds
Set *set_init()
{
    return set_init_ex(htable_init());
}
Exemplo n.º 19
0
int ipm_init(int flags)
{
    int i, state, rv;
    double t_init;
    char cmdline[MAXSIZE_CMDLINE];
    char realpath[MAXSIZE_CMDLINE];
    char *target;

    state=ipm_state;
    ipm_state=STATE_IN_INIT;

    /* check if IPM_TARGET is set and if it is,
       only monitor matching processes */
    target=getenv("IPM_TARGET");
    ipm_get_exec_cmdline(cmdline,realpath);

    /* IPM_TARGET specifies string that has to appear in cmdline */
    if( target && target[0]!='!' && !strstr(cmdline,target) ) {
        ipm_state=STATE_NOTACTIVE;
        return IPM_OK;
    }

    /* IPM_TARGET specifies string that must not appear in cmdline */
    if( target && target[0]=='!' && strstr(cmdline,target) ) {
        ipm_state=STATE_NOTACTIVE;
        return IPM_OK;
    }

    ipm_time_init(flags);

    rstack_init(flags);

    t_init = ipm_wtime();
    taskdata_init(&task);
    htable_init(ipm_htable);

    /* need to get env variables before modules init */
    ipm_get_env();

    /* init local data structures */
    for( i=0; i<MAXNUM_MODULES; i++ ) {
        ipm_module_init( &(modules[i]) );
    }

    /* --- initialize modules --- */

#ifdef HAVE_MPI
    modules[IPM_MODULE_MPI].init=mod_mpi_init;
#endif

#ifdef HAVE_POSIXIO
    modules[IPM_MODULE_POSIXIO].init=mod_posixio_init;
#endif

#ifdef HAVE_MPIIO
    modules[IPM_MODULE_MPIIO].init=mod_mpiio_init;
#endif

#ifdef HAVE_CALLPATH
    modules[IPM_MODULE_CALLPATH].init=mod_callpath_init;
#endif

#ifdef HAVE_KEYHIST
    modules[IPM_MODULE_KEYHIST].init=mod_keyhist_init;
#endif

#ifdef HAVE_PAPI
    modules[IPM_MODULE_PAPI].init=mod_papi_init;
#endif

#ifdef HAVE_SELFMONITOR
    modules[IPM_MODULE_SELFMONITOR].init=mod_selfmonitor_init;
#endif

#ifdef HAVE_PROCCTRL
    modules[IPM_MODULE_PROCCTRL].init=mod_procctrl_init;
#endif

#ifdef HAVE_CLUSTERING
    modules[IPM_MODULE_CLUSTERING].init=mod_clustering_init;
#endif

#ifdef HAVE_OMPTRACEPOINTS
    modules[IPM_MODULE_OMPTRACEPOINTS].init=mod_omptracepoints_init;
#endif

#ifdef HAVE_CUDA
    modules[IPM_MODULE_CUDA].init=mod_cuda_init;
#endif

#ifdef HAVE_CUFFT
    modules[IPM_MODULE_CUFFT].init=mod_cufft_init;
#endif

#ifdef HAVE_CUBLAS
    modules[IPM_MODULE_CUBLAS].init=mod_cublas_init;
#endif


    /* TODO: handle errors in module initialization, set
       ipm_state to STATE_ERROR */

    for( i=0; i<MAXNUM_MODULES; i++ ) {
        if( modules[i].init ) { /* call init function if it is set */
            rv=modules[i].init(&(modules[i]), flags);
            if(rv!=IPM_OK) {
                IPMERR("Error initializing module %d (%s), error %d\n",
                       i, modules[i].name?modules[i].name:"", rv);
            }

#ifdef HAVE_MPI
            if( i==IPM_MODULE_POSIXIO )
                modules[i].state=STATE_NOTACTIVE;
#endif
        }
    }

    /* --- done initializing modules --- */


#ifdef DELAYED_MPI_FINALIZE
    rv = atexit(ipm_atexit_handler);
    if(!rv) {
        task.flags|=FLAG_USING_ATEXIT;
    } else {
        IPMERR("Error installing atexit() handler\n");
        task.flags&=~FLAG_USING_ATEXIT;
    }
#endif

    signal(SIGXCPU, ipm_sig_handler);
    signal(SIGTERM, ipm_sig_handler);
    signal(SIGABRT, ipm_sig_handler);

#ifdef HAVE_SELFMONITOR
    ipm_selfmon.t_init = ipm_wtime()-t_init;
#endif

    /* this should be close to user code */
    ipm_region(1, "ipm_main");
    ipm_region_begin(&ipm_app);

    ipm_state=STATE_ACTIVE;
    return IPM_OK;
}
Exemplo n.º 20
0
Arquivo: php_set.c Projeto: Driky/ds
zend_object *set_create_object(zend_class_entry *ce)
{
    return set_create_object_ex(htable_init());
}
Exemplo n.º 21
0
void  capping_init(){
	
	CapItem r;
	cap_htable=htable_init((char*)&r.next-(char*)&r,4,32); // 32 ¸öcontainer

}