gboolean tm_source_file_parse(TMSourceFile *source_file) { const char *file_name; gboolean status = TRUE; int passCount = 0; if ((NULL == source_file) || (NULL == source_file->work_object.file_name)) { g_warning("Attempt to parse NULL file"); return FALSE; } file_name = source_file->work_object.file_name; if (NULL == LanguageTable) { initializeParsing(); installLanguageMapDefaults(); if (NULL == TagEntryFunction) TagEntryFunction = tm_source_file_tags; if (NULL == TagEntrySetArglistFunction) TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; } current_source_file = source_file; if (LANG_AUTO == source_file->lang) source_file->lang = getFileLanguage (file_name); if (source_file->lang < 0 || ! LanguageTable [source_file->lang]->enabled) return status; while ((TRUE == status) && (passCount < 3)) { if (source_file->work_object.tags_array) tm_tags_array_free(source_file->work_object.tags_array, FALSE); if (fileOpen (file_name, source_file->lang)) { if (LanguageTable [source_file->lang]->parser != NULL) { LanguageTable [source_file->lang]->parser (); fileClose (); break; } else if (LanguageTable [source_file->lang]->parser2 != NULL) status = LanguageTable [source_file->lang]->parser2 (passCount); fileClose (); } else { g_warning("%s: Unable to open %s", G_STRFUNC, file_name); return FALSE; } ++ passCount; } return status; }
void tm_source_file_destroy(TMSourceFile *source_file) { #ifdef TM_DEBUG g_message("Destroying source file: %s", source_file->work_object.file_name); #endif if (NULL != TM_WORK_OBJECT(source_file)->tags_array) { tm_tags_array_free(TM_WORK_OBJECT(source_file)->tags_array, TRUE); TM_WORK_OBJECT(source_file)->tags_array = NULL; } tm_work_object_destroy(&(source_file->work_object)); }
/* Frees the workspace structure and all child source files. Use only when exiting from the main program. */ void tm_workspace_free(void) { guint i; #ifdef TM_DEBUG g_message("Workspace destroyed"); #endif for (i=0; i < theWorkspace->source_files->len; ++i) tm_source_file_free(theWorkspace->source_files->pdata[i]); g_ptr_array_free(theWorkspace->source_files, TRUE); tm_tags_array_free(theWorkspace->global_tags, TRUE); g_ptr_array_free(theWorkspace->tags_array, TRUE); g_ptr_array_free(theWorkspace->typename_array, TRUE); g_free(theWorkspace); theWorkspace = NULL; }
gboolean tm_source_file_buffer_parse(TMSourceFile *source_file, guchar* text_buf, gint buf_size) { const char *file_name; gboolean status = TRUE; if ((NULL == source_file) || (NULL == source_file->work_object.file_name)) { g_warning("Attempt to parse NULL file"); return FALSE; } if ((NULL == text_buf) || (0 == buf_size)) { g_warning("Attempt to parse a NULL text buffer"); } file_name = source_file->work_object.file_name; if (NULL == LanguageTable) { initializeParsing(); installLanguageMapDefaults(); if (NULL == TagEntryFunction) TagEntryFunction = tm_source_file_tags; if (NULL == TagEntrySetArglistFunction) TagEntrySetArglistFunction = tm_source_file_set_tag_arglist; } current_source_file = source_file; if (LANG_AUTO == source_file->lang) source_file->lang = getFileLanguage (file_name); if (source_file->lang == LANG_IGNORE) { #ifdef TM_DEBUG g_warning("ignoring %s (unknown language)\n", file_name); #endif } else if (! LanguageTable [source_file->lang]->enabled) { #ifdef TM_DEBUG g_warning("ignoring %s (language disabled)\n", file_name); #endif } else { int passCount = 0; while ((TRUE == status) && (passCount < 3)) { if (source_file->work_object.tags_array) tm_tags_array_free(source_file->work_object.tags_array, FALSE); if (bufferOpen (text_buf, buf_size, file_name, source_file->lang)) { if (LanguageTable [source_file->lang]->parser != NULL) { LanguageTable [source_file->lang]->parser (); bufferClose (); break; } else if (LanguageTable [source_file->lang]->parser2 != NULL) status = LanguageTable [source_file->lang]->parser2 (passCount); bufferClose (); } else { g_warning("Unable to open %s", file_name); return FALSE; } ++ passCount; } return TRUE; } return status; }