diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2011-10-14 04:55:05 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2011-10-14 04:55:05 +0200 |
commit | 6aa0e0017d7d0cddc006da885946934b06949a91 (patch) | |
tree | 66b688ec32e2f91266db760b1762f2a50cc52036 /libslang/modules/newt-module.c | |
parent | a966db5b71328f6adf9dd767e64b322a3bd7ed9c (diff) | |
download | erlang-slang-fork-6aa0e0017d7d0cddc006da885946934b06949a91.tar.gz |
include libslang-1.4.9 and automatically build it and link erlang-slang against it
few (erlang) people will still have libslang-1.4.9 installed or spend time
to get it to link against the driver
Diffstat (limited to 'libslang/modules/newt-module.c')
-rw-r--r-- | libslang/modules/newt-module.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/libslang/modules/newt-module.c b/libslang/modules/newt-module.c new file mode 100644 index 0000000..9788ed1 --- /dev/null +++ b/libslang/modules/newt-module.c @@ -0,0 +1,91 @@ +/* This module implements and interface to the Newt library */ +#include <stdio.h> +#include <slang.h> +#include <newt.h> + +SLANG_MODULE(newt); + +static int Ok_To_Draw; + +static void init (void) +{ + newtInit (); + Ok_To_Draw = 1; +} + +static void cls (void) +{ + if (Ok_To_Draw) + newtCls (); +} + +static void draw_root_text (int *c, int *r, char *s) +{ + if (Ok_To_Draw) + newtDrawRootText (*c, *r, s); +} + +static void open_window (int *c, int *r, int *dc, int *dr, char *title) +{ + if (Ok_To_Draw) + newtOpenWindow (*c, *r, *dc, *dr, title); +} + +static void refresh (void) +{ + if (Ok_To_Draw) + newtRefresh (); +} + +static void finished (void) +{ + if (Ok_To_Draw) + newtFinished (); + Ok_To_Draw = 0; +} + +#define I SLANG_INT_TYPE +#define S SLANG_STRING_TYPE + +static SLang_Intrin_Fun_Type Module_Funs [] = +{ + MAKE_INTRINSIC_0("newtInit", init, SLANG_VOID_TYPE), + MAKE_INTRINSIC_0("newtCls", cls, SLANG_VOID_TYPE), + MAKE_INTRINSIC_IIS("newtDrawRootText", draw_root_text, SLANG_VOID_TYPE), + MAKE_INTRINSIC_5("newtOpenWindow", open_window, SLANG_VOID_TYPE, I,I,I,I,S), + MAKE_INTRINSIC_0("newtRefresh", refresh, SLANG_VOID_TYPE), + MAKE_INTRINSIC_0("NewtFinished", finished, SLANG_VOID_TYPE), + + SLANG_END_TABLE +}; + +static SLang_Intrin_Var_Type Module_Variables [] = +{ + SLANG_END_TABLE +}; + +static SLang_IConstant_Type Module_Constants [] = +{ + SLANG_END_TABLE +}; + + +int init_newt_module_ns (char *ns) +{ + if ((-1 == SLns_add_intrin_fun_table (ns, Module_Funs, "__NEWT__")) + || (-1 == SLns_add_intrin_var_table (ns, Module_Variables, NULL)) + || (-1 == SLns_add_iconstant_table (ns, Module_Constants, NULL))) + return -1; + + Ok_To_Draw = 0; + + (void) SLang_add_cleanup_function (finished); + + return 0; +} + +/* This function is optional */ +void deinit_newt_module (void) +{ + finished (); +} |