X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=tools%2Fcpkg2c.mll;h=57e825895b6d07158aa9c61b6190ec68aceac110;hb=8f75834aeadb902879602a82a259f4d3bf9c569c;hp=835519987821e3f4999c193a2c47724359e4bc5d;hpb=4606bdeeaf175b61f3c54dcbadc330f2505d9f67;p=apps%2Fmadmutt.git diff --git a/tools/cpkg2c.mll b/tools/cpkg2c.mll index 8355199..57e8258 100644 --- a/tools/cpkg2c.mll +++ b/tools/cpkg2c.mll @@ -31,6 +31,14 @@ let put_line = printf "#line %d \"%s\"\n" + let isspace = function |' '|'\t' -> true | _ -> false + + let strip s = + let l = ref 0 and r = ref (String.length s) in + while (isspace s.[!l] && !l < !r) do incr l done; + while (isspace s.[!r - 1] && !l < !r) do decr r done; + String.sub s !l (!r - !l) + (* @types related {{{ *) type typedef = @@ -91,9 +99,9 @@ | [t] -> (false, type_find lpos fpos t) | _ -> assert false in - match s with + match strip s with | "void" -> [] - | s -> List.map aux (Str.split (Str.regexp "[ \t]+,[ \t]+") s) + | s -> List.map aux (Str.split (Str.regexp "[ \t]*,[ \t]*") s) let parse_args lpos fpos s = let aux t = @@ -102,9 +110,9 @@ | [t; n] -> ((false, type_find lpos fpos t), n) | _ -> assert false in - match s with + match strip s with | "void" -> [] - | s -> List.map aux (Str.split (Str.regexp "[ \t]+,[ \t]+") s) + | s -> List.map aux (Str.split (Str.regexp "[ \t]*,[ \t]*") s) (* }}} *) (* parsing helpers {{{ *) @@ -415,7 +423,7 @@ and ext_bodycode buf = parse ) 0 fn.args); printf "\n#define RAISE(s) luaL_error(L, (s))\n"; if fn.rettype = [] then ( - printf "#define RETURN return luaM_ret_%s_%s(L)\n" pkg.name fn.fname + printf "#define RETURN() return luaM_ret_%s_%s(L)\n" pkg.name fn.fname ) else ( printf "#define RETURN(luaM_x1"; for i = 2 to retlen do printf ", luaM_x%d" i done;