コード例 #1
0
__declspec(dllexport) void curl_shim_initialize()
{
    g_hModCurl = GetModuleHandle("libcurl.dll");
    g_hModSock = GetModuleHandle("ws2_32.dll");
    g_delegateTable = Table_new(16, NULL, NULL);
    InitializeCriticalSection(&g_csDelegateTable);
    g_shareDelegateTable = Table_new(16, NULL, NULL);
    InitializeCriticalSection(&g_csShareDelegateTable);
}
コード例 #2
0
ファイル: wf.c プロジェクト: ZoneMo/backup
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);
}
コード例 #3
0
ファイル: stab.c プロジェクト: bhanug/cdb
/* stabinit - initialize for symbol table emission */
static void stabinit(char *file, int argc, char *argv[]) {
	extern Interface sparcIR, solarisIR, x86IR;
	extern int getpid(void);

	if (IR == &solarisIR || IR == &sparcIR)
		leader = "!";
	else if (IR == &x86IR)
		leader = ";";
	else
		leader = " #";  /* it's a MIPS or ALPHA */
	uname = time(NULL)<<7|getpid();
	pickle = sym_module(file ? file : string(""), uname, 1, Seq_new(0), 0, Seq_new(0));
	locals = Seq_new(0);
	statics = Seq_new(0);
	uidTable = Table_new(0, 0, 0);
	module = mksymbol(AUTO,	stringf("_module_V%x", uname), array(unsignedtype, 0, 0));
	module->generated = 1;
	nub_bpflags = mksymbol(EXTERN, "_Nub_bpflags", array(chartype, 1, 0));
	nub_bpflags->defined = 0;
	attach((Apply) entry_hook, NULL, &events.entry);
	attach((Apply) block_hook, NULL, &events.blockentry);
	attach((Apply) point_hook, NULL, &events.points);
	attach((Apply)  call_hook, NULL, &events.calls);
	attach((Apply)return_hook, NULL, &events.returns);
	nub_bp = mksymbol(EXTERN, "_Nub_bp", ftype(voidtype, inttype));
	nub_bp->defined = 0;
	nub_tos = mksymbol(EXTERN, "_Nub_tos", voidptype);
	nub_tos->defined = 0;
}
コード例 #4
0
ファイル: cref.c プロジェクト: KoyoA/patterns
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;
}
コード例 #5
0
ファイル: fgroups.c プロジェクト: gwolfeagle/comp40
int main(int argc, char* argv[])
{
    FILE* fp = process_args(argc, argv);
    T table = Table_new(1000, NULL, NULL);
    read_fgroups(fp, &table);
    print_fgroups(&table);
}
コード例 #6
0
/* Umsections_new makes a new 'assembler' in the form of a Umsections_T. It
 * creates a new table and makes the first key value pair with the given
 * section. It also sets the assembler to emit to that section.
 */
