Пример #1
0
int main() 
{
    struct avl_table *avltree;
    struct bst_table *bsttree;
    struct rb_table *rbtree;

    avltree = avl_create(Compare_by_lexicographical_order, NULL, NULL);
    bsttree = bst_create(Compare_by_lexicographical_order, NULL, NULL);
    rbtree = rb_create(Compare_by_lexicographical_order, NULL, NULL);

    for (int i = 0; i < 32; i++)
    {
        struct word *element = 
            (struct word *)malloc(sizeof(struct word));

        ReadWord(element);

#ifdef DEBUG
        printf("Read in word: %s, length = %d\n", element->s, element->length);
#endif

        avl_probe(avltree, element);
        bst_probe(bsttree, element);
        rb_probe(rbtree, element);
    }

    preorder_avl(avltree->avl_root); puts("");
    preorder_bst(bsttree->bst_root); puts("");
    preorder_rb(rbtree->rb_root); puts("");
    return 0;
}
Пример #2
0
/* Inserts ITEM into TREE.	Returns NULL if the item was inserted,
	 otherwise a pointer to the duplicate item. */
void *avl_insert(avl_tree_t * tree, void *item)
{
	void **p;

	p = avl_probe(tree, item);
	return (*p == item) ? NULL : *p;
}
Пример #3
0
int main() {
	struct avl_table* avl_tree;
	struct bst_table* bst_tree;
	struct rb_table* rb_tree;
	char* input_str[STR_NUM];
	char buf[BUF_SIZE];
	void** p[3];
	int str_length;
	
	avl_tree = avl_create( str_cmp , NULL, NULL) ;
	bst_tree = bst_create( str_cmp, NULL , NULL);
	rb_tree = rb_create(str_cmp, NULL , NULL);
	
	// input string
	for(int i=0;i<STR_NUM;i++){
		if(fgets(buf, BUF_SIZE , stdin)!= NULL) {
			str_length = strlen(buf)-1;
			input_str[i] = malloc(str_length*sizeof(char));
			strncpy(input_str[i],buf,str_length);
			//printf("%s\n",input_str[i]);
			p[0] = avl_probe( avl_tree , input_str[i]);
			p[1] = bst_probe( bst_tree , input_str[i]);
			p[2] = rb_probe( rb_tree , input_str[i]);
		}
	}
	print_avl(avl_tree->avl_root);
	printf("\n");
	print_bst(bst_tree->bst_root);
	printf("\n");
	print_rb(rb_tree->rb_root);
	printf("\n");
	return 0;
}
Пример #4
0
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int p;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &p);
		tree[i] = avl_create(comp, NULL, NULL);
		avl_probe(tree[i], p);
		par[i] = own[i] = i;
		rank[i] = 0;
	}

	int c, i, j;
	Price s;
	for (int k = 1; k <= m; k++) {
		scanf("%d", &c);
		if (c == 1) {
			scanf("%d%d", &i, &j);
			int set1 = find(i), set2 = find(j);
			if (set1 != set2) merge_set(set1, set2);
		}
		else { // c == 2
			scanf("%d%lld", &i, &s);
			int set = find(i);
			int k = K(tree[set]->avl_root, s);
			printf("%d %d\n", own[set], k);
		}
	}
}
Пример #5
0
static void ttf_copy_encoding(void)
{
    int i, *q;
    void **aa;
    char **glyph_names;
    long *charcodes;
    static char buf[SMALL_BUF_SIZE];
    struct avl_traverser t;
    ttfenc_entry *e = ttfenc_tab;

    assert(fd_cur->tx_tree != NULL);    /* this must be set in create_fontdictionary */

    if (fd_cur->fe != NULL) {
        glyph_names = fd_cur->fe->glyph_names;
        assert(glyph_names != NULL);

        for (i = 0; i < 256; i++)
            ttfenc_tab[i].name = notdef;

        /* a workaround for a bug of AcroReader 4.0 */
        if (strcmp(glyph_names[97], "a") == 0) {
            q = xtalloc(1, int);
            *q = 'a';
            aa = avl_probe(fd_cur->tx_tree, q);
            assert(aa != NULL);
        }
Пример #6
0
void merge(Tree *t, Node *node) {
	if (node == NULL) return;
	for (int i = 0; i < node->avl_cnt; i++)
		avl_probe(t, node->avl_data);
	merge(t, node->left);
	merge(t, node->right);
	free(node);
}
Пример #7
0
Файл: avl.c Проект: cran/foreign
/* Inserts ITEM into TREE.  Returns NULL if the item was inserted,
   otherwise a pointer to the duplicate item. */
void *
R_avl_insert (avl_tree *tree, void *item)
{
  void **p;

  if (!(tree != NULL)) error("assert failed : tree != NULL");

  p = avl_probe (tree, item);
  return (*p == item) ? NULL : *p;
}
Пример #8
0
/* Inserts ITEM into TREE.  Returns NULL if the item was inserted,
   otherwise a pointer to the duplicate item. */
void *
avl_insert (avl_tree *tree, void *item)
{
  void **p;
  
  assert (tree != NULL);
  
  p = avl_probe (tree, item);
  return (*p == item) ? NULL : *p;
}
Пример #9
0
/* Inserts |item| into |table|, replacing any duplicate item.
   Returns |NULL| if |item| was inserted without replacing a duplicate,
   or if a memory allocation error occurred.
   Otherwise, returns the item that was replaced. */
void *avl_replace(struct avl_table *table, void *item)
{
    void **p = avl_probe(table, item);
    if (p == NULL || *p == item)
        return NULL;
    else {
        void *r = *p;
        *p = item;
        return r;
    }
}
Пример #10
0
void register_fd_entry(fd_entry * fd)
{
    void **aa;
    if (fd_tree == NULL) {
        fd_tree = avl_create(comp_fd_entry, NULL, &avl_xallocator);
        assert(fd_tree != NULL);
    }
    assert(fd != NULL && fd->fm != NULL && is_fontfile(fd->fm));
    assert(lookup_fd_entry(fd->fm->ff_name, fd->fm->slant, fd->fm->extend) == NULL);    /* font descriptor not yet registered */
    aa = avl_probe(fd_tree, fd);
    assert(aa != NULL);
}
Пример #11
0
/* If ITEM does not exist in TREE, inserts it and returns NULL.	If a
	 matching item does exist, it is replaced by ITEM and the item
	 replaced is returned.	The caller is responsible for freeing the
	 item returned. */
void *avl_replace(avl_tree_t * tree, void *item)
{
	void **p;

	p = avl_probe(tree, item);
	if (*p == item) return NULL;
	else {
		void *r = *p;
		*p = item;
		return r;
	}
}
Пример #12
0
void add_table( Table* table, const intptr_t cle, intptr_t valeur ) {
    Table_association* asso = creer_table_association(table, cle, valeur);
    void* val = avl_probe ( table->root, (void*) asso );
    if( val == NULL ) {
        ERREUR( "Espace insuffisant" );
    }
    Table_association* asso_tree = *( Table_association** ) val;
    if( asso_tree != asso  ) {
        supprimer_table_association( asso );
        asso_tree->valeur = valeur;
    }
}
Пример #13
0
void register_fe_entry(fe_entry * fe)
{
    void **aa;
    if (fe_tree == NULL) {
        fe_tree = avl_create(comp_fe_entry, NULL, &avl_xallocator);
        assert(fe_tree != NULL);
    }
    assert(fe != NULL);
    assert(fe->name != NULL);
    assert(lookup_fe_entry(fe->name) == NULL);  /* encoding not yet registered */
    aa = avl_probe(fe_tree, fe);
    assert(aa != NULL);
}
Пример #14
0
char *add_encname(char *s)
{
    char *p;
    void **aa;
    assert(s != NULL);
    assert(encname_tree != NULL);
    if ((p = (char *) avl_find(encname_tree, s)) == NULL) {     /* encoding name not yet registered */
        p = xstrdup(s);
        aa = avl_probe(encname_tree, p);
        assert(aa != NULL);
    }
    return p;
}
Пример #15
0
/* Attempts to insert |item| into |tree|.
   If |item| is inserted successfully, it is returned and |trav| is
   initialized to its location.
   If a duplicate is found, it is returned and |trav| is initialized to
   its location.  No replacement of the item occurs.
   If a memory allocation failure occurs, |NULL| is returned and |trav|
   is initialized to the null item. */
void *avl_t_insert(struct avl_traverser *trav, struct avl_table *tree,
                   void *item)
{
    void **p;

    assert(trav != NULL && tree != NULL && item != NULL);

    p = avl_probe(tree, item);
    if (p != NULL) {
        trav->avl_table = tree;
        trav->avl_node = ((struct avl_node *)
                          ((char *) p - offsetof(struct avl_node, avl_data)));
        trav->avl_generation = tree->avl_generation - 1;
        return *p;
    } else {
Пример #16
0
Файл: avl.c Проект: cran/foreign
/* If ITEM does not exist in TREE, inserts it and returns NULL.  If a
   matching item does exist, it is replaced by ITEM and the item
   replaced is returned.  The caller is responsible for freeing the
   item returned. */
void *
R_avl_replace (avl_tree *tree, void *item)
{
  void **p;

  if (!(tree != NULL)) error("assert failed : tree != NULL");

  p = avl_probe (tree, item);
  if (*p == item)
    return NULL;
  else
    {
      void *r = *p;
      *p = item;
      return r;
    }
}
Пример #17
0
static struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
                             internalfontnumber f)
{
    int i, *j;
    void **aa;
    if (tx_tree == NULL) {
        tx_tree = avl_create(comp_int_entry, NULL, &avl_xallocator);
        assert(tx_tree != NULL);
    }
    for (i = fo->first_char; i <= fo->last_char; i++) {
        if (pdfcharmarked(f, i) && (int *) avl_find(tx_tree, &i) == NULL) {
            j = xtalloc(1, int);
            *j = i;
            aa = avl_probe(tx_tree, j);
            assert(aa != NULL);
        }
    }
Пример #18
0
void epdf_mark_glyphs(fd_entry * fd, char *charset)
{
    char *p, *q, *s;
    char *glyph;
    void **aa;
    if (charset == NULL)
        return;
    assert(fd != NULL);
    for (s = charset + 1, q = charset + strlen(charset); s < q; s = p + 1) {
        for (p = s; *p != '\0' && *p != '/'; p++);
        *p = '\0';
        if ((char *) avl_find(fd->gl_tree, s) == NULL) {
            glyph = xstrdup(s);
            aa = avl_probe(fd->gl_tree, glyph);
            assert(aa != NULL);
        }
    }
}
Пример #19
0
static void mark_reenc_glyphs(fo_entry * fo, internalfontnumber f)
{
    int i;
    char **g;
    void **aa;
    assert(fo->fe != NULL);
    if (is_subsetted(fo->fm)) {
        assert(is_included(fo->fm));
        /* mark glyphs from TeX (externally reencoded characters) */
        g = fo->fe->glyph_names;
        for (i = fo->first_char; i <= fo->last_char; i++) {
            if (pdfcharmarked(f, i) && g[i] != notdef
                && (char *) avl_find(fo->fd->gl_tree, g[i]) == NULL) {
                aa = avl_probe(fo->fd->gl_tree, xstrdup(g[i]));
                assert(aa != NULL);
            }
        }
    }
}
Пример #20
0
ff_entry *check_ff_exist(char *ff_name, boolean is_tt)
{
    ff_entry *ff;
    ff_entry tmp;
    void **aa;
    int callback_id;
	char *filepath=NULL;

    assert(ff_name != NULL);
    tmp.ff_name = ff_name;
    ff = (ff_entry *) avl_find(ff_tree, &tmp);
    if (ff == NULL) {           /* not yet in database */
        ff = new_ff_entry();
        ff->ff_name = xstrdup(ff_name);
        if (is_tt) {
           callback_id=callback_defined(find_truetype_file_callback);
           if (callback_id>0) {
             run_callback(callback_id,"S->S",ff_name,&filepath);
                 if (filepath && strlen(filepath)==0)
                       filepath=NULL;
             ff->ff_path = filepath;
           } else {
             ff->ff_path = kpse_find_file (ff_name, kpse_truetype_format, 0);
           }
		}
		else {
		  callback_id=callback_defined(find_type1_file_callback);
		  if (callback_id>0) {
			run_callback(callback_id,"S->S",ff_name,&filepath);
			if (filepath && strlen(filepath)==0)
			  filepath=NULL;
			ff->ff_path = filepath;
		  } else {
			ff->ff_path = kpse_find_file (ff_name, kpse_type1_format, 0);
		  }
		}
        aa = avl_probe(ff_tree, ff);
        assert(aa != NULL);
    }
    return ff;
}
Пример #21
0
ff_entry *check_ff_exist(char *ff_name, boolean is_tt)
{
    ff_entry *ff;
    ff_entry tmp;
    void **aa;

    assert(ff_name != NULL);
    tmp.ff_name = ff_name;
    ff = (ff_entry *) avl_find(ff_tree, &tmp);
    if (ff == NULL) {           /* not yet in database */
        ff = new_ff_entry();
        ff->ff_name = xstrdup(ff_name);
        if (is_tt)
            ff->ff_path = kpse_find_file(ff_name, kpse_truetype_format, 0);
        else
            ff->ff_path = kpse_find_file(ff_name, kpse_type1_format, 0);
        aa = avl_probe(ff_tree, ff);
        assert(aa != NULL);
    }
    return ff;
}
Пример #22
0
struct page *pagetable_insert(addr_t vaddr, char type) {
	struct page *newpage = malloc(sizeof(struct page));
	newpage->vaddr = vaddr;
	newpage->type = type;
	newpage->pframe = -1;

	void **p = avl_probe(avl_tree, newpage);
	if (p == NULL) {
		if (debug >= 0)
			printf ("    Out of memory in insertion.\n");
		avl_destroy (avl_tree, NULL);
		exit(1);
	}
	
	if (*p != newpage && debug) {
		printf ("    Duplicate item in tree!\n");
	}
	if(*p != newpage) {
		free(newpage);
	}
	return (struct page *)*p;
}
Пример #23
0
void deftounicode(strnumber glyph, strnumber unistr)
{
    char buf[SMALL_BUF_SIZE], *p;
    char buf2[SMALL_BUF_SIZE], *q;
    int valid_unistr;           /* 0: invalid; 1: unicode value; 2: string */
    int i, l;
    glyph_unicode_entry *gu, t;
    void **aa;

    p = makecstring(glyph);
    assert(strlen(p) < SMALL_BUF_SIZE);
    strcpy(buf, p);             /* copy the result to buf before next call of makecstring() */
    p = makecstring(unistr);
    while (*p == ' ')
        p++;                    /* ignore leading spaces */
    l = strlen(p);
    while (l > 0 && p[l - 1] == ' ')
        l--;                    /* ignore traling spaces */
    valid_unistr = 1;           /* a unicode value is the most common case */
    for (i = 0; i < l; i++) {
        if (p[i] == ' ')
            valid_unistr = 2;   /* if a space occurs we treat this entry as a string */
        else if (!isXdigit(p[i])) {
            valid_unistr = 0;
            break;
        }
    }
    if (l == 0 || valid_unistr == 0 || strlen(buf) == 0
        || strcmp(buf, notdef) == 0) {
        pdftex_warn("ToUnicode: invalid parameter(s): `%s' => `%s'", buf, p);
        return;
    }
    if (glyph_unicode_tree == NULL) {
        glyph_unicode_tree =
            avl_create(comp_glyph_unicode_entry, NULL, &avl_xallocator);
        assert(glyph_unicode_tree != NULL);
    }
    t.name = buf;
    /* allow overriding existing entries */
    if ((gu = (glyph_unicode_entry *) avl_find(glyph_unicode_tree, &t)) != NULL) {
        if (gu->code == UNI_STRING) {
            assert(gu->unicode_seq != NULL);
            xfree(gu->unicode_seq);
        }
    } else {                    /* make new entry */
        gu = new_glyph_unicode_entry();
        gu->name = xstrdup(buf);
    }
    if (valid_unistr == 2) {    /* a string with space(s) */
        /* copy p to buf2, ignoring spaces */
        for (q = buf2; *p != 0; p++)
            if (*p != ' ')
                *q++ = *p;
        *q = 0;
        gu->code = UNI_STRING;
        gu->unicode_seq = xstrdup(buf2);
    } else {
        i = sscanf(p, "%lX", &(gu->code));
        assert(i == 1);
    }
    aa = avl_probe(glyph_unicode_tree, gu);
    assert(aa != NULL);
}
Пример #24
0
/* Inserts |item| into |table|.
   Returns |NULL| if |item| was successfully inserted
   or if a memory allocation error occurred.
   Otherwise, returns the duplicate item. */
void *
avl_insert (struct avl_table *table, void *item)
{
  void **p = avl_probe (table, item);
  return p == NULL || *p == item ? NULL : *p;
}
Пример #25
0
static sfd_entry *read_sfd (char *sfd_name)
{
    void **aa;
    sfd_entry *sfd, tmp_sfd;
    subfont_entry *sf;
	char *ftemp = NULL;
    char buf[SMALL_BUF_SIZE], *p;
    long int i, j, k;
    int n;
    int callback_id=0;
    int file_opened=0;
    /* check whether this sfd has been read */
    tmp_sfd.name = sfd_name;
    if (sfd_tree == NULL) {
        sfd_tree = avl_create (comp_sfd_entry, NULL, &avl_xallocator);
        assert (sfd_tree != NULL);
    }
    sfd = (sfd_entry *) avl_find (sfd_tree, &tmp_sfd);
    if (sfd != NULL)
        return sfd;
    set_cur_file_name (sfd_name);
    if (sfd_buffer!=NULL) {
      xfree(sfd_buffer);
      sfd_buffer=NULL;
    }
    sfd_curbyte=0;
    sfd_size=0;

	callback_id=callback_defined(find_sfd_file_callback);
	if (callback_id>0) {
	  if(run_callback(callback_id,"S->S",cur_file_name,&ftemp)) {
		if(ftemp!=NULL&&strlen(ftemp)) {
		  if (cur_file_name)
			free(cur_file_name);
		  cur_file_name = xstrdup(ftemp);
		  free(ftemp);
		}
	  }
	}
    callback_id=callback_defined(read_sfd_file_callback);
    if (callback_id>0) {
      if(! (run_callback(callback_id,"S->bSd",cur_file_name,
		       &file_opened, &sfd_buffer,&sfd_size) &&
	    file_opened && 
	    sfd_size>0 ) ) {
	pdftex_warn ("cannot open SFD file for reading");
	cur_file_name = NULL;
	return NULL;      
      }
      sfd_read_file();
      sfd_close();
    }
    tex_printf ("{");
    tex_printf (cur_file_name);
    sfd = new_sfd_entry ();
    sfd->name = xstrdup (sfd_name);
    while (!sfd_eof ()) {
        sfd_getline (true);
        if (*sfd_line == 10)    /* empty line indicating eof */
            break;
        sf = new_subfont_entry ();
        sf->next = sfd->subfont;
        sfd->subfont = sf;
        sscanf (sfd_line, "%s %n", buf, &n);
        sf->infix = xstrdup (buf);
        p = sfd_line + n;       /* skip to the next word */
        k = 0;
      read_ranges:
        for (;;) {
            if (*p == '\\') {   /* continue on next line */
                sfd_getline (false);
                p = sfd_line;
                goto read_ranges;
            } else if (*p == 0) /* end of subfont */
                break;
            if (sscanf (p, " %li %n", &i, &n) == 0)
                pdftex_fail ("invalid token:\n%s", p);
            p += n;
            if (*p == ':') {    /* offset */
                k = i;
                p++;
            } else if (*p == '_') {     /* range */
                if (sscanf (p + 1, " %li %n", &j, &n) == 0)
                    pdftex_fail ("invalid token:\n%s", p);
                if (i > j || k + (j - i) > 255)
                    pdftex_fail ("invalid range:\n%s", p);
                while (i <= j)
                    sf->charcodes[k++] = i++;
                p += n + 1;
            } else              /* codepoint */
                sf->charcodes[k++] = i;
        }
    }
    tex_printf ("}");
    aa = avl_probe (sfd_tree, sfd);
    assert (aa != NULL);
    return sfd;
}
Пример #26
0
int main (int argc, const char * argv[])
{
  FILE							*inFile,
  *mapFile;
  
  struct	bufferedString			**currentBuffers;
  
  struct  storedNameTag			*aTag,
  *aTag2;
  
  char	automatonState			= 0,
  currentField			= 0,
  currentChar				= 0,
  line_buffer       [MAX_LINE_BUFFER];
  
  long	currentLineID			= 1,
  expectedFields			= 2,
  mappedID				,
  indexer;
  
  size_t  current_buffer_index    = 0L,
  current_buffer_size     = 0L;
  
  
 
  globalNameBuffer = allocateNewString();
  globalTagBuffer	 = allocateNewBufferedTag();
  
  currentBuffers   = (struct	bufferedString**)malloc (expectedFields*sizeof (struct	bufferedString*));
  nameTagAVL		 = avl_create (compare_tags, NULL, NULL);
  
  for (indexer = 0; indexer < expectedFields; indexer++)
    currentBuffers[indexer] = allocateNewString();
  
		
  if (argc != 3)
  {
    fprintf (stderr,"%s\n", UsageString);
    return 1;
  }
		
  inFile		= fopen (argv[1], "rb");
  
  if (!inFile)
  {
	   fprintf (stderr,"Failed to open input file: %s\n", argv[1]);
	   return 1;
  }
  
  mapFile		= fopen (argv[2], "rb");
  
  if (!mapFile)
  {
	   fprintf (stderr,"Failed to open gid-taxid map file: %s\n", argv[2]);
	   return 1;
  }
  
  for (indexer = 0; indexer < 256; indexer ++) {
    digits [indexer] = 0;
  }
  
  for (indexer = (long)'0'; indexer <= (long)'9'; indexer ++) {
    digits [indexer] = 1;
  }
  
  for (;;) {
    if (current_buffer_index >= current_buffer_size) {
      current_buffer_size = fread (line_buffer, 1L, MAX_LINE_BUFFER, inFile);
      if (current_buffer_size == 0L) {
        break;
      }
      current_buffer_index = 1L;
      currentChar = line_buffer[0];
    } else {
      currentChar = line_buffer[current_buffer_index++];
    }
  
    switch (automatonState)
    {
      case 0: /* start of the line; expecting numbers */
        if (digits[currentChar])
        {
          automatonState = 1; /* reading sequence ID */
          appendCharacterToString(currentBuffers[currentField],currentChar);
        }
        else
          if (!(currentChar == '\n' || currentChar == '\r'))
            reportErrorLine ("Could not find a valid sequence ID to start the line",currentLineID);
        break;
        
      case 1: /* reading file ID */
        if (currentChar >= '0' && currentChar <='9')
          appendCharacterToString(currentBuffers[currentField],currentChar);
        else
          if (currentChar == '\t')
          {
            currentField ++;
            automatonState = 2;
            /* reading file ID */
          }
          else
            reportErrorLine ("Expected a tab following the gi ID",currentLineID);
        break;
        
      case 2: /* read a field */
        if (isalnum(currentChar) || currentChar == '/' || currentChar == '.' || currentChar == '_' || currentChar == '-')
          appendCharacterToString(currentBuffers[currentField],currentChar);
        else
          if (currentChar == '\n' || currentChar == '\r')
          {
            automatonState = 0;
            currentLineID ++;
            currentField = 0;
            
            aTag			 = allocateNameTag();
            aTag->taxID      = atoi(currentBuffers[0]->sData);
            aTag->startIndex = globalNameBuffer->sLength;
            aTag->length	 = appendRangeToString(globalNameBuffer,currentBuffers[1],0,currentBuffers[1]->sLength-1);
            
            appendTagToBuffer (globalTagBuffer, aTag->taxID, aTag->startIndex, aTag->length);
            
            if (aTag->length <= 0)
              reportErrorLine ("Empty name tag",currentLineID);
            if (*avl_probe(nameTagAVL,aTag) != aTag)
            {
              free			(aTag);
                //reportErrorLine ("Duplicate name tag",currentLineID);
            }
            for (indexer = 0; indexer < expectedFields; indexer++)
              clear_buffered_string(currentBuffers[indexer]);
          }
          else
            reportErrorLine ("Unexpected character",currentLineID);
        break;
        
        
    }
  }
  
  fclose (inFile);
		
  aTag	    = allocateNameTag();
  fprintf (stderr, "Reading gid-taxid mapping file...\n");
  currentLineID = 0;
  current_buffer_index = current_buffer_size = 0L;

  for (;;) {
    if (current_buffer_index >= current_buffer_size) {
      current_buffer_size = fread (line_buffer, 1L, MAX_LINE_BUFFER, mapFile);
      if (current_buffer_size == 0L) {
        break;
      }
      current_buffer_index = 1L;
      currentChar = line_buffer[0];
    } else {
      currentChar = line_buffer[current_buffer_index++];
    }
    if (currentLineID > 1 && currentLineID % 5000000 == 0 && automatonState == 0) {
      fprintf (stderr, "Read %ld lines\n", currentLineID);
    }
    switch (automatonState)
    {
      case 0: /* start of the line; expecting numbers */
        if (currentChar >= '0' && currentChar <='9')
        {
          automatonState = 1; /* reading sequence ID */
          appendCharacterToString(currentBuffers[currentField],currentChar);
        }
        else
          if (!(currentChar == '\n' || currentChar == '\r'))
            reportErrorLine ("Could not find a valid sequence ID to start the line",currentLineID);
        break;
        
      case 1: /* reading file ID */
        if (digits[currentChar])
          appendCharacterToString(currentBuffers[currentField],currentChar);
        else
          if (currentChar == '\t')
          {
            currentField ++;
            automatonState = 2;
            /* reading file ID */
          }
          else
            reportErrorLine ("Expected a tab following the tax ID",currentLineID);
        break;
        
      case 2: /* read a field */
        if (digits[currentChar])
          appendCharacterToString(currentBuffers[currentField],currentChar);
        else
          if (currentChar == '\n' || currentChar == '\r')
          {
            automatonState = 0;
            currentLineID ++;
            currentField = 0;
            
            aTag->taxID      = atoi(currentBuffers[0]->sData);
            mappedID		 = atoi(currentBuffers[1]->sData);
            
            aTag2 = avl_find(nameTagAVL,aTag);
            if (aTag2)
              aTag2->mappedTag = mappedID;
            for (indexer = 0; indexer < expectedFields; indexer++)
              clear_buffered_string(currentBuffers[indexer]);
          }
          else
            reportErrorLine ("Unexpected character",currentLineID);
        break;
        
        
    }
  }
  
  fclose (mapFile);
  
  for (indexer = 0L; indexer < expectedFields; indexer++)
    destroy_string(currentBuffers[indexer]);
  
  free(currentBuffers);
  
  for (indexer = 0L; indexer < globalTagBuffer->sLength; indexer++) {
    aTag->taxID      = globalTagBuffer->gID[indexer];
    aTag2 = avl_find(nameTagAVL,aTag);
    if (aTag2) {
      printf ("%ld\t%ld\t", aTag->taxID,aTag2->mappedTag);
    }
    else {
      printf ("%ld\t-1\t", aTag->taxID);
    }
    for (expectedFields = globalTagBuffer->startTag[indexer]; 
         expectedFields < globalTagBuffer->startTag[indexer] + globalTagBuffer->lengthTag[indexer];
         expectedFields ++)
    {
      printf ("%c",globalNameBuffer->sData[expectedFields]);
    }
    printf ("\n");
  }
  
    //printf ("-1,NULL");
  free (aTag);
  return 0;
}
Пример #27
0
int avl_do_entry(fm_entry * fm, int mode)
{
    fm_entry *p;
    void *a;
    void **aa;

    /* handle tfm_name link */

    if (strcmp(fm->tfm_name, nontfm)) {
        p = (fm_entry *) avl_find(tfm_tree, fm);
        if (p != NULL) {
            switch (mode) {
            case FM_DUPIGNORE:
                pdftex_warn
                    ("fontmap entry for `%s' already exists, duplicates ignored",
                     fm->tfm_name);
                goto exit;
                break;
            case FM_REPLACE:
            case FM_DELETE:
                if (p->in_use) {
                    pdftex_warn
                        ("fontmap entry for `%s' has been used, replace/delete not allowed",
                         fm->tfm_name);
                    goto exit;
                }
                a = avl_delete(tfm_tree, p);
                assert(a != NULL);
                unset_tfmlink(p);
                if (!has_pslink(p))
                    delete_fm_entry(p);
                break;
            default:
                assert(0);
            }
        }
        if (mode != FM_DELETE) {
            aa = avl_probe(tfm_tree, fm);
            assert(aa != NULL);
            set_tfmlink(fm);
        }
    }

    /* handle ps_name link */

    if (fm->ps_name != NULL) {
        p = (fm_entry *) avl_find(ps_tree, fm);
        if (p != NULL) {
            switch (mode) {
            case FM_DUPIGNORE:
                goto exit;
                break;
            case FM_REPLACE:
            case FM_DELETE:
                if (p->in_use)
                    goto exit;
                a = avl_delete(ps_tree, p);
                assert(a != NULL);
                unset_pslink(p);
                if (!has_tfmlink(p))
                    delete_fm_entry(p);
                break;
            default:
                assert(0);
            }
        }
        if (mode != FM_DELETE && is_t1fontfile(fm) && is_included(fm)) {
            aa = avl_probe(ps_tree, fm);
            assert(aa != NULL);
            set_pslink(fm);
        }
    }
  exit:
    if (!has_tfmlink(fm) && !has_pslink(fm))    /* e. g. after FM_DELETE */
        return 1;               /* deallocation of fm_entry structure required */
    else
        return 0;
}