static void tm_workspace_merge_tags(GPtrArray **big_array, GPtrArray *small_array) { GPtrArray *new_tags = tm_tags_merge(*big_array, small_array, workspace_tags_sort_attrs, FALSE); /* tags owned by TMSourceFile - free just the pointer array */ g_ptr_array_free(*big_array, TRUE); *big_array = new_tags; }
gboolean tm_workspace_load_global_tags(const char *tags_file, gint mode) { gsize orig_len; guchar buf[BUFSIZ]; FILE *fp; TMTag *tag; TMFileFormat format = TM_FILE_FORMAT_TAGMANAGER; if (NULL == theWorkspace) return FALSE; if (NULL == (fp = g_fopen(tags_file, "r"))) return FALSE; if (NULL == theWorkspace->global_tags) theWorkspace->global_tags = g_ptr_array_new(); orig_len = theWorkspace->global_tags->len; if ((NULL == fgets((gchar*) buf, BUFSIZ, fp)) || ('\0' == *buf)) { fclose(fp); return FALSE; /* early out on error */ } else { /* We read the first line for the format specification. */ if (buf[0] == '#' && strstr((gchar*) buf, "format=pipe") != NULL) format = TM_FILE_FORMAT_PIPE; else if (buf[0] == '#' && strstr((gchar*) buf, "format=tagmanager") != NULL) format = TM_FILE_FORMAT_TAGMANAGER; else if (buf[0] == '#' && strstr((gchar*) buf, "format=ctags") != NULL) format = TM_FILE_FORMAT_CTAGS; else if (strncmp((gchar*) buf, "!_TAG_", 6) == 0) format = TM_FILE_FORMAT_CTAGS; else { /* We didn't find a valid format specification, so we try to auto-detect the format * by counting the pipe characters on the first line and asumme pipe format when * we find more than one pipe on the line. */ guint i, pipe_cnt = 0, tab_cnt = 0; for (i = 0; i < BUFSIZ && buf[i] != '\0' && pipe_cnt < 2; i++) { if (buf[i] == '|') pipe_cnt++; else if (buf[i] == '\t') tab_cnt++; } if (pipe_cnt > 1) format = TM_FILE_FORMAT_PIPE; else if (tab_cnt > 1) format = TM_FILE_FORMAT_CTAGS; } rewind(fp); /* reset the file pointer, to start reading again from the beginning */ } while (NULL != (tag = tm_tag_new_from_file(NULL, fp, mode, format))) g_ptr_array_add(theWorkspace->global_tags, tag); fclose(fp); /* reorder the whole array, because tm_tags_find expects a sorted array */ tm_tags_merge(theWorkspace->global_tags, orig_len, global_tags_sort_attrs, TRUE); return TRUE; }
/* Loads the global tag list from the specified file. The global tag list should have been first created using tm_workspace_create_global_tags(). @param tags_file The file containing global tags. @return TRUE on success, FALSE on failure. @see tm_workspace_create_global_tags() */ gboolean tm_workspace_load_global_tags(const char *tags_file, TMParserType mode) { GPtrArray *file_tags, *new_tags; file_tags = tm_source_file_read_tags_file(tags_file, mode); if (!file_tags) return FALSE; tm_tags_sort(file_tags, global_tags_sort_attrs, TRUE, TRUE); /* reorder the whole array, because tm_tags_find expects a sorted array */ new_tags = tm_tags_merge(theWorkspace->global_tags, file_tags, global_tags_sort_attrs, TRUE); g_ptr_array_free(theWorkspace->global_tags, TRUE); g_ptr_array_free(file_tags, TRUE); theWorkspace->global_tags = new_tags; g_ptr_array_free(theWorkspace->global_typename_array, TRUE); theWorkspace->global_typename_array = tm_tags_extract(new_tags, TM_GLOBAL_TYPE_MASK); return TRUE; }