Umsections_T Umsections_new(const char *section, 
                 int (*error)(void *errstate, const char *message),
                 void *errstate)
{
        Umsections_T assembler = malloc(sizeof(*assembler));
        assert(assembler);

        Table_T table = Table_new(100, NULL, NULL);
        assert(table);

        Seq_T order = Seq_new(100);
        assert(order);
        Seq_addhi(order, (void *)section);

        Seq_T instructions = Seq_new(100);
        assert(instructions);

        Table_put(table, Atom_string(section), instructions);

        /* intializes the struct */
        assembler->table = table;
        assembler->section = section;
        assembler->order = order;
        assembler->err_func = error;
        assembler->errstate = errstate;

        return assembler;
}
コード例 #7
0
ファイル: kref.c プロジェクト: ZoneMo/backup
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;
}
コード例 #8
0
ファイル: xref.c プロジェクト: 22beer1bif/cii
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;
}
コード例 #9
0
ファイル: kref.c プロジェクト: ZoneMo/backup
void kref(char *name, FILE *fp, Table_T identifiers) {
	char buf[512], *filename = "";
	int linenum;

	if (name)
		filename = name;
	for (linenum = 1; fgets(buf, sizeof buf, fp) != NULL; linenum++) {
		int i, j;
		for (i = 0; (j = getword(buf, &i, first, rest)) > 0; i = j) {
			char *id = Str_sub(buf, j, i);
			const char *ln = Atom_int(linenum);
			Seq_T seq;
			Table_T files;
			files = Table_get(identifiers, id);
			if (files == NULL) {
				files = Table_new(0,
					(int (*)(const void *, const void *))strcmp, strhash);
				Table_put(identifiers, id, files);
			} else
				FREE(id);
			seq = Table_get(files, filename);
			if (seq == NULL) {
				seq = Seq_new(0);
				Table_put(files, Str_dup(filename, 1, 0, 1), seq);
				Seq_addlo(seq, (void *)ln);
			} else if (Seq_get(seq, 0) != ln)
				Seq_addlo(seq, (void *)ln);
		}
	}
}
コード例 #10
0
ファイル: xref.c プロジェクト: 22beer1bif/cii
void xref(const char *name, FILE *fp,
		Table_T identifiers){
	char buf[128];
	if (name == NULL)
		name = "";
	name = Atom_string(name);
	linenum = 1;
	while (getword(fp, buf, sizeof buf, first, rest)) {
		Set_T set;
		Table_T files;
		const char *id = Atom_string(buf);
		files = Table_get(identifiers, id);
		if (files == NULL) {
			files = Table_new(0, NULL, NULL);
			Table_put(identifiers, id, files);
		}
		set = Table_get(files, name);
		if (set == NULL) {
			set = Set_new(0, intcmp, inthash);
			Table_put(files, name, set);
		}
		{
			int *p = &linenum;
			if (!Set_member(set, p)) {
				NEW(p);
				*p = linenum;
				Set_put(set, p);
			}
		}
	}
}
コード例 #11
0
ファイル: umsections.c プロジェクト: andy7i/C_Projects
T Umsections_new (const char *section, 
            int (*error)(void *errstate, const char *message),
            void *errstate) {
   T Umsections = malloc(sizeof(*Umsections));
   Umsections->sections = Table_new(TABLE_HINT, NULL, NULL);
   Seq_T temp;
   temp = Seq_new(SEQ_HINT);
   Seq_T temp2;
   temp2 = Seq_new(SEQ_HINT);

   Umsections->error = error;
   Umsections->errstate = errstate;

   Umsections->currentSection = temp;
   Umsections->sectionOrder = temp2;
   Seq_addlo(Umsections->sectionOrder, temp);
   Table_put(Umsections->sections, Atom_string(section), temp);  
/*    Table_map((Umsections)->sections,applyFree,NULL);
    Table_free(&((Umsections)->sections));
    Seq_free(&((Umsections)->sectionOrder));
//    Seq_free(((Umsectinos)->currentSection));
    free(Umsections);
    exit(1);*/
   return Umsections;
}
コード例 #12
0
ファイル: spblasi_table.c プロジェクト: khaled777b/image-dec
int SPBLASI_table_insert(SPBLASI_Matrix *A)
{
	if (SPBLASI_Table == NULL)
		SPBLASI_Table = Table_new(1);

	return Table_insert(SPBLASI_Table, A);
}     
コード例 #13
0
ファイル: cref.c プロジェクト: KoyoA/patterns
void cref(char *name, FILE *fp, Table_T identifiers) {
	char buf[512];
	Text_T filename = { 0, "" };
	int linenum;

	if (name)
		filename = Text_put(name);
	for (linenum = 1; fgets(buf, sizeof buf, fp) != NULL; linenum++) {
		Text_T id, line = Text_put(buf);
		while ((id = getword(&line, first, rest)).len > 0) {
			Ring_T ring;
			Table_T files;
			files = Table_get(identifiers, &id);
			if (files == NULL) {
				files = Table_new(0, textcmp, texthash);
				Table_put(identifiers, copy(id), files);
			}
			ring = Table_get(files, &filename);
			if (ring == NULL) {
				ring = Ring_new();
				Table_put(files, copy(filename), ring);
				Ring_addlo(ring, Integer_new(linenum));
			} else if (Integer_get(Ring_get(ring, 0)) != linenum)
				Ring_addlo(ring, Integer_new(linenum));
		}
	}
}
コード例 #14
0
ファイル: exptable.c プロジェクト: ChristineJost/M2
exponent_table *exponent_table_new(int hint,
                                   int nvars)
{
  exponent_table *result;
  NEW(result);
  result->nvars = nvars;
  result->table = Table_new(hint, exp_cmp, exp_hash);
  return result;
}
コード例 #15
0
ファイル: fgroups2.c プロジェクト: trankmichael/intro
int main( int argc, char *argv[])
{

        (void) argc;
        (void) argv;

        Table_T fpTable = Table_new( initTableSize, NULL, NULL );

        readAll( fpTable );
        printAll( fpTable);
        Table_free(&fpTable);
        return 0;
}
コード例 #16
0
ファイル: fgroups.c プロジェクト: iancross/projects
/*Function Definitions*/
int main(int argc, char** argv)
{
        Table_T ftable = Table_new(1, NULL, NULL);  
        
        if (argc == 1) {
                input(&ftable);
                print_table(&ftable);
        } else {
                fprintf(stderr, "%s: %s\n",
                        argv[0], "Could not open file for reading");
                exit(1);
        }

        Table_free(&ftable);
}
コード例 #17
0
ファイル: table.c プロジェクト: lucabol/llib
unsigned test_table() {

    Table_T tbl = Table_new(10, NULL, NULL);
    struct Test t1 = { 10, "Luca"};
    char* s1 = TestToStr(&t1);
    const char* a1 = Atom_string(s1);
    char * result;

    Table_put(tbl, a1, "Luca");
    result = (char*) Table_get(tbl, a1);
    test_assert(strcmp(result, "Luca") == 0);

    Table_free(&tbl);
    FREE(s1);
    Atom_freeAll();
    return TEST_SUCCESS;
}
コード例 #18
0
ファイル: test_table.c プロジェクト: jun0813/libamp
END_TEST


