コード例 #1
0
ファイル: numerical.c プロジェクト: flijten/saffire
/**
 * Initializes numerical methods and properties
 */
void object_numerical_init(void) {
    Object_Numerical_struct.methods = ht_create();
    object_add_internal_method(&Object_Numerical_struct, "ctor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_ctor);
    object_add_internal_method(&Object_Numerical_struct, "dtor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_dtor);

    object_add_internal_method(&Object_Numerical_struct, "boolean", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_conv_boolean);
    object_add_internal_method(&Object_Numerical_struct, "null", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_conv_null);
    object_add_internal_method(&Object_Numerical_struct, "numerical", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_conv_numerical);
    object_add_internal_method(&Object_Numerical_struct, "string", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_conv_string);

    object_add_internal_method(&Object_Numerical_struct, "neg", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_neg);
    object_add_internal_method(&Object_Numerical_struct, "abs", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_abs);
    object_add_internal_method(&Object_Numerical_struct, "print", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_numerical_method_print);

    Object_Numerical_struct.properties = ht_create();


    // Create a numerical cache
    int value = NUMERICAL_CACHED_MIN;
    for (int i=0; i!=NUMERICAL_CACHED_CNT; i++, value++) {
        numerical_cache[i] = smm_malloc(sizeof(t_numerical_object));
        memcpy(numerical_cache[i], Object_Numerical, sizeof(t_numerical_object));
        numerical_cache[i]->value = value;

        numerical_cache[i]->flags |= OBJECT_FLAG_IMMUTABLE | OBJECT_FLAG_STATIC;

        // These are instances
        numerical_cache[i]->flags &= ~OBJECT_TYPE_MASK;
        numerical_cache[i]->flags |= OBJECT_TYPE_INSTANCE;
    }
}
コード例 #2
0
void test_ht_free(void **state)
{
    Hashtable *ht;
    int i;

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);

    for (i=0; i<LIMIT; i++)
    {
        uint16_t *data;
        uint16_t *key;

        data = malloc(sizeof(uint16_t));
        *data = i;
        key = malloc(sizeof(uint16_t));
        *key = i;
        ht_insert(ht, key, data);
    }
    ht_free(ht);

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);

    ht_free(ht);
}
コード例 #3
0
int sba_jfs_init(void)
{
	sba_debug(1, "Initializing the jfs data structures\n");
	ht_create(&h_sba_jfs_journal, "jfs_journal");
	ht_create(&h_jfs_journaled_blocks, "jfs_journal");

	return 1;
}
コード例 #4
0
ファイル: null.c プロジェクト: AlexanderC/saffire
/**
 * Initializes string methods and properties, these are used
 */
void object_null_init(void) {
    Object_Null_struct.methods = ht_create();

    object_add_internal_method(&Object_Null_struct, "boolean", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_null_method_conv_boolean);
    object_add_internal_method(&Object_Null_struct, "null", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_null_method_conv_null);
    object_add_internal_method(&Object_Null_struct, "numerical", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_null_method_conv_numerical);
    object_add_internal_method(&Object_Null_struct, "string", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_null_method_conv_string);

    Object_Null_struct.properties = ht_create();
}
コード例 #5
0
ファイル: logread.c プロジェクト: KevinCooper/buildit
int main(int argc, char * argv[]) {
	peopleHead = NULL;
	allMahHashes_employees = ht_create(65536);
	allMahHashes_guests = ht_create(65536);
	int32_t fileSize = 0;
	FILE* file = NULL;
	size_t bytes = 0;
	ssize_t read = 0;
	char * line = NULL;
	char interString[MAX * 4];

	//get Logreader arguements
	logread_args args = opt_parser(argc, argv, 1);
	//Verify integrity and hopefully the syntax should be right

	fileSize = fsize(args.logName);
	if (fileSize > 15) {
		unsigned int salt[] = { 12345, 54321 };
		FILE * encrypted_file = fopen(args.logName, "r");
		FILE * decrypted = fopen("tempblahman", "w+");
		do_crypt(encrypted_file, decrypted, DECRYPT, args.token,
				strlen(args.token), (unsigned char *) salt);
		rename("tempblahman", args.logName);
	} else {
		invalid();
	}

	file = fopen(args.logName, "r");
	//Line by line apply the options
	while ((read = getline(&line, &bytes, file)) != -1 && fileSize > 10) {

		int len = strlen(line);
		fileSize = fileSize - len;
		// RERUN COMMANDS CAUZE LOGIC!
		sprintf(interString, "./logappend %s", line);
		int tempc;
		char ** tempv = argv_split(interString, &tempc);
		logappend_args temp = opt_parser_log(tempc, tempv);
		buildDataStructs(&temp);
		bzero(interString, MAX * 4);
		argv_free(tempv);
		// FINISH LOGICZ
	}
	doBadThings(&args);

	unsigned int salt[] = { 12345, 54321 };
	FILE * decrypted_file = fopen(args.logName, "r");
	FILE * encrypted = fopen("tempblahman", "w+");
	do_crypt(decrypted_file, encrypted, ENCRYPT, args.token, strlen(args.token),
			(unsigned char *) salt);
	rename("tempblahman", args.logName);

	return 0;
}
コード例 #6
0
ファイル: code.c プロジェクト: AlexanderC/saffire
/**
 * Initializes methods and properties, these are used
 */
