Add shebank-like detection for XML files.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1573 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2007-05-25 15:19:23 +00:00
parent 39dbad8829
commit 6e630eb8ae
2 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,7 @@
* geany.glade, src/callbacks.c, src/callbacks.h, src/geany.h,
src/interface.c, src/main.c, src/ui_utils.c:
Improve sensitivity of recent files sub menus.
* src/filetypes.c: Add shebank-like detection for XML files.
2007-05-25 Nick Treleaven <nick.treleaven@btinternet.com>

View File

@ -574,7 +574,7 @@ static filetype *find_shebang(gint idx)
gchar *line = sci_get_line(doc_list[idx].sci, 0);
filetype *ft = NULL;
if (strlen(line) > 2 && line[0] == '#' && line[1]=='!')
if (strlen(line) > 2 && line[0] == '#' && line[1] == '!')
{
/// TODO does g_path_get_basename() also work under Win32 for Unix filenames?
gchar *basename_interpreter = g_path_get_basename(line + 2);
@ -609,6 +609,20 @@ static filetype *find_shebang(gint idx)
g_free(basename_interpreter);
}
// detect XML files
if (strncmp(line, "<?xml", 5) == 0)
{
// HTML and DocBook files might also start with <?xml, so detect them based on filename
// extension and use the detected filetype, else assume XML
ft = filetypes_detect_from_filename(doc_list[idx].file_name);
if (FILETYPE_ID(ft) != GEANY_FILETYPES_HTML &&
FILETYPE_ID(ft) != GEANY_FILETYPES_DOCBOOK &&
FILETYPE_ID(ft) != GEANY_FILETYPES_PERL && // Perl, Python and PHP only to be safe
FILETYPE_ID(ft) != GEANY_FILETYPES_PHP &&
FILETYPE_ID(ft) != GEANY_FILETYPES_PYTHON)
ft = filetypes[GEANY_FILETYPES_XML];
}
g_free(line);
return ft;
@ -624,6 +638,7 @@ filetype *filetypes_detect_from_file(gint idx)
return filetypes[GEANY_FILETYPES_ALL];
// try to find a shebang and if found use it prior to the filename extension
// also checks for <?xml
ft = find_shebang(idx);
if (ft != NULL) return ft;