c syntax_checker: modify 'pkg-config' handler

This commit is contained in:
kongo2002 2010-04-02 02:12:41 +08:00 committed by Martin Grenfell
parent 5166c7f26e
commit faef18d981

View File

@ -41,10 +41,13 @@ set cpo&vim
" initialize handlers " initialize handlers
function! s:Init() function! s:Init()
let s:handlers = [] let s:handlers = []
call s:RegHandler('\%(gtk\|glib\)', s:CheckGtk()) let s:cflags = {}
call s:RegHandler('ruby', s:CheckRuby()) call s:RegHandler('\%(gtk\|glib\)', 's:CheckPKG',
call s:RegHandler('Python\.h', s:CheckPython()) \ ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib'])
call s:RegHandler('glade', s:CheckGlade()) call s:RegHandler('glade', 's:CheckPKG',
\ ['glade', 'libglade-2.0', 'libglade'])
call s:RegHandler('ruby', 's:CheckRuby', [])
call s:RegHandler('Python\.h', 's:CheckPython', [])
unlet! s:RegHandler unlet! s:RegHandler
endfunction endfunction
@ -85,7 +88,7 @@ function! s:SearchHeaders(handlers)
for handler in l:handlers for handler in l:handlers
let line = getline(i) let line = getline(i)
if line =~# '^#include.*' . handler["regex"] if line =~# '^#include.*' . handler["regex"]
let includes .= handler["func"] let includes .= call(handler["func"], handler["args"])
call remove(l:handlers, index(l:handlers, handler)) call remove(l:handlers, index(l:handlers, handler))
elseif line =~# '^#include\s\+"\S\+"' elseif line =~# '^#include\s\+"\S\+"'
call add(files, matchstr(line, '^#include\s\+"\zs\S\+\ze"')) call add(files, matchstr(line, '^#include\s\+"\zs\S\+\ze"'))
@ -106,7 +109,7 @@ function! s:SearchHeaders(handlers)
for line in lines for line in lines
for handler in l:handlers for handler in l:handlers
if line =~# '^#include.*' . handler["regex"] if line =~# '^#include.*' . handler["regex"]
let includes .= handler["func"] let includes .= call(handler["func"], handler["args"])
call remove(l:handlers, index(l:handlers, handler)) call remove(l:handlers, index(l:handlers, handler))
endif endif
endfor endfor
@ -117,15 +120,23 @@ function! s:SearchHeaders(handlers)
return includes return includes
endfunction endfunction
" try to find the gtk headers with 'pkg-config' " try to find library with 'pkg-config'
function! s:CheckGtk() " search possible libraries from first to last given
" argument until one is found
function! s:CheckPKG(name, ...)
if executable('pkg-config') if executable('pkg-config')
if !exists('s:gtk_flags') if !has_key(s:cflags, a:name)
let s:gtk_flags = system('pkg-config --cflags gtk+-2.0') for i in range(a:0)
let s:gtk_flags = substitute(s:gtk_flags, "\n", '', '') let l:cflags = system('pkg-config --cflags '.a:000[i])
let s:gtk_flags = ' ' . s:gtk_flags if v:shell_error == 0
let l:cflags = ' '.substitute(l:cflags, "\n", '', '')
let s:cflags[a:name] = l:cflags
return l:cflags
endif
endfor
else
return s:cflags[a:name]
endif endif
return s:gtk_flags
endif endif
return '' return ''
endfunction endfunction
@ -158,24 +169,12 @@ function! s:CheckPython()
return '' return ''
endfunction endfunction
" try to find the glade headers with 'pkg-config'
function! s:CheckGlade()
if executable('pkg-config')
if !exists('s:glade_flags')
let s:glade_flags = system('pkg-config --cflags libglade-2.0')
let s:glade_flags = substitute(s:glade_flags, "\n", '', '')
let s:glade_flags = ' ' . s:glade_flags
endif
return s:glade_flags
endif
return ''
endfunction
" return a handler dictionary object " return a handler dictionary object
function! s:RegHandler(regex, function) function! s:RegHandler(regex, function, args)
let handler = {} let handler = {}
let handler["regex"] = a:regex let handler["regex"] = a:regex
let handler["func"] = a:function let handler["func"] = function(a:function)
let handler["args"] = a:args
call add(s:handlers, handler) call add(s:handlers, handler)
endfunction endfunction