コード例 #1
0
ファイル: autoconvert.c プロジェクト: morenko/sven
static gpointer create(gpointer sdata)
{
	Sven *sven = (Sven *)sdata;
	AConvert *aconv= g_slice_new0(AConvert);
	//aconv = g_new0 (AConvert, 1);
	
	aconv->sven=sven;
	init_sxkb(sven,aconv);
	dictionary_init(aconv);
	grab_keyboard_init(aconv);
	
	 return aconv;
}
コード例 #2
0
ファイル: gnoetics.c プロジェクト: michel-slm/gnoetry
void
initxxx_gnoetics (void)
{
  PyObject *m, *d;
  int i;

  m = Py_InitModule ("xxx_gnoetics", gnoetics_methods);
  d = PyModule_GetDict (m);

  fate_seed_from_time ();
  dictionary_init ();

  for (i = 0; register_funcs[i] != NULL; ++i)
      register_funcs[i] (d);
}
コード例 #3
0
ファイル: zdb.c プロジェクト: koodaamo/yadifa
void
zdb_create(zdb* db)
{
    int i;
    for(i = HOST_CLASS_IN - 1; i < ZDB_RECORDS_MAX_CLASS; i++)
    {
        zdb_zone_label* zone_label;

        ZALLOC_OR_DIE(zdb_zone_label*, zone_label, zdb_zone_label, ZDB_ZONELABEL_TAG);
        ZEROMEMORY(zone_label, sizeof (zdb_zone_label));
        zone_label->name = dnslabel_dup(ROOT_LABEL); /* . */
        dictionary_init(&zone_label->sub);

#if ZDB_CACHE_ENABLED!=0
        btree_init(&zone_label->global_resource_record_set);
#endif
        db->root[i] = zone_label;
    }

    db->alarm_handle = alarm_open((const u8*)"\010database");
}
コード例 #4
0
ファイル: part2.c プロジェクト: karanghai/SystemsProgramming
int main()
{
	/*
	 * Initialize the dictionary data structure.
	 */
	dictionary_t dictionary;
	dictionary_init(&dictionary);


	/*
	 * Preform some basic actions
	 */
	int result;
	const char *s;

	/* _add() */
	result = dictionary_add(&dictionary, "key", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }
	
	result = dictionary_add(&dictionary, "key2", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }



	result = dictionary_add(&dictionary, "key3", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }


//dictionary_print(&dictionary);
	result = dictionary_add(&dictionary, "key", "value2");
	if (result == 0) { printf("_add() was successful, and it should've failed.\n"); }
	else { printf("_add(): OKAY!\n"); }
//dictionary_print(&dictionary);
	/* _remove() */
	dictionary_remove(&dictionary, "key3");

	/* _get() */
	s = dictionary_get(&dictionary, "non-existant");
	if (s != NULL) { printf("_get() was successful, and it should've failed.\n"); }
	else { printf("_get(): OKAY!\n"); }

	s = dictionary_get(&dictionary, "key");
	if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); }
	else { printf("_get(): OKAY!\n"); }
	
	/* _parse() */
	char *s1 = malloc(100);
	strcpy(s1, "key3: value");
	result = dictionary_parse(&dictionary, s1);
	if (result != 0) { printf("_parse() failed, and it should have been successful.\n"); }
	else { printf("_parse(): OKAY!\n"); }
	
	//if(dictionary_remove(&dictionary, "key3")!=0) printf("unsuccesfull\n");//added
	char *s2 = malloc(100);
	strcpy(s2, "bad key-value");
	result = dictionary_parse(&dictionary, s2);
	if (result == 0) { printf("_parse() was successful, and it should've failed.\n"); }
	else { printf("_parse(): OKAY!\n"); }

	

	/* _get() */
	s = dictionary_get(&dictionary, "key3");
	if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); }
	else { printf("_get(): OKAY!\n"); }
	


	/*
	 * Free up the memory used by the dictionary and close the file.
	 */
	dictionary_destroy(&dictionary);
	free(s1);
	free(s2);

	return 0;
}
コード例 #5
0
ファイル: test2.c プロジェクト: DeathByTape/UofI_undergrad
int main(int argc, char *argv[]) {
  char *prgm = *argv;
  argv++; argc--;

  dictionary_t dictionary;

  if(argc < 1) {
    printf("Usage: %s [options]\n",prgm);
    printf("Use any combination of the following:\n");
    printf("  -i: Initialize the dictionary\n");
    printf("  -a [key] [value]: Add a key/value to the dictionary\n");
    printf("  -p [string]: Parse a string into the dictionary\n");
    printf("  -g [key]: Get a value by its key from the dictionary\n");
    printf("  -r [key]: Remove a key from the dictionary\n");
    printf("  -d: Destroy the dictionary\n");
  }

  char *key, *value, *string;

  while(argc > 0) {
    if(strcmp(*argv,"-i") == 0) { //Initialize
      printf("Running init()\n");
      dictionary_init(&dictionary);
      printf("  completed\n");
    } else if(strcmp(*argv,"-a") == 0) {
      if(argc < 3) {
	printf("Not enough parameters to -a\n");
	return 2;
      }
      key = mstrcpy(argv[1]);
      value = mstrcpy(argv[2]);
      printf("Running add(\"%s\",\"%s\")\n",argv[1],argv[2]);
      d_retint(dictionary_add(&dictionary, key, value));
      d_compare("key",argv[1],key);
      d_compare("value",argv[2],value);
      argv += 2; argc -= 2;
    } else if(strcmp(*argv,"-p") == 0) {
      if(argc < 2) {
	printf("Not enough parameters to -p\n");
	return 2;
      }
      string = mstrcpy(argv[1]);
      printf("Running parse(\"%s\")\n",argv[1]);
      d_retint(dictionary_parse(&dictionary, string));
      d_compare("string",argv[1],string);
      argv += 1; argc -= 1;
    } else if(strcmp(*argv,"-g") == 0) {
      if(argc < 2) {
	printf("Not enough parameters to -g\n");
	return 2;
      }
      key = mstrcpy(argv[1]);
      printf("Running get(\"%s\")\n",argv[1]);
      d_retstr(dictionary_get(&dictionary, key));
      d_compare("key",argv[1],key);
      argv += 1; argc -= 1;
    } else if(strcmp(*argv,"-r") == 0) {
      if(argc < 2) {
	printf("Not enough parameters to -r\n");
	return 2;
      }
      key = mstrcpy(argv[1]);
      printf("Running remove(\"%s\")\n",argv[1]);
      d_retint(dictionary_remove(&dictionary, key));
      d_compare("remove",argv[1],key);
      argv += 1; argc -= 1;
    } else if(strcmp(*argv,"-d") == 0) {
      printf("Running destroy()\n");
      dictionary_destroy(&dictionary);
      printf("  completed\n");
    } else {
      printf("Did not understand parameter: %s\n",*argv);
      return 3;
    }
    argv++; argc--;
  }
}
コード例 #6
0
ファイル: part2.c プロジェクト: DeathByTape/UofI_undergrad
int main()
{
	/*
	 * Initialize the dictionary data structure.
	 */
	dictionary_t dictionary;
	dictionary_init(&dictionary);


	/*
	 * Preform some basic actions
	 */
	int result;
	const char *s;

	/* _add() */
	result = dictionary_add(&dictionary, "key", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }

	result = dictionary_add(&dictionary, "key2", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }

	result = dictionary_add(&dictionary, "key3", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }

	result = dictionary_add(&dictionary, "key", "value2");
	if (result == 0) { printf("_add() was successful, and it should've failed.\n"); }
	else { printf("_add(): OKAY!\n"); }

	/* _remove() */
	dictionary_remove(&dictionary, "key3");

	/* _get() */
	s = dictionary_get(&dictionary, "non-existant");
	if (s != NULL) { printf("_get() was successful, and it should've failed.\n"); }
	else { printf("_get(): OKAY!\n"); }

	s = dictionary_get(&dictionary, "key");
	if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); }
	else { printf("_get(): OKAY!\n"); }

	/* _parse() */
	char *s1 = malloc(100);
	strcpy(s1, "key3: value");
	result = dictionary_parse(&dictionary, s1);
	if (result != 0) { printf("_parse() failed, and it should have been successful.\n"); }
	else { printf("_parse(): OKAY!\n"); }

	char *s2 = malloc(100);
	strcpy(s2, "bad key-value");
	result = dictionary_parse(&dictionary, s2);
	if (result == 0) { printf("_parse() was successful, and it should've failed.\n"); }
	else { printf("_parse(): OKAY!\n"); }

	/* _get() */
	s = dictionary_get(&dictionary, "key3");
	if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); }
	else { printf("_get(): OKAY!\n"); }

    result = dictionary_parse(&dictionary, "hola, :senor");
    if(result == 0) printf("Bad!\r\n");
    else printf("Success\r\n");

    strcpy(s1, "w00t: d00ddd");
    result = dictionary_parse(&dictionary, s1);
    //char * z = "w00t: d00ddd";
    s = dictionary_get(&dictionary, "w00t");
    if(s == 0 || strcmp(s, "d00ddd") != 0) printf("Bad: %s\r\n", s);
    else printf("Success\r\n");

    char * s3 = (char*)malloc(100);
    strcpy(s3, "    : sdasda");
    result = dictionary_parse(&dictionary, s3);
    s = dictionary_get(&dictionary, "");
    if(s != 0) printf("Bad: %s\r\n", s);
    else printf("Success\r\n");

    char* s4 = (char*)malloc(100);
    strcpy(s1, "ad: (&DAS^\\x");
    if(dictionary_parse(&dictionary, s1) != 0)
        printf("Error\r\n");
    s = dictionary_get(&dictionary, "ad");
    strcpy(s1, "w00t1: test");
    dictionary_parse(&dictionary, s1);
 strcpy(s4, "w00t1");
    s = dictionary_get(&dictionary, s4);
    if(s == 0 || strcmp(s, "test") != 0)
        printf("Error3\r\n");
    else
        printf("Success\r\n");

    strcpy(s1, "w00t1: test2324334");
    if((result = dictionary_parse(&dictionary, s1)) != KEY_EXISTS)
        printf("Error: %d\r\n", result);
    else printf("Success\r\n");


    /**** BEGIN "Robust" Test Cases ****/
    // Test 1
    printf("\r\n\r\n=== BEGIN ROBUST ===\r\n\r\n");
    char x[] = "Test Me: 57 ad9 X";
    result = dictionary_parse(&dictionary, x);
    if(result != 0) printf("Error: Test 1, %d\r\n", result);
    else printf("Test 1 Passed!\r\n");

    // Test 2
    s = dictionary_get(&dictionary, "Test Me");
    if(s != 0 && strcmp(s, "57 ad9 X") == 0) printf("Test 2 Passed!\r\n");
    else printf("Error: Test2\r\n");

    // Test 3
    result = dictionary_add(&dictionary, "Test me", "test_value");
    s = dictionary_get(&dictionary, "tESt mE");
    if(result != KEY_EXISTS || strcmp(s, "57 ad9 X") != 0) printf("Error: Test 3, %d, %s\r\n", result, s);
    else printf("Test 3 Passed!\r\n");

    // Test 4
    char y[] = "TeSt Me: d00d another one <3";
    result = dictionary_parse(&dictionary, y);
    if(result != KEY_EXISTS) printf("Error: Test 4\r\n");
    else printf("Test 4 Passed!\r\n");

    // Test 5
    dictionary_remove(&dictionary, "TeSt ME");
    s = dictionary_get(&dictionary, "test me");
    if(s != 0) printf("Error: Test 5\r\n");
    else printf("Test 5 Passed!\r\n");


	/*
	 * Free up the memory used by the dictionary and close the file.
	 */
	dictionary_destroy(&dictionary);
	free(s1);
	free(s2);
    free(s3);
    free(s4);

	return 0;
}
コード例 #7
0
int main()
{
	/**
 	 * Set the start time
 	 */ 
	clock_t start, end;
	double time_spent;
	start = clock();

	/*
	 * Initialize the dictionary data structure.
	 */
	dictionary_t dictionary;
	dictionary_init(&dictionary);

	int i=0;
	char** key_values = (char**)malloc(MAX_ENTRIES*sizeof(char*));
	for(i=0; i<MAX_ENTRIES; i++){
	    key_values[i] = (char*)malloc(50*sizeof(char));
	    sprintf(key_values[i], "%d: %d", i, i); 
	    if(dictionary_parse(&dictionary, key_values[i])!=0)
	    {
		printf("NOT_OK...THE ITEM SHOULD NOT ALREADY EXIST IN DICTIONARY\n");
		return 1;
	    } 
	}

        for(i=0; i<MAX_ENTRIES; i++){
	    char tmp[30];
            sprintf(tmp, "%d", i);
            if(strcmp(tmp, dictionary_get(&dictionary, tmp))!=0)
	    {
		printf("NOT_OK...CANNOT GET EXISTING ITEM IN DICTIONARY\n");
	        return 1;
	    }
        }

        for(i=0; i<MAX_ENTRIES; i++){
            if(dictionary_parse(&dictionary, key_values[i])==0)
            {
                printf("NOT_OK...THE ITEM SHOULD ALREADY EXIST IN DICTIONARY\n");
                return 1;
            } 
        }

	for(i=0; i<MAX_ENTRIES; i++){
            char tmp[30];
            sprintf(tmp, "%d", i);
	    if(dictionary_remove(&dictionary, tmp)!=0){
                printf("NOT_OK...THE ITEM TO REMOVE SHOULD IN DICTIONARY\n");
                return 1;
	    }
	}

	/*
	 * Free up the memory used by the dictionary and close the file.
	 */
	dictionary_destroy(&dictionary);

	for(i=0; i<MAX_ENTRIES; i++)
	    free(key_values[i]);
	free(key_values);

	/**
 	 * Set the end time
 	 */ 
        end = clock();
	time_spent = (double)(end - start) / CLOCKS_PER_SEC;
	printf("The running time for your dictionary is: %f seconds\n", time_spent);

	return 0;
}
コード例 #8
0
ファイル: part2.c プロジェクト: frank0098/CS241-1
int main()
{
	/*
	 * Initialize the dictionary data structure.
	 */
	dictionary_t dictionary;
	dictionary_init(&dictionary);


	/*
	 * Preform some basic actions
	 */
	int result;
	const char *s;

	/* _add() */
	result = dictionary_add(&dictionary, "key", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }

	result = dictionary_add(&dictionary, "key2", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }

	result = dictionary_add(&dictionary, "key3", "value");
	if (result != 0) { printf("_add() failed, and it should have been successful.\n"); }
	else { printf("_add(): OKAY!\n"); }

	result = dictionary_add(&dictionary, "key", "value2");
	if (result == 0) { printf("_add() was successful, and it should've failed.\n"); }
	else { printf("_add(): OKAY!\n"); }

	/* _remove() */
	dictionary_remove(&dictionary, "key3");

	/* _get() */
	s = dictionary_get(&dictionary, "non-existant");
	if (s != NULL) { printf("_get() was successful, and it should've failed.\n"); }
	else { printf("_get(): OKAY!\n"); }

	s = dictionary_get(&dictionary, "key");
	if (s == NULL){printf("NULL");}
	if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); }
	else { printf("_get(): OKAY!\n"); }

	/* _parse() */
	char *s1 = malloc(100);
	strcpy(s1, "key3: value");
	result = dictionary_parse(&dictionary, s1);
	if (result != 0) { printf("_parse() failed, and it should have been successful.\n"); }
	else { printf("_parse(): OKAY!\n"); }
	
	char *s2 = malloc(100);
	strcpy(s2, "a:: b");
	result = dictionary_parse(&dictionary, s2);
	if (result == 0) { printf("_parse() was successful, and it should've failed.\n"); }
	else { printf("_parse(): OKAY!\n"); }
	
	
	
	
	/*OWN TEST
	 * - ": www.cs.uiuc.edu", since the KEY is zero-length
 * - "MyKey, MyValue", since no colon, space exists
 * - "a:b", since no colon, space exists.
 * - "a:: b", since the first colon isn't followed by a space.
 * - ": key: value"
 * - " : "
 * - "         :  "
 */ 
	char *s3 = malloc(100);
	strcpy(s3, " :  ");
	result = dictionary_parse(&dictionary, s3);
	printf("The result is %d\n",result);
	
	
	/* _get() */
	s = dictionary_get(&dictionary, "key3");
	/*
	if (s != NULL){printf("ITS NOT NULL");} 
	if (s = NULL){printf("ITS NULL");}
	if (strcmp(s,"value") == 0){printf("Its 0");}
	if (strcmp(s,"value") != 0){printf("Its NOT 0");}
	*/
	
	if (s == NULL || strcmp(s, "value") != 0) { printf("_get() failed or was not the expected result.\n"); }
	
	else { printf("_get(): OKAY!\n"); }
	
	//printf("Im Here\n");
	/*
	 * Free up the memory used by the dictionary and close the file.
	 */
	dictionary_destroy(&dictionary);
	free(s1);
	free(s2);

	return 0;
}