Commit 0089f8d00ff1f58356ed398757694568eb30aa31

Thomas de Grivel 2020-03-23T15:22:20

fix build and running on MSYS2

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 4563d4c..a18a741 100644
--- a/rtbuf_cli.c
+++ b/rtbuf_cli.c
@@ -376,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 a2b9085..343979d 100644
--- a/rtbuf_gtk.c
+++ b/rtbuf_gtk.c
@@ -46,11 +46,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);
@@ -93,6 +97,7 @@ RtbufWidget * rtbuf_gtk_new (gchar *library, gchar *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);
@@ -319,7 +324,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 2abbaa1..f8e42a6 100644
--- a/rtbuf_gtk.h
+++ b/rtbuf_gtk.h
@@ -33,14 +33,14 @@ 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;
-gint       drag_x;
-gint       drag_y;
+extern GtkWidget *drag_widget;
+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 96b1778..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)
diff --git a/rtbuf_lib.h b/rtbuf_lib.h
index f4dc01e..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);
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)