START_TEST(test_put_replace)
{
    /* New values replace old values with the same key. */

    Table_T *table = Table_new(0, cmpatom, hashatom);

    Table_put(table, (void*)0x12, (void*)0x34);
    Table_put(table, (void*)0x12, (void*)0x56);

    fail_unless( Table_length(table) == 1 );
    fail_unless( Table_get(table, (void*)0x12) == (void*)0x56);

    Table_remove(table, (void*)0x12);
    Table_free(&table);
}
コード例 #19
0
ファイル: test_table.c プロジェクト: jun0813/libamp
END_TEST


START_TEST(test_get)
{
    /* Table_get() with non-existant key returns NULL */

    Table_T *table = Table_new(0, cmpatom, hashatom);

    Table_put(table, (void*)0x12, (void*)0x34);

    fail_unless( Table_length(table) == 1 );
    fail_unless( Table_get(table, (void*)0x12) == (void*)0x34);

    /* non-existant key */
    fail_unless( Table_get(table, (void*)0x34) == NULL);

    Table_remove(table, (void*)0x12);
    Table_free(&table);
}
コード例 #20
0
ファイル: xref.c プロジェクト: ywang2014/Rookie
void xref(const char *name, FILE *fp, Table_T identifiers){
	char buf[128];
	
	if (name == NULL){
		name = "";
	}
	name = Atom_string(name);
	linenum = 1;
	while (getword(fp, buf, sizeof(buf), first, rest)){
		Set_T set;
		Table_T files;
		const char *id = Atom_string(buf);
		
		// files <- file table in identifiers associated with id 
		files = Table_get(identifiers, id);
		if (files == NULL){
			files = Table_new(0, NULL, NULL);
			Table_put(identifiers, id, files);
		}
		
		
		// set <- set in files associated with name 
		set = Table_get(files, name);
		if (set == NULL){
			set = Set_new(0, intcmp, inthash);
			Table_put(files, name, set);
		}
		
		
		// add linenum to set, if necessary 
		{
			int *p = &linenum;
			if (!Set_member(set, p)){
				NEW(p);
				*p = linenum;
				Set_put(set, p);
			}
		}
	}
}
コード例 #21
0
ファイル: test_table.c プロジェクト: jun0813/libamp
END_TEST


START_TEST(test_put_in_same_bucket)
{
    /* Our hash function always places key/vals in the same bucket -
     * assert that multiple items can be placed and retreived from
     * the same bucket */

    Table_T *table = Table_new(0, cmpatom, hashatom);

    Table_put(table, (void*)0x12, (void*)0x34);
    Table_put(table, (void*)0x56, (void*)0x78);

    fail_unless( Table_length(table) == 2 );
    fail_unless( Table_get(table, (void*)0x12) == (void*)0x34);
    fail_unless( Table_get(table, (void*)0x56) == (void*)0x78);

    Table_remove(table, (void*)0x12);
    Table_remove(table, (void*)0x56);
    Table_free(&table);
}
コード例 #22
0
ファイル: OepClient.c プロジェクト: navicore/oescript_c
T OepClient_new(Oed_Dispatcher dispatcher,
                OeNet net, oe_scalar username,
                oe_scalar pwd, char *spec) {

    assert(dispatcher);
    Arena_T arena = Arena_new();
    T _this_;
    _this_ = Arena_calloc(arena, 1, sizeof *_this_, __FILE__, __LINE__);
    _this_->arena = arena;
    _this_->dispatcher = dispatcher;
    _this_->pending = Table_new(100, cidcmp, cidhash);
    _this_->spec = spec;
    Subject s = Subject_new(arena);
    _this_->subject = s;
    Subject_set_username(s, username);
    Subject_set_pwd(s, pwd);

    OeNet_set_read_handler(net, _buffered_on_read);
    _this_->net = net;
    OeNet_set_proto(net, _this_);
    assert(_this_->net);

    return _this_;
}
コード例 #23
0
ファイル: gmapindex.c プロジェクト: fabiocpn/GMAP-GSNAP
static void
write_contig_file (char *genomesubdir, char *fileroot, Table_T accsegmentpos_table, 
		   Tableint_T chrlength_table, List_T contigtypelist) {
  FILE *textfp;
  char *textfile, *iitfile, *annot;
  int naccessions, i;
  char **accessions, *divstring;
  Segmentpos_T segmentpos;
  Chrom_T chrom;
  Genomicpos_T chroffset, universalpos1, universalpos2;
  List_T divlist = NULL, intervallist = NULL, labellist = NULL, annotlist = NULL, p;
  Table_T intervaltable, labeltable, annottable;
  Interval_T interval;
#if 0
  void **keys;
  int *values, ntypes;
#endif
  
  if (divsort == NO_SORT) {
    accessions = (char **) Table_keys_by_timeindex(accsegmentpos_table,NULL);
    naccessions = Table_length(accsegmentpos_table);
  } else {
    /* Get accessions in order */
    accessions = (char **) Table_keys(accsegmentpos_table,NULL);
    naccessions = Table_length(accsegmentpos_table);
    current_accsegmentpos_table = accsegmentpos_table;
    qsort(accessions,naccessions,sizeof(char *),bysegmentpos_compare);
  }

#if 0
  /* Get types in order */
  keys = Tableint_keys(contigtype_table,NULL);
  values = Tableint_values(contigtype_table,0);
  ntypes = Tableint_length(contigtype_table);
  contigtypes = (char **) CALLOC(ntypes+1,sizeof(char *)); /* Add 1 for type 0 */
  contigtypes[0] = "";
  for (j = 0; j < ntypes; j++) {
    contigtypes[values[j]] = keys[j];
  }
  FREE(values);
  FREE(keys);
#endif

  /* Write contig text file */
  textfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
			     strlen(fileroot)+strlen(".contig")+1,sizeof(char));
  sprintf(textfile,"%s/%s.contig",genomesubdir,fileroot);
  /* Use binary, not text, so files are Unix-compatible */
  if ((textfp = FOPEN_WRITE_BINARY(textfile)) == NULL) {
    fprintf(stderr,"Can't write to file %s\n",textfile);
    exit(9);
  }
  FREE(textfile);

  for (i = 0; i < naccessions; i++) {
    segmentpos = (Segmentpos_T) Table_get(accsegmentpos_table,(void *) accessions[i]);
    chrom = Segmentpos_chrom(segmentpos);
    chroffset = (Genomicpos_T) Tableint_get(chrlength_table,chrom);
    universalpos1 = chroffset + Segmentpos_chrpos1(segmentpos);
    universalpos2 = chroffset + Segmentpos_chrpos2(segmentpos);

    /* Print as 1-based, inclusive [a,b] */
    if (Segmentpos_revcompp(segmentpos) == true) {
      fprintf(textfp,"%s\t%u..%u\t%s:%u..%u\t%u",
	      accessions[i],universalpos2+1U,universalpos1,
	      Chrom_string(chrom),Segmentpos_chrpos2(segmentpos)+1U,Segmentpos_chrpos1(segmentpos),
	      Segmentpos_length(segmentpos));
    } else {
      fprintf(textfp,"%s\t%u..%u\t%s:%u..%u\t%u",
	      accessions[i],universalpos1+1U,universalpos2,
	      Chrom_string(chrom),Segmentpos_chrpos1(segmentpos)+1U,Segmentpos_chrpos2(segmentpos),
	      Segmentpos_length(segmentpos));
    }
#if 0
    if (Segmentpos_type(segmentpos) > 0) {
      fprintf(textfp,"\t%s",contigtypes[Segmentpos_type(segmentpos)]);
    }
#endif

    fprintf(textfp,"\n");

    /* Store as 0-based, inclusive [a,b] */
    labellist = List_push(labellist,(void *) accessions[i]);
    if (Segmentpos_revcompp(segmentpos) == true) {
      /* The negative sign in the interval is the indication that the
	 contig was reverse complement */
      intervallist = List_push(intervallist, 
			       (void *) Interval_new(universalpos2-1U,universalpos1,
						     Segmentpos_type(segmentpos)));
    } else {
      intervallist = List_push(intervallist, 
			       (void *) Interval_new(universalpos1,universalpos2-1U,
						     Segmentpos_type(segmentpos)));
    }

#if 0
    /* IIT version 1 */
    sprintf(seglength,"%u",Segmentpos_length(segmentpos));
    annot = (char *) CALLOC(strlen(seglength)+1,sizeof(char));
    strcpy(annot,seglength);
#else
    /* IIT versions >= 2 */
    annot = (char *) CALLOC(1,sizeof(char));
    annot[0] = '\0';
#endif
    annotlist = List_push(annotlist,(void *) annot);

  }
  fclose(textfp);

