X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=tools%2Fcpkg2c.mll;h=a942ee7bc1b15b4326f99ef993c01953bfb149a9;hp=a3a378289f9b82d101b8c1fffaee10ee2baa97f3;hb=6920eb5798f2d9f25e5ea1af2ba86122cf408bd1;hpb=87f0ade5709ed7f08271f6e73dec2112d96bfc97 diff --git a/tools/cpkg2c.mll b/tools/cpkg2c.mll index a3a3782..a942ee7 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 @@ -585,7 +585,7 @@ int luaopen_%s(lua_State *L) %s_init(); /* create methods table, add it the the table of globals */ - luaL_openlib(L, \"%s\", luaM_%s_methods, 0); + luaL_register(L, \"%s\", luaM_%s_methods); methods = lua_gettop(L); lua_newtable(L); /* for new members */ @@ -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 ] 0o444 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 }