diff --git a/msys.sh b/msys.sh
new file mode 100644
index 0000000..aeebd46
--- /dev/null
+++ b/msys.sh
@@ -0,0 +1,5 @@
+export CC=cc
+export CFLAGS=-I/mingw64/include
+export LDFLAGS=-L/mingw64/lib
+export PATH="$PATH:/mingw64/bin"
+export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig
diff --git a/rtbuf.c b/rtbuf.c
index 639459d..d42b83b 100644
--- a/rtbuf.c
+++ b/rtbuf.c
@@ -30,7 +30,7 @@ s_data_type g_rtbuf_type = {
DATA_TYPE_BITS
};
s_data_alloc g_rtbuf_alloc;
-s_rtbuf *g_rtbuf;
+s_rtbuf *g_rtbuf = 0;
int g_rtbuf_run = 0;
unsigned int g_rtbuf_sort = 0;
unsigned int g_rtbuf_sorted[RTBUF_MAX];
@@ -42,6 +42,7 @@ int librtbuf_init ()
bzero(g_rtbuf_sorted, sizeof(g_rtbuf_sorted));
data_alloc_init(&g_rtbuf_alloc, &g_rtbuf_type, RTBUF_MAX, NULL, NULL);
g_rtbuf = g_rtbuf_alloc.mem;
+ assert(g_rtbuf);
rtbuf_type_init();
rtbuf_proc_init();
rtbuf_lib_init_();
@@ -56,6 +57,7 @@ int rtbuf_new (s_rtbuf_proc *rp)
void *data;
unsigned int j = 0;
assert(rp);
+ assert(g_rtbuf);
data = data_new(&rp->alloc);
if (!data)
return rtbuf_err("rtbuf data allocation failed, "
diff --git a/rtbuf.h b/rtbuf.h
index d7ea7f3..ed3e2a0 100644
--- a/rtbuf.h
+++ b/rtbuf.h
@@ -43,9 +43,9 @@ struct rtbuf
#define RTBUF_MAX 10000
#define RTBUF_INSTANCE_MAX 100
-s_data_alloc g_rtbuf_alloc;
-s_rtbuf *g_rtbuf;
-int g_rtbuf_run;
+extern s_data_alloc g_rtbuf_alloc;
+extern s_rtbuf *g_rtbuf;
+extern int g_rtbuf_run;
int librtbuf_init ();
diff --git a/rtbuf_cli.c b/rtbuf_cli.c
index e6d34dc..a18a741 100644
--- a/rtbuf_cli.c
+++ b/rtbuf_cli.c
@@ -38,7 +38,7 @@ int rtbuf_cli_libs (int argc, const char *argv[])
printf("Listing %i libraries :\n", n);
while (i < g_rtbuf_lib_alloc.n && n > 0) {
if (g_rtbuf_lib[i].path[0]) {
- rtbuf_lib_print(i);
+ rtbuf_lib_print(&g_rtbuf_lib[i]);
n--;
}
i++;
@@ -62,15 +62,13 @@ int rtbuf_cli_lib (int argc, const char *argv[])
int rtbuf_cli_load (int argc, const char *argv[])
{
s_rtbuf_lib *lib;
- unsigned int i;
assert(argc == 1);
lib = rtbuf_lib_load(argv[1]);
if (!lib) {
printf("load failed\n");
return -1;
}
- i = ((char*) lib - (char*) g_rtbuf_lib) / sizeof(s_rtbuf_lib);
- rtbuf_lib_print(i);
+ rtbuf_lib_print(lib);
return 0;
}
@@ -378,6 +376,7 @@ int main (int argc, char *argv[])
{
symbols_init();
librtbuf_init();
+ assert(g_rtbuf);
repl_init();
rtbuf_cli_args(argc, argv);
return repl();
diff --git a/rtbuf_gtk.c b/rtbuf_gtk.c
index a28f4bf..27aa822 100644
--- a/rtbuf_gtk.c
+++ b/rtbuf_gtk.c
@@ -82,11 +82,15 @@ RtbufWidget * rtbuf_gtk_modular_layout_new (s_rtbuf *rtbuf,
RtbufWidget *widget;
GtkWidget *event_box;
char label[1024];
+ assert(rtbuf);
+ assert(rtbuf >= g_rtbuf && (rtbuf - g_rtbuf) < RTBUF_MAX);
printf("rtbuf-gtk modular layout new\n");
+ assert(rtbuf->proc);
+ assert(rtbuf->proc->name);
snprintf(label, sizeof(label), "%s%02d",
rtbuf->proc->name,
g_next_id++);
- rtbuf_var_rtbuf_set(label, (rtbuf - g_rtbuf) / sizeof(s_rtbuf));
+ rtbuf_var_rtbuf_set(label, rtbuf - g_rtbuf);
widget = rtbuf_widget_new(rtbuf, label);
gtk_layout_put(modular_layout, GTK_WIDGET(widget), x, y);
event_box = rtbuf_widget_get_event_box(widget);
@@ -120,15 +124,19 @@ RtbufWidget * rtbuf_gtk_new (gchar *library, gchar *proc,
fprintf(stderr, "rtbuf-gtk: load failed: '%s'\n", library);
return NULL;
}
+ rtbuf_lib_print(rl);
}
- else
+ else {
+ assert(i < RTBUF_LIB_MAX);
rl = &g_rtbuf_lib[i];
+ }
i = rtbuf_lib_find_proc(rl, proc);
if (i < 0) {
fprintf(stderr, "rtbuf-gtk new: not found %s %s\n", library, proc);
return NULL;
}
rp = rl->proc[i];
+ assert(g_rtbuf);
i = rtbuf_new(rp);
if (i < 0) {
fprintf(stderr, "rtbuf-gtk new rtbuf_new failed: %s %s\n", library, proc);
@@ -359,7 +367,9 @@ int rtbuf_gtk_builder ()
int main (int argc, char *argv[])
{
+ symbols_init();
librtbuf_init();
+ assert(g_rtbuf);
gtk_init(&argc, &argv);
rtbuf_gtk_connection_init();
rtbuf_gtk_output_init();
diff --git a/rtbuf_gtk.h b/rtbuf_gtk.h
index 9fb0b87..e999221 100644
--- a/rtbuf_gtk.h
+++ b/rtbuf_gtk.h
@@ -33,15 +33,15 @@ typedef struct signal_binding {
GCallback callback;
} s_signal_binding;
-GtkLayout *modular_layout;
-s_rtbuf_gtk_connection *modular_connections;
+extern GtkLayout *modular_layout;
+extern s_rtbuf_gtk_connection *modular_connections;
-GtkTargetList *rtbuf_move_target_list;
+extern GtkTargetList *rtbuf_move_target_list;
-GtkWidget *drag_widget;
-s_rtbuf_gtk_connection *drag_connection;
-gint drag_x;
-gint drag_y;
+extern GtkWidget *drag_widget;
+extern s_rtbuf_gtk_connection *drag_connection;
+extern gint drag_x;
+extern gint drag_y;
gboolean rtbuf_gtk_rtbuf_button_press (GtkWidget *widget,
GdkEvent *event,
diff --git a/rtbuf_lib.c b/rtbuf_lib.c
index 9be68c6..775e987 100644
--- a/rtbuf_lib.c
+++ b/rtbuf_lib.c
@@ -47,6 +47,7 @@ void rtbuf_lib_init_ ()
data_alloc_init(&g_rtbuf_lib_alloc, &g_rtbuf_lib_type,
RTBUF_LIB_MAX, 0, 0);
g_rtbuf_lib = g_rtbuf_lib_alloc.mem;
+ assert(g_rtbuf_lib);
if (!in)
in = ".";
while (*in)
@@ -285,10 +286,14 @@ void rtbuf_lib_proc_init_proc (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x)
rtbuf_lib_proc_out_init_proc(proc, x->out);
}
-void rtbuf_lib_print (unsigned int i)
+void rtbuf_lib_print (const s_rtbuf_lib *lib)
{
- assert(i < RTBUF_LIB_MAX);
- printf("#<lib %i %s>\n", i, g_rtbuf_lib[i].name);
+ unsigned int i;
+ if (lib >= g_rtbuf_lib &&
+ (i = lib - g_rtbuf_lib) < RTBUF_LIB_MAX)
+ printf("#<lib %i %s>\n", i, lib->name);
+ else
+ printf("#<lib %p %s>\n", lib, lib->name);
}
void rtbuf_lib_print_long (unsigned int i)
diff --git a/rtbuf_lib.h b/rtbuf_lib.h
index bdc25d6..863c266 100644
--- a/rtbuf_lib.h
+++ b/rtbuf_lib.h
@@ -51,8 +51,8 @@ struct rtbuf_lib {
const char *path;
};
-s_data_alloc g_rtbuf_lib_alloc;
-s_rtbuf_lib *g_rtbuf_lib;
+extern s_data_alloc g_rtbuf_lib_alloc;
+extern s_rtbuf_lib *g_rtbuf_lib;
void rtbuf_lib_delete (s_rtbuf_lib *rl);
int rtbuf_lib_find (const char *str);
@@ -60,7 +60,7 @@ int rtbuf_lib_find_proc (s_rtbuf_lib *rl, const char *str);
void rtbuf_lib_init_ ();
s_rtbuf_lib * rtbuf_lib_load (const char *path);
s_rtbuf_lib * rtbuf_lib_new ();
-void rtbuf_lib_print (unsigned int i);
+void rtbuf_lib_print (const s_rtbuf_lib *lib);
void rtbuf_lib_print_long (unsigned int i);
void rtbuf_lib_proc_var_init_proc (s_rtbuf_proc *proc,
diff --git a/rtbuf_proc.c b/rtbuf_proc.c
index 023dc60..7a44d07 100644
--- a/rtbuf_proc.c
+++ b/rtbuf_proc.c
@@ -33,6 +33,8 @@ void rtbuf_proc_init ()
{
data_alloc_init(&g_rtbuf_proc_alloc, &g_rtbuf_proc_type,
RTBUF_PROC_MAX, 0, 0);
+ g_rtbuf_proc = g_rtbuf_proc_alloc.mem;
+ assert(g_rtbuf_proc);
}
int rtbuf_proc_p (s_rtbuf_proc *proc)
diff --git a/rtbuf_proc.h b/rtbuf_proc.h
index c8970cc..d39964a 100644
--- a/rtbuf_proc.h
+++ b/rtbuf_proc.h
@@ -54,8 +54,8 @@ struct rtbuf_proc {
};
#define RTBUF_PROC_MAX 1024
-s_data_alloc g_rtbuf_proc_alloc;
-s_rtbuf_proc *g_rtbuf_proc;
+extern s_data_alloc g_rtbuf_proc_alloc;
+extern s_rtbuf_proc *g_rtbuf_proc;
void rtbuf_proc_init ();
int rtbuf_proc_p (s_rtbuf_proc *proc);
diff --git a/rtbuf_type.c b/rtbuf_type.c
index 6f073bf..567dc1d 100644
--- a/rtbuf_type.c
+++ b/rtbuf_type.c
@@ -34,6 +34,7 @@ void rtbuf_type_init ()
data_alloc_init(&g_rtbuf_data_type_alloc, &g_rtbuf_data_type_type,
RTBUF_TYPE_MAX, 0, 0);
g_rtbuf_data_type = g_rtbuf_data_type_alloc.mem;
+ assert(g_rtbuf_data_type);
rtbuf_type_define("char" , sizeof(char));
rtbuf_type_define("unsigned char" , sizeof(unsigned char));
rtbuf_type_define("short" , sizeof(short));
diff --git a/rtbuf_var.c b/rtbuf_var.c
index 874ae2a..fadc3f8 100644
--- a/rtbuf_var.c
+++ b/rtbuf_var.c
@@ -15,6 +15,7 @@ void rtbuf_var_init (void)
{
data_alloc_init(&g_rtbuf_var_alloc, &g_rtbuf_var_type, RTBUF_VAR_MAX, NULL, NULL);
g_rtbuf_var = g_rtbuf_var_alloc.mem;
+ assert(g_rtbuf_var);
}
s_rtbuf_var * rtbuf_var_new (const char *name)