add ReadConfig() function for C/C++ checkers
This commit is contained in:
parent
b4e85a8762
commit
d8f3aa5d50
@ -65,6 +65,41 @@ function! syntastic#c#GetIncludeDirs(filetype)
|
||||
return join(map(s:Unique(include_dirs), '"-I" . v:val'), ' ')
|
||||
endfunction
|
||||
|
||||
" read additional compiler flags from the given configuration file
|
||||
" the file format and its parsing mechanism is inspired by clang_complete
|
||||
function! syntastic#c#ReadConfig(file)
|
||||
" search in the current file's directory upwards
|
||||
let config = findfile(a:file, '.;')
|
||||
if config == '' || !filereadable(config) | return '' | endif
|
||||
|
||||
" convert filename into absolute path
|
||||
let filepath = substitute(fnamemodify(config, ':p:h'), '\', '/', 'g')
|
||||
|
||||
" try to read config file
|
||||
try
|
||||
let lines = map(readfile(config),
|
||||
\ 'substitute(v:val, ''\'', ''/'', ''g'')')
|
||||
catch /E484/
|
||||
return ''
|
||||
endtry
|
||||
|
||||
let parameters = []
|
||||
for line in lines
|
||||
let matches = matchlist(line, '^\s*-I\s*\(\S\+\)')
|
||||
if matches != [] && matches[1] != ''
|
||||
" this one looks like an absolute path
|
||||
if match(matches[1], '^\%(/\|\a:\)') != -1
|
||||
call add(parameters, '-I' . matches[1])
|
||||
else
|
||||
call add(parameters, '-I' . filepath . '/' . matches[1])
|
||||
endif
|
||||
else
|
||||
call add(parameters, line)
|
||||
endif
|
||||
endfor
|
||||
|
||||
return join(parameters, ' ')
|
||||
endfunction
|
||||
|
||||
" search the first 100 lines for include statements that are
|
||||
" given in the handlers dictionary
|
||||
|
Loading…
Reference in New Issue
Block a user