Revision: 474 Author: eht16 Date: 2006-06-24 07:36:35 -0700 (Sat, 24 Jun 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=474&view=rev
Log Message: ----------- Replaced 'blank' by 'include "..."'. Fixed a bug in utils_brace_match() which prevents correctly matching. Made auto completion work only for the current filetype (i.e. it hides symbols from other filetypes). Removed unneeded code.
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/geany.h trunk/src/sci_cb.c trunk/src/utils.c trunk/tagmanager/options.c trunk/tagmanager/options.h trunk/tagmanager/parse.c Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/ChangeLog 2006-06-24 14:36:35 UTC (rev 474) @@ -1,3 +1,18 @@ +2006-06-24 Enrico Troeger enrico.troeger@uvena.de + + * src/utils.c: Replaced 'blank' by 'include "..."'. Fixed a bug in + utils_brace_match() which prevents correctly matching. + * src/document.c, src/sci_cb.c, src/filetypes.c: + Made auto completion work only for the current filetype + (i.e. it hides symbols from other filetypes). + * tagmanager/options.c, tagmanager/parse.c: Removed unneeded code. + * tagmanager/tm_workspace.c, tagmanager/tm_source_file + tagmanager/tm_tag.c, tagmanager/tm_project, tagmanager/parsers.h, + tagmanager/tm_file_entry.c, tagmanager/entry.c, src/highlighting.c, + data/latex.tags, data/php.tags, Makefile.am: + Added global auto completion tags for PHP and LaTeX. + + 2006-06-23 Nick Treleaven nick.treleaven@btinternet.com
* src/msgwindow.c: Add a timestamp to messages in the Status window
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/src/document.c 2006-06-24 14:36:35 UTC (rev 474) @@ -930,17 +930,13 @@ if (doc_list[idx].tm_file == NULL) { gchar *locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL); - doc_list[idx].tm_file = tm_source_file_new(locale_filename, FALSE); + doc_list[idx].tm_file = tm_source_file_new(locale_filename, FALSE, + doc_list[idx].file_type->name); g_free(locale_filename); if (! doc_list[idx].tm_file) return; tm_workspace_add_object(doc_list[idx].tm_file); if (update) - { - // parse the file after setting the filetype - // this is necessary to switch between filetypes - TM_SOURCE_FILE(doc_list[idx].tm_file)->lang = getNamedLanguage((doc_list[idx].file_type)->name); tm_source_file_update(doc_list[idx].tm_file, TRUE, FALSE, TRUE); - } utils_update_tag_list(idx, TRUE); } else
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/src/filetypes.c 2006-06-24 14:36:35 UTC (rev 474) @@ -48,6 +48,7 @@ #define C // these macros are only to ease navigation filetypes[GEANY_FILETYPES_C] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_C]->id = GEANY_FILETYPES_C; + filetypes[GEANY_FILETYPES_C]->lang = 0; filetypes[GEANY_FILETYPES_C]->name = g_strdup("C"); filetypes[GEANY_FILETYPES_C]->has_tags = TRUE; filetypes[GEANY_FILETYPES_C]->title = g_strdup(_("C source file")); @@ -66,6 +67,8 @@ #define CPP filetypes[GEANY_FILETYPES_CPP] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_CPP]->id = GEANY_FILETYPES_CPP; + // C++ has langType 1, but to get the global tags for C, too, we use the langType of C + filetypes[GEANY_FILETYPES_CPP]->lang = 0; filetypes[GEANY_FILETYPES_CPP]->name = g_strdup("C++"); filetypes[GEANY_FILETYPES_CPP]->has_tags = TRUE; filetypes[GEANY_FILETYPES_CPP]->title = g_strdup(_("C++ source file")); @@ -93,6 +96,7 @@ filetypes[GEANY_FILETYPES_JAVA] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_JAVA]->id = GEANY_FILETYPES_JAVA; filetypes[GEANY_FILETYPES_JAVA]->name = g_strdup("Java"); + filetypes[GEANY_FILETYPES_JAVA]->lang = 2; filetypes[GEANY_FILETYPES_JAVA]->has_tags = TRUE; filetypes[GEANY_FILETYPES_JAVA]->title = g_strdup(_("Java source file")); filetypes[GEANY_FILETYPES_JAVA]->extension = g_strdup("java"); @@ -109,6 +113,7 @@ #define PERL filetypes[GEANY_FILETYPES_PERL] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_PERL]->id = GEANY_FILETYPES_PERL; + filetypes[GEANY_FILETYPES_PERL]->lang = 5; filetypes[GEANY_FILETYPES_PERL]->name = g_strdup("Perl"); filetypes[GEANY_FILETYPES_PERL]->has_tags = TRUE; filetypes[GEANY_FILETYPES_PERL]->title = g_strdup(_("Perl source file")); @@ -127,6 +132,7 @@ #define PHP filetypes[GEANY_FILETYPES_PHP] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_PHP]->id = GEANY_FILETYPES_PHP; + filetypes[GEANY_FILETYPES_PHP]->lang = 6; filetypes[GEANY_FILETYPES_PHP]->name = g_strdup("PHP"); filetypes[GEANY_FILETYPES_PHP]->has_tags = TRUE; filetypes[GEANY_FILETYPES_PHP]->title = g_strdup(_("PHP / HTML source file")); @@ -149,6 +155,7 @@ #define XML filetypes[GEANY_FILETYPES_XML] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_XML]->id = GEANY_FILETYPES_XML; + filetypes[GEANY_FILETYPES_XML]->lang = -2; filetypes[GEANY_FILETYPES_XML]->name = g_strdup("XML"); filetypes[GEANY_FILETYPES_XML]->has_tags = FALSE; filetypes[GEANY_FILETYPES_XML]->title = g_strdup(_("XML source file")); @@ -166,6 +173,7 @@ #define DOCBOOK filetypes[GEANY_FILETYPES_DOCBOOK] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_DOCBOOK]->id = GEANY_FILETYPES_DOCBOOK; + filetypes[GEANY_FILETYPES_DOCBOOK]->lang = 12; filetypes[GEANY_FILETYPES_DOCBOOK]->name = g_strdup("Docbook"); filetypes[GEANY_FILETYPES_DOCBOOK]->has_tags = TRUE; filetypes[GEANY_FILETYPES_DOCBOOK]->title = g_strdup(_("Docbook source file")); @@ -182,6 +190,7 @@ #define PYTHON filetypes[GEANY_FILETYPES_PYTHON] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_PYTHON]->id = GEANY_FILETYPES_PYTHON; + filetypes[GEANY_FILETYPES_PYTHON]->lang = 7; filetypes[GEANY_FILETYPES_PYTHON]->name = g_strdup("Python"); filetypes[GEANY_FILETYPES_PYTHON]->has_tags = TRUE; filetypes[GEANY_FILETYPES_PYTHON]->title = g_strdup(_("Python source file")); @@ -199,6 +208,7 @@ #define LATEX filetypes[GEANY_FILETYPES_LATEX] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_LATEX]->id = GEANY_FILETYPES_LATEX; + filetypes[GEANY_FILETYPES_LATEX]->lang = 8; filetypes[GEANY_FILETYPES_LATEX]->name = g_strdup("LaTeX"); filetypes[GEANY_FILETYPES_LATEX]->has_tags = TRUE; filetypes[GEANY_FILETYPES_LATEX]->title = g_strdup(_("LaTeX source file")); @@ -217,6 +227,7 @@ #define PASCAL filetypes[GEANY_FILETYPES_PASCAL] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_PASCAL]->id = GEANY_FILETYPES_PASCAL; + filetypes[GEANY_FILETYPES_PASCAL]->lang = 4; filetypes[GEANY_FILETYPES_PASCAL]->name = g_strdup("Pascal"); filetypes[GEANY_FILETYPES_PASCAL]->has_tags = TRUE; filetypes[GEANY_FILETYPES_PASCAL]->title = g_strdup(_("Pascal source file")); @@ -238,6 +249,7 @@ #define SH filetypes[GEANY_FILETYPES_SH] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_SH]->id = GEANY_FILETYPES_SH; + filetypes[GEANY_FILETYPES_SH]->lang = 16; filetypes[GEANY_FILETYPES_SH]->name = g_strdup("Sh"); filetypes[GEANY_FILETYPES_SH]->has_tags = TRUE; filetypes[GEANY_FILETYPES_SH]->title = g_strdup(_("Shell script file")); @@ -260,6 +272,7 @@ #define MAKE filetypes[GEANY_FILETYPES_MAKE] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_MAKE]->id = GEANY_FILETYPES_MAKE; + filetypes[GEANY_FILETYPES_MAKE]->lang = 3; filetypes[GEANY_FILETYPES_MAKE]->name = g_strdup("Make"); filetypes[GEANY_FILETYPES_MAKE]->has_tags = TRUE; filetypes[GEANY_FILETYPES_MAKE]->title = g_strdup(_("Makefile")); @@ -277,6 +290,7 @@ #define CSS filetypes[GEANY_FILETYPES_CSS] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_CSS]->id = GEANY_FILETYPES_CSS; + filetypes[GEANY_FILETYPES_CSS]->lang = 13; filetypes[GEANY_FILETYPES_CSS]->name = g_strdup("CSS"); filetypes[GEANY_FILETYPES_CSS]->has_tags = TRUE; filetypes[GEANY_FILETYPES_CSS]->title = g_strdup(_("Cascading StyleSheet")); @@ -293,6 +307,7 @@ #define CONF filetypes[GEANY_FILETYPES_CONF] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_CONF]->id = GEANY_FILETYPES_CONF; + filetypes[GEANY_FILETYPES_CONF]->lang = 10; filetypes[GEANY_FILETYPES_CONF]->name = g_strdup("Conf"); filetypes[GEANY_FILETYPES_CONF]->has_tags = TRUE; filetypes[GEANY_FILETYPES_CONF]->title = g_strdup(_("Config file")); @@ -312,8 +327,9 @@ #define ASM filetypes[GEANY_FILETYPES_ASM] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_ASM]->id = GEANY_FILETYPES_ASM; + filetypes[GEANY_FILETYPES_ASM]->lang = 9; filetypes[GEANY_FILETYPES_ASM]->name = g_strdup("ASM"); - filetypes[GEANY_FILETYPES_ASM]->has_tags = FALSE; + filetypes[GEANY_FILETYPES_ASM]->has_tags = TRUE; filetypes[GEANY_FILETYPES_ASM]->title = g_strdup(_("Assembler source file")); filetypes[GEANY_FILETYPES_ASM]->extension = g_strdup("asm"); filetypes[GEANY_FILETYPES_ASM]->pattern = g_new0(gchar*, 2); @@ -328,6 +344,7 @@ #define SQL filetypes[GEANY_FILETYPES_SQL] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_SQL]->id = GEANY_FILETYPES_SQL; + filetypes[GEANY_FILETYPES_SQL]->lang = 11; filetypes[GEANY_FILETYPES_SQL]->name = g_strdup("SQL"); filetypes[GEANY_FILETYPES_SQL]->has_tags = TRUE; filetypes[GEANY_FILETYPES_SQL]->title = g_strdup(_("SQL Dump file")); @@ -344,6 +361,7 @@ #define CAML filetypes[GEANY_FILETYPES_CAML] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_CAML]->id = GEANY_FILETYPES_CAML; + filetypes[GEANY_FILETYPES_CAML]->lang = -2; filetypes[GEANY_FILETYPES_CAML]->name = g_strdup("CAML"); filetypes[GEANY_FILETYPES_CAML]->has_tags = FALSE; filetypes[GEANY_FILETYPES_CAML]->title = g_strdup(_("(O)Caml source file")); @@ -361,6 +379,7 @@ #define OMS filetypes[GEANY_FILETYPES_OMS] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_OMS]->id = GEANY_FILETYPES_OMS; + filetypes[GEANY_FILETYPES_OMS]->lang = -2; filetypes[GEANY_FILETYPES_OMS]->name = g_strdup("O-Matrix"); filetypes[GEANY_FILETYPES_OMS]->has_tags = FALSE; filetypes[GEANY_FILETYPES_OMS]->title = g_strdup(_("O-Matrix source file")); @@ -377,6 +396,7 @@ #define RUBY filetypes[GEANY_FILETYPES_RUBY] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_RUBY]->id = GEANY_FILETYPES_RUBY; + filetypes[GEANY_FILETYPES_RUBY]->lang = 14; filetypes[GEANY_FILETYPES_RUBY]->name = g_strdup("Ruby"); filetypes[GEANY_FILETYPES_RUBY]->has_tags = TRUE; filetypes[GEANY_FILETYPES_RUBY]->title = g_strdup(_("Ruby source file")); @@ -395,6 +415,7 @@ #define TCL filetypes[GEANY_FILETYPES_TCL] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_TCL]->id = GEANY_FILETYPES_TCL; + filetypes[GEANY_FILETYPES_TCL]->lang = 15; filetypes[GEANY_FILETYPES_TCL]->name = g_strdup("Tcl"); filetypes[GEANY_FILETYPES_TCL]->has_tags = TRUE; filetypes[GEANY_FILETYPES_TCL]->title = g_strdup(_("Tcl source file")); @@ -414,6 +435,7 @@ filetypes[GEANY_FILETYPES_ALL] = g_new0(filetype, 1); filetypes[GEANY_FILETYPES_ALL]->id = GEANY_FILETYPES_ALL; filetypes[GEANY_FILETYPES_ALL]->name = g_strdup("None"); + filetypes[GEANY_FILETYPES_ALL]->lang = -2; filetypes[GEANY_FILETYPES_ALL]->has_tags = FALSE; filetypes[GEANY_FILETYPES_ALL]->title = g_strdup(_("All files")); filetypes[GEANY_FILETYPES_ALL]->extension = g_strdup("*");
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/src/filetypes.h 2006-06-24 14:36:35 UTC (rev 474) @@ -73,6 +73,8 @@ typedef struct filetype { guint id; + langType lang; // represents the langType of tagmanager(see the table + // in tagmanager/parsers.h), -1 represents all, -2 none gchar *name; // will be used as name for tagmanager gboolean has_tags; // indicates whether there is a tag parser for it or not gchar *title; // will be shown in the file open dialog
Modified: trunk/src/geany.h =================================================================== --- trunk/src/geany.h 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/src/geany.h 2006-06-24 14:36:35 UTC (rev 474) @@ -65,7 +65,7 @@ #define GEANY_SESSION_FILES 25 #define GEANY_MAX_TAGS_COUNT 1000 #define GEANY_CHECK_FILE_DELAY 30 -#define GEANY_WORDCHARS "_#&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" +#define GEANY_WORDCHARS "_#&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\" #define GEANY_MAX_WORD_LENGTH 192 #define GEANY_MAX_AUTOCOMPLETE_WORDS 30 #define GEANY_STRING_UNTITLED _("untitled") @@ -263,9 +263,6 @@ GIGABYTE = (MEGABYTE*1024) };
-// prototype from tagmanager/parse.h, used in document.c, ugly but it works -extern langType getNamedLanguage(const char *const name); - // implementation in main.c void geany_debug(gchar const *format, ...);
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/src/sci_cb.c 2006-06-24 14:36:35 UTC (rev 474) @@ -182,6 +182,7 @@ case '{': { // Tex auto-closing sci_cb_auto_close_bracket(sci, pos, nt->ch); // Tex auto-closing + sci_cb_show_calltip(sci, pos); break; } case '}': @@ -365,24 +366,26 @@ gint lexer = SSM(sci, SCI_GETLEXER, 0, 0); gint style; gchar word[GEANY_MAX_WORD_LENGTH]; + gint idx = document_find_by_sci(sci); const GPtrArray *tags;
word[0] = '\0'; if (pos == -1) { // position of '(' is unknown, so go backwards to find it pos = SSM(sci, SCI_GETCURRENTPOS, 0, 0); - while (pos >= 0 && SSM(sci, SCI_GETCHARAT, pos, 0) != '(') pos--; + // I'm not sure if utils_isbrace() is a good idea, but it is the simplest way, but we need + // something more intelligent than only check for '(' because e.g. LaTeX uses {, [ or ( + while (pos >= 0 && ! utils_isbrace(SSM(sci, SCI_GETCHARAT, pos, 0))) pos--; }
style = SSM(sci, SCI_GETSTYLEAT, pos, 0); - if (lexer != SCLEX_CPP) return FALSE; if (lexer == SCLEX_CPP && (style == SCE_C_COMMENT || style == SCE_C_COMMENTLINE || style == SCE_C_COMMENTDOC)) return FALSE;
utils_find_current_word(sci, pos - 1, word, sizeof word); if (word[0] == '\0') return FALSE;
- tags = tm_workspace_find(word, tm_tag_max_t, NULL, FALSE); + tags = tm_workspace_find(word, tm_tag_max_t, NULL, FALSE, doc_list[idx].file_type->lang); if (tags->len == 1 && TM_TAG(tags->pdata[0])->atts.entry.arglist) { SSM(sci, SCI_CALLTIPSHOW, pos, (sptr_t) TM_TAG(tags->pdata[0])->atts.entry.arglist); @@ -439,25 +442,27 @@ g_strfreev(ents); } else - { // C and C++ tag autocompletion + { // PHP, LaTeX, C and C++ tag autocompletion gint i = 0; + gint idx = document_find_by_sci(sci); + TMTagAttrType attrs[] = { tm_tag_attr_name_t, 0 };
while ((line_pos - i >= 0) && ! g_ascii_isspace(linebuf[line_pos - i])) i++; if (i < 4) return FALSE; // go home if typed less than 4 chars
- tags = tm_workspace_find(root, tm_tag_max_t, NULL, TRUE); + tags = tm_workspace_find(root, tm_tag_max_t, attrs, TRUE, doc_list[idx].file_type->lang); if (NULL != tags && tags->len > 0) { GString *words = g_string_sized_new(150); - TMTag *tag; guint j; + for (j = 0; ((j < tags->len) && (j < GEANY_MAX_AUTOCOMPLETE_WORDS)); ++j) { - tag = (TMTag *) tags->pdata[j]; if (j > 0) g_string_append_c(words, ' '); - g_string_append(words, tag->name); + g_string_append(words, ((TMTag *) tags->pdata[j])->name); } SSM(sci, SCI_AUTOCSHOW, rootlen, (sptr_t) words->str); + //geany_debug("string size: %d", words->len); g_string_free(words, TRUE); } }
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/src/utils.c 2006-06-24 14:36:35 UTC (rev 474) @@ -308,19 +308,18 @@ case '>': return TRUE; } } - else + + switch (c) { - switch (c) - { - case '(': - case ')': - case '{': - case '}': - case '[': - case ']': return TRUE; - default: return FALSE; - } + case '(': + case ')': + case '{': + case '}': + case '[': + case ']': return TRUE; + default: return FALSE; } + return FALSE; }
@@ -1827,16 +1826,24 @@ "iterator", "functional", "string", "complex", "valarray", NULL }; - blank = gtk_menu_item_new_with_label(_("(blank)")); + blank = gtk_menu_item_new_with_label("#include "...""); gtk_container_add(GTK_CONTAINER(menu_edit), blank); gtk_widget_show(blank); g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate), (gpointer) "blank"); - blank = gtk_menu_item_new_with_label(_("(blank)")); + blank = gtk_separator_menu_item_new (); + gtk_container_add(GTK_CONTAINER(menu_edit), blank); + gtk_widget_show(blank); + + blank = gtk_menu_item_new_with_label("#include "...""); gtk_container_add(GTK_CONTAINER(menu_popup), blank); gtk_widget_show(blank); g_signal_connect((gpointer) blank, "activate", G_CALLBACK(on_insert_include_activate), (gpointer) "blank"); + blank = gtk_separator_menu_item_new (); + gtk_container_add(GTK_CONTAINER(menu_popup), blank); + gtk_widget_show(blank); + insert_items(menu_edit, menu_popup, (gchar**) c_includes_stdlib, _("C Standard Library")); insert_items(menu_edit, menu_popup, (gchar**) c_includes_c99, _("ISO C99")); insert_items(menu_edit, menu_popup, (gchar**) c_includes_cpp, _("C++ (C Standard Library)"));
Modified: trunk/tagmanager/options.c =================================================================== --- trunk/tagmanager/options.c 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/tagmanager/options.c 2006-06-24 14:36:35 UTC (rev 474) @@ -24,20 +24,11 @@ #include "options.h" #include "parse.h"
-/* -* MACROS -*/ -#define INVOCATION "Usage: %s [options] [file(s)]\n"
#define CTAGS_ENVIRONMENT "CTAGS" -#define ETAGS_ENVIRONMENT "ETAGS"
#define CTAGS_FILE "tags" -#define ETAGS_FILE "TAGS"
-#ifndef ETAGS -# define ETAGS "etags" /* name which causes default use of to -e */ -#endif
/* The following separators are permitted for list options. */ @@ -56,44 +47,12 @@
#define isCompoundOption(c) (boolean) (strchr ("fohiILpDb", (c)) != NULL)
-/* -* Data declarations -*/
-enum eOptionLimits { - MaxHeaderExtensions = 100, /* maximum number of extensions in -h option */ - MaxSupportedTagFormat = 2 -};
-typedef struct sOptionDescription { - int usedByEtags; - const char *const description; -} optionDescription; - -typedef void (*parametricOptionHandler) (const char *const option, const char *const parameter); - -typedef const struct { - const char* name; /* name of option as specified by user */ - parametricOptionHandler handler; /* routine to handle option */ - boolean initOnly; /* option must be specified before any files */ -} parametricOption; - -typedef const struct { - const char* name; /* name of option as specified by user */ - boolean* pValue; /* pointer to option value */ - boolean initOnly; /* option must be specified before any files */ -} booleanOption; - /* * DATA DEFINITIONS */
-static boolean ParsedLeadingOptions = FALSE; - -static const char *const HeaderExtensions [] = { - "h", "H", "hh", "hpp", "hxx", "h++", "inc", "def", NULL -}; - optionValues Option = { { FALSE, /* --extra=f */ @@ -130,7 +89,6 @@ NULL, /* -L */ NULL, /* -o */ NULL, /* -h */ - NULL, /* --etags-include */ DEFAULT_FILE_FORMAT,/* --format */ FALSE, /* --if0 */ FALSE, /* --kind-long */ @@ -143,117 +101,13 @@ FALSE, /* --totals */ FALSE, /* --line-directives */ FALSE, -#ifdef TM_DEBUG - 0, 0 /* -D, -b */ -#endif };
-/* -- Locally used only -*/
-static optionDescription LongOptionDescription [] = { - {1," --version"}, - {1," Print version identifier to standard output."}, - {1, NULL} -}; - -static const char* const License = -"This program is free software; you can redistribute it and/or\n\ -modify it under the terms of the GNU General Public License\n\ -as published by the Free Software Foundation; either version 2\n\ -of the License, or (at your option) any later version.\n\ -\n\ -This program is distributed in the hope that it will be useful,\n\ -but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ -GNU General Public License for more details.\n\ -\n\ -You should have received a copy of the GNU General Public License\n\ -along with this program; if not, write to the Free Software\n\ -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"; - -/* Contains a set of strings describing the set of "features" compiled into - * the code. - */ -static const char *const Features [] = { -#ifdef WIN32 - "win32", -#endif -#ifdef DJGPP - "msdos_32", -#else -# ifdef MSDOS - "msdos_16", -# endif -#endif -#ifdef OS2 - "os2", -#endif -#ifdef AMIGA - "amiga", -#endif -#ifdef VMS - "vms", -#endif -#ifdef HAVE_FNMATCH - "wildcards", -#endif -#ifdef HAVE_REGEX - "regex", -#endif -#ifndef EXTERNAL_SORT - "internal-sort", -#endif -#ifdef CUSTOM_CONFIGURATION_FILE - "custom-conf", -#endif -#if (defined (MSDOS) || defined (WIN32) || defined (OS2)) && defined (UNIX_PATH_SEPARATOR) - "unix-path-separator", -#endif -#ifdef TM_DEBUG - "debug", -#endif - NULL -}; - -/* -* FUNCTION PROTOTYPES -*/ -static boolean parseFileOptions (const char *const fileName); - -/* -* FUNCTION DEFINITIONS -*/ - extern void verbose (const char *const format, ...) { - if (Option.verbose) - { - va_list ap; - va_start (ap, format); - vprintf (format, ap); - va_end (ap); - } }
-static char *stringCopy (const char *const string) -{ - char* result = NULL; - if (string != NULL) - result = eStrdup (string); - return result; -} - -static void freeString (char **const pString) -{ - if (*pString != NULL) - { - eFree (*pString); - *pString = NULL; - } -} - extern void freeList (stringList** const pList) { if (*pList != NULL) @@ -265,306 +119,17 @@
extern void setDefaultTagFileName (void) { - if (Option.tagFileName != NULL) - ; /* accept given name */ - else if (Option.etags) - Option.tagFileName = stringCopy (ETAGS_FILE); - else - Option.tagFileName = stringCopy (CTAGS_FILE); + Option.tagFileName = eStrdup (CTAGS_FILE); }
-extern void checkOptions (void) -{ - const char* notice; - if (Option.xref) - { - notice = "xref output"; - if (Option.include.fileNames) - { - error (WARNING, "%s disables file name tags", notice); - Option.include.fileNames = FALSE; - } - } - if (Option.append) - { - notice = "append mode is not compatible with"; - if (isDestinationStdout ()) - error (FATAL, "%s tags to stdout", notice); - } - if (Option.filter) - { - notice = "filter mode"; - if (Option.printTotals) - { - error (WARNING, "%s disables totals", notice); - Option.printTotals = FALSE; - } - if (Option.tagFileName != NULL) - error (WARNING, "%s ignores output tag file name", notice); - } -#ifdef UPDATE_ENABLED - if (Option.update) - { - notice = "update option is not compatible with"; - if (Option.etags) - error (FATAL, "%s emacs-style tags", notice); - if (Option.filter) - error (FATAL, "%s filter option", notice); - if (isDestinationStdout ()) - error (FATAL, "%s tags to stdout", notice); - Option.append = TRUE; - } -#endif -} - -static void setEtagsMode (void) -{ - Option.etags = TRUE; - Option.sorted = FALSE; - Option.lineDirectives = FALSE; - Option.tagRelative = TRUE; -} - -extern void testEtagsInvocation (void) -{ - char* const execName = eStrdup (getExecutableName ()); - char* const etags = eStrdup (ETAGS); -#ifdef CASE_INSENSITIVE_FILENAMES - toLowerString (execName); - toLowerString (etags); -#endif - if (strstr (execName, etags) != NULL) - { - verbose ("Running in etags mode\n"); - setEtagsMode (); - } -} - /* - * Cooked argument parsing - */ - -static void parseShortOption (cookedArgs *const args) -{ - args->simple [0] = *args->shortOptions++; - args->simple [1] = '\0'; - args->item = args->simple; - if (! isCompoundOption (*args->simple)) - args->parameter = ""; - else if (*args->shortOptions == '\0') - { - argForth (args->args); - if (argOff (args->args)) - args->parameter = NULL; - else - args->parameter = argItem (args->args); - args->shortOptions = NULL; - } - else - { - args->parameter = args->shortOptions; - args->shortOptions = NULL; - } -} - -static void parseLongOption (cookedArgs *const args, const char *item) -{ - const char* const equal = strchr (item, '='); - if (equal == NULL) - { - args->item = eStrdup (item); - args->parameter = ""; - } - else - { - const size_t length = equal - item; - args->item = xMalloc (length + 1, char); - strncpy (args->item, item, length); - args->item [length] = '\0'; - args->parameter = equal + 1; - } -} - -static void cArgRead (cookedArgs *const current) -{ - char* item; - - Assert (current != NULL); - if (! argOff (current->args)) - { - item = argItem (current->args); - current->shortOptions = NULL; - Assert (item != NULL); - if (strncmp (item, "--", (size_t) 2) == 0) - { - current->isOption = TRUE; - current->longOption = TRUE; - parseLongOption (current, item + 2); - } - else if (*item == '-') - { - current->isOption = TRUE; - current->longOption = FALSE; - current->shortOptions = item + 1; - parseShortOption (current); - } - else - { - current->isOption = FALSE; - current->longOption = FALSE; - current->item = item; - current->parameter = ""; - } - } -} - -extern cookedArgs* cArgNewFromString (const char* string) -{ - cookedArgs* const result = xMalloc (1, cookedArgs); - memset (result, 0, sizeof (cookedArgs)); - result->args = argNewFromString (string); - cArgRead (result); - return result; -} - -extern cookedArgs* cArgNewFromArgv (char* const* const argv) -{ - cookedArgs* const result = xMalloc (1, cookedArgs); - memset (result, 0, sizeof (cookedArgs)); - result->args = argNewFromArgv (argv); - cArgRead (result); - return result; -} - -extern cookedArgs* cArgNewFromFile (FILE* const fp) -{ - cookedArgs* const result = xMalloc (1, cookedArgs); - memset (result, 0, sizeof (cookedArgs)); - result->args = argNewFromFile (fp); - cArgRead (result); - return result; -} - -extern cookedArgs* cArgNewFromLineFile (FILE* const fp) -{ - cookedArgs* const result = xMalloc (1, cookedArgs); - memset (result, 0, sizeof (cookedArgs)); - result->args = argNewFromLineFile (fp); - cArgRead (result); - return result; -} - -extern void cArgDelete (cookedArgs* const current) -{ - Assert (current != NULL); - argDelete (current->args); - memset (current, 0, sizeof (cookedArgs)); - eFree (current); -} - -static boolean cArgOptionPending (cookedArgs* const current) -{ - boolean result = FALSE; - if (current->shortOptions != NULL) - if (*current->shortOptions != '\0') - result = TRUE; - return result; -} - -extern boolean cArgOff (cookedArgs* const current) -{ - Assert (current != NULL); - return (boolean) (argOff (current->args) && ! cArgOptionPending (current)); -} - -extern boolean cArgIsOption (cookedArgs* const current) -{ - Assert (current != NULL); - return current->isOption; -} - -extern const char* cArgItem (cookedArgs* const current) -{ - Assert (current != NULL); - return current->item; -} - -extern void cArgForth (cookedArgs* const current) -{ - Assert (current != NULL); - Assert (! cArgOff (current)); - if (cArgOptionPending (current)) - parseShortOption (current); - else - { - Assert (! argOff (current->args)); - argForth (current->args); - if (! argOff (current->args)) - cArgRead (current); - else - { - current->isOption = FALSE; - current->longOption = FALSE; - current->shortOptions = NULL; - current->item = NULL; - current->parameter = NULL; - } - } -} - -/* * File extension and language mapping */ - -static void addExtensionList (stringList *const slist, - const char *const elist, const boolean clear) -{ - char *const extensionList = eStrdup (elist); - const char *extension = NULL; - boolean first = TRUE; - - if (clear) - { - verbose (" clearing\n"); - stringListClear (slist); - } - verbose (" adding: "); - if (elist != NULL && *elist != '\0') - { - extension = extensionList; - if (elist [0] == EXTENSION_SEPARATOR) - ++extension; - } - while (extension != NULL) - { - char *separator = strchr (extension, EXTENSION_SEPARATOR); - if (separator != NULL) - *separator = '\0'; - verbose ("%s%s", first ? "" : ", ", - *extension == '\0' ? "(NONE)" : extension); - stringListAdd (slist, vStringNewInit (extension)); - first = FALSE; - if (separator == NULL) - extension = NULL; - else - extension = separator + 1; - } - if (Option.verbose) - { - printf ("\n now: "); - stringListPrint (slist); - putchar ('\n'); - } - eFree (extensionList); -} - extern const char *fileExtension (const char *const fileName) { const char *extension; const char *pDelimiter = NULL; -#ifdef QDOS - pDelimiter = strrchr (fileName, '_'); -#endif + if (pDelimiter == NULL) pDelimiter = strrchr (fileName, '.');
@@ -582,330 +147,19 @@ */ extern boolean isIncludeFile (const char *const fileName) { - boolean result = FALSE; - const char *const extension = fileExtension (fileName); - if (Option.headerExt != NULL) - result = stringListExtensionMatched (Option.headerExt, extension); - return result; + return FALSE; }
-static void processLanguageForceOption (const char *const option, - const char *const parameter) -{ - langType language; - if (stricmp (parameter, "auto") == 0) - language = LANG_AUTO; - else - language = getNamedLanguage (parameter);
- if (strcmp (option, "lang") == 0 || strcmp (option, "language") == 0) - error (WARNING, - ""--%s" option is obsolete; use "--language-force" instead", - option); - if (language == LANG_IGNORE) - error (FATAL, "Uknown language specified in "%s" option", option); - else - Option.language = language; -} - -static char* skipPastMap (char* p) -{ - while (*p != EXTENSION_SEPARATOR && - *p != PATTERN_START && *p != ',' && *p != '\0') - ++p; - return p; -} - -/* Parses the mapping beginning at `map', adds it to the language map, and - * returns first character past the map. - */ -static char* addLanguageMap (const langType language, char* map) -{ - char* p = NULL; - const char first = *map; - if (first == EXTENSION_SEPARATOR) /* extension map */ - { - ++map; - p = skipPastMap (map); - if (*p == '\0') - { - verbose (" .%s", map); - addLanguageExtensionMap (language, map); - p = map + strlen (map); - } - else - { - const char separator = *p; - *p = '\0'; - verbose (" .%s", map); - addLanguageExtensionMap (language, map); - *p = separator; - } - } - else if (first == PATTERN_START) /* pattern map */ - { - ++map; - for (p = map ; *p != PATTERN_STOP && *p != '\0' ; ++p) - { - if (*p == '\' && *(p + 1) == PATTERN_STOP) - ++p; - } - if (*p == '\0') - error (FATAL, "Unterminated file name pattern for %s language", - getLanguageName (language)); - else - { - *p++ = '\0'; - verbose (" (%s)", map); - addLanguagePatternMap (language, map); - } - } - else - error (FATAL, "Badly formed language map for %s language", - getLanguageName (language)); - return p; -} - -static char* processLanguageMap (char* map) -{ - char* const separator = strchr (map, ':'); - char* result = NULL; - if (separator != NULL) - { - langType language; - char *list = separator + 1; - boolean clear = FALSE; - *separator = '\0'; - language = getNamedLanguage (map); - if (language != LANG_IGNORE) - { - char* p; - if (*list == '+') - ++list; - else - clear = TRUE; - for (p = list ; *p != ',' && *p != '\0' ; ++p) /*no-op*/ ; - if (strnicmp (list, "default", p - list) == 0) - { - verbose (" Restoring default %s language map: ", getLanguageName (language)); - installLanguageMapDefault (language); - list = p; - } - else - { - if (clear) - { - verbose (" Setting %s language map:", getLanguageName (language)); - clearLanguageMap (language); - } - else - verbose (" Adding to %s language map:", getLanguageName (language)); - while (list != NULL && *list != '\0' && *list != ',') - list = addLanguageMap (language, list); - verbose ("\n"); - } - if (list != NULL && *list == ',') - ++list; - result = list; - } - } - return result; -} - -static void processLanguageMapOption (const char *const option, - const char *const parameter) -{ - char *const maps = eStrdup (parameter); - char *map = maps; - - if (strcmp (parameter, "default") == 0) - { - verbose (" Restoring default language maps:\n"); - installLanguageMapDefaults (); - } - else while (map != NULL && *map != '\0') - { - char* const next = processLanguageMap (map); - if (next == NULL) - error (WARNING, "Unknown language specified in "%s" option", option); - map = next; - } - eFree (maps); -} - -static void processLanguageListOption (const char *const option, - const char *const parameter) -{ - char *const langs = eStrdup (parameter); - enum { Add, Remove, Replace } mode = Replace; - boolean first = TRUE; - char *lang = langs; - const char* prefix = ""; - verbose (" Enabled languages: "); - while (lang != NULL) - { - char *const end = strchr (lang, ','); - if (lang [0] == '+') - { - ++lang; - mode = Add; - prefix = "+ "; - } - else if (lang [0] == '-') - { - ++lang; - mode = Remove; - prefix = "- "; - } - if (mode == Replace) - enableLanguages (FALSE); - if (end != NULL) - *end = '\0'; - if (lang [0] != '\0') - { - if (strcmp (lang, "all") == 0) - enableLanguages ((boolean) (mode != Remove)); - else - { - const langType language = getNamedLanguage (lang); - if (language == LANG_IGNORE) - error (WARNING, "Unknown language specified in "%s" option", option); - else - enableLanguage (language, (boolean) (mode != Remove)); - } - verbose ("%s%s%s", (first ? "" : ", "), prefix, lang); - prefix = ""; - first = FALSE; - if (mode == Replace) - mode = Add; - } - lang = (end != NULL ? end + 1 : NULL); - } - verbose ("\n"); - eFree (langs); -} - -static void processOptionFile (const char *const option, - const char *const parameter) -{ - if (parameter == NULL || parameter [0] == '\0') - error (WARNING, "no option file supplied for "%s"", option); - else if (! parseFileOptions (parameter)) - error (FATAL | PERROR, "cannot open option file "%s"", parameter); -} - -static void installHeaderListDefaults (void) -{ - Option.headerExt = stringListNewFromArgv (HeaderExtensions); - if (Option.verbose) - { - printf (" Setting default header extensions: "); - stringListPrint (Option.headerExt); - putchar ('\n'); - } -} - -static void processHeaderListOption (const int option, const char *parameter) -{ - /* Check to make sure that the user did not enter "ctags -h *.c" - * by testing to see if the list is a filename that exists. - */ - if (doesFileExist (parameter)) - error (FATAL, "-%c: Invalid list", option); - if (strcmp (parameter, "default") == 0) - installHeaderListDefaults (); - else - { - boolean clear = TRUE; - - if (parameter [0] == '+') - { - ++parameter; - clear = FALSE; - } - if (Option.headerExt == NULL) - Option.headerExt = stringListNew (); - verbose (" Header Extensions:\n"); - addExtensionList (Option.headerExt, parameter, clear); - } -} - -/* - * Token ignore processing - */ - /* Determines whether or not "name" should be ignored, per the ignore list. */ extern boolean isIgnoreToken (const char *const name, boolean *const pIgnoreParens, const char **const replacement) { - boolean result = FALSE; - - if (Option.ignore != NULL) - { - const size_t nameLen = strlen (name); - unsigned int i; - - if (pIgnoreParens != NULL) - *pIgnoreParens = FALSE; - - for (i = 0 ; i < stringListCount (Option.ignore) ; ++i) - { - vString *token = stringListItem (Option.ignore, i); - - if (strncmp (vStringValue (token), name, nameLen) == 0) - { - const size_t tokenLen = vStringLength (token); - - if (nameLen == tokenLen) - { - result = TRUE; - break; - } - else if (tokenLen == nameLen + 1 && - vStringChar (token, tokenLen - 1) == '+') - { - result = TRUE; - if (pIgnoreParens != NULL) - *pIgnoreParens = TRUE; - break; - } - else if (vStringChar (token, nameLen) == '=') - { - if (replacement != NULL) - *replacement = vStringValue (token) + nameLen + 1; - break; - } - } - } - } - return result; + return FALSE; }
-static void saveIgnoreToken (vString *const ignoreToken) -{ - if (Option.ignore == NULL) - Option.ignore = stringListNew (); - stringListAdd (Option.ignore, ignoreToken); - verbose (" ignore token: %s\n", vStringValue (ignoreToken)); -} - -static void readIgnoreList (const char *const list) -{ - char* newList = stringCopy (list); - const char *token = strtok (newList, IGNORE_SEPARATORS); - - while (token != NULL) - { - vString *const entry = vStringNewInit (token); - - saveIgnoreToken (entry); - token = strtok (NULL, IGNORE_SEPARATORS); - } - eFree (newList); -} - void addIgnoreListFromFile (const char *const fileName) { stringList* tokens = stringListNewFromFile (fileName); @@ -915,569 +169,13 @@ stringListCombine (Option.ignore, tokens); }
-static void processIgnoreOption (const char *const list) -{ - if (strchr ("@./\", list [0]) != NULL) - { - const char* fileName = (*list == '@') ? list + 1 : list; - addIgnoreListFromFile (fileName); - } -#if defined (MSDOS) || defined (WIN32) || defined (OS2) - else if (isalpha (list [0]) && list [1] == ':') - addIgnoreListFromFile (list); -#endif - else if (strcmp (list, "-") == 0) - { - freeList (&Option.ignore); - verbose (" clearing list\n"); - } - else - readIgnoreList (list); -}
-/* - * Specific option processing - */
-static void printfFeatureList (void) -{ - int i; - - for (i = 0 ; Features [i] != NULL ; ++i) - { - if (i == 0) - printf (" Optional compiled features: "); - printf ("%s+%s", (i>0 ? ", " : ""), Features [i]); -#ifdef CUSTOM_CONFIGURATION_FILE - if (strcmp (Features [i], "custom-conf") == 0) - printf ("=%s", CUSTOM_CONFIGURATION_FILE); -#endif - } - if (i > 0) - putchar ('\n'); -} - -static void printProgramIdentification (void) -{ - printf ("%s %s, Copyright (C) 1996-2001 %s\n", - PROGRAM_NAME, PROGRAM_VERSION, AUTHOR_NAME); - printf (" Addresses: <%s>, %s\n", AUTHOR_EMAIL, PROGRAM_URL); - printfFeatureList (); -} - -static void printInvocationDescription (void) -{ - printf (INVOCATION, getExecutableName ()); -} - -static void printOptionDescriptions (const optionDescription *const optDesc) -{ - int i; - for (i = 0 ; optDesc [i].description != NULL ; ++i) - { - if (! Option.etags || optDesc [i].usedByEtags) - puts (optDesc [i].description); - } -} - -static void printHelp (const optionDescription *const optDesc) -{ - - printProgramIdentification (); - putchar ('\n'); - printInvocationDescription (); - putchar ('\n'); - printOptionDescriptions (optDesc); -} - -static void processExcmdOption (const char *const option, - const char *const parameter) -{ - switch (*parameter) - { - case 'm': Option.locate = EX_MIX; break; - case 'n': Option.locate = EX_LINENUM; break; - case 'p': Option.locate = EX_PATTERN; break; - default: - error (FATAL, "Invalid value for "%s" option", option); - break; - } -} - -static void processFormatOption (const char *const option, - const char *const parameter) -{ - unsigned int format; - - if (sscanf (parameter, "%u", &format) < 1) - error (FATAL, "Invalid value for "%s" option",option); - else if (format <= (unsigned int) MaxSupportedTagFormat) - Option.tagFileFormat = format; - else - error (FATAL, "Unsupported value for "%s" option", option); -} - -static void processEtagsInclude (const char *const __unused__ option, - const char *const parameter) -{ - vString *const file = vStringNewInit (parameter); - if (Option.etagsInclude == NULL) - Option.etagsInclude = stringListNew (); - stringListAdd (Option.etagsInclude, file); -} - -static void processFilterTerminatorOption (const char *const __unused__ option, - const char *const parameter) -{ - freeString (&Option.filterTerminator); - Option.filterTerminator = stringCopy (parameter); -} - -static void processExtensionFieldsOption (const char *const option, - const char *const parameter) -{ - struct sExtFields *const field = &Option.extensionFields; - const char *p = parameter; - boolean mode = TRUE; - int c; - - if (*p != '+' && *p != '-') - { - field->access = FALSE; - field->fileScope = FALSE; - field->implementation = FALSE; - field->inheritance = FALSE; - field->kind = FALSE; - field->kindKey = FALSE; - field->kindLong = FALSE; - field->language = FALSE; - field->scope = FALSE; - field->argList = FALSE; - } - while ((c = *p++) != '\0') switch (c) - { - case '+': mode = TRUE; break; - case '-': mode = FALSE; break; - - case 'a': field->access = mode; break; - case 'f': field->fileScope = mode; break; - case 'm': field->implementation = mode; break; - case 'i': field->inheritance = mode; break; - case 'k': field->kind = mode; break; - case 'K': field->kindLong = mode; break; - case 'l': field->language = mode; break; - case 'n': field->lineNumber = mode; break; - case 's': field->scope = mode; break; - case 'z': field->kindKey = mode; break; - case 'P': field->filePosition = mode; break; - case 'A': field->argList = mode; break; - - default: error(WARNING, "Unsupported parameter '%c' for "%s" option", - c, option); - break; - } -} - -static void processExtraTagsOption (const char *const option, - const char *const parameter) -{ - struct sInclude *const inc = &Option.include; - const char *p = parameter; - boolean mode = TRUE; - int c; - - if (*p != '+' && *p != '-') - { - inc->fileNames = FALSE; - inc->qualifiedTags = FALSE; -#if 0 - inc->fileScope = FALSE; -#endif - } - while ((c = *p++) != '\0') switch (c) - { - case '+': mode = TRUE; break; - case '-': mode = FALSE; break; - - case 'f': inc->fileNames = mode; break; - case 'q': inc->qualifiedTags = mode; break; -#if 0 - case 'F': inc->fileScope = mode; break; -#endif - - default: error(WARNING, "Unsupported parameter '%c' for "%s" option", - c, option); - break; - } -} - /* - * Option tables - */ - -static parametricOption ParametricOptions [] = { - { "etags-include", processEtagsInclude, FALSE }, - { "exclude", processExcludeOption, FALSE }, - { "excmd", processExcmdOption, FALSE }, - { "extra", processExtraTagsOption, FALSE }, - { "fields", processExtensionFieldsOption, FALSE }, - { "filter-terminator", processFilterTerminatorOption, TRUE }, - { "format", processFormatOption, TRUE }, - { "lang", processLanguageForceOption, FALSE }, - { "language", processLanguageForceOption, FALSE }, - { "language-force", processLanguageForceOption, FALSE }, - { "languages", processLanguageListOption, FALSE }, - { "langdef", processLanguageDefineOption, FALSE }, - { "langmap", processLanguageMapOption, FALSE }, - { "options", processOptionFile, FALSE }, -}; - -static booleanOption BooleanOptions [] = { - { "append", &Option.append, TRUE }, - { "file-scope", &Option.include.fileScope, FALSE }, - { "file-tags", &Option.include.fileNames, FALSE }, - { "filter", &Option.filter, TRUE }, - { "if0", &Option.if0, FALSE }, - { "kind-long", &Option.kindLong, TRUE }, - { "line-directives",&Option.lineDirectives, FALSE }, - { "nest",&Option.nestFunction, FALSE }, - { "links", &Option.followLinks, FALSE }, -#ifdef RECURSE_SUPPORTED - { "recurse", &Option.recurse, FALSE }, -#endif - { "sort", &Option.sorted, TRUE }, - { "tag-relative", &Option.tagRelative, TRUE }, - { "totals", &Option.printTotals, TRUE }, - { "verbose", &Option.verbose, FALSE }, -}; - -/* * Generic option parsing */ +#define readOptionConfiguration +#define initOptions +#define freeOptionResources
-static void checkOptionOrder (const char* const option) -{ - if (ParsedLeadingOptions) - error (FATAL, "-%s option may not follow a file name", option); -} - -static boolean processParametricOption (const char *const option, - const char *const parameter) -{ - const int count = sizeof (ParametricOptions) / sizeof (parametricOption); - boolean found = FALSE; - int i; - - for (i = 0 ; i < count && ! found ; ++i) - { - parametricOption* const entry = &ParametricOptions [i]; - if (strcmp (option, entry->name) == 0) - { - found = TRUE; - if (entry->initOnly) - checkOptionOrder (option); - (entry->handler) (option, parameter); - } - } - return found; -} - -static boolean getBooleanOption (const char *const option, - const char *const parameter) -{ - boolean selection = TRUE; - - if (parameter [0] == '\0') - selection = TRUE; - else if (strcmp (parameter, "0" ) == 0 || - strcmp (parameter, "no" ) == 0 || - strcmp (parameter, "off") == 0) - selection = FALSE; - else if (strcmp (parameter, "1" ) == 0 || - strcmp (parameter, "yes") == 0 || - strcmp (parameter, "on" ) == 0) - selection = TRUE; - else - error (FATAL, "Invalid value for "%s" option", option); - - return selection; -} - -static boolean processBooleanOption (const char *const option, - const char *const parameter) -{ - const int count = sizeof (BooleanOptions) / sizeof (booleanOption); - boolean found = FALSE; - int i; - - for (i = 0 ; i < count && ! found ; ++i) - { - booleanOption* const entry = &BooleanOptions [i]; - if (strcmp (option, entry->name) == 0) - { - found = TRUE; - if (entry->initOnly) - checkOptionOrder (option); - *entry->pValue = getBooleanOption (option, parameter); - } - } - return found; -} - -static void processLongOption (const char *const option, - const char *const parameter) -{ - if (parameter == NULL || *parameter == '\0') - verbose (" Option: --%s\n", option); - else - verbose (" Option: --%s=%s\n", option, parameter); - - if (processBooleanOption (option, parameter)) - ; - else if (processParametricOption (option, parameter)) - ; - else if (processKindOption (option, parameter)) - ; -#ifdef HAVE_REGEX - else if (processRegexOption (option, parameter)) - ; -#endif -#define isOption(item) (boolean) (strcmp (item,option) == 0) - else if (isOption ("help")) - { - printHelp (LongOptionDescription); - printKindOptions (); - exit (0); - } - else if (isOption ("license")) - { - printProgramIdentification (); - puts (""); - puts (License); - exit (0); - } - else if (isOption ("version")) - { - printProgramIdentification (); - exit (0); - } -#ifndef RECURSE_SUPPORTED - else if (isOption ("recurse")) - error (WARNING, "%s option not supported on this host", option); -#endif - else - error (FATAL, "Unknown option: --%s", option); -#undef isOption -} - -static void processShortOption (const char *const option, - const char *const parameter) -{ - if (parameter == NULL || *parameter == '\0') - verbose (" Option: -%s\n", option); - else - verbose (" Option: -%s %s\n", option, parameter); - - if (isCompoundOption (*option) && *parameter == '\0') - error (FATAL, "Missing parameter for "%s" option", option); - else switch (*option) - { - case '?': - printHelp (LongOptionDescription); - exit (0); - break; - case 'a': - checkOptionOrder (option); - Option.append = TRUE; - break; - case 'B': - Option.backward = TRUE; - break; - case 'e': - checkOptionOrder (option); - setEtagsMode (); - break; - case 'f': - case 'o': - checkOptionOrder (option); - if (Option.tagFileName != NULL) - { - error (WARNING, - "-%s option specified more than once, last value used", - option); - freeString (&Option.tagFileName); - } - else if (parameter [0] == '-' && parameter [1] != '\0') - error (FATAL, "output file name may not begin with a '-'"); - Option.tagFileName = stringCopy (parameter); - break; - case 'F': - Option.backward = FALSE; - break; - case 'h': - processHeaderListOption (*option, parameter); - break; - case 'i': - processLegacyKindOption (parameter); - break; - case 'I': - processIgnoreOption (parameter); - break; - case 'L': - if (Option.fileList != NULL) - { - error (WARNING, - "-%s option specified more than once, last value used", - option); - freeString (&Option.fileList); - } - Option.fileList = stringCopy (parameter); - break; - case 'n': - Option.locate = EX_LINENUM; - break; - case 'N': - Option.locate = EX_PATTERN; - break; - case 'R': -#ifdef RECURSE_SUPPORTED - Option.recurse = TRUE; -#else - error (WARNING, "-%s option not supported on this host", option); -#endif - break; - case 'u': - checkOptionOrder (option); - Option.sorted = FALSE; - break; - case 'V': - Option.verbose = TRUE; - break; - case 'w': - /* silently ignored */ - break; - case 'x': - checkOptionOrder (option); - Option.xref = TRUE; - break; - default: - error (FATAL, "Unknown option: -%s", option); - break; - } -} - -extern void parseOption (cookedArgs* const args) -{ - Assert (! cArgOff (args)); - if (args->isOption) - { - if (args->longOption) - processLongOption (args->item, args->parameter); - else - { - const char *parameter = args->parameter; - while (*parameter == ' ') - ++parameter; - processShortOption (args->item, parameter); - } - cArgForth (args); - } -} - -extern void parseOptions (cookedArgs* const args) -{ - while (! cArgOff (args) && cArgIsOption (args)) - parseOption (args); - if (! cArgOff (args) && ! cArgIsOption (args)) - ParsedLeadingOptions = TRUE; -} - -static boolean parseFileOptions (const char* const fileName) -{ - boolean fileFound = FALSE; - FILE* const fp = fopen (fileName, "r"); - if (fp != NULL) - { - cookedArgs* const args = cArgNewFromLineFile (fp); - verbose ("Reading options from %s\n", fileName); - parseOptions (args); - cArgDelete (args); - fclose (fp); - fileFound = TRUE; - } - return fileFound; -} - -extern void previewFirstOption (cookedArgs* const args) -{ - if (cArgIsOption (args) && - (strcmp (args->item, "V") == 0 || strcmp (args->item, "verbose") == 0)) - { - parseOption (args); - } -} - -static void parseConfigurationFileOptions (void) -{ - const char* const home = getenv ("HOME"); - parseFileOptions ("/etc/ctags.conf"); - parseFileOptions ("/usr/local/etc/ctags.conf"); -#ifdef CUSTOM_CONFIGURATION_FILE - parseFileOptions (CUSTOM_CONFIGURATION_FILE); -#endif - if (home != NULL) - { - vString* const dotFile = combinePathAndFile (home, ".ctags"); - parseFileOptions (vStringValue (dotFile)); - vStringDelete (dotFile); - } - parseFileOptions (".ctags"); -} - -static void parseEnvironmentOptions (void) -{ - const char *envOptions = NULL; - - if (Option.etags) - envOptions = getenv (ETAGS_ENVIRONMENT); - if (envOptions == NULL) - envOptions = getenv (CTAGS_ENVIRONMENT); - if (envOptions != NULL && envOptions [0] != '\0') - { - cookedArgs* const args = cArgNewFromString (envOptions); - verbose ("Reading options from $CTAGS\n"); - parseOptions (args); - cArgDelete (args); - } -} - -extern void readOptionConfiguration (void) -{ - parseConfigurationFileOptions (); - parseEnvironmentOptions (); -} - -/* -* Option initialization -*/ - -extern void initOptions (void) -{ - verbose ("Setting option defaults\n"); - installHeaderListDefaults (); - verbose (" Installing default language mappings:\n"); - installLanguageMapDefaults (); -} - -extern void freeOptionResources (void) -{ - freeString (&Option.tagFileName); - freeString (&Option.fileList); - freeString (&Option.filterTerminator); - - freeList (&Option.ignore); - freeList (&Option.headerExt); - freeList (&Option.etagsInclude); -} - /* vi:set tabstop=8 shiftwidth=4: */
Modified: trunk/tagmanager/options.h =================================================================== --- trunk/tagmanager/options.h 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/tagmanager/options.h 2006-06-24 14:36:35 UTC (rev 474) @@ -32,20 +32,7 @@ * DATA DECLARATIONS */
-typedef enum { OPTION_NONE, OPTION_SHORT, OPTION_LONG } optionType;
-typedef struct sCookedArgs { -/* private */ - Arguments* args; - char *shortOptions; - char simple[2]; - boolean isOption; - boolean longOption; - const char* parameter; -/* public */ - char* item; -} cookedArgs; - /* This stores the command line options. */ typedef struct sOptionValues { @@ -71,7 +58,6 @@ stringList* ignore; /* -I name of file containing tokens to ignore */ boolean append; /* -a append to "tags" file */ boolean backward; /* -B regexp patterns search backwards */ - boolean etags; /* -e output Emacs style tags file */ enum eLocate { EX_MIX, /* line numbers for defines, patterns otherwise */ EX_LINENUM, /* -n only line numbers in tag file */ @@ -97,10 +83,6 @@ boolean printTotals; /* --totals print cumulative statistics */ boolean lineDirectives; /* --linedirectives process #line directives */ boolean nestFunction; /* --nest Nest inside function blocks for tags */ -#ifdef TM_DEBUG - long debugLevel; /* -D debugging output */ - unsigned long breakLine;/* -b source line at which to call lineBreak() */ -#endif } optionValues;
/* @@ -114,25 +96,10 @@ extern void verbose (const char *const format, ...) __printf__ (1, 2); extern void freeList (stringList** const pString); extern void setDefaultTagFileName (void); -extern void checkOptions (void); -extern void testEtagsInvocation (void);
-extern cookedArgs* cArgNewFromString (const char* string); -extern cookedArgs* cArgNewFromArgv (char* const* const argv); -extern cookedArgs* cArgNewFromFile (FILE* const fp); -extern cookedArgs* cArgNewFromLineFile (FILE* const fp); -extern void cArgDelete (cookedArgs* const current); -extern boolean cArgOff (cookedArgs* const current); -extern boolean cArgIsOption (cookedArgs* const current); -extern const char* cArgItem (cookedArgs* const current); -extern void cArgForth (cookedArgs* const current); - extern const char *fileExtension (const char *const fileName); extern boolean isIncludeFile (const char *const fileName); extern boolean isIgnoreToken (const char *const name, boolean *const pIgnoreParens, const char **const replacement); -extern void parseOption (cookedArgs* const cargs); -extern void parseOptions (cookedArgs* const cargs); -extern void previewFirstOption (cookedArgs* const cargs); extern void readOptionConfiguration (void); extern void initOptions (void); extern void freeOptionResources (void);
Modified: trunk/tagmanager/parse.c =================================================================== --- trunk/tagmanager/parse.c 2006-06-23 14:00:22 UTC (rev 473) +++ trunk/tagmanager/parse.c 2006-06-24 14:36:35 UTC (rev 474) @@ -239,9 +239,6 @@ LanguageTable [language]->currentExtensions = stringListNewFromArgv (LanguageTable [language]->extensions); } - if (Option.verbose) - printLanguageMap (language); - verbose ("\n"); }
extern void installLanguageMapDefaults (void) @@ -249,7 +246,6 @@ unsigned int i; for (i = 0 ; i < LanguageCount ; ++i) { - //verbose (" %s: ", getLanguageName (i)); installLanguageMapDefault (i); } } @@ -307,7 +303,6 @@ builtInCount = sizeof (BuiltInParsers) / sizeof (BuiltInParsers [0]); LanguageTable = xMalloc (builtInCount, parserDefinition*);
- verbose ("Installing parsers: "); for (i = 0 ; i < builtInCount ; ++i) { parserDefinition* const def = (*BuiltInParsers [i]) (); @@ -331,13 +326,11 @@ accepted = TRUE; if (accepted) { - verbose ("%s%s", i > 0 ? ", " : "", def->name); def->id = LanguageCount++; LanguageTable [def->id] = def; } } } - verbose ("\n"); enableLanguages (TRUE); initializeParsers (); } @@ -603,8 +596,6 @@
if (fileOpen (fileName, language)) { - if (Option.etags) - beginEtagsFile ();
makeFileTag (fileName);
@@ -613,8 +604,6 @@ else if (LanguageTable [language]->parser2 != NULL) retried = LanguageTable [language]->parser2 (passCount);
- if (Option.etags) - endEtagsFile (getSourceFileTagPath ());
fileClose (); } @@ -649,23 +638,13 @@ if (Option.language == LANG_AUTO) language = getFileLanguage (fileName); Assert (language != LANG_AUTO); - if (language == LANG_IGNORE) - verbose ("ignoring %s (unknown language)\n", fileName); - else if (! LanguageTable [language]->enabled) - verbose ("ignoring %s (language disabled)\n", fileName); - else - { if (Option.filter) openTagFile ();
tagFileResized = createTagsWithFallback (fileName, language);
- if (Option.filter) - closeTagFile (tagFileResized); addTotals (1, 0L, 0L);
- return tagFileResized; - } return tagFileResized; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.