Exemple #1
0
int main(int argc, char *argv[]) {
	int i;
	Table_T identifiers = Table_new(5000,
		(int (*)(const void *, const void *))strcmp, strhash);

	Fmt_register('S', Str_fmt);
	first = Str_catv("abcdefghijklmnopqrstuvwxyz", 1, 0,
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 0, "_", 1, 0, NULL);
	rest  = Str_cat(first, 1, 0, "0123456789", 1, 0);
	for (i = 1; i < argc; i++) {
		FILE *fp = fopen(argv[i], "r");
		if (fp == NULL)
			fprintf(stderr, "%s: can't open '%s' (%s)\n", argv[0], argv[i], strerror(errno));
		else {
			kref(argv[i], fp, identifiers);
			fclose(fp);
		}
	}
	if (argc == 1)
		kref(NULL, stdin, identifiers);
	{
		int i;
		void **array = Table_toArray(identifiers, NULL);
		qsort(array, Table_length(identifiers), 2*sizeof (*array), compare);
		for (i = 0; array[i]; i += 2) {
			Fmt_print("%S", array[i], 1, 0);
			print(array[i+1]);
			FREE(array[i]);
		}
		FREE(array);
		Table_free(&identifiers);
	}
	return EXIT_SUCCESS;
}
Exemple #2
0
int main(int argc, char *argv[]) {
	int i;
	Table_T identifiers = Table_new(0, NULL, NULL);
	for (i = 1; i < argc; i++) {
		FILE *fp = fopen(argv[i], "r");
		if (fp == NULL) {
			fprintf(stderr, "%s: can't open '%s' (%s)\n",
				argv[0], argv[i], strerror(errno));
			return EXIT_FAILURE;
		} else {
			xref(argv[i], fp, identifiers);
			fclose(fp);
		}
	}
	if (argc == 1) xref(NULL, stdin, identifiers);
	{
		int i;
		void **array = Table_toArray(identifiers, NULL);
		qsort(array, Table_length(identifiers),
			2*sizeof (*array), compare);
		for (i = 0; array[i]; i += 2) {
			printf("%s", (char *)array[i]);
			print(array[i+1]);
		}
		FREE(array);
	}
	return EXIT_SUCCESS;
}
Exemple #3
0
void print(Table_T files) {
	int i;
	void **array = Table_toArray(files, NULL);
	qsort(array, Table_length(files), 2*sizeof (*array),
		compare);
	for (i = 0; array[i]; i += 2) {
		if (*(char *)array[i] != '\0')
			printf("\t%s:", (char *)array[i]);
		{
			void **lines = Set_toArray(array[i+1], NULL);
			qsort(lines, Set_length(array[i+1]), sizeof (*lines),
				cmpint);
         int j, c;
			for (j = 0; lines[j]; j++) {
            printf(" %d", *(int *)lines[j]);
            c = 0;
			   while (lines[j+1] 
			      && *(int *)lines[j+1] == *(int *)lines[j] + 1) {
			      j++;
               c = 1;
			   }
			   if (c)
               printf("-%d", *(int *)lines[j]);
			}
			FREE(lines);
		}
		printf("\n");
	}
	FREE(array);
}
Exemple #4
0
int main(int argc, char *argv[]) {
	int i;
	Table_T identifiers = Table_new(10000, textcmp, texthash);
	Text_save_T mark = Text_save();

	Fmt_register('T', Text_fmt);
	Fmt_register('D', Integer_fmt);
	first = Text_cat(Text_cat(Text_ucase, Text_lcase), Text_box("_", 1));
	rest  = Text_cat(first, Text_digits);
	for (i = 1; i < argc; i++) {
		FILE *fp = fopen(argv[i], "r");
		if (fp == NULL)
		fprintf(stderr, "%s: can't open '%s' (%s)\n", argv[0], argv[i], strerror(errno));
		else {
			cref(argv[i], fp, identifiers);
			fclose(fp);
		}
	}
	if (argc == 1)
		cref(NULL, stdin, identifiers);
	{
		int i;
		void **array = Table_toArray(identifiers, NULL);
		qsort(array, Table_length(identifiers), 2*sizeof (*array), compare);
		for (i = 0; array[i]; i += 2) {
			Fmt_print("%T", array[i]);
			print(array[i+1]);
			FREE(array[i]);
		}
		FREE(array);
		Table_free(&identifiers);
	}
	Text_restore(&mark);
	return EXIT_SUCCESS;
}
Exemple #5
0
void wf(char *name, FILE *fp) {
	Table_T table = Table_new(0, NULL, NULL);
	char buf[128];
	while (getword(fp, buf, sizeof buf, first, rest)) {
		const char *word;
		int i, *count;
		for (i = 0; buf[i] != '\0'; i++)
			buf[i] = tolower(buf[i]);
		word = Atom_string(buf);
		count = Table_get(table, word);
		if (count)
			(*count)++;
		else {
			NEW(count);
			*count = 1;
			Table_put(table, word, count);
		}
	}
	if (name)
		printf("%s:\n", name);
	{ int i;
	  void **array = Table_toArray(table, NULL);
	  qsort(array, Table_length(table), 2*sizeof (*array),
	  	compare);
	  for (i = 0; array[i]; i += 2)
	  	printf("%d\t%s\n", *(int *)array[i+1],
	  		(char *)array[i]);
	  FREE(array); }
	Table_map(table, vfree, NULL);
	Table_free(&table);
}
Exemple #6
0
void print(Table_T files){
	int i;
	void **array = Table_toArray(files, NULL);
	
	qsort(array, Table_length(files), 2 * sizeof(*array), compare);
	
	for (i = 0; array[i]; i += 2){
		if (*(char *)array[i] != '\0'){
			printf("\t%s:", (char *)array[i]);
		}
		// print the line numbers in the set array[i+1]
		{
			int j;
			void **lines = Set_toArray(array[i + 1], NULL);
			
			qsort(lines, Set_length(array[i+1], sizeof(*lines), cmpint);
			
			for (j = 0; lines[j]; j++){
				printf(" %d", *(int *)lines[j]);
			}
			FREE(lines);
		}
		
		printf("\n");
	}
	FREE(array);
}
Exemple #7
0
static void _cleanup(OeSession session) {

    T _this_ = OeNet_get_proto(OeSession_get_net(session));
    int sz = Table_length(_this_->pending);
    void **array = Table_toArray(_this_->pending, NULL);
    for ( int i = 0; i < sz && array[i]; i+= 2 ) {
        CID_KEY *key = (CID_KEY *) array[i];
        ACContext *pc = Table_remove(_this_->pending, key);
        _send_con_closed(pc->context);
    }
    Mem_free(array, __FILE__, __LINE__);
    Table_free(&_this_->pending);
    //OepClient_free(&_this_);  //closing the proto is hard and buggy.
}
Exemple #8
0
/*finds and returns the number of sets with more than one value*/
int num_fgroups(Table_T* table)
{
        int table_len = Table_length(*table);
        void **table_array = Table_toArray(*table, NULL);
        int counter = 0;

        for (int i=1; i<(2*table_len); i += 2) {
                if (Set_length((Set_T)table_array[i]) > 1) {
                        counter++;
                }
        }
        free(table_array);
        return counter;
}
Exemple #9
0
static void _free_items(Table_T items) {

    assert(items);

    int sz = Table_length(items);
    if (sz > 0) {
        void **array = Table_toArray(items, NULL);
        for ( int i = 0; i < sz && array[i]; i+= 2 ) {
            char *key = (char *) array[i];
            Set_T titem = Table_remove(items, key);
            if (titem) {
                Set_free( &titem );
            }
        }
        Mem_free(array, __FILE__, __LINE__);
    }
}
Exemple #10
0
void print(Table_T files) {
	int i;

	void **array = Table_toArray(files, NULL);
	qsort(array, Table_length(files), 2*sizeof (*array), compare);
	for (i = 0; array[i]; i += 2) {
		Seq_T seq = array[i+1];
		char *filename = array[i];
		if (*filename)
			Fmt_print("\t%S:", filename, 1, 0);
		while (Seq_length(seq) > 0)
			Fmt_print(" %S", Seq_remhi(seq), 1, 0);
		Fmt_print("\n");
		FREE(filename);
		Seq_free(&seq);
	}
	FREE(array);
	Table_free(&files);
}
Exemple #11
0
 /* prints the sets in the table that have more than 1 value*/
void print_table(Table_T* table)
{
        int table_len = Table_length(*table);
        void **table_array = Table_toArray(*table, NULL);

        int counter = num_fgroups(table);

        for (int i=1; i<(2*table_len); i += 2) {
                if(Set_length((Set_T)table_array[i]) > 1) {
                        print_set((Set_T *)&table_array[i]);
                        counter--;
                        if (counter != 0) {     
                                printf("\n");
                        }
                }
                Set_free((Set_T *)&table_array[i]);
        }
        free(table_array);
}
Exemple #12
0
void print_fgroups(T* table)
{
    char ** arr = (char **)Table_toArray(*table, NULL);
    int table_length = Table_length(*table) * 2;
    for (int i=0; i < table_length; i+=2) {
        L list_ptr = ((L)arr[i+1]);
        int list_size = List_length(list_ptr);
        if (list_size >= 2) {
            char **names = (char**) List_toArray(list_ptr, NULL);
            for (int j = 0; names[j]; j++)
                printf("%s\n", (char*)(names[j]));
            if (2*i+2 < table_length)
                printf("\n");
            free(names);
        }
        List_free(&list_ptr);
    }
    free(arr);
    Table_free(table);
}
Exemple #13
0
int try_running_tests_in_dso(struct herc *h, const char *file, void *handle) {
	size_t i = 0;
	void *suite_fixture, *test_fixture;
	//get the suites
	Table_T suitesTable = get_testnames_in_file(file, handle);

	//convert to array for easier sorting and iteration
	unsigned nSuites = Table_length(suitesTable);
	void **suites = Table_toArray(suitesTable, 0);
	Table_free(&suitesTable);
	
	//sort
	qsort(suites, nSuites, 2*sizeof(suites[0]), (int (*)(const void *, const void *))strcmp);

	//iterate and run
	for (i = 0; i<nSuites; i++) {
		suite_desc *suite = suites[i*2+1];
		suite_fixture = invoke_before_suite(suite);//TODO call RBE callback
		cr_list_iter *iter = cr_list_iter_create(suite->tests);
		while (!cr_list_iter_past_end(iter)) {
			test_fixture = invoke_before_test(suite, suite_fixture);
			test_desc *test = (test_desc*)cr_list_iter_get(iter);
			herc_rbe_invoke(h->rbe, start_test, test);
			run_test(h, handle, test, test_fixture);
			herc_rbe_invoke(h->rbe, end_test, test);
			invoke_after_test(suite, test_fixture);
			cr_list_iter_next(iter);
		}
		cr_list_iter_free(iter);
		invoke_after_suite(suite, suite_fixture);
	}

	for (i = 0; i<nSuites; i++) {
		suite_desc_free(suites[i*2+1]);
	}


	free(suites);
	return 0;
}
Exemple #14
0
void print(Table_T files) {
	int i;

	void **array = Table_toArray(files, NULL);
	qsort(array, Table_length(files), 2*sizeof (*array), compare);
	for (i = 0; array[i]; i += 2) {
		Ring_T ring = array[i+1];
		Text_T *filename = array[i];
		if (filename->len > 0)
			Fmt_print("\t%T:", filename);
		while (Ring_length(ring) > 0) {
			Integer_T line = Ring_remhi(ring);
			Fmt_print(" %D", line);
			FREE(line);
		}
		Fmt_print("\n");
		FREE(filename);
		Ring_free(&ring);
	}
	FREE(array);
	Table_free(&files);
}
Exemple #15
0
int main()
{
  FILE *fp = fopen("test.txt", "r");
  int c = 0;
  int i = 0;
  char s[512];
  Table_T our_table = Table_new(10, NULL, NULL);
  char * name;
  const char *fingerprint;
  const char* temp;
  while((c=fgetc(fp)) != ' ' && c != EOF)  //Fingerprint section
    {
      s[i]= c;
      i++;
    }
  s[i] = '\0';
  //Here we have fingerprint in s
  fingerprint = Atom_string(s);
  temp = Atom_string(s); 
  i = 0;
  while((c = getc(fp)) != '\n' && c != EOF)
    {
      s[i] = c;
      i++;
    }
  s[i] = '\0';
  //Here we have name in s
  name = s;    
  Table_put(our_table, fingerprint, name);
  while( c != EOF)
    {
      i = 0;
      while((c = fgetc(fp)) != ' ' && c != EOF) // Fingerprint section
	{
	  s[i] = c;
          i++;
	}
       s[i] = '\0';
       fingerprint = Atom_string(s);
       i = 0;
       while((c = getc(fp)) != '\n' && c != EOF)
	   {
             s[i] = c;
             i++;
            }
        s[i] = '\0';
        name = s;
        printf("FP: %s\n ", fingerprint);
    printf("NAME: %s\n", name);
 
	char * test = Table_put(our_table, fingerprint, name);
        printf("idk: %s\n", test); 
	// printf("VALUE STORED IN FP: %s\n\n", (char *)Table_get(our_table, temp));   
  }

  // NEED TO DEAL WITH TABLE MAP AND IMPLEMENTING A LIST   
  // Table_map(our_table, vfree, NULL);
  
  //printf("%s", fingerprint);
  // printf("%s", (char *)Table_get(our_table, fingerprint));
  
  printf("%d", Table_length(our_table));
  
  // Table_map(our_table, vfree, NULL);
  int length = Table_length(our_table);
  void **table = Table_toArray(our_table, NULL);
 for(int x = 0; x < 2*length; x++)
    {
      printf("%s ", (char *)table[x]); 
   }


  Table_free(&our_table);
  return 0;
}