[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] make suffix list of include file configurable
From: |
Hideki IWAMOTO |
Subject: |
Re: [PATCH] make suffix list of include file configurable |
Date: |
Wed, 01 Sep 2004 22:28:36 +0900 |
On Mon, 30 Aug 2004 22:33:56 +0900, Hideki IWAMOTO wrote...
> This patch makes suffix list of include file configurable.
In addition to previous change, I made language mapping configurable.
The interpretation routine of mapping is moved to library from gctags,
and it is shared with htags.
How about this?
Index: gctags/gctags.c
===================================================================
RCS file: /cvsroot/global/global/gctags/gctags.c,v
retrieving revision 1.24
diff -u -r1.24 gctags.c
--- gctags/gctags.c 1 Sep 2004 10:02:28 -0000 1.24
+++ gctags/gctags.c 1 Sep 2004 13:00:15 -0000
@@ -46,7 +46,6 @@
int main(int, char **);
static void usage(void);
static void help(void);
-static int match_suffix_list(const char *, const char *);
struct words {
const char *name;
@@ -62,7 +61,6 @@
*/
static const char *default_map =
"c:.c.h,yacc:.y,asm:.s.S,java:.java,cpp:.c++.cc.cpp.cxx.hxx.hpp.C.H,php:.php.php3.phtml";
static char *langmap;
-static STRBUF *active_map;
int bflag; /* -b: force level 1 block start */
int dflag; /* -d: treat #define with no argument */
@@ -119,7 +117,6 @@
char **argv;
{
char *p;
- int flag;
int optchar;
int option_index = 0;
@@ -172,25 +169,7 @@
fprintf(stdout, "Part of GLOBAL\n");
exit(0);
}
- /*
- * construct language map.
- */
- active_map = strbuf_open(0);
- strbuf_puts(active_map, (langmap) ? langmap : default_map);
- flag = 0;
- for (p = strbuf_value(active_map); *p; p++) {
- /*
- * "c:.c.h,java:.java,cpp:.C.H"
- */
- if ((flag == 0 && *p == ',') || (flag == 1 && *p == ':'))
- die_with_code(2, "syntax error in --langmap option.");
- if (*p == ':' || *p == ',') {
- flag ^= 1;
- *p = 0;
- }
- }
- if (flag == 0)
- die_with_code(2, "syntax error in --langmap option.");
+ setup_langmap(langmap ? langmap : default_map);
argc -= optind;
argv += optind;
@@ -245,8 +224,7 @@
* pick up files and parse them.
*/
for (; argc > 0; argv++, argc--) {
- char *lang = NULL;
- char *suffix, *list, *tail;
+ const char *lang, *suffix;
#if defined(_WIN32) || defined(__DJGPP__)
/* Lower case the file name since names are case insensitive */
@@ -256,18 +234,7 @@
suffix = locatestring(argv[0], ".", MATCH_LAST);
if (!suffix)
continue;
- list = strbuf_value(active_map);
- tail = list + strbuf_getlen(active_map);
-
- /* check whether or not list includes suffix. */
- while (list < tail) {
- lang = list;
- list = lang + strlen(lang) + 1;
- if (match_suffix_list(suffix, list))
- break;
- lang = NULL;
- list += strlen(list) + 1;
- }
+ lang = decide_lang(suffix);
if (lang == NULL)
continue;
@@ -305,23 +272,6 @@
return 0;
}
-/*
- * return true if suffix matches with one in suffix list.
- */
-int
-match_suffix_list(suffix, list)
- const char *suffix;
- const char *list;
-{
- while (*list) {
- if (locatestring(list, suffix, MATCH_AT_FIRST))
- return 1;
- for (list++; *list && *list != '.'; list++)
- ;
- }
- return 0;
-}
-
int
cmp(s1, s2)
const void *s1, *s2;
Index: htags/fileindex.c
===================================================================
RCS file: /cvsroot/global/global/htags/fileindex.c,v
retrieving revision 1.7
diff -u -r1.7 fileindex.c
--- htags/fileindex.c 5 Aug 2004 12:24:37 -0000 1.7
+++ htags/fileindex.c 1 Sep 2004 13:00:15 -0000
@@ -583,17 +583,27 @@
*/
struct data *inc;
int flags = REG_EXTENDED;
- char *pattern;
- regex_t is_include_file, is_c_file;
+ regex_t is_include_file;
if (w32)
flags |= REG_ICASE;
- pattern = "\\.(h|hxx|hpp|H|inc\\.php)$";
- if (regcomp(&is_include_file, pattern, flags) != 0)
- die("cannot compile regular expression '%s'.", pattern);
- pattern = "\\.(h|c|y|c\\+\\+|cc|cpp|cxx|hxx|hpp|C|H)$";
- if (regcomp(&is_c_file, pattern, flags) != 0)
- die("cannot compile regular expression '%s'.", pattern);
+ strbuf_reset(sb);
+ strbuf_puts(sb, "\\.(");
+ {
+ char *p = include_file_suffixes;
+ int c;
+
+ while ((c = (unsigned char)*p++) != '\0') {
+ if (isregexchar(c))
+ strbuf_putc(sb, '\\');
+ else if (c == ',')
+ c = '|';
+ strbuf_putc(sb, c);
+ }
+ }
+ strbuf_puts(sb, ")$");
+ if (regcomp(&is_include_file, strbuf_value(sb), flags) != 0)
+ die("cannot compile regular expression '%s'.",
strbuf_value(sb));
/*
* preparations.
@@ -767,7 +777,15 @@
}
strbuf_sprintf(sb, " TARGET=%s TITLE='%s'>", target, _);
if (icon_list) {
- char *text_icon = regexec(&is_c_file, _, 0, 0, 0) == 0
? c_icon : file_icon;
+ const char *lang, *suffix, *text_icon;
+
+ if ((suffix = locatestring(_, ".", MATCH_LAST)) != NULL
+ && (lang = decide_lang(suffix)) != NULL
+ && (strcmp(lang, "c") == 0 || strcmp(lang, "cpp")
== 0
+ || strcmp(lang, "yacc") == 0))
+ text_icon = c_icon;
+ else
+ text_icon = file_icon;
strbuf_puts(sb, "<IMG SRC=");
if (count_stack(dirstack))
strbuf_puts(sb, "../");
Index: htags/htags.c
===================================================================
RCS file: /cvsroot/global/global/htags/htags.c,v
retrieving revision 1.13
diff -u -r1.13 htags.c
--- htags/htags.c 31 Aug 2004 15:44:38 -0000 1.13
+++ htags/htags.c 1 Sep 2004 13:00:15 -0000
@@ -195,6 +195,8 @@
int cgi = 1; /* 1: make cgi-bin/ */
int definition_header=NO_HEADER; /* (NO|BEFORE|RIGHT|AFTER)_HEADER */
char *htags_options = NULL;
+char *include_file_suffixes = "h,hxx,hpp,H,inc.php";
+static char *htags_langmap =
"c:.c,yacc:.y,asm:.s.S,java:.java,cpp:.c++.cc.cpp.cxx.h.hxx.hpp.C.H,php:.php.php3.phtml";
static struct option const long_options[] = {
{"alphabet", no_argument, NULL, 'a'},
@@ -1182,6 +1184,20 @@
free(p);
}
}
+ strbuf_reset(sb);
+ if (getconfs("include_file_suffixes", sb)) {
+ p = strdup(strbuf_value(sb));
+ if (p == NULL)
+ die("short of memory.");
+ include_file_suffixes = p;
+ }
+ strbuf_reset(sb);
+ if (getconfs("htags_langmap", sb)) {
+ p = strdup(strbuf_value(sb));
+ if (p == NULL)
+ die("short of memory.");
+ htags_langmap = p;
+ }
/* insert htags_options into the head of ARGSV array. */
strbuf_reset(sb);
if (getconfs("htags_options", sb)) {
@@ -1345,6 +1361,7 @@
basic_check();
setup_html();
configuration(argc, argv);
+ setup_langmap(htags_langmap);
save_environment(argc, argv);
/*
Index: htags/htags.h
===================================================================
RCS file: /cvsroot/global/global/htags/htags.h,v
retrieving revision 1.5
diff -u -r1.5 htags.h
--- htags/htags.h 31 Aug 2004 15:44:38 -0000 1.5
+++ htags/htags.h 1 Sep 2004 13:00:15 -0000
@@ -149,5 +149,6 @@
extern int cgi;
extern int definition_header;
extern char *htags_options;
+extern char *include_file_suffixes;
#endif /* _HTAGS_H_ */
Index: htags/manual.in
===================================================================
RCS file: /cvsroot/global/global/htags/manual.in,v
retrieving revision 1.61
diff -u -r1.61 manual.in
--- htags/manual.in 12 Aug 2004 04:54:26 -0000 1.61
+++ htags/manual.in 1 Sep 2004 13:00:15 -0000
@@ -254,6 +254,12 @@
@address@hidden(boolean)}
Enable id-utils search using CGI program. The default is false.
When this function is enabled, you cannot move hypertext from
source directory.
+ @address@hidden(comma separated list)}
+ Suffixes of include file. The default is 'h,hxx,hpp,H,inc.php'.
+ @address@hidden(comma separated list)}
+ Language mapping. Each comma-separated map consists of
+ the language name, a colon, and a list of file extensions.
+ Default mapping is
'c:.c,yacc:.y,asm:.s.S,java:.java,cpp:.c++.cc.cpp.cxx.h.hxx.hpp.C.H,php:.php.php3.phtml'.
@end_itemize
@DIAGNOSTICS
@name{Htags} exits with a non 0 value if an error occurred, 0 otherwise.
Index: htags/src2html.c
===================================================================
RCS file: /cvsroot/global/global/htags/src2html.c,v
retrieving revision 1.7
diff -u -r1.7 src2html.c
--- htags/src2html.c 10 Aug 2004 11:16:05 -0000 1.7
+++ htags/src2html.c 1 Sep 2004 13:00:15 -0000
@@ -622,6 +622,7 @@
struct data *incref;
struct anchor *ancref;
static STRBUF *define_index = NULL;
+ const char *lang, *suffix;
/*
* INCLUDED FROM index.
@@ -682,26 +683,19 @@
/*
* print source code
*/
- fprintf(out, "%s\n", verbatim_begin);
- if (locatestring(src, ".java", MATCH_AT_LAST)) {
+ fprintf(out, "%s\n", verbatim_begin);
+ if ((suffix = locatestring(src, ".", MATCH_LAST)) == NULL
+ || (lang = decide_lang(suffix)) == NULL)
+ lang = "c";
+ if (!strcmp(lang, "java")) {
java_parser_init(in);
while (javalex())
;
- } else if (locatestring(src, ".php", MATCH_AT_LAST) ||
- locatestring(src, ".php3", MATCH_AT_LAST) ||
- locatestring(src, ".phtml", MATCH_AT_LAST)) {
+ } else if (!strcmp(lang, "php")) {
php_parser_init(in);
while (phplex())
;
- } else if (locatestring(src, ".h", MATCH_AT_LAST) ||
- locatestring(src, ".c++", MATCH_AT_LAST) ||
- locatestring(src, ".cc", MATCH_AT_LAST) ||
- locatestring(src, ".cpp", MATCH_AT_LAST) ||
- locatestring(src, ".cxx", MATCH_AT_LAST) ||
- locatestring(src, ".hxx", MATCH_AT_LAST) ||
- locatestring(src, ".hpp", MATCH_AT_LAST) ||
- locatestring(src, ".C", MATCH_AT_LAST) ||
- locatestring(src, ".H", MATCH_AT_LAST)) {
+ } else if (!strcmp(lang, "cpp")) {
cpp_parser_init(in);
while (cpplex())
;
Index: libutil/Makefile.am
===================================================================
RCS file: /cvsroot/global/global/libutil/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- libutil/Makefile.am 6 Jul 2004 06:13:00 -0000 1.17
+++ libutil/Makefile.am 1 Sep 2004 13:00:15 -0000
@@ -16,13 +16,13 @@
conf.h dbop.h defined.h die.h find.h getdbpath.h global.h gparam.h \
gtagsop.h locatestring.h makepath.h path.h gpathop.h strbuf.h \
strmake.h tab.h test.h token.h usable.h version.h is_unixy.h abs2rel.h \
-split.h strlimcpy.h linetable.h env.h char.h vfind.h date.h
+split.h strlimcpy.h linetable.h env.h char.h vfind.h date.h langmap.h
libgloutil_a_SOURCES = \
conf.c dbop.c defined.c die.c find.c getdbpath.c gtagsop.c locatestring.c \
makepath.c path.c gpathop.c strbuf.c strmake.c tab.c test.c \
token.c usable.c version.c is_unixy.c abs2rel.c split.c strlimcpy.c
linetable.c \
-env.c char.c vfind.c date.c
+env.c char.c vfind.c date.c langmap.c
AM_CFLAGS = -DBINDIR='"$(bindir)"' -DDATADIR='"$(datadir)"'
Index: libutil/global.h
===================================================================
RCS file: /cvsroot/global/global/libutil/global.h,v
retrieving revision 1.14
diff -u -r1.14 global.h
--- libutil/global.h 6 Jul 2004 06:13:14 -0000 1.14
+++ libutil/global.h 1 Sep 2004 13:00:15 -0000
@@ -35,6 +35,7 @@
#include "getdbpath.h"
#include "gtagsop.h"
#include "is_unixy.h"
+#include "langmap.h"
#include "linetable.h"
#include "locatestring.h"
#include "makepath.h"
Index: libutil/langmap.c
===================================================================
RCS file: libutil/langmap.c
diff -N libutil/langmap.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libutil/langmap.c 1 Sep 2004 13:00:15 -0000
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 1998, 1999 Shigio Yamaguchi
+ * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004 Tama Communications
Corporation
+ *
+ * This file is part of GNU GLOBAL.
+ *
+ * GNU GLOBAL is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU GLOBAL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+
+#include "die.h"
+#include "locatestring.h"
+#include "strbuf.h"
+#include "langmap.h"
+
+static int match_suffix_list(const char *, const char *);
+
+static STRBUF *active_map;
+
+/*
+ * construct language map.
+ */
+void
+setup_langmap(map)
+ const char *map;
+{
+ char *p;
+ int flag;
+
+ active_map = strbuf_open(0);
+ strbuf_puts(active_map, map);
+ flag = 0;
+ for (p = strbuf_value(active_map); *p; p++) {
+ /*
+ * "c:.c.h,java:.java,cpp:.C.H"
+ */
+ if ((flag == 0 && *p == ',') || (flag == 1 && *p == ':'))
+ die_with_code(2, "syntax error in langmap '%s'.", map);
+ if (*p == ':' || *p == ',') {
+ flag ^= 1;
+ *p = '\0';
+ }
+ }
+ if (flag == 0)
+ die_with_code(2, "syntax error in langmap '%s'.", map);
+}
+
+const char *
+decide_lang(suffix)
+ const char *suffix;
+{
+ char *lang, *list, *tail;
+
+ list = strbuf_value(active_map);
+ tail = list + strbuf_getlen(active_map);
+ lang = list;
+
+ /* check whether or not list includes suffix. */
+ while (list < tail) {
+ list = lang + strlen(lang) + 1;
+ if (match_suffix_list(suffix, list))
+ return lang;
+ lang = list + strlen(list) + 1;
+ }
+
+ return NULL;
+}
+
+/*
+ * return true if suffix matches with one in suffix list.
+ */
+static int
+match_suffix_list(suffix, list)
+ const char *suffix;
+ const char *list;
+{
+ while (*list) {
+ if (locatestring(list, suffix, MATCH_AT_FIRST))
+ return 1;
+ for (list++; *list && *list != '.'; list++)
+ ;
+ }
+ return 0;
+}
Index: libutil/langmap.h
===================================================================
RCS file: libutil/langmap.h
diff -N libutil/langmap.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libutil/langmap.h 1 Sep 2004 13:00:15 -0000
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 1998, 1999 Shigio Yamaguchi
+ * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004 Tama Communications
Corporation
+ *
+ * This file is part of GNU GLOBAL.
+ *
+ * GNU GLOBAL is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU GLOBAL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _LANGMAP_H_
+#define _LANGMAP_H_
+
+void setup_langmap(const char *);
+const char *decide_lang(const char *);
+
+#endif
----
Hideki IWAMOTO address@hidden
- Re: [PATCH] make suffix list of include file configurable,
Hideki IWAMOTO <=