00001
00002 #include <stdio.h>
00003 #include <slang.h>
00004 #include <newt.h>
00005
00006 SLANG_MODULE(newt);
00007
00008 static int Ok_To_Draw;
00009
00010 static void init (void)
00011 {
00012 newtInit ();
00013 Ok_To_Draw = 1;
00014 }
00015
00016 static void cls (void)
00017 {
00018 if (Ok_To_Draw)
00019 newtCls ();
00020 }
00021
00022 static void draw_root_text (int *c, int *r, char *s)
00023 {
00024 if (Ok_To_Draw)
00025 newtDrawRootText (*c, *r, s);
00026 }
00027
00028 static void open_window (int *c, int *r, int *dc, int *dr, char *title)
00029 {
00030 if (Ok_To_Draw)
00031 newtOpenWindow (*c, *r, *dc, *dr, title);
00032 }
00033
00034 static void refresh (void)
00035 {
00036 if (Ok_To_Draw)
00037 newtRefresh ();
00038 }
00039
00040 static void finished (void)
00041 {
00042 if (Ok_To_Draw)
00043 newtFinished ();
00044 Ok_To_Draw = 0;
00045 }
00046
00047 #define I SLANG_INT_TYPE
00048 #define S SLANG_STRING_TYPE
00049
00050 static SLang_Intrin_Fun_Type Module_Funs [] =
00051 {
00052 MAKE_INTRINSIC_0("newtInit", init, SLANG_VOID_TYPE),
00053 MAKE_INTRINSIC_0("newtCls", cls, SLANG_VOID_TYPE),
00054 MAKE_INTRINSIC_IIS("newtDrawRootText", draw_root_text, SLANG_VOID_TYPE),
00055 MAKE_INTRINSIC_5("newtOpenWindow", open_window, SLANG_VOID_TYPE, I,I,I,I,S),
00056 MAKE_INTRINSIC_0("newtRefresh", refresh, SLANG_VOID_TYPE),
00057 MAKE_INTRINSIC_0("NewtFinished", finished, SLANG_VOID_TYPE),
00058
00059 SLANG_END_TABLE
00060 };
00061
00062 static SLang_Intrin_Var_Type Module_Variables [] =
00063 {
00064 SLANG_END_TABLE
00065 };
00066
00067 static SLang_IConstant_Type Module_Constants [] =
00068 {
00069 SLANG_END_TABLE
00070 };
00071
00072
00073 int init_newt_module_ns (char *ns)
00074 {
00075 if ((-1 == SLns_add_intrin_fun_table (ns, Module_Funs, "__NEWT__"))
00076 || (-1 == SLns_add_intrin_var_table (ns, Module_Variables, NULL))
00077 || (-1 == SLns_add_iconstant_table (ns, Module_Constants, NULL)))
00078 return -1;
00079
00080 Ok_To_Draw = 0;
00081
00082 (void) SLang_add_cleanup_function (finished);
00083
00084 return 0;
00085 }
00086
00087
00088 void deinit_newt_module (void)
00089 {
00090 finished ();
00091 }