#if 0
  FREE(contigtypes);
#endif
  FREE(accessions);
  intervallist = List_reverse(intervallist);
  /* contigtypelist = List_reverse(contigtypelist); -- Done by caller */ 
  labellist = List_reverse(labellist);
  annotlist = List_reverse(annotlist);

  /* Write contig IIT file */
  divstring = (char *) CALLOC(1,sizeof(char));
  divstring[0] = '\0';
  divlist = List_push(NULL,divstring);

  intervaltable = Table_new(65522,Table_string_compare,Table_string_hash);
  labeltable = Table_new(65522,Table_string_compare,Table_string_hash);
  annottable = Table_new(65522,Table_string_compare,Table_string_hash);

  Table_put(intervaltable,(void *) divstring,intervallist);
  Table_put(labeltable,(void *) divstring,labellist);
  Table_put(annottable,(void *) divstring,annotlist);

  iitfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
			    strlen(fileroot)+strlen(".contig.iit")+1,sizeof(char));
  sprintf(iitfile,"%s/%s.contig.iit",genomesubdir,fileroot);

#if 0
  debug(
	for (p = contigtypelist; p != NULL; p = List_next(p)) {
	  printf("Type %s\n",(char *) List_head(p));
	}
	);
コード例 #24
0
ファイル: fgroups.joe.c プロジェクト: paultreny/comp40
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;
}
コード例 #25
0
ファイル: gmapindex.c プロジェクト: fabiocpn/GMAP-GSNAP
/* Modifies chrlength_table to store offsets, rather than chrlengths */
static void
write_chromosome_file (char *genomesubdir, char *fileroot, Tableint_T chrlength_table) {
  FILE *textfp, *chrsubsetfp;
  char *divstring, *textfile, *chrsubsetfile, *iitfile, *chr_string, emptystring[1];
  int n, i;
  Chrom_T *chroms;
  Genomicpos_T chroffset = 0, chrlength;
  List_T divlist = NULL;
  List_T intervallist = NULL, chrtypelist = NULL, labellist = NULL, annotlist = NULL, p;
  Table_T intervaltable, labeltable, annottable;
  Interval_T interval;

  emptystring[0] = '\0';

  if (divsort == NO_SORT) {
    chroms = (Chrom_T *) Tableint_keys_by_timeindex(chrlength_table,0U);
    n = Tableint_length(chrlength_table);
  } else {
    /* Get chromosomes in order */
    chroms = (Chrom_T *) Tableint_keys(chrlength_table,0U);
    n = Tableint_length(chrlength_table);
    switch (divsort) {
    case ALPHA_SORT: qsort(chroms,n,sizeof(Chrom_T),Chrom_compare_alpha); break;
    case NUMERIC_ALPHA_SORT: qsort(chroms,n,sizeof(Chrom_T),Chrom_compare_numeric_alpha); break;
    case CHROM_SORT: qsort(chroms,n,sizeof(Chrom_T),Chrom_compare_chrom); break;
    default: abort();
    }
  }

  /* Write chromosome text file and chrsubset file */
  textfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
			     strlen(fileroot)+strlen(".chromosome")+1,sizeof(char));
  sprintf(textfile,"%s/%s.chromosome",genomesubdir,fileroot);
  /* Use binary, not text, so files are Unix-compatible */
  if ((textfp = FOPEN_WRITE_BINARY(textfile)) == NULL) {
    fprintf(stderr,"Can't write to file %s\n",textfile);
    exit(9);
  }
  FREE(textfile);

  chrsubsetfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
				  strlen(fileroot)+strlen(".chrsubset")+1,sizeof(char));
  sprintf(chrsubsetfile,"%s/%s.chrsubset",genomesubdir,fileroot);
  /* Use binary, not text, so files are Unix-compatible */
  if ((chrsubsetfp = FOPEN_WRITE_BINARY(chrsubsetfile)) == NULL) {
    fprintf(stderr,"Can't write to file %s\n",chrsubsetfile);
    exit(9);
  }
  FREE(chrsubsetfile);
  fprintf(chrsubsetfp,">all\n");
  fprintf(chrsubsetfp,"\n");

  chrtypelist = List_push(chrtypelist,"");
  for (i = 0; i < n; i++) {
    chrlength = (Genomicpos_T) Tableint_get(chrlength_table,chroms[i]);
    assert(chroffset <= chroffset+chrlength-1);
    chr_string = Chrom_string(chroms[i]);
    if (i < 100) {
      fprintf(stderr,"Chromosome %s has universal coordinates %u..%u\n",
	      chr_string,chroffset+1,chroffset+1+chrlength-1);
    } else if (i == 100) {
      fprintf(stderr,"More than 100 contigs.  Will stop printing messages\n");
    }
      
    if (n <= 100) {
      fprintf(chrsubsetfp,">%s\n",chr_string);
      fprintf(chrsubsetfp,"+%s\n",chr_string);
    }

    fprintf(textfp,"%s\t%u..%u\t%u\n",
	    chr_string,chroffset+1,chroffset+chrlength,chrlength);
    intervallist = List_push(intervallist,(void *) Interval_new(chroffset,chroffset+chrlength-1U,0));
    labellist = List_push(labellist,(void *) chr_string);
    annotlist = List_push(annotlist,(void *) emptystring); /* No annotations */
    Tableint_put(chrlength_table,chroms[i],chroffset);
    chroffset += chrlength;
  }
  FREE(chroms);
  intervallist = List_reverse(intervallist);
  labellist = List_reverse(labellist);

  fclose(chrsubsetfp);
  fclose(textfp);

  /* Write chromosome IIT file */
  divstring = (char *) CALLOC(1,sizeof(char));
  divstring[0] = '\0';
  divlist = List_push(NULL,divstring);

  intervaltable = Table_new(65522,Table_string_compare,Table_string_hash);
  labeltable = Table_new(65522,Table_string_compare,Table_string_hash);
  annottable = Table_new(65522,Table_string_compare,Table_string_hash);

  Table_put(intervaltable,(void *) divstring,intervallist);
  Table_put(labeltable,(void *) divstring,labellist);
  Table_put(annottable,(void *) divstring,annotlist);

  iitfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+
			    strlen(fileroot)+strlen(".chromosome.iit")+1,sizeof(char));
  sprintf(iitfile,"%s/%s.chromosome.iit",genomesubdir,fileroot);
  IIT_write(iitfile,divlist,chrtypelist,/*fieldlist*/(List_T) NULL,
	    intervaltable,labeltable,annottable,divsort,
	    /*version, use 1 for backward compatibility*/1,
	    /*label_pointers_8p*/false,/*annot_pointers_8p*/false);
  FREE(iitfile);

  List_free(&divlist);
  FREE(divstring);

  Table_free(&annottable);
  Table_free(&labeltable);
  Table_free(&intervaltable);

  List_free(&annotlist);

  /* Do not free strings in labellist, since they are not allocated */
  List_free(&labellist);

  /* chrtypelist has no dynamically allocated strings */
  List_free(&chrtypelist);

  for (p = intervallist; p != NULL; p = List_next(p)) {
    interval = (Interval_T) List_head(p);
    Interval_free(&interval);
  }
  List_free(&intervallist);

  return;
}