void object_code_init(void) {
    Object_Code_struct.methods = ht_create();
    object_add_internal_method(&Object_Code_struct, "ctor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_code_method_ctor);
    object_add_internal_method(&Object_Code_struct, "dtor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_code_method_dtor);

    object_add_internal_method(&Object_Code_struct, "boolean", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_code_method_conv_boolean);
    object_add_internal_method(&Object_Code_struct, "null", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_code_method_conv_null);

    object_add_internal_method(&Object_Code_struct, "call", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_code_method_call);
    object_add_internal_method(&Object_Code_struct, "internal?", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_code_method_internal);

    Object_Code_struct.properties = ht_create();
}
コード例 #7
0
void test_ht_create(void **state)
{
    Hashtable *ht;

    expect_assert_failure(ht_create(-1, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free));

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);
    ht_free(ht);
}
コード例 #8
0
ファイル: 1-24.c プロジェクト: ddsnowboard/JavaProjects
int checkSegment(FILE *f, char ending)
{
    struct ht_Table *status = ht_create(NUMBER_OF_SYMBOLS);
    struct ht_Table *opposites = ht_create(NUMBER_OF_OPPOSITES);
    initializeStatus(status);
    initializeOpposites(opposites);
    char CLOSERS[] = {')', '>', ']', '}'};
    char OPENERS[] = {'(', '<', '[', '{'};
    const int LISTS_LENGTH = 4;
    char last = 'a';
    char curr;
    while((curr = fgetc(f)) != EOF)
    {
        printf("%c", curr);
        if(curr == '#')
            skipLineComment(f);
        else if(curr == '*' && last == '/')
            skipBlockComment(f);
        else if(curr == '/' && last == '/')
            skipLineComment(f);
        else if(curr == '\'' || curr == '"')
        {
            if(skipString(f, curr) != 0)
                return 1;
        }
        else if(search(OPENERS, LISTS_LENGTH, curr) != -1)
        {
            (*ht_get(status, curr))++;
        }
        // Struct pointer references screw up the normal algorithm. Don't tell Tim Peters or Linus Torvalds
        else if(curr == '>' && last == '-')
        {}
        else if(search(CLOSERS, LISTS_LENGTH, curr) != -1)
        {
            char correspondingOpener = (char) (*ht_get(opposites, curr));
            int *num = ht_get(status, correspondingOpener);
            if(*num == 0)
            {
                printf("There is an unmatched %c!\n", curr);
                return 1;
            }
            else
            {
                (*num)--;
            }
        }
        last = curr;
    }
    return 0;
}
コード例 #9
0
ファイル: io.c プロジェクト: flijten/saffire
static void _init(void) {
    io_struct.methods = ht_create();
    object_add_internal_method(&io_struct, "printf", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, io_print);
    object_add_internal_method(&io_struct, "print", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, io_print);
    object_add_internal_method(&io_struct, "printf", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, io_printf);
    object_add_internal_method(&io_struct, "sprintf", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, io_sprintf);
    io_struct.properties = ht_create();

    console_struct.methods = ht_create();
    object_add_internal_method(&console_struct, "print", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, console_print);
    object_add_internal_method(&console_struct, "printf", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, console_printf);
    object_add_internal_method(&console_struct, "sprintf", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, console_sprintf);
    console_struct.properties = ht_create();
}
コード例 #10
0
ファイル: hash.c プロジェクト: AlexanderC/saffire
/**
 * Initializes hash methods and properties, these are used
 */
void object_hash_init(void) {
    Object_Hash_struct.methods = ht_create();
    object_add_internal_method(&Object_Hash_struct, "ctor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_ctor);
    object_add_internal_method(&Object_Hash_struct, "dtor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_dtor);

    object_add_internal_method(&Object_Hash_struct, "boolean", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_conv_boolean);
    object_add_internal_method(&Object_Hash_struct, "null", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_conv_null);
    object_add_internal_method(&Object_Hash_struct, "numerical", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_conv_numerical);
    object_add_internal_method(&Object_Hash_struct, "string", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_conv_string);

    object_add_internal_method(&Object_Hash_struct, "length", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_hash_method_length);

    Object_Hash_struct.properties = ht_create();
}
コード例 #11
0
ファイル: regex.c プロジェクト: flijten/saffire
/**
 * Initializes regex methods and properties, these are used
 */
void object_regex_init(void) {
    Object_Regex_struct.methods = ht_create();
    object_add_internal_method(&Object_Regex_struct, "ctor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_ctor);
    object_add_internal_method(&Object_Regex_struct, "dtor", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_dtor);

    object_add_internal_method(&Object_Regex_struct, "boolean", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_conv_boolean);
    object_add_internal_method(&Object_Regex_struct, "null", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_conv_null);
    object_add_internal_method(&Object_Regex_struct, "numerical", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_conv_numerical);
    object_add_internal_method(&Object_Regex_struct, "string", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_conv_string);

    object_add_internal_method(&Object_Regex_struct, "match", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_match);
    object_add_internal_method(&Object_Regex_struct, "regex", METHOD_FLAG_STATIC, METHOD_VISIBILITY_PUBLIC, object_regex_method_regex);

    Object_Regex_struct.properties = ht_create();
}
コード例 #12
0
void pre_populate_symboltable(){
	symboltable = ht_create( 10000 );
	ht_set( symboltable, "short", "0");
	ht_set( symboltable, "sizeofint", "0");
	ht_set( symboltable, "float", "0");
	ht_set( symboltable, "double", "0");
	ht_set( symboltable, "bool", "0");
	ht_set( symboltable, "char", "0");
	ht_set( symboltable, "signed", "0");
	ht_set( symboltable, "unsigned", "0");
	ht_set( symboltable, "for", "0");
	ht_set( symboltable, "while", "0");
	ht_set( symboltable, "do", "0");
	ht_set( symboltable, "return", "0");
	ht_set( symboltable, "structconst", "0");
	ht_set( symboltable, "void", "0");
	ht_set( symboltable, "switch", "0");
	ht_set( symboltable, "break", "0");
	ht_set( symboltable, "case", "0");
	ht_set( symboltable, "continue", "0");
	ht_set( symboltable, "goto", "0");
	ht_set( symboltable, "long", "0");
	ht_set( symboltable, "static", "0");
	ht_set( symboltable, "union", "0");
	ht_set( symboltable, "default", "0");
}
コード例 #13
0
/** \brief    Construct the BDD that represent all hitting sets from a ZDD.
 *  \param    f     ZDD
 *  \return   The contructed BDD
 *  \see      hit_z2b_rec
 */
bddp hit_z2b(zddp f)
{
  my_hash *h = ht_create(0);
  ENSURE_TRUE_MSG(h != NULL, "hash table creation failed");

#ifdef SIZE_LOG
  char str[BUFSIZ];
  snprintf(str, BUFSIZ, "%s-hit.log", g_basename);
  sizelog = fopen(str, "w");
  ENSURE_TRUE_MSG(sizelog != NULL, "file open failed");
  maxsize = 0;
#endif /*SIZE_LOG*/

  assert(recdepth == 0);
  bddp r = hit_z2b_rec(f, h);
  ENSURE_TRUE(r != BDD_NULL);
  assert(recdepth == 0);

#ifdef SIZE_LOG
  fclose(sizelog);
  printf("max|bdd|\t%ju\n", maxsize);
#endif /*SIZE_LOG*/

  ht_destroy(h); 
  return r;
}
コード例 #14
0
void test_ht_search(void **state)
{
    Hashtable *ht;
    int i;

    ht = ht_create(0, uint16_hash,
            uint16_compare, uint16_copy, uint16_free,
            uint16_compare, uint16_copy, uint16_free);

    for (i=0; i<LIMIT; i++)
    {
        uint16_t *key;
        uint16_t *data;

        data = malloc(sizeof(uint16_t));
        *data = i;
        key = malloc(sizeof(uint16_t));
        *key = i;
        ht_insert(ht, key, data);
    }

    for (i=0; i<LIMIT; i++)
    {
        uint16_t *data;

        data = ht_search(ht, &i);
        assert_true(data != NULL);
        assert_int_equal(*data, i);
    }
    i = LIMIT + 1;
    assert_true(ht_search(ht, &i) == NULL);

    ht_free(ht);
}
コード例 #15
0
ファイル: knucleotide-7.c プロジェクト: philix/c_bench
void
print_freqs(struct print_freqs_param *param) {
    char *start = param->start;
    int length = param->length;
    int frame = param->frame;
    char *output = param->output;
    int output_size = param->output_size;

    struct ht_ht *ht = ht_create(32);
    char buffer[frame + 1];
    int output_pos = 0;

    generate_seqences(start, length, frame, ht);
    
    struct ht_node *counts = ht_values_as_vector(ht);
    int size = ht->items;

    qsort(counts, size, sizeof(struct ht_node), &key_count_cmp);

    int total_count = 0;
    for (int i = 0; i < size; i++) {
        total_count += counts[i].val;
    }

    for (int i = 0; i < size; i++) {
        unpack_key(counts[i].key, frame, buffer);
        output_pos += snprintf(output + output_pos, output_size - output_pos,
                "%s %.3f\n", buffer, counts[i].val*100.0f/total_count);
    }

    free(counts);
    ht_destroy(ht);
}
コード例 #16
0
ファイル: zipfile.c プロジェクト: laochailan/taisei
static void vfs_zipfile_init_pathmap(VFSNode *node) {
	VFSZipFileData *zdata = node->data1;
	VFSZipFileTLS *tls = vfs_zipfile_get_tls(node, true);
	zip_int64_t num = zip_get_num_entries(tls->zip, 0);

	ht_create(&zdata->pathmap);

	for(zip_int64_t i = 0; i < num; ++i) {
		const char *original = zip_get_name(tls->zip, i, 0);
		char normalized[strlen(original) + 1];

		vfs_path_normalize(original, normalized);

		if(*normalized) {
			char *c = strchr(normalized, 0) - 1;
			if(*c == '/') {
				*c = 0;
			}
		}

		if(strcmp(original, normalized)) {
			ht_set(&zdata->pathmap, normalized, i);
		}
	}
}
コード例 #17
0
int test_add_to_same_key(){
  hashtable_t *ht = ht_create( 65536, free_jambo );

  ht_set( ht, "key1", "blorg" );

  ht_set( ht, "key1", "bloff" );
  ht_set( ht, "key1", "gladd" );
  ht_set( ht, "key1", "grutt" );
  ht_set( ht, "key1", "twerky" );
  ht_set( ht, "key1", "lennart" );
  ht_set( ht, "key2", "sverker" );
  ht_set( ht, "key3", "Rogge" );
  ht_set( ht, "key4", "Swutt" );


  check( strcmp( ht_get(ht, "key1"), "lennart") == 0 );
  check( strcmp( ht_get(ht, "key2"), "sverker") == 0);
  check( strcmp( ht_get(ht, "key3"), "Rogge") == 0);
  check( strcmp( ht_get(ht, "key4"), "Swutt") == 0);

  check(ht_size(ht) == 4);

  ht_destroy(ht);

  return 0;
}
コード例 #18
0
int test_perfomance(){
  hashtable_t *ht = ht_create( 65536, destroy_gv_t );

  char key[10];
  char s1[10];
  char s2[10];

  for(int i=0;i < 50000; i++){

    sprintf(key,"key-%d", i);
    sprintf(s1,"s1-%d", i);
    sprintf(s2,"s2-%d", i);

    ht_set( ht, key, create_gv_t(i, s1, s2) );

    check( strcmp( ((gv_t *) ht_get(ht, key))->s1, s1) == 0 );
    check( strcmp( ((gv_t *) ht_get(ht, key))->s2, s2) == 0 );
    check(((gv_t *) ht_get(ht, key))->i1 == i );

  }
  ht_destroy(ht);
 

  return 0;
}
コード例 #19
0
ファイル: identifiers.c プロジェクト: 0mp/freebsd
/* Set up the identifier hash table.  Use TABLE if non-null, otherwise
   create our own.  */
void
_cpp_init_hashtable (cpp_reader *pfile, hash_table *table)
{
  struct spec_nodes *s;

  if (table == NULL)
    {
      pfile->our_hashtable = 1;
      table = ht_create (13);	/* 8K (=2^13) entries.  */
      table->alloc_node = (hashnode (*) (hash_table *)) alloc_node;

      _obstack_begin (&pfile->hash_ob, 0, 0,
		      (void *(*) (long)) xmalloc,
		      (void (*) (void *)) free);
    }

  table->pfile = pfile;
  pfile->hash_table = table;

  /* Now we can initialize things that use the hash table.  */
  _cpp_init_directives (pfile);
  _cpp_init_internal_pragmas (pfile);

  s = &pfile->spec_nodes;
  s->n_defined		= cpp_lookup (pfile, DSC("defined"));
  s->n_true		= cpp_lookup (pfile, DSC("true"));
  s->n_false		= cpp_lookup (pfile, DSC("false"));
  s->n__VA_ARGS__       = cpp_lookup (pfile, DSC("__VA_ARGS__"));
  s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
}
コード例 #20
0
ファイル: main.c プロジェクト: Jonghwanshin/sicxeassembler
int main(){
	char* filename = (char *)malloc(20*sizeof(char));
	char* symboldef = (char *)malloc(5*sizeof(char));
	char* opcode_mnemonic = (char *)malloc(4*sizeof(char));
	char* operand = (char *)malloc(10*sizeof(char));
	unsigned int* opcode = (unsigned int *)malloc(sizeof(int));
	outputBufferPointer = &outputBuffer[0];

	SYMTAB = ht_create(100);

	printf("_______________SIC/XE Assembler_______________\n");
	printf("Assemble을 원하는 File의 이름을 입력해주세요.\n Filename >");
	scanf("%s",filename);

	SinglePass(filename,symboldef,opcode_mnemonic,operand,opcode);
	whichPass = 2;
	SinglePass(filename,symboldef,opcode_mnemonic,operand,opcode);
	
	filename = NULL;
	symboldef = NULL;
	opcode_mnemonic = NULL;
	operand = NULL;
	opcode = NULL;

	free(SYMTAB);
	free(LITTAB);
	free(MDRTAB);
	free(filename);
	free(symboldef);
	free(opcode_mnemonic);
	free(operand);
	free(opcode);
	return 0;
}
コード例 #21
0
ファイル: hashy_tests.cpp プロジェクト: andylamp/hashy_table
/**
 * Test that half fills a moderately sized hash table with
 * entries, then drains it. Hash function used here is the
 * Jenkins hash (which is the default).
 */
TEST(hashy_tests, test_jenkins_hash) {
    size_t ht_size = 1024;
    std::string skey = "key_",
                svalue = "value_";

    std::stringstream sskey, ssvalue;
    skey.append("key_");
    svalue.append("value_");

    hashtable_t *ht = ht_create(ht_size, NULL);


    for(int i = 0; i < ht_size/2; i++) {
        sskey << skey << i;
        ssvalue << svalue << i;

        ht_set(ht, (char *) sskey.str().c_str(),
               (char *) ssvalue.str().c_str());
        sskey.str(std::string());
        ssvalue.str(std::string());
    }

    for(int i = 0; i < ht_size/2; i++) {
        sskey << skey << i;
        ssvalue << svalue << i;

        char * val = ht_rem(ht, (char *) sskey.str().c_str());
        if(val) {free(val);}
        sskey.str(std::string());
    }
    EXPECT_EQ(ht->stored_elements, 0);
    EXPECT_EQ(ht_destroy(ht), 0);
}
コード例 #22
0
ファイル: identifiers.c プロジェクト: abumaryam/gcc
/* Set up the identifier hash table.  Use TABLE if non-null, otherwise
   create our own.  */
void
_cpp_init_hashtable (cpp_reader *pfile, cpp_hash_table *table)
{
  struct spec_nodes *s;

  if (table == NULL)
    {
      pfile->our_hashtable = 1;
      table = ht_create (13);	/* 8K (=2^13) entries.  */
      table->alloc_node = alloc_node;

      obstack_specify_allocation (&pfile->hash_ob, 0, 0, xmalloc, free);
    }

  table->pfile = pfile;
  pfile->hash_table = table;

  /* Now we can initialize things that use the hash table.  */
  _cpp_init_directives (pfile);
  _cpp_init_internal_pragmas (pfile);

  s = &pfile->spec_nodes;
  s->n_defined		= cpp_lookup (pfile, DSC("defined"));
  s->n_true		= cpp_lookup (pfile, DSC("true"));
  s->n_false		= cpp_lookup (pfile, DSC("false"));
  s->n__VA_ARGS__       = cpp_lookup (pfile, DSC("__VA_ARGS__"));
  s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
  s->n__has_include__   = cpp_lookup (pfile, DSC("__has_include__"));
  s->n__has_include_next__ = cpp_lookup (pfile, DSC("__has_include_next__"));
}
コード例 #23
0
ファイル: compiler.c プロジェクト: alex4o/AL-VM
int main(int argc, char *argv[]){
	char op[3];
	int v;
	int c;
	hashtable_t *hashtable = ht_create(64);
	ht_set(hashtable, (char*)&"mov", 0 ,2);
	ht_set(hashtable, (char*)&"lod", 1, 2);
	ht_set(hashtable, (char*)&"add", 2, 2);
	while (1){

		scanf("%s", &op);
		v = ht_get(hashtable, (char*)&op);
		c = ht_get_count(hashtable, (char*)&op);
		printf("code: %d, count: %d\n", v, c);
	} 


	//FILE *program;
	printf("%Opening [%s]\n", argv[1]);
	//program = fopen(argv[1],"w+");


	//fclose(program);
	return 0;
}
コード例 #24
0
ファイル: main.c プロジェクト: Elytum/Lemins
int				main(void)
{
	char		*line;
	t_map		map;

	bzero(&map, sizeof(map));
	if (!(map.cells = ht_create(2048)) ||
		!(map.list = new_vector(sizeof(char *))) ||
		!extract_nb_ants(&map) || map.ants_nb > 1000000)
		exit(write(1, "Error\n", 6));
	line = NULL;
	while (get_next_line(0, &line) == 1)
	{
		write(1, line, ft_strlen(line));
		write(1, "\n", 1);
		if (!analyze_line(line, &map))
			break ;
		free(line);
	}
	write(1, "\n", 1);
	if (map.start && map.end)
		solve_master(&map);
	else
		write(1, "Error\n", 6);
	return (1);
}
コード例 #25
0
ファイル: indexer.c プロジェクト: chickenbug/Indexer
int main(int argc, char *argv[])
{    
    if (argc != 3) {

        printf("Incorrect number of arguments.  Run again\n");
        return EXIT_FAILURE;

    } 
    else {
        if(strcmp(argv[2], ".") == 0 || strcmp(argv[2], "..") == 0){
            printf("Error: Cannot utilize parent directory or current working directory as input.\n");
            return EXIT_FAILURE;
        }
        if(strcmp(argv[2],"") == 0){
            printf("Error: Starting file or directory is NULL\n");
             return EXIT_FAILURE;
        }
    
        ht = ht_create();
        out_path = argv[1];
        if(get_Files(argv[2]) == -1) {
            printf("File read fails. Invalid start input\n");
            return EXIT_FAILURE;
        }
        
    }
    Record** rec_array;
    rec_array = hash_pull(ht);
    qsort(rec_array, ht->size, sizeof(Record*), rec_compare);
    print_json(rec_array);
    ht_free(ht);
    free(rec_array);
    return 0;
}
コード例 #26
0
ファイル: eval.c プロジェクト: SiegeLord/libeval
int eval_def_fn(const char *name, FunctionPtr fn, void *data, int args)
{
	VarFn *f;
	
	if(G_varfn_table == NULL)
	{ /* allocate new fn table */
		G_varfn_table = ht_create(500, vhash, vcomp, NULL, vdel);
		if(G_varfn_table == NULL)
			return 1; /* failed to create table */
	}
	if(ht_lookup(G_varfn_table, name, (void*)(&f)))
	{
		f = create_fn(name, fn, args, data);
		if(f == NULL)
			return 2; /* failed to create new entry */
		if(ht_insert(G_varfn_table, (void*)(f->name), (void*)f))
			return 3; /* insert failed */
	}else if(f->fn == NULL)
		return 4; /* this is a variable, NOT a function */
	else
	{
		f->fn = fn;
		f->data = data;
		f->nargs = args;
	}
	
	return 0;
}
コード例 #27
0
ファイル: arc.c プロジェクト: theseusyang/libshardcache
/* Create a new cache. */
arc_t *
arc_create(arc_ops_t *ops, size_t c, size_t cached_object_size, size_t *lists_size[4], arc_mode_t mode)
{
    arc_t *cache = calloc(1, sizeof(arc_t));

    cache->mode = mode;

    cache->ops = ops;

    cache->hash = ht_create(1<<16, 1<<22, NULL);

    cache->c = c >> 1;
    cache->p = cache->c >> 1;
    cache->cos = cached_object_size;

    arc_list_init(&cache->mrug.head);
    arc_list_init(&cache->mru.head);
    arc_list_init(&cache->mfu.head);
    arc_list_init(&cache->mfug.head);

    lists_size[0] = &cache->mru.size;
    lists_size[1] = &cache->mfu.size;
    lists_size[2] = &cache->mrug.size;
    lists_size[3] = &cache->mfug.size;

    MUTEX_INIT_RECURSIVE(&cache->lock);

    cache->refcnt = refcnt_create(1<<8, terminate_node_callback, free_node_ptr_callback);
    return cache;
}
コード例 #28
0
ファイル: eval.c プロジェクト: SiegeLord/libeval
/* public: variable access (set) function */
int eval_set_var(const char *name, double value)
{
	VarFn *var;
	
	if(G_varfn_table == NULL)
	{ /* allocate the var table */
		G_varfn_table = ht_create(500, vhash, vcomp, NULL, vdel);
		if(G_varfn_table == NULL)
			return 1;
	}
	/* find named var, update value or insert var/value */
	if(ht_lookup(G_varfn_table, name, (void*)&var))
	{ /* not found, insert new variable */
		var = create_var(name, value);
		if(var == NULL)
			return 2;
		if(ht_insert(G_varfn_table, (void*)(var->name), (void*)var))
			return 3;
		G_var_count++;
	}else if(var->fn != NULL)
		return 4;
	else
		var->value = value;
	
	return 0;
}
コード例 #29
0
ファイル: stringpool.c プロジェクト: CookieChen/gcc
/* Initialize the string pool.  */
void
init_stringpool (void)
{
  /* Create with 16K (2^14) entries.  */
  ident_hash = ht_create (14);
  ident_hash->alloc_node = alloc_node;
  ident_hash->alloc_subobject = stringpool_ggc_alloc;
}
コード例 #30
0
ファイル: backend_c.c プロジェクト: wm4/boringlang
void generate_c(FILE *f, struct ir_unit *unit)
{
    CTX *ctx = talloc_struct(NULL, CTX, { f, 0 });
    ctx->type_mangle = ht_create(ctx, HT_DATA_dptr, HT_DATA_dstr);
    ctx->redef = ht_create(ctx, HT_DATA_dstr, HT_DATA_dempty);
    ctx->tuple_abbrev = ht_create(ctx, HT_DATA_dstr, HT_DATA_dstr);
    ctx->tmp = talloc_new(ctx);
    prelude(ctx);
    struct optimize_settings opt = OPTIMIZE_DEFAULT;
    opt.opt_inline = true;
    unit_optimize(unit, &opt);
    for (int n = 0; n < unit->fn_decls_count; n++) {
        struct ir_fn_decl *fn = unit->fn_decls[n];
        gen_fn(ctx, fn->body, link_name(ctx, fn->name), fn->name.visible);
    }
    talloc_free(ctx);
}