int tags_equal(fru_tag_t t1, fru_tag_t t2) { return ((get_tag_type(&t1) == get_tag_type(&t2)) && (get_tag_dense(&t1) == get_tag_dense(&t2)) && (get_payload_length(&t1) == get_payload_length(&t2))); }
/* Initializes a TMTag structure with information from a tagEntryInfo struct used by the ctags parsers. Note that the TMTag structure must be malloc()ed before calling this function. This function is called by tm_tag_new() - you should not need to call this directly. @param tag The TMTag structure to initialize @param file Pointer to a TMSourceFile struct (it is assigned to the file member) @param tag_entry Tag information gathered by the ctags parser @return TRUE on success, FALSE on failure */ static gboolean tm_tag_init(TMTag *tag, TMSourceFile *file, const tagEntryInfo *tag_entry) { tag->refcount = 1; if (NULL == tag_entry) return FALSE; /* This is a normal tag entry */ if (NULL == tag_entry->name) return FALSE; tag->name = g_strdup(tag_entry->name); tag->type = get_tag_type(tag_entry->kindName); tag->local = tag_entry->isFileScope; tag->pointerOrder = 0; /* backward compatibility (use var_type instead) */ tag->line = tag_entry->lineNumber; if (NULL != tag_entry->extensionFields.arglist) tag->arglist = g_strdup(tag_entry->extensionFields.arglist); if ((NULL != tag_entry->extensionFields.scope[1]) && (0 != tag_entry->extensionFields.scope[1][0])) tag->scope = g_strdup(tag_entry->extensionFields.scope[1]); if (tag_entry->extensionFields.inheritance != NULL) tag->inheritance = g_strdup(tag_entry->extensionFields.inheritance); if (tag_entry->extensionFields.varType != NULL) tag->var_type = g_strdup(tag_entry->extensionFields.varType); if (tag_entry->extensionFields.access != NULL) tag->access = get_tag_access(tag_entry->extensionFields.access); if (tag_entry->extensionFields.implementation != NULL) tag->impl = get_tag_impl(tag_entry->extensionFields.implementation); if ((tm_tag_macro_t == tag->type) && (NULL != tag->arglist)) tag->type = tm_tag_macro_with_arg_t; tag->file = file; tag->lang = file->lang; return TRUE; }
void tag_show_stack(){ t_tag_item *item; int i; for(i=tag_stack.size-1; i>=0; i--){ item = tag_stack.arr[i]; printf( "%s, level %d\n" , get_tag_type(item->tag) , item->indent_level ); } printf("=====================\n"); }
const fru_regdef_t * fru_reg_lookup_def_by_tag(fru_tag_t tag) { fru_regdef_t *ret_def = NULL; int i = 0; for (i = 0; i < max_data_element_count; i++) { ret_def = &(Element_Defs[i]); if (ret_def->tagType == get_tag_type(&tag) && ret_def->tagDense == get_tag_dense(&tag) && ret_def->payloadLen == get_payload_length(&tag)) { return (ret_def); } } return (NULL); }
size_t get_payload_length(fru_tag_t *tag) { uint64_t tmp64; uint32_t tmp32; fru_tag_t tmp; tmp = *tag; switch (get_tag_type(tag)) { case FRU_A: return (tag->a.pl_len); case FRU_B: tmp.raw_data = (tag->byte[0] << 8) | tag->byte[1]; return (tmp.b.pl_len); case FRU_C: tmp.raw_data = (tag->byte[0] << 8) | tag->byte[1]; return (tmp.c.pl_len); case FRU_D: tmp32 = (tag->byte[0] << 16) | (tag->byte[1] << 8) | tag->byte[2]; tmp.raw_data = tmp32; return (tmp.d.pl_len); case FRU_E: tmp32 = (tag->byte[0] << 16) | (tag->byte[1] << 8) | tag->byte[2]; tmp.raw_data = tmp32; return (tmp.e.pl_len); case FRU_F: tmp32 = (tag->byte[0] << 24) | (tag->byte[1] << 16) | (tag->byte[2] << 8) | tag->byte[3]; tmp.raw_data = tmp32; return (tmp.f.pl_len); case FRU_G: tmp64 = ((uint64_t)tag->byte[0] << 40) | ((uint64_t)tag->byte[1] << 32) | ((uint64_t)tag->byte[2] << 24) | ((uint64_t)tag->byte[3] << 16) | ((uint64_t)tag->byte[4] << 8) | (uint64_t)tag->byte[5]; tmp.raw_data = tmp64; return (tmp.g.pl_len); default: errno = EINVAL; return ((uint32_t)-1); } }
size_t get_payload_length(fru_tag_t *tag) { switch (get_tag_type(tag)) { case FRU_A: return (tag->a.pl_len); case FRU_B: return (tag->b.pl_len); case FRU_C: return (tag->c.pl_len); case FRU_D: return (tag->d.pl_len); case FRU_E: return (tag->e.pl_len); case FRU_F: return (tag->f.pl_len); case FRU_G: return (tag->g.pl_len); default: errno = EINVAL; return ((uint32_t)-1); } }
uint32_t get_tag_dense(fru_tag_t *tag) { switch (get_tag_type(tag)) { case FRU_A: return (tag->a.dense); case FRU_B: return (tag->b.dense); case FRU_C: return (tag->c.dense); case FRU_D: return (tag->d.dense); case FRU_E: return (tag->e.dense); case FRU_F: return (tag->f.dense); case FRU_G: return (tag->g.dense); default: errno = EINVAL; return ((uint32_t)-1); } }
/* Same as tm_tag_init_from_file(), but parsing CTags tag file format (http://ctags.sourceforge.net/FORMAT) */ static gboolean tm_tag_init_from_file_ctags(TMTag *tag, TMSourceFile *file, FILE *fp) { gchar buf[BUFSIZ]; gchar *p, *tab; tag->refcount = 1; tag->type = tm_tag_function_t; /* default type is function if no kind is specified */ do { if ((NULL == fgets(buf, BUFSIZ, fp)) || ('\0' == *buf)) return FALSE; } while (strncmp(buf, "!_TAG_", 6) == 0); /* skip !_TAG_ lines */ p = buf; /* tag name */ if (! (tab = strchr(p, '\t')) || p == tab) return FALSE; tag->name = g_strndup(p, (gsize)(tab - p)); p = tab + 1; /* tagfile, unused */ if (! (tab = strchr(p, '\t'))) { g_free(tag->name); tag->name = NULL; return FALSE; } p = tab + 1; /* Ex command, unused */ if (*p == '/' || *p == '?') { gchar c = *p; for (++p; *p && *p != c; p++) { if (*p == '\\' && p[1]) p++; } } else /* assume a line */ tag->line = atol(p); tab = strstr(p, ";\""); /* read extension fields */ if (tab) { p = tab + 2; while (*p && *p != '\n' && *p != '\r') { gchar *end; const gchar *key, *value = NULL; /* skip leading tabulations */ while (*p && *p == '\t') p++; /* find the separator (:) and end (\t) */ key = end = p; while (*end && *end != '\t' && *end != '\n' && *end != '\r') { if (*end == ':' && ! value) { *end = 0; /* terminate the key */ value = end + 1; } end++; } /* move p paste the so we won't stop parsing by setting *end=0 below */ p = *end ? end + 1 : end; *end = 0; /* terminate the value (or key if no value) */ if (! value || 0 == strcmp(key, "kind")) /* tag kind */ { const gchar *kind = value ? value : key; if (kind[0] && kind[1]) tag->type = get_tag_type(kind); else { switch (*kind) { case 'c': tag->type = tm_tag_class_t; break; case 'd': tag->type = tm_tag_macro_t; break; case 'e': tag->type = tm_tag_enumerator_t; break; case 'F': tag->type = tm_tag_other_t; break; /* Obsolete */ case 'f': tag->type = tm_tag_function_t; break; case 'g': tag->type = tm_tag_enum_t; break; case 'I': tag->type = tm_tag_class_t; break; case 'i': tag->type = tm_tag_interface_t; break; case 'l': tag->type = tm_tag_variable_t; break; case 'M': tag->type = tm_tag_macro_t; break; case 'm': tag->type = tm_tag_member_t; break; case 'n': tag->type = tm_tag_namespace_t; break; case 'P': tag->type = tm_tag_package_t; break; case 'p': tag->type = tm_tag_prototype_t; break; case 's': tag->type = tm_tag_struct_t; break; case 't': tag->type = tm_tag_typedef_t; break; case 'u': tag->type = tm_tag_union_t; break; case 'v': tag->type = tm_tag_variable_t; break; case 'x': tag->type = tm_tag_externvar_t; break; default: #ifdef TM_DEBUG g_warning("Unknown tag kind %c", *kind); #endif tag->type = tm_tag_other_t; break; } } } else if (0 == strcmp(key, "inherits")) /* comma-separated list of classes this class inherits from */ { g_free(tag->inheritance); tag->inheritance = g_strdup(value); } else if (0 == strcmp(key, "implementation")) /* implementation limit */ tag->impl = get_tag_impl(value); else if (0 == strcmp(key, "line")) /* line */ tag->line = atol(value); else if (0 == strcmp(key, "access")) /* access */ tag->access = get_tag_access(value); else if (0 == strcmp(key, "class") || 0 == strcmp(key, "enum") || 0 == strcmp(key, "function") || 0 == strcmp(key, "struct") || 0 == strcmp(key, "union")) /* Name of the class/enum/function/struct/union in which this tag is a member */ { g_free(tag->scope); tag->scope = g_strdup(value); } else if (0 == strcmp(key, "file")) /* static (local) tag */ tag->local = TRUE; else if (0 == strcmp(key, "signature")) /* arglist */ { g_free(tag->arglist); tag->arglist = g_strdup(value); } } } tag->file = file; return TRUE; }
static int get_packets(hash_obj_t *seg_hash, raw_list_t *rawlist, int offset, int length) { int tag_size; int paylen; int retval; int seg_limit = 0; int pktcnt = 0; char *data; uint32_t crc; uint32_t origcrc; fru_tag_t tag; hash_obj_t *pkt_hash_obj; hash_obj_t *sec_hash; fru_segdesc_t *segdesc; fru_tagtype_t tagtype; char *ignore_flag; retval = get_packet(rawlist, &tag, sizeof (fru_tag_t), offset); if (retval == -1) { return (-1); } /* section hash object */ sec_hash = lookup_handle_object(seg_hash->u.seg_obj->section_hdl, SECTION_TYPE); if (sec_hash == NULL) { return (-1); } seg_hash->u.seg_obj->trailer_offset = offset; data = (char *)&tag; while (data[0] != SEG_TRAILER_TAG) { tagtype = get_tag_type(&tag); /* verify tag type */ if (tagtype == -1) { return (-1); } tag_size = get_tag_size(tagtype); if (tag_size == -1) { return (-1); } seg_limit += tag_size; if (seg_limit > length) { return (-1); } paylen = get_payload_length((void *)&tag); if (paylen == -1) { return (-1); } seg_limit += paylen; if (seg_limit > length) { return (-1); } if ((offset + tag_size + paylen) > (sec_hash->u.sec_obj->section.offset + sec_hash->u.sec_obj->section.length)) { return (-1); } pkt_hash_obj = create_packet_hash_object(); if (pkt_hash_obj == NULL) { return (-1); } pkt_hash_obj->u.pkt_obj->payload = malloc(paylen); if (pkt_hash_obj->u.pkt_obj->payload == NULL) { free(pkt_hash_obj); return (-1); } offset += tag_size; retval = raw_memcpy(pkt_hash_obj->u.pkt_obj->payload, rawlist, offset, paylen); if (retval != paylen) { free(pkt_hash_obj->u.pkt_obj->payload); free(pkt_hash_obj); return (-1); } /* don't change this */ pkt_hash_obj->u.pkt_obj->tag.raw_data = 0; (void) memcpy(&pkt_hash_obj->u.pkt_obj->tag, &tag, tag_size); pkt_hash_obj->u.pkt_obj->paylen = paylen; pkt_hash_obj->u.pkt_obj->tag_size = tag_size; pkt_hash_obj->u.pkt_obj->payload_offset = offset; offset += paylen; add_hashobject_to_hashtable(pkt_hash_obj); add_to_pkt_object_list(seg_hash, pkt_hash_obj); pktcnt++; retval = get_packet(rawlist, &tag, sizeof (fru_tag_t), offset); if (retval == -1) { return (retval); } data = (char *)&tag; } segdesc = (fru_segdesc_t *)&seg_hash->u.seg_obj->segment.descriptor; seg_hash->u.seg_obj->trailer_offset = offset; if (!segdesc->field.ignore_checksum) { crc = get_checksum_crc(seg_hash, seg_limit); offset = seg_hash->u.seg_obj->segment.offset; retval = raw_memcpy(&origcrc, rawlist, offset + seg_limit + 1, sizeof (origcrc)); ignore_flag = getenv(IGNORE_CHECK); if (ignore_flag != NULL) { return (pktcnt); } if (retval != sizeof (origcrc)) { return (-1); } origcrc = BE_32(origcrc); if (origcrc != crc) { seg_hash->u.seg_obj->trailer_offset = offset; return (-1); } } return (pktcnt); }