Created
February 16, 2014 22:37
-
-
Save lawrencejones/9041652 to your computer and use it in GitHub Desktop.
Generates C function stubs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! GenPrototypes(reg) | |
let fs=[] | |
let l:space = '\_s\{-}' | |
let l:keywd = '\(\(\w\+\s\+\)\+\)' . l:space ") #1 | |
let l:rtype = '\(\w\+\)' . l:space ") #3 | |
let l:fname = '\(\w\+\)' . l:space ") #4 | |
let l:parms = '\((.*)\)' . l:space ") #5 | |
let l:block = '\({\_.\{-}}\)' | |
let l:regex = l:keywd . l:rtype | |
\ . l:fname . l:parms | |
\ . l:block | |
execute "normal /^" . l:regex . "/ge\<CR>" | |
%s//\=len(add(fs, ( submatch(1) . | |
\ submatch(3) . " " . | |
\ submatch(4) . " " . | |
\ submatch(5) . ';' ))) ? submatch(0) : ''/ge | |
let reg = empty(a:reg) ? 'f' : a:reg | |
let l:joined = join(fs, "\n") . "\n" | |
execute "let @".reg." = system(\"column -t\", l:joined)" | |
endfunction | |
command! -register GenPrototypes call GenPrototypes(<q-reg>) | |
function! InsertPrototypes(line) | |
if a:0 > 0 | |
let line = a:line | |
else | |
let line = 0 | |
end | |
call GenPrototypes('x') | |
execute "normal! ".line.'gg | "fP' | |
endfunction | |
command! -register InsertPrototypes call InsertPrototypes(<q-args>) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Example output from InsertPrototypes */ | |
static inline int32_t fp_int_to_fp (int n); | |
static inline int fp_fp_to_zero_int (int32_t x); | |
static inline int fp_fp_to_nearest_int (int32_t x); | |
static inline int32_t fp_add_fp_fp (int32_t x, int32_t y); | |
static inline int32_t fp_add_fp_int (int32_t x, int n); | |
static inline int32_t fp_mul_fp_fp (int32_t x, int32_t y); | |
static inline int32_t fp_mul_fp_int (int32_t x, int n); | |
static inline int32_t fp_div_int_int (int a, int b); | |
static inline int32_t fp_div_fp_fp (int32_t x, int32_t y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment