Rename some functions to make them unique
authorThomas White <taw@physics.org>
Sun, 11 Mar 2018 22:17:06 +0000 (23:17 +0100)
committerThomas White <taw@physics.org>
Sun, 11 Mar 2018 22:21:52 +0000 (23:21 +0100)
Makes things less confusing.
Ulterior motive: makes Meson unity builds work.

15 files changed:
meson.build
src/colloquium.c
src/debugger.c
src/narrative_window.c
src/pr_clock.c
src/presentation.c
src/print.c
src/render.c
src/sc_editor.c
src/slide_window.c
src/slideshow.c
src/testcard.c
src/utils.c [new file with mode: 0644]
src/utils.h [new file with mode: 0644]
tests/meson.build

index 3aff3f1..bd9a961 100644 (file)
@@ -32,6 +32,7 @@ executable('colloquium',
             'src/imagestore.c',
             'src/print.c',
             'src/sc_parse.c',
+            'src/utils.c',
           ],
            dependencies : [gtkdep, mdep],
            install : true)
index 84dc73d..830c2f7 100644 (file)
@@ -36,6 +36,7 @@
 #include "colloquium.h"
 #include "presentation.h"
 #include "narrative_window.h"
+#include "utils.h"
 
 
 struct _colloquium
@@ -236,21 +237,6 @@ static void create_config(const char *filename)
 }
 
 
-static void chomp(char *s)
-{
-       size_t i;
-
-       if ( !s ) return;
-
-       for ( i=0; i<strlen(s); i++ ) {
-               if ( (s[i] == '\n') || (s[i] == '\r') ) {
-                       s[i] = '\0';
-                       return;
-               }
-       }
-}
-
-
 static void read_config(const char *filename, Colloquium *app)
 {
        FILE *fh;
index e90eef2..09332d4 100644 (file)
@@ -178,7 +178,7 @@ static void record_runs(struct debugwindow *dbgw)
 }
 
 
-static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct debugwindow *dbgw)
+static gboolean dbg_draw_sig(GtkWidget *da, cairo_t *cr, struct debugwindow *dbgw)
 {
        int width, height;
        char tmp[256];
@@ -292,7 +292,7 @@ void open_debugger(struct frame *fr)
        gtk_widget_set_size_request(dbgw->drawingarea, 100, 8000);
 
        g_signal_connect(G_OBJECT(dbgw->drawingarea), "draw",
-                        G_CALLBACK(draw_sig), dbgw);
+                        G_CALLBACK(dbg_draw_sig), dbgw);
 
        g_signal_connect(G_OBJECT(dbgw->window), "delete-event",
                         G_CALLBACK(close_sig), dbgw);
index 3bd066f..e5faffa 100644 (file)
@@ -489,8 +489,8 @@ static void exportpdf_sig(GSimpleAction *action, GVariant *parameter,
 
 
 
-static gboolean button_press_sig(GtkWidget *da, GdkEventButton *event,
-                                 NarrativeWindow *nw)
+static gboolean nw_button_press_sig(GtkWidget *da, GdkEventButton *event,
+                                    NarrativeWindow *nw)
 {
        return 0;
 }
@@ -515,15 +515,15 @@ static void scroll_down(NarrativeWindow *nw)
 }
 
 
-static gboolean destroy_sig(GtkWidget *da, NarrativeWindow *nw)
+static gboolean nw_destroy_sig(GtkWidget *da, NarrativeWindow *nw)
 {
        g_application_release(nw->app);
        return FALSE;
 }
 
 
-static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
-                              NarrativeWindow *nw)
+static gboolean nw_key_press_sig(GtkWidget *da, GdkEventKey *event,
+                                 NarrativeWindow *nw)
 {
        switch ( event->keyval ) {
 
@@ -597,7 +597,7 @@ static void start_slideshow_here_sig(GSimpleAction *action, GVariant *parameter,
        if ( nw->show == NULL ) return;
 
        g_signal_connect(G_OBJECT(nw->show), "key-press-event",
-                G_CALLBACK(key_press_sig), nw);
+                G_CALLBACK(nw_key_press_sig), nw);
        g_signal_connect(G_OBJECT(nw->show), "destroy",
                 G_CALLBACK(ss_destroy_sig), nw);
        sc_slideshow_set_slide(nw->show, bvp);
@@ -618,7 +618,7 @@ static void start_slideshow_noslides_sig(GSimpleAction *action, GVariant *parame
        if ( nw->show == NULL ) return;
 
        g_signal_connect(G_OBJECT(nw->show), "key-press-event",
-                G_CALLBACK(key_press_sig), nw);
+                G_CALLBACK(nw_key_press_sig), nw);
        g_signal_connect(G_OBJECT(nw->show), "destroy",
                 G_CALLBACK(ss_destroy_sig), nw);
        sc_slideshow_set_slide(nw->show, first_slide(nw->p));
@@ -639,7 +639,7 @@ static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter,
        if ( nw->show == NULL ) return;
 
        g_signal_connect(G_OBJECT(nw->show), "key-press-event",
-                G_CALLBACK(key_press_sig), nw);
+                G_CALLBACK(nw_key_press_sig), nw);
        g_signal_connect(G_OBJECT(nw->show), "destroy",
                 G_CALLBACK(ss_destroy_sig), nw);
        sc_slideshow_set_slide(nw->show, first_slide(nw->p));
@@ -890,13 +890,13 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *papp
        sc_editor_set_top_frame_editable(nw->sceditor, 1);
 
        g_signal_connect(G_OBJECT(nw->sceditor), "button-press-event",
-                        G_CALLBACK(button_press_sig), nw);
+                        G_CALLBACK(nw_button_press_sig), nw);
        g_signal_connect(G_OBJECT(nw->sceditor), "changed",
                         G_CALLBACK(changed_sig), nw);
        g_signal_connect(G_OBJECT(nw->sceditor), "key-press-event",
-                        G_CALLBACK(key_press_sig), nw);
+                        G_CALLBACK(nw_key_press_sig), nw);
        g_signal_connect(G_OBJECT(nw->window), "destroy",
-                        G_CALLBACK(destroy_sig), nw);
+                        G_CALLBACK(nw_destroy_sig), nw);
 
        gtk_window_set_default_size(GTK_WINDOW(nw->window), 768, 768);
        gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
index 21ed4c7..82b9af5 100644 (file)
@@ -222,7 +222,7 @@ static gint close_clock_sig(GtkWidget *w, PRClock *n)
 }
 
 
-static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct pr_clock *n)
+static gboolean clock_draw_sig(GtkWidget *da, cairo_t *cr, struct pr_clock *n)
 {
        int width, height;
        double s;
@@ -387,7 +387,7 @@ PRClock *pr_clock_new()
 
        n->da = gtk_drawing_area_new();
        gtk_box_pack_start(GTK_BOX(vbox), n->da, TRUE, TRUE, 0);
-       g_signal_connect(G_OBJECT(n->da), "draw", G_CALLBACK(draw_sig), n);
+       g_signal_connect(G_OBJECT(n->da), "draw", G_CALLBACK(clock_draw_sig), n);
        g_signal_connect(G_OBJECT(n->window), "destroy",
                         G_CALLBACK(close_clock_sig), n); /* FIXME: Uniqueness */
 
index 0169f19..3ec00e3 100644 (file)
@@ -36,6 +36,7 @@
 #include "imagestore.h"
 #include "render.h"
 #include "sc_interp.h"
+#include "utils.h"
 
 
 void free_presentation(struct presentation *p)
@@ -203,14 +204,6 @@ static char *fgets_long(FILE *fh, size_t *lp)
 }
 
 
-static int safe_strcmp(const char *a, const char *b)
-{
-       if ( a == NULL ) return 1;
-       if ( b == NULL ) return 1;
-       return strcmp(a, b);
-}
-
-
 int slide_number(struct presentation *p, SCBlock *sl)
 {
        SCBlock *bl = p->scblocks;
index 250c9da..18402fc 100644 (file)
@@ -149,8 +149,8 @@ static void print_slide_only(GtkPrintOperation *op, GtkPrintContext *ctx,
 }
 
 
-static int create_thumbnail(SCInterpreter *scin, SCBlock *bl,
-                            double *w, double *h, void **bvp, void *vp)
+static int print_create_thumbnail(SCInterpreter *scin, SCBlock *bl,
+                                  double *w, double *h, void **bvp, void *vp)
 {
        struct print_stuff *ps = vp;
        struct presentation *p = ps->p;
@@ -166,7 +166,7 @@ static int create_thumbnail(SCInterpreter *scin, SCBlock *bl,
 }
 
 
-static cairo_surface_t *render_thumbnail(int w, int h, void *bvp, void *vp)
+static cairo_surface_t *print_render_thumbnail(int w, int h, void *bvp, void *vp)
 {
        struct print_stuff *ps = vp;
        struct presentation *p = ps->p;
@@ -186,7 +186,7 @@ static cairo_surface_t *render_thumbnail(int w, int h, void *bvp, void *vp)
 }
 
 
-static SCBlock *narrative_stylesheet()
+static SCBlock *print_narrative_stylesheet()
 {
        return sc_parse("\\stylesheet{"
                        "\\ss[slide]{\\callback[sthumb]}"
@@ -205,17 +205,17 @@ static void begin_narrative_print(GtkPrintOperation *op, GtkPrintContext *ctx,
 
        cbl = sc_callback_list_new();
        ps->slide_number = 1;
-       sc_callback_list_add_callback(cbl, "sthumb", create_thumbnail,
-                                     render_thumbnail, NULL, ps);
+       sc_callback_list_add_callback(cbl, "sthumb", print_create_thumbnail,
+                                     print_render_thumbnail, NULL, ps);
 
        ps->is = imagestore_new(ps->storename);
 
        if ( ps->p->stylesheet != NULL ) {
                stylesheets[0] = ps->p->stylesheet;
-               stylesheets[1] = narrative_stylesheet();
+               stylesheets[1] = print_narrative_stylesheet();
                stylesheets[2] = NULL;
        } else {
-               stylesheets[0] = narrative_stylesheet();
+               stylesheets[0] = print_narrative_stylesheet();
                stylesheets[1] = NULL;
        }
 
index 40ab78b..f1ff019 100644 (file)
@@ -41,6 +41,7 @@
 #include "frame.h"
 #include "render.h"
 #include "imagestore.h"
+#include "utils.h"
 
 
 static void do_background(cairo_t *cr, struct frame *fr)
@@ -274,14 +275,6 @@ cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h,
 }
 
 
-static int safe_strcmp(const char *a, const char *b)
-{
-       if ( a == NULL ) return 1;
-       if ( b == NULL ) return 1;
-       return strcmp(a, b);
-}
-
-
 int export_pdf(struct presentation *p, const char *filename)
 {
        double r;
index 115e7b6..00c626d 100644 (file)
@@ -43,6 +43,7 @@
 #include "sc_editor.h"
 #include "slideshow.h"
 #include "debugger.h"
+#include "utils.h"
 
 
 static void scroll_interface_init(GtkScrollable *iface)
@@ -1682,21 +1683,6 @@ static gboolean dnd_drop(GtkWidget *widget, GdkDragContext *drag_context,
 }
 
 
-static void chomp(char *s)
-{
-       size_t i;
-
-       if ( !s ) return;
-
-       for ( i=0; i<strlen(s); i++ ) {
-               if ( (s[i] == '\n') || (s[i] == '\r') ) {
-                       s[i] = '\0';
-                       return;
-               }
-       }
-}
-
-
 /* Scale the image down if it's a silly size */
 static void check_import_size(SCEditor *e)
 {
index e6d0970..9dcab2d 100644 (file)
@@ -185,15 +185,15 @@ void slidewindow_redraw(SlideWindow *sw)
 }
 
 
-static gboolean close_sig(GtkWidget *w, SlideWindow *sw)
+static gboolean sw_close_sig(GtkWidget *w, SlideWindow *sw)
 {
        sw->p->slidewindow = NULL;
        return FALSE;
 }
 
 
-static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
-                              SlideWindow *sw)
+static gboolean sw_key_press_sig(GtkWidget *da, GdkEventKey *event,
+                                 SlideWindow *sw)
 {
        switch ( event->keyval ) {
 
@@ -244,7 +244,7 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks,
                                        G_N_ELEMENTS(sw_entries), sw);
 
        g_signal_connect(G_OBJECT(window), "destroy",
-                        G_CALLBACK(close_sig), sw);
+                        G_CALLBACK(sw_close_sig), sw);
 
        stylesheets[0] = p->stylesheet;
        stylesheets[1] = NULL;
@@ -263,7 +263,7 @@ SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks,
 //     gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(sw->sceditor));
 //     gtk_window_set_focus(GTK_WINDOW(window), GTK_WIDGET(sw->sceditor));
        g_signal_connect(G_OBJECT(sw->sceditor), "key-press-event",
-                        G_CALLBACK(key_press_sig), sw);
+                        G_CALLBACK(sw_key_press_sig), sw);
 
        sc_editor_set_logical_size(sw->sceditor,
                                   p->slide_width, p->slide_height);
index 76f200d..84f1edb 100644 (file)
@@ -78,7 +78,7 @@ static void slideshow_rerender(SCSlideshow *ss)
 }
 
 
-static gint ss_destroy_sig(GtkWidget *widget, SCSlideshow *ss)
+static gint ssh_destroy_sig(GtkWidget *widget, SCSlideshow *ss)
 {
        if ( ss->blank_cursor != NULL ) {
                g_object_unref(ss->blank_cursor);
@@ -192,7 +192,7 @@ SCSlideshow *sc_slideshow_new(struct presentation *p, GtkApplication *app)
                              GDK_KEY_PRESS_MASK);
 
        g_signal_connect(G_OBJECT(ss), "destroy",
-                        G_CALLBACK(ss_destroy_sig), ss);
+                        G_CALLBACK(ssh_destroy_sig), ss);
        g_signal_connect(G_OBJECT(ss), "realize",
                         G_CALLBACK(ss_realize_sig), ss);
        g_signal_connect(G_OBJECT(ss), "size-allocate",
index 45fc348..5c723a0 100644 (file)
@@ -44,7 +44,7 @@ struct testcard
        struct presentation *p;
 };
 
-static gint destroy_sig(GtkWidget *widget, struct testcard *tc)
+static gint tc_destroy_sig(GtkWidget *widget, struct testcard *tc)
 {
        free(tc);
        return FALSE;
@@ -105,7 +105,7 @@ static void colour_box(cairo_t *cr, double x, double y,
 }
 
 
-static gboolean draw_sig(GtkWidget *da, cairo_t *cr, struct testcard *tc)
+static gboolean tc_draw_sig(GtkWidget *da, cairo_t *cr, struct testcard *tc)
 {
        double xoff, yoff;
        double width, height;
@@ -224,8 +224,8 @@ static void size_sig(GtkWidget *widget, GdkRectangle *rect, struct testcard *ss)
 
 
 
-static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event,
-                              struct testcard *tc)
+static gboolean tc_key_press_sig(GtkWidget *da, GdkEventKey *event,
+                                 struct testcard *tc)
 {
        if ( !event->is_modifier ) gtk_widget_destroy(tc->window);
        return FALSE;
@@ -252,13 +252,13 @@ void show_testcard(struct presentation *p)
        gtk_widget_add_events(GTK_WIDGET(tc->drawingarea), GDK_KEY_PRESS_MASK);
 
        g_signal_connect(G_OBJECT(tc->drawingarea), "key-press-event",
-                        G_CALLBACK(key_press_sig), tc);
+                        G_CALLBACK(tc_key_press_sig), tc);
        g_signal_connect(G_OBJECT(tc->window), "destroy",
-                        G_CALLBACK(destroy_sig), tc);
+                        G_CALLBACK(tc_destroy_sig), tc);
        g_signal_connect(G_OBJECT(tc->window), "size-allocate",
                         G_CALLBACK(size_sig), tc);
        g_signal_connect(G_OBJECT(tc->drawingarea), "draw",
-                        G_CALLBACK(draw_sig), tc);
+                        G_CALLBACK(tc_draw_sig), tc);
 
        gtk_widget_grab_focus(GTK_WIDGET(tc->drawingarea));
 
diff --git a/src/utils.c b/src/utils.c
new file mode 100644 (file)
index 0000000..17f9665
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * utils.c
+ *
+ * Copyright © 2013-2018 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This file is part of Colloquium.
+ *
+ * Colloquium is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+void chomp(char *s)
+{
+       size_t i;
+
+       if ( !s ) return;
+
+       for ( i=0; i<strlen(s); i++ ) {
+               if ( (s[i] == '\n') || (s[i] == '\r') ) {
+                       s[i] = '\0';
+                       return;
+               }
+       }
+}
+
+
+int safe_strcmp(const char *a, const char *b)
+{
+       if ( a == NULL ) return 1;
+       if ( b == NULL ) return 1;
+       return strcmp(a, b);
+}
+
+
diff --git a/src/utils.h b/src/utils.h
new file mode 100644 (file)
index 0000000..11351fb
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * utils.h
+ *
+ * Copyright © 2013-2018 Thomas White <taw@bitwiz.org.uk>
+ *
+ * This file is part of Colloquium.
+ *
+ * Colloquium is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+extern void chomp(char *s);
+extern int safe_strcmp(const char *a, const char *b);
+
+
+#endif /* UTILS_H */
index d970f87..0d8b760 100644 (file)
@@ -1,6 +1,6 @@
 basic_rendering = ['../src/render.c', '../src/frame.c',
                    '../src/sc_parse.c', '../src/imagestore.c',
-                   '../src/sc_interp.c']
+                   '../src/sc_interp.c', '../src/utils.c']
 
 e = executable('storycode_test', 'storycode_test.c', '../src/sc_parse.c',
                dependencies : [gtkdep])