X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=tools%2Fcpkg2c.mll;h=388973a06b126cc5904ac34f72294eafb1def280;hp=cefc38990eaafe3776bb4b1c601a57d62b24dbd2;hb=981e10e224fde4de5d40adcee1deda89df2715ca;hpb=c855a6e8e9522ac9add840b18a869c831030f569 diff --git a/tools/cpkg2c.mll b/tools/cpkg2c.mll index cefc389..388973a 100644 --- a/tools/cpkg2c.mll +++ b/tools/cpkg2c.mll @@ -496,7 +496,7 @@ and ext_member m f = parse fprintf ob "};\n"; (* dump struct init func *) - fprintf ob "\nstatic void %s_init(void)\n{\n" pkg.name; + fprintf ob "\nstatic void (%s_init)(void)\n{\n" pkg.name; List.iter (function (m, _, _) -> if not (fst m.typ) then let init, f, l = m.init in @@ -621,21 +621,21 @@ int luaopen_%s(lua_State *L) (* }}} *) let usage () = - output_string stderr "usage: cpkg2c (-h | -c) file.cpkg -o output\n"; + output_string stderr "usage: cpkg2c file.cpkg header.out source.out\n"; exit 1 + let warn ob = output_endline ob "/*** THIS FILE IS AUTOGENERATED !!! ***/" + + let process fn file l = + (try Unix.unlink file with _ -> ()); + let ob = open_out_gen [ Open_trunc ; Open_wronly; Open_creat ] 0o444 file in + warn ob; fn ob l; close_out ob + let _ = - let warn ob = output_endline ob "/*** THIS FILE IS AUTOGENERATED !!! ***/" in - if Array.length Sys.argv != 5 then usage(); - let file = Sys.argv.(2) in + if Array.length Sys.argv != 4 then usage(); + let file = Sys.argv.(1) in let lexbuf = L.from_channel (open_in file) in let l = (startchunk cLine file lexbuf) in - if Sys.argv.(3) = "-o" then - let ob = open_out_gen [ Open_trunc ; Open_wronly; Open_creat ] 0444 Sys.argv.(4) in - match Sys.argv.(1) with - | "-h" -> warn ob; do_h ob l; close_out ob - | "-c" -> warn ob; do_c ob l; close_out ob - | _ -> usage () - else - usage(); + process do_h Sys.argv.(2) l; + process do_c Sys.argv.(3) l }