From 532832f035837a6a3379090edd7238b2fbf58bd0 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Wed, 12 Oct 2022 15:57:44 +0200 Subject: [PATCH 01/26] Add debug output if desired Introduced two environment variables to optionally enable debug output - GR_DEBUG - enable debug output in GR, showing all function calls and function parameters - GKS_DEBUG - enable debug output in GKS, showing all function calls with involved output drivers and logging all file open/close operations --- lib/gks/gks.c | 159 ++++++++++++++++++++++-------------- lib/gks/gkscore.h | 4 + lib/gr/gr.c | 202 ++++++++++++++++++++++++---------------------- lib/gr/gr.h | 1 + lib/gr/stream.c | 19 +++-- 5 files changed, 221 insertions(+), 164 deletions(-) diff --git a/lib/gks/gks.c b/lib/gks/gks.c index 61a5205e1..570feb201 100644 --- a/lib/gks/gks.c +++ b/lib/gks/gks.c @@ -43,64 +43,65 @@ static int id = 0; static gks_list_t *open_ws = NULL, *active_ws = NULL, *av_ws_types = NULL; -static ws_descr_t ws_types[] = {{2, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 4, "mf", NULL}, - {3, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 5, "mf", NULL}, - {5, GKS_K_METERS, 1.00000, 1.00000, 32767, 32767, 3, NULL, NULL}, - {41, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {61, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {62, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {63, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {64, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {100, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {101, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL}, - {102, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL}, - {120, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL}, - {121, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL}, - {130, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "gif", NULL}, - {131, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "apng", NULL}, - {140, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL}, - {141, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {142, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {143, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {144, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL}, - {145, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "bmp", NULL}, - {146, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "tif", NULL}, - {150, GKS_K_METERS, 0.20320, 0.15240, 560, 420, 0, "six", NULL}, - {151, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL}, - {160, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mp4", NULL}, - {161, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "webm", NULL}, - {162, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "ogg", NULL}, - {170, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ppm", NULL}, - {171, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL}, - {172, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL}, - {173, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {210, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL}, - {211, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {212, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {213, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {214, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "rf", "GKS_RF"}, - {215, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", "GKS_GIF"}, - {216, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "uil", "GKS_UIL"}, - {217, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL}, - {218, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", NULL}, - {301, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL}, - {314, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "tex", NULL}, - {320, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {321, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {322, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {323, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {371, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {380, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {381, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {382, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "svg", NULL}, - {390, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "wmf", NULL}, - {400, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {410, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {411, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {412, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {413, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {415, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {420, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}}; +static ws_descr_t ws_types[] = { + {2, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 4, "mf", NULL, "MO"}, + {3, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 5, "mf", NULL, "MI"}, + {5, GKS_K_METERS, 1.00000, 1.00000, 32767, 32767, 3, NULL, NULL, "WISS"}, + {41, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "Windows GDI"}, + {61, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "PostScript"}, + {62, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "Color PostScript"}, + {63, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "PostScript (landscape)"}, + {64, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "Color PostScript (landscape)"}, + {100, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "NULL"}, + {101, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL, "PDF"}, + {102, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL, "PDF"}, + {120, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL, "QuickTime movie"}, + {121, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL, "High DPI QuickTime movie"}, + {130, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "gif", NULL, "GIF"}, + {131, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "apng", NULL, "animated PNG"}, + {140, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL, "PNG"}, + {141, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Cairo X11"}, + {142, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Cairo Gtk"}, + {143, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "Cairo pixmap"}, + {144, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL, "Cairo JPEG"}, + {145, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "bmp", NULL, "Cairo BMP"}, + {146, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "tif", NULL, "Cairo TIFF"}, + {150, GKS_K_METERS, 0.20320, 0.15240, 560, 420, 0, "six", NULL, "Sixel"}, + {151, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL, "PNG"}, + {160, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mp4", NULL, "MPEG-4"}, + {161, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "webm", NULL, "WEBM"}, + {162, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "ogg", NULL, "OGG"}, + {170, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ppm", NULL, "Anti-Grain PPM"}, + {171, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL, "Anti-Grain PNG"}, + {172, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL, "Anti-Grain JPEG"}, + {173, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "Anti-Grain pixmap"}, + {210, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL, "X11"}, + {211, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "X11"}, + {212, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "X drawable"}, + {213, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "X widget"}, + {214, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "rf", "GKS_RF", "Sun rasterfile"}, + {215, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", "GKS_GIF", "X GIF"}, + {216, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "uil", "GKS_UIL", "X UIL"}, + {217, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL, "X pixmap"}, + {218, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", NULL, "GIF-89"}, + {301, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL, "plugin"}, + {314, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "tex", NULL, "PGF"}, + {320, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript BMP"}, + {321, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript JPEG"}, + {322, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript PNG"}, + {323, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript TIFF"}, + {371, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Gtk"}, + {380, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "WxWidgets"}, + {381, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Qt"}, + {382, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "svg", NULL, "SVG"}, + {390, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "wmf", NULL, "WMF"}, + {400, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Quartz"}, + {410, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "socket"}, + {411, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Qt"}, + {412, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Qt (Cairo)"}, + {413, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Qt (Agg)"}, + {415, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "ZMQ"}, + {420, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "OpenGL"}}; static int num_ws_types = sizeof(ws_types) / sizeof(ws_types[0]); @@ -179,6 +180,10 @@ static void gks_ddlk(int fctid, int dx, int dy, int dimx, int *i_arr, int len_f_ ptr = &ws->ptr; #ifndef EMSCRIPTEN + if (s->debug) + fprintf(stdout, "[DEBUG:GKS] dispatch %s function to %s driver (wtype: %d)\n", gks_function_name(fctid), + ws->name, ws->wtype); + switch (ws->wtype) { case 2: @@ -411,6 +416,8 @@ static void gks_parse_env(void) } if (gks_getenv("GKS_NO_EXIT_HANDLER") == NULL) atexit(gks_emergency_close); + + if (gks_getenv("GKS_DEBUG") != NULL) s->debug = 1; } void gks_set_encoding(int encoding) @@ -535,9 +542,17 @@ void gks_init_gks(void) s->aspect_ratio = 1; s->callback = NULL; + s->debug = 0; } } +int gks_debug(void) +{ + if (s != NULL) return s->debug; + + return 0; +} + void gks_open_gks(int errfil) { int i; @@ -596,6 +611,8 @@ void gks_close_gks(void) if (s->fontfile > 0) { /* close font database */ + if (s->debug) fprintf(stdout, "[DEBUG:GKS] close font database (fd=%d)\n", s->fontfile); + gks_close_font(s->fontfile); s->fontfile = 0; } @@ -620,7 +637,12 @@ static int open_file(char *name, int wtype) if (*name) { char *mode = wtype == GKS_K_WSTYPE_MI ? "r" : "w"; + + if (s->debug) fprintf(stdout, "[DEBUG:GKS] open file '%s' with mode '%c' ", name, *mode); + fd = gks_open_file(name, mode); + + if (s->debug) fprintf(stdout, "=> fd=%d\n", fd); } else fd = 1; @@ -669,8 +691,10 @@ void gks_open_ws(int wkid, char *path, int wtype) } else ws->path = gks_strdup(path); + ws->wtype = wtype; ws->conid = 0; + ws->name = descr->name; if (descr->env) { @@ -757,7 +781,13 @@ void gks_open_ws(int wkid, char *path, int wtype) { if (ws->conid && ws->conid != 1) if (ws->path) - if (*ws->path != '!') gks_close_file(ws->conid); + if (*ws->path != '!') + { + if (s->debug) + fprintf(stdout, "[DEBUG:GKS] close file '%s' (fd=%d)\n", ws->path, ws->conid); + + gks_close_file(ws->conid); + } if (ws->path) free(ws->path); @@ -817,7 +847,12 @@ void gks_close_ws(int wkid) if (ws->conid && ws->conid != 1) if (ws->path) - if (*ws->path != '!') gks_close_file(ws->conid); + if (*ws->path != '!') + { + if (s->debug) fprintf(stdout, "[DEBUG:GKS] close file '%s' (fd=%d)\n", ws->path, ws->conid); + + gks_close_file(ws->conid); + } if (ws->path) free(ws->path); @@ -1550,7 +1585,11 @@ void gks_set_text_fontprec(int font, int prec) if ((prec == GKS_K_TEXT_PRECISION_STROKE || prec == GKS_K_TEXT_PRECISION_CHAR) && s->fontfile == 0) { /* open font database */ + if (s->debug) fprintf(stdout, "[DEBUG:GKS] open font database "); + s->fontfile = gks_open_font(); + + if (s->debug) fprintf(stdout, "=> fd=%d\n", s->fontfile); } s->txfont = i_arr[0] = font; diff --git a/lib/gks/gkscore.h b/lib/gks/gkscore.h index e50609cce..60573a526 100644 --- a/lib/gks/gkscore.h +++ b/lib/gks/gkscore.h @@ -168,6 +168,7 @@ typedef struct int resize_behaviour; double aspect_ratio; char *(*callback)(const char *); + int debug; } gks_state_list_t; typedef struct gks_list @@ -185,6 +186,7 @@ typedef struct int conid; void *ptr; double vp[4]; + char *name; } ws_list_t; typedef struct @@ -196,6 +198,7 @@ typedef struct int wscat; char *type; char *env; + char *name; } ws_descr_t; typedef struct @@ -295,6 +298,7 @@ DLLEXPORT int gks_dl_read_item(char *dl, gks_state_list_t **gkss, void (*fn)(int fctid, int dx, int dy, int dimx, int *ia, int lr1, double *r1, int lr2, double *r2, int lc, char *chars, void **ptr)); void gks_wiss_dispatch(int fctid, int wkid, int segn); +int gks_debug(void); #ifndef EMSCRIPTEN diff --git a/lib/gr/gr.c b/lib/gr/gr.c index bd6ca0b00..5ec30cecd 100644 --- a/lib/gr/gr.c +++ b/lib/gr/gr.c @@ -276,6 +276,8 @@ static int autoinit = 1, double_buf = 0, state_saved = 0, def_color = 0; static const char *display = NULL; +static const char *debug = NULL; + static double vxmin = 0.2, vxmax = 0.9, vymin = 0.2, vymax = 0.9; static double cxl, cxr, cyf, cyb, czb, czt; @@ -284,7 +286,7 @@ static int arrow_style = 0; static double arrow_size = 1; -static int flag_printing = 0, flag_graphics = 0; +static int flag_printing = 0, flag_stream = 0, flag_graphics = 0; static text_node_t *text, *head; @@ -1411,6 +1413,9 @@ static void initialize(int state) if (display) if (*display == '\0') display = NULL; + debug = gks_getenv("GR_DEBUG"); + flag_stream = flag_graphics || debug != NULL; + setscale(options); } @@ -1481,7 +1486,7 @@ static void initgks(void) { gr_writestream(XML_HEADER); gr_writestream(GR_HEADER); - flag_graphics = 1; + flag_stream = flag_graphics = 1; } else fprintf(stderr, "%s: open failed\n", display); @@ -1514,6 +1519,11 @@ void gr_initgr(void) } } +int gr_debug() +{ + return debug != NULL; +} + void gr_opengks(void) { int errfil = 0; @@ -1691,7 +1701,7 @@ void gr_clearws(void) foreach_activews((void (*)(int, void *))clear, (void *)&clearflag); - if (flag_graphics) + if (flag_stream) { gr_writestream(GR_TRAILER); gr_flushstream(1); @@ -1721,7 +1731,7 @@ void gr_updatews(void) foreach_openws((void (*)(int, void *))update, (void *)®enflag); - if (flag_graphics) + if (flag_stream) if (display) { gr_writestream(GR_TRAILER); @@ -1872,7 +1882,7 @@ void gr_polyline(int n, double *x, double *y) polyline(n, x, y); - if (flag_graphics) primitive("polyline", n, x, y); + if (flag_stream) primitive("polyline", n, x, y); } static void polymarker(int n, double *x, double *y) @@ -1916,7 +1926,7 @@ void gr_polymarker(int n, double *x, double *y) polymarker(n, x, y); - if (flag_graphics) primitive("polymarker", n, x, y); + if (flag_stream) primitive("polymarker", n, x, y); } /*! @@ -1933,7 +1943,7 @@ void gr_fillarea(int n, double *x, double *y) { fillarea(n, x, y); - if (flag_graphics) primitive("fillarea", n, x, y); + if (flag_stream) primitive("fillarea", n, x, y); } /*! @@ -1963,7 +1973,7 @@ void gr_cellarray(double xmin, double xmax, double ymin, double ymax, int dimx, gks_cellarray(x_lin(xmin), y_lin(ymax), x_lin(xmax), y_lin(ymin), dimx, dimy, scol, srow, ncol, nrow, color); - if (flag_graphics) + if (flag_stream) { gr_writestream("ltype = type; - if (flag_graphics) gr_writestream("\n", type); + if (flag_stream) gr_writestream("\n", type); } void gr_inqlinetype(int *ltype) @@ -2966,7 +2976,7 @@ void gr_setlinewidth(double width) gks_set_pline_linewidth(width); if (ctx) ctx->lwidth = width; - if (flag_graphics) gr_writestream("\n", width); + if (flag_stream) gr_writestream("\n", width); } void gr_inqlinewidth(double *width) @@ -2990,7 +3000,7 @@ void gr_setlinecolorind(int color) gks_set_pline_color_index(color); if (ctx) ctx->plcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } void gr_inqlinecolorind(int *coli) @@ -3097,7 +3107,7 @@ void gr_setmarkertype(int type) gks_set_pmark_type(type); if (ctx) ctx->mtype = type; - if (flag_graphics) gr_writestream("\n", type); + if (flag_stream) gr_writestream("\n", type); } void gr_inqmarkertype(int *mtype) @@ -3124,7 +3134,7 @@ void gr_setmarkersize(double size) gks_set_pmark_size(size); if (ctx) ctx->mszsc = size; - if (flag_graphics) gr_writestream("\n", size); + if (flag_stream) gr_writestream("\n", size); } /*! @@ -3155,7 +3165,7 @@ void gr_setmarkercolorind(int color) gks_set_pmark_color_index(color); if (ctx) ctx->pmcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } void gr_inqmarkercolorind(int *coli) @@ -3278,7 +3288,7 @@ void gr_settextfontprec(int font, int precision) ctx->txprec = precision; } - if (flag_graphics) gr_writestream("\n", font, precision); + if (flag_stream) gr_writestream("\n", font, precision); } static int loadfont(char *name) @@ -3341,7 +3351,7 @@ void gr_loadfont(char *filename, int *font) } if (*font > 0) { - if (flag_graphics) gr_writestream("\n", filename); + if (flag_stream) gr_writestream("\n", filename); } } @@ -3363,7 +3373,7 @@ void gr_setcharexpan(double factor) gks_set_text_expfac(factor); if (ctx) ctx->chxp = factor; - if (flag_graphics) gr_writestream("\n", factor); + if (flag_stream) gr_writestream("\n", factor); } void gr_setcharspace(double spacing) @@ -3373,7 +3383,7 @@ void gr_setcharspace(double spacing) gks_set_text_spacing(spacing); if (ctx) ctx->chsp = spacing; - if (flag_graphics) gr_writestream("\n", spacing); + if (flag_stream) gr_writestream("\n", spacing); } /*! @@ -3391,7 +3401,7 @@ void gr_settextcolorind(int color) gks_set_text_color_index(color); if (ctx) ctx->txcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } /*! @@ -3423,7 +3433,7 @@ void gr_setcharheight(double height) gks_set_text_height(height); if (ctx) ctx->chh = height; - if (flag_graphics) gr_writestream("\n", height); + if (flag_stream) gr_writestream("\n", height); } void gr_setwscharheight(double chh, double height) @@ -3466,7 +3476,7 @@ void gr_setcharup(double ux, double uy) ctx->chup[1] = uy; } - if (flag_graphics) gr_writestream("\n", ux, uy); + if (flag_stream) gr_writestream("\n", ux, uy); } /*! @@ -3495,7 +3505,7 @@ void gr_settextpath(int path) gks_set_text_path(path); if (ctx) ctx->txp = path; - if (flag_graphics) gr_writestream("\n", path); + if (flag_stream) gr_writestream("\n", path); } /*! @@ -3547,7 +3557,7 @@ void gr_settextalign(int horizontal, int vertical) ctx->txal[1] = vertical; } - if (flag_graphics) gr_writestream("\n", horizontal, vertical); + if (flag_stream) gr_writestream("\n", horizontal, vertical); } /*! @@ -3580,7 +3590,7 @@ void gr_setfillintstyle(int style) gks_set_fill_int_style(style); if (ctx) ctx->ints = style; - if (flag_graphics) gr_writestream("\n", style); + if (flag_stream) gr_writestream("\n", style); } /*! @@ -3618,7 +3628,7 @@ void gr_setfillstyle(int index) gks_set_fill_style_index(index); if (ctx) ctx->styli = index; - if (flag_graphics) gr_writestream("\n", index); + if (flag_stream) gr_writestream("\n", index); } /*! @@ -3653,7 +3663,7 @@ void gr_setfillcolorind(int color) gks_set_fill_color_index(color); if (ctx) ctx->facoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } /*! @@ -3679,7 +3689,7 @@ void gr_setresizebehaviour(int flag) gks_set_resize_behaviour(flag); if (ctx) ctx->resize_behaviour = flag; - if (flag_graphics) gr_writestream("\n", flag); + if (flag_stream) gr_writestream("\n", flag); } void gr_inqresizebehaviour(int *flag) @@ -3726,7 +3736,7 @@ void gr_setcolorrep(int index, double red, double green, double blue) setcolorrep(index, red, green, blue); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", index, red, green, blue); } @@ -3785,7 +3795,7 @@ int gr_setscale(int options) result = setscale(options); if (ctx) ctx->scale_options = options; - if (flag_graphics) gr_writestream("\n", options); + if (flag_stream) gr_writestream("\n", options); return result; } @@ -3832,7 +3842,7 @@ void gr_setwindow(double xmin, double xmax, double ymin, double ymax) } setscale(lx.scale_options); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -3903,7 +3913,7 @@ void gr_setviewport(double xmin, double xmax, double ymin, double ymax) vymin = ymin; vymax = ymax; - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -3939,7 +3949,7 @@ void gr_selntran(int transform) gks_select_xform(transform); - if (flag_graphics) gr_writestream("\n", transform); + if (flag_stream) gr_writestream("\n", transform); } /*! @@ -3970,7 +3980,7 @@ void gr_setclip(int indicator) gks_set_clipping(indicator); - if (flag_graphics) gr_writestream("\n", indicator); + if (flag_stream) gr_writestream("\n", indicator); } static void wswindow(int workstation_id, rect_t *rect) @@ -4012,7 +4022,7 @@ void gr_setwswindow(double xmin, double xmax, double ymin, double ymax) foreach_activews((void (*)(int, void *))wswindow, (void *)&rect); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -4051,7 +4061,7 @@ void gr_setwsviewport(double xmin, double xmax, double ymin, double ymax) sizex = xmax - xmin; - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -4181,7 +4191,7 @@ int gr_setspace(double zmin, double zmax, int rotation, int tilt) setspace(zmin, zmax, rotation, tilt); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", zmin, zmax, rotation, tilt); return 0; @@ -4215,7 +4225,7 @@ void gr_setprojectiontype(int flag) { gpx.projection_type = flag; - if (flag_graphics) gr_writestream("\n", flag); + if (flag_stream) gr_writestream("\n", flag); } else { @@ -4315,7 +4325,7 @@ void gr_settransformationparameters(double camera_pos_x, double camera_pos_y, do settransformationparameters(camera_pos_x, camera_pos_y, camera_pos_z, up_x, up_y, up_z, focus_point_x, focus_point_y, focus_point_z); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", @@ -4355,7 +4365,7 @@ void gr_setperspectiveprojection(double near_plane, double far_plane, double fov setperspectiveprojection(near_plane, far_plane, fov); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", near_plane, far_plane, fov); } @@ -4392,7 +4402,7 @@ void gr_setorthographicprojection(double left, double right, double bottom, doub setorthographicprojection(left, right, bottom, top, near_plane, far_plane); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", left, right, bottom, top, near_plane, far_plane); @@ -4646,7 +4656,7 @@ int gr_textext(double x, double y, char *string) if (tnr != NDC) gks_select_xform(tnr); - if (flag_graphics) gr_writestream("\n", x, y, string); + if (flag_stream) gr_writestream("\n", x, y, string); return result; } @@ -4710,7 +4720,7 @@ void gr_setscientificformat(int format_option) scientific_format = format_option; } - if (flag_graphics) gr_writestream("\n", format_option); + if (flag_stream) gr_writestream("\n", format_option); } static void text2dlbl(double x, double y, char *chars, double value, void (*fp)(double, double, const char *, double)) @@ -5160,7 +5170,7 @@ void gr_axeslbl(double x_tick, double y_tick, double x_org, double y_org, int ma gks_set_text_upvec(chux, chuy); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", x_tick, y_tick, x_org, y_org, major_x, major_y, tick_size); @@ -5397,7 +5407,7 @@ void gr_grid(double x_tick, double y_tick, double x_org, double y_org, int major gks_set_pline_color_index(color); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", x_tick, y_tick, x_org, y_org, major_x, major_y); @@ -5717,7 +5727,7 @@ void gr_grid3d(double x_tick, double y_tick, double z_tick, double x_org, double gks_set_pline_color_index(color); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", @@ -5779,7 +5789,7 @@ void gr_verrorbars(int n, double *px, double *py, double *e1, double *e2) polymarker(n, px, py); - if (flag_graphics) + if (flag_stream) { gr_writestream(" 0) gks_polymarker(m, xpoint, ypoint); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", x, y, z, chars, axis); } @@ -7171,7 +7181,7 @@ void gr_axes3d(double x_tick, double y_tick, double z_tick, double x_org, double gks_set_text_upvec(chux, chuy); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", @@ -7564,8 +7574,7 @@ void gr_titles3d(char *x_title, char *y_title, char *z_title) gks_set_text_upvec(chux, chuy); } - if (flag_graphics) - gr_writestream("\n", x_title, y_title, z_title); + if (flag_stream) gr_writestream("\n", x_title, y_title, z_title); if (modern_projection_type) { @@ -8366,7 +8375,7 @@ void gr_surface(int nx, int ny, double *px, double *py, double *pz, int option) gks_set_fill_int_style(int_style); gks_set_fill_color_index(coli); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", index); + if (flag_stream) gr_writestream("\n", index); } void gr_inqcolormap(int *index) @@ -9452,7 +9461,7 @@ void gr_colorbar(void) gks_set_text_align(halign, valign); gks_set_clipping(clsw); - if (flag_graphics) gr_writestream("\n"); + if (flag_stream) gr_writestream("\n"); } void gr_inqcolor(int color, int *rgb) @@ -10004,7 +10013,7 @@ void gr_drawrect(double xmin, double xmax, double ymin, double ymax) gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 5, codes); } - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -10053,7 +10062,7 @@ void gr_fillrect(double xmin, double xmax, double ymin, double ymax) gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 5, codes); } - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -10131,7 +10140,7 @@ void gr_drawarc(double xmin, double xmax, double ymin, double ymax, double a1, d gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 3, codes); } - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", @@ -10218,7 +10227,7 @@ void gr_fillarc(double xmin, double xmax, double ymin, double ymax, double a1, d gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 3, codes); } - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", @@ -10372,7 +10381,7 @@ void gr_drawpath(int n, vertex_t *vertices, unsigned char *codes, int fill) } closepath(fill); - if (flag_graphics) + if (flag_stream) { gr_writestream("= 1 && style <= 18) arrow_style = style - 1; - if (flag_graphics) gr_writestream("\n", style); + if (flag_stream) gr_writestream("\n", style); } /*! @@ -10454,7 +10463,7 @@ void gr_setarrowsize(double size) if (size > 0) arrow_size = size; - if (flag_graphics) gr_writestream("\n", size); + if (flag_stream) gr_writestream("\n", size); } /*! @@ -10553,7 +10562,7 @@ void gr_drawarrow(double x1, double y1, double x2, double y2) gks_set_fill_int_style(intstyle); gks_set_pline_linetype(ltype); - if (flag_graphics) gr_writestream("\n", x1, y1, x2, y2); + if (flag_stream) gr_writestream("\n", x1, y1, x2, y2); } static void drawimage_calculation(double xmin, double xmax, double ymin, double ymax, int width, int height, int *data, @@ -10676,7 +10685,7 @@ void gr_drawimage(double xmin, double xmax, double ymin, double ymax, int width, drawimage_calculation(xmin, xmax, ymin, ymax, width, height, data, model); - if (flag_graphics) + if (flag_stream) { n = width * height; gr_writestream("\n", x, y, string); + if (flag_stream) gr_writestream("\n", x, y, string); } void gr_inqmathtex(double x, double y, char *string, double *tbx, double *tby) @@ -11449,7 +11459,7 @@ void gr_text(double x, double y, char *string) if (tnr != NDC) gks_select_xform(tnr); - if (flag_graphics) gr_writestream("\n", x, y, string); + if (flag_stream) gr_writestream("\n", x, y, string); } /*! @@ -11493,7 +11503,7 @@ void gr_textx(double x, double y, char *string, int opts) if (tnr != NDC) gks_select_xform(tnr); - if (flag_graphics) gr_writestream("\n", x, y, string, opts); + if (flag_stream) gr_writestream("\n", x, y, string, opts); } void gr_inqtext(double x, double y, char *string, double *tbx, double *tby) @@ -11669,7 +11679,7 @@ void gr_savestate(void) else fprintf(stderr, "attempt to save state beyond implementation limit\n"); - if (flag_graphics) gr_writestream("\n"); + if (flag_stream) gr_writestream("\n"); } void gr_restorestate(void) @@ -11715,7 +11725,7 @@ void gr_restorestate(void) else fprintf(stderr, "attempt to restore unsaved state\n"); - if (flag_graphics) gr_writestream("\n"); + if (flag_stream) gr_writestream("\n"); } void gr_selectcontext(int context) @@ -11947,7 +11957,7 @@ int gr_uselinespec(char *linespec) gr_setlinecolorind(color); gr_setmarkercolorind(color); - if (flag_graphics) gr_writestream("\n", linespec); + if (flag_stream) gr_writestream("\n", linespec); return result; } @@ -12134,7 +12144,7 @@ void gr_shadepoints(int n, double *x, double *y, int xform, int w, int h) free(bins); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", start_mouse_pos_x, start_mouse_pos_y, end_mouse_pos_x, end_mouse_pos_y); @@ -12863,7 +12873,7 @@ void gr_setwindow3d(double xmin, double xmax, double ymin, double ymax, double z wx.zmin = zmin; wx.zmax = zmax; - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax, zmin, zmax); } @@ -12896,7 +12906,7 @@ void gr_setscalefactors3d(double x_axis_scale, double y_axis_scale, double z_axi setscalefactors3d(x_axis_scale, y_axis_scale, z_axis_scale); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", x_axis_scale, y_axis_scale, z_axis_scale); } @@ -12923,7 +12933,7 @@ void gr_setborderwidth(double width) gks_set_border_width(width); if (ctx) ctx->bwidth = width; - if (flag_graphics) gr_writestream("\n", width); + if (flag_stream) gr_writestream("\n", width); } void gr_inqborderwidth(double *width) @@ -12947,7 +12957,7 @@ void gr_setbordercolorind(int color) gks_set_border_color_index(color); if (ctx) ctx->bcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } void gr_inqbordercolorind(int *coli) @@ -12966,7 +12976,7 @@ void gr_selectclipxform(int tnr) gks_select_clip_xform(tnr); if (ctx) ctx->clip_tnr = tnr; - if (flag_graphics) gr_writestream("\n", tnr); + if (flag_stream) gr_writestream("\n", tnr); } void gr_inqclipxform(int *tnr) @@ -13040,7 +13050,7 @@ void gr_setspace3d(double phi, double theta, double fov, double cam) setscalefactors3d(scale_factor_x, scale_factor_y, scale_factor_z); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", phi, theta, fov, cam); } @@ -13050,7 +13060,7 @@ void gr_settextencoding(int encoding) gks_set_encoding(encoding); - if (flag_graphics) gr_writestream("\n", encoding); + if (flag_stream) gr_writestream("\n", encoding); } void gr_inqtextencoding(int *encoding) @@ -13089,7 +13099,7 @@ void gr_setthreadnumber(int num) vt.max_threads = max(1, num); vt.thread_size = 10 * (1.0 / (2.0 * num)); - if (flag_graphics) gr_writestream("\n", num); + if (flag_stream) gr_writestream("\n", num); } /*! @@ -13106,7 +13116,7 @@ void gr_setpicturesizeforvolume(int width, int height) vt.picture_height = height; vt.picture_width = width; - if (flag_graphics) gr_writestream("\n", width, height); + if (flag_stream) gr_writestream("\n", width, height); } /*! @@ -13128,7 +13138,7 @@ void gr_setapproximativecalculation(int approximative_calculation) fprintf(stderr, "Invalid number for approximative_calculation. Valid numbers are 0 and 1.\n"); } - if (flag_graphics) + if (flag_stream) gr_writestream("\n", flag); + if (flag_stream) gr_writestream("\n", flag); } /*! @@ -14070,7 +14080,7 @@ void gr_cpubasedvolume(int nx, int ny, int nz, double *data, int algorithm, doub free(pixels); free(jobs); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", nx, ny, nz); print_float_array("data", nx * ny * nz, data); @@ -14185,7 +14195,7 @@ void gr_polygonmesh3d(int num_points, const double *px, const double *py, const free(y); free(x); - if (flag_graphics) + if (flag_stream) { gr_writestream(" Date: Wed, 12 Oct 2022 20:20:19 +0200 Subject: [PATCH 02/26] Fix GRM logging for streams not connected to a tty If the logging output stream is not a tty, the logged file, line number and function name were wrong. --- lib/grm/logging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index 16f89a3e3..aeae627bb 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -91,7 +91,7 @@ void logger1_(FILE *stream, const char *filename, int line_number, const char *c } else { - fprintf(stream, "%s:%d(%s): ", __FILE__, __LINE__, CURRENT_FUNCTION); + fprintf(stream, "%s:%d(%s): ", filename, line_number, current_function); } #endif } From 6e1f39d554633cc9a0468632daa3dc3cb4daae69 Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Wed, 12 Oct 2022 20:37:09 +0200 Subject: [PATCH 03/26] [GRM] Restructure the GRM source tree (use a split layout) This commit adopts commit d392d9fa08b96f0ed051356a2387156fb1e51c42 of the `develop-grm-graphics-tree` branch. --- .gitlab-ci.yml | 77 ++++++---------- CMakeLists.txt | 58 +++++------- js/Makefile | 89 +++++++++++++++---- lib/grm/Makefile | 41 ++++++--- lib/grm/grm.h | 16 ---- lib/grm/include/grm.h | 15 ++++ lib/grm/{ => include/grm}/args.h | 0 lib/grm/include/grm/base64.h | 23 +++++ lib/grm/{ => include/grm}/dump.h | 0 lib/grm/{ => include/grm}/event.h | 0 lib/grm/{ => include/grm}/interaction.h | 0 lib/grm/{ => include/grm}/net.h | 0 lib/grm/{ => include/grm}/plot.h | 0 lib/grm/{ => include/grm}/util.h | 0 lib/grm/makefile.mingw | 36 ++++++-- lib/grm/{ => src/grm}/args.c | 0 lib/grm/{ => src/grm}/args_int.h | 2 +- lib/grm/{ => src/grm}/base64.c | 0 lib/grm/{ => src/grm}/base64_int.h | 1 + lib/grm/{ => src/grm}/datatype/double_map.c | 0 .../{ => src/grm}/datatype/double_map_int.h | 0 .../{ => src/grm}/datatype/string_array_map.c | 0 .../grm}/datatype/string_array_map_int.h | 0 lib/grm/{ => src/grm}/datatype/string_list.c | 0 .../{ => src/grm}/datatype/string_list_int.h | 0 lib/grm/{ => src/grm}/datatype/string_map.c | 0 .../{ => src/grm}/datatype/string_map_int.h | 0 .../grm}/datatype/template/list_int.h | 4 +- .../{ => src/grm}/datatype/template/map_int.h | 2 +- .../{ => src/grm}/datatype/template/set_int.h | 6 +- lib/grm/{ => src/grm}/datatype/uint_map.c | 0 lib/grm/{ => src/grm}/datatype/uint_map_int.h | 0 lib/grm/{ => src/grm}/dump.c | 0 lib/grm/{ => src/grm}/dump_int.h | 2 +- lib/grm/{ => src/grm}/dynamic_args_array.c | 0 .../{ => src/grm}/dynamic_args_array_int.h | 2 +- lib/grm/{ => src/grm}/error.c | 0 lib/grm/{ => src/grm}/error_int.h | 0 lib/grm/{ => src/grm}/event.c | 0 lib/grm/{ => src/grm}/event_int.h | 2 +- lib/grm/{ => src/grm}/interaction.c | 0 lib/grm/{ => src/grm}/interaction_int.h | 2 +- lib/grm/{ => src/grm}/json.c | 0 lib/grm/{ => src/grm}/json_int.h | 2 +- lib/grm/{ => src/grm}/logging.c | 0 lib/grm/{ => src/grm}/logging_int.h | 0 lib/grm/{ => src/grm}/memwriter.c | 0 lib/grm/{ => src/grm}/memwriter_int.h | 0 lib/grm/{ => src/grm}/net.c | 0 lib/grm/{ => src/grm}/net_int.h | 2 +- lib/grm/{ => src/grm}/plot.c | 2 +- lib/grm/{ => src/grm}/plot_int.h | 2 +- lib/grm/{ => src/grm}/util.c | 0 lib/grm/{ => src/grm}/util_int.h | 4 +- .../internal_api/{ => grm}/CMakeLists.txt | 0 .../args_automatic_array_conversion.c | 2 +- .../{ => grm}/datatype/string_array_map.c | 2 +- .../{ => grm}/get_compatible_format.c | 2 +- lib/grm/test/internal_api/{ => grm}/test.h | 0 .../test/public_api/{ => grm}/CMakeLists.txt | 0 .../test/public_api/{ => grm}/bar_errorbar.c | 0 lib/grm/test/public_api/{ => grm}/barplot.c | 0 .../public_api/{ => grm}/custom_receiver.c | 0 .../test/public_api/{ => grm}/custom_sender.c | 0 .../public_api/{ => grm}/event_handling.c | 0 lib/grm/test/public_api/{ => grm}/heatmap.c | 0 lib/grm/test/public_api/{ => grm}/histogram.c | 0 .../test/public_api/{ => grm}/hold_append.c | 0 lib/grm/test/public_api/{ => grm}/imshow.c | 0 .../test/public_api/{ => grm}/isosurface.c | 0 .../test/public_api/{ => grm}/line_errorbar.c | 0 .../test/public_api/{ => grm}/merge_args.c | 0 .../test/public_api/{ => grm}/multi_plot.c | 0 lib/grm/test/public_api/{ => grm}/pie.c | 0 lib/grm/test/public_api/{ => grm}/plot.c | 0 .../public_api/{ => grm}/polar_histogram.c | 0 .../public_api/{ => grm}/qt/gr_widget.cxx | 0 .../public_api/{ => grm}/qt/gr_widget.hxx | 0 lib/grm/test/public_api/{ => grm}/qt/main.cxx | 0 .../public_api/{ => grm}/qt/main_window.cxx | 0 .../public_api/{ => grm}/qt/main_window.hxx | 0 .../public_api/{ => grm}/qt/qt_grm_test.pro | 0 lib/grm/test/public_api/{ => grm}/qt/util.hxx | 0 lib/grm/test/public_api/{ => grm}/quiver.c | 0 lib/grm/test/public_api/{ => grm}/raw.c | 0 .../{ => grm}/raw_gen_graphics_export.py | 0 lib/grm/test/public_api/{ => grm}/receiver.c | 0 .../public_api/{ => grm}/scatter_errorbar.c | 0 lib/grm/test/public_api/{ => grm}/sender.c | 0 lib/grm/test/public_api/{ => grm}/size.c | 0 lib/grm/test/public_api/{ => grm}/subplots.c | 0 .../test/public_api/{ => grm}/test_server.py | 0 lib/grm/test/public_api/{ => grm}/volume.c | 0 93 files changed, 240 insertions(+), 156 deletions(-) delete mode 100644 lib/grm/grm.h create mode 100644 lib/grm/include/grm.h rename lib/grm/{ => include/grm}/args.h (100%) create mode 100644 lib/grm/include/grm/base64.h rename lib/grm/{ => include/grm}/dump.h (100%) rename lib/grm/{ => include/grm}/event.h (100%) rename lib/grm/{ => include/grm}/interaction.h (100%) rename lib/grm/{ => include/grm}/net.h (100%) rename lib/grm/{ => include/grm}/plot.h (100%) rename lib/grm/{ => include/grm}/util.h (100%) rename lib/grm/{ => src/grm}/args.c (100%) rename lib/grm/{ => src/grm}/args_int.h (99%) rename lib/grm/{ => src/grm}/base64.c (100%) rename lib/grm/{ => src/grm}/base64_int.h (95%) rename lib/grm/{ => src/grm}/datatype/double_map.c (100%) rename lib/grm/{ => src/grm}/datatype/double_map_int.h (100%) rename lib/grm/{ => src/grm}/datatype/string_array_map.c (100%) rename lib/grm/{ => src/grm}/datatype/string_array_map_int.h (100%) rename lib/grm/{ => src/grm}/datatype/string_list.c (100%) rename lib/grm/{ => src/grm}/datatype/string_list_int.h (100%) rename lib/grm/{ => src/grm}/datatype/string_map.c (100%) rename lib/grm/{ => src/grm}/datatype/string_map_int.h (100%) rename lib/grm/{ => src/grm}/datatype/template/list_int.h (99%) rename lib/grm/{ => src/grm}/datatype/template/map_int.h (99%) rename lib/grm/{ => src/grm}/datatype/template/set_int.h (99%) rename lib/grm/{ => src/grm}/datatype/uint_map.c (100%) rename lib/grm/{ => src/grm}/datatype/uint_map_int.h (100%) rename lib/grm/{ => src/grm}/dump.c (100%) rename lib/grm/{ => src/grm}/dump_int.h (91%) rename lib/grm/{ => src/grm}/dynamic_args_array.c (100%) rename lib/grm/{ => src/grm}/dynamic_args_array_int.h (98%) rename lib/grm/{ => src/grm}/error.c (100%) rename lib/grm/{ => src/grm}/error_int.h (100%) rename lib/grm/{ => src/grm}/event.c (100%) rename lib/grm/{ => src/grm}/event_int.h (98%) rename lib/grm/{ => src/grm}/interaction.c (100%) rename lib/grm/{ => src/grm}/interaction_int.h (96%) rename lib/grm/{ => src/grm}/json.c (100%) rename lib/grm/{ => src/grm}/json_int.h (99%) rename lib/grm/{ => src/grm}/logging.c (100%) rename lib/grm/{ => src/grm}/logging_int.h (100%) rename lib/grm/{ => src/grm}/memwriter.c (100%) rename lib/grm/{ => src/grm}/memwriter_int.h (100%) rename lib/grm/{ => src/grm}/net.c (100%) rename lib/grm/{ => src/grm}/net_int.h (99%) rename lib/grm/{ => src/grm}/plot.c (99%) rename lib/grm/{ => src/grm}/plot_int.h (99%) rename lib/grm/{ => src/grm}/util.c (100%) rename lib/grm/{ => src/grm}/util_int.h (99%) rename lib/grm/test/internal_api/{ => grm}/CMakeLists.txt (100%) rename lib/grm/test/internal_api/{ => grm}/args_automatic_array_conversion.c (98%) rename lib/grm/test/internal_api/{ => grm}/datatype/string_array_map.c (92%) rename lib/grm/test/internal_api/{ => grm}/get_compatible_format.c (97%) rename lib/grm/test/internal_api/{ => grm}/test.h (100%) rename lib/grm/test/public_api/{ => grm}/CMakeLists.txt (100%) rename lib/grm/test/public_api/{ => grm}/bar_errorbar.c (100%) rename lib/grm/test/public_api/{ => grm}/barplot.c (100%) rename lib/grm/test/public_api/{ => grm}/custom_receiver.c (100%) rename lib/grm/test/public_api/{ => grm}/custom_sender.c (100%) rename lib/grm/test/public_api/{ => grm}/event_handling.c (100%) rename lib/grm/test/public_api/{ => grm}/heatmap.c (100%) rename lib/grm/test/public_api/{ => grm}/histogram.c (100%) rename lib/grm/test/public_api/{ => grm}/hold_append.c (100%) rename lib/grm/test/public_api/{ => grm}/imshow.c (100%) rename lib/grm/test/public_api/{ => grm}/isosurface.c (100%) rename lib/grm/test/public_api/{ => grm}/line_errorbar.c (100%) rename lib/grm/test/public_api/{ => grm}/merge_args.c (100%) rename lib/grm/test/public_api/{ => grm}/multi_plot.c (100%) rename lib/grm/test/public_api/{ => grm}/pie.c (100%) rename lib/grm/test/public_api/{ => grm}/plot.c (100%) rename lib/grm/test/public_api/{ => grm}/polar_histogram.c (100%) rename lib/grm/test/public_api/{ => grm}/qt/gr_widget.cxx (100%) rename lib/grm/test/public_api/{ => grm}/qt/gr_widget.hxx (100%) rename lib/grm/test/public_api/{ => grm}/qt/main.cxx (100%) rename lib/grm/test/public_api/{ => grm}/qt/main_window.cxx (100%) rename lib/grm/test/public_api/{ => grm}/qt/main_window.hxx (100%) rename lib/grm/test/public_api/{ => grm}/qt/qt_grm_test.pro (100%) rename lib/grm/test/public_api/{ => grm}/qt/util.hxx (100%) rename lib/grm/test/public_api/{ => grm}/quiver.c (100%) rename lib/grm/test/public_api/{ => grm}/raw.c (100%) rename lib/grm/test/public_api/{ => grm}/raw_gen_graphics_export.py (100%) rename lib/grm/test/public_api/{ => grm}/receiver.c (100%) rename lib/grm/test/public_api/{ => grm}/scatter_errorbar.c (100%) rename lib/grm/test/public_api/{ => grm}/sender.c (100%) rename lib/grm/test/public_api/{ => grm}/size.c (100%) rename lib/grm/test/public_api/{ => grm}/subplots.c (100%) rename lib/grm/test/public_api/{ => grm}/test_server.py (100%) rename lib/grm/test/public_api/{ => grm}/volume.c (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e5da4a233..9c58d4a3d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,10 +64,8 @@ ubuntu-self-contained: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-ubuntu1604 artifacts: expire_in: 1 week @@ -192,10 +190,8 @@ debian-self-contained: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-debian9 artifacts: expire_in: 1 week @@ -262,10 +258,8 @@ debian-self-contained-armhf: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-debian9-armhf artifacts: expire_in: 1 week @@ -311,10 +305,8 @@ debian-self-contained-aarch64: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-debian9-aarch64 artifacts: expire_in: 1 week @@ -438,10 +430,8 @@ centos7-self-contained: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-centos7 artifacts: expire_in: 1 week @@ -507,10 +497,9 @@ centos7-32bit-self-contained: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-centos7-32bit artifacts: expire_in: 1 week @@ -572,10 +561,8 @@ arch-self-contained: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-arch artifacts: expire_in: 1 week @@ -635,10 +622,8 @@ freebsd-self-contained: lib/gr3/libGR3platform.so lib/grm/libGRM.a lib/grm/libGRM.so lib/gr/qtgr/*.so artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-freebsd13 artifacts: expire_in: 1 week @@ -689,10 +674,8 @@ windows-32bit-cross: - cp -r lib/gks/fonts artifacts/ - cp /usr/lib/gcc/i686-w64-mingw32/6.3-win32/libgcc_s_sjlj-1.dll artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-windows32 artifacts: expire_in: 1 week @@ -787,10 +770,8 @@ windows-64bit-cross: - cp -r lib/gks/fonts artifacts/ - cp /usr/lib/gcc/x86_64-w64-mingw32/6.3-win32/libgcc_s_seh-1.dll artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mv artifacts artifacts-windows64 artifacts: expire_in: 1 week @@ -888,10 +869,8 @@ darwin-self-contained-iff1600: lib/grm/libGRM.a lib/grm/libGRM.dylib lib/gr/qtgr/*.dylib artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mkdir artifacts/Applications/ - cp -r lib/gks/quartz/build/Release/GKSTerm.app artifacts/Applications/GKSTerm.app - cp -r lib/gks/qt/gksqt.app artifacts/Applications/gksqt.app @@ -931,10 +910,8 @@ darwin-self-contained: lib/grm/libGRM.a lib/grm/libGRM.dylib lib/gr/qtgr/*.dylib artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mkdir artifacts/Applications/ - cp -r lib/gks/quartz/build/Release/GKSTerm.app artifacts/Applications/GKSTerm.app - cp -r lib/gks/qt/gksqt.app artifacts/Applications/gksqt.app @@ -974,10 +951,8 @@ darwin-self-contained-iff1605: lib/grm/libGRM.a lib/grm/libGRM.dylib lib/gr/qtgr/*.dylib artifacts/ - cp -r lib/gks/fonts artifacts/ - mkdir artifacts/include/ - - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - - mkdir artifacts/include/grm/ - - cp lib/grm/args.h lib/grm/dump.h lib/grm/event.h lib/grm/interaction.h lib/grm/net.h lib/grm/plot.h lib/grm/util.h - artifacts/include/grm/ + - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ + - cp -r lib/grm/include/grm artifacts/include/ - mkdir artifacts/Applications/ - cp -r lib/gks/quartz/build/Release/GKSTerm.app artifacts/Applications/GKSTerm.app - cp -r lib/gks/qt/gksqt.app artifacts/Applications/gksqt.app diff --git a/CMakeLists.txt b/CMakeLists.txt index 47d4e2b61..36eda202e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -455,34 +455,24 @@ elseif(NOT OpenGL_FOUND) endif() set(GRM_SOURCES - lib/grm/args.c - lib/grm/base64.c - lib/grm/dump.c - lib/grm/dynamic_args_array.c - lib/grm/error.c - lib/grm/event.c - lib/grm/interaction.c - lib/grm/json.c - lib/grm/logging.c - lib/grm/memwriter.c - lib/grm/net.c - lib/grm/plot.c - lib/grm/util.c - lib/grm/datatype/double_map.c - lib/grm/datatype/string_array_map.c - lib/grm/datatype/string_list.c - lib/grm/datatype/string_map.c - lib/grm/datatype/uint_map.c -) - -set(GRM_SUBDIR_HEADERS - lib/grm/args.h - lib/grm/dump.h - lib/grm/event.h - lib/grm/interaction.h - lib/grm/net.h - lib/grm/plot.h - lib/grm/util.h + lib/grm/src/grm/args.c + lib/grm/src/grm/base64.c + lib/grm/src/grm/dump.c + lib/grm/src/grm/dynamic_args_array.c + lib/grm/src/grm/error.c + lib/grm/src/grm/event.c + lib/grm/src/grm/interaction.c + lib/grm/src/grm/json.c + lib/grm/src/grm/logging.c + lib/grm/src/grm/memwriter.c + lib/grm/src/grm/net.c + lib/grm/src/grm/plot.c + lib/grm/src/grm/util.c + lib/grm/src/grm/datatype/double_map.c + lib/grm/src/grm/datatype/string_array_map.c + lib/grm/src/grm/datatype/string_list.c + lib/grm/src/grm/datatype/string_map.c + lib/grm/src/grm/datatype/uint_map.c ) add_library(grm_static STATIC ${GRM_SOURCES}) @@ -506,8 +496,8 @@ foreach(LIBRARY grm_static grm_shared grm_shared_internal) endif() target_include_directories( ${LIBRARY} - PUBLIC $ $ - $ + PUBLIC $ + $ $ ) target_compile_options(${LIBRARY} PRIVATE ${COMPILER_OPTION_ERROR_IMPLICIT}) set_target_properties( @@ -1100,8 +1090,8 @@ if(GR_BUILD_DEMOS) target_compile_options(grdemo PRIVATE ${COMPILER_OPTION_ERROR_IMPLICIT}) set_target_properties(grdemo PROPERTIES C_STANDARD 90 C_EXTENSIONS OFF C_STANDARD_REQUIRED ON) - add_subdirectory(lib/grm/test/public_api grm_test_public_api) - add_subdirectory(lib/grm/test/internal_api grm_test_internal_api) + add_subdirectory(lib/grm/test/public_api/grm grm_test_public_api) + add_subdirectory(lib/grm/test/internal_api/grm grm_test_internal_api) endif() if(GR_INSTALL) @@ -1233,8 +1223,8 @@ if(GR_INSTALL) BUNDLE DESTINATION Applications ) endif() - install(FILES lib/gr/gr.h lib/gks/gks.h lib/gr3/gr3.h lib/grm/grm.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/) - install(FILES ${GRM_SUBDIR_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/grm/) + install(FILES lib/gr/gr.h lib/gks/gks.h lib/gr3/gr3.h lib/grm/include/grm.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/) + install(DIRECTORY lib/grm/include/grm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/) if(TARGET qt4gr OR TARGET qt5gr OR TARGET qt6gr diff --git a/js/Makefile b/js/Makefile index 9ce34019f..5921567c5 100755 --- a/js/Makefile +++ b/js/Makefile @@ -34,25 +34,78 @@ QHULLDIR = ../3rdparty/qhull GRDIR = ../lib/gr GR3DIR = ../lib/gr3 GRMDIR = ../lib/grm -INCLUDES = -I$(THIRDPARTYDIR)/include/ -I$(GRMDIR) -I$(GR3DIR) -I$(GRDIR) -I$(GKSDIR) -I$(JPEGDIR) -I$(PNGDIR) \ - -I$(ZLIBDIR) -I$(QHULLDIR) -I$(FTDIR) - GKSOBJS = jsplugin.o $(GKSDIR)/gks.o $(GKSDIR)/font.o $(GKSDIR)/afm.o $(GKSDIR)/util.o \ - $(GKSDIR)/malloc.o $(GKSDIR)/error.o $(GKSDIR)/wiss.o $(GKSDIR)/io.o $(GKSDIR)/ft.o - GROBJS = $(GRDIR)/gr.o $(GRDIR)/stream.o $(GRDIR)/text.o $(GRDIR)/gridit.o \ - $(GRDIR)/strlib.o $(GRDIR)/contour.o $(GRDIR)/spline.o \ - $(GRDIR)/import.o $(GRDIR)/grforbnd.o $(GRDIR)/md5.o \ - $(GRDIR)/interp2.o $(GRDIR)/shade.o $(GRDIR)/delaunay.o \ - $(GRDIR)/contourf.o $(GRDIR)/image.o $(GRDIR)/mathtex2.o $(GRDIR)/mathtex2_kerning.o $(GRDIR)/mathtex2.tab.o - GR3OBJS = $(GR3DIR)/gr3.o $(GR3DIR)/gr3_convenience.o \ - $(GR3DIR)/gr3_html.o $(GR3DIR)/gr3_povray.o $(GR3DIR)/gr3_png.o \ - $(GR3DIR)/gr3_jpeg.o $(GR3DIR)/gr3_gr.o $(GR3DIR)/gr3_mc.o $(GR3DIR)/gr3_sr.o - GRMOBJS = $(GRMDIR)/args.o $(GRMDIR)/base64.o $(GRMDIR)/dump.o $(GRMDIR)/dynamic_args_array.o $(GRMDIR)/error.o \ - $(GRMDIR)/event.o $(GRMDIR)/interaction.o $(GRMDIR)/json.o $(GRMDIR)/logging.o $(GRMDIR)/memwriter.o \ - $(GRMDIR)/net.o $(GRMDIR)/plot.o $(GRMDIR)/util.o $(GRMDIR)/datatype/double_map.o \ - $(GRMDIR)/datatype/string_array_map.o $(GRMDIR)/datatype/string_list.o $(GRMDIR)/datatype/string_map.o \ - $(GRMDIR)/datatype/uint_map.o +INCLUDES = -I$(THIRDPARTYDIR)/include/ \ + -I$(GRMDIR)/include \ + -I$(GRMDIR)/src \ + -I$(GR3DIR) \ + -I$(GRDIR) \ + -I$(GKSDIR) \ + -I$(JPEGDIR) \ + -I$(PNGDIR) \ + -I$(ZLIBDIR) \ + -I$(QHULLDIR) \ + -I$(FTDIR) + GKSOBJS = jsplugin.o \ + $(GKSDIR)/gks.o \ + $(GKSDIR)/font.o \ + $(GKSDIR)/afm.o \ + $(GKSDIR)/util.o \ + $(GKSDIR)/malloc.o \ + $(GKSDIR)/error.o \ + $(GKSDIR)/wiss.o \ + $(GKSDIR)/io.o \ + $(GKSDIR)/ft.o + GROBJS = $(GRDIR)/gr.o \ + $(GRDIR)/stream.o \ + $(GRDIR)/text.o \ + $(GRDIR)/gridit.o \ + $(GRDIR)/strlib.o \ + $(GRDIR)/contour.o \ + $(GRDIR)/spline.o \ + $(GRDIR)/import.o \ + $(GRDIR)/grforbnd.o \ + $(GRDIR)/md5.o \ + $(GRDIR)/interp2.o \ + $(GRDIR)/shade.o \ + $(GRDIR)/delaunay.o \ + $(GRDIR)/contourf.o \ + $(GRDIR)/image.o \ + $(GRDIR)/mathtex2.o \ + $(GRDIR)/mathtex2_kerning.o \ + $(GRDIR)/mathtex2.tab.o + GR3OBJS = $(GR3DIR)/gr3.o \ + $(GR3DIR)/gr3_convenience.o \ + $(GR3DIR)/gr3_html.o \ + $(GR3DIR)/gr3_povray.o \ + $(GR3DIR)/gr3_png.o \ + $(GR3DIR)/gr3_jpeg.o \ + $(GR3DIR)/gr3_gr.o \ + $(GR3DIR)/gr3_mc.o \ + $(GR3DIR)/gr3_sr.o + GRMOBJS = $(GRMDIR)/src/grm/args.o \ + $(GRMDIR)/src/grm/base64.o \ + $(GRMDIR)/src/grm/dump.o \ + $(GRMDIR)/src/grm/dynamic_args_array.o \ + $(GRMDIR)/src/grm/error.o \ + $(GRMDIR)/src/grm/event.o \ + $(GRMDIR)/src/grm/interaction.o \ + $(GRMDIR)/src/grm/json.o \ + $(GRMDIR)/src/grm/logging.o \ + $(GRMDIR)/src/grm/memwriter.o \ + $(GRMDIR)/src/grm/net.o \ + $(GRMDIR)/src/grm/plot.o \ + $(GRMDIR)/src/grm/util.o \ + $(GRMDIR)/src/grm/datatype/double_map.o \ + $(GRMDIR)/src/grm/datatype/string_array_map.o \ + $(GRMDIR)/src/grm/datatype/string_list.o \ + $(GRMDIR)/src/grm/datatype/string_map.o \ + $(GRMDIR)/src/grm/datatype/uint_map.o OBJS = $(GRMOBJS) $(GR3OBJS) $(GROBJS) $(GKSOBJS) - LIBS = $(JPEGDIR)/libjpeg.a $(PNGDIR)/libpng.a $(ZLIBDIR)/libz.a $(QHULLDIR)/libqhull.a $(FTDIR)/libfreetype.a + LIBS = $(JPEGDIR)/libjpeg.a \ + $(PNGDIR)/libpng.a \ + $(ZLIBDIR)/libz.a \ + $(QHULLDIR)/libqhull.a \ + $(FTDIR)/libfreetype.a .PHONY: default clean .SECONDARY .FORCE diff --git a/lib/grm/Makefile b/lib/grm/Makefile index e68428059..a232e5706 100644 --- a/lib/grm/Makefile +++ b/lib/grm/Makefile @@ -5,16 +5,34 @@ endif GRDIR = /usr/local/gr LIBDIR = $(DESTDIR)$(GRDIR)/lib INCDIR = $(DESTDIR)$(GRDIR)/include - GRMINCDIR = $(INCDIR)/grm UNAME := $(shell uname) - GRMOBJS = args.o base64.o dump.o dynamic_args_array.o error.o event.o interaction.o json.o logging.o memwriter.o \ - net.o plot.o util.o datatype/double_map.o datatype/string_list.o datatype/string_array_map.o \ - datatype/string_map.o datatype/uint_map.o - GRMHEADERS = args.h dump.h event.h interaction.h net.h plot.h util.h + GRMOBJS = src/grm/args.o \ + src/grm/base64.o \ + src/grm/dump.o \ + src/grm/dynamic_args_array.o \ + src/grm/error.o \ + src/grm/event.o \ + src/grm/interaction.o \ + src/grm/json.o \ + src/grm/logging.o \ + src/grm/memwriter.o \ + src/grm/net.o \ + src/grm/plot.o \ + src/grm/util.o \ + src/grm/datatype/double_map.o \ + src/grm/datatype/string_list.o \ + src/grm/datatype/string_array_map.o \ + src/grm/datatype/string_map.o \ + src/grm/datatype/uint_map.o DEFINES = - INCLUDES = -I. -I../gks -I../gr -I../gr3 -I$(THIRDPARTYDIR)/include + INCLUDES = -I./include \ + -I./src \ + -I../gks \ + -I../gr \ + -I../gr3 \ + -I$(THIRDPARTYDIR)/include CC = cc CFLAGS = $(DEFINES) -O3 -Wall -fPIC -fvisibility=hidden $(EXTRA_CFLAGS) AR ?= ar @@ -67,11 +85,14 @@ install: @if [ ! -d $(LIBDIR) ]; then mkdir -m 755 $(LIBDIR); fi cp -p libGRM.* $(LIBDIR) @if [ ! -d $(INCDIR) ]; then mkdir -m 755 $(INCDIR); fi - cp -p grm.h $(INCDIR) - @if [ ! -d $(GRMINCDIR) ]; then mkdir -m 755 $(GRMINCDIR); fi - cp -p $(GRMHEADERS) $(GRMINCDIR) + cp -p include/grm.h $(INCDIR) + cp -rp include/grm $(INCDIR)/ clean: - rm -f *.so *.a *.o datatype/*.o *${GR_SHARED_LIBRARY_SUFFIX} + rm -f *.so \ + *.a \ + src/grm/*.o \ + src/grm/datatype/*.o \ + *${GR_SHARED_LIBRARY_SUFFIX} .PHONY: all targets install clean prerequisites libGR libGR3 diff --git a/lib/grm/grm.h b/lib/grm/grm.h deleted file mode 100644 index 3349ea95b..000000000 --- a/lib/grm/grm.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GRM_H_INCLUDED -#define GRM_H_INCLUDED - -/* This is a convenience header which includes all public header files of the GRM library. */ - - -#include "grm/args.h" -#include "grm/dump.h" -#include "grm/event.h" -#include "grm/interaction.h" -#include "grm/net.h" -#include "grm/plot.h" -#include "grm/util.h" - - -#endif /* ifndef GRM_H_INCLUDED */ diff --git a/lib/grm/include/grm.h b/lib/grm/include/grm.h new file mode 100644 index 000000000..d1f6ac7ae --- /dev/null +++ b/lib/grm/include/grm.h @@ -0,0 +1,15 @@ +#ifndef GRM_H_INCLUDED +#define GRM_H_INCLUDED + +/* This is a convenience header which includes all public header files of the GRM library. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* ifndef GRM_H_INCLUDED */ diff --git a/lib/grm/args.h b/lib/grm/include/grm/args.h similarity index 100% rename from lib/grm/args.h rename to lib/grm/include/grm/args.h diff --git a/lib/grm/include/grm/base64.h b/lib/grm/include/grm/base64.h new file mode 100644 index 000000000..2edf0b263 --- /dev/null +++ b/lib/grm/include/grm/base64.h @@ -0,0 +1,23 @@ +#ifndef GRM_BASE64_H_INCLUDED +#define GRM_BASE64_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +/* ######################### includes ############################################################################### */ + +#include + +#include "util.h" + + +/* ######################### public interface ####################################################################### */ + +EXPORT char *grm_base64_decode(char *dst, const char *src, size_t *dst_len, int *was_successful); +EXPORT char *grm_base64_encode(char *dst, const char *src, size_t src_len, int *was_successful); + +#ifdef __cplusplus +} +#endif +#endif /* ifndef GRM_BASE64_H_INCLUDED */ diff --git a/lib/grm/dump.h b/lib/grm/include/grm/dump.h similarity index 100% rename from lib/grm/dump.h rename to lib/grm/include/grm/dump.h diff --git a/lib/grm/event.h b/lib/grm/include/grm/event.h similarity index 100% rename from lib/grm/event.h rename to lib/grm/include/grm/event.h diff --git a/lib/grm/interaction.h b/lib/grm/include/grm/interaction.h similarity index 100% rename from lib/grm/interaction.h rename to lib/grm/include/grm/interaction.h diff --git a/lib/grm/net.h b/lib/grm/include/grm/net.h similarity index 100% rename from lib/grm/net.h rename to lib/grm/include/grm/net.h diff --git a/lib/grm/plot.h b/lib/grm/include/grm/plot.h similarity index 100% rename from lib/grm/plot.h rename to lib/grm/include/grm/plot.h diff --git a/lib/grm/util.h b/lib/grm/include/grm/util.h similarity index 100% rename from lib/grm/util.h rename to lib/grm/include/grm/util.h diff --git a/lib/grm/makefile.mingw b/lib/grm/makefile.mingw index d2269d2c9..e48a0370f 100644 --- a/lib/grm/makefile.mingw +++ b/lib/grm/makefile.mingw @@ -3,17 +3,37 @@ override THIRDPARTYDIR = $(abspath $(CURDIR)/../../3rdparty/build) endif DEFINES = -DGRDIR=\"$(GRDIR)\" -DNO_GS -DNO_X11 -D_WIN32_WINNT=0x0600 -DBUILDING_DLL - INCLUDES = -I. -I../gks -I../gr -I../gr3 -I$(THIRDPARTYDIR)/include - CFLAGS = $(DEFINES) $(INCLUDES) + CFLAGS = $(DEFINES) -std=c90 + INCLUDES = -I./include \ + -I./src \ + -I../gks \ + -I../gr \ + -I../gr3 \ + -I$(THIRDPARTYDIR)/include GKSLIBS = -L ../gks/ -lGKS GRLIBS = -L ../gr/ -lGR GR3LIBS = -L ../gr3/ -lGR3 LDFLAGS = -Wl,--out-implib,$(@:.dll=.a) LIBS = $(GR3LIBS) $(GRLIBS) $(GKSLIBS) -lm -lws2_32 -lmsimg32 -lgdi32 -OBJS = args.o base64.o datatype/double_map.o datatype/string_array_map.o datatype/string_list.o datatype/string_map.o \ - datatype/uint_map.o dump.o dynamic_args_array.o error.o event.o interaction.o json.o logging.o memwriter.o \ - net.o plot.o util.o + OBJS = src/grm/args.o \ + src/grm/base64.o \ + src/grm/dump.o \ + src/grm/dynamic_args_array.o \ + src/grm/error.o \ + src/grm/event.o \ + src/grm/interaction.o \ + src/grm/json.o \ + src/grm/logging.o \ + src/grm/memwriter.o \ + src/grm/net.o \ + src/grm/plot.o \ + src/grm/util.o \ + src/grm/datatype/double_map.o \ + src/grm/datatype/string_array_map.o \ + src/grm/datatype/string_list.o \ + src/grm/datatype/string_map.o \ + src/grm/datatype/uint_map.o .SUFFIXES: .o .c @@ -34,7 +54,9 @@ libGRM.dll: $(OBJS) grm.c: grm.h clean: - $(RM) libGRM.so - $(RM) *.o + $(RM) libGRM.lib \ + libGRM.dll \ + src/grm/*.o \ + src/grm/datatype/*.o .PHONY: default all clean diff --git a/lib/grm/args.c b/lib/grm/src/grm/args.c similarity index 100% rename from lib/grm/args.c rename to lib/grm/src/grm/args.c diff --git a/lib/grm/args_int.h b/lib/grm/src/grm/args_int.h similarity index 99% rename from lib/grm/args_int.h rename to lib/grm/src/grm/args_int.h index a1f1c635a..d47bd0643 100644 --- a/lib/grm/args_int.h +++ b/lib/grm/src/grm/args_int.h @@ -7,7 +7,7 @@ #include #include -#include "args.h" +#include #include "error_int.h" #include "util_int.h" diff --git a/lib/grm/base64.c b/lib/grm/src/grm/base64.c similarity index 100% rename from lib/grm/base64.c rename to lib/grm/src/grm/base64.c diff --git a/lib/grm/base64_int.h b/lib/grm/src/grm/base64_int.h similarity index 95% rename from lib/grm/base64_int.h rename to lib/grm/src/grm/base64_int.h index a442ffc19..63418e809 100644 --- a/lib/grm/base64_int.h +++ b/lib/grm/src/grm/base64_int.h @@ -4,6 +4,7 @@ #include #include "error_int.h" +#include error_t block_decode(char dst[3], const char src[4], int block_len, int *decoded_block_len); diff --git a/lib/grm/datatype/double_map.c b/lib/grm/src/grm/datatype/double_map.c similarity index 100% rename from lib/grm/datatype/double_map.c rename to lib/grm/src/grm/datatype/double_map.c diff --git a/lib/grm/datatype/double_map_int.h b/lib/grm/src/grm/datatype/double_map_int.h similarity index 100% rename from lib/grm/datatype/double_map_int.h rename to lib/grm/src/grm/datatype/double_map_int.h diff --git a/lib/grm/datatype/string_array_map.c b/lib/grm/src/grm/datatype/string_array_map.c similarity index 100% rename from lib/grm/datatype/string_array_map.c rename to lib/grm/src/grm/datatype/string_array_map.c diff --git a/lib/grm/datatype/string_array_map_int.h b/lib/grm/src/grm/datatype/string_array_map_int.h similarity index 100% rename from lib/grm/datatype/string_array_map_int.h rename to lib/grm/src/grm/datatype/string_array_map_int.h diff --git a/lib/grm/datatype/string_list.c b/lib/grm/src/grm/datatype/string_list.c similarity index 100% rename from lib/grm/datatype/string_list.c rename to lib/grm/src/grm/datatype/string_list.c diff --git a/lib/grm/datatype/string_list_int.h b/lib/grm/src/grm/datatype/string_list_int.h similarity index 100% rename from lib/grm/datatype/string_list_int.h rename to lib/grm/src/grm/datatype/string_list_int.h diff --git a/lib/grm/datatype/string_map.c b/lib/grm/src/grm/datatype/string_map.c similarity index 100% rename from lib/grm/datatype/string_map.c rename to lib/grm/src/grm/datatype/string_map.c diff --git a/lib/grm/datatype/string_map_int.h b/lib/grm/src/grm/datatype/string_map_int.h similarity index 100% rename from lib/grm/datatype/string_map_int.h rename to lib/grm/src/grm/datatype/string_map_int.h diff --git a/lib/grm/datatype/template/list_int.h b/lib/grm/src/grm/datatype/template/list_int.h similarity index 99% rename from lib/grm/datatype/template/list_int.h rename to lib/grm/src/grm/datatype/template/list_int.h index e47b56624..b65f65477 100644 --- a/lib/grm/datatype/template/list_int.h +++ b/lib/grm/src/grm/datatype/template/list_int.h @@ -5,8 +5,8 @@ #include #include -#include "error_int.h" -#include "util_int.h" +#include +#include /* ######################### interface ############################################################################## */ diff --git a/lib/grm/datatype/template/map_int.h b/lib/grm/src/grm/datatype/template/map_int.h similarity index 99% rename from lib/grm/datatype/template/map_int.h rename to lib/grm/src/grm/datatype/template/map_int.h index c43dbf61f..44a976015 100644 --- a/lib/grm/datatype/template/map_int.h +++ b/lib/grm/src/grm/datatype/template/map_int.h @@ -12,7 +12,7 @@ #include "gkscore.h" #include "set_int.h" -#include "util_int.h" +#include /* ######################### interface ############################################################################## */ diff --git a/lib/grm/datatype/template/set_int.h b/lib/grm/src/grm/datatype/template/set_int.h similarity index 99% rename from lib/grm/datatype/template/set_int.h rename to lib/grm/src/grm/datatype/template/set_int.h index 9d2ebfe24..1720ea529 100644 --- a/lib/grm/datatype/template/set_int.h +++ b/lib/grm/src/grm/datatype/template/set_int.h @@ -10,9 +10,9 @@ typedef SSIZE_T ssize_t; #endif -#include "error_int.h" -#include "logging_int.h" -#include "util_int.h" +#include +#include +#include /* ######################### interface ############################################################################## */ diff --git a/lib/grm/datatype/uint_map.c b/lib/grm/src/grm/datatype/uint_map.c similarity index 100% rename from lib/grm/datatype/uint_map.c rename to lib/grm/src/grm/datatype/uint_map.c diff --git a/lib/grm/datatype/uint_map_int.h b/lib/grm/src/grm/datatype/uint_map_int.h similarity index 100% rename from lib/grm/datatype/uint_map_int.h rename to lib/grm/src/grm/datatype/uint_map_int.h diff --git a/lib/grm/dump.c b/lib/grm/src/grm/dump.c similarity index 100% rename from lib/grm/dump.c rename to lib/grm/src/grm/dump.c diff --git a/lib/grm/dump_int.h b/lib/grm/src/grm/dump_int.h similarity index 91% rename from lib/grm/dump_int.h rename to lib/grm/src/grm/dump_int.h index 1a6d5ad60..757e8bb71 100644 --- a/lib/grm/dump_int.h +++ b/lib/grm/src/grm/dump_int.h @@ -3,7 +3,7 @@ /* ######################### includes ############################################################################### */ -#include "dump.h" +#include #endif /* ifndef GRM_DUMP_INT_H_INCLUDED */ diff --git a/lib/grm/dynamic_args_array.c b/lib/grm/src/grm/dynamic_args_array.c similarity index 100% rename from lib/grm/dynamic_args_array.c rename to lib/grm/src/grm/dynamic_args_array.c diff --git a/lib/grm/dynamic_args_array_int.h b/lib/grm/src/grm/dynamic_args_array_int.h similarity index 98% rename from lib/grm/dynamic_args_array_int.h rename to lib/grm/src/grm/dynamic_args_array_int.h index 55fd7286b..58bb0b000 100644 --- a/lib/grm/dynamic_args_array_int.h +++ b/lib/grm/src/grm/dynamic_args_array_int.h @@ -3,7 +3,7 @@ /* ######################### includes ############################################################################### */ -#include "args.h" +#include #include "error_int.h" diff --git a/lib/grm/error.c b/lib/grm/src/grm/error.c similarity index 100% rename from lib/grm/error.c rename to lib/grm/src/grm/error.c diff --git a/lib/grm/error_int.h b/lib/grm/src/grm/error_int.h similarity index 100% rename from lib/grm/error_int.h rename to lib/grm/src/grm/error_int.h diff --git a/lib/grm/event.c b/lib/grm/src/grm/event.c similarity index 100% rename from lib/grm/event.c rename to lib/grm/src/grm/event.c diff --git a/lib/grm/event_int.h b/lib/grm/src/grm/event_int.h similarity index 98% rename from lib/grm/event_int.h rename to lib/grm/src/grm/event_int.h index 4bb961512..3c8ecf422 100644 --- a/lib/grm/event_int.h +++ b/lib/grm/src/grm/event_int.h @@ -5,7 +5,7 @@ #include "datatype/template/list_int.h" #include "error_int.h" -#include "event.h" +#include /* ######################### internal interface ##################################################################### */ diff --git a/lib/grm/interaction.c b/lib/grm/src/grm/interaction.c similarity index 100% rename from lib/grm/interaction.c rename to lib/grm/src/grm/interaction.c diff --git a/lib/grm/interaction_int.h b/lib/grm/src/grm/interaction_int.h similarity index 96% rename from lib/grm/interaction_int.h rename to lib/grm/src/grm/interaction_int.h index cc1607bf2..d7b914b4e 100644 --- a/lib/grm/interaction_int.h +++ b/lib/grm/src/grm/interaction_int.h @@ -3,7 +3,7 @@ /* ######################### includes ############################################################################### */ -#include "interaction.h" +#include /* ######################### internal interface ##################################################################### */ diff --git a/lib/grm/json.c b/lib/grm/src/grm/json.c similarity index 100% rename from lib/grm/json.c rename to lib/grm/src/grm/json.c diff --git a/lib/grm/json_int.h b/lib/grm/src/grm/json_int.h similarity index 99% rename from lib/grm/json_int.h rename to lib/grm/src/grm/json_int.h index d2342cc83..47739648b 100644 --- a/lib/grm/json_int.h +++ b/lib/grm/src/grm/json_int.h @@ -5,7 +5,7 @@ #include -#include "args.h" +#include #include "error_int.h" #include "memwriter_int.h" diff --git a/lib/grm/logging.c b/lib/grm/src/grm/logging.c similarity index 100% rename from lib/grm/logging.c rename to lib/grm/src/grm/logging.c diff --git a/lib/grm/logging_int.h b/lib/grm/src/grm/logging_int.h similarity index 100% rename from lib/grm/logging_int.h rename to lib/grm/src/grm/logging_int.h diff --git a/lib/grm/memwriter.c b/lib/grm/src/grm/memwriter.c similarity index 100% rename from lib/grm/memwriter.c rename to lib/grm/src/grm/memwriter.c diff --git a/lib/grm/memwriter_int.h b/lib/grm/src/grm/memwriter_int.h similarity index 100% rename from lib/grm/memwriter_int.h rename to lib/grm/src/grm/memwriter_int.h diff --git a/lib/grm/net.c b/lib/grm/src/grm/net.c similarity index 100% rename from lib/grm/net.c rename to lib/grm/src/grm/net.c diff --git a/lib/grm/net_int.h b/lib/grm/src/grm/net_int.h similarity index 99% rename from lib/grm/net_int.h rename to lib/grm/src/grm/net_int.h index 12d448e12..331293d62 100644 --- a/lib/grm/net_int.h +++ b/lib/grm/src/grm/net_int.h @@ -5,7 +5,7 @@ #include "error_int.h" #include "memwriter_int.h" -#include "net.h" +#include /* ######################### internal interface ##################################################################### */ diff --git a/lib/grm/plot.c b/lib/grm/src/grm/plot.c similarity index 99% rename from lib/grm/plot.c rename to lib/grm/src/grm/plot.c index 6ced8c9ac..cde6d8ebc 100644 --- a/lib/grm/plot.c +++ b/lib/grm/src/grm/plot.c @@ -12,7 +12,7 @@ #include #include "base64_int.h" -#include "dump.h" +#include #include "event_int.h" #include "gks.h" #include "gr.h" diff --git a/lib/grm/plot_int.h b/lib/grm/src/grm/plot_int.h similarity index 99% rename from lib/grm/plot_int.h rename to lib/grm/src/grm/plot_int.h index d9d1c55a3..ddba6b407 100644 --- a/lib/grm/plot_int.h +++ b/lib/grm/src/grm/plot_int.h @@ -7,7 +7,7 @@ #include "datatype/uint_map_int.h" #include "error_int.h" #include "event_int.h" -#include "plot.h" +#include /* ######################### internal interface ##################################################################### */ diff --git a/lib/grm/util.c b/lib/grm/src/grm/util.c similarity index 100% rename from lib/grm/util.c rename to lib/grm/src/grm/util.c diff --git a/lib/grm/util_int.h b/lib/grm/src/grm/util_int.h similarity index 99% rename from lib/grm/util_int.h rename to lib/grm/src/grm/util_int.h index 5dca272f5..e80c7e3b3 100644 --- a/lib/grm/util_int.h +++ b/lib/grm/src/grm/util_int.h @@ -5,9 +5,9 @@ #include -#include "args.h" +#include #include "logging_int.h" -#include "util.h" +#include /* ######################### internal interface ##################################################################### */ diff --git a/lib/grm/test/internal_api/CMakeLists.txt b/lib/grm/test/internal_api/grm/CMakeLists.txt similarity index 100% rename from lib/grm/test/internal_api/CMakeLists.txt rename to lib/grm/test/internal_api/grm/CMakeLists.txt diff --git a/lib/grm/test/internal_api/args_automatic_array_conversion.c b/lib/grm/test/internal_api/grm/args_automatic_array_conversion.c similarity index 98% rename from lib/grm/test/internal_api/args_automatic_array_conversion.c rename to lib/grm/test/internal_api/grm/args_automatic_array_conversion.c index ec453810a..e222519b5 100644 --- a/lib/grm/test/internal_api/args_automatic_array_conversion.c +++ b/lib/grm/test/internal_api/grm/args_automatic_array_conversion.c @@ -6,7 +6,7 @@ #include "test.h" -#include "args_int.h" +#include void test(void) diff --git a/lib/grm/test/internal_api/datatype/string_array_map.c b/lib/grm/test/internal_api/grm/datatype/string_array_map.c similarity index 92% rename from lib/grm/test/internal_api/datatype/string_array_map.c rename to lib/grm/test/internal_api/grm/datatype/string_array_map.c index 6f034e4d7..1bd0783d8 100644 --- a/lib/grm/test/internal_api/datatype/string_array_map.c +++ b/lib/grm/test/internal_api/grm/datatype/string_array_map.c @@ -4,7 +4,7 @@ #include "test.h" -#include "datatype/string_array_map_int.h" +#include static const string_map_entry_t test_data[] = {{"test", "abc|def|ghi"}}; diff --git a/lib/grm/test/internal_api/get_compatible_format.c b/lib/grm/test/internal_api/grm/get_compatible_format.c similarity index 97% rename from lib/grm/test/internal_api/get_compatible_format.c rename to lib/grm/test/internal_api/grm/get_compatible_format.c index 352701d4c..c6f98196d 100644 --- a/lib/grm/test/internal_api/get_compatible_format.c +++ b/lib/grm/test/internal_api/grm/get_compatible_format.c @@ -4,7 +4,7 @@ #include "test.h" -#include "plot_int.h" +#include void test(void) diff --git a/lib/grm/test/internal_api/test.h b/lib/grm/test/internal_api/grm/test.h similarity index 100% rename from lib/grm/test/internal_api/test.h rename to lib/grm/test/internal_api/grm/test.h diff --git a/lib/grm/test/public_api/CMakeLists.txt b/lib/grm/test/public_api/grm/CMakeLists.txt similarity index 100% rename from lib/grm/test/public_api/CMakeLists.txt rename to lib/grm/test/public_api/grm/CMakeLists.txt diff --git a/lib/grm/test/public_api/bar_errorbar.c b/lib/grm/test/public_api/grm/bar_errorbar.c similarity index 100% rename from lib/grm/test/public_api/bar_errorbar.c rename to lib/grm/test/public_api/grm/bar_errorbar.c diff --git a/lib/grm/test/public_api/barplot.c b/lib/grm/test/public_api/grm/barplot.c similarity index 100% rename from lib/grm/test/public_api/barplot.c rename to lib/grm/test/public_api/grm/barplot.c diff --git a/lib/grm/test/public_api/custom_receiver.c b/lib/grm/test/public_api/grm/custom_receiver.c similarity index 100% rename from lib/grm/test/public_api/custom_receiver.c rename to lib/grm/test/public_api/grm/custom_receiver.c diff --git a/lib/grm/test/public_api/custom_sender.c b/lib/grm/test/public_api/grm/custom_sender.c similarity index 100% rename from lib/grm/test/public_api/custom_sender.c rename to lib/grm/test/public_api/grm/custom_sender.c diff --git a/lib/grm/test/public_api/event_handling.c b/lib/grm/test/public_api/grm/event_handling.c similarity index 100% rename from lib/grm/test/public_api/event_handling.c rename to lib/grm/test/public_api/grm/event_handling.c diff --git a/lib/grm/test/public_api/heatmap.c b/lib/grm/test/public_api/grm/heatmap.c similarity index 100% rename from lib/grm/test/public_api/heatmap.c rename to lib/grm/test/public_api/grm/heatmap.c diff --git a/lib/grm/test/public_api/histogram.c b/lib/grm/test/public_api/grm/histogram.c similarity index 100% rename from lib/grm/test/public_api/histogram.c rename to lib/grm/test/public_api/grm/histogram.c diff --git a/lib/grm/test/public_api/hold_append.c b/lib/grm/test/public_api/grm/hold_append.c similarity index 100% rename from lib/grm/test/public_api/hold_append.c rename to lib/grm/test/public_api/grm/hold_append.c diff --git a/lib/grm/test/public_api/imshow.c b/lib/grm/test/public_api/grm/imshow.c similarity index 100% rename from lib/grm/test/public_api/imshow.c rename to lib/grm/test/public_api/grm/imshow.c diff --git a/lib/grm/test/public_api/isosurface.c b/lib/grm/test/public_api/grm/isosurface.c similarity index 100% rename from lib/grm/test/public_api/isosurface.c rename to lib/grm/test/public_api/grm/isosurface.c diff --git a/lib/grm/test/public_api/line_errorbar.c b/lib/grm/test/public_api/grm/line_errorbar.c similarity index 100% rename from lib/grm/test/public_api/line_errorbar.c rename to lib/grm/test/public_api/grm/line_errorbar.c diff --git a/lib/grm/test/public_api/merge_args.c b/lib/grm/test/public_api/grm/merge_args.c similarity index 100% rename from lib/grm/test/public_api/merge_args.c rename to lib/grm/test/public_api/grm/merge_args.c diff --git a/lib/grm/test/public_api/multi_plot.c b/lib/grm/test/public_api/grm/multi_plot.c similarity index 100% rename from lib/grm/test/public_api/multi_plot.c rename to lib/grm/test/public_api/grm/multi_plot.c diff --git a/lib/grm/test/public_api/pie.c b/lib/grm/test/public_api/grm/pie.c similarity index 100% rename from lib/grm/test/public_api/pie.c rename to lib/grm/test/public_api/grm/pie.c diff --git a/lib/grm/test/public_api/plot.c b/lib/grm/test/public_api/grm/plot.c similarity index 100% rename from lib/grm/test/public_api/plot.c rename to lib/grm/test/public_api/grm/plot.c diff --git a/lib/grm/test/public_api/polar_histogram.c b/lib/grm/test/public_api/grm/polar_histogram.c similarity index 100% rename from lib/grm/test/public_api/polar_histogram.c rename to lib/grm/test/public_api/grm/polar_histogram.c diff --git a/lib/grm/test/public_api/qt/gr_widget.cxx b/lib/grm/test/public_api/grm/qt/gr_widget.cxx similarity index 100% rename from lib/grm/test/public_api/qt/gr_widget.cxx rename to lib/grm/test/public_api/grm/qt/gr_widget.cxx diff --git a/lib/grm/test/public_api/qt/gr_widget.hxx b/lib/grm/test/public_api/grm/qt/gr_widget.hxx similarity index 100% rename from lib/grm/test/public_api/qt/gr_widget.hxx rename to lib/grm/test/public_api/grm/qt/gr_widget.hxx diff --git a/lib/grm/test/public_api/qt/main.cxx b/lib/grm/test/public_api/grm/qt/main.cxx similarity index 100% rename from lib/grm/test/public_api/qt/main.cxx rename to lib/grm/test/public_api/grm/qt/main.cxx diff --git a/lib/grm/test/public_api/qt/main_window.cxx b/lib/grm/test/public_api/grm/qt/main_window.cxx similarity index 100% rename from lib/grm/test/public_api/qt/main_window.cxx rename to lib/grm/test/public_api/grm/qt/main_window.cxx diff --git a/lib/grm/test/public_api/qt/main_window.hxx b/lib/grm/test/public_api/grm/qt/main_window.hxx similarity index 100% rename from lib/grm/test/public_api/qt/main_window.hxx rename to lib/grm/test/public_api/grm/qt/main_window.hxx diff --git a/lib/grm/test/public_api/qt/qt_grm_test.pro b/lib/grm/test/public_api/grm/qt/qt_grm_test.pro similarity index 100% rename from lib/grm/test/public_api/qt/qt_grm_test.pro rename to lib/grm/test/public_api/grm/qt/qt_grm_test.pro diff --git a/lib/grm/test/public_api/qt/util.hxx b/lib/grm/test/public_api/grm/qt/util.hxx similarity index 100% rename from lib/grm/test/public_api/qt/util.hxx rename to lib/grm/test/public_api/grm/qt/util.hxx diff --git a/lib/grm/test/public_api/quiver.c b/lib/grm/test/public_api/grm/quiver.c similarity index 100% rename from lib/grm/test/public_api/quiver.c rename to lib/grm/test/public_api/grm/quiver.c diff --git a/lib/grm/test/public_api/raw.c b/lib/grm/test/public_api/grm/raw.c similarity index 100% rename from lib/grm/test/public_api/raw.c rename to lib/grm/test/public_api/grm/raw.c diff --git a/lib/grm/test/public_api/raw_gen_graphics_export.py b/lib/grm/test/public_api/grm/raw_gen_graphics_export.py similarity index 100% rename from lib/grm/test/public_api/raw_gen_graphics_export.py rename to lib/grm/test/public_api/grm/raw_gen_graphics_export.py diff --git a/lib/grm/test/public_api/receiver.c b/lib/grm/test/public_api/grm/receiver.c similarity index 100% rename from lib/grm/test/public_api/receiver.c rename to lib/grm/test/public_api/grm/receiver.c diff --git a/lib/grm/test/public_api/scatter_errorbar.c b/lib/grm/test/public_api/grm/scatter_errorbar.c similarity index 100% rename from lib/grm/test/public_api/scatter_errorbar.c rename to lib/grm/test/public_api/grm/scatter_errorbar.c diff --git a/lib/grm/test/public_api/sender.c b/lib/grm/test/public_api/grm/sender.c similarity index 100% rename from lib/grm/test/public_api/sender.c rename to lib/grm/test/public_api/grm/sender.c diff --git a/lib/grm/test/public_api/size.c b/lib/grm/test/public_api/grm/size.c similarity index 100% rename from lib/grm/test/public_api/size.c rename to lib/grm/test/public_api/grm/size.c diff --git a/lib/grm/test/public_api/subplots.c b/lib/grm/test/public_api/grm/subplots.c similarity index 100% rename from lib/grm/test/public_api/subplots.c rename to lib/grm/test/public_api/grm/subplots.c diff --git a/lib/grm/test/public_api/test_server.py b/lib/grm/test/public_api/grm/test_server.py similarity index 100% rename from lib/grm/test/public_api/test_server.py rename to lib/grm/test/public_api/grm/test_server.py diff --git a/lib/grm/test/public_api/volume.c b/lib/grm/test/public_api/grm/volume.c similarity index 100% rename from lib/grm/test/public_api/volume.c rename to lib/grm/test/public_api/grm/volume.c From f4c26a2dd10e7d1502d61e18adf158a8904c220a Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 14 Oct 2022 10:21:44 +0200 Subject: [PATCH 04/26] [GRM] Change `GR_DEBUG` in GRM to `GRM_DEBUG` for consistency Since commit 532832f035837a6a3379090edd7238b2fbf58bd0 GKS and GR debugging can be enabled with the environment variables `GKS_DEBUG` and `GR_DEBUG`. GR3 uses `GR3_DEBUG`. Therefore, use `GRM_DEBUG` in GRM instead of `GR_DEBUG` to be consistent with the other libraries. --- lib/grm/logging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index aeae627bb..f0dc7b530 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -31,7 +31,7 @@ static void logger_init(void); /* ========================= macros ================================================================================= */ -#define ENABLE_LOGGING_ENV_KEY "GR_DEBUG" +#define ENABLE_LOGGING_ENV_KEY "GRM_DEBUG" /* ========================= static variables ======================================================================= */ From eaf3c8c95767d973a5a7dd1593e7bd6c7c810209 Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 14 Oct 2022 10:39:21 +0200 Subject: [PATCH 05/26] [GRM] Always compile in logging messages With this commit, debug messages in GRM can always be enabled with the `GRM_DEBUG` environment variable regardless of the (CMake) compile mode (Debug or Release). --- lib/grm/logging.c | 12 ------------ lib/grm/logging_int.h | 6 ------ 2 files changed, 18 deletions(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index aeae627bb..c4b872bcc 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -22,9 +22,7 @@ /* ========================= functions ============================================================================== */ -#ifndef NDEBUG static void logger_init(void); -#endif /* ######################### internal implementation ################################################################ */ @@ -36,16 +34,13 @@ static void logger_init(void); /* ========================= static variables ======================================================================= */ -#ifndef NDEBUG static int logging_enabled = -1; -#endif /* ========================= functions ============================================================================== */ /* ------------------------- logging -------------------------------------------------------------------------------- */ -#ifndef NDEBUG void logger_init(void) { if (logging_enabled < 0) @@ -55,7 +50,6 @@ void logger_init(void) str_equals_any(getenv(ENABLE_LOGGING_ENV_KEY), 7, "1", "on", "ON", "true", "TRUE", "yes", "YES")); } } -#endif /* ######################### public implementation ################################################################## */ @@ -66,15 +60,10 @@ void logger_init(void) int logger_enabled(void) { -#ifndef NDEBUG logger_init(); return logging_enabled; -#else - return 0; -#endif } -#ifndef NDEBUG void logger1_(FILE *stream, const char *filename, int line_number, const char *current_function) { logger_init(); @@ -110,4 +99,3 @@ void logger2_(FILE *stream, const char *format, ...) va_end(vl); } } -#endif diff --git a/lib/grm/logging_int.h b/lib/grm/logging_int.h index 52b15dc96..24cd89c73 100644 --- a/lib/grm/logging_int.h +++ b/lib/grm/logging_int.h @@ -12,7 +12,6 @@ /* ------------------------- logging -------------------------------------------------------------------------------- */ -#ifndef NDEBUG #define logger(logger_arguments) \ do \ { \ @@ -20,9 +19,6 @@ logger2_ logger_arguments; \ } \ while (0) -#else -#define logger(logger_arguments) -#endif /* ========================= functions ============================================================================== */ @@ -30,10 +26,8 @@ /* ------------------------- logging -------------------------------------------------------------------------------- */ int logger_enabled(void); -#ifndef NDEBUG void logger1_(FILE *stream, const char *filename, int line_number, const char *current_function); void logger2_(FILE *stream, const char *format, ...); -#endif #endif /* ifndef GRM_LOGGING_INT_H_INCLUDED */ From 1df7c81246dde6faca2e871f35362973675f97ba Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 14 Oct 2022 10:52:09 +0200 Subject: [PATCH 06/26] [GRM] Prefix logging messages with `[DEBUG:GRM]` --- lib/grm/logging.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index c4b872bcc..93956834e 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -71,16 +71,17 @@ void logger1_(FILE *stream, const char *filename, int line_number, const char *c if (logging_enabled) { #if defined(_WIN32) || defined(__EMSCRIPTEN__) - fprintf(stream, "%s:%d(%s): ", filename, line_number, current_function); + fprintf(stream, "[DEBUG:GRM] %s:%d(%s): ", filename, line_number, current_function); #else if (isatty(fileno(stream))) { - fprintf(stream, "\033[36m%s\033[0m:\033[33m%d\033[0m(\033[34m%s\033[0m): ", filename, line_number, - current_function); + fprintf(stream, + "\033[32;1m[DEBUG:GRM]\033[0m \033[36m%s\033[0m:\033[33m%d\033[0m(\033[34m%s\033[0m): ", filename, + line_number, current_function); } else { - fprintf(stream, "%s:%d(%s): ", filename, line_number, current_function); + fprintf(stream, "[DEBUG:GRM] %s:%d(%s): ", filename, line_number, current_function); } #endif } From e6f2a044fe5b435a241a62fdc88d2727449880bc Mon Sep 17 00:00:00 2001 From: Thomas Verbovsek Date: Fri, 21 Oct 2022 11:14:19 +0000 Subject: [PATCH 07/26] Added marginalheatmap and tooltip support for heatmaps. --- lib/grm/src/grm/interaction.c | 79 +++- lib/grm/src/grm/plot.c | 490 +++++++++++++++++---- lib/grm/src/grm/plot_int.h | 2 + lib/grm/test/public_api/grm/CMakeLists.txt | 1 + lib/grm/test/public_api/marginalheatmap.c | 79 ++++ 5 files changed, 564 insertions(+), 87 deletions(-) create mode 100644 lib/grm/test/public_api/marginalheatmap.c diff --git a/lib/grm/src/grm/interaction.c b/lib/grm/src/grm/interaction.c index cf8c30cd2..f83c23c26 100644 --- a/lib/grm/src/grm/interaction.c +++ b/lib/grm/src/grm/interaction.c @@ -97,11 +97,41 @@ int grm_input(const grm_args_t *input_args) const char *kind; args_values(subplot_args, "viewport", "D", &viewport); + args_values(subplot_args, "kind", "s", &kind); + if (strcmp(kind, "marginalheatmap") == 0) + { + grm_args_t **current_series; + double *x_series, *y_series; + unsigned int x_length, y_length; + double x_0, x_end, y_0, y_end, x_step, y_step; + + args_values(input_args, "x", "i", &x); + args_values(input_args, "y", "i", &y); + args_values(subplot_args, "series", "A", ¤t_series); + args_first_value(*current_series, "x", "D", &x_series, &x_length); + args_first_value(*current_series, "y", "D", &y_series, &y_length); + + x_0 = x_series[0], x_end = x_series[x_length - 1]; + y_0 = y_series[0], y_end = y_series[y_length - 1]; + + gr_wctondc(&x_0, &y_0); + gr_wctondc(&x_end, &y_end); + x_0 = x_0 * max_width_height; + x_end = x_end * max_width_height; + y_0 = height - y_0 * max_width_height; + y_end = height - y_end * max_width_height; + + x_step = (x_end - x_0) / x_length; + y_step = (y_end - y_0) / y_length; + + grm_args_push(subplot_args, "xind", "i", (int)((x - x_0) / x_step)); + grm_args_push(subplot_args, "yind", "i", (int)((y - y_0) / y_step)); + } + if (args_values(input_args, "angle_delta", "d", &angle_delta)) { double focus_x, focus_y; - args_values(subplot_args, "kind", "s", &kind); if (str_equals_any(kind, 7, "wireframe", "surface", "plot3", "scatter3", "trisurf", "volume", "isosurface")) { @@ -127,7 +157,6 @@ int grm_input(const grm_args_t *input_args) { double focus_x, focus_y; - args_values(subplot_args, "kind", "s", &kind); if (str_equals_any(kind, 7, "wireframe", "surface", "plot3", "scatter3", "trisurf", "volume", "isosurface")) { @@ -154,8 +183,6 @@ int grm_input(const grm_args_t *input_args) int shift_pressed; const char *kind; - args_values(subplot_args, "kind", "s", &kind); - if (str_equals_any(kind, 7, "wireframe", "surface", "plot3", "scatter3", "trisurf", "volume", "isosurface")) { @@ -280,13 +307,13 @@ int grm_get_box(const int x1, const int y1, const int x2, const int y2, const in grm_tooltip_info_t *grm_get_tooltip(const int mouse_x, const int mouse_y) { grm_tooltip_info_t *info = malloc(sizeof(grm_tooltip_info_t)); - double *x_series, *y_series, x, y, x_min, x_max, y_min, y_max, mindiff = DBL_MAX, diff; + double *x_series, *y_series, *z_series, x, y, x_min, x_max, y_min, y_max, mindiff = DBL_MAX, diff; double x_range_min, x_range_max, y_range_min, y_range_max, x_px, y_px; int width, height, max_width_height; unsigned int num_labels = 0; char *kind, **labels; grm_args_t *subplot_args, **current_series; - unsigned int x_length, y_length, series_i = 0, i; + unsigned int x_length, y_length, z_length, series_i = 0, i; get_figure_size(NULL, &width, &height, NULL, NULL); max_width_height = max(width, height); @@ -298,7 +325,7 @@ grm_tooltip_info_t *grm_get_tooltip(const int mouse_x, const int mouse_y) { args_values(subplot_args, "kind", "s", &kind); } - if (subplot_args == NULL || !str_equals_any(kind, 4, "line", "scatter", "stem", "step")) + if (subplot_args == NULL || !str_equals_any(kind, 6, "line", "scatter", "stem", "step", "heatmap", "marginalheatmap")) { info->x_px = -1; info->y_px = -1; @@ -342,10 +369,15 @@ grm_tooltip_info_t *grm_get_tooltip(const int mouse_x, const int mouse_y) { args_first_value(*current_series, "x", "D", &x_series, &x_length); args_first_value(*current_series, "y", "D", &y_series, &y_length); + if (str_equals_any(kind, 2, "heatmap", "marginalheatmap")) + { + args_first_value(*current_series, "z", "D", &z_series, &z_length); + } for (i = 0; i < x_length; i++) { - if (x_series[i] < x_range_min || x_series[i] > x_range_max || y_series[i] < y_range_min || - y_series[i] > y_range_max) + if ((x_series[i] < x_range_min || x_series[i] > x_range_max || y_series[i] < y_range_min || + y_series[i] > y_range_max) && + !str_equals_any(kind, 2, "heatmap", "marginalheatmap")) { continue; } @@ -371,6 +403,35 @@ grm_tooltip_info_t *grm_get_tooltip(const int mouse_x, const int mouse_y) info->label = ""; } } + else if (str_equals_any(kind, 2, "heatmap", "marginalheatmap")) + { + static char output[50]; + double num; + double x_0 = x_series[0], x_end = x_series[x_length - 1], y_0 = y_series[0], + y_end = y_series[y_length - 1]; + double x_step, y_step; + + gr_wctondc(&x_0, &y_0); + gr_wctondc(&x_end, &y_end); + x_0 = x_0 * max_width_height; + x_end = x_end * max_width_height; + y_0 = height - y_0 * max_width_height; + y_end = height - y_end * max_width_height; + + x_step = (x_end - x_0) / x_length; + y_step = (y_end - y_0) / y_length; + + mindiff = 0; + info->x = x_series[(int)((mouse_x - x_0) / x_step)]; + info->y = y_series[(int)((mouse_y - y_0) / y_step)]; + info->x_px = mouse_x; + info->y_px = mouse_y; + + num = z_series[((y_length - 1) - (int)((mouse_y - y_0) / y_step)) * x_length + + (int)((mouse_x - x_0) / x_step)]; + snprintf(output, 50, "%f", num); + info->label = output; + } } ++series_i; ++current_series; diff --git a/lib/grm/src/grm/plot.c b/lib/grm/src/grm/plot.c index cde6d8ebc..f457922f3 100644 --- a/lib/grm/src/grm/plot.c +++ b/lib/grm/src/grm/plot.c @@ -159,7 +159,7 @@ static string_map_entry_t kind_to_fmt[] = {{"line", "xys"}, {"hexbin", {"barplot", "y"}, {"isosurface", "c"}, {"imshow", "c"}, {"nonuniformheatmap", "xyzc"}, {"polar_histogram", "x"}, {"pie", "x"}, - {"volume", "c"}}; + {"volume", "c"}, {"marginalheatmap", "xyzc"}}; /* ~~~~~~~~~~~~~~~~~~~~~~~~~ kind to func ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -175,6 +175,7 @@ static plot_func_map_entry_t kind_to_func[] = {{"line", plot_line}, {"contourf", plot_contourf}, {"hexbin", plot_hexbin}, {"heatmap", plot_heatmap}, + {"marginalheatmap", plot_marginalheatmap}, {"wireframe", plot_wireframe}, {"surface", plot_surface}, {"plot3", plot_plot3}, @@ -232,56 +233,24 @@ static int pre_plot_text_encoding = -1; const char *valid_root_keys[] = {"plots", "append_plots", "hold_plots", NULL}; const char *valid_plot_keys[] = {"clear", "figsize", "raw", "size", "subplots", "update", NULL}; -const char *valid_subplot_keys[] = {"adjust_xlim", - "adjust_ylim", - "adjust_zlim", - "alpha", - "angle_ticks", - "backgroundcolor", - "bar_color", - "bar_width", - "colormap", - "font", - "font_precision", - "ind_bar_color", - "ind_edge_color", - "ind_edge_width", - "keep_aspect_ratio", - "kind", - "labels", - "levels", - "location", - "normalization", - "panzoom", - "phiflip", - "resample_method", - "reset_ranges", - "rings", - "rotation", - "series", - "style", - "subplot", - "tilt", - "title", - "xbins", - "xflip", - "xform", - "xgrid", - "xlabel", - "xlim", - "xlog", - "xticklabels", - "ybins", - "yflip", - "ygrid", - "ylabel", - "ylim", - "ylog", - "zflip", - "zgrid", - "zlim", - "zlog", - NULL}; +const char *valid_subplot_keys[] = {"adjust_xlim", "adjust_ylim", "adjust_zlim", + "alpha", "angle_ticks", "backgroundcolor", + "bar_color", "bar_width", "colormap", + "font", "font_precision", "ind_bar_color", + "ind_edge_color", "ind_edge_width", "keep_aspect_ratio", + "kind", "labels", "levels", + "location", "normalization", "orientation", + "panzoom", "phiflip", "resample_method", + "reset_ranges", "rings", "rotation", + "series", "style", "subplot", + "tilt", "title", "type", + "xbins", "xflip", "xform", + "xgrid", "xlabel", "xlim", + "xlog", "xind", "xticklabels", + "ybins", "yflip", "ygrid", + "ylabel", "ylim", "ylog", + "yind", "zflip", "zgrid", + "zlim", "zlog", NULL}; const char *valid_series_keys[] = {"a", "algorithm", "bin_width", "bin_edges", "bin_counts", "c", @@ -343,6 +312,7 @@ static string_map_entry_t key_to_formats[] = {{"a", "A"}, {"location", "i"}, {"markertype", "i"}, {"nbins", "i"}, + {"orientation", "s"}, {"panzoom", "D"}, {"raw", "s"}, {"resample_method", "s|i"}, @@ -355,6 +325,7 @@ static string_map_entry_t key_to_formats[] = {{"a", "A"}, {"subplot", "D"}, {"tilt", "d"}, {"title", "s"}, + {"type", "s"}, {"u", "D"}, {"update", "i"}, {"v", "D"}, @@ -366,6 +337,7 @@ static string_map_entry_t key_to_formats[] = {{"a", "A"}, {"xgrid", "i"}, {"xlabel", "s"}, {"xlim", "D"}, + {"xind", "i"}, {"xrange", "D"}, {"xlog", "i"}, {"y", "D"}, @@ -376,6 +348,7 @@ static string_map_entry_t key_to_formats[] = {{"a", "A"}, {"ygrid", "i"}, {"ylabel", "s"}, {"ylim", "D"}, + {"yind", "i"}, {"yrange", "D"}, {"ylog", "i"}, {"z", "D"}, @@ -896,7 +869,7 @@ void plot_set_attribute_defaults(grm_args_t *plot_args) args_setdefault(*current_subplot, "ygrid", "i", PLOT_DEFAULT_YGRID); args_setdefault(*current_subplot, "zgrid", "i", PLOT_DEFAULT_ZGRID); args_setdefault(*current_subplot, "resample_method", "i", PLOT_DEFAULT_RESAMPLE_METHOD); - if (strcmp(kind, "heatmap") == 0) + if (str_equals_any(kind, 2, "heatmap", "marginalheatmap")) { args_setdefault(*current_subplot, "adjust_xlim", "i", 0); args_setdefault(*current_subplot, "adjust_ylim", "i", 0); @@ -928,6 +901,15 @@ void plot_set_attribute_defaults(grm_args_t *plot_args) { args_setdefault(*current_subplot, "levels", "i", PLOT_DEFAULT_TRICONT_LEVELS); } + else if (str_equals_any(kind, 2, "hist", "line")) + { + args_setdefault(*current_subplot, "orientation", "s", PLOT_DEFAULT_ORIENTATION); + } + else if (str_equals_any(kind, 2, "marginalheatmap", "hist")) + { + args_setdefault(*current_subplot, "xind", "i", -1); + args_setdefault(*current_subplot, "yind", "i", -1); + } args_values(*current_subplot, "series", "A", ¤t_series); while (*current_series != NULL) @@ -945,6 +927,11 @@ void plot_set_attribute_defaults(grm_args_t *plot_args) { args_setdefault(*current_series, "algorithm", "i", PLOT_DEFAULT_VOLUME_ALGORITHM); } + else if (strcmp(kind, "marginalheatmap") == 0) + { + args_setdefault(*current_series, "algorithm", "s", "sum"); + args_setdefault(*current_series, "type", "s", "all"); + } ++current_series; } ++current_subplot; @@ -1195,8 +1182,8 @@ void plot_process_viewport(grm_args_t *subplot_args) } left_margin = args_values(subplot_args, "ylabel", "s", &y_label) ? 0.05 : 0; - if (str_equals_any(kind, 8, "contour", "contourf", "hexbin", "heatmap", "nonuniformheatmap", "surface", "trisurf", - "volume")) + if (str_equals_any(kind, 9, "contour", "contourf", "hexbin", "heatmap", "nonuniformheatmap", "surface", "trisurf", + "volume", "marginalheatmap")) { right_margin = (vp1 - vp0) * 0.1; } @@ -1205,7 +1192,14 @@ void plot_process_viewport(grm_args_t *subplot_args) right_margin = 0; } bottom_margin = args_values(subplot_args, "xlabel", "s", &x_label) ? 0.05 : 0; - top_margin = args_values(subplot_args, "title", "s", &title) ? 0.075 : 0; + if (strcmp(kind, "marginalheatmap") == 0) + { + top_margin = args_values(subplot_args, "title", "s", &title) ? 0.075 + (vp1 - vp0) * 0.1 : (vp1 - vp0) * 0.1; + } + else + { + top_margin = args_values(subplot_args, "title", "s", &title) ? 0.075 : 0; + } viewport[0] = vp0 + (0.075 + left_margin) * (vp1 - vp0); viewport[1] = vp0 + (0.95 - right_margin) * (vp1 - vp0); @@ -1586,7 +1580,8 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) continue; } /* Heatmaps need calculated range keys, so run the calculation even if limits are given */ - if (!grm_args_contains(subplot_args, current_range_keys->subplot) || strcmp(kind, "heatmap") == 0) + if (!grm_args_contains(subplot_args, current_range_keys->subplot) || + str_equals_any(kind, 2, "heatmap", "marginalheatmap")) { args_first_value(subplot_args, "series", "A", ¤t_series, &series_count); while (*current_series != NULL) @@ -1626,7 +1621,8 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) } } } - else if (strcmp(kind, "heatmap") == 0 && str_equals_any(*current_component_name, 2, "x", "y")) + else if (str_equals_any(kind, 2, "heatmap", "marginalheatmap") && + str_equals_any(*current_component_name, 2, "x", "y")) { /* in this case `x` or `y` (or both) are missing * -> set the current min/max_component to the dimensions of `z` @@ -1998,11 +1994,12 @@ error_t plot_line(grm_args_t *subplot_args) { grm_args_t **current_series; error_t error; - char *kind; + char *kind, *orientation; kind = "line"; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); + args_values(subplot_args, "orientation", "s", &orientation); while (*current_series != NULL) { double *x, *y; @@ -2016,11 +2013,25 @@ error_t plot_line(grm_args_t *subplot_args) mask = gr_uselinespec(spec); if (int_equals_any(mask, 5, 0, 1, 3, 4, 5)) { - gr_polyline(x_length, x, y); + if (strcmp(orientation, "horizontal") == 0) + { + gr_polyline(x_length, x, y); + } + else + { + gr_polyline(x_length, y, x); + } } if (mask & 2) { - gr_polymarker(x_length, x, y); + if (strcmp(orientation, "horizontal") == 0) + { + gr_polymarker(x_length, x, y); + } + else + { + gr_polymarker(x_length, y, x); + } } error = plot_draw_errorbars(*current_series, x, x_length, y, kind); return_if_error; @@ -2040,27 +2051,122 @@ error_t plot_step(grm_args_t *subplot_args) * optional `spec` */ grm_args_t **current_series; + char *kind, *orientation; + int xind, yind; + double *x_step_boundaries = NULL, *y_step_values = NULL; + double xmin, xmax, ymin, ymax; + double *y = NULL, *xi = NULL; + int is_vertical; + error_t error = NO_ERROR; args_values(subplot_args, "series", "A", ¤t_series); + args_values(subplot_args, "kind", "s", &kind); + args_values(subplot_args, "orientation", "s", &orientation); + args_values(subplot_args, "xind", "i", &xind); + args_values(subplot_args, "yind", "i", &yind); + is_vertical = strcmp(orientation, "vertical") == 0; while (*current_series != NULL) { - double *x, *y, *x_step_boundaries = NULL, *y_step_values = NULL; + double *x = NULL; unsigned int x_length, y_length, mask, i; char *spec; - return_error_if(!args_first_value(*current_series, "x", "D", &x, &x_length) && x_length < 1, - ERROR_PLOT_MISSING_DATA); - return_error_if(!args_first_value(*current_series, "y", "D", &y, &y_length), ERROR_PLOT_MISSING_DATA); - return_error_if(x_length != y_length, ERROR_PLOT_COMPONENT_LENGTH_MISMATCH); + cleanup_and_set_error_if(!args_first_value(*current_series, "x", "D", &x, &x_length) && x_length < 1, + ERROR_PLOT_MISSING_DATA); + cleanup_and_set_error_if(!args_first_value(*current_series, "y", "D", &y, &y_length), ERROR_PLOT_MISSING_DATA); + if (strcmp(kind, "marginalheatmap") == 0 && xind != -1 && yind != -1) + { + double y_max = 0, *plot, c_min, c_max; + unsigned int n = 0; + + args_values(*current_series, "xrange", "dd", &xmin, &xmax); + args_values(*current_series, "yrange", "dd", &ymin, &ymax); + args_values(subplot_args, "_zlim", "dd", &c_min, &c_max); + args_first_value(*current_series, "z", "D", &plot, &n); + + y = malloc((is_vertical ? y_length : x_length) * sizeof(double)); + cleanup_and_set_error_if(y == NULL, ERROR_MALLOC); + xi = malloc((is_vertical ? y_length : x_length) * sizeof(double)); + cleanup_and_set_error_if(xi == NULL, ERROR_MALLOC); + for (i = 0; i < (is_vertical ? y_length : x_length); i++) + { + if (is_vertical) + { + y[(is_vertical ? y_length : x_length) - i - 1] = + isnan(plot[xind + i * x_length]) ? 0 : plot[xind + i * x_length]; + y_max = max(y_max, y[(is_vertical ? y_length : x_length) - i - 1]); + } + else + { + y[i] = isnan(plot[x_length * (y_length - 1 - yind) + i]) ? 0 + : plot[x_length * (y_length - 1 - yind) + i]; + y_max = max(y_max, y[i]); + } + } + for (i = 0; i < (is_vertical ? y_length : x_length); i++) + { + y[i] = y[i] / y_max * (c_max / 15); + xi[i] = x[i] + (is_vertical ? ymin : xmin); + } + } + else + { + return_error_if(x_length != y_length, ERROR_PLOT_COMPONENT_LENGTH_MISMATCH); + } args_values(*current_series, "spec", "s", &spec); /* `spec` is always set */ mask = gr_uselinespec(spec); if (int_equals_any(mask, 5, 0, 1, 3, 4, 5)) { const char *where; args_values(*current_series, "step_where", "s", &where); /* `spec` is always set */ - if (strcmp(where, "pre") == 0) + if (strcmp(kind, "marginalheatmap") == 0) + { + double x_pos, y_pos; + unsigned int len = is_vertical ? y_length : x_length; + + x_step_boundaries = calloc(2 * len, sizeof(double)); + cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); + y_step_values = calloc(2 * len, sizeof(double)); + cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); + x_step_boundaries[0] = is_vertical ? ymin : xmin; + for (i = 2; i < 2 * len; i += 2) + { + x_step_boundaries[i - 1] = x_step_boundaries[i] = + x_step_boundaries[0] + (i / 2) * (is_vertical ? (ymax - ymin) : (xmax - xmin)) / len; + } + x_step_boundaries[2 * len - 1] = is_vertical ? ymax : xmax; + y_step_values[0] = y[0]; + for (i = 2; i < 2 * len; i += 2) + { + y_step_values[i - 1] = y[i / 2 - 1]; + y_step_values[i] = y[i / 2]; + } + y_step_values[2 * len - 1] = y[len - 1]; + + gr_setlinecolorind(989); + gr_setmarkercolorind(2); + gr_setmarkertype(-1); + gr_setmarkersize(1.5 * (len / (is_vertical ? (ymax - ymin) : (xmax - xmin)))); + if (is_vertical) + { + gr_polyline(2 * len, y_step_values, x_step_boundaries); + x_pos = (x_step_boundaries[yind * 2] + x_step_boundaries[yind * 2 + 1]) / 2; + y_pos = y[yind]; + gr_polymarker(1, &y_pos, &x_pos); + } + else + { + gr_polyline(2 * len, x_step_boundaries, y_step_values); + x_pos = (x_step_boundaries[xind * 2] + x_step_boundaries[xind * 2 + 1]) / 2; + y_pos = y[xind]; + gr_polymarker(1, &x_pos, &y_pos); + } + } + else if (strcmp(where, "pre") == 0) { x_step_boundaries = calloc(2 * x_length - 1, sizeof(double)); + cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); y_step_values = calloc(2 * x_length - 1, sizeof(double)); + cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); x_step_boundaries[0] = x[0]; for (i = 1; i < 2 * x_length - 2; i += 2) { @@ -2072,12 +2178,21 @@ error_t plot_step(grm_args_t *subplot_args) { y_step_values[i] = y_step_values[i + 1] = y[i / 2 + 1]; } - gr_polyline(2 * x_length - 1, x_step_boundaries, y_step_values); + if (is_vertical) + { + gr_polyline(2 * x_length - 1, y_step_values, x_step_boundaries); + } + else + { + gr_polyline(2 * x_length - 1, x_step_boundaries, y_step_values); + } } else if (strcmp(where, "post") == 0) { x_step_boundaries = calloc(2 * x_length - 1, sizeof(double)); + cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); y_step_values = calloc(2 * x_length - 1, sizeof(double)); + cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); for (i = 0; i < 2 * x_length - 2; i += 2) { x_step_boundaries[i] = x[i / 2]; @@ -2089,12 +2204,21 @@ error_t plot_step(grm_args_t *subplot_args) y_step_values[i] = y_step_values[i + 1] = y[i / 2]; } y_step_values[2 * x_length - 2] = y[x_length - 1]; - gr_polyline(2 * x_length - 1, x_step_boundaries, y_step_values); + if (is_vertical) + { + gr_polyline(2 * x_length - 1, y_step_values, x_step_boundaries); + } + else + { + gr_polyline(2 * x_length - 1, x_step_boundaries, y_step_values); + } } else if (strcmp(where, "mid") == 0) { x_step_boundaries = calloc(2 * x_length, sizeof(double)); + cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); y_step_values = calloc(2 * x_length, sizeof(double)); + cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); x_step_boundaries[0] = x[0]; for (i = 1; i < 2 * x_length - 2; i += 2) { @@ -2105,19 +2229,49 @@ error_t plot_step(grm_args_t *subplot_args) { y_step_values[i] = y_step_values[i + 1] = y[i / 2]; } - gr_polyline(2 * x_length, x_step_boundaries, y_step_values); + if (is_vertical) + { + gr_polyline(2 * x_length, y_step_values, x_step_boundaries); + } + else + { + gr_polyline(2 * x_length, x_step_boundaries, y_step_values); + } } free(x_step_boundaries); free(y_step_values); + x_step_boundaries = y_step_values = NULL; } if (mask & 2) { - gr_polymarker(x_length, x, y); + if (is_vertical) + { + gr_polymarker(y_length, y, x); + } + else + { + gr_polymarker(x_length, x, y); + } } ++current_series; + if (strcmp(kind, "marginalheatmap") == 0 && xind != -1 && yind != -1) + { + free(y); + free(xi); + y = xi = NULL; + } } - return NO_ERROR; +cleanup: + if (strcmp(kind, "marginalheatmap") == 0 && xind != -1 && yind != -1) + { + free(y); + free(xi); + } + free(x_step_boundaries); + free(y_step_values); + + return error; } error_t plot_scatter(grm_args_t *subplot_args) @@ -2291,7 +2445,7 @@ error_t plot_hist(grm_args_t *subplot_args) char *kind; grm_args_t **current_series; double *bar_centers = NULL; - int bar_color_index = 989, i; + int bar_color_index = 989, i, xind, yind; double bar_color_rgb[3] = {-1}; error_t error = NO_ERROR; @@ -2299,6 +2453,8 @@ error_t plot_hist(grm_args_t *subplot_args) args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "bar_color", "ddd", &bar_color_rgb[0], &bar_color_rgb[1], &bar_color_rgb[2]); args_values(subplot_args, "bar_color", "i", &bar_color_index); + args_values(subplot_args, "xind", "i", &xind); + args_values(subplot_args, "yind", "i", &yind); if (bar_color_rgb[0] != -1) { for (i = 0; i < 3; i++) @@ -2311,11 +2467,13 @@ error_t plot_hist(grm_args_t *subplot_args) while (*current_series != NULL) { - double edge_color_index = 1; + int edge_color_index = 1; double edge_color_rgb[3] = {-1}; double x_min, x_max, bar_width; double *bins; unsigned int num_bins; + char *orientation; + int is_horizontal; args_values(*current_series, "edge_color", "ddd", &edge_color_rgb[0], &edge_color_rgb[1], &edge_color_rgb[2]); args_values(*current_series, "edge_color", "i", &edge_color_index); @@ -2330,7 +2488,16 @@ error_t plot_hist(grm_args_t *subplot_args) } args_first_value(*current_series, "bins", "D", &bins, &num_bins); - args_values(*current_series, "xrange", "dd", &x_min, &x_max); + args_values(subplot_args, "orientation", "s", &orientation); + is_horizontal = strcmp(orientation, "horizontal") == 0; + if (is_horizontal) + { + args_values(*current_series, "xrange", "dd", &x_min, &x_max); + } + else + { + args_values(*current_series, "yrange", "dd", &x_min, &x_max); + } bar_width = (x_max - x_min) / num_bins; for (i = 1; i < num_bins + 1; ++i) @@ -2338,10 +2505,32 @@ error_t plot_hist(grm_args_t *subplot_args) double x = x_min + (i - 1) * bar_width; gr_setfillcolorind(bar_color_index); gr_setfillintstyle(GKS_K_INTSTYLE_SOLID); - gr_fillrect(x, x + bar_width, 0., bins[i - 1]); + if (is_horizontal) + { + if (i == xind + 1) + { + gr_setfillcolorind(2); + } + gr_fillrect(x, x + bar_width, 0., bins[i - 1]); + } + else + { + if (i == yind + 1) + { + gr_setfillcolorind(2); + } + gr_fillrect(0., bins[i - 1], x, x + bar_width); + } gr_setfillcolorind(edge_color_index); gr_setfillintstyle(GKS_K_INTSTYLE_HOLLOW); - gr_fillrect(x, x + bar_width, 0., bins[i - 1]); + if (is_horizontal) + { + gr_fillrect(x, x + bar_width, 0., bins[i - 1]); + } + else + { + gr_fillrect(0., bins[i - 1], x, x + bar_width); + } } if (grm_args_contains(*current_series, "error")) { @@ -3459,7 +3648,10 @@ error_t plot_heatmap(grm_args_t *subplot_args) ++current_series; } - plot_draw_colorbar(subplot_args, 0.0, 256); + if (strcmp(kind, "marginalheatmap") != 0) + { + plot_draw_colorbar(subplot_args, 0.0, 256); + } cleanup: free(rgba); @@ -3468,6 +3660,148 @@ error_t plot_heatmap(grm_args_t *subplot_args) return error; } +error_t plot_marginalheatmap(grm_args_t *subplot_args) +{ + const double *viewport; + double c_min, c_max; + int flip, options, xind, yind; + unsigned int i, j, k; + grm_args_t **current_series; + char *algorithm, *type; + double *bins = NULL; + unsigned int num_bins_x = 0, num_bins_y = 0, n = 0; + double *xi, *yi, *plot; + error_t error = NO_ERROR; + + plot_heatmap(subplot_args); + + args_values(subplot_args, "type", "s", &type); + args_values(subplot_args, "xind", "i", &xind); + args_values(subplot_args, "yind", "i", &yind); + + for (k = 0; k < 2; k++) + { + double x_min, x_max, y_min, y_max, value, bin_max = 0; + + gr_savestate(); + + args_values(subplot_args, "series", "A", ¤t_series); + args_values(*current_series, "algorithm", "s", &algorithm); + args_values(*current_series, "xrange", "dd", &x_min, &x_max); + args_values(*current_series, "yrange", "dd", &y_min, &y_max); + if (!args_values(subplot_args, "_clim", "dd", &c_min, &c_max)) + { + cleanup_and_set_error_if(!args_values(subplot_args, "_zlim", "dd", &c_min, &c_max), ERROR_PLOT_MISSING_DATA); + } + + args_first_value(*current_series, "x", "D", &xi, &num_bins_x); + args_first_value(*current_series, "y", "D", &yi, &num_bins_y); + args_first_value(*current_series, "z", "D", &plot, &n); + + if (strcmp(type, "all") == 0) + { + unsigned int x_len = num_bins_x, y_len = num_bins_y; + + bins = malloc(((k == 0) ? num_bins_y : num_bins_x) * sizeof(double)); + cleanup_and_set_error_if(bins == NULL, ERROR_MALLOC); + grm_args_push(subplot_args, "kind", "s", "hist"); + + for (i = 0; i < ((k == 0) ? num_bins_y : num_bins_x); i++) + { + bins[i] = 0; + } + for (i = 0; i < y_len; i++) + { + for (j = 0; j < x_len; j++) + { + value = (isnan(plot[(num_bins_y - 1 - i) * num_bins_x + j])) + ? 0 + : plot[(num_bins_y - 1 - i) * num_bins_x + j]; + if (strcmp(algorithm, "sum") == 0) + { + bins[(k == 0) ? i : j] += value; + } + else if (strcmp(algorithm, "max") == 0) + { + bins[(k == 0) ? i : j] = max(bins[(k == 0) ? i : j], value); + } + } + if (k == 0) + { + bin_max = max(bin_max, bins[i]); + } + } + if (k == 1) + { + for (i = 0; i < x_len; i++) + { + bin_max = max(bin_max, bins[i]); + } + } + for (i = 0; i < ((k == 0) ? y_len : x_len); i++) + { + bins[i] = (bin_max == 0) ? 0 : bins[i] / bin_max * (c_max / 15); + } + + grm_args_push(*current_series, "bins", "nD", ((k == 0) ? num_bins_y : num_bins_x), bins); + + free(bins); + bins = NULL; + } + + args_values(subplot_args, "viewport", "D", &viewport); + + gr_inqscale(&options); + if (args_values(subplot_args, "xflip", "i", &flip) && flip) + { + options = (options | GR_OPTION_FLIP_Y) & ~GR_OPTION_FLIP_X; + gr_setscale(options); + } + else if (args_values(subplot_args, "yflip", "i", &flip) && flip) + { + options = options & ~GR_OPTION_FLIP_Y & ~GR_OPTION_FLIP_X; + gr_setscale(options); + } + else + { + options = options & ~GR_OPTION_FLIP_X; + gr_setscale(options); + } + + if (k == 0) + { + gr_setwindow(0.0, c_max / 10, y_min, y_max); + gr_setviewport(viewport[1] + 0.02 + 0.0, viewport[1] + 0.12 + 0.0, viewport[2], viewport[3]); + + grm_args_push(subplot_args, "orientation", "s", "vertical"); + } + else + { + gr_setwindow(x_min, x_max, 0.0, c_max / 10); + gr_setviewport(viewport[0], viewport[1], viewport[3] + 0.02, min(viewport[3] + 0.12, 1)); + + grm_args_push(subplot_args, "orientation", "s", "horizontal"); + } + + if (strcmp(type, "all") == 0) + { + plot_hist(subplot_args); + } + else if (strcmp(type, "line") == 0 && xind != -1 && yind != -1) + { + plot_step(subplot_args); + } + + gr_restorestate(); + } + grm_args_push(subplot_args, "kind", "s", "marginalheatmap"); + +cleanup: + free(bins); + + return error; +} + error_t plot_wireframe(grm_args_t *subplot_args) { double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; @@ -5364,7 +5698,7 @@ error_t plot_draw_axes(grm_args_t *args, unsigned int pass) { charheight = max(0.018 * diag, 0.012); gr_setcharheight(charheight); - if (str_equals_any(kind, 2, "heatmap", "shade")) + if (str_equals_any(kind, 3, "heatmap", "shade", "marginalheatmap")) { ticksize = -ticksize; } diff --git a/lib/grm/src/grm/plot_int.h b/lib/grm/src/grm/plot_int.h index ddba6b407..49c32a294 100644 --- a/lib/grm/src/grm/plot_int.h +++ b/lib/grm/src/grm/plot_int.h @@ -76,6 +76,7 @@ extern const char *plot_clear_exclude_keys[]; #define PLOT_DEFAULT_HEXBIN_NBINS 40 #define PLOT_DEFAULT_TRICONT_LEVELS 20 #define PLOT_DEFAULT_VOLUME_ALGORITHM GR_VOLUME_EMISSION +#define PLOT_DEFAULT_ORIENTATION "horizontal" #define SERIES_DEFAULT_SPEC "" #define PLOT_POLAR_AXES_TEXT_BUFFER 40 #define PLOT_CONTOUR_GRIDIT_N 200 @@ -178,6 +179,7 @@ error_t plot_contour(grm_args_t *subplot_args); error_t plot_contourf(grm_args_t *subplot_args); error_t plot_hexbin(grm_args_t *subplot_args); error_t plot_heatmap(grm_args_t *subplot_args); +error_t plot_marginalheatmap(grm_args_t *subplot_args); error_t plot_wireframe(grm_args_t *subplot_args); error_t plot_surface(grm_args_t *subplot_args); error_t plot_plot3(grm_args_t *subplot_args); diff --git a/lib/grm/test/public_api/grm/CMakeLists.txt b/lib/grm/test/public_api/grm/CMakeLists.txt index dc50b4c6b..a8ca72ec2 100644 --- a/lib/grm/test/public_api/grm/CMakeLists.txt +++ b/lib/grm/test/public_api/grm/CMakeLists.txt @@ -31,6 +31,7 @@ set(EXECUTABLE_SOURCES size.c subplots.c volume.c + marginalheatmap.c ) foreach(executable_source ${EXECUTABLE_SOURCES}) diff --git a/lib/grm/test/public_api/marginalheatmap.c b/lib/grm/test/public_api/marginalheatmap.c new file mode 100644 index 000000000..8e5b84c4a --- /dev/null +++ b/lib/grm/test/public_api/marginalheatmap.c @@ -0,0 +1,79 @@ +#ifdef __unix__ +#define _XOPEN_SOURCE 500 +#endif +#include +#include "grm.h" + +#define ROWS 4 +#define COLS 4 +#define XMIN 0 +#define XMAX 4 +#define YMIN 0 +#define YMAX 4 + +static void test_marginalheatmap() +{ + unsigned int row, col; + grm_args_t *args; + double xi[ROWS], yi[COLS], zi[ROWS * COLS]; + double df[COLS][ROWS]; + + df[0][0] = 1, df[1][0] = 2, df[2][0] = 3, df[3][0] = 4; + df[0][1] = 2, df[1][1] = 8, df[2][1] = 4, df[3][1] = 5; + df[0][2] = 3, df[1][2] = 4, df[2][2] = 5, df[3][2] = 6; + df[0][3] = 4, df[1][3] = 5, df[2][3] = 6, df[3][3] = 7; + + for (row = 0; row < ROWS; ++row) + { + xi[row] = XMIN + (XMAX - XMIN) * ((double)row / ((double)ROWS - 1)); + for (col = 0; col < COLS; ++col) + { + if (row == 0) + { + yi[col] = YMIN + (YMAX - YMIN) * ((double)col / ((double)COLS - 1)); + } + zi[((COLS - 1) - col) * ROWS + row] = df[col][row]; + } + } + + printf("plot a marginalheatmap with x, y and z\n"); + args = grm_args_new(); + grm_args_push(args, "x", "nD", ROWS, xi); + grm_args_push(args, "y", "nD", COLS, yi); + grm_args_push(args, "z", "nD", ROWS * COLS, zi); + grm_args_push(args, "kind", "s", "marginalheatmap"); + grm_args_push(args, "type", "s", "all"); + grm_args_push(args, "algorithm", "s", "sum"); + grm_plot(args); + + printf("Press any key to continue...\n"); + getchar(); + + grm_args_delete(args); + + printf("plot a special type of marginalheatmap where only one line and column is shown\n"); + args = grm_args_new(); + grm_args_push(args, "x", "nD", ROWS, xi); + grm_args_push(args, "y", "nD", COLS, yi); + grm_args_push(args, "z", "nD", ROWS * COLS, zi); + grm_args_push(args, "kind", "s", "marginalheatmap"); + grm_args_push(args, "type", "s", "line"); + grm_args_push(args, "algorithm", "s", "sum"); + grm_args_push(args, "xind", "i", 1); + grm_args_push(args, "yind", "i", 1); + grm_plot(args); + + printf("Press any key to continue...\n"); + getchar(); + + grm_args_delete(args); +} + + +int main() +{ + test_marginalheatmap(); + grm_finalize(); + + return 0; +} From 9d490eabf3ab4f89dace305ed102b98fc596b16d Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Wed, 23 Feb 2022 17:55:56 +0100 Subject: [PATCH 08/26] [GRM] Allow C++ modules in GRM This commit allows the usage of C++ in GRM and converts `plot.c` to `plot.cxx` (which is still C code but is C++ compatible). --- 3rdparty/bzip2/Makefile | 2 +- 3rdparty/cairo/Makefile | 2 +- 3rdparty/ffmpeg/Makefile | 2 +- 3rdparty/freetype/Makefile | 2 +- 3rdparty/glfw/Makefile | 2 +- 3rdparty/jpeg/Makefile | 2 +- 3rdparty/libpng16/Makefile | 2 +- 3rdparty/ogg/Makefile | 2 +- 3rdparty/openh264/Makefile | 2 +- 3rdparty/pixman/Makefile | 2 +- 3rdparty/qhull/Makefile | 2 +- 3rdparty/theora/Makefile | 2 +- 3rdparty/tiff/Makefile | 2 +- 3rdparty/vpx/Makefile | 2 +- 3rdparty/zeromq/Makefile | 4 +- 3rdparty/zlib/Makefile | 2 +- CMakeLists.txt | 5 +- js/Makefile | 12 +- lib/gks/Makefile | 4 +- lib/gks/plugin/Makefile | 8 +- lib/gr/Makefile | 4 +- lib/gr/qtgr/Makefile | 2 +- lib/gr3/Makefile | 4 +- lib/grm/Makefile | 15 +- lib/grm/include/grm/interaction.h | 1 - lib/grm/makefile.mingw | 10 +- lib/grm/src/grm/args.c | 38 +- lib/grm/src/grm/args_int.h | 35 +- lib/grm/src/grm/base64.c | 20 +- lib/grm/src/grm/base64_int.h | 15 +- lib/grm/src/grm/datatype/string_list.c | 4 +- lib/grm/src/grm/datatype/string_map.c | 6 +- lib/grm/src/grm/datatype/string_map_int.h | 3 +- lib/grm/src/grm/datatype/template/list_int.h | 56 +- lib/grm/src/grm/datatype/template/set_int.h | 6 +- lib/grm/src/grm/dump.c | 100 ++-- lib/grm/src/grm/dump_int.h | 7 + lib/grm/src/grm/dynamic_args_array.c | 2 +- lib/grm/src/grm/dynamic_args_array_int.h | 9 +- lib/grm/src/grm/error_int.h | 9 +- lib/grm/src/grm/event.c | 20 +- lib/grm/src/grm/event_int.h | 15 +- lib/grm/src/grm/interaction.c | 20 +- lib/grm/src/grm/interaction_int.h | 7 + lib/grm/src/grm/json.c | 120 ++--- lib/grm/src/grm/json_int.h | 69 +-- lib/grm/src/grm/logging_int.h | 7 + lib/grm/src/grm/memwriter.c | 20 +- lib/grm/src/grm/memwriter_int.h | 23 +- lib/grm/src/grm/net.c | 60 +-- lib/grm/src/grm/net_int.h | 41 +- lib/grm/src/grm/{plot.c => plot.cxx} | 499 +++++++++--------- lib/grm/src/grm/plot_int.h | 97 ++-- lib/grm/src/grm/util.c | 4 +- lib/grm/src/grm/util_int.h | 31 +- lib/grm/test/public_api/grm/CMakeLists.txt | 8 +- .../public_api/{ => grm}/marginalheatmap.c | 0 57 files changed, 776 insertions(+), 674 deletions(-) rename lib/grm/src/grm/{plot.c => plot.cxx} (94%) rename lib/grm/test/public_api/{ => grm}/marginalheatmap.c (100%) diff --git a/3rdparty/bzip2/Makefile b/3rdparty/bzip2/Makefile index 2362a0814..972a536aa 100644 --- a/3rdparty/bzip2/Makefile +++ b/3rdparty/bzip2/Makefile @@ -4,7 +4,7 @@ endif CFLAGS = -O -I. -fPIC -fno-common $(ARCHS) ifeq ($(shell uname),Darwin) - CFLAGS += -mmacosx-version-min=10.11 + CFLAGS += -mmacosx-version-min=10.14 endif OBJS = blocksort.o \ huffman.o \ diff --git a/3rdparty/cairo/Makefile b/3rdparty/cairo/Makefile index 7493ea337..9bf6eb0f8 100644 --- a/3rdparty/cairo/Makefile +++ b/3rdparty/cairo/Makefile @@ -5,7 +5,7 @@ endif VERSION = 1.16.0 CAIRO_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) -CAIRO_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.11 +CAIRO_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/ffmpeg/Makefile b/3rdparty/ffmpeg/Makefile index cc938873d..33ec023be 100644 --- a/3rdparty/ffmpeg/Makefile +++ b/3rdparty/ffmpeg/Makefile @@ -5,7 +5,7 @@ endif VERSION = 4.2.1 FFMPEG_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) -FFMPEG_EXTRA_CONFIGURE_FLAGS += --extra-cflags=-mmacosx-version-min=10.11 +FFMPEG_EXTRA_CONFIGURE_FLAGS += --extra-cflags=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/freetype/Makefile b/3rdparty/freetype/Makefile index 8ce4c6c26..597e0cfc8 100644 --- a/3rdparty/freetype/Makefile +++ b/3rdparty/freetype/Makefile @@ -9,7 +9,7 @@ FTINCLUDES = -Isrc -Iinclude FTCFLAGS = -O -fPIC -fno-common $(FTINCLUDES) $(FTDEFINES) $(ARCHS) ifeq ($(shell uname -s),Darwin) - FTCFLAGS += -mmacosx-version-min=10.11 + FTCFLAGS += -mmacosx-version-min=10.14 endif OBJS = \ diff --git a/3rdparty/glfw/Makefile b/3rdparty/glfw/Makefile index 164fab59b..ab11fd995 100644 --- a/3rdparty/glfw/Makefile +++ b/3rdparty/glfw/Makefile @@ -5,7 +5,7 @@ endif VERSION = 3.3.3 GLFW_EXTRA_CMAKE_FLAGS ?= ifeq ($(shell uname),Darwin) - GLFW_EXTRA_CMAKE_FLAGS += -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 + GLFW_EXTRA_CMAKE_FLAGS += -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/jpeg/Makefile b/3rdparty/jpeg/Makefile index 718828349..bd472885d 100644 --- a/3rdparty/jpeg/Makefile +++ b/3rdparty/jpeg/Makefile @@ -5,7 +5,7 @@ endif CFLAGS = -O -I. -fPIC -fno-common $(ARCHS) ifeq ($(shell uname),Darwin) ifneq ($(notdir $(CC)),emcc) - CFLAGS += -mmacosx-version-min=10.11 + CFLAGS += -mmacosx-version-min=10.14 endif endif OBJS = \ diff --git a/3rdparty/libpng16/Makefile b/3rdparty/libpng16/Makefile index 0e3ec1a2b..e189a9c53 100644 --- a/3rdparty/libpng16/Makefile +++ b/3rdparty/libpng16/Makefile @@ -5,7 +5,7 @@ endif PNGCFLAGS = -O -I. -I../zlib/ -fPIC -fno-common $(PNG_EXTRA_CFLAGS) $(ARCHS) ifeq ($(shell uname),Darwin) ifneq ($(notdir $(CC)),emcc) -PNGCFLAGS += -mmacosx-version-min=10.11 +PNGCFLAGS += -mmacosx-version-min=10.14 ifeq ($(shell arch),arm64) PNGCFLAGS += -DPNG_ARM_NEON_OPT=0 endif diff --git a/3rdparty/ogg/Makefile b/3rdparty/ogg/Makefile index 3e07a3186..f5b1c6166 100644 --- a/3rdparty/ogg/Makefile +++ b/3rdparty/ogg/Makefile @@ -5,7 +5,7 @@ endif VERSION = 1.3.2 OGG_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) -OGG_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.11 +OGG_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/openh264/Makefile b/3rdparty/openh264/Makefile index a0ba67808..9fdb4b37f 100644 --- a/3rdparty/openh264/Makefile +++ b/3rdparty/openh264/Makefile @@ -5,7 +5,7 @@ endif VERSION = 2.0.0 OPENH264_EXTRA_MAKE_FLAGS ?= ifeq ($(shell uname),Darwin) -OPENH264_EXTRA_MAKE_FLAGS += CFLAGS=-mmacosx-version-min=10.11 +OPENH264_EXTRA_MAKE_FLAGS += CFLAGS=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/pixman/Makefile b/3rdparty/pixman/Makefile index 4abd21a26..a64b9e84a 100644 --- a/3rdparty/pixman/Makefile +++ b/3rdparty/pixman/Makefile @@ -5,7 +5,7 @@ endif VERSION = 0.40.0 PIXMAN_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) -PIXMAN_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.11 +PIXMAN_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/qhull/Makefile b/3rdparty/qhull/Makefile index 48c205fc6..71f58e2d2 100644 --- a/3rdparty/qhull/Makefile +++ b/3rdparty/qhull/Makefile @@ -5,7 +5,7 @@ endif CFLAGS = -O -fPIC -fno-common $(ARCHS) ifeq ($(shell uname),Darwin) ifneq ($(notdir $(CC)),emcc) -CFLAGS += -mmacosx-version-min=10.11 +CFLAGS += -mmacosx-version-min=10.14 endif endif LIBS = libqhull.a diff --git a/3rdparty/theora/Makefile b/3rdparty/theora/Makefile index bbabc17a3..0a926fd5c 100644 --- a/3rdparty/theora/Makefile +++ b/3rdparty/theora/Makefile @@ -6,7 +6,7 @@ VERSION = 1.1.1 THEORA_CONFIGURE ?= ./configure THEORA_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) -THEORA_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.11 +THEORA_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/tiff/Makefile b/3rdparty/tiff/Makefile index a0cb43a46..2de575759 100644 --- a/3rdparty/tiff/Makefile +++ b/3rdparty/tiff/Makefile @@ -5,7 +5,7 @@ endif VERSION = 4.0.10 TIFF_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) - TIFF_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.11 + TIFF_EXTRA_CONFIGURE_FLAGS += CFLAGS=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/vpx/Makefile b/3rdparty/vpx/Makefile index 02e4c8573..f59ac7c76 100644 --- a/3rdparty/vpx/Makefile +++ b/3rdparty/vpx/Makefile @@ -5,7 +5,7 @@ endif VERSION = 1.4.0 VPX_EXTRA_CONFIGURE_FLAGS ?= ifeq ($(shell uname),Darwin) -VPX_EXTRA_CONFIGURE_FLAGS += --extra-cflags=-mmacosx-version-min=10.11 +VPX_EXTRA_CONFIGURE_FLAGS += --extra-cflags=-mmacosx-version-min=10.14 endif ifeq ($(DOWNLOAD_CMD),) diff --git a/3rdparty/zeromq/Makefile b/3rdparty/zeromq/Makefile index bac54a545..9e31e7c79 100644 --- a/3rdparty/zeromq/Makefile +++ b/3rdparty/zeromq/Makefile @@ -45,8 +45,8 @@ $(PREFIX)/src/zeromq-$(VERSION)/Makefile: $(PREFIX)/src/zeromq-$(VERSION)/config $(ZEROMQ_EXTRA_CONFIGURE_FLAGS) $(PREFIX)/lib/libzmq.a: $(PREFIX)/src/zeromq-$(VERSION)/Makefile - MACOSX_DEPLOYMENT_TARGET="10.11" $(MAKE) -C $(PREFIX)/src/zeromq-$(VERSION) -j4 - MACOSX_DEPLOYMENT_TARGET="10.11" $(MAKE) -C $(PREFIX)/src/zeromq-$(VERSION) install + MACOSX_DEPLOYMENT_TARGET="10.14" $(MAKE) -C $(PREFIX)/src/zeromq-$(VERSION) -j4 + MACOSX_DEPLOYMENT_TARGET="10.14" $(MAKE) -C $(PREFIX)/src/zeromq-$(VERSION) install install: $(PREFIX)/lib/libzmq.a diff --git a/3rdparty/zlib/Makefile b/3rdparty/zlib/Makefile index 5fe45c42e..639279f8b 100644 --- a/3rdparty/zlib/Makefile +++ b/3rdparty/zlib/Makefile @@ -5,7 +5,7 @@ endif CFLAGS=-O -fPIC -DHAVE_HIDDEN $(ARCHS) ifeq ($(shell uname),Darwin) ifneq ($(notdir $(CC)),emcc) -CFLAGS += -mmacosx-version-min=10.11 +CFLAGS += -mmacosx-version-min=10.14 endif endif LIBS=libz.a diff --git a/CMakeLists.txt b/CMakeLists.txt index 36eda202e..9722e84f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -466,7 +466,7 @@ set(GRM_SOURCES lib/grm/src/grm/logging.c lib/grm/src/grm/memwriter.c lib/grm/src/grm/net.c - lib/grm/src/grm/plot.c + lib/grm/src/grm/plot.cxx lib/grm/src/grm/util.c lib/grm/src/grm/datatype/double_map.c lib/grm/src/grm/datatype/string_array_map.c @@ -505,6 +505,9 @@ foreach(LIBRARY grm_static grm_shared grm_shared_internal) PROPERTIES C_STANDARD 90 C_EXTENSIONS OFF C_STANDARD_REQUIRED ON + CXX_STANDARD 17 + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON POSITION_INDEPENDENT_CODE ON C_VISIBILITY_PRESET hidden INSTALL_RPATH "${INSTALL_RPATH}" diff --git a/js/Makefile b/js/Makefile index 5921567c5..297a6bfee 100755 --- a/js/Makefile +++ b/js/Makefile @@ -25,6 +25,9 @@ else OPTS += -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2 endif DEFINES = -DEMSCRIPTEN -D__SVR4 -DGRDIR=\"\" -DNO_GL -DNO_THREADS + CFLAGS = $(DEFINES) $(OPTS) $(EXTRA_CFLAGS) +CXXFLAGS = $(DEFINES) $(OPTS) -std=c++17 $(EXTRA_CXXFLAGS) + LDFLAGS = $(DEFINES) $(OPTS) $(EXTRA_LDFLAGS) JPEGDIR = ../3rdparty/jpeg PNGDIR = ../3rdparty/libpng16 ZLIBDIR = ../3rdparty/zlib @@ -110,7 +113,7 @@ INCLUDES = -I$(THIRDPARTYDIR)/include/ \ .PHONY: default clean .SECONDARY .FORCE .SUFFIXES: -.SUFFIXES: .c .o +.SUFFIXES: .c .cxx .o .SECONDARY: @@ -146,10 +149,13 @@ $(FTDIR)/libfreetype.a: $(GRDIR)/gr.o: ../lib/gr/gr_version.h %.o: %.c $(LIBS) - $(CC) -c $(OPTS) $(DEFINES) -o $@ $< $(INCLUDES) + $(CC) -c $(CFLAGS) -o $@ $< $(INCLUDES) + +%.o: %.cxx $(LIBS) + $(CXX) -c $(CXXFLAGS) -o $@ $< $(INCLUDES) libGR.js: $(OBJS) $(LIBS) library.js fonts - $(CC) $(OPTS) $(DEFINES) \ + $(CXX) $(LDFLAGS) \ --embed-file fonts/gksfont.dat --embed-file fonts/CMUSerif-Math.ttf --embed-file fonts/DejaVuSans.ttf --embed-file fonts/mathtex2_offsets.bin \ --js-library library.js \ -o $@ $(OBJS) $(LIBS) \ diff --git a/lib/gks/Makefile b/lib/gks/Makefile index 5ed28c0fa..a8074aa1c 100644 --- a/lib/gks/Makefile +++ b/lib/gks/Makefile @@ -29,9 +29,9 @@ UNAME := $(shell uname) RANLIB = ar ts ifeq ($(UNAME), Darwin) GR_SHARED_LIBRARY_SUFFIX ?= .dylib - CFLAGS += -mmacosx-version-min=10.11 + CFLAGS += -mmacosx-version-min=10.14 INSTALL_NAME = -Wl,-install_name,@rpath/libGKS${GR_SHARED_LIBRARY_SUFFIX} - LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.11 + LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.14 SOFLAGS = -dynamiclib else GR_SHARED_LIBRARY_SUFFIX ?= .so diff --git a/lib/gks/plugin/Makefile b/lib/gks/plugin/Makefile index c211381fc..ededf4e78 100644 --- a/lib/gks/plugin/Makefile +++ b/lib/gks/plugin/Makefile @@ -13,9 +13,9 @@ endif SOFLAGS = -shared LDFLAGS = $(EXTRA_LDFLAGS) ifeq ($(UNAME),Darwin) - CFLAGS += -mmacosx-version-min=10.11 - CXXFLAGS += -mmacosx-version-min=10.11 - LDFLAGS += -mmacosx-version-min=10.11 + CFLAGS += -mmacosx-version-min=10.14 + CXXFLAGS += -mmacosx-version-min=10.14 + LDFLAGS += -mmacosx-version-min=10.14 endif WX_CONFIG = false WXDEFS = @@ -29,7 +29,7 @@ ifneq ($(QT4_QMAKE),false) QT4LIBS = -L$(QT4LIBDIR) -lQtGui -lQtCore ifeq ($(UNAME),Darwin) ifneq ($(QT4INC),) - QT4INC += -mmacosx-version-min=10.11 + QT4INC += -mmacosx-version-min=10.14 endif else EXTRA_LDFLAGS_QT4="-Wl,-rpath=$(QT4LIBDIR)" diff --git a/lib/gr/Makefile b/lib/gr/Makefile index 63f5ede98..1fa5b3042 100644 --- a/lib/gr/Makefile +++ b/lib/gr/Makefile @@ -21,9 +21,9 @@ UNAME := $(shell uname) RANLIB = ar ts ifeq ($(UNAME), Darwin) GR_SHARED_LIBRARY_SUFFIX ?= .dylib - CFLAGS += -mmacosx-version-min=10.11 + CFLAGS += -mmacosx-version-min=10.14 INSTALL_NAME = -Wl,-install_name,@rpath/libGR${GR_SHARED_LIBRARY_SUFFIX} - LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.11 + LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.14 SOFLAGS = -dynamiclib else GR_SHARED_LIBRARY_SUFFIX ?= .so diff --git a/lib/gr/qtgr/Makefile b/lib/gr/qtgr/Makefile index a4158f1fe..dd160e5ce 100644 --- a/lib/gr/qtgr/Makefile +++ b/lib/gr/qtgr/Makefile @@ -18,7 +18,7 @@ QT4INCDIR = `$(QT4_QMAKE) -query QT_INSTALL_HEADERS` QT4INC = -I$(QT4INCDIR) -I$(QT4INCDIR)/QtCore -I$(QT4INCDIR)/QtGui ifeq ($(UNAME_S),Darwin) ifneq ($(QT4INC),) - QT4INC += -mmacosx-version-min=10.11 + QT4INC += -mmacosx-version-min=10.14 endif endif QT4LIBDIR = `$(QT4_QMAKE) -query QT_INSTALL_LIBS` diff --git a/lib/gr3/Makefile b/lib/gr3/Makefile index 0ad0a3a79..7441d9cd3 100644 --- a/lib/gr3/Makefile +++ b/lib/gr3/Makefile @@ -19,11 +19,11 @@ UNAME := $(shell uname) ifeq ($(UNAME), Darwin) GR_SHARED_LIBRARY_SUFFIX ?= .dylib - CFLAGS+= -mmacosx-version-min=10.11 + CFLAGS+= -mmacosx-version-min=10.14 GLLIBS = -framework OpenGL -framework Cocoa OBJS+= gr3_cgl.o INSTALL_NAME = -Wl,-install_name,@rpath/libGR3${GR_SHARED_LIBRARY_SUFFIX} - LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.11 + LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.14 SOFLAGS = -dynamiclib LIBS = else diff --git a/lib/grm/Makefile b/lib/grm/Makefile index a232e5706..4f50f8756 100644 --- a/lib/grm/Makefile +++ b/lib/grm/Makefile @@ -34,14 +34,16 @@ UNAME := $(shell uname) -I../gr3 \ -I$(THIRDPARTYDIR)/include CC = cc - CFLAGS = $(DEFINES) -O3 -Wall -fPIC -fvisibility=hidden $(EXTRA_CFLAGS) + CFLAGS = $(DEFINES) -std=c90 -O3 -Wall -fPIC -fvisibility=hidden $(EXTRA_CFLAGS) + CXXFLAGS = $(DEFINES) -std=c++17 -O3 -Wall -fPIC -fvisibility=hidden $(EXTRA_CXXFLAGS) AR ?= ar RANLIB ?= ar ts ifeq ($(UNAME), Darwin) GR_SHARED_LIBRARY_SUFFIX ?= .dylib - CFLAGS += -mmacosx-version-min=10.11 + CFLAGS += -mmacosx-version-min=10.14 + CXXFLAGS += -mmacosx-version-min=10.14 INSTALL_NAME = -Wl,-install_name,@rpath/libGRM${GR_SHARED_LIBRARY_SUFFIX} - LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.11 + LDFLAGS = $(EXTRA_LDFLAGS) -Wl,-rpath,@loader_path/. -mmacosx-version-min=10.14 SOFLAGS = -dynamiclib else GR_SHARED_LIBRARY_SUFFIX ?= .so @@ -56,6 +58,9 @@ endif .c.o: $(CC) -o $@ -c $(INCLUDES) $(CFLAGS) $< +.cxx.o: + $(CXX) -o $@ -c $(INCLUDES) $(CXXFLAGS) $< + default: $(MAKE) -C ../.. Makedefs $(MAKE) `cat ../../Makedefs` @@ -78,7 +83,7 @@ libGRM.a: $(GRMOBJS) $(RANLIB) $@ libGRM${GR_SHARED_LIBRARY_SUFFIX}: $(GRMOBJS) libGR libGR3 - $(CC) -o $@ $(SOFLAGS) $(GRMOBJS) $(LIBS) $(LDFLAGS) $(INSTALL_NAME) + $(CXX) -o $@ $(SOFLAGS) $(GRMOBJS) $(LIBS) $(LDFLAGS) $(INSTALL_NAME) install: @if [ ! -d $(DESTDIR)$(GRDIR) ]; then mkdir -m 755 $(DESTDIR)$(GRDIR); fi @@ -96,3 +101,5 @@ clean: *${GR_SHARED_LIBRARY_SUFFIX} .PHONY: all targets install clean prerequisites libGR libGR3 +.SUFFIXES: # Delete the default suffixes +.SUFFIXES: .c .cxx .o # List all suffixes for suffix rules explicitly diff --git a/lib/grm/include/grm/interaction.h b/lib/grm/include/grm/interaction.h index b3c38ae1c..54d7d932d 100644 --- a/lib/grm/include/grm/interaction.h +++ b/lib/grm/include/grm/interaction.h @@ -42,5 +42,4 @@ EXPORT grm_tooltip_info_t *grm_get_tooltip(const int, const int); #ifdef __cplusplus } #endif - #endif /* ifndef GRM_INTERACTION_H_INCLUDED */ diff --git a/lib/grm/makefile.mingw b/lib/grm/makefile.mingw index e48a0370f..aa9945c5f 100644 --- a/lib/grm/makefile.mingw +++ b/lib/grm/makefile.mingw @@ -4,6 +4,7 @@ endif DEFINES = -DGRDIR=\"$(GRDIR)\" -DNO_GS -DNO_X11 -D_WIN32_WINNT=0x0600 -DBUILDING_DLL CFLAGS = $(DEFINES) -std=c90 + CXXFLAGS = $(DEFINES) -std=c++17 INCLUDES = -I./include \ -I./src \ -I../gks \ @@ -36,8 +37,6 @@ endif src/grm/datatype/uint_map.o -.SUFFIXES: .o .c - default: all all: libGRM.dll libGRM.lib @@ -45,11 +44,14 @@ all: libGRM.dll libGRM.lib .c.o: $(CC) -o $@ -c $(INCLUDES) $(CFLAGS) $< +.cxx.o: + $(CXX) -o $@ -c $(INCLUDES) $(CXXFLAGS) $< + libGRM.lib: $(OBJS) $(AR) crs $@ $? libGRM.dll: $(OBJS) - $(CC) -shared -o $@ $^ $(LIBS) $(LDFLAGS) + $(CXX) -shared -o $@ $^ $(LIBS) $(LDFLAGS) grm.c: grm.h @@ -60,3 +62,5 @@ clean: src/grm/datatype/*.o .PHONY: default all clean +.SUFFIXES: # Delete the default suffixes +.SUFFIXES: .c .cxx .o # List all suffixes for suffix rules explicitly diff --git a/lib/grm/src/grm/args.c b/lib/grm/src/grm/args.c index 3ce697c36..fd98b54c8 100644 --- a/lib/grm/src/grm/args.c +++ b/lib/grm/src/grm/args.c @@ -1029,7 +1029,7 @@ args_value_iterator_t *arg_value_iter(const arg_t *arg) return args_value_iterator_new(arg); } -error_t arg_increase_array(arg_t *arg, size_t increment) +err_t arg_increase_array(arg_t *arg, size_t increment) { size_t *current_size_ptr, new_size; void ***current_buffer_ptr, **new_buffer; @@ -1490,8 +1490,8 @@ grm_args_t *args_copy_extended(const grm_args_t *copy_args, const char **keys_co return args; } -error_t args_push_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, va_list *vl, - int apply_padding) +err_t args_push_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, va_list *vl, + int apply_padding) { arg_t *arg; args_node_t *args_node; @@ -1536,15 +1536,15 @@ error_t args_push_common(grm_args_t *args, const char *key, const char *value_fo return NO_ERROR; } -error_t args_push_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl) +err_t args_push_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl) { return args_push_common(args, key, value_format, NULL, vl, 0); } -error_t args_push_arg(grm_args_t *args, arg_t *arg) +err_t args_push_arg(grm_args_t *args, arg_t *arg) { args_node_t *args_node = NULL, *previous_node_by_keyword = NULL; - error_t error = NO_ERROR; + err_t error = NO_ERROR; ++(arg->priv->reference_count); args_node = malloc(sizeof(args_node_t)); @@ -1600,12 +1600,12 @@ error_t args_push_arg(grm_args_t *args, arg_t *arg) return error; } -error_t args_update_many(grm_args_t *args, const grm_args_t *update_args) +err_t args_update_many(grm_args_t *args, const grm_args_t *update_args) { return args_merge(args, update_args, NULL); } -error_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *const *merge_keys) +err_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *const *merge_keys) { args_iterator_t *it = NULL; args_value_iterator_t *value_it = NULL, *merge_value_it = NULL; @@ -1614,7 +1614,7 @@ error_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *c const char *const *current_key_ptr; int merge; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; it = args_iter(merge_args); cleanup_and_set_error_if(it == NULL, ERROR_MALLOC); @@ -1690,8 +1690,8 @@ error_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *c return error; } -error_t args_setdefault_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, - va_list *vl, int apply_padding) +err_t args_setdefault_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, + va_list *vl, int apply_padding) { if (!grm_args_contains(args, key)) { @@ -1700,9 +1700,9 @@ error_t args_setdefault_common(grm_args_t *args, const char *key, const char *va return NO_ERROR; } -error_t args_setdefault(grm_args_t *args, const char *key, const char *value_format, ...) +err_t args_setdefault(grm_args_t *args, const char *key, const char *value_format, ...) { - error_t error; + err_t error; va_list vl; va_start(vl, value_format); @@ -1713,13 +1713,13 @@ error_t args_setdefault(grm_args_t *args, const char *key, const char *value_for return error; } -error_t args_setdefault_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, - int apply_padding) +err_t args_setdefault_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, + int apply_padding) { return args_setdefault_common(args, key, value_format, buffer, NULL, apply_padding); } -error_t args_setdefault_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl) +err_t args_setdefault_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl) { return args_setdefault_common(args, key, value_format, NULL, vl, 0); } @@ -1764,7 +1764,7 @@ void args_clear(grm_args_t *args, const char **exclude_keys) } } -error_t args_increase_array(grm_args_t *args, const char *key, size_t increment) +err_t args_increase_array(grm_args_t *args, const char *key, size_t increment) { arg_t *arg; @@ -2077,7 +2077,7 @@ void grm_args_delete(grm_args_t *args) int grm_args_push(grm_args_t *args, const char *key, const char *value_format, ...) { va_list vl; - error_t error; + err_t error; va_start(vl, value_format); @@ -2091,7 +2091,7 @@ int grm_args_push(grm_args_t *args, const char *key, const char *value_format, . int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, int apply_padding) { - error_t error; + err_t error; error = args_push_common(args, key, value_format, buffer, NULL, apply_padding); diff --git a/lib/grm/src/grm/args_int.h b/lib/grm/src/grm/args_int.h index d47bd0643..d684e9025 100644 --- a/lib/grm/src/grm/args_int.h +++ b/lib/grm/src/grm/args_int.h @@ -1,6 +1,10 @@ #ifndef GRM_ARGS_INT_H_INCLUDED #define GRM_ARGS_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -124,7 +128,7 @@ void *copy_value(char format, void *value_ptr); args_value_iterator_t *arg_value_iter(const arg_t *arg); -error_t arg_increase_array(arg_t *arg, size_t increment); +err_t arg_increase_array(arg_t *arg, size_t increment); int arg_first_value(const arg_t *arg, const char *first_value_format, void *first_value, unsigned int *array_length); #define arg_first_value(arg, first_value_format, first_value, array_length) \ @@ -141,22 +145,22 @@ grm_args_t *args_flatcopy(const grm_args_t *args) UNUSED; grm_args_t *args_copy(const grm_args_t *copy_args); grm_args_t *args_copy_extended(const grm_args_t *copy_args, const char **keys_copy_as_array, const char **ignore_keys); -error_t args_push_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, va_list *vl, - int apply_padding); -error_t args_push_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl); -error_t args_push_arg(grm_args_t *args, arg_t *arg); -error_t args_update_many(grm_args_t *args, const grm_args_t *update_args) UNUSED; -error_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *const *merge_keys); -error_t args_setdefault_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, - va_list *vl, int apply_padding); -error_t args_setdefault(grm_args_t *args, const char *key, const char *value_format, ...); -error_t args_setdefault_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, - int apply_padding) UNUSED; -error_t args_setdefault_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl); +err_t args_push_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, va_list *vl, + int apply_padding); +err_t args_push_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl); +err_t args_push_arg(grm_args_t *args, arg_t *arg); +err_t args_update_many(grm_args_t *args, const grm_args_t *update_args) UNUSED; +err_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *const *merge_keys); +err_t args_setdefault_common(grm_args_t *args, const char *key, const char *value_format, const void *buffer, + va_list *vl, int apply_padding); +err_t args_setdefault(grm_args_t *args, const char *key, const char *value_format, ...); +err_t args_setdefault_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, + int apply_padding) UNUSED; +err_t args_setdefault_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl); void args_clear(grm_args_t *args, const char **exclude_keys); -error_t args_increase_array(grm_args_t *args, const char *key, size_t increment) UNUSED; +err_t args_increase_array(grm_args_t *args, const char *key, size_t increment) UNUSED; unsigned int args_count(const grm_args_t *args) UNUSED; @@ -192,4 +196,7 @@ void args_value_iterator_finalize(args_value_iterator_t *args_value_iterator); void *args_value_iterator_next(args_value_iterator_t *args_value_iterator); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_ARGS_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/base64.c b/lib/grm/src/grm/base64.c index bbdbecd0a..4390f0b66 100644 --- a/lib/grm/src/grm/base64.c +++ b/lib/grm/src/grm/base64.c @@ -41,7 +41,7 @@ static const char base64_encode_table[64] = { static const char padding_char = '='; -error_t block_decode(char dst[3], const char src[4], int block_len, int *decoded_block_len) +err_t block_decode(char dst[3], const char src[4], int block_len, int *decoded_block_len) { /* * Transform the four input characters with the `base64_decode_table` and interpret the result as four 6-bit values. @@ -52,7 +52,7 @@ error_t block_decode(char dst[3], const char src[4], int block_len, int *decoded int i; /* The C standard does not require that a char has 8 bits (but almost all systems have 8 bit chars). */ - static_assert(CHAR_BIT == 8, "A char must consist of 8 bits for this code to work."); + grm_static_assert(CHAR_BIT == 8, "A char must consist of 8 bits for this code to work."); /* Ignore padding characters */ while (src[block_len - 1] == padding_char && block_len > 0) @@ -133,12 +133,12 @@ error_t block_decode(char dst[3], const char src[4], int block_len, int *decoded } -error_t block_encode(char dst[4], const char src[3], int block_len) +err_t block_encode(char dst[4], const char src[3], int block_len) { /* Interpret three 8-bit characters as four 6-bit indices for the `base64_encode_table` */ /* The C standard does not require that a char has 8 bits (but almost all systems have 8 bit chars). */ - static_assert(CHAR_BIT == 8, "A char must consist of 8 bits for this code to work."); + grm_static_assert(CHAR_BIT == 8, "A char must consist of 8 bits for this code to work."); if (block_len < 1) { @@ -198,12 +198,12 @@ error_t block_encode(char dst[4], const char src[3], int block_len) } -char *base64_decode(char *dst, const char *src, size_t *dst_len, error_t *error) +char *base64_decode(char *dst, const char *src, size_t *dst_len, err_t *error) { size_t src_len, max_dst_len; size_t dst_index = 0, src_index; int decoded_block_len; - error_t _error = NO_ERROR; + err_t _error = NO_ERROR; src_len = strlen(src); @@ -225,7 +225,7 @@ char *base64_decode(char *dst, const char *src, size_t *dst_len, error_t *error) for (dst_index = 0, src_index = 0; src_index < src_len; dst_index += decoded_block_len, src_index += 4) { - _error = block_decode(dst + dst_index, src + src_index, min(src_len - src_index, 4), &decoded_block_len); + _error = block_decode(dst + dst_index, src + src_index, grm_min(src_len - src_index, 4), &decoded_block_len); if (_error != NO_ERROR) { break; @@ -250,11 +250,11 @@ char *base64_decode(char *dst, const char *src, size_t *dst_len, error_t *error) } -char *base64_encode(char *dst, const char *src, size_t src_len, error_t *error) +char *base64_encode(char *dst, const char *src, size_t src_len, err_t *error) { size_t dst_len; size_t dst_index = 0, src_index; - error_t _error = NO_ERROR; + err_t _error = NO_ERROR; /* Always round up to multiple of 4 */ dst_len = (4 * src_len) / 3; @@ -274,7 +274,7 @@ char *base64_encode(char *dst, const char *src, size_t src_len, error_t *error) for (dst_index = 0, src_index = 0; src_index < src_len; dst_index += 4, src_index += 3) { - _error = block_encode(dst + dst_index, src + src_index, min(src_len - src_index, 3)); + _error = block_encode(dst + dst_index, src + src_index, grm_min(src_len - src_index, 3)); if (_error != NO_ERROR) { break; diff --git a/lib/grm/src/grm/base64_int.h b/lib/grm/src/grm/base64_int.h index 63418e809..72542a542 100644 --- a/lib/grm/src/grm/base64_int.h +++ b/lib/grm/src/grm/base64_int.h @@ -1,16 +1,23 @@ #ifndef GRM_BASE64_INT_H_INCLUDED #define GRM_BASE64_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #include #include "error_int.h" #include -error_t block_decode(char dst[3], const char src[4], int block_len, int *decoded_block_len); -error_t block_encode(char dst[4], const char src[3], int block_len); +err_t block_decode(char dst[3], const char src[4], int block_len, int *decoded_block_len); +err_t block_encode(char dst[4], const char src[3], int block_len); -char *base64_decode(char *dst, const char *src, size_t *dst_len, error_t *error); -char *base64_encode(char *dst, const char *src, size_t src_len, error_t *error); +char *base64_decode(char *dst, const char *src, size_t *dst_len, err_t *error); +char *base64_encode(char *dst, const char *src, size_t src_len, err_t *error); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_BASE64_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/datatype/string_list.c b/lib/grm/src/grm/datatype/string_list.c index 835786ec1..358baa4a5 100644 --- a/lib/grm/src/grm/datatype/string_list.c +++ b/lib/grm/src/grm/datatype/string_list.c @@ -16,7 +16,7 @@ DEFINE_LIST_METHODS(string) -error_t string_list_entry_copy(string_list_entry_t *copy, const string_list_const_entry_t entry) +err_t string_list_entry_copy(string_list_entry_t *copy, const string_list_const_entry_t entry) { string_list_entry_t _copy; @@ -30,7 +30,7 @@ error_t string_list_entry_copy(string_list_entry_t *copy, const string_list_cons return NO_ERROR; } -error_t string_list_entry_delete(string_list_entry_t entry) +err_t string_list_entry_delete(string_list_entry_t entry) { free(entry); return NO_ERROR; diff --git a/lib/grm/src/grm/datatype/string_map.c b/lib/grm/src/grm/datatype/string_map.c index 2b1e921ed..88256bcf0 100644 --- a/lib/grm/src/grm/datatype/string_map.c +++ b/lib/grm/src/grm/datatype/string_map.c @@ -18,7 +18,7 @@ DEFINE_MAP_METHODS(string) -int string_map_value_copy(char **copy, const char *value) +int string_map_value_copy(const char **copy, const char *value) { char *_copy; @@ -32,9 +32,9 @@ int string_map_value_copy(char **copy, const char *value) return 1; } -void string_map_value_delete(char *value) +void string_map_value_delete(const char *value) { - free(value); + free((void *)value); } diff --git a/lib/grm/src/grm/datatype/string_map_int.h b/lib/grm/src/grm/datatype/string_map_int.h index fa4ac2546..37dea5757 100644 --- a/lib/grm/src/grm/datatype/string_map_int.h +++ b/lib/grm/src/grm/datatype/string_map_int.h @@ -12,7 +12,8 @@ /* ------------------------- string_map ----------------------------------------------------------------------------- */ -DECLARE_MAP_TYPE(string, char *) +typedef const char *const_char_p; +DECLARE_MAP_TYPE(string, const_char_p) /* ========================= methods ================================================================================ */ diff --git a/lib/grm/src/grm/datatype/template/list_int.h b/lib/grm/src/grm/datatype/template/list_int.h index b65f65477..4601fc9db 100644 --- a/lib/grm/src/grm/datatype/template/list_int.h +++ b/lib/grm/src/grm/datatype/template/list_int.h @@ -19,8 +19,8 @@ #define DECLARE_LIST_TYPE(prefix, entry_type) \ typedef entry_type prefix##_list_entry_t; \ typedef const entry_type prefix##_list_const_entry_t; \ - typedef error_t (*prefix##_list_entry_copy_func_t)(prefix##_list_entry_t *, prefix##_list_const_entry_t); \ - typedef error_t (*prefix##_list_entry_delete_func_t)(prefix##_list_entry_t); \ + typedef err_t (*prefix##_list_entry_copy_func_t)(prefix##_list_entry_t *, prefix##_list_const_entry_t); \ + typedef err_t (*prefix##_list_entry_delete_func_t)(prefix##_list_entry_t); \ \ typedef struct \ { \ @@ -45,8 +45,8 @@ /* ~~~~~~~~~~~~~~~~~~~~~~~ ref list ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ \ \ typedef entry_type prefix##_reflist_entry_t; \ - typedef error_t (*prefix##_reflist_entry_copy_func_t)(prefix##_reflist_entry_t *, prefix##_reflist_entry_t); \ - typedef error_t (*prefix##_reflist_entry_delete_func_t)(prefix##_reflist_entry_t); \ + typedef err_t (*prefix##_reflist_entry_copy_func_t)(prefix##_reflist_entry_t *, prefix##_reflist_entry_t); \ + typedef err_t (*prefix##_reflist_entry_delete_func_t)(prefix##_reflist_entry_t); \ \ typedef struct \ { \ @@ -78,22 +78,22 @@ prefix##_list_t *prefix##_list_new(void); \ void prefix##_list_delete(prefix##_list_t *list); \ \ - error_t prefix##_list_push_front(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ - error_t prefix##_list_push_back(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ + err_t prefix##_list_push_front(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ + err_t prefix##_list_push_back(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ \ prefix##_list_entry_t prefix##_list_pop_front(prefix##_list_t *list); \ prefix##_list_entry_t prefix##_list_pop_back(prefix##_list_t *list); \ \ - error_t prefix##_list_push(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ + err_t prefix##_list_push(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ prefix##_list_entry_t prefix##_list_pop(prefix##_list_t *list); \ \ - error_t prefix##_list_enqueue(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ + err_t prefix##_list_enqueue(prefix##_list_t *list, prefix##_list_const_entry_t entry); \ prefix##_list_entry_t prefix##_list_dequeue(prefix##_list_t *list); \ \ int prefix##_list_empty(prefix##_list_t *list); \ \ - error_t prefix##_list_entry_copy(prefix##_list_entry_t *copy, prefix##_list_const_entry_t entry); \ - error_t prefix##_list_entry_delete(prefix##_list_entry_t entry); \ + err_t prefix##_list_entry_copy(prefix##_list_entry_t *copy, prefix##_list_const_entry_t entry); \ + err_t prefix##_list_entry_delete(prefix##_list_entry_t entry); \ \ int prefix##_list_find_previous_node(const prefix##_list_t *list, const prefix##_list_node_t *node, \ prefix##_list_node_t **previous_node); \ @@ -104,22 +104,22 @@ void prefix##_reflist_delete(prefix##_reflist_t *list) MAYBE_UNUSED; \ void prefix##_reflist_delete_with_entries(prefix##_reflist_t *list) MAYBE_UNUSED; \ \ - error_t prefix##_reflist_push_front(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ - error_t prefix##_reflist_push_back(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ + err_t prefix##_reflist_push_front(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ + err_t prefix##_reflist_push_back(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ \ prefix##_reflist_entry_t prefix##_reflist_pop_front(prefix##_reflist_t *list) MAYBE_UNUSED; \ prefix##_reflist_entry_t prefix##_reflist_pop_back(prefix##_reflist_t *list) MAYBE_UNUSED; \ \ - error_t prefix##_reflist_push(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ + err_t prefix##_reflist_push(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ prefix##_reflist_entry_t prefix##_reflist_pop(prefix##_reflist_t *list) MAYBE_UNUSED; \ \ - error_t prefix##_reflist_enqueue(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ + err_t prefix##_reflist_enqueue(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) MAYBE_UNUSED; \ prefix##_reflist_entry_t prefix##_reflist_dequeue(prefix##_reflist_t *list) MAYBE_UNUSED; \ \ int prefix##_reflist_empty(prefix##_reflist_t *list) MAYBE_UNUSED; \ \ - error_t prefix##_reflist_entry_copy(prefix##_reflist_entry_t *copy, const prefix##_reflist_entry_t entry); \ - error_t prefix##_reflist_entry_delete(prefix##_reflist_entry_t entry); \ + err_t prefix##_reflist_entry_copy(prefix##_reflist_entry_t *copy, const prefix##_reflist_entry_t entry); \ + err_t prefix##_reflist_entry_delete(prefix##_reflist_entry_t entry); \ \ int prefix##_reflist_find_previous_node(const prefix##_reflist_t *list, const prefix##_reflist_node_t *node, \ prefix##_reflist_node_t **previous_node) MAYBE_UNUSED; @@ -170,10 +170,10 @@ free(list); \ } \ \ - error_t prefix##_list_push_front(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ + err_t prefix##_list_push_front(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ { \ prefix##_list_node_t *new_list_node; \ - error_t error = NO_ERROR; \ + err_t error = NO_ERROR; \ \ new_list_node = malloc(sizeof(prefix##_list_node_t)); \ error_cleanup_and_set_error_if(new_list_node == NULL, ERROR_MALLOC); \ @@ -194,10 +194,10 @@ return error; \ } \ \ - error_t prefix##_list_push_back(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ + err_t prefix##_list_push_back(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ { \ prefix##_list_node_t *new_list_node; \ - error_t error = NO_ERROR; \ + err_t error = NO_ERROR; \ \ new_list_node = malloc(sizeof(prefix##_list_node_t)); \ error_cleanup_and_set_error_if(new_list_node == NULL, ERROR_MALLOC); \ @@ -266,14 +266,14 @@ return last_entry; \ } \ \ - error_t prefix##_list_push(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ + err_t prefix##_list_push(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ { \ return prefix##_list_push_front(list, entry); \ } \ \ prefix##_list_entry_t prefix##_list_pop(prefix##_list_t *list) { return prefix##_list_pop_front(list); } \ \ - error_t prefix##_list_enqueue(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ + err_t prefix##_list_enqueue(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ { \ return prefix##_list_push_back(list, entry); \ } \ @@ -341,12 +341,12 @@ free(list); \ } \ \ - error_t prefix##_reflist_push_front(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ + err_t prefix##_reflist_push_front(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ { \ return prefix##_list_push_front((prefix##_list_t *)list, (prefix##_list_entry_t)entry); \ } \ \ - error_t prefix##_reflist_push_back(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ + err_t prefix##_reflist_push_back(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ { \ return prefix##_list_push_back((prefix##_list_t *)list, (prefix##_list_entry_t)entry); \ } \ @@ -361,7 +361,7 @@ return prefix##_list_pop_back((prefix##_list_t *)list); \ } \ \ - error_t prefix##_reflist_push(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ + err_t prefix##_reflist_push(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ { \ return prefix##_list_push((prefix##_list_t *)list, (prefix##_list_entry_t)entry); \ } \ @@ -371,7 +371,7 @@ return prefix##_list_pop((prefix##_list_t *)list); \ } \ \ - error_t prefix##_reflist_enqueue(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ + err_t prefix##_reflist_enqueue(prefix##_reflist_t *list, prefix##_reflist_entry_t entry) \ { \ return prefix##_list_enqueue((prefix##_list_t *)list, (prefix##_list_entry_t)entry); \ } \ @@ -391,10 +391,10 @@ (prefix##_list_node_t **)previous_node); \ } \ \ - error_t prefix##_reflist_entry_copy(prefix##_reflist_entry_t *copy, prefix##_reflist_entry_t entry) \ + err_t prefix##_reflist_entry_copy(prefix##_reflist_entry_t *copy, prefix##_reflist_entry_t entry) \ { \ *copy = entry; \ return NO_ERROR; \ } \ \ - error_t prefix##_reflist_entry_delete(prefix##_reflist_entry_t entry UNUSED) { return NO_ERROR; } + err_t prefix##_reflist_entry_delete(prefix##_reflist_entry_t entry UNUSED) { return NO_ERROR; } diff --git a/lib/grm/src/grm/datatype/template/set_int.h b/lib/grm/src/grm/datatype/template/set_int.h index 1720ea529..51b46e18e 100644 --- a/lib/grm/src/grm/datatype/template/set_int.h +++ b/lib/grm/src/grm/datatype/template/set_int.h @@ -70,7 +70,7 @@ typedef SSIZE_T ssize_t; \ /* Use the power of 2 which is equal or greater than 2*capacity as the set capacity */ \ power2_capacity = next_or_equal_power2(2 * capacity); \ - set = malloc(sizeof(prefix##_set_t)); \ + set = (prefix##_set_t *)malloc(sizeof(prefix##_set_t)); \ if (set == NULL) \ { \ debug_print_malloc_error(); \ @@ -78,13 +78,13 @@ typedef SSIZE_T ssize_t; } \ set->set = NULL; \ set->used = NULL; \ - set->set = malloc(power2_capacity * sizeof(prefix##_set_entry_t)); \ + set->set = (prefix##_set_entry_t *)malloc(power2_capacity * sizeof(prefix##_set_entry_t)); \ if (set->set == NULL) \ { \ debug_print_malloc_error(); \ goto error_cleanup; \ } \ - set->used = calloc(power2_capacity, sizeof(unsigned char)); \ + set->used = (unsigned char *)calloc(power2_capacity, sizeof(unsigned char)); \ if (set->used == NULL) \ { \ debug_print_malloc_error(); \ diff --git a/lib/grm/src/grm/dump.c b/lib/grm/src/grm/dump.c index 61a2bfa66..3abe7d911 100644 --- a/lib/grm/src/grm/dump.c +++ b/lib/grm/src/grm/dump.c @@ -136,56 +136,56 @@ void grm_dump(const grm_args_t *args, FILE *f) } \ while (0) -#define print_values(value_type, format_string, color_code) \ - do \ - { \ - int print_last_element = 0; \ - fputc('[', f); \ - cursor_xpos += strlen(arg->key) + 3; \ - for (i = 0; i < min(value_it->array_length, array_print_elements_count); i++) \ - { \ - if (print_last_element) \ - { \ - i = value_it->array_length - 1; \ - } \ - if (array_print_elements_count >= value_it->array_length || i != array_print_elements_count - 2) \ - { \ - if (use_color_codes) \ - { \ - count_characters = \ - snprintf(buffer, BUFFER_LEN, \ - "\033[38;5;%dm" format_string "\033[0m" \ - "%s", \ - color_code, (*((value_type **)value_it->value_ptr))[i], \ - (i < min(value_it->array_length, array_print_elements_count) - 1) ? ", " : "]"); \ - count_characters -= (color_code >= 100) ? 15 : ((color_code >= 10) ? 14 : 13); \ - } \ - else \ - { \ - count_characters = \ - snprintf(buffer, BUFFER_LEN, format_string "%s", (*((value_type **)value_it->value_ptr))[i], \ - (i < min(value_it->array_length, array_print_elements_count) - 1) ? ", " : "]"); \ - } \ - } \ - else \ - { \ - count_characters = snprintf(buffer, BUFFER_LEN, "..., "); \ - print_last_element = 1; \ - } \ - if (cursor_xpos + count_characters > columns) \ - { \ - fputc('\n', f); \ - print_indent; \ - cursor_xpos = INDENT * recursion_level + fprintf(f, "%*s", (int)strlen(arg->key) + 3, "") - 1; \ - } \ - fputs(buffer, f); \ - cursor_xpos += count_characters; \ - } \ - if (value_it->array_length == 0) \ - { \ - fputc(']', f); \ - } \ - } \ +#define print_values(value_type, format_string, color_code) \ + do \ + { \ + int print_last_element = 0; \ + fputc('[', f); \ + cursor_xpos += strlen(arg->key) + 3; \ + for (i = 0; i < grm_min(value_it->array_length, array_print_elements_count); i++) \ + { \ + if (print_last_element) \ + { \ + i = value_it->array_length - 1; \ + } \ + if (array_print_elements_count >= value_it->array_length || i != array_print_elements_count - 2) \ + { \ + if (use_color_codes) \ + { \ + count_characters = \ + snprintf(buffer, BUFFER_LEN, \ + "\033[38;5;%dm" format_string "\033[0m" \ + "%s", \ + color_code, (*((value_type **)value_it->value_ptr))[i], \ + (i < grm_min(value_it->array_length, array_print_elements_count) - 1) ? ", " : "]"); \ + count_characters -= (color_code >= 100) ? 15 : ((color_code >= 10) ? 14 : 13); \ + } \ + else \ + { \ + count_characters = \ + snprintf(buffer, BUFFER_LEN, format_string "%s", (*((value_type **)value_it->value_ptr))[i], \ + (i < grm_min(value_it->array_length, array_print_elements_count) - 1) ? ", " : "]"); \ + } \ + } \ + else \ + { \ + count_characters = snprintf(buffer, BUFFER_LEN, "..., "); \ + print_last_element = 1; \ + } \ + if (cursor_xpos + count_characters > columns) \ + { \ + fputc('\n', f); \ + print_indent; \ + cursor_xpos = INDENT * recursion_level + fprintf(f, "%*s", (int)strlen(arg->key) + 3, "") - 1; \ + } \ + fputs(buffer, f); \ + cursor_xpos += count_characters; \ + } \ + if (value_it->array_length == 0) \ + { \ + fputc(']', f); \ + } \ + } \ while (0) #define print_type(value_type, format_string, color_code) \ diff --git a/lib/grm/src/grm/dump_int.h b/lib/grm/src/grm/dump_int.h index 757e8bb71..71407177e 100644 --- a/lib/grm/src/grm/dump_int.h +++ b/lib/grm/src/grm/dump_int.h @@ -1,9 +1,16 @@ #ifndef GRM_DUMP_INT_H_INCLUDED #define GRM_DUMP_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_DUMP_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/dynamic_args_array.c b/lib/grm/src/grm/dynamic_args_array.c index 7b9c99849..f981efddf 100644 --- a/lib/grm/src/grm/dynamic_args_array.c +++ b/lib/grm/src/grm/dynamic_args_array.c @@ -46,7 +46,7 @@ void dynamic_args_array_delete_with_elements(dynamic_args_array_t *args_array) dynamic_args_array_delete(args_array); } -error_t dynamic_args_array_push_back(dynamic_args_array_t *args_array, grm_args_t *args) +err_t dynamic_args_array_push_back(dynamic_args_array_t *args_array, grm_args_t *args) { if (args_array->size == args_array->capacity) { diff --git a/lib/grm/src/grm/dynamic_args_array_int.h b/lib/grm/src/grm/dynamic_args_array_int.h index 58bb0b000..91bdcdcd4 100644 --- a/lib/grm/src/grm/dynamic_args_array_int.h +++ b/lib/grm/src/grm/dynamic_args_array_int.h @@ -1,6 +1,10 @@ #ifndef GRM_DYNAMIC_ARGS_ARRAY_INT_H_INCLUDED #define GRM_DYNAMIC_ARGS_ARRAY_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -35,7 +39,10 @@ typedef struct dynamic_args_array_t *dynamic_args_array_new(void); void dynamic_args_array_delete(dynamic_args_array_t *args_array); void dynamic_args_array_delete_with_elements(dynamic_args_array_t *args_array); -error_t dynamic_args_array_push_back(dynamic_args_array_t *args_array, grm_args_t *args); +err_t dynamic_args_array_push_back(dynamic_args_array_t *args_array, grm_args_t *args); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_DYNAMIC_ARGS_ARRAY_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/error_int.h b/lib/grm/src/grm/error_int.h index 5423c36af..5dbed779d 100644 --- a/lib/grm/src/grm/error_int.h +++ b/lib/grm/src/grm/error_int.h @@ -1,6 +1,10 @@ #ifndef GRM_ERROR_INT_H_INCLUDED #define GRM_ERROR_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __unix__ #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L @@ -137,7 +141,7 @@ typedef enum ENUM_VALUE(NO_ERROR, 0) #endif ENUM_ELEMENTS(ENUM_VALUE, ENUM_LAST_VALUE) -} error_t; +} err_t; /* ######################### public implementatin ################################################################### */ @@ -157,4 +161,7 @@ void debug_printf(const char *format, ...); #endif +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_ERROR_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/event.c b/lib/grm/src/grm/event.c index 590739e01..c30c364ac 100644 --- a/lib/grm/src/grm/event.c +++ b/lib/grm/src/grm/event.c @@ -46,7 +46,7 @@ int process_events(void) DEFINE_LIST_METHODS(event) -error_t event_list_entry_copy(event_list_entry_t *copy, event_list_const_entry_t entry) +err_t event_list_entry_copy(event_list_entry_t *copy, event_list_const_entry_t entry) { event_list_entry_t _copy; @@ -62,7 +62,7 @@ error_t event_list_entry_copy(event_list_entry_t *copy, event_list_const_entry_t return NO_ERROR; } -error_t event_list_entry_delete(event_list_entry_t entry) +err_t event_list_entry_delete(event_list_entry_t entry) { free(entry); return NO_ERROR; @@ -152,10 +152,10 @@ int event_queue_process_all(event_queue_t *queue) return 1; } -error_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id) +err_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id) { grm_new_plot_event_t *new_plot_event = NULL; - error_t error = NO_ERROR; + err_t error = NO_ERROR; new_plot_event = malloc(sizeof(grm_new_plot_event_t)); error_cleanup_and_set_error_if(new_plot_event == NULL, ERROR_MALLOC); @@ -176,10 +176,10 @@ error_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id) return error; } -error_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id) +err_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id) { grm_update_plot_event_t *update_plot_event = NULL; - error_t error = NO_ERROR; + err_t error = NO_ERROR; update_plot_event = malloc(sizeof(grm_update_plot_event_t)); error_cleanup_and_set_error_if(update_plot_event == NULL, ERROR_MALLOC); @@ -200,10 +200,10 @@ error_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id) return error; } -error_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int width, int height) +err_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int width, int height) { grm_size_event_t *size_event = NULL; - error_t error = NO_ERROR; + err_t error = NO_ERROR; size_event = malloc(sizeof(grm_size_event_t)); error_cleanup_and_set_error_if(size_event == NULL, ERROR_MALLOC); @@ -226,10 +226,10 @@ error_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int wi return error; } -error_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *identificator) +err_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *identificator) { grm_merge_end_event_t *merge_end_event = NULL; - error_t error = NO_ERROR; + err_t error = NO_ERROR; merge_end_event = malloc(sizeof(grm_merge_end_event_t)); error_cleanup_and_set_error_if(merge_end_event == NULL, ERROR_MALLOC); diff --git a/lib/grm/src/grm/event_int.h b/lib/grm/src/grm/event_int.h index 3c8ecf422..2cbd24818 100644 --- a/lib/grm/src/grm/event_int.h +++ b/lib/grm/src/grm/event_int.h @@ -1,6 +1,10 @@ #ifndef GRM_EVENT_INT_H_INCLUDED #define GRM_EVENT_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include "datatype/template/list_int.h" @@ -46,13 +50,16 @@ void event_queue_unregister(event_queue_t *queue, grm_event_type_t type); int event_queue_process_next(event_queue_t *queue); int event_queue_process_all(event_queue_t *queue); -error_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id); -error_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id); -error_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int width, int height); -error_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *identificator); +err_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id); +err_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id); +err_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int width, int height); +err_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *identificator); #undef DECLARE_LIST_METHODS +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_EVENT_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/interaction.c b/lib/grm/src/grm/interaction.c index f83c23c26..6c92f1ddb 100644 --- a/lib/grm/src/grm/interaction.c +++ b/lib/grm/src/grm/interaction.c @@ -49,7 +49,7 @@ int grm_input(const grm_args_t *input_args) logger((stderr, "Processing input\n")); get_figure_size(NULL, &width, &height, NULL, NULL); - max_width_height = max(width, height); + max_width_height = grm_max(width, height); logger((stderr, "Using size (%d, %d)\n", width, height)); if (args_values(input_args, "x", "i", &x) && args_values(input_args, "y", "i", &y)) @@ -260,7 +260,7 @@ int grm_is3d(const int x, const int y) const char *kind; get_figure_size(NULL, &width, &height, NULL, NULL); - max_width_height = max(width, height); + max_width_height = grm_max(width, height); ndc_x = (double)x / max_width_height; ndc_y = (double)y / max_width_height; @@ -286,7 +286,7 @@ int grm_get_box(const int x1, const int y1, const int x2, const int y2, const in const double *viewport, *wswindow; grm_args_t *subplot_args; get_figure_size(NULL, &width, &height, NULL, NULL); - max_width_height = max(width, height); + max_width_height = grm_max(width, height); if (!get_focus_and_factor(x1, y1, x2, y2, keep_aspect_ratio, &factor_x, &factor_y, &focus_x, &focus_y, &subplot_args)) { return 0; @@ -295,12 +295,12 @@ int grm_get_box(const int x1, const int y1, const int x2, const int y2, const in args_values(subplot_args, "viewport", "D", &viewport); viewport_mid_x = (viewport[1] + viewport[0]) / 2.0; viewport_mid_y = (viewport[3] + viewport[2]) / 2.0; - *w = (int)round(factor_x * width * (viewport[1] - viewport[0]) / (wswindow[1] - wswindow[0])); - *h = (int)round(factor_y * height * (viewport[3] - viewport[2]) / (wswindow[3] - wswindow[2])); - *x = (int)round(((viewport_mid_x + focus_x) - ((viewport_mid_x + focus_x) - viewport[0]) * factor_x) * - max_width_height); - *y = (int)round(height - ((viewport_mid_y + focus_y) - ((viewport_mid_y + focus_y) - viewport[3]) * factor_y) * - max_width_height); + *w = (int)grm_round(factor_x * width * (viewport[1] - viewport[0]) / (wswindow[1] - wswindow[0])); + *h = (int)grm_round(factor_y * height * (viewport[3] - viewport[2]) / (wswindow[3] - wswindow[2])); + *x = (int)grm_round(((viewport_mid_x + focus_x) - ((viewport_mid_x + focus_x) - viewport[0]) * factor_x) * + max_width_height); + *y = (int)grm_round(height - ((viewport_mid_y + focus_y) - ((viewport_mid_y + focus_y) - viewport[3]) * factor_y) * + max_width_height); return 1; } @@ -316,7 +316,7 @@ grm_tooltip_info_t *grm_get_tooltip(const int mouse_x, const int mouse_y) unsigned int x_length, y_length, z_length, series_i = 0, i; get_figure_size(NULL, &width, &height, NULL, NULL); - max_width_height = max(width, height); + max_width_height = grm_max(width, height); x = (double)mouse_x / max_width_height; y = (double)(height - mouse_y) / max_width_height; diff --git a/lib/grm/src/grm/interaction_int.h b/lib/grm/src/grm/interaction_int.h index d7b914b4e..e6349c15e 100644 --- a/lib/grm/src/grm/interaction_int.h +++ b/lib/grm/src/grm/interaction_int.h @@ -1,6 +1,10 @@ #ifndef GRM_INTERACTION_INT_H_INCLUDED #define GRM_INTERACTION_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -16,4 +20,7 @@ #define INPUT_DEFAULT_KEEP_ASPECT_RATIO 1 +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_INTERACTION_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/json.c b/lib/grm/src/grm/json.c index c272d22f7..ccb65eb10 100644 --- a/lib/grm/src/grm/json.c +++ b/lib/grm/src/grm/json.c @@ -33,13 +33,13 @@ const char *FROMJSON_VALID_DELIMITERS = ",]}"; const char FROMJSON_STRING_DELIMITER = '"'; const char FROMJSON_ESCAPE_CHARACTER = '\\'; -static error_t (*fromjson_datatype_to_func[])(fromjson_state_t *) = {NULL, - fromjson_parse_null, - fromjson_parse_bool, - fromjson_parse_number, - fromjson_parse_string, - fromjson_parse_array, - fromjson_parse_object}; +static err_t (*fromjson_datatype_to_func[])(fromjson_state_t *) = {NULL, + fromjson_parse_null, + fromjson_parse_bool, + fromjson_parse_number, + fromjson_parse_string, + fromjson_parse_array, + fromjson_parse_object}; static const char *const fromjson_datatype_to_string[] = {"unknown", "null", "bool", "number", "string", "array", "object"}; @@ -47,7 +47,7 @@ static const char *const fromjson_datatype_to_string[] = {"unknown", "null", "b /* ------------------------- json serializer ------------------------------------------------------------------------ */ -static error_t (*tojson_datatype_to_func[128])(tojson_state_t *); +static err_t (*tojson_datatype_to_func[128])(tojson_state_t *); static int tojson_static_variables_initialized = 0; static tojson_permanent_state_t tojson_permanent_state = {complete, 0}; @@ -61,7 +61,7 @@ int grm_read(grm_args_t *args, const char *json_string) return (fromjson_read(args, json_string) == NO_ERROR); } -error_t fromjson_read(grm_args_t *args, const char *json_string) +err_t fromjson_read(grm_args_t *args, const char *json_string) { return fromjson_parse(args, json_string, NULL); } @@ -71,12 +71,12 @@ int grm_load_from_str(const char *json_string) return (fromjson_read(active_plot_args, json_string) == NO_ERROR); } -error_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_state_t *shared_state) +err_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_state_t *shared_state) { char *filtered_json_string = NULL; fromjson_state_t state; int allocated_shared_state_mem = 0; - error_t error = NO_ERROR; + err_t error = NO_ERROR; state.datatype = JSON_DATATYPE_UNKNOWN; state.value_buffer = NULL; @@ -212,7 +212,7 @@ error_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_share } \ while (0) -error_t fromjson_parse_null(fromjson_state_t *state) +err_t fromjson_parse_null(fromjson_state_t *state) { if (strncmp(state->shared_state->json_ptr, "null", 4) != 0) { @@ -223,7 +223,7 @@ error_t fromjson_parse_null(fromjson_state_t *state) return NO_ERROR; } -error_t fromjson_parse_bool(fromjson_state_t *state) +err_t fromjson_parse_bool(fromjson_state_t *state) { int bool_value; @@ -246,9 +246,9 @@ error_t fromjson_parse_bool(fromjson_state_t *state) return NO_ERROR; } -error_t fromjson_parse_number(fromjson_state_t *state) +err_t fromjson_parse_number(fromjson_state_t *state) { - error_t error; + err_t error; if (is_int_number(state->shared_state->json_ptr)) { @@ -261,7 +261,7 @@ error_t fromjson_parse_number(fromjson_state_t *state) return error; } -error_t fromjson_parse_int(fromjson_state_t *state) +err_t fromjson_parse_int(fromjson_state_t *state) { int was_successful; int int_value; @@ -277,7 +277,7 @@ error_t fromjson_parse_int(fromjson_state_t *state) return NO_ERROR; } -error_t fromjson_parse_double(fromjson_state_t *state) +err_t fromjson_parse_double(fromjson_state_t *state) { int was_successful; double double_value; @@ -293,7 +293,7 @@ error_t fromjson_parse_double(fromjson_state_t *state) return NO_ERROR; } -error_t fromjson_parse_string(fromjson_state_t *state) +err_t fromjson_parse_string(fromjson_state_t *state) { char *string_value; char *json_ptr; @@ -339,7 +339,7 @@ error_t fromjson_parse_string(fromjson_state_t *state) return string_is_complete ? NO_ERROR : ERROR_PARSE_STRING; } -error_t fromjson_parse_array(fromjson_state_t *state) +err_t fromjson_parse_array(fromjson_state_t *state) { fromjson_datatype_t json_datatype; const char *next_delim_ptr; @@ -388,7 +388,7 @@ error_t fromjson_parse_array(fromjson_state_t *state) array_type[0] = '\0'; do { - error_t error = NO_ERROR; + err_t error = NO_ERROR; size_t array_length = 0; state->shared_state->json_ptr += is_nested_array ? 2 : 1; next_delim_ptr = state->shared_state->json_ptr; @@ -460,10 +460,10 @@ error_t fromjson_parse_array(fromjson_state_t *state) #undef PARSE_VALUES } -error_t fromjson_parse_object(fromjson_state_t *state) +err_t fromjson_parse_object(fromjson_state_t *state) { grm_args_t *args; - error_t error; + err_t error; CHECK_AND_ALLOCATE_MEMORY(grm_args_t *, 1); args = grm_args_new(); @@ -512,7 +512,7 @@ fromjson_datatype_t fromjson_check_type(const fromjson_state_t *state) return datatype; } -error_t fromjson_copy_and_filter_json_string(char **dest, const char *src) +err_t fromjson_copy_and_filter_json_string(char **dest, const char *src) { const char *src_ptr; char *dest_buffer, *dest_ptr; @@ -833,17 +833,17 @@ int fromjson_str_to_int(const char **str, int *was_successful) } \ while (0) -#define DEFINE_STRINGIFY_VALUE(name, type, format_specifier) \ - error_t tojson_stringify_##name##_value(memwriter_t *memwriter, type value) \ - { \ - return memwriter_printf(memwriter, format_specifier, value); \ +#define DEFINE_STRINGIFY_VALUE(name, type, format_specifier) \ + err_t tojson_stringify_##name##_value(memwriter_t *memwriter, type value) \ + { \ + return memwriter_printf(memwriter, format_specifier, value); \ } #define DEFINE_STRINGIFY_SINGLE(name, type, promoted_type) \ - error_t tojson_stringify_##name(tojson_state_t *state) \ + err_t tojson_stringify_##name(tojson_state_t *state) \ { \ type value; \ - error_t error = NO_ERROR; \ + err_t error = NO_ERROR; \ RETRIEVE_SINGLE_VALUE(value, type, promoted_type); \ if ((error = tojson_stringify_##name##_value(state->memwriter, value)) != NO_ERROR) \ { \ @@ -854,13 +854,13 @@ int fromjson_str_to_int(const char **str, int *was_successful) } #define DEFINE_STRINGIFY_MULTI(name, type) \ - error_t tojson_stringify_##name##_array(tojson_state_t *state) \ + err_t tojson_stringify_##name##_array(tojson_state_t *state) \ { \ type *values; \ type current_value; \ unsigned int length; \ int remaining_elements; \ - error_t error = NO_ERROR; \ + err_t error = NO_ERROR; \ INIT_MULTI_VALUE(values, type); \ if (state->additional_type_info != NULL) \ { \ @@ -930,9 +930,9 @@ DEFINE_STRINGIFY_MULTI(args, grm_args_t *) #define STR(x) #x #define XSTR(x) STR(x) -error_t tojson_stringify_double_value(memwriter_t *memwriter, double value) +err_t tojson_stringify_double_value(memwriter_t *memwriter, double value) { - error_t error; + err_t error; size_t string_start_index; const char *unprocessed_string; @@ -959,12 +959,12 @@ error_t tojson_stringify_double_value(memwriter_t *memwriter, double value) #undef XSTR #undef STR -error_t tojson_stringify_char_array(tojson_state_t *state) +err_t tojson_stringify_char_array(tojson_state_t *state) { char *chars; char *escaped_chars = NULL; unsigned int length; - error_t error = NO_ERROR; + err_t error = NO_ERROR; INIT_MULTI_VALUE(chars, char); @@ -1005,11 +1005,11 @@ error_t tojson_stringify_char_array(tojson_state_t *state) return error; } -error_t tojson_stringify_string_value(memwriter_t *memwriter, char *value) +err_t tojson_stringify_string_value(memwriter_t *memwriter, char *value) { char *escaped_chars = NULL; unsigned int length = 0; - error_t error = NO_ERROR; + err_t error = NO_ERROR; if ((error = tojson_escape_special_chars(&escaped_chars, value, &length))) { @@ -1025,19 +1025,19 @@ error_t tojson_stringify_string_value(memwriter_t *memwriter, char *value) return error; } -error_t tojson_stringify_bool_value(memwriter_t *memwriter, int value) +err_t tojson_stringify_bool_value(memwriter_t *memwriter, int value) { return memwriter_puts(memwriter, value ? "true" : "false"); } -error_t tojson_stringify_object(tojson_state_t *state) +err_t tojson_stringify_object(tojson_state_t *state) { char **member_names = NULL; char **data_types = NULL; char **member_name_ptr; char **data_type_ptr; int has_members; - error_t error = NO_ERROR; + err_t error = NO_ERROR; /* IMPORTANT: additional_type_info is altered after the unzip call! */ if ((error = tojson_unzip_membernames_and_datatypes(state->additional_type_info, &member_names, &data_types)) != @@ -1131,9 +1131,9 @@ error_t tojson_stringify_object(tojson_state_t *state) return NO_ERROR; } -error_t tojson_stringify_args_value(memwriter_t *memwriter, grm_args_t *args) +err_t tojson_stringify_args_value(memwriter_t *memwriter, grm_args_t *args) { - error_t error = NO_ERROR; + err_t error = NO_ERROR; if ((error = memwriter_putc(memwriter, '{')) != NO_ERROR) { @@ -1240,7 +1240,7 @@ void tojson_read_datatype(tojson_state_t *state) state->additional_type_info = additional_type_info; } -error_t tojson_skip_bytes(tojson_state_t *state) +err_t tojson_skip_bytes(tojson_state_t *state) { unsigned int count; @@ -1268,9 +1268,9 @@ error_t tojson_skip_bytes(tojson_state_t *state) return NO_ERROR; } -error_t tojson_close_object(tojson_state_t *state) +err_t tojson_close_object(tojson_state_t *state) { - error_t error; + err_t error; --(state->shared->struct_nested_level); if ((error = memwriter_putc(state->memwriter, '}')) != NO_ERROR) { @@ -1279,7 +1279,7 @@ error_t tojson_close_object(tojson_state_t *state) return NO_ERROR; } -error_t tojson_read_array_length(tojson_state_t *state) +err_t tojson_read_array_length(tojson_state_t *state) { int value; @@ -1289,7 +1289,7 @@ error_t tojson_read_array_length(tojson_state_t *state) return NO_ERROR; } -error_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_name_ptr, char ***data_type_ptr) +err_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_name_ptr, char ***data_type_ptr) { int member_count; char **arrays[2]; @@ -1351,7 +1351,7 @@ error_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_n return NO_ERROR; } -error_t tojson_escape_special_chars(char **escaped_string, const char *unescaped_string, unsigned int *length) +err_t tojson_escape_special_chars(char **escaped_string, const char *unescaped_string, unsigned int *length) { /* characters '\' and '"' must be escaped before written to a json string value */ /* length can be `0` -> use `strlen(unescaped_string)` instead */ @@ -1406,9 +1406,9 @@ error_t tojson_escape_special_chars(char **escaped_string, const char *unescaped #undef INIT_MULTI_VALUE #undef FIN_MULTI_VALUE -error_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data, va_list *vl, int apply_padding, - int add_data, int add_data_without_separator, unsigned int *struct_nested_level, - tojson_serialization_result_t *serial_result, tojson_shared_state_t *shared_state) +err_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data, va_list *vl, int apply_padding, + int add_data, int add_data_without_separator, unsigned int *struct_nested_level, + tojson_serialization_result_t *serial_result, tojson_shared_state_t *shared_state) { /** * memwriter: memwriter handle @@ -1430,7 +1430,7 @@ error_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *da tojson_state_t state; int json_array_needed = 0; int allocated_shared_state_mem = 0; - error_t error = NO_ERROR; + err_t error = NO_ERROR; state.memwriter = memwriter; state.data_type_ptr = data_desc; @@ -1571,7 +1571,7 @@ void tojson_init_static_variables(void) } } -error_t tojson_init_variables(int *add_data, int *add_data_without_separator, char **_data_desc, const char *data_desc) +err_t tojson_init_variables(int *add_data, int *add_data_without_separator, char **_data_desc, const char *data_desc) { tojson_init_static_variables(); *add_data = (tojson_permanent_state.serial_result != complete); @@ -1609,11 +1609,11 @@ error_t tojson_init_variables(int *add_data, int *add_data_without_separator, ch return NO_ERROR; } -error_t tojson_write_vl(memwriter_t *memwriter, const char *data_desc, va_list *vl) +err_t tojson_write_vl(memwriter_t *memwriter, const char *data_desc, va_list *vl) { int add_data, add_data_without_separator; char *_data_desc; - error_t error; + err_t error; error = tojson_init_variables(&add_data, &add_data_without_separator, &_data_desc, data_desc); if (!error) @@ -1627,11 +1627,11 @@ error_t tojson_write_vl(memwriter_t *memwriter, const char *data_desc, va_list * return error; } -error_t tojson_write_buf(memwriter_t *memwriter, const char *data_desc, const void *buffer, int apply_padding) +err_t tojson_write_buf(memwriter_t *memwriter, const char *data_desc, const void *buffer, int apply_padding) { int add_data, add_data_without_separator; char *_data_desc; - error_t error; + err_t error; error = tojson_init_variables(&add_data, &add_data_without_separator, &_data_desc, data_desc); if (!error) @@ -1645,9 +1645,9 @@ error_t tojson_write_buf(memwriter_t *memwriter, const char *data_desc, const vo return error; } -error_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg) +err_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg) { - error_t error = NO_ERROR; + err_t error = NO_ERROR; if (arg->key == NULL) { @@ -1686,7 +1686,7 @@ error_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg) return error; } -error_t tojson_write_args(memwriter_t *memwriter, const grm_args_t *args) +err_t tojson_write_args(memwriter_t *memwriter, const grm_args_t *args) { args_iterator_t *it; arg_t *arg; diff --git a/lib/grm/src/grm/json_int.h b/lib/grm/src/grm/json_int.h index 47739648b..417e6126c 100644 --- a/lib/grm/src/grm/json_int.h +++ b/lib/grm/src/grm/json_int.h @@ -1,6 +1,10 @@ #ifndef GRM_JSON_INT_H_INCLUDED #define GRM_JSON_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -62,7 +66,7 @@ typedef struct /* ------------------------- json serializer ------------------------------------------------------------------------ */ -typedef error_t (*tojson_post_processing_callback_t)(memwriter_t *, unsigned int, const char *); +typedef err_t (*tojson_post_processing_callback_t)(memwriter_t *, unsigned int, const char *); enum { @@ -114,20 +118,20 @@ typedef struct /* ------------------------- json deserializer ---------------------------------------------------------------------- */ int grm_read(grm_args_t *args, const char *json_string); -error_t fromjson_read(grm_args_t *args, const char *json_string); - -error_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_state_t *shared_state); -error_t fromjson_parse_null(fromjson_state_t *state); -error_t fromjson_parse_bool(fromjson_state_t *state); -error_t fromjson_parse_number(fromjson_state_t *state); -error_t fromjson_parse_int(fromjson_state_t *state); -error_t fromjson_parse_double(fromjson_state_t *state); -error_t fromjson_parse_string(fromjson_state_t *state); -error_t fromjson_parse_array(fromjson_state_t *state); -error_t fromjson_parse_object(fromjson_state_t *state); +err_t fromjson_read(grm_args_t *args, const char *json_string); + +err_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_state_t *shared_state); +err_t fromjson_parse_null(fromjson_state_t *state); +err_t fromjson_parse_bool(fromjson_state_t *state); +err_t fromjson_parse_number(fromjson_state_t *state); +err_t fromjson_parse_int(fromjson_state_t *state); +err_t fromjson_parse_double(fromjson_state_t *state); +err_t fromjson_parse_string(fromjson_state_t *state); +err_t fromjson_parse_array(fromjson_state_t *state); +err_t fromjson_parse_object(fromjson_state_t *state); fromjson_datatype_t fromjson_check_type(const fromjson_state_t *state); -error_t fromjson_copy_and_filter_json_string(char **dest, const char *src); +err_t fromjson_copy_and_filter_json_string(char **dest, const char *src); int fromjson_is_escaped_delimiter(const char *delim_ptr, const char *str); int fromjson_find_next_delimiter(const char **delim_ptr, const char *src, int include_start, int exclude_nested_structures); @@ -138,21 +142,21 @@ int fromjson_str_to_int(const char **str, int *was_successful); /* ------------------------- json serializer ------------------------------------------------------------------------ */ -#define DECLARE_STRINGIFY(name, type) \ - error_t tojson_stringify_##name(tojson_state_t *state); \ - error_t tojson_stringify_##name##_array(tojson_state_t *state); \ - error_t tojson_stringify_##name##_value(memwriter_t *memwriter, type value); +#define DECLARE_STRINGIFY(name, type) \ + err_t tojson_stringify_##name(tojson_state_t *state); \ + err_t tojson_stringify_##name##_array(tojson_state_t *state); \ + err_t tojson_stringify_##name##_value(memwriter_t *memwriter, type value); -error_t tojson_read_array_length(tojson_state_t *state); -error_t tojson_skip_bytes(tojson_state_t *state); +err_t tojson_read_array_length(tojson_state_t *state); +err_t tojson_skip_bytes(tojson_state_t *state); DECLARE_STRINGIFY(int, int) DECLARE_STRINGIFY(double, double) DECLARE_STRINGIFY(char, char) DECLARE_STRINGIFY(string, char *) DECLARE_STRINGIFY(bool, int) -error_t tojson_stringify_object(tojson_state_t *state); +err_t tojson_stringify_object(tojson_state_t *state); DECLARE_STRINGIFY(args, grm_args_t *) -error_t tojson_close_object(tojson_state_t *state); +err_t tojson_close_object(tojson_state_t *state); #undef DECLARE_STRINGIFY_SINGLE #undef DECLARE_STRINGIFY_MULTI @@ -160,19 +164,22 @@ error_t tojson_close_object(tojson_state_t *state); int tojson_get_member_count(const char *data_desc); int tojson_is_json_array_needed(const char *data_desc); void tojson_read_datatype(tojson_state_t *state); -error_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_name_ptr, char ***data_type_ptr); -error_t tojson_escape_special_chars(char **escaped_string, const char *unescaped_string, unsigned int *length); -error_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data, va_list *vl, int apply_padding, - int add_data, int add_data_without_separator, unsigned int *struct_nested_level, - tojson_serialization_result_t *serial_result, tojson_shared_state_t *shared_state); +err_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_name_ptr, char ***data_type_ptr); +err_t tojson_escape_special_chars(char **escaped_string, const char *unescaped_string, unsigned int *length); +err_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data, va_list *vl, int apply_padding, + int add_data, int add_data_without_separator, unsigned int *struct_nested_level, + tojson_serialization_result_t *serial_result, tojson_shared_state_t *shared_state); void tojson_init_static_variables(void); -error_t tojson_init_variables(int *add_data, int *add_data_without_separator, char **_data_desc, const char *data_desc); -error_t tojson_write_vl(memwriter_t *memwriter, const char *data_desc, va_list *vl); -error_t tojson_write_buf(memwriter_t *memwriter, const char *data_desc, const void *buffer, int apply_padding); -error_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg); -error_t tojson_write_args(memwriter_t *memwriter, const grm_args_t *args); +err_t tojson_init_variables(int *add_data, int *add_data_without_separator, char **_data_desc, const char *data_desc); +err_t tojson_write_vl(memwriter_t *memwriter, const char *data_desc, va_list *vl); +err_t tojson_write_buf(memwriter_t *memwriter, const char *data_desc, const void *buffer, int apply_padding); +err_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg); +err_t tojson_write_args(memwriter_t *memwriter, const grm_args_t *args); int tojson_is_complete(void); int tojson_struct_nested_level(void); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_JSON_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/logging_int.h b/lib/grm/src/grm/logging_int.h index 24cd89c73..b0fe20175 100644 --- a/lib/grm/src/grm/logging_int.h +++ b/lib/grm/src/grm/logging_int.h @@ -1,6 +1,10 @@ #ifndef GRM_LOGGING_INT_H_INCLUDED #define GRM_LOGGING_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -30,4 +34,7 @@ void logger1_(FILE *stream, const char *filename, int line_number, const char *c void logger2_(FILE *stream, const char *format, ...); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_LOGGING_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/memwriter.c b/lib/grm/src/grm/memwriter.c index b63b5068f..00a771c6f 100644 --- a/lib/grm/src/grm/memwriter.c +++ b/lib/grm/src/grm/memwriter.c @@ -55,10 +55,10 @@ void memwriter_clear(memwriter_t *memwriter) *memwriter->buf = '\0'; } -error_t memwriter_replace(memwriter_t *memwriter, int index, int count, const char *replacement_str) +err_t memwriter_replace(memwriter_t *memwriter, int index, int count, const char *replacement_str) { int replacement_str_len = (replacement_str != NULL) ? strlen(replacement_str) : 0; - error_t error = NO_ERROR; + err_t error = NO_ERROR; if ((replacement_str_len > count) && (error = memwriter_ensure_buf(memwriter, replacement_str_len - count)) != NO_ERROR) @@ -79,17 +79,17 @@ error_t memwriter_replace(memwriter_t *memwriter, int index, int count, const ch return error; } -error_t memwriter_erase(memwriter_t *memwriter, int index, int count) +err_t memwriter_erase(memwriter_t *memwriter, int index, int count) { return memwriter_replace(memwriter, index, count, NULL); } -error_t memwriter_insert(memwriter_t *memwriter, int index, const char *str) +err_t memwriter_insert(memwriter_t *memwriter, int index, const char *str) { return memwriter_replace(memwriter, index, 0, str); } -error_t memwriter_enlarge_buf(memwriter_t *memwriter, size_t size_increment) +err_t memwriter_enlarge_buf(memwriter_t *memwriter, size_t size_increment) { void *new_buf; @@ -129,7 +129,7 @@ error_t memwriter_enlarge_buf(memwriter_t *memwriter, size_t size_increment) return NO_ERROR; } -error_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_size) +err_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_size) { if (memwriter->size + needed_additional_size > memwriter->capacity) { @@ -138,10 +138,10 @@ error_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_si return NO_ERROR; } -error_t memwriter_printf(memwriter_t *memwriter, const char *format, ...) +err_t memwriter_printf(memwriter_t *memwriter, const char *format, ...) { va_list vl; - error_t error = NO_ERROR; + err_t error = NO_ERROR; while (1) { @@ -168,12 +168,12 @@ error_t memwriter_printf(memwriter_t *memwriter, const char *format, ...) return error; } -error_t memwriter_puts(memwriter_t *memwriter, const char *s) +err_t memwriter_puts(memwriter_t *memwriter, const char *s) { return memwriter_printf(memwriter, "%s", s); } -error_t memwriter_putc(memwriter_t *memwriter, char c) +err_t memwriter_putc(memwriter_t *memwriter, char c) { return memwriter_printf(memwriter, "%c", c); } diff --git a/lib/grm/src/grm/memwriter_int.h b/lib/grm/src/grm/memwriter_int.h index 78ab49015..b04cc6d9d 100644 --- a/lib/grm/src/grm/memwriter_int.h +++ b/lib/grm/src/grm/memwriter_int.h @@ -1,6 +1,10 @@ #ifndef GRM_MEMWRITER_INT_H_INCLUDED #define GRM_MEMWRITER_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -40,16 +44,19 @@ typedef struct _memwriter_t memwriter_t; memwriter_t *memwriter_new(void); void memwriter_delete(memwriter_t *memwriter); void memwriter_clear(memwriter_t *memwriter); -error_t memwriter_replace(memwriter_t *memwriter, int index, int count, const char *replacement_str); -error_t memwriter_erase(memwriter_t *memwriter, int index, int count); -error_t memwriter_insert(memwriter_t *memwriter, int index, const char *str) UNUSED; -error_t memwriter_enlarge_buf(memwriter_t *memwriter, size_t size_increment); -error_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_size); -error_t memwriter_printf(memwriter_t *memwriter, const char *format, ...); -error_t memwriter_puts(memwriter_t *memwriter, const char *s); -error_t memwriter_putc(memwriter_t *memwriter, char c); +err_t memwriter_replace(memwriter_t *memwriter, int index, int count, const char *replacement_str); +err_t memwriter_erase(memwriter_t *memwriter, int index, int count); +err_t memwriter_insert(memwriter_t *memwriter, int index, const char *str) UNUSED; +err_t memwriter_enlarge_buf(memwriter_t *memwriter, size_t size_increment); +err_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_size); +err_t memwriter_printf(memwriter_t *memwriter, const char *format, ...); +err_t memwriter_puts(memwriter_t *memwriter, const char *s); +err_t memwriter_putc(memwriter_t *memwriter, char c); char *memwriter_buf(const memwriter_t *memwriter); size_t memwriter_size(const memwriter_t *memwriter); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_MEMWRITER_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/net.c b/lib/grm/src/grm/net.c index e13b64f0b..58c08f83d 100644 --- a/lib/grm/src/grm/net.c +++ b/lib/grm/src/grm/net.c @@ -65,7 +65,7 @@ DECLARE_LIST_METHODS(dynamic_args_array) DEFINE_LIST_METHODS(args) -error_t args_list_entry_copy(args_list_entry_t *copy, args_list_const_entry_t entry) +err_t args_list_entry_copy(args_list_entry_t *copy, args_list_const_entry_t entry) { args_list_entry_t _copy; @@ -79,7 +79,7 @@ error_t args_list_entry_copy(args_list_entry_t *copy, args_list_const_entry_t en return NO_ERROR; } -error_t args_list_entry_delete(args_list_entry_t entry) +err_t args_list_entry_delete(args_list_entry_t entry) { grm_args_delete(entry); return NO_ERROR; @@ -90,15 +90,15 @@ error_t args_list_entry_delete(args_list_entry_t entry) DEFINE_LIST_METHODS(dynamic_args_array) -error_t dynamic_args_array_list_entry_copy(dynamic_args_array_list_entry_t *copy, - dynamic_args_array_list_const_entry_t entry) +err_t dynamic_args_array_list_entry_copy(dynamic_args_array_list_entry_t *copy, + dynamic_args_array_list_const_entry_t entry) { /* TODO: create a copy of the object! Otherwise code will segfault on list deletion for a non-ref list */ *copy = (dynamic_args_array_list_entry_t)entry; return NO_ERROR; } -error_t dynamic_args_array_list_entry_delete(dynamic_args_array_list_entry_t entry) +err_t dynamic_args_array_list_entry_delete(dynamic_args_array_list_entry_t entry) { dynamic_args_array_delete(entry); return NO_ERROR; @@ -113,8 +113,8 @@ error_t dynamic_args_array_list_entry_delete(dynamic_args_array_list_entry_t ent /* ------------------------- receiver ------------------------------------------------------------------------------- */ -error_t receiver_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, - const char *(*custom_recv)(const char *, unsigned int)) +err_t receiver_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, + const char *(*custom_recv)(const char *, unsigned int)) { handle->sender_receiver.receiver.comm.custom.recv = custom_recv; handle->sender_receiver.receiver.comm.custom.name = name; @@ -131,7 +131,7 @@ error_t receiver_init_for_custom(net_handle_t *handle, const char *name, unsigne return NO_ERROR; } -error_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port) +err_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port) { char port_str[PORT_MAX_STRING_LENGTH]; struct addrinfo *addr_result = NULL, addr_hints; @@ -249,16 +249,16 @@ error_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, uns return NO_ERROR; } -error_t receiver_finalize_for_custom(net_handle_t *handle) +err_t receiver_finalize_for_custom(net_handle_t *handle) { memwriter_delete(handle->sender_receiver.receiver.memwriter); return NO_ERROR; } -error_t receiver_finalize_for_socket(net_handle_t *handle) +err_t receiver_finalize_for_socket(net_handle_t *handle) { - error_t error = NO_ERROR; + err_t error = NO_ERROR; memwriter_delete(handle->sender_receiver.receiver.memwriter); #ifdef _WIN32 @@ -305,12 +305,12 @@ error_t receiver_finalize_for_socket(net_handle_t *handle) return error; } -error_t receiver_recv_for_socket(net_handle_t *handle) +err_t receiver_recv_for_socket(net_handle_t *handle) { int search_start_index = 0; char *end_ptr; static char recv_buf[SOCKET_RECV_BUF_SIZE]; - error_t error = NO_ERROR; + err_t error = NO_ERROR; while ((end_ptr = memchr(memwriter_buf(handle->sender_receiver.receiver.memwriter) + search_start_index, ETB, memwriter_size(handle->sender_receiver.receiver.memwriter) - search_start_index)) == NULL) @@ -340,11 +340,11 @@ error_t receiver_recv_for_socket(net_handle_t *handle) return error; } -error_t receiver_recv_for_custom(net_handle_t *handle) +err_t receiver_recv_for_custom(net_handle_t *handle) { /* TODO: is it really necessary to copy the memory? */ const char *recv_buf; - error_t error = NO_ERROR; + err_t error = NO_ERROR; recv_buf = handle->sender_receiver.receiver.comm.custom.recv(handle->sender_receiver.receiver.comm.custom.name, handle->sender_receiver.receiver.comm.custom.id); @@ -365,8 +365,8 @@ error_t receiver_recv_for_custom(net_handle_t *handle) /* ------------------------- sender --------------------------------------------------------------------------------- */ -error_t sender_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, - int (*custom_send)(const char *, unsigned int, const char *)) +err_t sender_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, + int (*custom_send)(const char *, unsigned int, const char *)) { handle->sender_receiver.sender.comm.custom.send = custom_send; handle->sender_receiver.sender.comm.custom.name = name; @@ -382,7 +382,7 @@ error_t sender_init_for_custom(net_handle_t *handle, const char *name, unsigned return NO_ERROR; } -error_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port) +err_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port) { char port_str[PORT_MAX_STRING_LENGTH]; struct addrinfo *addr_result = NULL, *addr_ptr = NULL, addr_hints; @@ -482,16 +482,16 @@ error_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsig return NO_ERROR; } -error_t sender_finalize_for_custom(net_handle_t *handle) +err_t sender_finalize_for_custom(net_handle_t *handle) { memwriter_delete(handle->sender_receiver.sender.memwriter); return NO_ERROR; } -error_t sender_finalize_for_socket(net_handle_t *handle) +err_t sender_finalize_for_socket(net_handle_t *handle) { - error_t error = NO_ERROR; + err_t error = NO_ERROR; memwriter_delete(handle->sender_receiver.sender.memwriter); #ifdef _WIN32 @@ -522,12 +522,12 @@ error_t sender_finalize_for_socket(net_handle_t *handle) return error; } -error_t sender_send_for_socket(net_handle_t *handle) +err_t sender_send_for_socket(net_handle_t *handle) { const char *buf; size_t buf_size; int bytes_left; - error_t error = NO_ERROR; + err_t error = NO_ERROR; if ((error = memwriter_putc(handle->sender_receiver.sender.memwriter, ETB)) != NO_ERROR) { @@ -554,10 +554,10 @@ error_t sender_send_for_socket(net_handle_t *handle) return error; } -error_t sender_send_for_custom(net_handle_t *handle) +err_t sender_send_for_custom(net_handle_t *handle) { const char *buf; - error_t error = NO_ERROR; + err_t error = NO_ERROR; buf = memwriter_buf(handle->sender_receiver.sender.memwriter); if (!handle->sender_receiver.sender.comm.custom.send(handle->sender_receiver.sender.comm.custom.name, @@ -583,7 +583,7 @@ void *grm_open(int is_receiver, const char *name, unsigned int id, int (*custom_send)(const char *, unsigned int, const char *)) { net_handle_t *handle; - error_t error = NO_ERROR; + err_t error = NO_ERROR; handle = malloc(sizeof(net_handle_t)); if (handle == NULL) @@ -687,7 +687,7 @@ int grm_send(const void *p, const char *data_desc, ...) { net_handle_t *handle = (net_handle_t *)p; va_list vl; - error_t error; + err_t error; va_start(vl, data_desc); error = tojson_write_vl(handle->sender_receiver.sender.memwriter, data_desc, &vl); @@ -703,7 +703,7 @@ int grm_send(const void *p, const char *data_desc, ...) int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int apply_padding) { net_handle_t *handle = (net_handle_t *)p; - error_t error; + err_t error; error = tojson_write_buf(handle->sender_receiver.sender.memwriter, data_desc, buffer, apply_padding); if (error == NO_ERROR && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) @@ -724,7 +724,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i char *_key = NULL; net_handle_t *handle = (net_handle_t *)p; char format_string[SEND_REF_FORMAT_MAX_LENGTH]; - error_t error = NO_ERROR; + err_t error = NO_ERROR; if (tojson_struct_nested_level() == 0) { @@ -975,7 +975,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i int grm_send_args(const void *p, const grm_args_t *args) { net_handle_t *handle = (net_handle_t *)p; - error_t error; + err_t error; error = tojson_write_args(handle->sender_receiver.sender.memwriter, args); if (error == NO_ERROR && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) diff --git a/lib/grm/src/grm/net_int.h b/lib/grm/src/grm/net_int.h index 331293d62..57f473a31 100644 --- a/lib/grm/src/grm/net_int.h +++ b/lib/grm/src/grm/net_int.h @@ -1,6 +1,10 @@ #ifndef GRM_NET_INT_H_INCLUDED #define GRM_NET_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include "error_int.h" @@ -30,11 +34,11 @@ struct _net_handle_t; typedef struct _net_handle_t net_handle_t; -typedef error_t (*recv_callback_t)(net_handle_t *); -typedef error_t (*send_callback_t)(net_handle_t *); +typedef err_t (*recv_callback_t)(net_handle_t *); +typedef err_t (*send_callback_t)(net_handle_t *); typedef const char *(*custom_recv_callback_t)(const char *, unsigned int); typedef int (*custom_send_callback_t)(const char *, unsigned int, const char *); -typedef error_t (*finalize_callback_t)(net_handle_t *); +typedef err_t (*finalize_callback_t)(net_handle_t *); struct _net_handle_t { @@ -88,24 +92,27 @@ struct _net_handle_t /* ------------------------- receiver ------------------------------------------------------------------------------- */ -static error_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port); -static error_t receiver_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, - const char *(*custom_recv)(const char *, unsigned int)); -static error_t receiver_finalize_for_socket(net_handle_t *handle); -static error_t receiver_finalize_for_custom(net_handle_t *handle); -static error_t receiver_recv_for_socket(net_handle_t *handle); -static error_t receiver_recv_for_custom(net_handle_t *handle); +static err_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port); +static err_t receiver_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, + const char *(*custom_recv)(const char *, unsigned int)); +static err_t receiver_finalize_for_socket(net_handle_t *handle); +static err_t receiver_finalize_for_custom(net_handle_t *handle); +static err_t receiver_recv_for_socket(net_handle_t *handle); +static err_t receiver_recv_for_custom(net_handle_t *handle); /* ------------------------- sender --------------------------------------------------------------------------------- */ -static error_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port); -static error_t sender_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, - int (*custom_send)(const char *, unsigned int, const char *)); -static error_t sender_finalize_for_socket(net_handle_t *handle); -static error_t sender_finalize_for_custom(net_handle_t *handle); -static error_t sender_send_for_socket(net_handle_t *handle); -static error_t sender_send_for_custom(net_handle_t *handle); +static err_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port); +static err_t sender_init_for_custom(net_handle_t *handle, const char *name, unsigned int id, + int (*custom_send)(const char *, unsigned int, const char *)); +static err_t sender_finalize_for_socket(net_handle_t *handle); +static err_t sender_finalize_for_custom(net_handle_t *handle); +static err_t sender_send_for_socket(net_handle_t *handle); +static err_t sender_send_for_custom(net_handle_t *handle); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_NET_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/plot.c b/lib/grm/src/grm/plot.cxx similarity index 94% rename from lib/grm/src/grm/plot.c rename to lib/grm/src/grm/plot.cxx index f457922f3..4045eecd9 100644 --- a/lib/grm/src/grm/plot.c +++ b/lib/grm/src/grm/plot.cxx @@ -1,9 +1,7 @@ -#ifdef __unix__ -#define _POSIX_C_SOURCE 200112L -#endif - /* ######################### includes ############################################################################### */ +extern "C" { + #include #include #include @@ -365,9 +363,9 @@ static string_map_entry_t key_to_formats[] = {{"a", "A"}, /* ~~~~~~~~~~~~~~~~~~~~~~~~~ general ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_init_static_variables(void) +err_t plot_init_static_variables(void) { - error_t error = NO_ERROR; + err_t error = NO_ERROR; if (!plot_static_variables_initialized) { @@ -449,8 +447,8 @@ error_t plot_init_static_variables(void) /* ~~~~~~~~~~~~~~~~~~~~~~~~~ plot arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const char **hierarchy_name_ptr, - uint_map_t *hierarchy_to_id, int hold_always) +err_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const char **hierarchy_name_ptr, + uint_map_t *hierarchy_to_id, int hold_always) { static args_set_map_t *key_to_cleared_args = NULL; static int recursion_level = -1; @@ -462,7 +460,7 @@ error_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const ch const char **current_hierarchy_name_ptr; grm_args_t **args_array, **merge_args_array, *current_args; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; ++recursion_level; if (hierarchy_name_ptr == NULL) @@ -723,12 +721,12 @@ error_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const ch return error; } -error_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, unsigned int next_hierarchy_level_max_id) +err_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, unsigned int next_hierarchy_level_max_id) { grm_args_t **args_array = NULL; unsigned int args_old_array_length; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; logger((stderr, "Init plot args structure for hierarchy: \"%s\"\n", *hierarchy_name_ptr)); @@ -763,13 +761,13 @@ error_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, uns return NO_ERROR; } -error_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr, - unsigned int next_hierarchy_level_max_id) +err_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr, + unsigned int next_hierarchy_level_max_id) { arg_t *arg = NULL; grm_args_t **args_array = NULL; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; logger((stderr, "Init plot args structure for hierarchy: \"%s\"\n", *hierarchy_name_ptr)); @@ -781,7 +779,7 @@ error_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_p arg = args_at(args, *hierarchy_name_ptr); if (arg == NULL) { - args_array = calloc(next_hierarchy_level_max_id, sizeof(grm_args_t *)); + args_array = static_cast(calloc(next_hierarchy_level_max_id, sizeof(grm_args_t *))); error_cleanup_and_set_error_if(args_array == NULL, ERROR_MALLOC); for (i = 0; i < next_hierarchy_level_max_id; ++i) { @@ -1007,11 +1005,11 @@ void plot_process_wswindow_wsviewport(grm_args_t *plot_args) (stderr, "Stored wsviewport (%lf, %lf, %lf, %lf)\n", wsviewport[0], wsviewport[1], wsviewport[2], wsviewport[3])); } -error_t plot_pre_subplot(grm_args_t *subplot_args) +err_t plot_pre_subplot(grm_args_t *subplot_args) { const char *kind; double alpha; - error_t error = NO_ERROR; + err_t error = NO_ERROR; logger((stderr, "Pre subplot processing\n")); @@ -1035,7 +1033,7 @@ error_t plot_pre_subplot(grm_args_t *subplot_args) plot_draw_axes(subplot_args, 1); } - gr_uselinespec(" "); + gr_uselinespec(const_cast(" ")); gr_savestate(); if (args_values(subplot_args, "alpha", "d", &alpha)) @@ -1111,8 +1109,8 @@ static void legend_size(grm_args_t *subplot_args, double *w, double *h) for (current_label = labels; *current_label != NULL; ++current_label) { gr_inqtext(0, 0, *(char **)current_label, tbx, tby); - *w = max(*w, tbx[2] - tbx[0]); - *h += max(tby[2] - tby[0], 0.03); + *w = grm_max(*w, tbx[2] - tbx[0]); + *h += grm_max(tby[2] - tby[0], 0.03); } } } @@ -1167,7 +1165,7 @@ void plot_process_viewport(grm_args_t *subplot_args) { double extent; - extent = min(vp[1] - vp[0], vp[3] - vp[2]); + extent = grm_min(vp[1] - vp[0], vp[3] - vp[2]); vp0 = 0.5 * (vp[0] + vp[1] - extent); vp1 = 0.5 * (vp[0] + vp[1] + extent); vp2 = 0.5 * (vp[2] + vp[3] - extent); @@ -1245,7 +1243,7 @@ void plot_process_viewport(grm_args_t *subplot_args) x_center = 0.5 * (viewport[0] + viewport[1]); y_center = 0.5 * (viewport[2] + viewport[3]); - r = 0.45 * min(viewport[1] - viewport[0], viewport[3] - viewport[2]); + r = 0.45 * grm_min(viewport[1] - viewport[0], viewport[3] - viewport[2]); if (grm_args_contains(subplot_args, "title")) { r *= 0.975; @@ -1528,7 +1526,7 @@ void plot_process_window(grm_args_t *subplot_args) gr_setscale(scale); } -error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) +err_t plot_store_coordinate_ranges(grm_args_t *subplot_args) { const char *kind; const char *style = ""; @@ -1549,7 +1547,7 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) range_keys[] = {{"xlim", "xrange"}, {"ylim", "yrange"}, {"zlim", "zrange"}, {"clim", "crange"}}; double *bins = NULL; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; logger((stderr, "Storing coordinate ranges\n")); @@ -1563,7 +1561,7 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) args_values(subplot_args, "kind", "s", &kind); args_values(subplot_args, "style", "s", &style); - cleanup_and_set_error_if(!string_map_at(fmt_map, kind, (char **)&fmt), ERROR_PLOT_UNKNOWN_KIND); + cleanup_and_set_error_if(!string_map_at(fmt_map, kind, static_cast(&fmt)), ERROR_PLOT_UNKNOWN_KIND); if (!str_equals_any(kind, 2, "pie", "polar_histogram")) { current_component_name = data_component_names; @@ -1615,8 +1613,8 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) { if (!is_nan(current_component[i])) { - current_min_component = min(current_component[i], current_min_component); - current_max_component = max(current_component[i], current_max_component); + current_min_component = grm_min(current_component[i], current_min_component); + current_max_component = grm_max(current_component[i], current_max_component); } } } @@ -1625,7 +1623,7 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) str_equals_any(*current_component_name, 2, "x", "y")) { /* in this case `x` or `y` (or both) are missing - * -> set the current min/max_component to the dimensions of `z` + * -> set the current grm_min/max_component to the dimensions of `z` * (shifted by half a unit to center color blocks) */ const char *other_component_name = (strcmp(*current_component_name, "x") == 0) ? "y" : "x"; double *other_component; @@ -1677,8 +1675,8 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) } } } - max_component = max(current_max_component, max_component); - min_component = min(current_min_component, min_component); + max_component = grm_max(current_max_component, max_component); + min_component = grm_min(current_min_component, min_component); } inner_series++; } @@ -1689,8 +1687,8 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) grm_args_push(*current_series, current_range_keys->series, "dd", current_min_component, current_max_component); } - min_component = min(current_min_component, min_component); - max_component = max(current_max_component, max_component); + min_component = grm_min(current_min_component, min_component); + max_component = grm_max(current_max_component, max_component); ++current_series; } } @@ -1710,7 +1708,7 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) } else if (strcmp(kind, "quiver") == 0) { - step = max(find_max_step(current_point_count, current_component), step); + step = grm_max(find_max_step(current_point_count, current_component), step); if (step > 0.0) { min_component -= step; @@ -1748,14 +1746,14 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) for (i = 0; i < u_length; i++) { double z = u[i] * u[i] + v[i] * v[i]; - current_min_component = min(z, current_min_component); - current_max_component = max(z, current_max_component); + current_min_component = grm_min(z, current_min_component); + current_max_component = grm_max(z, current_max_component); } current_min_component = sqrt(current_min_component); current_max_component = sqrt(current_max_component); } - min_component = min(current_min_component, min_component); - max_component = max(current_max_component, max_component); + min_component = grm_min(current_min_component, min_component); + max_component = grm_max(current_max_component, max_component); ++current_series; } } @@ -1790,7 +1788,7 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) { double *y; args_first_value(*current_series, "y", "D", &y, ¤t_point_count); - x_max = max(current_point_count + 1, x_max); + x_max = grm_max(current_point_count + 1, x_max); ++current_series; } } @@ -1823,20 +1821,20 @@ error_t plot_store_coordinate_ranges(grm_args_t *subplot_args) { num_bins = (int)(3.3 * log10(current_point_count) + 0.5) + 1; } - bins = malloc(num_bins * sizeof(double)); + bins = static_cast(malloc(num_bins * sizeof(double))); cleanup_and_set_error_if(bins == NULL, ERROR_MALLOC); bin_data(current_point_count, x, num_bins, bins, weights); for (i = 0; i < num_bins; i++) { - current_y_min = min(current_y_min, bins[i]); - current_y_max = max(current_y_max, bins[i]); + current_y_min = grm_min(current_y_min, bins[i]); + current_y_max = grm_max(current_y_max, bins[i]); } grm_args_push(*current_series, "bins", "nD", num_bins, bins); free(bins); bins = NULL; } - y_min = min(current_y_min, y_min); - y_max = max(current_y_max, y_max); + y_min = grm_min(current_y_min, y_min); + y_max = grm_max(current_y_max, y_max); current_series++; } grm_args_push(subplot_args, "_ylim", "dd", y_min, y_max); @@ -1907,9 +1905,9 @@ void plot_post_subplot(grm_args_t *subplot_args) } } -error_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name_start_ptr, const char *key, - uint_map_t *hierarchy_to_id, const grm_args_t **found_args, - const char ***found_hierarchy_name_ptr) +err_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name_start_ptr, const char *key, + uint_map_t *hierarchy_to_id, const grm_args_t **found_args, + const char ***found_hierarchy_name_ptr) { const char *key_hierarchy_name, **current_hierarchy_name_ptr; grm_args_t *current_args, **args_array; @@ -1917,7 +1915,8 @@ error_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name unsigned int args_array_length, current_id; logger((stderr, "Check hierarchy level for key \"%s\"...\n", key)); - return_error_if(!string_map_at(plot_valid_keys_map, key, (char **)&key_hierarchy_name), ERROR_PLOT_UNKNOWN_KEY); + return_error_if(!string_map_at(plot_valid_keys_map, key, static_cast(&key_hierarchy_name)), + ERROR_PLOT_UNKNOWN_KEY); logger((stderr, "... got hierarchy \"%s\"\n", key_hierarchy_name)); current_hierarchy_name_ptr = hierarchy_name_start_ptr; current_args = args; @@ -1955,7 +1954,7 @@ error_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name if (strcmp(*current_hierarchy_name_ptr, "plots") == 0) { int in_use; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(current_args, "in_use", "i", &in_use); if (in_use) { @@ -1990,13 +1989,12 @@ error_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name /* ~~~~~~~~~~~~~~~~~~~~~~~~~ plotting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_line(grm_args_t *subplot_args) +err_t plot_line(grm_args_t *subplot_args) { grm_args_t **current_series; - error_t error; - char *kind, *orientation; + err_t error; + const char *kind, *orientation; - kind = "line"; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); args_values(subplot_args, "orientation", "s", &orientation); @@ -2041,7 +2039,7 @@ error_t plot_line(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_step(grm_args_t *subplot_args) +err_t plot_step(grm_args_t *subplot_args) { /* * Parameters: @@ -2057,7 +2055,7 @@ error_t plot_step(grm_args_t *subplot_args) double xmin, xmax, ymin, ymax; double *y = NULL, *xi = NULL; int is_vertical; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); @@ -2083,23 +2081,24 @@ error_t plot_step(grm_args_t *subplot_args) args_values(subplot_args, "_zlim", "dd", &c_min, &c_max); args_first_value(*current_series, "z", "D", &plot, &n); - y = malloc((is_vertical ? y_length : x_length) * sizeof(double)); + y = static_cast(malloc((is_vertical ? y_length : x_length) * sizeof(double))); cleanup_and_set_error_if(y == NULL, ERROR_MALLOC); - xi = malloc((is_vertical ? y_length : x_length) * sizeof(double)); + xi = static_cast(malloc((is_vertical ? y_length : x_length) * sizeof(double))); cleanup_and_set_error_if(xi == NULL, ERROR_MALLOC); for (i = 0; i < (is_vertical ? y_length : x_length); i++) { if (is_vertical) { y[(is_vertical ? y_length : x_length) - i - 1] = - isnan(plot[xind + i * x_length]) ? 0 : plot[xind + i * x_length]; - y_max = max(y_max, y[(is_vertical ? y_length : x_length) - i - 1]); + grm_isnan(plot[xind + i * x_length]) ? 0 : plot[xind + i * x_length]; + y_max = grm_max(y_max, y[(is_vertical ? y_length : x_length) - i - 1]); } else { - y[i] = isnan(plot[x_length * (y_length - 1 - yind) + i]) ? 0 - : plot[x_length * (y_length - 1 - yind) + i]; - y_max = max(y_max, y[i]); + y[i] = grm_isnan(plot[x_length * (y_length - 1 - yind) + i]) + ? 0 + : plot[x_length * (y_length - 1 - yind) + i]; + y_max = grm_max(y_max, y[i]); } } for (i = 0; i < (is_vertical ? y_length : x_length); i++) @@ -2123,9 +2122,9 @@ error_t plot_step(grm_args_t *subplot_args) double x_pos, y_pos; unsigned int len = is_vertical ? y_length : x_length; - x_step_boundaries = calloc(2 * len, sizeof(double)); + x_step_boundaries = static_cast(calloc(2 * len, sizeof(double))); cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); - y_step_values = calloc(2 * len, sizeof(double)); + y_step_values = static_cast(calloc(2 * len, sizeof(double))); cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); x_step_boundaries[0] = is_vertical ? ymin : xmin; for (i = 2; i < 2 * len; i += 2) @@ -2163,9 +2162,9 @@ error_t plot_step(grm_args_t *subplot_args) } else if (strcmp(where, "pre") == 0) { - x_step_boundaries = calloc(2 * x_length - 1, sizeof(double)); + x_step_boundaries = static_cast(calloc(2 * x_length - 1, sizeof(double))); cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); - y_step_values = calloc(2 * x_length - 1, sizeof(double)); + y_step_values = static_cast(calloc(2 * x_length - 1, sizeof(double))); cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); x_step_boundaries[0] = x[0]; for (i = 1; i < 2 * x_length - 2; i += 2) @@ -2189,9 +2188,9 @@ error_t plot_step(grm_args_t *subplot_args) } else if (strcmp(where, "post") == 0) { - x_step_boundaries = calloc(2 * x_length - 1, sizeof(double)); + x_step_boundaries = static_cast(calloc(2 * x_length - 1, sizeof(double))); cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); - y_step_values = calloc(2 * x_length - 1, sizeof(double)); + y_step_values = static_cast(calloc(2 * x_length - 1, sizeof(double))); cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); for (i = 0; i < 2 * x_length - 2; i += 2) { @@ -2215,9 +2214,9 @@ error_t plot_step(grm_args_t *subplot_args) } else if (strcmp(where, "mid") == 0) { - x_step_boundaries = calloc(2 * x_length, sizeof(double)); + x_step_boundaries = static_cast(calloc(2 * x_length, sizeof(double))); cleanup_and_set_error_if(x_step_boundaries == NULL, ERROR_MALLOC); - y_step_values = calloc(2 * x_length, sizeof(double)); + y_step_values = static_cast(calloc(2 * x_length, sizeof(double))); cleanup_and_set_error_if(y_step_values == NULL, ERROR_MALLOC); x_step_boundaries[0] = x[0]; for (i = 1; i < 2 * x_length - 2; i += 2) @@ -2274,7 +2273,7 @@ error_t plot_step(grm_args_t *subplot_args) return error; } -error_t plot_scatter(grm_args_t *subplot_args) +err_t plot_scatter(grm_args_t *subplot_args) { /* * Parameters: @@ -2285,7 +2284,7 @@ error_t plot_scatter(grm_args_t *subplot_args) * optional `markertype` as integer (see: [Marker types](https://gr-framework.org/markertypes.html?highlight=marker)) */ grm_args_t **current_series; - error_t error; + err_t error; char *kind; int *previous_marker_type = plot_scatter_markertypes; args_values(subplot_args, "series", "A", ¤t_series); @@ -2379,10 +2378,10 @@ error_t plot_scatter(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_quiver(grm_args_t *subplot_args) +err_t plot_quiver(grm_args_t *subplot_args) { grm_args_t **current_series; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "A", ¤t_series); while (*current_series != NULL) @@ -2405,7 +2404,7 @@ error_t plot_quiver(grm_args_t *subplot_args) return error; } -error_t plot_stem(grm_args_t *subplot_args) +err_t plot_stem(grm_args_t *subplot_args) { const double *window; double base_line_y[2] = {0.0, 0.0}; @@ -2440,14 +2439,14 @@ error_t plot_stem(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_hist(grm_args_t *subplot_args) +err_t plot_hist(grm_args_t *subplot_args) { char *kind; grm_args_t **current_series; double *bar_centers = NULL; int bar_color_index = 989, i, xind, yind; double bar_color_rgb[3] = {-1}; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "kind", "s", &kind); args_values(subplot_args, "series", "A", ¤t_series); @@ -2534,7 +2533,7 @@ error_t plot_hist(grm_args_t *subplot_args) } if (grm_args_contains(*current_series, "error")) { - bar_centers = malloc(num_bins * sizeof(double)); + bar_centers = static_cast(malloc(num_bins * sizeof(double))); cleanup_and_set_error_if(bar_centers == NULL, ERROR_MALLOC); linspace(x_min + 0.5 * bar_width, x_max - 0.5 * bar_width, num_bins, bar_centers); error = plot_draw_errorbars(*current_series, bar_centers, num_bins, bins, kind); @@ -2551,7 +2550,7 @@ error_t plot_hist(grm_args_t *subplot_args) return error; } -error_t plot_barplot(grm_args_t *subplot_args) +err_t plot_barplot(grm_args_t *subplot_args) { grm_args_t **current_series; grm_args_t **inner_series; @@ -2584,7 +2583,7 @@ error_t plot_barplot(grm_args_t *subplot_args) int change_edge_color = 0; int change_edge_width = 0; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; double *y_lightness = NULL; gr_settextalign(2, 3); @@ -2615,14 +2614,14 @@ error_t plot_barplot(grm_args_t *subplot_args) ERROR_PLOT_MISSING_DATA); y_length = inner_series_length; } - fixed_y_length = max(y_length, fixed_y_length); + fixed_y_length = grm_max(y_length, fixed_y_length); ++current_series; } /* ind_bar_color */ if (args_values(subplot_args, "ind_bar_color", "A", &ind_bar_color)) { - pos_ind_bar_color = malloc(3 * fixed_y_length * sizeof(double)); + pos_ind_bar_color = static_cast(malloc(3 * fixed_y_length * sizeof(double))); cleanup_and_set_error_if(pos_ind_bar_color == NULL, ERROR_MALLOC); change_bar_color = 1; for (i = 0; i < fixed_y_length; ++i) @@ -2670,7 +2669,7 @@ error_t plot_barplot(grm_args_t *subplot_args) /* ind_edge_color */ if (args_values(subplot_args, "ind_edge_color", "A", &ind_edge_color)) { - pos_ind_edge_color = malloc(3 * fixed_y_length * sizeof(double)); + pos_ind_edge_color = static_cast(malloc(3 * fixed_y_length * sizeof(double))); cleanup_and_set_error_if(pos_ind_edge_color == NULL, ERROR_MALLOC); change_edge_color = 1; for (i = 0; i < fixed_y_length; ++i) @@ -2718,7 +2717,7 @@ error_t plot_barplot(grm_args_t *subplot_args) /* ind_edge_width */ if (args_values(subplot_args, "ind_edge_width", "A", &ind_edge_width)) { - pos_ind_edge_width = malloc(sizeof(double) * fixed_y_length); + pos_ind_edge_width = static_cast(malloc(sizeof(double) * fixed_y_length)); cleanup_and_set_error_if(pos_ind_edge_width == NULL, ERROR_MALLOC); for (i = 0; i < fixed_y_length; ++i) { @@ -2821,7 +2820,7 @@ error_t plot_barplot(grm_args_t *subplot_args) } if (ylabels != NULL) { - y_lightness = (double *)malloc(sizeof(double) * y_lightness_to_get); + y_lightness = static_cast(malloc(sizeof(double) * y_lightness_to_get)); use_y_notations_from_inner_series = 0; } @@ -3096,7 +3095,7 @@ error_t plot_barplot(grm_args_t *subplot_args) args_first_value(inner_series[inner_series_index], "ylabels", "nS", &ylabels, &ylabels_length); ylabels_left = ylabels_length; y_lightness_to_get = ylabels_length; - y_lightness = (double *)malloc(sizeof(double) * y_lightness_to_get); + y_lightness = static_cast(malloc(sizeof(double) * y_lightness_to_get)); } for (i = 0; i < y_length; i++) { @@ -3292,7 +3291,7 @@ error_t plot_barplot(grm_args_t *subplot_args) return error; } -error_t plot_contour(grm_args_t *subplot_args) +err_t plot_contour(grm_args_t *subplot_args) { double z_min, z_max; int num_levels; @@ -3300,13 +3299,13 @@ error_t plot_contour(grm_args_t *subplot_args) double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "_zlim", "dd", &z_min, &z_max); gr_setprojectiontype(0); gr_setspace(z_min, z_max, 0, 90); args_values(subplot_args, "levels", "i", &num_levels); - h = malloc(num_levels * sizeof(double)); + h = static_cast(malloc(num_levels * sizeof(double))); if (h == NULL) { debug_print_malloc_error(); @@ -3325,9 +3324,9 @@ error_t plot_contour(grm_args_t *subplot_args) { if (gridit_x == NULL) { - gridit_x = malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double)); - gridit_y = malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double)); - gridit_z = malloc(PLOT_CONTOUR_GRIDIT_N * PLOT_CONTOUR_GRIDIT_N * sizeof(double)); + gridit_x = static_cast(malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double))); + gridit_y = static_cast(malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double))); + gridit_z = static_cast(malloc(PLOT_CONTOUR_GRIDIT_N * PLOT_CONTOUR_GRIDIT_N * sizeof(double))); if (gridit_x == NULL || gridit_y == NULL || gridit_z == NULL) { debug_print_malloc_error(); @@ -3338,8 +3337,8 @@ error_t plot_contour(grm_args_t *subplot_args) gr_gridit(x_length, x, y, z, PLOT_CONTOUR_GRIDIT_N, PLOT_CONTOUR_GRIDIT_N, gridit_x, gridit_y, gridit_z); for (i = 0; i < PLOT_CONTOUR_GRIDIT_N * PLOT_CONTOUR_GRIDIT_N; i++) { - z_min = min(gridit_z[i], z_min); - z_max = max(gridit_z[i], z_max); + z_min = grm_min(gridit_z[i], z_min); + z_max = grm_max(gridit_z[i], z_max); } for (i = 0; i < num_levels; ++i) { @@ -3376,7 +3375,7 @@ error_t plot_contour(grm_args_t *subplot_args) return error; } -error_t plot_contourf(grm_args_t *subplot_args) +err_t plot_contourf(grm_args_t *subplot_args) { double z_min, z_max; int num_levels, scale; @@ -3384,13 +3383,13 @@ error_t plot_contourf(grm_args_t *subplot_args) double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "_zlim", "dd", &z_min, &z_max); gr_setprojectiontype(0); gr_setspace(z_min, z_max, 0, 90); args_values(subplot_args, "levels", "i", &num_levels); - h = malloc(num_levels * sizeof(double)); + h = static_cast(malloc(num_levels * sizeof(double))); if (h == NULL) { debug_print_malloc_error(); @@ -3416,9 +3415,9 @@ error_t plot_contourf(grm_args_t *subplot_args) { if (gridit_x == NULL) { - gridit_x = malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double)); - gridit_y = malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double)); - gridit_z = malloc(PLOT_CONTOUR_GRIDIT_N * PLOT_CONTOUR_GRIDIT_N * sizeof(double)); + gridit_x = static_cast(malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double))); + gridit_y = static_cast(malloc(PLOT_CONTOUR_GRIDIT_N * sizeof(double))); + gridit_z = static_cast(malloc(PLOT_CONTOUR_GRIDIT_N * PLOT_CONTOUR_GRIDIT_N * sizeof(double))); if (gridit_x == NULL || gridit_y == NULL || gridit_z == NULL) { debug_print_malloc_error(); @@ -3429,8 +3428,8 @@ error_t plot_contourf(grm_args_t *subplot_args) gr_gridit(x_length, x, y, z, PLOT_CONTOUR_GRIDIT_N, PLOT_CONTOUR_GRIDIT_N, gridit_x, gridit_y, gridit_z); for (i = 0; i < PLOT_CONTOUR_GRIDIT_N * PLOT_CONTOUR_GRIDIT_N; i++) { - z_min = min(gridit_z[i], z_min); - z_max = max(gridit_z[i], z_max); + z_min = grm_min(gridit_z[i], z_min); + z_max = grm_max(gridit_z[i], z_max); } for (i = 0; i < num_levels; ++i) { @@ -3463,7 +3462,7 @@ error_t plot_contourf(grm_args_t *subplot_args) return error; } -error_t plot_hexbin(grm_args_t *subplot_args) +err_t plot_hexbin(grm_args_t *subplot_args) { grm_args_t **current_series; @@ -3490,14 +3489,14 @@ error_t plot_hexbin(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_heatmap(grm_args_t *subplot_args) +err_t plot_heatmap(grm_args_t *subplot_args) { const char *kind = NULL; grm_args_t **current_series; int icmap[256], *rgba = NULL, *data = NULL, zlog = 0; unsigned int i, cols, rows, z_length; double *x = NULL, *y = NULL, *z, x_min, x_max, y_min, y_max, z_min, z_max, c_min, c_max, zv; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); @@ -3567,7 +3566,7 @@ error_t plot_heatmap(grm_args_t *subplot_args) gr_inqcolor(1000 + i, icmap + i); } - data = malloc(rows * cols * sizeof(int)); + data = static_cast(malloc(rows * cols * sizeof(int))); cleanup_and_set_error_if(data == NULL, ERROR_MALLOC); if (z_max > z_min) { @@ -3582,7 +3581,7 @@ error_t plot_heatmap(grm_args_t *subplot_args) zv = z[i]; } - if (zv > z_max || zv < z_min || isnan(zv)) + if (zv > z_max || zv < z_min || grm_isnan(zv)) { data[i] = -1; } @@ -3607,7 +3606,7 @@ error_t plot_heatmap(grm_args_t *subplot_args) data[i] = 0; } } - rgba = malloc(rows * cols * sizeof(int)); + rgba = static_cast(malloc(rows * cols * sizeof(int))); cleanup_and_set_error_if(rgba == NULL, ERROR_MALLOC); if (is_uniform_heatmap) { @@ -3660,7 +3659,7 @@ error_t plot_heatmap(grm_args_t *subplot_args) return error; } -error_t plot_marginalheatmap(grm_args_t *subplot_args) +err_t plot_marginalheatmap(grm_args_t *subplot_args) { const double *viewport; double c_min, c_max; @@ -3671,7 +3670,7 @@ error_t plot_marginalheatmap(grm_args_t *subplot_args) double *bins = NULL; unsigned int num_bins_x = 0, num_bins_y = 0, n = 0; double *xi, *yi, *plot; - error_t error = NO_ERROR; + err_t error = NO_ERROR; plot_heatmap(subplot_args); @@ -3702,7 +3701,7 @@ error_t plot_marginalheatmap(grm_args_t *subplot_args) { unsigned int x_len = num_bins_x, y_len = num_bins_y; - bins = malloc(((k == 0) ? num_bins_y : num_bins_x) * sizeof(double)); + bins = static_cast(malloc(((k == 0) ? num_bins_y : num_bins_x) * sizeof(double))); cleanup_and_set_error_if(bins == NULL, ERROR_MALLOC); grm_args_push(subplot_args, "kind", "s", "hist"); @@ -3714,7 +3713,7 @@ error_t plot_marginalheatmap(grm_args_t *subplot_args) { for (j = 0; j < x_len; j++) { - value = (isnan(plot[(num_bins_y - 1 - i) * num_bins_x + j])) + value = (grm_isnan(plot[(num_bins_y - 1 - i) * num_bins_x + j])) ? 0 : plot[(num_bins_y - 1 - i) * num_bins_x + j]; if (strcmp(algorithm, "sum") == 0) @@ -3723,19 +3722,19 @@ error_t plot_marginalheatmap(grm_args_t *subplot_args) } else if (strcmp(algorithm, "max") == 0) { - bins[(k == 0) ? i : j] = max(bins[(k == 0) ? i : j], value); + bins[(k == 0) ? i : j] = grm_max(bins[(k == 0) ? i : j], value); } } if (k == 0) { - bin_max = max(bin_max, bins[i]); + bin_max = grm_max(bin_max, bins[i]); } } if (k == 1) { for (i = 0; i < x_len; i++) { - bin_max = max(bin_max, bins[i]); + bin_max = grm_max(bin_max, bins[i]); } } for (i = 0; i < ((k == 0) ? y_len : x_len); i++) @@ -3778,7 +3777,7 @@ error_t plot_marginalheatmap(grm_args_t *subplot_args) else { gr_setwindow(x_min, x_max, 0.0, c_max / 10); - gr_setviewport(viewport[0], viewport[1], viewport[3] + 0.02, min(viewport[3] + 0.12, 1)); + gr_setviewport(viewport[0], viewport[1], viewport[3] + 0.02, grm_min(viewport[3] + 0.12, 1)); grm_args_push(subplot_args, "orientation", "s", "horizontal"); } @@ -3802,11 +3801,11 @@ error_t plot_marginalheatmap(grm_args_t *subplot_args) return error; } -error_t plot_wireframe(grm_args_t *subplot_args) +err_t plot_wireframe(grm_args_t *subplot_args) { double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "A", ¤t_series); while (*current_series != NULL) @@ -3821,9 +3820,10 @@ error_t plot_wireframe(grm_args_t *subplot_args) { if (gridit_x == NULL) { - gridit_x = malloc(PLOT_WIREFRAME_GRIDIT_N * sizeof(double)); - gridit_y = malloc(PLOT_WIREFRAME_GRIDIT_N * sizeof(double)); - gridit_z = malloc(PLOT_WIREFRAME_GRIDIT_N * PLOT_WIREFRAME_GRIDIT_N * sizeof(double)); + gridit_x = static_cast(malloc(PLOT_WIREFRAME_GRIDIT_N * sizeof(double))); + gridit_y = static_cast(malloc(PLOT_WIREFRAME_GRIDIT_N * sizeof(double))); + gridit_z = + static_cast(malloc(PLOT_WIREFRAME_GRIDIT_N * PLOT_WIREFRAME_GRIDIT_N * sizeof(double))); if (gridit_x == NULL || gridit_y == NULL || gridit_z == NULL) { debug_print_malloc_error(); @@ -3856,11 +3856,11 @@ error_t plot_wireframe(grm_args_t *subplot_args) return error; } -error_t plot_surface(grm_args_t *subplot_args) +err_t plot_surface(grm_args_t *subplot_args) { double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "A", ¤t_series); while (*current_series != NULL) @@ -3875,9 +3875,9 @@ error_t plot_surface(grm_args_t *subplot_args) { if (gridit_x == NULL) { - gridit_x = malloc(PLOT_SURFACE_GRIDIT_N * sizeof(double)); - gridit_y = malloc(PLOT_SURFACE_GRIDIT_N * sizeof(double)); - gridit_z = malloc(PLOT_SURFACE_GRIDIT_N * PLOT_SURFACE_GRIDIT_N * sizeof(double)); + gridit_x = static_cast(malloc(PLOT_SURFACE_GRIDIT_N * sizeof(double))); + gridit_y = static_cast(malloc(PLOT_SURFACE_GRIDIT_N * sizeof(double))); + gridit_z = static_cast(malloc(PLOT_SURFACE_GRIDIT_N * PLOT_SURFACE_GRIDIT_N * sizeof(double))); if (gridit_x == NULL || gridit_y == NULL || gridit_z == NULL) { debug_print_malloc_error(); @@ -3911,7 +3911,7 @@ error_t plot_surface(grm_args_t *subplot_args) return error; } -error_t plot_plot3(grm_args_t *subplot_args) +err_t plot_plot3(grm_args_t *subplot_args) { grm_args_t **current_series; @@ -3932,7 +3932,7 @@ error_t plot_plot3(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_scatter3(grm_args_t *subplot_args) +err_t plot_scatter3(grm_args_t *subplot_args) { grm_args_t **current_series; double c_min, c_max; @@ -3978,7 +3978,7 @@ error_t plot_scatter3(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_imshow(grm_args_t *subplot_args) +err_t plot_imshow(grm_args_t *subplot_args) { grm_args_t **current_series; double *c_data; @@ -4002,7 +4002,7 @@ error_t plot_imshow(grm_args_t *subplot_args) rows = shape[0]; cols = shape[1]; - img_data = malloc(sizeof(int) * c_data_length); + img_data = static_cast(malloc(sizeof(int) * c_data_length)); if (img_data == NULL) { debug_print_malloc_error(); @@ -4015,14 +4015,14 @@ error_t plot_imshow(grm_args_t *subplot_args) for (j = 0; j < rows; ++j) for (i = 0; i < cols; ++i) { - img_data[k++] = 1000 + (int)round((1.0 * c_data[i * rows + j] - c_min) / (c_max - c_min) * 255); + img_data[k++] = 1000 + (int)grm_round((1.0 * c_data[i * rows + j] - c_min) / (c_max - c_min) * 255); } if (cols * (vp[3] - vp[2]) < rows * (vp[1] - vp[0])) { w = (double)cols / (double)rows * (vp[3] - vp[2]); - x_min = max(0.5 * (vp[0] + vp[1] - w), vp[0]); - x_max = min(0.5 * (vp[0] + vp[1] + w), vp[1]); + x_min = grm_max(0.5 * (vp[0] + vp[1] - w), vp[0]); + x_max = grm_min(0.5 * (vp[0] + vp[1] + w), vp[1]); y_min = vp[2]; y_max = vp[3]; } @@ -4031,8 +4031,8 @@ error_t plot_imshow(grm_args_t *subplot_args) h = (double)rows / (double)cols * (vp[1] - vp[0]); x_min = vp[0]; x_max = vp[1]; - y_min = max(0.5 * (vp[3] + vp[2] - h), vp[2]); - y_max = min(0.5 * (vp[3] + vp[2] + h), vp[3]); + y_min = grm_max(0.5 * (vp[3] + vp[2] - h), vp[2]); + y_max = grm_min(0.5 * (vp[3] + vp[2] + h), vp[3]); } gr_selntran(0); @@ -4076,7 +4076,7 @@ void gr3_mc_dtype_test_(void) } } -error_t plot_isosurface(grm_args_t *subplot_args) +err_t plot_isosurface(grm_args_t *subplot_args) { /* * Possible arguments to pass: @@ -4121,8 +4121,8 @@ error_t plot_isosurface(grm_args_t *subplot_args) y_max = viewport[3]; get_figure_size(NULL, &fig_width, &fig_height, NULL, NULL); - subplot_width = (int)(max(fig_width, fig_height) * (x_max - x_min)); - subplot_height = (int)(max(fig_width, fig_height) * (y_max - y_min)); + subplot_width = (int)(grm_max(fig_width, fig_height) * (x_max - x_min)); + subplot_height = (int)(grm_max(fig_width, fig_height) * (y_max - y_min)); logger((stderr, "viewport: (%lf, %lf, %lf, %lf)\n", x_min, x_max, y_min, y_max)); logger((stderr, "viewport ratio: %lf\n", (x_min - x_max) / (y_min - y_max))); @@ -4161,11 +4161,11 @@ error_t plot_isosurface(grm_args_t *subplot_args) { if (isfinite(orig_data[i])) { - if (isnan(c_min) || c_min > orig_data[i]) + if (grm_isnan(c_min) || c_min > orig_data[i]) { c_min = orig_data[i]; } - if (isnan(c_max) || c_max < orig_data[i]) + if (grm_isnan(c_max) || c_max < orig_data[i]) { c_max = orig_data[i]; } @@ -4177,7 +4177,7 @@ error_t plot_isosurface(grm_args_t *subplot_args) isovalue_int = (unsigned short)((isovalue - c_min) / (c_max - c_min) * USHRT_MAX); logger((stderr, "c_min %lf c_max %lf isovalue_int %hu\n ", c_min, c_max, isovalue_int)); - conv_data = malloc(sizeof(unsigned short) * data_length); + conv_data = static_cast(malloc(sizeof(unsigned short) * data_length)); if (conv_data == NULL) { debug_print_malloc_error(); @@ -4187,7 +4187,7 @@ error_t plot_isosurface(grm_args_t *subplot_args) for (i = 0; i < data_length; ++i) { - if (isnan(orig_data[i]) || orig_data[i] < c_min) + if (grm_isnan(orig_data[i]) || orig_data[i] < c_min) { conv_data[i] = 0; } @@ -4259,12 +4259,12 @@ error_t plot_isosurface(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_volume(grm_args_t *subplot_args) +err_t plot_volume(grm_args_t *subplot_args) { grm_args_t **current_series; const char *kind; double dlim[2] = {INFINITY, -INFINITY}; - error_t error; + err_t error; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); @@ -4327,8 +4327,8 @@ error_t plot_volume(grm_args_t *subplot_args) gr_setpicturesizeforvolume((int)width * device_pixel_ratio, (int)height * device_pixel_ratio); gr_volume(shape[0], shape[1], shape[2], (double *)c, algorithm, &dmin, &dmax); - dlim[0] = min(dlim[0], dmin); - dlim[1] = max(dlim[1], dmax); + dlim[0] = grm_min(dlim[0], dmin); + dlim[1] = grm_max(dlim[1], dmax); ++current_series; } @@ -4344,7 +4344,7 @@ error_t plot_volume(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_polar(grm_args_t *subplot_args) +err_t plot_polar(grm_args_t *subplot_args) { const double *window; double r_min, r_max, tick; @@ -4367,8 +4367,8 @@ error_t plot_polar(grm_args_t *subplot_args) return_error_if(!args_first_value(*current_series, "x", "D", &theta, &theta_length), ERROR_PLOT_MISSING_DATA); return_error_if(!args_first_value(*current_series, "y", "D", &rho, &rho_length), ERROR_PLOT_MISSING_DATA); return_error_if(rho_length != theta_length, ERROR_PLOT_COMPONENT_LENGTH_MISMATCH); - x = malloc(rho_length * sizeof(double)); - y = malloc(rho_length * sizeof(double)); + x = static_cast(malloc(rho_length * sizeof(double))); + y = static_cast(malloc(rho_length * sizeof(double))); if (x == NULL || y == NULL) { debug_print_malloc_error(); @@ -4459,7 +4459,7 @@ error_t plot_polar(grm_args_t *subplot_args) * The default value is 1. * * */ -error_t plot_polar_histogram(grm_args_t *subplot_args) +err_t plot_polar_histogram(grm_args_t *subplot_args) { unsigned int num_bins; double *classes = NULL; @@ -4474,7 +4474,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) double *liste2 = NULL; double *mlist = NULL; double *rectlist = NULL; - char *norm = NULL; + const char *norm = NULL; double bin_width = -1.0; double *bin_edges = NULL; unsigned int num_bin_edges; @@ -4510,7 +4510,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) int freeable_bin_widths = 0; int freeable_bin_edges = 0; int freeable_angles = 0; - error_t error = NO_ERROR; + err_t error = NO_ERROR; gr_inqresamplemethod(&resample); gr_setresamplemethod(0x2020202); @@ -4584,7 +4584,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) /* no bin_edges */ else if (num_bin_edges == 0) { - mlist = (double *)malloc(num_bins * 4 * sizeof(double)); + mlist = static_cast(malloc(num_bins * 4 * sizeof(double))); cleanup_and_set_error_if(mlist == NULL, ERROR_MALLOC); if (stairs != 0) { @@ -4593,7 +4593,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) } else { - rectlist = (double *)malloc(num_bins * sizeof(double)); + rectlist = static_cast(malloc(num_bins * sizeof(double))); cleanup_and_set_error_if(rectlist == NULL, ERROR_MALLOC); } } @@ -4605,7 +4605,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) else { /* TODO: Potential memory leak, s. `malloc` in line 3788 */ - mlist = (double *)malloc((num_bins + 1) * 4 * sizeof(double)); + mlist = static_cast(malloc((num_bins + 1) * 4 * sizeof(double))); cleanup_and_set_error_if(mlist == NULL, ERROR_MALLOC); if (rlim[0] > rlim[1]) { @@ -4666,10 +4666,10 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) double max_radius; - lineardata = (int *)calloc(image_size * image_size, sizeof(int)); + lineardata = static_cast(calloc(image_size * image_size, sizeof(int))); cleanup_and_set_error_if(lineardata == NULL, ERROR_MALLOC); - bin_counts = (int *)malloc(num_bins * sizeof(int)); + bin_counts = static_cast(malloc(num_bins * sizeof(int))); cleanup_and_set_error_if(bin_counts == NULL, ERROR_MALLOC); colormap = create_colormap(xcolormap, ycolormap, colormap_size); @@ -4677,7 +4677,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) if (num_bin_edges == 0) { - angles = (double *)malloc((num_bins + 1) * sizeof(double)); + angles = static_cast(malloc((num_bins + 1) * sizeof(double))); cleanup_and_set_error_if(angles == NULL, ERROR_MALLOC); freeable_angles = 1; linspace(0, M_PI * 2, num_bins + 1, angles); @@ -4760,14 +4760,13 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) norm_factor = bin_widths[q]; } - if ((round(radius * 100) / 100) <= - (round((count * 1.0 / norm_factor / max * center) * 100) / 100) && + if ((grm_round(radius * 100) / 100) <= + (grm_round((count * 1.0 / norm_factor / max * center) * 100) / 100) && radius <= r_max && radius > r_min) { - lineardata[y * image_size + x] = - colormap[(int)(radius / (center * pow(2, 0.5)) * (colormap_size - 1)) * - colormap_size + - max(min((int)(angle / (2 * M_PI) * colormap_size), colormap_size - 1), 0)]; + lineardata[y * image_size + x] = colormap + [(int)(radius / (center * pow(2, 0.5)) * (colormap_size - 1)) * colormap_size + + grm_max(grm_min((int)(angle / (2 * M_PI) * colormap_size), colormap_size - 1), 0)]; } } /* end angle check */ @@ -4795,9 +4794,9 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) { double *temp = NULL; double *temp2 = NULL; - temp = malloc(num_bin_edges * sizeof(double)); + temp = static_cast(malloc(num_bin_edges * sizeof(double))); cleanup_and_set_error_if(temp == NULL, ERROR_MALLOC); - temp2 = malloc(num_bins * sizeof(double)); + temp2 = static_cast(malloc(num_bins * sizeof(double))); cleanup_and_set_error_if(temp2 == NULL, ERROR_MALLOC); int u; for (u = 0; u < num_bin_edges; u++) @@ -4960,11 +4959,11 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) diff_angle = end_angle - start_angle; num_angle = (int)(diff_angle / (0.2 / convert)); - phi_array = (double *)malloc(num_angle * sizeof(double)); + phi_array = static_cast(malloc(num_angle * sizeof(double))); cleanup_and_set_error_if(phi_array == NULL, ERROR_MALLOC); linspace(start_angle, end_angle, num_angle, phi_array); - f1 = (double *)malloc((4 + 2 * num_angle) * sizeof(double)); + f1 = static_cast(malloc((4 + 2 * num_angle) * sizeof(double))); cleanup_and_set_error_if(f1 == NULL, ERROR_MALLOC); /* line_1_x[0] and [1]*/ f1[0] = r_min_list[0]; @@ -4984,7 +4983,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) free(arc_2_x); arc_2_x = NULL; - f2 = (double *)malloc((4 + 2 * num_angle) * sizeof(double)); + f2 = static_cast(malloc((4 + 2 * num_angle) * sizeof(double))); cleanup_and_set_error_if(f2 == NULL, ERROR_MALLOC); /* line_1_y[0] and [1] */ f2[0] = r_min_list[1]; @@ -5065,20 +5064,20 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) diff_angle = end_angle - start_angle; num_angle = (int)(diff_angle / (0.2 / convert)); - phi_array = (double *)malloc(num_angle * sizeof(double)); + phi_array = static_cast(malloc(num_angle * sizeof(double))); cleanup_and_set_error_if(phi_array == NULL, ERROR_MALLOC); linspace(start_angle, end_angle, num_angle, phi_array); - f1 = (double *)malloc((4 + 2 * num_angle) * sizeof(double)); + f1 = static_cast(malloc((4 + 2 * num_angle) * sizeof(double))); cleanup_and_set_error_if(f1 == NULL, ERROR_MALLOC); /* line_1_x[0] and [1]*/ f1[0] = cos(bin_edges[x]) * r_min; - f1[1] = min(rect, r_max) * cos(bin_edges[x]); + f1[1] = grm_min(rect, r_max) * cos(bin_edges[x]); /*arc_1_x */ listcomprehension(r, cos, phi_array, num_angle, 2, f1); /* reversed line_2_x [0] and [1] */ f1[2 + num_angle + 1] = cos(bin_edges[x + 1]) * r_min; - f1[2 + num_angle] = min(rect, r_max) * cos(bin_edges[x + 1]); + f1[2 + num_angle] = grm_min(rect, r_max) * cos(bin_edges[x + 1]); /* reversed arc_2_x */ arc_2_x = listcomprehension(r_min, cos, phi_array, num_angle, 0, NULL); cleanup_and_set_error_if(arc_2_x == NULL, ERROR_MALLOC); @@ -5089,16 +5088,16 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) free(arc_2_x); arc_2_x = NULL; - f2 = (double *)malloc((4 + 2 * num_angle) * sizeof(double)); + f2 = static_cast(malloc((4 + 2 * num_angle) * sizeof(double))); cleanup_and_set_error_if(f2 == NULL, ERROR_MALLOC); /* line_1_y[0] and [1] */ f2[0] = r_min * sin(bin_edges[x]); - f2[1] = min(rect, r_max) * sin(bin_edges[x]); + f2[1] = grm_min(rect, r_max) * sin(bin_edges[x]); /*arc_1_y */ listcomprehension(r, sin, phi_array, num_angle, 2, f2); /* reversed line_2_y [0] and [1] */ f2[2 + num_angle + 1] = r_min * sin(bin_edges[x + 1]); - f2[2 + num_angle] = min(rect, r_max) * sin(bin_edges[x + 1]); + f2[2 + num_angle] = grm_min(rect, r_max) * sin(bin_edges[x + 1]); /* reversed arc_2_y */ arc_2_y = listcomprehension(r_min, sin, phi_array, num_angle, 0, NULL); cleanup_and_set_error_if(arc_2_y == NULL, ERROR_MALLOC); @@ -5183,8 +5182,8 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) if (rect > r_min) { - gr_drawarc(-min(rect, r_max), min(rect, r_max), -min(rect, r_max), min(rect, r_max), - x * (360.0 / num_bins), (x + 1) * 360.0 / num_bins); + gr_drawarc(-grm_min(rect, r_max), grm_min(rect, r_max), -grm_min(rect, r_max), + grm_min(rect, r_max), x * (360.0 / num_bins), (x + 1) * 360.0 / num_bins); gr_drawarc(-r_min, r_min, -r_min, r_min, x * (360.0 / num_bins), (x + 1) * (360.0 / num_bins)); @@ -5217,8 +5216,8 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) if (rect > r_min) { - gr_drawarc(-min(rect, r_max), min(rect, r_max), -min(rect, r_max), min(rect, r_max), - bin_edges[x] * convert, bin_edges[x + 1] * convert); + gr_drawarc(-grm_min(rect, r_max), grm_min(rect, r_max), -grm_min(rect, r_max), + grm_min(rect, r_max), bin_edges[x] * convert, bin_edges[x + 1] * convert); gr_drawarc(-r_min, r_min, -r_min, r_min, bin_edges[x] * convert, bin_edges[x + 1] * convert); } @@ -5302,10 +5301,10 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) gr_polyline(2, line_x, line_y); } } - line_x[0] = mlist[(num_bins - 1) * 4 + 2] = max(mlist[(num_bins - 1) * 4 + 2], r_min * cos(0)); - line_y[0] = mlist[(num_bins - 1) * 4 + 3] = max(mlist[(num_bins - 1) * 4 + 3], r_min * sin(0)); - line_x[1] = mlist[0] = max(mlist[0], r_min * cos(0)); - line_y[1] = mlist[1] = max(mlist[1], r_min * sin(0)); + line_x[0] = mlist[(num_bins - 1) * 4 + 2] = grm_max(mlist[(num_bins - 1) * 4 + 2], r_min * cos(0)); + line_y[0] = mlist[(num_bins - 1) * 4 + 3] = grm_max(mlist[(num_bins - 1) * 4 + 3], r_min * sin(0)); + line_x[1] = mlist[0] = grm_max(mlist[0], r_min * cos(0)); + line_y[1] = mlist[1] = grm_max(mlist[1], r_min * sin(0)); gr_polyline(2, line_x, line_y); } @@ -5353,8 +5352,8 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) /* stairs with bin_edges and rlim */ else if (rectlist != NULL && rlim != NULL) { - double startx = max(rectlist[0] * cos(bin_edges[0]), r_min * cos(bin_edges[0])); - double starty = max(rectlist[0] * sin(bin_edges[0]), r_min * sin(bin_edges[0])); + double startx = grm_max(rectlist[0] * cos(bin_edges[0]), r_min * cos(bin_edges[0])); + double starty = grm_max(rectlist[0] * sin(bin_edges[0]), r_min * sin(bin_edges[0])); double line_x[2]; double line_y[2]; @@ -5445,7 +5444,7 @@ error_t plot_polar_histogram(grm_args_t *subplot_args) return error; } -error_t plot_pie(grm_args_t *subplot_args) +err_t plot_pie(grm_args_t *subplot_args) { grm_args_t *series; double *x; @@ -5459,7 +5458,7 @@ error_t plot_pie(grm_args_t *subplot_args) char text[80]; const char *title; unsigned int i; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "a", &series); /* series exists always */ @@ -5516,7 +5515,7 @@ error_t plot_pie(grm_args_t *subplot_args) return error; } -error_t plot_trisurf(grm_args_t *subplot_args) +err_t plot_trisurf(grm_args_t *subplot_args) { grm_args_t **current_series; @@ -5538,7 +5537,7 @@ error_t plot_trisurf(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_tricont(grm_args_t *subplot_args) +err_t plot_tricont(grm_args_t *subplot_args) { double z_min, z_max; double *levels; @@ -5548,7 +5547,7 @@ error_t plot_tricont(grm_args_t *subplot_args) args_values(subplot_args, "_zlim", "dd", &z_min, &z_max); args_values(subplot_args, "levels", "i", &num_levels); - levels = malloc(num_levels * sizeof(double)); + levels = static_cast(malloc(num_levels * sizeof(double))); if (levels == NULL) { debug_print_malloc_error(); @@ -5577,7 +5576,7 @@ error_t plot_tricont(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_shade(grm_args_t *subplot_args) +err_t plot_shade(grm_args_t *subplot_args) { grm_args_t **current_shader; const char *data_component_names[] = {"x", "y", NULL}; @@ -5612,11 +5611,11 @@ error_t plot_shade(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_raw(grm_args_t *plot_args) +err_t plot_raw(grm_args_t *plot_args) { const char *base64_data = NULL; char *graphics_data = NULL; - error_t error = NO_ERROR; + err_t error = NO_ERROR; cleanup_and_set_error_if(!args_values(plot_args, "raw", "s", &base64_data), ERROR_PLOT_MISSING_DATA); graphics_data = base64_decode(NULL, base64_data, NULL, &error); @@ -5636,7 +5635,7 @@ error_t plot_raw(grm_args_t *plot_args) /* ~~~~~~~~~~~~~~~~~~~~~~~~~ auxiliary drawing functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_draw_axes(grm_args_t *args, unsigned int pass) +err_t plot_draw_axes(grm_args_t *args, unsigned int pass) { const char *kind = NULL; const double *viewport, *vp; @@ -5677,7 +5676,7 @@ error_t plot_draw_axes(grm_args_t *args, unsigned int pass) ticksize = 0.0075 * diag; if (str_equals_any(kind, 6, "wireframe", "surface", "plot3", "scatter3", "trisurf", "volume")) { - charheight = max(0.024 * diag, 0.012); + charheight = grm_max(0.024 * diag, 0.012); gr_setcharheight(charheight); args_values(args, "ztick", "d", &z_tick); args_values(args, "zorg", "dd", &z_org_low, &z_org_high); @@ -5696,7 +5695,7 @@ error_t plot_draw_axes(grm_args_t *args, unsigned int pass) } else { - charheight = max(0.018 * diag, 0.012); + charheight = grm_max(0.018 * diag, 0.012); gr_setcharheight(charheight); if (str_equals_any(kind, 3, "heatmap", "shade", "marginalheatmap")) { @@ -5787,7 +5786,7 @@ error_t plot_draw_axes(grm_args_t *args, unsigned int pass) return NO_ERROR; } -error_t plot_draw_polar_axes(grm_args_t *args) +err_t plot_draw_polar_axes(grm_args_t *args) { const double *window, *viewport, *vp; double diag; @@ -5809,7 +5808,7 @@ error_t plot_draw_polar_axes(grm_args_t *args) args_values(args, "vp", "D", &vp); diag = sqrt((viewport[1] - viewport[0]) * (viewport[1] - viewport[0]) + (viewport[3] - viewport[2]) * (viewport[3] - viewport[2])); - charheight = max(0.018 * diag, 0.012); + charheight = grm_max(0.018 * diag, 0.012); args_values(args, "window", "D", &window); r_min = window[2]; @@ -5913,14 +5912,14 @@ error_t plot_draw_polar_axes(grm_args_t *args) gr_wctondc(x, y); if (phiflip == 0) { - snprintf(text_buffer, PLOT_POLAR_AXES_TEXT_BUFFER, "%d\xc2\xb0", (int)round(alpha)); + snprintf(text_buffer, PLOT_POLAR_AXES_TEXT_BUFFER, "%d\xc2\xb0", (int)grm_round(alpha)); } else { if (alpha == 0.0) snprintf(text_buffer, PLOT_POLAR_AXES_TEXT_BUFFER, "%d\xc2\xb0", 0); else - snprintf(text_buffer, PLOT_POLAR_AXES_TEXT_BUFFER, "%d\xc2\xb0", 330 - (int)round(alpha - interval)); + snprintf(text_buffer, PLOT_POLAR_AXES_TEXT_BUFFER, "%d\xc2\xb0", 330 - (int)grm_round(alpha - interval)); } gr_text(x[0], y[0], text_buffer); } @@ -5937,7 +5936,7 @@ error_t plot_draw_polar_axes(grm_args_t *args) return NO_ERROR; } -error_t plot_draw_legend(grm_args_t *subplot_args) +err_t plot_draw_legend(grm_args_t *subplot_args) { const char **labels, **current_label; unsigned int num_labels, num_series; @@ -6004,7 +6003,7 @@ error_t plot_draw_legend(grm_args_t *subplot_args) gr_setlinewidth(1); gr_drawrect(px - 0.08, px + w + 0.02, py + 0.03, py - h); i = 1; - gr_uselinespec(" "); + gr_uselinespec(const_cast(" ")); current_label = labels; while (*current_series != NULL) { @@ -6015,7 +6014,7 @@ error_t plot_draw_legend(grm_args_t *subplot_args) if (i <= num_labels) { gr_inqtext(0, 0, *(char **)current_label, tbx, tby); - dy = max((tby[2] - tby[0]) - 0.03, 0); + dy = grm_max((tby[2] - tby[0]) - 0.03, 0); py -= 0.5 * dy; } gr_savestate(); @@ -6055,7 +6054,7 @@ error_t plot_draw_legend(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_draw_pie_legend(grm_args_t *subplot_args) +err_t plot_draw_pie_legend(grm_args_t *subplot_args) { grm_args_t *series; const char **labels, **current_label; @@ -6077,7 +6076,7 @@ error_t plot_draw_pie_legend(grm_args_t *subplot_args) { gr_inqtext(0, 0, *(char **)current_label, tbx, tby); w += tbx[2] - tbx[0]; - h = max(h, tby[2] - tby[0]); + h = grm_max(h, tby[2] - tby[0]); } w += num_labels * 0.03 + (num_labels - 1) * 0.02; @@ -6092,7 +6091,7 @@ error_t plot_draw_pie_legend(grm_args_t *subplot_args) gr_setlinewidth(1); gr_drawrect(px - 0.02, px + w + 0.02, py - 0.5 * h - 0.02, py + 0.5 * h + 0.02); gr_settextalign(GKS_K_TEXT_HALIGN_LEFT, GKS_K_TEXT_VALIGN_HALF); - gr_uselinespec(" "); + gr_uselinespec(const_cast(" ")); set_next_color(series, "c", GR_COLOR_FILL); for (current_label = labels; *current_label != NULL; ++current_label) { @@ -6111,7 +6110,7 @@ error_t plot_draw_pie_legend(grm_args_t *subplot_args) return NO_ERROR; } -error_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int colors) +err_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int colors) { const double *viewport; double c_min, c_max; @@ -6119,20 +6118,19 @@ error_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int co double diag, charheight; int scale, flip, options; unsigned int i; - error_t error; + err_t error; gr_savestate(); args_values(subplot_args, "viewport", "D", &viewport); /* TODO: What to do, if there is a `_clim` and a `_zlim`? Merge both together? */ if (!args_values(subplot_args, "_clim", "dd", &c_min, &c_max)) { - error = args_values(subplot_args, "_zlim", "dd", &c_min, &c_max); - if (!error) + if (!args_values(subplot_args, "_zlim", "dd", &c_min, &c_max)) { - return error; + return ERROR_PLOT_MISSING_DATA; } } - data = malloc(colors * sizeof(int)); + data = static_cast(malloc(colors * sizeof(int))); if (data == NULL) { debug_print_malloc_error(); @@ -6163,7 +6161,7 @@ error_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int co gr_cellarray(0, 1, c_max, c_min, 1, colors, 1, 1, 1, colors, data); diag = sqrt((viewport[1] - viewport[0]) * (viewport[1] - viewport[0]) + (viewport[3] - viewport[2]) * (viewport[3] - viewport[2])); - charheight = max(0.016 * diag, 0.012); + charheight = grm_max(0.016 * diag, 0.012); gr_setcharheight(charheight); args_values(subplot_args, "scale", "i", &scale); if (scale & GR_OPTION_Z_LOG) @@ -6182,9 +6180,9 @@ error_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int co return NO_ERROR; } -error_t extract_multi_type_argument(grm_args_t *error_container, const char *key, unsigned int x_length, - unsigned int *downwards_length, unsigned int *upwards_length, double **downwards, - double **upwards, double *downwards_flt, double *upwards_flt) +err_t extract_multi_type_argument(grm_args_t *error_container, const char *key, unsigned int x_length, + unsigned int *downwards_length, unsigned int *upwards_length, double **downwards, + double **upwards, double *downwards_flt, double *upwards_flt) { arg_t *arg_ptr; args_value_iterator_t *value_it; @@ -6240,11 +6238,11 @@ error_t extract_multi_type_argument(grm_args_t *error_container, const char *key return NO_ERROR; } -error_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_length, double *y, char *kind) +err_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_length, double *y, const char *kind) { grm_args_t *error_container; arg_t *arg_ptr; - error_t error; + err_t error; double *absolute_upwards, *absolute_downwards, *relative_upwards, *relative_downwards; double absolute_upwards_flt, relative_upwards_flt, absolute_downwards_flt, relative_downwards_flt; @@ -6384,7 +6382,7 @@ double find_max_step(unsigned int n, const double *x) } for (i = 1; i < n; ++i) { - max_step = max(x[i] - x[i - 1], max_step); + max_step = grm_max(x[i] - x[i - 1], max_step); } return max_step; @@ -6409,7 +6407,7 @@ double *normalize(unsigned int n, const double *x) sum += x[i]; } - normalized_x = malloc(n * sizeof(double)); + normalized_x = static_cast(malloc(n * sizeof(double))); if (normalized_x == NULL) { debug_print_malloc_error(); @@ -6451,7 +6449,7 @@ unsigned int *normalize_int(unsigned int n, const double *x, unsigned int sum) sum_x += x[i]; } - normalized_x = malloc(n * sizeof(unsigned int)); + normalized_x = static_cast(malloc(n * sizeof(unsigned int))); if (normalized_x == NULL) { debug_print_malloc_error(); @@ -6503,7 +6501,7 @@ const char *next_fmt_key(const char *kind) if (kind != NULL) { - string_map_at(fmt_map, kind, (char **)&saved_fmt); + string_map_at(fmt_map, kind, static_cast(&saved_fmt)); } if (saved_fmt == NULL) { @@ -6680,7 +6678,7 @@ int get_figure_size(const grm_args_t *plot_args, int *pixel_width, int *pixel_he { for (i = 0; i < 2; ++i) { - pixel_size[i] = (int)round(tmp_size_d[i] * dpi[i]); + pixel_size[i] = (int)grm_round(tmp_size_d[i] * dpi[i]); metric_size[i] = tmp_size_d[i] / 0.0254; } } @@ -6690,7 +6688,7 @@ int get_figure_size(const grm_args_t *plot_args, int *pixel_width, int *pixel_he for (i = 0; i < 2; ++i) { - pixel_size[i] = (int)round(tmp_size_d[i]); + pixel_size[i] = (int)grm_round(tmp_size_d[i]); metric_size[i] = tmp_size_d[i] / dpm[i]; } } @@ -6735,7 +6733,7 @@ int get_figure_size(const grm_args_t *plot_args, int *pixel_width, int *pixel_he /* If no value is given, fall back to default value */ return 0; } - pixel_size[i] = (int)round(tmp_size_d[i]); + pixel_size[i] = (int)grm_round(tmp_size_d[i]); metric_size[i] = tmp_size_d[i] / dpm[i]; } } @@ -6779,7 +6777,7 @@ int get_focus_and_factor(const int x1, const int y1, const int x2, const int y2, int width, height, max_width_height; get_figure_size(NULL, &width, &height, NULL, NULL); - max_width_height = max(width, height); + max_width_height = grm_max(width, height); if (x1 <= x2) { @@ -6883,7 +6881,7 @@ grm_args_t *get_subplot_from_ndc_points(unsigned int n, const double *x, const d double *moivre(double r, int x, int n) { - double *result = (double *)malloc(2 * sizeof(double)); + double *result = static_cast(malloc(2 * sizeof(double))); if (result != NULL) { if (n != 0) @@ -6909,7 +6907,7 @@ double *listcomprehension(double factor, double (*pFunction)(double), double *li int i; if (result == NULL) { - result = (double *)malloc(num * sizeof(double)); + result = static_cast(malloc(num * sizeof(double))); if (result == NULL) { return NULL; @@ -6941,7 +6939,7 @@ int *create_colormap(int x, int y, int size) return NULL; } - colormap = malloc(size * size * sizeof(int)); + colormap = static_cast(malloc(size * size * sizeof(int))); if (colormap == NULL) { debug_print_malloc_error(); @@ -7017,12 +7015,12 @@ int *create_colormap(int x, int y, int size) /* * Calculates the classes for polar histogram * */ -error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) +err_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) { unsigned int num_bins; double *theta = NULL; unsigned int length; - char *norm; + const char *norm; double *classes = NULL; double interval; @@ -7042,7 +7040,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) int is_bin_counts; int *bin_counts = NULL; - double false = -1; + double false_ = -1; double *philim = NULL; unsigned int dummy; @@ -7052,7 +7050,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) grm_args_t **series; - error_t error = NO_ERROR; + err_t error = NO_ERROR; args_values(subplot_args, "series", "A", &series); @@ -7074,7 +7072,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) if (args_first_value(*series, "philim", "D", &philim, &dummy) == 0) { - philim = &false; + philim = &false_; } else { @@ -7107,14 +7105,14 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) { if (args_values(*series, "nbins", "i", &num_bins) == 0) { - num_bins = min(12, (int)(length * 1.0 / 2) - 1); + num_bins = grm_min(12, (int)(length * 1.0 / 2) - 1); grm_args_push(*series, "nbins", "i", num_bins); } else { if (num_bins <= 0 || num_bins > 200) { - num_bins = min(12, (int)(length * 1.0 / 2) - 1); + num_bins = grm_min(12, (int)(length * 1.0 / 2) - 1); grm_args_push(*series, "nbins", "i", num_bins); } } @@ -7122,7 +7120,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) num_bin_edges = 0; else { - bin_edges = bin_edges_buf = (double *)malloc((num_bins + 1) * sizeof(double)); + bin_edges = bin_edges_buf = static_cast(malloc((num_bins + 1) * sizeof(double))); cleanup_and_set_error_if(bin_edges == NULL, ERROR_MALLOC); linspace(philim[0], philim[1], num_bins + 1, bin_edges); num_bin_edges = num_bins + 1; @@ -7139,7 +7137,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) /* filter bin_edges */ int temp = 0; int i; - new_edges = malloc(num_bin_edges * sizeof(double)); + new_edges = static_cast(malloc(num_bin_edges * sizeof(double))); cleanup_and_set_error_if(new_edges == NULL, ERROR_MALLOC); for (i = 0; i < num_bin_edges; ++i) @@ -7173,7 +7171,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) { /* filter bin_edges */ int temp = 0; - new_edges = malloc(num_bin_edges * sizeof(double)); + new_edges = static_cast(malloc(num_bin_edges * sizeof(double))); cleanup_and_set_error_if(new_edges == NULL, ERROR_MALLOC); int i; @@ -7231,7 +7229,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) if (num_bin_edges > 0) { int i; - bin_widths = (double *)malloc((num_bins + 1) * sizeof(double)); + bin_widths = static_cast(malloc((num_bins + 1) * sizeof(double))); cleanup_and_set_error_if(bin_widths == NULL, ERROR_MALLOC); for (i = 1; i <= num_bin_edges - 1; ++i) @@ -7258,7 +7256,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) logger((stderr, "bin_width is not compatible with bin_edges\n")); cleanup_and_set_error(ERROR_PLOT_INCOMPATIBLE_ARGUMENTS); - bin_widths = (double *)malloc(num_bins * sizeof(double)); + bin_widths = static_cast(malloc(num_bins * sizeof(double))); cleanup_and_set_error_if(bin_widths == NULL, ERROR_MALLOC); for (i = 1; i <= num_bin_edges - 1; ++i) @@ -7294,7 +7292,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) } n = num_bins; } - bin_edges = bin_edges_buf = (double *)malloc((n + 1) * sizeof(double)); + bin_edges = bin_edges_buf = static_cast(malloc((n + 1) * sizeof(double))); cleanup_and_set_error_if(bin_edges == NULL, ERROR_MALLOC); linspace(philim[0], n * bin_width, n + 1, bin_edges); @@ -7324,7 +7322,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) } n = num_bins; } - bin_edges = bin_edges_buf = (double *)malloc((n + 1) * sizeof(double)); + bin_edges = bin_edges_buf = static_cast(malloc((n + 1) * sizeof(double))); cleanup_and_set_error_if(bin_edges == NULL, ERROR_MALLOC); linspace(0, n * bin_width, n + 1, bin_edges); @@ -7334,7 +7332,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) num_bins = n; grm_args_push(*series, "bin_edges", "nD", num_bin_edges, bin_edges); grm_args_push(*series, "bin_width", "d", bin_width); - bin_widths = malloc(num_bins * sizeof(double)); + bin_widths = static_cast(malloc(num_bins * sizeof(double))); cleanup_and_set_error_if(bin_widths == NULL, ERROR_MALLOC); for (temp = 0; temp < num_bins; ++temp) @@ -7390,7 +7388,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) } /* double classes[num_bins][total]; */ - classes = (double *)malloc((num_bins * total) * sizeof(double)); + classes = static_cast(malloc((num_bins * total) * sizeof(double))); cleanup_and_set_error_if(classes == NULL, ERROR_MALLOC); length = (int)temp_max_bc; @@ -7451,7 +7449,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) if (str_equals_any(norm, 4, "count", "pdf", "countdensity", "probability")) { /*double classes[num_bins][length];*/ - classes = (double *)malloc(num_bins * length * sizeof(double)); + classes = static_cast(malloc(num_bins * length * sizeof(double))); cleanup_and_set_error_if(classes == NULL, ERROR_MALLOC); p = classes; int i; @@ -7482,7 +7480,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) else if (str_equals_any(norm, 2, "cdf", "cumcount")) { /*double classes[num_bins][length];*/ - classes = (double *)malloc(num_bins * length * sizeof(double)); + classes = static_cast(malloc(num_bins * length * sizeof(double))); cleanup_and_set_error_if(classes == NULL, ERROR_MALLOC); int i; int prev; @@ -7544,7 +7542,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) int temp = 0; double bin_min = *bin_edges; double bin_max = bin_edges[num_bin_edges - 1]; - new_theta = (double *)malloc(length * sizeof(double)); + new_theta = static_cast(malloc(length * sizeof(double))); cleanup_and_set_error_if(new_theta == NULL, ERROR_MALLOC); for (filter = 0; filter < length; ++filter) { @@ -7562,7 +7560,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) { int a; /* double classes[num_bins][length]; */ - classes = (double *)malloc(num_bins * length * sizeof(double)); + classes = static_cast(malloc(num_bins * length * sizeof(double))); cleanup_and_set_error_if(classes == NULL, ERROR_MALLOC); p = classes; for (a = 0; a < (num_bins * length); ++a) @@ -7606,7 +7604,7 @@ error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) int c; int prev; int d; - classes = (double *)malloc(num_bins * length * sizeof(double)); + classes = static_cast(malloc(num_bins * length * sizeof(double))); cleanup_and_set_error_if(classes == NULL, ERROR_MALLOC); p = classes; for (c = 0; c < (num_bins * length); ++c) @@ -8127,3 +8125,4 @@ int grm_switch(unsigned int id) return 1; } +} diff --git a/lib/grm/src/grm/plot_int.h b/lib/grm/src/grm/plot_int.h index 49c32a294..6d91536b5 100644 --- a/lib/grm/src/grm/plot_int.h +++ b/lib/grm/src/grm/plot_int.h @@ -1,6 +1,10 @@ #ifndef GRM_PLOT_INT_H_INCLUDED #define GRM_PLOT_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include "args_int.h" @@ -95,7 +99,7 @@ extern const char *plot_clear_exclude_keys[]; /* ~~~~~~~~~~~~~~~~~~~~~~~~~ kind to func ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -typedef error_t (*plot_func_t)(grm_args_t *args); +typedef err_t (*plot_func_t)(grm_args_t *args); /* ~~~~~~~~~~~~~~~~~~~~~~~~~ options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -136,74 +140,74 @@ typedef enum /* ~~~~~~~~~~~~~~~~~~~~~~~~~ general ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_init_static_variables(void); +err_t plot_init_static_variables(void); /* ~~~~~~~~~~~~~~~~~~~~~~~~~ plot arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const char **hierarchy_name_ptr, - uint_map_t *hierarchy_to_id, int hold_always); -error_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, unsigned int next_hierarchy_level_max_id); -error_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr, - unsigned int next_hierarchy_level_max_id); +err_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const char **hierarchy_name_ptr, + uint_map_t *hierarchy_to_id, int hold_always); +err_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, unsigned int next_hierarchy_level_max_id); +err_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr, + unsigned int next_hierarchy_level_max_id); void plot_set_flag_defaults(void); void plot_set_attribute_defaults(grm_args_t *subplot_args); void plot_pre_plot(grm_args_t *plot_args); void plot_set_text_encoding(void); void plot_process_wswindow_wsviewport(grm_args_t *plot_args); -error_t plot_pre_subplot(grm_args_t *subplot_args); +err_t plot_pre_subplot(grm_args_t *subplot_args); void plot_process_colormap(grm_args_t *subplot_args); void plot_process_font(grm_args_t *subplot_args); void plot_process_resample_method(grm_args_t *subplot_args); void plot_process_viewport(grm_args_t *subplot_args); void plot_process_window(grm_args_t *subplot_args); -error_t plot_store_coordinate_ranges(grm_args_t *subplot_args); +err_t plot_store_coordinate_ranges(grm_args_t *subplot_args); void plot_post_plot(grm_args_t *plot_args); void plot_restore_text_encoding(void); void plot_post_subplot(grm_args_t *subplot_args); -error_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name_start_ptr, const char *key, - uint_map_t *hierarchy_to_id, const grm_args_t **found_args, - const char ***found_hierarchy_ptr); +err_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name_start_ptr, const char *key, + uint_map_t *hierarchy_to_id, const grm_args_t **found_args, + const char ***found_hierarchy_ptr); /* ~~~~~~~~~~~~~~~~~~~~~~~~~ plotting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_line(grm_args_t *subplot_args); -error_t plot_step(grm_args_t *subplot_args); -error_t plot_scatter(grm_args_t *subplot_args); -error_t plot_quiver(grm_args_t *subplot_args); -error_t plot_stem(grm_args_t *subplot_args); -error_t plot_hist(grm_args_t *subplot_args); -error_t plot_barplot(grm_args_t *subplot_args); -error_t plot_contour(grm_args_t *subplot_args); -error_t plot_contourf(grm_args_t *subplot_args); -error_t plot_hexbin(grm_args_t *subplot_args); -error_t plot_heatmap(grm_args_t *subplot_args); -error_t plot_marginalheatmap(grm_args_t *subplot_args); -error_t plot_wireframe(grm_args_t *subplot_args); -error_t plot_surface(grm_args_t *subplot_args); -error_t plot_plot3(grm_args_t *subplot_args); -error_t plot_scatter3(grm_args_t *subplot_args); -error_t plot_imshow(grm_args_t *subplot_args); -error_t plot_isosurface(grm_args_t *subplot_args); -error_t plot_volume(grm_args_t *subplot_args); -error_t plot_polar(grm_args_t *subplot_args); -error_t plot_polar_histogram(grm_args_t *subplot_args); -error_t plot_pie(grm_args_t *subplot_args); -error_t plot_trisurf(grm_args_t *subplot_args); -error_t plot_tricont(grm_args_t *subplot_args); -error_t plot_shade(grm_args_t *subplot_args); -error_t plot_raw(grm_args_t *subplot_args); +err_t plot_line(grm_args_t *subplot_args); +err_t plot_step(grm_args_t *subplot_args); +err_t plot_scatter(grm_args_t *subplot_args); +err_t plot_quiver(grm_args_t *subplot_args); +err_t plot_stem(grm_args_t *subplot_args); +err_t plot_hist(grm_args_t *subplot_args); +err_t plot_barplot(grm_args_t *subplot_args); +err_t plot_contour(grm_args_t *subplot_args); +err_t plot_contourf(grm_args_t *subplot_args); +err_t plot_hexbin(grm_args_t *subplot_args); +err_t plot_heatmap(grm_args_t *subplot_args); +err_t plot_marginalheatmap(grm_args_t *subplot_args); +err_t plot_wireframe(grm_args_t *subplot_args); +err_t plot_surface(grm_args_t *subplot_args); +err_t plot_plot3(grm_args_t *subplot_args); +err_t plot_scatter3(grm_args_t *subplot_args); +err_t plot_imshow(grm_args_t *subplot_args); +err_t plot_isosurface(grm_args_t *subplot_args); +err_t plot_volume(grm_args_t *subplot_args); +err_t plot_polar(grm_args_t *subplot_args); +err_t plot_polar_histogram(grm_args_t *subplot_args); +err_t plot_pie(grm_args_t *subplot_args); +err_t plot_trisurf(grm_args_t *subplot_args); +err_t plot_tricont(grm_args_t *subplot_args); +err_t plot_shade(grm_args_t *subplot_args); +err_t plot_raw(grm_args_t *subplot_args); /* ~~~~~~~~~~~~~~~~~~~~~~~~~ auxiliary drawing functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -error_t plot_draw_axes(grm_args_t *args, unsigned int pass); -error_t plot_draw_polar_axes(grm_args_t *args); -error_t plot_draw_legend(grm_args_t *args); -error_t plot_draw_pie_legend(grm_args_t *args); -error_t plot_draw_colorbar(grm_args_t *args, double off, unsigned int colors); -error_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_length, double *y, char *kind); +err_t plot_draw_axes(grm_args_t *args, unsigned int pass); +err_t plot_draw_polar_axes(grm_args_t *args); +err_t plot_draw_legend(grm_args_t *args); +err_t plot_draw_pie_legend(grm_args_t *args); +err_t plot_draw_colorbar(grm_args_t *args, double off, unsigned int colors); +err_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_length, double *y, const char *kind); /* ~~~~~~~~~~~~~~~~~~~~~~~~~ util ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -225,11 +229,14 @@ double *moivre(double r, int x, int n); double *listcomprehension(double count, double (*pFunction)(double), double *pDouble, int num, int start, double *result); int *create_colormap(int x, int y, int size); -error_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max); +err_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max); double get_lightness_from_rbg(double r, double g, double b); void set_text_color_for_background(double r, double g, double b); void draw_xticklabel(double x1, double x2, const char *label, double available_width); void set_next_color(const grm_args_t *args, const char *key, gr_color_type_t color_type); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_PLOT_INT_H_INCLUDED */ diff --git a/lib/grm/src/grm/util.c b/lib/grm/src/grm/util.c index 61c732d2b..b13c45213 100644 --- a/lib/grm/src/grm/util.c +++ b/lib/grm/src/grm/util.c @@ -36,8 +36,8 @@ void bin_data(unsigned int n, double *x, unsigned int num_bins, double *bins, do for (i = 0; i < n; ++i) { - x_min = min(x[i], x_min); - x_max = max(x[i], x_max); + x_min = grm_min(x[i], x_min); + x_max = grm_max(x[i], x_max); } memset(bins, 0, num_bins * sizeof(double)); for (i = 0; i < n; ++i) diff --git a/lib/grm/src/grm/util_int.h b/lib/grm/src/grm/util_int.h index e80c7e3b3..5e83abe51 100644 --- a/lib/grm/src/grm/util_int.h +++ b/lib/grm/src/grm/util_int.h @@ -1,6 +1,10 @@ #ifndef GRM_UTIL_INT_H_INCLUDED #define GRM_UTIL_INT_H_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + /* ######################### includes ############################################################################### */ #include @@ -22,29 +26,15 @@ #define array_size(a) ((sizeof(a) / sizeof(*(a)))) #endif -#ifndef isnan -#define isnan(x) ((x) != (x)) -#endif - #ifndef INFINITY #define INFINITY (1.0 / 0.0) #endif -#ifndef min -#define min(x, y) (((x) < (y)) ? (x) : (y)) -#endif - -#ifndef max -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#endif - -#ifndef round -#define round(x) (((x) < 0) ? ceil((x)-.5) : floor((x) + .5)) -#endif - -#ifndef static_assert /* defined in C11 */ -#define static_assert(cond, message) ((void)sizeof(char[(cond) ? 1 : -1])) -#endif +#define grm_isnan(x) ((x) != (x)) +#define grm_min(x, y) (((x) < (y)) ? (x) : (y)) +#define grm_max(x, y) (((x) > (y)) ? (x) : (y)) +#define grm_round(x) (((x) < 0) ? ceil((x)-.5) : floor((x) + .5)) +#define grm_static_assert(cond, message) ((void)sizeof(char[(cond) ? 1 : -1])) /* test macros which can be used like `assert` */ #define return_error_if(condition, error_value) \ @@ -142,4 +132,7 @@ int is_homogenous_string_of_char(const char *str, char c); const char *private_name(const char *public_name); unsigned long next_or_equal_power2(unsigned long num); +#ifdef __cplusplus +} +#endif #endif /* ifndef GRM_UTIL_INT_H_INCLUDED */ diff --git a/lib/grm/test/public_api/grm/CMakeLists.txt b/lib/grm/test/public_api/grm/CMakeLists.txt index a8ca72ec2..cc08413d5 100644 --- a/lib/grm/test/public_api/grm/CMakeLists.txt +++ b/lib/grm/test/public_api/grm/CMakeLists.txt @@ -43,6 +43,12 @@ foreach(executable_source ${EXECUTABLE_SOURCES}) target_link_libraries("${PROJECT_NAME}_${executable}" PRIVATE m) target_compile_options("${PROJECT_NAME}_${executable}" PRIVATE ${COMPILER_OPTION_ERROR_IMPLICIT}) set_target_properties( - "${PROJECT_NAME}_${executable}" PROPERTIES C_STANDARD 90 C_STANDARD_REQUIRED ON C_EXTENSIONS OFF + "${PROJECT_NAME}_${executable}" + PROPERTIES C_STANDARD 90 + C_STANDARD_REQUIRED ON + C_EXTENSIONS OFF + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF ) endforeach() diff --git a/lib/grm/test/public_api/marginalheatmap.c b/lib/grm/test/public_api/grm/marginalheatmap.c similarity index 100% rename from lib/grm/test/public_api/marginalheatmap.c rename to lib/grm/test/public_api/grm/marginalheatmap.c From 975b61da2e4ae20342f475ab64a83600dd227d2c Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 22 Apr 2022 11:54:48 +0200 Subject: [PATCH 09/26] [GRM] Make the code compatible with MSVC (again) Activate the permissive mode and rename `NO_ERROR` to `ERROR_NONE` to avoid collisions with the Windows API. --- CMakeLists.txt | 3 + lib/grm/src/grm/args.c | 16 +-- lib/grm/src/grm/base64.c | 12 +- lib/grm/src/grm/datatype/string_list.c | 4 +- lib/grm/src/grm/datatype/template/list_int.h | 12 +- lib/grm/src/grm/dynamic_args_array.c | 2 +- lib/grm/src/grm/error.c | 2 +- lib/grm/src/grm/error_int.h | 6 +- lib/grm/src/grm/event.c | 24 ++-- lib/grm/src/grm/json.c | 138 +++++++++---------- lib/grm/src/grm/memwriter.c | 12 +- lib/grm/src/grm/net.c | 78 +++++------ lib/grm/src/grm/plot.cxx | 126 ++++++++--------- lib/grm/src/grm/util_int.h | 4 +- 14 files changed, 220 insertions(+), 219 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9722e84f3..d1a7f2b3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -500,6 +500,9 @@ foreach(LIBRARY grm_static grm_shared grm_shared_internal) $ $ ) target_compile_options(${LIBRARY} PRIVATE ${COMPILER_OPTION_ERROR_IMPLICIT}) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_options(${LIBRARY} PRIVATE /permissive-) + endif() set_target_properties( ${LIBRARY} PROPERTIES C_STANDARD 90 diff --git a/lib/grm/src/grm/args.c b/lib/grm/src/grm/args.c index fd98b54c8..a0a63f7bc 100644 --- a/lib/grm/src/grm/args.c +++ b/lib/grm/src/grm/args.c @@ -1060,7 +1060,7 @@ err_t arg_increase_array(arg_t *arg, size_t increment) *current_size_ptr = new_size; *current_buffer_ptr = new_buffer; - return NO_ERROR; + return ERROR_NONE; } int(arg_first_value)(const arg_t *arg, const char *first_value_format, void *first_value, unsigned int *array_length) @@ -1533,7 +1533,7 @@ err_t args_push_common(grm_args_t *args, const char *key, const char *value_form ++(args->count); } - return NO_ERROR; + return ERROR_NONE; } err_t args_push_vl(grm_args_t *args, const char *key, const char *value_format, va_list *vl) @@ -1544,7 +1544,7 @@ err_t args_push_vl(grm_args_t *args, const char *key, const char *value_format, err_t args_push_arg(grm_args_t *args, arg_t *arg) { args_node_t *args_node = NULL, *previous_node_by_keyword = NULL; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; ++(arg->priv->reference_count); args_node = malloc(sizeof(args_node_t)); @@ -1590,7 +1590,7 @@ err_t args_push_arg(grm_args_t *args, arg_t *arg) ++(args->count); } - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (args_node != NULL) @@ -1614,7 +1614,7 @@ err_t args_merge(grm_args_t *args, const grm_args_t *merge_args, const char *con const char *const *current_key_ptr; int merge; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; it = args_iter(merge_args); cleanup_and_set_error_if(it == NULL, ERROR_MALLOC); @@ -1697,7 +1697,7 @@ err_t args_setdefault_common(grm_args_t *args, const char *key, const char *valu { return args_push_common(args, key, value_format, buffer, vl, apply_padding); } - return NO_ERROR; + return ERROR_NONE; } err_t args_setdefault(grm_args_t *args, const char *key, const char *value_format, ...) @@ -2085,7 +2085,7 @@ int grm_args_push(grm_args_t *args, const char *key, const char *value_format, . va_end(vl); - return error == NO_ERROR; + return error == ERROR_NONE; } int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, @@ -2095,7 +2095,7 @@ int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_forma error = args_push_common(args, key, value_format, buffer, NULL, apply_padding); - return error == NO_ERROR; + return error == ERROR_NONE; } int grm_args_contains(const grm_args_t *args, const char *keyword) diff --git a/lib/grm/src/grm/base64.c b/lib/grm/src/grm/base64.c index 4390f0b66..82be118c4 100644 --- a/lib/grm/src/grm/base64.c +++ b/lib/grm/src/grm/base64.c @@ -129,7 +129,7 @@ err_t block_decode(char dst[3], const char src[4], int block_len, int *decoded_b *decoded_block_len = block_len - 1; } - return NO_ERROR; + return ERROR_NONE; } @@ -194,7 +194,7 @@ err_t block_encode(char dst[4], const char src[3], int block_len) } } - return NO_ERROR; + return ERROR_NONE; } @@ -203,7 +203,7 @@ char *base64_decode(char *dst, const char *src, size_t *dst_len, err_t *error) size_t src_len, max_dst_len; size_t dst_index = 0, src_index; int decoded_block_len; - err_t _error = NO_ERROR; + err_t _error = ERROR_NONE; src_len = strlen(src); @@ -226,7 +226,7 @@ char *base64_decode(char *dst, const char *src, size_t *dst_len, err_t *error) for (dst_index = 0, src_index = 0; src_index < src_len; dst_index += decoded_block_len, src_index += 4) { _error = block_decode(dst + dst_index, src + src_index, grm_min(src_len - src_index, 4), &decoded_block_len); - if (_error != NO_ERROR) + if (_error != ERROR_NONE) { break; } @@ -254,7 +254,7 @@ char *base64_encode(char *dst, const char *src, size_t src_len, err_t *error) { size_t dst_len; size_t dst_index = 0, src_index; - err_t _error = NO_ERROR; + err_t _error = ERROR_NONE; /* Always round up to multiple of 4 */ dst_len = (4 * src_len) / 3; @@ -275,7 +275,7 @@ char *base64_encode(char *dst, const char *src, size_t src_len, err_t *error) for (dst_index = 0, src_index = 0; src_index < src_len; dst_index += 4, src_index += 3) { _error = block_encode(dst + dst_index, src + src_index, grm_min(src_len - src_index, 3)); - if (_error != NO_ERROR) + if (_error != ERROR_NONE) { break; } diff --git a/lib/grm/src/grm/datatype/string_list.c b/lib/grm/src/grm/datatype/string_list.c index 358baa4a5..e9811e062 100644 --- a/lib/grm/src/grm/datatype/string_list.c +++ b/lib/grm/src/grm/datatype/string_list.c @@ -27,13 +27,13 @@ err_t string_list_entry_copy(string_list_entry_t *copy, const string_list_const_ } *copy = _copy; - return NO_ERROR; + return ERROR_NONE; } err_t string_list_entry_delete(string_list_entry_t entry) { free(entry); - return NO_ERROR; + return ERROR_NONE; } diff --git a/lib/grm/src/grm/datatype/template/list_int.h b/lib/grm/src/grm/datatype/template/list_int.h index 4601fc9db..bc2c130af 100644 --- a/lib/grm/src/grm/datatype/template/list_int.h +++ b/lib/grm/src/grm/datatype/template/list_int.h @@ -173,7 +173,7 @@ err_t prefix##_list_push_front(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ { \ prefix##_list_node_t *new_list_node; \ - err_t error = NO_ERROR; \ + err_t error = ERROR_NONE; \ \ new_list_node = malloc(sizeof(prefix##_list_node_t)); \ error_cleanup_and_set_error_if(new_list_node == NULL, ERROR_MALLOC); \ @@ -187,7 +187,7 @@ } \ ++(list->size); \ \ - return NO_ERROR; \ + return ERROR_NONE; \ \ error_cleanup: \ free(new_list_node); \ @@ -197,7 +197,7 @@ err_t prefix##_list_push_back(prefix##_list_t *list, prefix##_list_const_entry_t entry) \ { \ prefix##_list_node_t *new_list_node; \ - err_t error = NO_ERROR; \ + err_t error = ERROR_NONE; \ \ new_list_node = malloc(sizeof(prefix##_list_node_t)); \ error_cleanup_and_set_error_if(new_list_node == NULL, ERROR_MALLOC); \ @@ -215,7 +215,7 @@ list->tail = new_list_node; \ ++(list->size); \ \ - return NO_ERROR; \ + return ERROR_NONE; \ \ error_cleanup: \ free(new_list_node); \ @@ -394,7 +394,7 @@ err_t prefix##_reflist_entry_copy(prefix##_reflist_entry_t *copy, prefix##_reflist_entry_t entry) \ { \ *copy = entry; \ - return NO_ERROR; \ + return ERROR_NONE; \ } \ \ - err_t prefix##_reflist_entry_delete(prefix##_reflist_entry_t entry UNUSED) { return NO_ERROR; } + err_t prefix##_reflist_entry_delete(prefix##_reflist_entry_t entry UNUSED) { return ERROR_NONE; } diff --git a/lib/grm/src/grm/dynamic_args_array.c b/lib/grm/src/grm/dynamic_args_array.c index f981efddf..23b37c5a3 100644 --- a/lib/grm/src/grm/dynamic_args_array.c +++ b/lib/grm/src/grm/dynamic_args_array.c @@ -62,5 +62,5 @@ err_t dynamic_args_array_push_back(dynamic_args_array_t *args_array, grm_args_t args_array->buf[args_array->size] = args; ++args_array->size; - return NO_ERROR; + return ERROR_NONE; } diff --git a/lib/grm/src/grm/error.c b/lib/grm/src/grm/error.c index 77d978179..cd1646ba4 100644 --- a/lib/grm/src/grm/error.c +++ b/lib/grm/src/grm/error.c @@ -11,7 +11,7 @@ /* ------------------------- error handling ------------------------------------------------------------------------- */ -const char *error_names[] = {STRING_ARRAY_VALUE(NO_ERROR, 0) +const char *error_names[] = {STRING_ARRAY_VALUE(ERROR_NONE, 0) ENUM_ELEMENTS(STRING_ARRAY_VALUE, STRING_ARRAY_LAST_VALUE)}; /* ========================= functions ============================================================================== */ diff --git a/lib/grm/src/grm/error_int.h b/lib/grm/src/grm/error_int.h index 5dbed779d..13aebfe56 100644 --- a/lib/grm/src/grm/error_int.h +++ b/lib/grm/src/grm/error_int.h @@ -80,6 +80,7 @@ extern "C" { /* ------------------------- error handling ------------------------------------------------------------------------- */ #define ENUM_ELEMENTS(X, Y) \ + X(ERROR_NONE, 0) \ X(ERROR_UNSPECIFIED, 1) \ X(ERROR_INTERNAL, 2) \ X(ERROR_MALLOC, 3) \ @@ -137,10 +138,7 @@ extern "C" { typedef enum { -#ifndef _WIN32 /* Windows uses `NO_ERROR` (= 0) for its own error codes */ - ENUM_VALUE(NO_ERROR, 0) -#endif - ENUM_ELEMENTS(ENUM_VALUE, ENUM_LAST_VALUE) + ENUM_ELEMENTS(ENUM_VALUE, ENUM_LAST_VALUE) } err_t; /* ######################### public implementatin ################################################################### */ diff --git a/lib/grm/src/grm/event.c b/lib/grm/src/grm/event.c index c30c364ac..1e413e9d3 100644 --- a/lib/grm/src/grm/event.c +++ b/lib/grm/src/grm/event.c @@ -59,13 +59,13 @@ err_t event_list_entry_copy(event_list_entry_t *copy, event_list_const_entry_t e memcpy(_copy, entry, sizeof(grm_event_t)); *copy = _copy; - return NO_ERROR; + return ERROR_NONE; } err_t event_list_entry_delete(event_list_entry_t entry) { free(entry); - return NO_ERROR; + return ERROR_NONE; } event_queue_t *event_queue_new(void) @@ -155,7 +155,7 @@ int event_queue_process_all(event_queue_t *queue) err_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id) { grm_new_plot_event_t *new_plot_event = NULL; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; new_plot_event = malloc(sizeof(grm_new_plot_event_t)); error_cleanup_and_set_error_if(new_plot_event == NULL, ERROR_MALLOC); @@ -165,7 +165,7 @@ err_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id) error = event_reflist_enqueue(queue->queue, (grm_event_t *)new_plot_event); error_cleanup_if_error; - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (new_plot_event != NULL) @@ -179,7 +179,7 @@ err_t event_queue_enqueue_new_plot_event(event_queue_t *queue, int plot_id) err_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id) { grm_update_plot_event_t *update_plot_event = NULL; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; update_plot_event = malloc(sizeof(grm_update_plot_event_t)); error_cleanup_and_set_error_if(update_plot_event == NULL, ERROR_MALLOC); @@ -189,7 +189,7 @@ err_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id) error = event_reflist_enqueue(queue->queue, (grm_event_t *)update_plot_event); error_cleanup_if_error; - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (update_plot_event != NULL) @@ -203,7 +203,7 @@ err_t event_queue_enqueue_update_plot_event(event_queue_t *queue, int plot_id) err_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int width, int height) { grm_size_event_t *size_event = NULL; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; size_event = malloc(sizeof(grm_size_event_t)); error_cleanup_and_set_error_if(size_event == NULL, ERROR_MALLOC); @@ -215,7 +215,7 @@ err_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int widt error = event_reflist_enqueue(queue->queue, (grm_event_t *)size_event); error_cleanup_if_error; - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (size_event != NULL) @@ -229,7 +229,7 @@ err_t event_queue_enqueue_size_event(event_queue_t *queue, int plot_id, int widt err_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *identificator) { grm_merge_end_event_t *merge_end_event = NULL; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; merge_end_event = malloc(sizeof(grm_merge_end_event_t)); error_cleanup_and_set_error_if(merge_end_event == NULL, ERROR_MALLOC); @@ -238,7 +238,7 @@ err_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *iden error = event_reflist_enqueue(queue->queue, (grm_event_t *)merge_end_event); error_cleanup_if_error; - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (merge_end_event != NULL) @@ -261,7 +261,7 @@ err_t event_queue_enqueue_merge_end_event(event_queue_t *queue, const char *iden int grm_register(grm_event_type_t type, grm_event_callback_t callback) { - if (plot_init_static_variables() != NO_ERROR) + if (plot_init_static_variables() != ERROR_NONE) { return 0; } @@ -273,7 +273,7 @@ int grm_register(grm_event_type_t type, grm_event_callback_t callback) int grm_unregister(grm_event_type_t type) { - if (plot_init_static_variables() != NO_ERROR) + if (plot_init_static_variables() != ERROR_NONE) { return 0; } diff --git a/lib/grm/src/grm/json.c b/lib/grm/src/grm/json.c index ccb65eb10..692f84ef1 100644 --- a/lib/grm/src/grm/json.c +++ b/lib/grm/src/grm/json.c @@ -58,7 +58,7 @@ static tojson_permanent_state_t tojson_permanent_state = {complete, 0}; int grm_read(grm_args_t *args, const char *json_string) { - return (fromjson_read(args, json_string) == NO_ERROR); + return (fromjson_read(args, json_string) == ERROR_NONE); } err_t fromjson_read(grm_args_t *args, const char *json_string) @@ -68,7 +68,7 @@ err_t fromjson_read(grm_args_t *args, const char *json_string) int grm_load_from_str(const char *json_string) { - return (fromjson_read(active_plot_args, json_string) == NO_ERROR); + return (fromjson_read(active_plot_args, json_string) == ERROR_NONE); } err_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_state_t *shared_state) @@ -76,7 +76,7 @@ err_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_ char *filtered_json_string = NULL; fromjson_state_t state; int allocated_shared_state_mem = 0; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; state.datatype = JSON_DATATYPE_UNKNOWN; state.value_buffer = NULL; @@ -98,7 +98,7 @@ err_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_ debug_print_malloc_error(); return ERROR_MALLOC; } - if ((error = fromjson_copy_and_filter_json_string(&filtered_json_string, json_string)) != NO_ERROR) + if ((error = fromjson_copy_and_filter_json_string(&filtered_json_string, json_string)) != ERROR_NONE) { free(state.next_value_type); free(shared_state); @@ -130,7 +130,7 @@ err_t fromjson_parse(grm_args_t *args, const char *json_string, fromjson_shared_ state.datatype = fromjson_check_type(&state); if (state.datatype) { - if ((error = fromjson_datatype_to_func[state.datatype](&state)) != NO_ERROR) + if ((error = fromjson_datatype_to_func[state.datatype](&state)) != ERROR_NONE) { break; } @@ -220,7 +220,7 @@ err_t fromjson_parse_null(fromjson_state_t *state) } strcpy(state->next_value_type, ""); state->shared_state->json_ptr += 4; - return NO_ERROR; + return ERROR_NONE; } err_t fromjson_parse_bool(fromjson_state_t *state) @@ -243,7 +243,7 @@ err_t fromjson_parse_bool(fromjson_state_t *state) *((int *)state->next_value_memory) = bool_value; strcpy(state->next_value_type, "i"); state->shared_state->json_ptr += bool_value ? 4 : 5; - return NO_ERROR; + return ERROR_NONE; } err_t fromjson_parse_number(fromjson_state_t *state) @@ -274,7 +274,7 @@ err_t fromjson_parse_int(fromjson_state_t *state) CHECK_AND_ALLOCATE_MEMORY(int, 1); *((int *)state->next_value_memory) = int_value; strcpy(state->next_value_type, "i"); - return NO_ERROR; + return ERROR_NONE; } err_t fromjson_parse_double(fromjson_state_t *state) @@ -290,7 +290,7 @@ err_t fromjson_parse_double(fromjson_state_t *state) CHECK_AND_ALLOCATE_MEMORY(double, 1); *((double *)state->next_value_memory) = double_value; strcpy(state->next_value_type, "d"); - return NO_ERROR; + return ERROR_NONE; } err_t fromjson_parse_string(fromjson_state_t *state) @@ -336,7 +336,7 @@ err_t fromjson_parse_string(fromjson_state_t *state) ++json_ptr; state->shared_state->json_ptr = json_ptr; - return string_is_complete ? NO_ERROR : ERROR_PARSE_STRING; + return string_is_complete ? ERROR_NONE : ERROR_PARSE_STRING; } err_t fromjson_parse_array(fromjson_state_t *state) @@ -388,7 +388,7 @@ err_t fromjson_parse_array(fromjson_state_t *state) array_type[0] = '\0'; do { - err_t error = NO_ERROR; + err_t error = ERROR_NONE; size_t array_length = 0; state->shared_state->json_ptr += is_nested_array ? 2 : 1; next_delim_ptr = state->shared_state->json_ptr; @@ -455,7 +455,7 @@ err_t fromjson_parse_array(fromjson_state_t *state) strcpy(state->next_value_type, "I(0)"); } - return NO_ERROR; + return ERROR_NONE; #undef PARSE_VALUES } @@ -545,7 +545,7 @@ err_t fromjson_copy_and_filter_json_string(char **dest, const char *src) *dest = dest_buffer; - return NO_ERROR; + return ERROR_NONE; } int fromjson_is_escaped_delimiter(const char *delim_ptr, const char *str) @@ -839,18 +839,18 @@ int fromjson_str_to_int(const char **str, int *was_successful) return memwriter_printf(memwriter, format_specifier, value); \ } -#define DEFINE_STRINGIFY_SINGLE(name, type, promoted_type) \ - err_t tojson_stringify_##name(tojson_state_t *state) \ - { \ - type value; \ - err_t error = NO_ERROR; \ - RETRIEVE_SINGLE_VALUE(value, type, promoted_type); \ - if ((error = tojson_stringify_##name##_value(state->memwriter, value)) != NO_ERROR) \ - { \ - return error; \ - } \ - state->shared->wrote_output = 1; \ - return error; \ +#define DEFINE_STRINGIFY_SINGLE(name, type, promoted_type) \ + err_t tojson_stringify_##name(tojson_state_t *state) \ + { \ + type value; \ + err_t error = ERROR_NONE; \ + RETRIEVE_SINGLE_VALUE(value, type, promoted_type); \ + if ((error = tojson_stringify_##name##_value(state->memwriter, value)) != ERROR_NONE) \ + { \ + return error; \ + } \ + state->shared->wrote_output = 1; \ + return error; \ } #define DEFINE_STRINGIFY_MULTI(name, type) \ @@ -860,7 +860,7 @@ int fromjson_str_to_int(const char **str, int *was_successful) type current_value; \ unsigned int length; \ int remaining_elements; \ - err_t error = NO_ERROR; \ + err_t error = ERROR_NONE; \ INIT_MULTI_VALUE(values, type); \ if (state->additional_type_info != NULL) \ { \ @@ -878,7 +878,7 @@ int fromjson_str_to_int(const char **str, int *was_successful) } \ remaining_elements = length; \ /* write array start */ \ - if ((error = memwriter_putc(state->memwriter, '[')) != NO_ERROR) \ + if ((error = memwriter_putc(state->memwriter, '[')) != ERROR_NONE) \ { \ return error; \ } \ @@ -886,13 +886,13 @@ int fromjson_str_to_int(const char **str, int *was_successful) while (remaining_elements) \ { \ current_value = *values++; \ - if ((error = tojson_stringify_##name##_value(state->memwriter, current_value)) != NO_ERROR) \ + if ((error = tojson_stringify_##name##_value(state->memwriter, current_value)) != ERROR_NONE) \ { \ return error; \ } \ if (remaining_elements > 1) \ { \ - if ((error = memwriter_putc(state->memwriter, ',')) != NO_ERROR) \ + if ((error = memwriter_putc(state->memwriter, ',')) != ERROR_NONE) \ { \ return error; \ } \ @@ -900,7 +900,7 @@ int fromjson_str_to_int(const char **str, int *was_successful) --remaining_elements; \ } \ /* write array end */ \ - if ((error = memwriter_putc(state->memwriter, ']')) != NO_ERROR) \ + if ((error = memwriter_putc(state->memwriter, ']')) != ERROR_NONE) \ { \ return error; \ } \ @@ -941,19 +941,19 @@ err_t tojson_stringify_double_value(memwriter_t *memwriter, double value) The %G format specifier is important here, as it returns "NAN" for missing values - %g would return "nan" and be handled as JSON_DATATYPE_NULL in fromjson_check_type() */ - if ((error = memwriter_printf(memwriter, "%." XSTR(DBL_DECIMAL_DIG) "G", value)) != NO_ERROR) + if ((error = memwriter_printf(memwriter, "%." XSTR(DBL_DECIMAL_DIG) "G", value)) != ERROR_NONE) { return error; } unprocessed_string = memwriter_buf(memwriter) + string_start_index; if (strspn(unprocessed_string, "0123456789-") == memwriter_size(memwriter) - string_start_index) { - if ((error = memwriter_putc(memwriter, '.')) != NO_ERROR) + if ((error = memwriter_putc(memwriter, '.')) != ERROR_NONE) { return error; } } - return NO_ERROR; + return ERROR_NONE; } #undef XSTR @@ -964,7 +964,7 @@ err_t tojson_stringify_char_array(tojson_state_t *state) char *chars; char *escaped_chars = NULL; unsigned int length; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; INIT_MULTI_VALUE(chars, char); @@ -988,11 +988,11 @@ err_t tojson_stringify_char_array(tojson_state_t *state) length = state->shared->array_length; } } - if ((error = tojson_escape_special_chars(&escaped_chars, chars, &length)) != NO_ERROR) + if ((error = tojson_escape_special_chars(&escaped_chars, chars, &length)) != ERROR_NONE) { goto cleanup; } - if ((error = memwriter_printf(state->memwriter, "\"%.*s\"", length, escaped_chars)) != NO_ERROR) + if ((error = memwriter_printf(state->memwriter, "\"%.*s\"", length, escaped_chars)) != ERROR_NONE) { goto cleanup; } @@ -1009,13 +1009,13 @@ err_t tojson_stringify_string_value(memwriter_t *memwriter, char *value) { char *escaped_chars = NULL; unsigned int length = 0; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; if ((error = tojson_escape_special_chars(&escaped_chars, value, &length))) { goto cleanup; } - if ((error = memwriter_printf(memwriter, "\"%s\"", escaped_chars)) != NO_ERROR) + if ((error = memwriter_printf(memwriter, "\"%s\"", escaped_chars)) != ERROR_NONE) { goto cleanup; } @@ -1037,11 +1037,11 @@ err_t tojson_stringify_object(tojson_state_t *state) char **member_name_ptr; char **data_type_ptr; int has_members; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; /* IMPORTANT: additional_type_info is altered after the unzip call! */ if ((error = tojson_unzip_membernames_and_datatypes(state->additional_type_info, &member_names, &data_types)) != - NO_ERROR) + ERROR_NONE) { goto cleanup; } @@ -1055,14 +1055,14 @@ err_t tojson_stringify_object(tojson_state_t *state) { if (state->shared->add_data && has_members) { - if ((error = memwriter_putc(state->memwriter, ',')) != NO_ERROR) + if ((error = memwriter_putc(state->memwriter, ',')) != ERROR_NONE) { goto cleanup; } } else if (!state->shared->add_data) { - if ((error = memwriter_putc(state->memwriter, '{')) != NO_ERROR) + if ((error = memwriter_putc(state->memwriter, '{')) != ERROR_NONE) { goto cleanup; } @@ -1078,12 +1078,12 @@ err_t tojson_stringify_object(tojson_state_t *state) int serialized_all_members = 0; while (!serialized_all_members) { - if ((error = memwriter_printf(state->memwriter, "\"%s\":", *member_name_ptr)) != NO_ERROR) + if ((error = memwriter_printf(state->memwriter, "\"%s\":", *member_name_ptr)) != ERROR_NONE) { goto cleanup; } if ((error = tojson_serialize(state->memwriter, *data_type_ptr, NULL, NULL, -1, -1, 0, NULL, NULL, - state->shared)) != NO_ERROR) + state->shared)) != ERROR_NONE) { goto cleanup; } @@ -1092,7 +1092,7 @@ err_t tojson_stringify_object(tojson_state_t *state) if (*member_name_ptr != NULL && *data_type_ptr != NULL) { /* write JSON separator */ - if ((error = memwriter_putc(state->memwriter, ',')) != NO_ERROR) + if ((error = memwriter_putc(state->memwriter, ',')) != ERROR_NONE) { goto cleanup; } @@ -1107,7 +1107,7 @@ err_t tojson_stringify_object(tojson_state_t *state) if (!state->is_type_info_incomplete) { --(state->shared->struct_nested_level); - if ((error = memwriter_putc(state->memwriter, '}')) != NO_ERROR) + if ((error = memwriter_putc(state->memwriter, '}')) != ERROR_NONE) { goto cleanup; } @@ -1121,31 +1121,31 @@ err_t tojson_stringify_object(tojson_state_t *state) cleanup: free(member_names); free(data_types); - if (error != NO_ERROR) + if (error != ERROR_NONE) { return error; } state->shared->wrote_output = 1; - return NO_ERROR; + return ERROR_NONE; } err_t tojson_stringify_args_value(memwriter_t *memwriter, grm_args_t *args) { - err_t error = NO_ERROR; + err_t error = ERROR_NONE; - if ((error = memwriter_putc(memwriter, '{')) != NO_ERROR) + if ((error = memwriter_putc(memwriter, '{')) != ERROR_NONE) { return error; } tojson_permanent_state.serial_result = incomplete_at_struct_beginning; - if ((error = tojson_write_args(memwriter, args)) != NO_ERROR) + if ((error = tojson_write_args(memwriter, args)) != ERROR_NONE) { return error; } - return NO_ERROR; + return ERROR_NONE; } int tojson_get_member_count(const char *data_desc) @@ -1247,7 +1247,7 @@ err_t tojson_skip_bytes(tojson_state_t *state) if (state->shared->data_ptr == NULL) { debug_print_error(("Skipping bytes is not supported when using the variable argument list and is ignored.\n")); - return NO_ERROR; + return ERROR_NONE; } if (state->additional_type_info != NULL) @@ -1255,7 +1255,7 @@ err_t tojson_skip_bytes(tojson_state_t *state) if (!str_to_uint(state->additional_type_info, &count)) { debug_print_error(("Byte skipping with an invalid number -> ignoring.\n")); - return NO_ERROR; + return ERROR_NONE; } } else @@ -1265,18 +1265,18 @@ err_t tojson_skip_bytes(tojson_state_t *state) state->shared->data_ptr = ((char *)state->shared->data_ptr) + count; state->shared->data_offset += count; - return NO_ERROR; + return ERROR_NONE; } err_t tojson_close_object(tojson_state_t *state) { err_t error; --(state->shared->struct_nested_level); - if ((error = memwriter_putc(state->memwriter, '}')) != NO_ERROR) + if ((error = memwriter_putc(state->memwriter, '}')) != ERROR_NONE) { return error; } - return NO_ERROR; + return ERROR_NONE; } err_t tojson_read_array_length(tojson_state_t *state) @@ -1286,7 +1286,7 @@ err_t tojson_read_array_length(tojson_state_t *state) RETRIEVE_SINGLE_VALUE(value, size_t, size_t); state->shared->array_length = value; - return NO_ERROR; + return ERROR_NONE; } err_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_name_ptr, char ***data_type_ptr) @@ -1348,7 +1348,7 @@ err_t tojson_unzip_membernames_and_datatypes(char *mixed_ptr, char ***member_nam } *arrays[member_name] = NULL; *arrays[data_type] = NULL; - return NO_ERROR; + return ERROR_NONE; } err_t tojson_escape_special_chars(char **escaped_string, const char *unescaped_string, unsigned int *length) @@ -1398,7 +1398,7 @@ err_t tojson_escape_special_chars(char **escaped_string, const char *unescaped_s *length = needed_memory - 1; } - return NO_ERROR; + return ERROR_NONE; } #undef CHECK_PADDING @@ -1430,7 +1430,7 @@ err_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data tojson_state_t state; int json_array_needed = 0; int allocated_shared_state_mem = 0; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; state.memwriter = memwriter; state.data_type_ptr = data_desc; @@ -1479,7 +1479,7 @@ err_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data /* write list head if needed */ if (json_array_needed) { - if ((error = memwriter_putc(memwriter, '[')) != NO_ERROR) + if ((error = memwriter_putc(memwriter, '[')) != ERROR_NONE) { goto cleanup; } @@ -1498,14 +1498,14 @@ err_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data state.current_data_type)); error = ERROR_UNSUPPORTED_DATATYPE; } - if (error != NO_ERROR) + if (error != ERROR_NONE) { goto cleanup; } if (*state.data_type_ptr != 0 && *state.data_type_ptr != ')' && shared_state->wrote_output) { /* write JSON separator, if data was written and the object is not closed in the next step */ - if ((error = memwriter_putc(memwriter, ',')) != NO_ERROR) + if ((error = memwriter_putc(memwriter, ',')) != ERROR_NONE) { goto cleanup; } @@ -1514,7 +1514,7 @@ err_t tojson_serialize(memwriter_t *memwriter, char *data_desc, const void *data /* write list tail if needed */ if (json_array_needed) { - if ((error = memwriter_putc(memwriter, ']')) != NO_ERROR) + if ((error = memwriter_putc(memwriter, ']')) != ERROR_NONE) { goto cleanup; } @@ -1606,7 +1606,7 @@ err_t tojson_init_variables(int *add_data, int *add_data_without_separator, char } } - return NO_ERROR; + return ERROR_NONE; } err_t tojson_write_vl(memwriter_t *memwriter, const char *data_desc, va_list *vl) @@ -1647,11 +1647,11 @@ err_t tojson_write_buf(memwriter_t *memwriter, const char *data_desc, const void err_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg) { - err_t error = NO_ERROR; + err_t error = ERROR_NONE; if (arg->key == NULL) { - if ((error = tojson_write_buf(memwriter, arg->value_format, arg->value_ptr, 1)) != NO_ERROR) + if ((error = tojson_write_buf(memwriter, arg->value_format, arg->value_ptr, 1)) != ERROR_NONE) { return error; } @@ -1675,7 +1675,7 @@ err_t tojson_write_arg(memwriter_t *memwriter, const arg_t *arg) memcpy(format_ptr, arg->value_format, value_format_length); format_ptr += value_format_length; *format_ptr = '\0'; - if ((error = tojson_write_buf(memwriter, format, arg->value_ptr, 1)) != NO_ERROR) + if ((error = tojson_write_buf(memwriter, format, arg->value_ptr, 1)) != ERROR_NONE) { free(format); return error; diff --git a/lib/grm/src/grm/memwriter.c b/lib/grm/src/grm/memwriter.c index 00a771c6f..8669ecba4 100644 --- a/lib/grm/src/grm/memwriter.c +++ b/lib/grm/src/grm/memwriter.c @@ -58,10 +58,10 @@ void memwriter_clear(memwriter_t *memwriter) err_t memwriter_replace(memwriter_t *memwriter, int index, int count, const char *replacement_str) { int replacement_str_len = (replacement_str != NULL) ? strlen(replacement_str) : 0; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; if ((replacement_str_len > count) && - (error = memwriter_ensure_buf(memwriter, replacement_str_len - count)) != NO_ERROR) + (error = memwriter_ensure_buf(memwriter, replacement_str_len - count)) != ERROR_NONE) { return error; } @@ -126,7 +126,7 @@ err_t memwriter_enlarge_buf(memwriter_t *memwriter, size_t size_increment) memwriter->buf = new_buf; memwriter->capacity += size_increment; - return NO_ERROR; + return ERROR_NONE; } err_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_size) @@ -135,13 +135,13 @@ err_t memwriter_ensure_buf(memwriter_t *memwriter, size_t needed_additional_size { return memwriter_enlarge_buf(memwriter, memwriter->size + needed_additional_size - memwriter->capacity); } - return NO_ERROR; + return ERROR_NONE; } err_t memwriter_printf(memwriter_t *memwriter, const char *format, ...) { va_list vl; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; while (1) { @@ -159,7 +159,7 @@ err_t memwriter_printf(memwriter_t *memwriter, const char *format, ...) memwriter->size += chars_needed; break; } - if ((error = memwriter_ensure_buf(memwriter, chars_needed + 1)) != NO_ERROR) + if ((error = memwriter_ensure_buf(memwriter, chars_needed + 1)) != ERROR_NONE) { break; } diff --git a/lib/grm/src/grm/net.c b/lib/grm/src/grm/net.c index 58c08f83d..b6ec97788 100644 --- a/lib/grm/src/grm/net.c +++ b/lib/grm/src/grm/net.c @@ -76,13 +76,13 @@ err_t args_list_entry_copy(args_list_entry_t *copy, args_list_const_entry_t entr } *copy = _copy; - return NO_ERROR; + return ERROR_NONE; } err_t args_list_entry_delete(args_list_entry_t entry) { grm_args_delete(entry); - return NO_ERROR; + return ERROR_NONE; } @@ -95,13 +95,13 @@ err_t dynamic_args_array_list_entry_copy(dynamic_args_array_list_entry_t *copy, { /* TODO: create a copy of the object! Otherwise code will segfault on list deletion for a non-ref list */ *copy = (dynamic_args_array_list_entry_t)entry; - return NO_ERROR; + return ERROR_NONE; } err_t dynamic_args_array_list_entry_delete(dynamic_args_array_list_entry_t entry) { dynamic_args_array_delete(entry); - return NO_ERROR; + return ERROR_NONE; } @@ -128,7 +128,7 @@ err_t receiver_init_for_custom(net_handle_t *handle, const char *name, unsigned return ERROR_MALLOC; } - return NO_ERROR; + return ERROR_NONE; } err_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port) @@ -246,19 +246,19 @@ err_t receiver_init_for_socket(net_handle_t *handle, const char *hostname, unsig return ERROR_MALLOC; } - return NO_ERROR; + return ERROR_NONE; } err_t receiver_finalize_for_custom(net_handle_t *handle) { memwriter_delete(handle->sender_receiver.receiver.memwriter); - return NO_ERROR; + return ERROR_NONE; } err_t receiver_finalize_for_socket(net_handle_t *handle) { - err_t error = NO_ERROR; + err_t error = ERROR_NONE; memwriter_delete(handle->sender_receiver.receiver.memwriter); #ifdef _WIN32 @@ -310,7 +310,7 @@ err_t receiver_recv_for_socket(net_handle_t *handle) int search_start_index = 0; char *end_ptr; static char recv_buf[SOCKET_RECV_BUF_SIZE]; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; while ((end_ptr = memchr(memwriter_buf(handle->sender_receiver.receiver.memwriter) + search_start_index, ETB, memwriter_size(handle->sender_receiver.receiver.memwriter) - search_start_index)) == NULL) @@ -329,7 +329,7 @@ err_t receiver_recv_for_socket(net_handle_t *handle) return ERROR_NETWORK_RECV_CONNECTION_SHUTDOWN; } if ((error = memwriter_printf(handle->sender_receiver.receiver.memwriter, "%.*s", bytes_received, recv_buf)) != - NO_ERROR) + ERROR_NONE) { return error; } @@ -344,7 +344,7 @@ err_t receiver_recv_for_custom(net_handle_t *handle) { /* TODO: is it really necessary to copy the memory? */ const char *recv_buf; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; recv_buf = handle->sender_receiver.receiver.comm.custom.recv(handle->sender_receiver.receiver.comm.custom.name, handle->sender_receiver.receiver.comm.custom.id); @@ -353,7 +353,7 @@ err_t receiver_recv_for_custom(net_handle_t *handle) return ERROR_CUSTOM_RECV; } memwriter_clear(handle->sender_receiver.receiver.memwriter); - if ((error = memwriter_puts(handle->sender_receiver.receiver.memwriter, recv_buf)) != NO_ERROR) + if ((error = memwriter_puts(handle->sender_receiver.receiver.memwriter, recv_buf)) != ERROR_NONE) { return error; } @@ -379,7 +379,7 @@ err_t sender_init_for_custom(net_handle_t *handle, const char *name, unsigned in return ERROR_MALLOC; } - return NO_ERROR; + return ERROR_NONE; } err_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsigned int port) @@ -479,19 +479,19 @@ err_t sender_init_for_socket(net_handle_t *handle, const char *hostname, unsigne return ERROR_MALLOC; } - return NO_ERROR; + return ERROR_NONE; } err_t sender_finalize_for_custom(net_handle_t *handle) { memwriter_delete(handle->sender_receiver.sender.memwriter); - return NO_ERROR; + return ERROR_NONE; } err_t sender_finalize_for_socket(net_handle_t *handle) { - err_t error = NO_ERROR; + err_t error = ERROR_NONE; memwriter_delete(handle->sender_receiver.sender.memwriter); #ifdef _WIN32 @@ -527,9 +527,9 @@ err_t sender_send_for_socket(net_handle_t *handle) const char *buf; size_t buf_size; int bytes_left; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; - if ((error = memwriter_putc(handle->sender_receiver.sender.memwriter, ETB)) != NO_ERROR) + if ((error = memwriter_putc(handle->sender_receiver.sender.memwriter, ETB)) != ERROR_NONE) { return error; } @@ -557,7 +557,7 @@ err_t sender_send_for_socket(net_handle_t *handle) err_t sender_send_for_custom(net_handle_t *handle) { const char *buf; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; buf = memwriter_buf(handle->sender_receiver.sender.memwriter); if (!handle->sender_receiver.sender.comm.custom.send(handle->sender_receiver.sender.comm.custom.name, @@ -583,7 +583,7 @@ void *grm_open(int is_receiver, const char *name, unsigned int id, int (*custom_send)(const char *, unsigned int, const char *)) { net_handle_t *handle; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; handle = malloc(sizeof(net_handle_t)); if (handle == NULL) @@ -615,7 +615,7 @@ void *grm_open(int is_receiver, const char *name, unsigned int id, } } - if (error != NO_ERROR) + if (error != ERROR_NONE) { if (error != ERROR_NETWORK_WINSOCK_INIT) { @@ -654,17 +654,17 @@ grm_args_t *grm_recv(const void *p, grm_args_t *args) created_args = 1; } - if (handle->sender_receiver.receiver.recv(handle) != NO_ERROR) + if (handle->sender_receiver.receiver.recv(handle) != ERROR_NONE) { goto error_cleanup; } - if (fromjson_read(args, memwriter_buf(handle->sender_receiver.receiver.memwriter)) != NO_ERROR) + if (fromjson_read(args, memwriter_buf(handle->sender_receiver.receiver.memwriter)) != ERROR_NONE) { goto error_cleanup; } if (memwriter_erase(handle->sender_receiver.receiver.memwriter, 0, - handle->sender_receiver.receiver.message_size + 1) != NO_ERROR) + handle->sender_receiver.receiver.message_size + 1) != ERROR_NONE) { goto error_cleanup; } @@ -691,13 +691,13 @@ int grm_send(const void *p, const char *data_desc, ...) va_start(vl, data_desc); error = tojson_write_vl(handle->sender_receiver.sender.memwriter, data_desc, &vl); - if (error == NO_ERROR && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) + if (error == ERROR_NONE && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) { error = handle->sender_receiver.sender.send(handle); } va_end(vl); - return error == NO_ERROR; + return error == ERROR_NONE; } int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int apply_padding) @@ -706,12 +706,12 @@ int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int a err_t error; error = tojson_write_buf(handle->sender_receiver.sender.memwriter, data_desc, buffer, apply_padding); - if (error == NO_ERROR && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) + if (error == ERROR_NONE && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) { error = handle->sender_receiver.sender.send(handle); } - return error == NO_ERROR; + return error == ERROR_NONE; } int grm_send_ref(const void *p, const char *key, char format, const void *ref, int len) @@ -724,7 +724,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i char *_key = NULL; net_handle_t *handle = (net_handle_t *)p; char format_string[SEND_REF_FORMAT_MAX_LENGTH]; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; if (tojson_struct_nested_level() == 0) { @@ -808,11 +808,11 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i break; } } - if ((error = args_reflist_push(args_stack, current_args)) != NO_ERROR) + if ((error = args_reflist_push(args_stack, current_args)) != ERROR_NONE) { break; } - if ((error = string_list_push(key_stack, key)) != NO_ERROR) + if ((error = string_list_push(key_stack, key)) != ERROR_NONE) { break; } @@ -863,7 +863,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i break; } } - if ((error = dynamic_args_array_reflist_push(args_array_stack, current_args_array)) != NO_ERROR) + if ((error = dynamic_args_array_reflist_push(args_array_stack, current_args_array)) != ERROR_NONE) { break; } @@ -879,7 +879,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i break; } } - if ((error = args_reflist_push(args_stack, current_args)) != NO_ERROR) + if ((error = args_reflist_push(args_stack, current_args)) != ERROR_NONE) { break; } @@ -893,7 +893,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i break; } } - if ((error = string_list_push(key_stack, key)) != NO_ERROR) + if ((error = string_list_push(key_stack, key)) != ERROR_NONE) { break; } @@ -909,7 +909,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i error = ERROR_MALLOC; break; } - if ((error = dynamic_args_array_push_back(current_args_array, current_args)) != NO_ERROR) + if ((error = dynamic_args_array_push_back(current_args_array, current_args)) != ERROR_NONE) { break; } @@ -923,7 +923,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i break; } assert(current_args_array != NULL); - if ((error = dynamic_args_array_push_back(current_args_array, current_args)) != NO_ERROR) + if ((error = dynamic_args_array_push_back(current_args_array, current_args)) != ERROR_NONE) { break; } @@ -969,7 +969,7 @@ int grm_send_ref(const void *p, const char *key, char format, const void *ref, i free((void *)_key); - return error == NO_ERROR; + return error == ERROR_NONE; } int grm_send_args(const void *p, const grm_args_t *args) @@ -978,10 +978,10 @@ int grm_send_args(const void *p, const grm_args_t *args) err_t error; error = tojson_write_args(handle->sender_receiver.sender.memwriter, args); - if (error == NO_ERROR && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) + if (error == ERROR_NONE && tojson_is_complete() && handle->sender_receiver.sender.send != NULL) { error = handle->sender_receiver.sender.send(handle); } - return error == NO_ERROR; + return error == ERROR_NONE; } diff --git a/lib/grm/src/grm/plot.cxx b/lib/grm/src/grm/plot.cxx index 4045eecd9..c2f068c5b 100644 --- a/lib/grm/src/grm/plot.cxx +++ b/lib/grm/src/grm/plot.cxx @@ -365,7 +365,7 @@ static string_map_entry_t key_to_formats[] = {{"a", "A"}, err_t plot_init_static_variables(void) { - err_t error = NO_ERROR; + err_t error = ERROR_NONE; if (!plot_static_variables_initialized) { @@ -408,7 +408,7 @@ err_t plot_init_static_variables(void) error_cleanup_and_set_error_if(type_map == NULL, ERROR_MALLOC); plot_static_variables_initialized = 1; } - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (global_root_args != NULL) @@ -460,7 +460,7 @@ err_t plot_merge_args(grm_args_t *args, const grm_args_t *merge_args, const char const char **current_hierarchy_name_ptr; grm_args_t **args_array, **merge_args_array, *current_args; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; ++recursion_level; if (hierarchy_name_ptr == NULL) @@ -726,19 +726,19 @@ err_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, unsig grm_args_t **args_array = NULL; unsigned int args_old_array_length; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; logger((stderr, "Init plot args structure for hierarchy: \"%s\"\n", *hierarchy_name_ptr)); ++hierarchy_name_ptr; if (*hierarchy_name_ptr == NULL) { - return NO_ERROR; + return ERROR_NONE; } arg_first_value(arg, "A", NULL, &args_old_array_length); if (next_hierarchy_level_max_id <= args_old_array_length) { - return NO_ERROR; + return ERROR_NONE; } logger((stderr, "Increase array for key \"%s\" from %d to %d\n", *hierarchy_name_ptr, args_old_array_length, next_hierarchy_level_max_id)); @@ -758,7 +758,7 @@ err_t plot_init_arg_structure(arg_t *arg, const char **hierarchy_name_ptr, unsig } } - return NO_ERROR; + return ERROR_NONE; } err_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr, @@ -767,14 +767,14 @@ err_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr arg_t *arg = NULL; grm_args_t **args_array = NULL; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; logger((stderr, "Init plot args structure for hierarchy: \"%s\"\n", *hierarchy_name_ptr)); ++hierarchy_name_ptr; if (*hierarchy_name_ptr == NULL) { - return NO_ERROR; + return ERROR_NONE; } arg = args_at(args, *hierarchy_name_ptr); if (arg == NULL) @@ -803,7 +803,7 @@ err_t plot_init_args_structure(grm_args_t *args, const char **hierarchy_name_ptr error_cleanup_if_error; } - return NO_ERROR; + return ERROR_NONE; error_cleanup: if (args_array != NULL) @@ -1009,7 +1009,7 @@ err_t plot_pre_subplot(grm_args_t *subplot_args) { const char *kind; double alpha; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; logger((stderr, "Pre subplot processing\n")); @@ -1041,7 +1041,7 @@ err_t plot_pre_subplot(grm_args_t *subplot_args) gr_settransparency(alpha); } - return NO_ERROR; + return ERROR_NONE; } void plot_process_colormap(grm_args_t *subplot_args) @@ -1547,7 +1547,7 @@ err_t plot_store_coordinate_ranges(grm_args_t *subplot_args) range_keys[] = {{"xlim", "xrange"}, {"ylim", "yrange"}, {"zlim", "zrange"}, {"clim", "crange"}}; double *bins = NULL; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; logger((stderr, "Storing coordinate ranges\n")); @@ -1556,7 +1556,7 @@ err_t plot_store_coordinate_ranges(grm_args_t *subplot_args) if (grm_args_contains(subplot_args, "_original_xlim")) { logger((stderr, "Panzoom active, do not modify limits...\n")); - return NO_ERROR; + return ERROR_NONE; } args_values(subplot_args, "kind", "s", &kind); @@ -1954,7 +1954,7 @@ err_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name_s if (strcmp(*current_hierarchy_name_ptr, "plots") == 0) { int in_use; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(current_args, "in_use", "i", &in_use); if (in_use) { @@ -1983,7 +1983,7 @@ err_t plot_get_args_in_hierarchy(grm_args_t *args, const char **hierarchy_name_s *found_hierarchy_name_ptr = current_hierarchy_name_ptr; } - return NO_ERROR; + return ERROR_NONE; } @@ -2036,7 +2036,7 @@ err_t plot_line(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } err_t plot_step(grm_args_t *subplot_args) @@ -2055,7 +2055,7 @@ err_t plot_step(grm_args_t *subplot_args) double xmin, xmax, ymin, ymax; double *y = NULL, *xi = NULL; int is_vertical; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); @@ -2375,13 +2375,13 @@ err_t plot_scatter(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } err_t plot_quiver(grm_args_t *subplot_args) { grm_args_t **current_series; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "A", ¤t_series); while (*current_series != NULL) @@ -2436,7 +2436,7 @@ err_t plot_stem(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } err_t plot_hist(grm_args_t *subplot_args) @@ -2446,7 +2446,7 @@ err_t plot_hist(grm_args_t *subplot_args) double *bar_centers = NULL; int bar_color_index = 989, i, xind, yind; double bar_color_rgb[3] = {-1}; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "kind", "s", &kind); args_values(subplot_args, "series", "A", ¤t_series); @@ -2583,7 +2583,7 @@ err_t plot_barplot(grm_args_t *subplot_args) int change_edge_color = 0; int change_edge_width = 0; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; double *y_lightness = NULL; gr_settextalign(2, 3); @@ -3299,7 +3299,7 @@ err_t plot_contour(grm_args_t *subplot_args) double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "_zlim", "dd", &z_min, &z_max); gr_setprojectiontype(0); @@ -3361,7 +3361,7 @@ err_t plot_contour(grm_args_t *subplot_args) } ++current_series; } - if ((error = plot_draw_colorbar(subplot_args, 0.0, num_levels)) != NO_ERROR) + if ((error = plot_draw_colorbar(subplot_args, 0.0, num_levels)) != ERROR_NONE) { goto cleanup; } @@ -3383,7 +3383,7 @@ err_t plot_contourf(grm_args_t *subplot_args) double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "_zlim", "dd", &z_min, &z_max); gr_setprojectiontype(0); @@ -3406,7 +3406,7 @@ err_t plot_contourf(grm_args_t *subplot_args) args_first_value(*current_series, "x", "D", &x, &x_length); args_first_value(*current_series, "y", "D", &y, &y_length); args_first_value(*current_series, "z", "D", &z, &z_length); - if ((error = plot_draw_colorbar(subplot_args, 0.0, num_levels)) != NO_ERROR) + if ((error = plot_draw_colorbar(subplot_args, 0.0, num_levels)) != ERROR_NONE) { goto cleanup; } @@ -3486,7 +3486,7 @@ err_t plot_hexbin(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } err_t plot_heatmap(grm_args_t *subplot_args) @@ -3496,7 +3496,7 @@ err_t plot_heatmap(grm_args_t *subplot_args) int icmap[256], *rgba = NULL, *data = NULL, zlog = 0; unsigned int i, cols, rows, z_length; double *x = NULL, *y = NULL, *z, x_min, x_max, y_min, y_max, z_min, z_max, c_min, c_max, zv; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "A", ¤t_series); args_values(subplot_args, "kind", "s", &kind); @@ -3670,7 +3670,7 @@ err_t plot_marginalheatmap(grm_args_t *subplot_args) double *bins = NULL; unsigned int num_bins_x = 0, num_bins_y = 0, n = 0; double *xi, *yi, *plot; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; plot_heatmap(subplot_args); @@ -3805,7 +3805,7 @@ err_t plot_wireframe(grm_args_t *subplot_args) { double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "A", ¤t_series); while (*current_series != NULL) @@ -3860,7 +3860,7 @@ err_t plot_surface(grm_args_t *subplot_args) { double *gridit_x = NULL, *gridit_y = NULL, *gridit_z = NULL; grm_args_t **current_series; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "A", ¤t_series); while (*current_series != NULL) @@ -3929,7 +3929,7 @@ err_t plot_plot3(grm_args_t *subplot_args) } plot_draw_axes(subplot_args, 2); - return NO_ERROR; + return ERROR_NONE; } err_t plot_scatter3(grm_args_t *subplot_args) @@ -3975,7 +3975,7 @@ err_t plot_scatter3(grm_args_t *subplot_args) } plot_draw_axes(subplot_args, 2); - return NO_ERROR; + return ERROR_NONE; } err_t plot_imshow(grm_args_t *subplot_args) @@ -4060,7 +4060,7 @@ err_t plot_imshow(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } /* @@ -4256,7 +4256,7 @@ err_t plot_isosurface(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } err_t plot_volume(grm_args_t *subplot_args) @@ -4341,7 +4341,7 @@ err_t plot_volume(grm_args_t *subplot_args) error = plot_draw_colorbar(subplot_args, 0.0, 256); return_if_error; - return NO_ERROR; + return ERROR_NONE; } err_t plot_polar(grm_args_t *subplot_args) @@ -4390,7 +4390,7 @@ err_t plot_polar(grm_args_t *subplot_args) ++current_series; } - return NO_ERROR; + return ERROR_NONE; } @@ -4510,7 +4510,7 @@ err_t plot_polar_histogram(grm_args_t *subplot_args) int freeable_bin_widths = 0; int freeable_bin_edges = 0; int freeable_angles = 0; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; gr_inqresamplemethod(&resample); gr_setresamplemethod(0x2020202); @@ -5458,7 +5458,7 @@ err_t plot_pie(grm_args_t *subplot_args) char text[80]; const char *title; unsigned int i; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "a", &series); /* series exists always */ @@ -5534,7 +5534,7 @@ err_t plot_trisurf(grm_args_t *subplot_args) plot_draw_axes(subplot_args, 2); plot_draw_colorbar(subplot_args, 0.05, 256); - return NO_ERROR; + return ERROR_NONE; } err_t plot_tricont(grm_args_t *subplot_args) @@ -5573,7 +5573,7 @@ err_t plot_tricont(grm_args_t *subplot_args) plot_draw_colorbar(subplot_args, 0.05, 256); free(levels); - return NO_ERROR; + return ERROR_NONE; } err_t plot_shade(grm_args_t *subplot_args) @@ -5608,14 +5608,14 @@ err_t plot_shade(grm_args_t *subplot_args) } gr_shadepoints(point_count, components[0], components[1], xform, xbins, ybins); - return NO_ERROR; + return ERROR_NONE; } err_t plot_raw(grm_args_t *plot_args) { const char *base64_data = NULL; char *graphics_data = NULL; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; cleanup_and_set_error_if(!args_values(plot_args, "raw", "s", &base64_data), ERROR_PLOT_MISSING_DATA); graphics_data = base64_decode(NULL, base64_data, NULL, &error); @@ -5783,7 +5783,7 @@ err_t plot_draw_axes(grm_args_t *args, unsigned int pass) } } - return NO_ERROR; + return ERROR_NONE; } err_t plot_draw_polar_axes(grm_args_t *args) @@ -5933,7 +5933,7 @@ err_t plot_draw_polar_axes(grm_args_t *args) gr_restorestate(); } - return NO_ERROR; + return ERROR_NONE; } err_t plot_draw_legend(grm_args_t *subplot_args) @@ -6051,7 +6051,7 @@ err_t plot_draw_legend(grm_args_t *subplot_args) gr_selntran(1); gr_restorestate(); - return NO_ERROR; + return ERROR_NONE; } err_t plot_draw_pie_legend(grm_args_t *subplot_args) @@ -6107,7 +6107,7 @@ err_t plot_draw_pie_legend(grm_args_t *subplot_args) gr_selntran(1); gr_restorestate(); - return NO_ERROR; + return ERROR_NONE; } err_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int colors) @@ -6177,7 +6177,7 @@ err_t plot_draw_colorbar(grm_args_t *subplot_args, double off, unsigned int colo free(data); gr_restorestate(); - return NO_ERROR; + return ERROR_NONE; } err_t extract_multi_type_argument(grm_args_t *error_container, const char *key, unsigned int x_length, @@ -6192,7 +6192,7 @@ err_t extract_multi_type_argument(grm_args_t *error_container, const char *key, arg_ptr = args_at(error_container, key); if (!arg_ptr) { - return NO_ERROR; + return ERROR_NONE; } if (strcmp(arg_ptr->value_format, "nDnD") == 0) { @@ -6213,7 +6213,7 @@ err_t extract_multi_type_argument(grm_args_t *error_container, const char *key, *downwards_flt = *upwards_flt = **downwards; *downwards = NULL; *downwards_length = 0; - return NO_ERROR; + return ERROR_NONE; } return_error_if(*downwards_length != x_length, ERROR_PLOT_COMPONENT_LENGTH_MISMATCH); *upwards = *downwards; @@ -6235,7 +6235,7 @@ err_t extract_multi_type_argument(grm_args_t *error_container, const char *key, return_error_if(!args_values(error_container, key, "i", &i), ERROR_INTERNAL); *upwards_flt = *downwards_flt = (double)i; } - return NO_ERROR; + return ERROR_NONE; } err_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_length, double *y, const char *kind) @@ -6259,7 +6259,7 @@ err_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_len arg_ptr = args_at(series_args, "error"); if (!arg_ptr) { - return NO_ERROR; + return ERROR_NONE; } error_container = NULL; if (strcmp(arg_ptr->value_format, "a") == 0 || strcmp(arg_ptr->value_format, "nA") == 0) @@ -6365,7 +6365,7 @@ err_t plot_draw_errorbars(grm_args_t *series_args, double *x, unsigned int x_len } gr_restorestate(); - return NO_ERROR; + return ERROR_NONE; } @@ -7050,7 +7050,7 @@ err_t classes_polar_histogram(grm_args_t *subplot_args, double *r_max) grm_args_t **series; - err_t error = NO_ERROR; + err_t error = ERROR_NONE; args_values(subplot_args, "series", "A", &series); @@ -7982,12 +7982,12 @@ void grm_finalize(void) int grm_clear(void) { - if (plot_init_static_variables() != NO_ERROR) + if (plot_init_static_variables() != ERROR_NONE) { return 0; } grm_args_clear(active_plot_args); - if (plot_init_args_structure(active_plot_args, plot_hierarchy_names + 1, 1) != NO_ERROR) + if (plot_init_args_structure(active_plot_args, plot_hierarchy_names + 1, 1) != ERROR_NONE) { return 0; } @@ -8014,13 +8014,13 @@ int grm_merge(const grm_args_t *args) int grm_merge_extended(const grm_args_t *args, int hold, const char *identificator) { - if (plot_init_static_variables() != NO_ERROR) + if (plot_init_static_variables() != ERROR_NONE) { return 0; } if (args != NULL) { - if (plot_merge_args(global_root_args, args, NULL, NULL, hold) != NO_ERROR) + if (plot_merge_args(global_root_args, args, NULL, NULL, hold) != ERROR_NONE) { return 0; } @@ -8064,7 +8064,7 @@ int grm_plot(const grm_args_t *args) args_values(active_plot_args, "subplots", "A", ¤t_subplot_args); while (*current_subplot_args != NULL) { - if (plot_pre_subplot(*current_subplot_args) != NO_ERROR) + if (plot_pre_subplot(*current_subplot_args) != ERROR_NONE) { return 0; } @@ -8074,7 +8074,7 @@ int grm_plot(const grm_args_t *args) { return 0; } - if (plot_func(*current_subplot_args) != NO_ERROR) + if (plot_func(*current_subplot_args) != ERROR_NONE) { return 0; }; @@ -8102,12 +8102,12 @@ int grm_switch(unsigned int id) grm_args_t **args_array = NULL; unsigned int args_array_length = 0; - if (plot_init_static_variables() != NO_ERROR) + if (plot_init_static_variables() != ERROR_NONE) { return 0; } - if (plot_init_args_structure(global_root_args, plot_hierarchy_names, id + 1) != NO_ERROR) + if (plot_init_args_structure(global_root_args, plot_hierarchy_names, id + 1) != ERROR_NONE) { return 0; } diff --git a/lib/grm/src/grm/util_int.h b/lib/grm/src/grm/util_int.h index 5e83abe51..607f7d69a 100644 --- a/lib/grm/src/grm/util_int.h +++ b/lib/grm/src/grm/util_int.h @@ -47,7 +47,7 @@ extern "C" { } \ } \ while (0) -#define return_if_error return_error_if((error) != NO_ERROR, (error)) +#define return_if_error return_error_if((error) != ERROR_NONE, (error)) #define goto_if(condition, goto_label) \ do \ { \ @@ -62,7 +62,7 @@ extern "C" { #define goto_if_error(goto_label) \ do \ { \ - if ((error) != NO_ERROR) \ + if ((error) != ERROR_NONE) \ { \ logger((stderr, "Got error \"%d\" (\"%s\")!\n", (error), error_names[(error)])); \ goto goto_label; \ From d23cb3bfc164d6842ff5b88c78a1c71a3233a423 Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Thu, 5 May 2022 15:49:16 +0200 Subject: [PATCH 10/26] Update the CI jobs to support C++17 --- .gitlab-ci.yml | 309 ++++++++++++++++++++------------------ lib/gks/qt/makefile.mingw | 4 +- 2 files changed, 163 insertions(+), 150 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9c58d4a3d..aafdba9ff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ stages: tag-type-check: stage: prebuild - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/deploy + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/deploy only: - tags@Scientific-IT-Systems/gr script: @@ -16,7 +16,7 @@ tag-type-check: code-style-check: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - set +e - for file in $(git diff $(git describe --tags --abbrev=0) HEAD --name-only --diff-filter=ACMR); do @@ -50,11 +50,11 @@ code-style-check: ubuntu-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make self GRDIR=/usr/local/gr - mkdir artifacts - cp lib/gks/demo artifacts/gksdemo @@ -66,19 +66,19 @@ ubuntu-self-contained: - mkdir artifacts/include/ - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - cp -r lib/grm/include/grm artifacts/include/ - - mv artifacts artifacts-ubuntu1604 + - mv artifacts artifacts-ubuntu2004 artifacts: expire_in: 1 week paths: - - artifacts-ubuntu1604/ + - artifacts-ubuntu2004/ ubuntu-cmake-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/ubuntu-self-contained + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/ubuntu-self-contained script: - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras - mkdir build - cd build @@ -86,11 +86,11 @@ ubuntu-cmake-self-contained: - make - make install - cd .. - - mv install artifacts-ubuntu1604-cmake + - mv install artifacts-ubuntu2004-cmake artifacts: expire_in: 1 week paths: - - artifacts-ubuntu1604-cmake/ + - artifacts-ubuntu2004-cmake/ ubuntu-cmake-self-contained-test: stage: test @@ -106,7 +106,7 @@ ubuntu-cmake-self-contained-test: needs: - ubuntu-cmake-self-contained script: - - export GRDIR=`pwd`/artifacts-ubuntu1604-cmake/ + - export GRDIR=`pwd`/artifacts-ubuntu2004-cmake/ - gr_test c `pwd`/test_result/ artifacts: paths: @@ -126,7 +126,7 @@ ubuntu-cmake-self-contained-rebuild-images: needs: - ubuntu-cmake-self-contained script: - - export GRDIR=`pwd`/artifacts-ubuntu1604-cmake/ + - export GRDIR=`pwd`/artifacts-ubuntu2004-cmake/ - mkdir -p ~/.ssh - cat $SSH_KEY | base64 -d > ~/.ssh/id_rsa @@ -156,19 +156,19 @@ ubuntu-cmake-self-contained-rebuild-images: ubuntu-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - make install GRDIR=/usr/local/gr ubuntu-cmake-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/ubuntu-system-dependencies + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/ubuntu-system-dependencies script: - apt-get update - - apt-get install -y libqhull-dev libbz2-dev libavdevice-dev libtheora-dev libogg-dev libvpx-dev libfreetype6-dev - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - apt-get install -y libqhull-dev libbz2-dev libjpeg-turbo8-dev libavdevice-dev libtheora-dev libogg-dev libvpx-dev libfreetype6-dev + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - mkdir build - cd build - $CMAKE_CMD .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -DGR_USE_BUNDLED_LIBRARIES=OFF @@ -176,11 +176,11 @@ ubuntu-cmake-system-dependencies: debian-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make self GRDIR=/usr/local/gr - mkdir artifacts - cp lib/gks/demo artifacts/gksdemo @@ -192,19 +192,19 @@ debian-self-contained: - mkdir artifacts/include/ - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - cp -r lib/grm/include/grm artifacts/include/ - - mv artifacts artifacts-debian9 + - mv artifacts artifacts-debian10 artifacts: expire_in: 1 week paths: - - artifacts-debian9/ + - artifacts-debian10/ debian-cmake-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/debian-self-contained + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/debian-self-contained script: - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras - mkdir build - cd build @@ -212,15 +212,15 @@ debian-cmake-self-contained: - make - make install - cd .. - - mv install artifacts-debian9-cmake + - mv install artifacts-debian10-cmake artifacts: expire_in: 1 week paths: - - artifacts-debian9-cmake/ + - artifacts-debian10-cmake/ debian-self-contained-armhf: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME-cross + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME-cross script: - make -C 3rdparty default extras \ HOST=arm-linux-gnueabihf \ @@ -260,15 +260,15 @@ debian-self-contained-armhf: - mkdir artifacts/include/ - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - cp -r lib/grm/include/grm artifacts/include/ - - mv artifacts artifacts-debian9-armhf + - mv artifacts artifacts-debian10-armhf artifacts: expire_in: 1 week paths: - - artifacts-debian9-armhf/ + - artifacts-debian10-armhf/ debian-self-contained-aarch64: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/debian-self-contained-aarch64 + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/debian-self-contained-aarch64 script: - make -C 3rdparty default extras \ HOST=aarch64-linux-gnu \ @@ -307,15 +307,15 @@ debian-self-contained-aarch64: - mkdir artifacts/include/ - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - cp -r lib/grm/include/grm artifacts/include/ - - mv artifacts artifacts-debian9-aarch64 + - mv artifacts artifacts-debian10-aarch64 artifacts: expire_in: 1 week paths: - - artifacts-debian9-aarch64/ + - artifacts-debian10-aarch64/ debian-cmake-self-contained-aarch64: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/debian-self-contained-aarch64 + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/debian-self-contained-aarch64 script: - make -C 3rdparty default extras \ HOST=aarch64-linux-gnu \ @@ -340,15 +340,15 @@ debian-cmake-self-contained-aarch64: - cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/gr -DCMAKE_TOOLCHAIN_FILE=../cmake/aarch64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -DGR_USE_BUNDLED_LIBRARIES=ON - make - make install - - mv /usr/local/gr ${CI_PROJECT_DIR}/artifacts-debian9-cmake-aarch64 + - mv /usr/local/gr ${CI_PROJECT_DIR}/artifacts-debian10-cmake-aarch64 artifacts: expire_in: 1 week paths: - - artifacts-debian9-cmake-aarch64/ + - artifacts-debian10-cmake-aarch64/ debian-cmake-self-contained-armhf: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/debian-self-contained-armhf-cross + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/debian-self-contained-armhf-cross script: - make -C 3rdparty default extras \ HOST=arm-linux-gnueabihf \ @@ -373,21 +373,21 @@ debian-cmake-self-contained-armhf: - cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/gr -DCMAKE_TOOLCHAIN_FILE=../cmake/armhf-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -DGR_USE_BUNDLED_LIBRARIES=ON - make - make install - - mv /usr/local/gr ${CI_PROJECT_DIR}/artifacts-debian9-cmake-armhf + - mv /usr/local/gr ${CI_PROJECT_DIR}/artifacts-debian10-cmake-armhf artifacts: expire_in: 1 week paths: - - artifacts-debian9-cmake-armhf/ + - artifacts-debian10-cmake-armhf/ debian-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - make install GRDIR=/usr/local/gr debian-system-dependencies-armhf: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME-cross + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME-cross script: - make install \ CC=arm-linux-gnueabihf-gcc \ @@ -402,13 +402,13 @@ debian-system-dependencies-armhf: debian-cmake-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/debian-system-dependencies + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/debian-system-dependencies script: - apt-get update - apt-get install -y libqhull-dev libbz2-dev libfreetype6-dev - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - mkdir build - cd build - $CMAKE_CMD .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -DGR_USE_BUNDLED_LIBRARIES=OFF @@ -416,11 +416,12 @@ debian-cmake-system-dependencies: centos7-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - source /opt/rh/devtoolset-8/enable + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make self GRDIR=/usr/local/gr - mkdir artifacts - cp lib/gks/demo artifacts/gksdemo @@ -440,11 +441,12 @@ centos7-self-contained: centos7-cmake-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/centos7-self-contained + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/centos7-self-contained script: - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - source /opt/rh/devtoolset-8/enable + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras - mkdir build - cd build @@ -461,18 +463,20 @@ centos7-cmake-self-contained: centos7-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: + - source /opt/rh/devtoolset-8/enable - make install GRDIR=/usr/local/gr centos7-cmake-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/centos7-system-dependencies + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/centos7-system-dependencies script: + - source /opt/rh/devtoolset-8/enable - yum install -y libjpeg-turbo-devel libtiff-devel bzip2-devel - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default TARGETS="qhull" - mkdir build - cd build @@ -481,13 +485,15 @@ centos7-cmake-system-dependencies: centos7-32bit-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-i386.tar.gz - - tar xf cmake-3.6.3-Linux-i386.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-i386/bin/cmake + - source /opt/gcc-8.5.0/enable + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-i386.tar.gz + - tar xf cmake-3.23.0-linux-i386.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-i386/bin/cmake - THEORA_EXTRA_CONFIGURE_FLAGS=--disable-asm OPENH264_EXTRA_MAKE_FLAGS=ARCH=i386 + EXTRA_LDFLAGS="-static-libstdc++ -static-libgcc" make self GRDIR=/usr/local/gr - mkdir artifacts - cp lib/gks/demo artifacts/gksdemo @@ -508,17 +514,19 @@ centos7-32bit-self-contained: centos7-32bit-cmake-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/centos7-32bit-self-contained + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/centos7-32bit-self-contained script: - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-i386.tar.gz - - tar xf cmake-3.6.3-Linux-i386.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-i386/bin/cmake + - source /opt/gcc-8.5.0/enable + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-i386.tar.gz + - tar xf cmake-3.23.0-linux-i386.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-i386/bin/cmake - THEORA_EXTRA_CONFIGURE_FLAGS=--disable-asm OPENH264_EXTRA_MAKE_FLAGS=ARCH=i386 make -C 3rdparty default extras - mkdir build - cd build - - $CMAKE_CMD .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -DGR_USE_BUNDLED_LIBRARIES=ON + - LDFLAGS="-static-libstdc++ -static-libgcc" + $CMAKE_CMD .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -DGR_USE_BUNDLED_LIBRARIES=ON - make - make install - cd .. @@ -530,27 +538,31 @@ centos7-32bit-cmake-self-contained: centos7-32bit-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - make install GRDIR=/usr/local/gr + - source /opt/gcc-8.5.0/enable + - EXTRA_LDFLAGS="-static-libstdc++ -static-libgcc" + make install GRDIR=/usr/local/gr centos7-32bit-cmake-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/centos7-32bit-system-dependencies + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/centos7-32bit-system-dependencies script: + - source /opt/gcc-8.5.0/enable - yum install -y libtiff-devel bzip2-devel - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-i386.tar.gz - - tar xf cmake-3.6.3-Linux-i386.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-i386/bin/cmake + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-i386.tar.gz + - tar xf cmake-3.23.0-linux-i386.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-i386/bin/cmake - make -C 3rdparty default TARGETS="qhull" - mkdir build - cd build - - $CMAKE_CMD .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -DGR_USE_BUNDLED_LIBRARIES=ON + - LDFLAGS="-static-libstdc++ -static-libgcc" + $CMAKE_CMD .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install -DGR_USE_BUNDLED_LIBRARIES=ON - make arch-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - make self GRDIR=/usr/local/gr - mkdir artifacts @@ -571,7 +583,7 @@ arch-self-contained: arch-cmake-self-contained: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/arch-self-contained + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/arch-self-contained script: - make -C 3rdparty default extras - mkdir build @@ -588,13 +600,13 @@ arch-cmake-self-contained: arch-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - make install GRDIR=/usr/local/gr arch-cmake-system-dependencies: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/arch-system-dependencies + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/arch-system-dependencies script: - pacman -Sy - pacman -S --noconfirm --needed qhull @@ -632,11 +644,11 @@ freebsd-self-contained: windows-32bit-cross: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras EXTRAS="tiff ogg theora vpx ffmpeg pixman cairo agg" HOST=i686-w64-mingw32 @@ -672,7 +684,7 @@ windows-32bit-cross: lib/gr/libGR.dll lib/gr/libGR.a lib/gr3/libGR3.dll lib/gr3/libGR3.a lib/grm/libGRM.dll lib/grm/libGRM.a artifacts/ - cp -r lib/gks/fonts artifacts/ - - cp /usr/lib/gcc/i686-w64-mingw32/6.3-win32/libgcc_s_sjlj-1.dll artifacts/ + - cp /usr/lib/gcc/i686-w64-mingw32/8.3-win32/libgcc_s_sjlj-1.dll artifacts/ - mkdir artifacts/include/ - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - cp -r lib/grm/include/grm artifacts/include/ @@ -684,16 +696,16 @@ windows-32bit-cross: windows-32bit-cmake-cross: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/windows-32bit-cross + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/windows-32bit-cross script: - mkdir qt5-runtime-Windows-i686 - cd qt5-runtime-Windows-i686 - - wget https://gr-framework.org/downloads/3rdparty/qt5-runtime-Windows-i686.tar.gz - - tar xf qt5-runtime-Windows-i686.tar.gz + - wget https://gr-framework.org/downloads/3rdparty/qt5-runtime-Windows-i686-mingw81.tar.gz + - tar xf qt5-runtime-Windows-i686-mingw81.tar.gz - cd .. - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras EXTRAS="tiff ogg theora vpx ffmpeg pixman cairo agg" HOST=i686-w64-mingw32 @@ -719,7 +731,7 @@ windows-32bit-cmake-cross: - cd .. - mv qt5-runtime-Windows-i686/*.dll install/bin/ - mv qt5-runtime-Windows-i686/platforms install/bin/platforms - - cp /usr/lib/gcc/i686-w64-mingw32/6.3-win32/libgcc_s_sjlj-1.dll install/bin/ + - cp /usr/lib/gcc/i686-w64-mingw32/8.3-win32/libgcc_s_sjlj-1.dll install/bin/ - mv install artifacts-windows-32bit-cmake artifacts: expire_in: 1 week @@ -728,11 +740,11 @@ windows-32bit-cmake-cross: windows-64bit-cross: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras EXTRAS="tiff ogg theora vpx openh264 ffmpeg pixman cairo agg" HOST=x86_64-w64-mingw32 @@ -768,7 +780,7 @@ windows-64bit-cross: lib/gr/libGR.dll lib/gr/libGR.a lib/gr3/libGR3.dll lib/gr3/libGR3.a lib/grm/libGRM.dll lib/grm/libGRM.a artifacts/ - cp -r lib/gks/fonts artifacts/ - - cp /usr/lib/gcc/x86_64-w64-mingw32/6.3-win32/libgcc_s_seh-1.dll artifacts/ + - cp /usr/lib/gcc/x86_64-w64-mingw32/8.3-win32/libgcc_s_seh-1.dll artifacts/ - mkdir artifacts/include/ - cp lib/gks/gks.h lib/gr/gr.h lib/gr3/gr3.h lib/grm/include/grm.h lib/gr/qtgr/grwidget.h artifacts/include/ - cp -r lib/grm/include/grm artifacts/include/ @@ -780,16 +792,16 @@ windows-64bit-cross: windows-64bit-cmake-cross: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/windows-64bit-cross + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/windows-64bit-cross script: - mkdir qt5-runtime-Windows-x86_64 - cd qt5-runtime-Windows-x86_64 - - wget https://gr-framework.org/downloads/3rdparty/qt5-runtime-Windows-x86_64.tar.gz - - tar xf qt5-runtime-Windows-x86_64.tar.gz + - wget https://gr-framework.org/downloads/3rdparty/qt5-runtime-Windows-x86_64-mingw81.tar.gz + - tar xf qt5-runtime-Windows-x86_64-mingw81.tar.gz - cd .. - - wget https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Linux-x86_64.tar.gz - - tar xf cmake-3.6.3-Linux-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake + - wget https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-linux-x86_64.tar.gz + - tar xf cmake-3.23.0-linux-x86_64.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-linux-x86_64/bin/cmake - make -C 3rdparty default extras EXTRAS="tiff ogg theora vpx openh264 ffmpeg pixman cairo agg" HOST=x86_64-w64-mingw32 @@ -815,7 +827,7 @@ windows-64bit-cmake-cross: - cd .. - mv qt5-runtime-Windows-x86_64/*.dll install/bin/ - mv qt5-runtime-Windows-x86_64/platforms install/bin/platforms - - cp /usr/lib/gcc/x86_64-w64-mingw32/6.3-win32/libgcc_s_seh-1.dll install/bin/ + - cp /usr/lib/gcc/x86_64-w64-mingw32/8.3-win32/libgcc_s_seh-1.dll install/bin/ - mv install artifacts-windows-64bit-cmake artifacts: expire_in: 1 week @@ -824,26 +836,27 @@ windows-64bit-cmake-cross: windows-64bit-cmake-msvc: stage: build - image: windows:10-gr-build + image: windows_cpp17:10-gr-build tags: - libvirt script: - vcvars_cmd cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/c/gr -DGR_USE_BUNDLED_LIBRARIES=OFF - vcvars_cmd cmake --build build --config Release - vcvars_cmd cmake --install build --config Release - - cd /c/Qt/5.15.2/msvc2015_64/bin + - cd /c/Qt/5.15.2/msvc2019_64/bin - cp -v Qt5Core.dll Qt5Gui.dll Qt5Widgets.dll Qt5Network.dll /c/gr/bin/ - cd - - cd /c/gr/bin - mkdir -p platforms - - cp -v /c/Qt/5.15.2/msvc2015_64/plugins/platforms/qwindows.dll platforms/ + - cp -v /c/Qt/5.15.2/msvc2019_64/plugins/platforms/qwindows.dll platforms/ - cd - - cd /c/local/bin - cp -v cairo.dll freetype.dll jpeg62.dll libpng16.dll pixman-1-0.dll qhull_r.dll tiff.dll tiffxx.dll turbojpeg.dll zlib.dll /c/gr/bin/ - cd - - - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.28.29325/x64/Microsoft.VC142.CRT/vcruntime140.dll" /c/gr/bin/ - - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.28.29325/x64/Microsoft.VC142.CRT/vcruntime140_1.dll" /c/gr/bin/ - - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Redist/MSVC/14.28.29325/x64/Microsoft.VC142.CRT/msvcp140.dll" /c/gr/bin/ + - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Redist/MSVC/14.31.31103/x64/Microsoft.VC143.CRT/vcruntime140.dll" /c/gr/bin/ + - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Redist/MSVC/14.31.31103/x64/Microsoft.VC143.CRT/vcruntime140_1.dll" /c/gr/bin/ + - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Redist/MSVC/14.31.31103/x64/Microsoft.VC143.CRT/msvcp140.dll" /c/gr/bin/ + - cp -v "/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Redist/MSVC/14.31.31103/x64/Microsoft.VC143.CRT/msvcp140_1.dll" /c/gr/bin/ - mv /c/gr artifacts-windows-64bit-cmake-msvc artifacts: expire_in: 1 week @@ -856,10 +869,10 @@ darwin-self-contained-iff1600: - branches@Scientific-IT-Systems/gr - tags@Scientific-IT-Systems/gr script: - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Darwin-x86_64.tar.gz - - tar xf cmake-3.6.3-Darwin-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Darwin-x86_64/CMake.app/Contents/bin/cmake - - export MACOSX_DEPLOYMENT_TARGET=10.11 + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-macos-universal.tar.gz + - tar xf cmake-3.23.0-macos-universal.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-macos-universal/CMake.app/Contents/bin/cmake + - export MACOSX_DEPLOYMENT_TARGET=10.14 - rm -rf /usr/local/gr/* - make self GRDIR=/usr/local/gr QMAKE=/usr/local/qt5/bin/qmake QT5_QMAKE=/usr/local/qt5/bin/qmake - mkdir artifacts @@ -899,7 +912,7 @@ darwin-self-contained: tags: - libvirt script: - - export MACOSX_DEPLOYMENT_TARGET=10.11 + - export MACOSX_DEPLOYMENT_TARGET=10.14 - sudo mkdir /usr/local/gr - sudo chown administrator:wheel /usr/local/gr - make self GRDIR=/usr/local/gr QMAKE=/usr/local/qt5/bin/qmake QT5_QMAKE=/usr/local/qt5/bin/qmake QT6_QMAKE=/usr/local/qt6/bin/qmake @@ -938,9 +951,9 @@ darwin-self-contained-iff1605: - branches@Scientific-IT-Systems/gr - tags@Scientific-IT-Systems/gr script: - - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.6.3-Darwin-x86_64.tar.gz - - tar xf cmake-3.6.3-Darwin-x86_64.tar.gz - - export CMAKE_CMD=`pwd`/cmake-3.6.3-Darwin-x86_64/CMake.app/Contents/bin/cmake + - curl -LO https://gr-framework.org/downloads/3rdparty/cmake-3.23.0-macos-universal.tar.gz + - tar xf cmake-3.23.0-macos-universal.tar.gz + - export CMAKE_CMD=`pwd`/cmake-3.23.0-macos-universal/CMake.app/Contents/bin/cmake - export MACOSX_DEPLOYMENT_TARGET=11.0 - rm -rf /usr/local/gr/* - make self GRDIR=/usr/local/gr QMAKE=/usr/local/qt5/bin/qmake QT5_QMAKE=/usr/local/qt5/bin/qmake @@ -977,7 +990,7 @@ darwin-self-contained-iff1605: emscripten: stage: build - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME script: - source /emsdk/emsdk_env.sh - emmake make -C js @@ -991,7 +1004,7 @@ emscripten: packages-tar: stage: package - image: ubuntu:16.04 + image: ubuntu:18.04 variables: GIT_STRATEGY: none script: @@ -1019,36 +1032,36 @@ packages-tar: - mv artifacts-windows-64bit-cmake-msvc Windows-x86_64-msvc/gr - mkdir -p Debian-x86_64/gr/bin - mkdir -p Debian-x86_64/gr/lib - - mv artifacts-debian9/*.so Debian-x86_64/gr/lib/ - - mv artifacts-debian9/gksqt Debian-x86_64/gr/bin/ - - mv artifacts-debian9/fonts Debian-x86_64/gr/ - - mv artifacts-debian9/include Debian-x86_64/gr/ + - mv artifacts-debian10/*.so Debian-x86_64/gr/lib/ + - mv artifacts-debian10/gksqt Debian-x86_64/gr/bin/ + - mv artifacts-debian10/fonts Debian-x86_64/gr/ + - mv artifacts-debian10/include Debian-x86_64/gr/ - cp artifacts-js/gr.js Debian-x86_64/gr/lib/ - - rm -rf artifacts-debian9 + - rm -rf artifacts-debian10 - mkdir -p Debian-armhf/gr/bin - mkdir -p Debian-armhf/gr/lib - - mv artifacts-debian9-armhf/*.so Debian-armhf/gr/lib/ - - mv artifacts-debian9-armhf/gksqt Debian-armhf/gr/bin/ - - mv artifacts-debian9-armhf/fonts Debian-armhf/gr/ - - mv artifacts-debian9-armhf/include Debian-armhf/gr/ + - mv artifacts-debian10-armhf/*.so Debian-armhf/gr/lib/ + - mv artifacts-debian10-armhf/gksqt Debian-armhf/gr/bin/ + - mv artifacts-debian10-armhf/fonts Debian-armhf/gr/ + - mv artifacts-debian10-armhf/include Debian-armhf/gr/ - cp artifacts-js/gr.js Debian-armhf/gr/lib/ - - rm -rf artifacts-debian9-armhf + - rm -rf artifacts-debian10-armhf - mkdir -p Debian-aarch64/gr/bin - mkdir -p Debian-aarch64/gr/lib - - mv artifacts-debian9-aarch64/*.so Debian-aarch64/gr/lib/ - - mv artifacts-debian9-aarch64/gksqt Debian-aarch64/gr/bin/ - - mv artifacts-debian9-aarch64/fonts Debian-aarch64/gr/ - - mv artifacts-debian9-aarch64/include Debian-aarch64/gr/ + - mv artifacts-debian10-aarch64/*.so Debian-aarch64/gr/lib/ + - mv artifacts-debian10-aarch64/gksqt Debian-aarch64/gr/bin/ + - mv artifacts-debian10-aarch64/fonts Debian-aarch64/gr/ + - mv artifacts-debian10-aarch64/include Debian-aarch64/gr/ - cp artifacts-js/gr.js Debian-aarch64/gr/lib/ - - rm -rf artifacts-debian9-aarch64 + - rm -rf artifacts-debian10-aarch64 - mkdir -p Ubuntu-x86_64/gr/bin - mkdir -p Ubuntu-x86_64/gr/lib - - mv artifacts-ubuntu1604/*.so Ubuntu-x86_64/gr/lib/ - - mv artifacts-ubuntu1604/gksqt Ubuntu-x86_64/gr/bin/ - - mv artifacts-ubuntu1604/fonts Ubuntu-x86_64/gr/ - - mv artifacts-ubuntu1604/include Ubuntu-x86_64/gr/ + - mv artifacts-ubuntu2004/*.so Ubuntu-x86_64/gr/lib/ + - mv artifacts-ubuntu2004/gksqt Ubuntu-x86_64/gr/bin/ + - mv artifacts-ubuntu2004/fonts Ubuntu-x86_64/gr/ + - mv artifacts-ubuntu2004/include Ubuntu-x86_64/gr/ - cp artifacts-js/gr.js Ubuntu-x86_64/gr/lib/ - - rm -rf artifacts-ubuntu1604 + - rm -rf artifacts-ubuntu2004 - mkdir -p CentOS-x86_64/gr/bin - mkdir -p CentOS-x86_64/gr/lib - mv artifacts-centos7/*.so CentOS-x86_64/gr/lib/ @@ -1173,7 +1186,7 @@ packages-tar: sync: stage: sync - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/deploy + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/deploy variables: GIT_STRATEGY: none only: @@ -1197,7 +1210,7 @@ sync: deploy-to-obs: stage: deploy - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME only: - develop@Scientific-IT-Systems/gr - tags@Scientific-IT-Systems/gr @@ -1224,7 +1237,7 @@ deploy-to-obs: deploy-to-aur: stage: deploy - image: iffregistry.fz-juelich.de/docker-images/gr-build-images/$CI_JOB_NAME + image: iffregistry.fz-juelich.de/imeyer/gr-build-images/$CI_JOB_NAME only: - develop@Scientific-IT-Systems/gr - tags@Scientific-IT-Systems/gr diff --git a/lib/gks/qt/makefile.mingw b/lib/gks/qt/makefile.mingw index 1079c5c04..796f37ac6 100644 --- a/lib/gks/qt/makefile.mingw +++ b/lib/gks/qt/makefile.mingw @@ -6,8 +6,8 @@ $(GKSLIB): $(MAKE) -C .. libGKS.lib gksqt.exe: gksqt.cxx gksserver.cxx gkswidget.cxx $(GKSLIB) - wget https://gr-framework.org/downloads/3rdparty/qt5-runtime-Windows-$(ARCHITECTURE).tar.gz - tar xzf qt5-runtime-Windows-$(ARCHITECTURE).tar.gz + wget https://gr-framework.org/downloads/3rdparty/qt5-runtime-Windows-$(ARCHITECTURE)-mingw81.tar.gz + tar xzf qt5-runtime-Windows-$(ARCHITECTURE)-mingw81.tar.gz moc -DGRDIR=\"$(GRDIR)\" -Iinclude gkswidget.h -o moc_gkswidget.cxx moc -DGRDIR=\"$(GRDIR)\" -Iinclude gksserver.h -o moc_gksserver.cxx rcc -o qrc_gksqt.cxx gksqt.qrc From f33412e39d3977626da813d1cec6c11dd7ff1096 Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 21 Oct 2022 20:07:27 +0200 Subject: [PATCH 11/26] [GRM CI] Fix the test stage - (Temporarily) use a fork of the `gr-test` repository to allow other test images. Otherwise, the binary artifacts of the Ubuntu 20.04 CI job could not be used (they do not run on Ubuntu 16.04 which is used in the upstream `gr-test` repository). - Install `gr-test` into a virtual environment: Editable installs into system directories are broken on newer `pip`/`setuptools` versions, so use a virtual environment instead. --- .gitlab-ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aafdba9ff..a7802388d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -94,7 +94,7 @@ ubuntu-cmake-self-contained: ubuntu-cmake-self-contained-test: stage: test - image: iffregistry.fz-juelich.de/scientific-it-systems/gr-test/c-testing + image: iffregistry.fz-juelich.de/imeyer/gr-test/c-testing rules: - if: '$CI_MERGE_REQUEST_ID' when: never @@ -115,7 +115,7 @@ ubuntu-cmake-self-contained-test: ubuntu-cmake-self-contained-rebuild-images: stage: test - image: iffregistry.fz-juelich.de/scientific-it-systems/gr-test/c-testing:latest + image: iffregistry.fz-juelich.de/imeyer/gr-test/c-testing:latest rules: - if: '$CI_MERGE_REQUEST_ID' when: never @@ -126,13 +126,15 @@ ubuntu-cmake-self-contained-rebuild-images: needs: - ubuntu-cmake-self-contained script: + - apt-get update && apt-get install -y python3-venv - export GRDIR=`pwd`/artifacts-ubuntu2004-cmake/ - mkdir -p ~/.ssh - cat $SSH_KEY | base64 -d > ~/.ssh/id_rsa - mv $SSH_KNOWN_HOSTS ~/.ssh/known_hosts - chmod 600 ~/.ssh/id_rsa - - git clone gitlab@iffgit.fz-juelich.de:Scientific-IT-Systems/gr-test.git + - python3 -m venv env && source env/bin/activate + - git clone gitlab@iffgit.fz-juelich.de:imeyer/gr-test.git - pip install -e gr-test/ - cd gr-test - git checkout -b update-files/job-$CI_JOB_ID From eb270ce05888927de1f45c4683bee789941c044b Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Wed, 12 Oct 2022 20:20:19 +0200 Subject: [PATCH 12/26] Fix GRM logging for streams not connected to a tty If the logging output stream is not a tty, the logged file, line number and function name were wrong. --- lib/grm/logging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index 16f89a3e3..aeae627bb 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -91,7 +91,7 @@ void logger1_(FILE *stream, const char *filename, int line_number, const char *c } else { - fprintf(stream, "%s:%d(%s): ", __FILE__, __LINE__, CURRENT_FUNCTION); + fprintf(stream, "%s:%d(%s): ", filename, line_number, current_function); } #endif } From 54bdbb77c05efa7503f41538f1b4732304758359 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Wed, 12 Oct 2022 15:57:44 +0200 Subject: [PATCH 13/26] Add debug output if desired Introduced two environment variables to optionally enable debug output - GR_DEBUG - enable debug output in GR, showing all function calls and function parameters - GKS_DEBUG - enable debug output in GKS, showing all function calls with involved output drivers and logging all file open/close operations --- lib/gks/gks.c | 159 ++++++++++++++++++++++-------------- lib/gks/gkscore.h | 4 + lib/gr/gr.c | 202 ++++++++++++++++++++++++---------------------- lib/gr/gr.h | 1 + lib/gr/stream.c | 19 +++-- 5 files changed, 221 insertions(+), 164 deletions(-) diff --git a/lib/gks/gks.c b/lib/gks/gks.c index 61a5205e1..570feb201 100644 --- a/lib/gks/gks.c +++ b/lib/gks/gks.c @@ -43,64 +43,65 @@ static int id = 0; static gks_list_t *open_ws = NULL, *active_ws = NULL, *av_ws_types = NULL; -static ws_descr_t ws_types[] = {{2, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 4, "mf", NULL}, - {3, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 5, "mf", NULL}, - {5, GKS_K_METERS, 1.00000, 1.00000, 32767, 32767, 3, NULL, NULL}, - {41, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {61, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {62, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {63, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {64, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL}, - {100, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {101, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL}, - {102, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL}, - {120, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL}, - {121, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL}, - {130, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "gif", NULL}, - {131, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "apng", NULL}, - {140, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL}, - {141, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {142, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {143, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {144, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL}, - {145, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "bmp", NULL}, - {146, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "tif", NULL}, - {150, GKS_K_METERS, 0.20320, 0.15240, 560, 420, 0, "six", NULL}, - {151, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL}, - {160, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mp4", NULL}, - {161, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "webm", NULL}, - {162, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "ogg", NULL}, - {170, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ppm", NULL}, - {171, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL}, - {172, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL}, - {173, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {210, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL}, - {211, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {212, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {213, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL}, - {214, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "rf", "GKS_RF"}, - {215, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", "GKS_GIF"}, - {216, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "uil", "GKS_UIL"}, - {217, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL}, - {218, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", NULL}, - {301, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL}, - {314, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "tex", NULL}, - {320, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {321, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {322, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {323, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL}, - {371, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {380, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {381, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}, - {382, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "svg", NULL}, - {390, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "wmf", NULL}, - {400, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {410, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {411, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {412, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {413, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {415, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL}, - {420, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL}}; +static ws_descr_t ws_types[] = { + {2, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 4, "mf", NULL, "MO"}, + {3, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536, 5, "mf", NULL, "MI"}, + {5, GKS_K_METERS, 1.00000, 1.00000, 32767, 32767, 3, NULL, NULL, "WISS"}, + {41, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "Windows GDI"}, + {61, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "PostScript"}, + {62, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "Color PostScript"}, + {63, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "PostScript (landscape)"}, + {64, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ps", NULL, "Color PostScript (landscape)"}, + {100, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "NULL"}, + {101, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL, "PDF"}, + {102, GKS_K_METERS, 0.28800, 0.19840, 810, 558, 0, "pdf", NULL, "PDF"}, + {120, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL, "QuickTime movie"}, + {121, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mov", NULL, "High DPI QuickTime movie"}, + {130, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "gif", NULL, "GIF"}, + {131, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "apng", NULL, "animated PNG"}, + {140, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL, "PNG"}, + {141, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Cairo X11"}, + {142, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Cairo Gtk"}, + {143, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "Cairo pixmap"}, + {144, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL, "Cairo JPEG"}, + {145, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "bmp", NULL, "Cairo BMP"}, + {146, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "tif", NULL, "Cairo TIFF"}, + {150, GKS_K_METERS, 0.20320, 0.15240, 560, 420, 0, "six", NULL, "Sixel"}, + {151, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL, "PNG"}, + {160, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "mp4", NULL, "MPEG-4"}, + {161, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "webm", NULL, "WEBM"}, + {162, GKS_K_METERS, 0.25400, 0.19050, 1440, 1080, 0, "ogg", NULL, "OGG"}, + {170, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "ppm", NULL, "Anti-Grain PPM"}, + {171, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "png", NULL, "Anti-Grain PNG"}, + {172, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL, "Anti-Grain JPEG"}, + {173, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "Anti-Grain pixmap"}, + {210, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL, "X11"}, + {211, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "X11"}, + {212, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "X drawable"}, + {213, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 2, NULL, NULL, "X widget"}, + {214, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "rf", "GKS_RF", "Sun rasterfile"}, + {215, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", "GKS_GIF", "X GIF"}, + {216, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "uil", "GKS_UIL", "X UIL"}, + {217, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL, "X pixmap"}, + {218, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, "gif", NULL, "GIF-89"}, + {301, GKS_K_METERS, 0.33300, 0.28100, 1024, 864, 0, NULL, NULL, "plugin"}, + {314, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "tex", NULL, "PGF"}, + {320, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript BMP"}, + {321, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript JPEG"}, + {322, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript PNG"}, + {323, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL, "GhostScript TIFF"}, + {371, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Gtk"}, + {380, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "WxWidgets"}, + {381, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "Qt"}, + {382, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "svg", NULL, "SVG"}, + {390, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "wmf", NULL, "WMF"}, + {400, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Quartz"}, + {410, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "socket"}, + {411, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Qt"}, + {412, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Qt (Cairo)"}, + {413, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "Qt (Agg)"}, + {415, GKS_K_METERS, 0.28560, 0.17850, 1280, 800, 0, NULL, NULL, "ZMQ"}, + {420, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, NULL, NULL, "OpenGL"}}; static int num_ws_types = sizeof(ws_types) / sizeof(ws_types[0]); @@ -179,6 +180,10 @@ static void gks_ddlk(int fctid, int dx, int dy, int dimx, int *i_arr, int len_f_ ptr = &ws->ptr; #ifndef EMSCRIPTEN + if (s->debug) + fprintf(stdout, "[DEBUG:GKS] dispatch %s function to %s driver (wtype: %d)\n", gks_function_name(fctid), + ws->name, ws->wtype); + switch (ws->wtype) { case 2: @@ -411,6 +416,8 @@ static void gks_parse_env(void) } if (gks_getenv("GKS_NO_EXIT_HANDLER") == NULL) atexit(gks_emergency_close); + + if (gks_getenv("GKS_DEBUG") != NULL) s->debug = 1; } void gks_set_encoding(int encoding) @@ -535,9 +542,17 @@ void gks_init_gks(void) s->aspect_ratio = 1; s->callback = NULL; + s->debug = 0; } } +int gks_debug(void) +{ + if (s != NULL) return s->debug; + + return 0; +} + void gks_open_gks(int errfil) { int i; @@ -596,6 +611,8 @@ void gks_close_gks(void) if (s->fontfile > 0) { /* close font database */ + if (s->debug) fprintf(stdout, "[DEBUG:GKS] close font database (fd=%d)\n", s->fontfile); + gks_close_font(s->fontfile); s->fontfile = 0; } @@ -620,7 +637,12 @@ static int open_file(char *name, int wtype) if (*name) { char *mode = wtype == GKS_K_WSTYPE_MI ? "r" : "w"; + + if (s->debug) fprintf(stdout, "[DEBUG:GKS] open file '%s' with mode '%c' ", name, *mode); + fd = gks_open_file(name, mode); + + if (s->debug) fprintf(stdout, "=> fd=%d\n", fd); } else fd = 1; @@ -669,8 +691,10 @@ void gks_open_ws(int wkid, char *path, int wtype) } else ws->path = gks_strdup(path); + ws->wtype = wtype; ws->conid = 0; + ws->name = descr->name; if (descr->env) { @@ -757,7 +781,13 @@ void gks_open_ws(int wkid, char *path, int wtype) { if (ws->conid && ws->conid != 1) if (ws->path) - if (*ws->path != '!') gks_close_file(ws->conid); + if (*ws->path != '!') + { + if (s->debug) + fprintf(stdout, "[DEBUG:GKS] close file '%s' (fd=%d)\n", ws->path, ws->conid); + + gks_close_file(ws->conid); + } if (ws->path) free(ws->path); @@ -817,7 +847,12 @@ void gks_close_ws(int wkid) if (ws->conid && ws->conid != 1) if (ws->path) - if (*ws->path != '!') gks_close_file(ws->conid); + if (*ws->path != '!') + { + if (s->debug) fprintf(stdout, "[DEBUG:GKS] close file '%s' (fd=%d)\n", ws->path, ws->conid); + + gks_close_file(ws->conid); + } if (ws->path) free(ws->path); @@ -1550,7 +1585,11 @@ void gks_set_text_fontprec(int font, int prec) if ((prec == GKS_K_TEXT_PRECISION_STROKE || prec == GKS_K_TEXT_PRECISION_CHAR) && s->fontfile == 0) { /* open font database */ + if (s->debug) fprintf(stdout, "[DEBUG:GKS] open font database "); + s->fontfile = gks_open_font(); + + if (s->debug) fprintf(stdout, "=> fd=%d\n", s->fontfile); } s->txfont = i_arr[0] = font; diff --git a/lib/gks/gkscore.h b/lib/gks/gkscore.h index e50609cce..60573a526 100644 --- a/lib/gks/gkscore.h +++ b/lib/gks/gkscore.h @@ -168,6 +168,7 @@ typedef struct int resize_behaviour; double aspect_ratio; char *(*callback)(const char *); + int debug; } gks_state_list_t; typedef struct gks_list @@ -185,6 +186,7 @@ typedef struct int conid; void *ptr; double vp[4]; + char *name; } ws_list_t; typedef struct @@ -196,6 +198,7 @@ typedef struct int wscat; char *type; char *env; + char *name; } ws_descr_t; typedef struct @@ -295,6 +298,7 @@ DLLEXPORT int gks_dl_read_item(char *dl, gks_state_list_t **gkss, void (*fn)(int fctid, int dx, int dy, int dimx, int *ia, int lr1, double *r1, int lr2, double *r2, int lc, char *chars, void **ptr)); void gks_wiss_dispatch(int fctid, int wkid, int segn); +int gks_debug(void); #ifndef EMSCRIPTEN diff --git a/lib/gr/gr.c b/lib/gr/gr.c index bd6ca0b00..5ec30cecd 100644 --- a/lib/gr/gr.c +++ b/lib/gr/gr.c @@ -276,6 +276,8 @@ static int autoinit = 1, double_buf = 0, state_saved = 0, def_color = 0; static const char *display = NULL; +static const char *debug = NULL; + static double vxmin = 0.2, vxmax = 0.9, vymin = 0.2, vymax = 0.9; static double cxl, cxr, cyf, cyb, czb, czt; @@ -284,7 +286,7 @@ static int arrow_style = 0; static double arrow_size = 1; -static int flag_printing = 0, flag_graphics = 0; +static int flag_printing = 0, flag_stream = 0, flag_graphics = 0; static text_node_t *text, *head; @@ -1411,6 +1413,9 @@ static void initialize(int state) if (display) if (*display == '\0') display = NULL; + debug = gks_getenv("GR_DEBUG"); + flag_stream = flag_graphics || debug != NULL; + setscale(options); } @@ -1481,7 +1486,7 @@ static void initgks(void) { gr_writestream(XML_HEADER); gr_writestream(GR_HEADER); - flag_graphics = 1; + flag_stream = flag_graphics = 1; } else fprintf(stderr, "%s: open failed\n", display); @@ -1514,6 +1519,11 @@ void gr_initgr(void) } } +int gr_debug() +{ + return debug != NULL; +} + void gr_opengks(void) { int errfil = 0; @@ -1691,7 +1701,7 @@ void gr_clearws(void) foreach_activews((void (*)(int, void *))clear, (void *)&clearflag); - if (flag_graphics) + if (flag_stream) { gr_writestream(GR_TRAILER); gr_flushstream(1); @@ -1721,7 +1731,7 @@ void gr_updatews(void) foreach_openws((void (*)(int, void *))update, (void *)®enflag); - if (flag_graphics) + if (flag_stream) if (display) { gr_writestream(GR_TRAILER); @@ -1872,7 +1882,7 @@ void gr_polyline(int n, double *x, double *y) polyline(n, x, y); - if (flag_graphics) primitive("polyline", n, x, y); + if (flag_stream) primitive("polyline", n, x, y); } static void polymarker(int n, double *x, double *y) @@ -1916,7 +1926,7 @@ void gr_polymarker(int n, double *x, double *y) polymarker(n, x, y); - if (flag_graphics) primitive("polymarker", n, x, y); + if (flag_stream) primitive("polymarker", n, x, y); } /*! @@ -1933,7 +1943,7 @@ void gr_fillarea(int n, double *x, double *y) { fillarea(n, x, y); - if (flag_graphics) primitive("fillarea", n, x, y); + if (flag_stream) primitive("fillarea", n, x, y); } /*! @@ -1963,7 +1973,7 @@ void gr_cellarray(double xmin, double xmax, double ymin, double ymax, int dimx, gks_cellarray(x_lin(xmin), y_lin(ymax), x_lin(xmax), y_lin(ymin), dimx, dimy, scol, srow, ncol, nrow, color); - if (flag_graphics) + if (flag_stream) { gr_writestream("ltype = type; - if (flag_graphics) gr_writestream("\n", type); + if (flag_stream) gr_writestream("\n", type); } void gr_inqlinetype(int *ltype) @@ -2966,7 +2976,7 @@ void gr_setlinewidth(double width) gks_set_pline_linewidth(width); if (ctx) ctx->lwidth = width; - if (flag_graphics) gr_writestream("\n", width); + if (flag_stream) gr_writestream("\n", width); } void gr_inqlinewidth(double *width) @@ -2990,7 +3000,7 @@ void gr_setlinecolorind(int color) gks_set_pline_color_index(color); if (ctx) ctx->plcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } void gr_inqlinecolorind(int *coli) @@ -3097,7 +3107,7 @@ void gr_setmarkertype(int type) gks_set_pmark_type(type); if (ctx) ctx->mtype = type; - if (flag_graphics) gr_writestream("\n", type); + if (flag_stream) gr_writestream("\n", type); } void gr_inqmarkertype(int *mtype) @@ -3124,7 +3134,7 @@ void gr_setmarkersize(double size) gks_set_pmark_size(size); if (ctx) ctx->mszsc = size; - if (flag_graphics) gr_writestream("\n", size); + if (flag_stream) gr_writestream("\n", size); } /*! @@ -3155,7 +3165,7 @@ void gr_setmarkercolorind(int color) gks_set_pmark_color_index(color); if (ctx) ctx->pmcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } void gr_inqmarkercolorind(int *coli) @@ -3278,7 +3288,7 @@ void gr_settextfontprec(int font, int precision) ctx->txprec = precision; } - if (flag_graphics) gr_writestream("\n", font, precision); + if (flag_stream) gr_writestream("\n", font, precision); } static int loadfont(char *name) @@ -3341,7 +3351,7 @@ void gr_loadfont(char *filename, int *font) } if (*font > 0) { - if (flag_graphics) gr_writestream("\n", filename); + if (flag_stream) gr_writestream("\n", filename); } } @@ -3363,7 +3373,7 @@ void gr_setcharexpan(double factor) gks_set_text_expfac(factor); if (ctx) ctx->chxp = factor; - if (flag_graphics) gr_writestream("\n", factor); + if (flag_stream) gr_writestream("\n", factor); } void gr_setcharspace(double spacing) @@ -3373,7 +3383,7 @@ void gr_setcharspace(double spacing) gks_set_text_spacing(spacing); if (ctx) ctx->chsp = spacing; - if (flag_graphics) gr_writestream("\n", spacing); + if (flag_stream) gr_writestream("\n", spacing); } /*! @@ -3391,7 +3401,7 @@ void gr_settextcolorind(int color) gks_set_text_color_index(color); if (ctx) ctx->txcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } /*! @@ -3423,7 +3433,7 @@ void gr_setcharheight(double height) gks_set_text_height(height); if (ctx) ctx->chh = height; - if (flag_graphics) gr_writestream("\n", height); + if (flag_stream) gr_writestream("\n", height); } void gr_setwscharheight(double chh, double height) @@ -3466,7 +3476,7 @@ void gr_setcharup(double ux, double uy) ctx->chup[1] = uy; } - if (flag_graphics) gr_writestream("\n", ux, uy); + if (flag_stream) gr_writestream("\n", ux, uy); } /*! @@ -3495,7 +3505,7 @@ void gr_settextpath(int path) gks_set_text_path(path); if (ctx) ctx->txp = path; - if (flag_graphics) gr_writestream("\n", path); + if (flag_stream) gr_writestream("\n", path); } /*! @@ -3547,7 +3557,7 @@ void gr_settextalign(int horizontal, int vertical) ctx->txal[1] = vertical; } - if (flag_graphics) gr_writestream("\n", horizontal, vertical); + if (flag_stream) gr_writestream("\n", horizontal, vertical); } /*! @@ -3580,7 +3590,7 @@ void gr_setfillintstyle(int style) gks_set_fill_int_style(style); if (ctx) ctx->ints = style; - if (flag_graphics) gr_writestream("\n", style); + if (flag_stream) gr_writestream("\n", style); } /*! @@ -3618,7 +3628,7 @@ void gr_setfillstyle(int index) gks_set_fill_style_index(index); if (ctx) ctx->styli = index; - if (flag_graphics) gr_writestream("\n", index); + if (flag_stream) gr_writestream("\n", index); } /*! @@ -3653,7 +3663,7 @@ void gr_setfillcolorind(int color) gks_set_fill_color_index(color); if (ctx) ctx->facoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } /*! @@ -3679,7 +3689,7 @@ void gr_setresizebehaviour(int flag) gks_set_resize_behaviour(flag); if (ctx) ctx->resize_behaviour = flag; - if (flag_graphics) gr_writestream("\n", flag); + if (flag_stream) gr_writestream("\n", flag); } void gr_inqresizebehaviour(int *flag) @@ -3726,7 +3736,7 @@ void gr_setcolorrep(int index, double red, double green, double blue) setcolorrep(index, red, green, blue); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", index, red, green, blue); } @@ -3785,7 +3795,7 @@ int gr_setscale(int options) result = setscale(options); if (ctx) ctx->scale_options = options; - if (flag_graphics) gr_writestream("\n", options); + if (flag_stream) gr_writestream("\n", options); return result; } @@ -3832,7 +3842,7 @@ void gr_setwindow(double xmin, double xmax, double ymin, double ymax) } setscale(lx.scale_options); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -3903,7 +3913,7 @@ void gr_setviewport(double xmin, double xmax, double ymin, double ymax) vymin = ymin; vymax = ymax; - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -3939,7 +3949,7 @@ void gr_selntran(int transform) gks_select_xform(transform); - if (flag_graphics) gr_writestream("\n", transform); + if (flag_stream) gr_writestream("\n", transform); } /*! @@ -3970,7 +3980,7 @@ void gr_setclip(int indicator) gks_set_clipping(indicator); - if (flag_graphics) gr_writestream("\n", indicator); + if (flag_stream) gr_writestream("\n", indicator); } static void wswindow(int workstation_id, rect_t *rect) @@ -4012,7 +4022,7 @@ void gr_setwswindow(double xmin, double xmax, double ymin, double ymax) foreach_activews((void (*)(int, void *))wswindow, (void *)&rect); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -4051,7 +4061,7 @@ void gr_setwsviewport(double xmin, double xmax, double ymin, double ymax) sizex = xmax - xmin; - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -4181,7 +4191,7 @@ int gr_setspace(double zmin, double zmax, int rotation, int tilt) setspace(zmin, zmax, rotation, tilt); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", zmin, zmax, rotation, tilt); return 0; @@ -4215,7 +4225,7 @@ void gr_setprojectiontype(int flag) { gpx.projection_type = flag; - if (flag_graphics) gr_writestream("\n", flag); + if (flag_stream) gr_writestream("\n", flag); } else { @@ -4315,7 +4325,7 @@ void gr_settransformationparameters(double camera_pos_x, double camera_pos_y, do settransformationparameters(camera_pos_x, camera_pos_y, camera_pos_z, up_x, up_y, up_z, focus_point_x, focus_point_y, focus_point_z); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", @@ -4355,7 +4365,7 @@ void gr_setperspectiveprojection(double near_plane, double far_plane, double fov setperspectiveprojection(near_plane, far_plane, fov); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", near_plane, far_plane, fov); } @@ -4392,7 +4402,7 @@ void gr_setorthographicprojection(double left, double right, double bottom, doub setorthographicprojection(left, right, bottom, top, near_plane, far_plane); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", left, right, bottom, top, near_plane, far_plane); @@ -4646,7 +4656,7 @@ int gr_textext(double x, double y, char *string) if (tnr != NDC) gks_select_xform(tnr); - if (flag_graphics) gr_writestream("\n", x, y, string); + if (flag_stream) gr_writestream("\n", x, y, string); return result; } @@ -4710,7 +4720,7 @@ void gr_setscientificformat(int format_option) scientific_format = format_option; } - if (flag_graphics) gr_writestream("\n", format_option); + if (flag_stream) gr_writestream("\n", format_option); } static void text2dlbl(double x, double y, char *chars, double value, void (*fp)(double, double, const char *, double)) @@ -5160,7 +5170,7 @@ void gr_axeslbl(double x_tick, double y_tick, double x_org, double y_org, int ma gks_set_text_upvec(chux, chuy); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", x_tick, y_tick, x_org, y_org, major_x, major_y, tick_size); @@ -5397,7 +5407,7 @@ void gr_grid(double x_tick, double y_tick, double x_org, double y_org, int major gks_set_pline_color_index(color); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", x_tick, y_tick, x_org, y_org, major_x, major_y); @@ -5717,7 +5727,7 @@ void gr_grid3d(double x_tick, double y_tick, double z_tick, double x_org, double gks_set_pline_color_index(color); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", @@ -5779,7 +5789,7 @@ void gr_verrorbars(int n, double *px, double *py, double *e1, double *e2) polymarker(n, px, py); - if (flag_graphics) + if (flag_stream) { gr_writestream(" 0) gks_polymarker(m, xpoint, ypoint); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", x, y, z, chars, axis); } @@ -7171,7 +7181,7 @@ void gr_axes3d(double x_tick, double y_tick, double z_tick, double x_org, double gks_set_text_upvec(chux, chuy); gks_set_clipping(clsw); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", @@ -7564,8 +7574,7 @@ void gr_titles3d(char *x_title, char *y_title, char *z_title) gks_set_text_upvec(chux, chuy); } - if (flag_graphics) - gr_writestream("\n", x_title, y_title, z_title); + if (flag_stream) gr_writestream("\n", x_title, y_title, z_title); if (modern_projection_type) { @@ -8366,7 +8375,7 @@ void gr_surface(int nx, int ny, double *px, double *py, double *pz, int option) gks_set_fill_int_style(int_style); gks_set_fill_color_index(coli); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", index); + if (flag_stream) gr_writestream("\n", index); } void gr_inqcolormap(int *index) @@ -9452,7 +9461,7 @@ void gr_colorbar(void) gks_set_text_align(halign, valign); gks_set_clipping(clsw); - if (flag_graphics) gr_writestream("\n"); + if (flag_stream) gr_writestream("\n"); } void gr_inqcolor(int color, int *rgb) @@ -10004,7 +10013,7 @@ void gr_drawrect(double xmin, double xmax, double ymin, double ymax) gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 5, codes); } - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -10053,7 +10062,7 @@ void gr_fillrect(double xmin, double xmax, double ymin, double ymax) gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 5, codes); } - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax); } @@ -10131,7 +10140,7 @@ void gr_drawarc(double xmin, double xmax, double ymin, double ymax, double a1, d gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 3, codes); } - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", @@ -10218,7 +10227,7 @@ void gr_fillarc(double xmin, double xmax, double ymin, double ymax, double a1, d gks_gdp(4, x, y, GKS_K_GDP_DRAW_PATH, 3, codes); } - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", @@ -10372,7 +10381,7 @@ void gr_drawpath(int n, vertex_t *vertices, unsigned char *codes, int fill) } closepath(fill); - if (flag_graphics) + if (flag_stream) { gr_writestream("= 1 && style <= 18) arrow_style = style - 1; - if (flag_graphics) gr_writestream("\n", style); + if (flag_stream) gr_writestream("\n", style); } /*! @@ -10454,7 +10463,7 @@ void gr_setarrowsize(double size) if (size > 0) arrow_size = size; - if (flag_graphics) gr_writestream("\n", size); + if (flag_stream) gr_writestream("\n", size); } /*! @@ -10553,7 +10562,7 @@ void gr_drawarrow(double x1, double y1, double x2, double y2) gks_set_fill_int_style(intstyle); gks_set_pline_linetype(ltype); - if (flag_graphics) gr_writestream("\n", x1, y1, x2, y2); + if (flag_stream) gr_writestream("\n", x1, y1, x2, y2); } static void drawimage_calculation(double xmin, double xmax, double ymin, double ymax, int width, int height, int *data, @@ -10676,7 +10685,7 @@ void gr_drawimage(double xmin, double xmax, double ymin, double ymax, int width, drawimage_calculation(xmin, xmax, ymin, ymax, width, height, data, model); - if (flag_graphics) + if (flag_stream) { n = width * height; gr_writestream("\n", x, y, string); + if (flag_stream) gr_writestream("\n", x, y, string); } void gr_inqmathtex(double x, double y, char *string, double *tbx, double *tby) @@ -11449,7 +11459,7 @@ void gr_text(double x, double y, char *string) if (tnr != NDC) gks_select_xform(tnr); - if (flag_graphics) gr_writestream("\n", x, y, string); + if (flag_stream) gr_writestream("\n", x, y, string); } /*! @@ -11493,7 +11503,7 @@ void gr_textx(double x, double y, char *string, int opts) if (tnr != NDC) gks_select_xform(tnr); - if (flag_graphics) gr_writestream("\n", x, y, string, opts); + if (flag_stream) gr_writestream("\n", x, y, string, opts); } void gr_inqtext(double x, double y, char *string, double *tbx, double *tby) @@ -11669,7 +11679,7 @@ void gr_savestate(void) else fprintf(stderr, "attempt to save state beyond implementation limit\n"); - if (flag_graphics) gr_writestream("\n"); + if (flag_stream) gr_writestream("\n"); } void gr_restorestate(void) @@ -11715,7 +11725,7 @@ void gr_restorestate(void) else fprintf(stderr, "attempt to restore unsaved state\n"); - if (flag_graphics) gr_writestream("\n"); + if (flag_stream) gr_writestream("\n"); } void gr_selectcontext(int context) @@ -11947,7 +11957,7 @@ int gr_uselinespec(char *linespec) gr_setlinecolorind(color); gr_setmarkercolorind(color); - if (flag_graphics) gr_writestream("\n", linespec); + if (flag_stream) gr_writestream("\n", linespec); return result; } @@ -12134,7 +12144,7 @@ void gr_shadepoints(int n, double *x, double *y, int xform, int w, int h) free(bins); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", start_mouse_pos_x, start_mouse_pos_y, end_mouse_pos_x, end_mouse_pos_y); @@ -12863,7 +12873,7 @@ void gr_setwindow3d(double xmin, double xmax, double ymin, double ymax, double z wx.zmin = zmin; wx.zmax = zmax; - if (flag_graphics) + if (flag_stream) gr_writestream("\n", xmin, xmax, ymin, ymax, zmin, zmax); } @@ -12896,7 +12906,7 @@ void gr_setscalefactors3d(double x_axis_scale, double y_axis_scale, double z_axi setscalefactors3d(x_axis_scale, y_axis_scale, z_axis_scale); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", x_axis_scale, y_axis_scale, z_axis_scale); } @@ -12923,7 +12933,7 @@ void gr_setborderwidth(double width) gks_set_border_width(width); if (ctx) ctx->bwidth = width; - if (flag_graphics) gr_writestream("\n", width); + if (flag_stream) gr_writestream("\n", width); } void gr_inqborderwidth(double *width) @@ -12947,7 +12957,7 @@ void gr_setbordercolorind(int color) gks_set_border_color_index(color); if (ctx) ctx->bcoli = color; - if (flag_graphics) gr_writestream("\n", color); + if (flag_stream) gr_writestream("\n", color); } void gr_inqbordercolorind(int *coli) @@ -12966,7 +12976,7 @@ void gr_selectclipxform(int tnr) gks_select_clip_xform(tnr); if (ctx) ctx->clip_tnr = tnr; - if (flag_graphics) gr_writestream("\n", tnr); + if (flag_stream) gr_writestream("\n", tnr); } void gr_inqclipxform(int *tnr) @@ -13040,7 +13050,7 @@ void gr_setspace3d(double phi, double theta, double fov, double cam) setscalefactors3d(scale_factor_x, scale_factor_y, scale_factor_z); - if (flag_graphics) + if (flag_stream) gr_writestream("\n", phi, theta, fov, cam); } @@ -13050,7 +13060,7 @@ void gr_settextencoding(int encoding) gks_set_encoding(encoding); - if (flag_graphics) gr_writestream("\n", encoding); + if (flag_stream) gr_writestream("\n", encoding); } void gr_inqtextencoding(int *encoding) @@ -13089,7 +13099,7 @@ void gr_setthreadnumber(int num) vt.max_threads = max(1, num); vt.thread_size = 10 * (1.0 / (2.0 * num)); - if (flag_graphics) gr_writestream("\n", num); + if (flag_stream) gr_writestream("\n", num); } /*! @@ -13106,7 +13116,7 @@ void gr_setpicturesizeforvolume(int width, int height) vt.picture_height = height; vt.picture_width = width; - if (flag_graphics) gr_writestream("\n", width, height); + if (flag_stream) gr_writestream("\n", width, height); } /*! @@ -13128,7 +13138,7 @@ void gr_setapproximativecalculation(int approximative_calculation) fprintf(stderr, "Invalid number for approximative_calculation. Valid numbers are 0 and 1.\n"); } - if (flag_graphics) + if (flag_stream) gr_writestream("\n", flag); + if (flag_stream) gr_writestream("\n", flag); } /*! @@ -14070,7 +14080,7 @@ void gr_cpubasedvolume(int nx, int ny, int nz, double *data, int algorithm, doub free(pixels); free(jobs); - if (flag_graphics) + if (flag_stream) { gr_writestream("\n", nx, ny, nz); print_float_array("data", nx * ny * nz, data); @@ -14185,7 +14195,7 @@ void gr_polygonmesh3d(int num_points, const double *px, const double *py, const free(y); free(x); - if (flag_graphics) + if (flag_stream) { gr_writestream(" Date: Fri, 14 Oct 2022 10:21:44 +0200 Subject: [PATCH 14/26] [GRM] Change `GR_DEBUG` in GRM to `GRM_DEBUG` for consistency Since commit 532832f035837a6a3379090edd7238b2fbf58bd0 GKS and GR debugging can be enabled with the environment variables `GKS_DEBUG` and `GR_DEBUG`. GR3 uses `GR3_DEBUG`. Therefore, use `GRM_DEBUG` in GRM instead of `GR_DEBUG` to be consistent with the other libraries. --- lib/grm/logging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index aeae627bb..f0dc7b530 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -31,7 +31,7 @@ static void logger_init(void); /* ========================= macros ================================================================================= */ -#define ENABLE_LOGGING_ENV_KEY "GR_DEBUG" +#define ENABLE_LOGGING_ENV_KEY "GRM_DEBUG" /* ========================= static variables ======================================================================= */ From 0acf01a412b970f0f21693bf382c7b3193f8023e Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 14 Oct 2022 10:39:21 +0200 Subject: [PATCH 15/26] [GRM] Always compile in logging messages With this commit, debug messages in GRM can always be enabled with the `GRM_DEBUG` environment variable regardless of the (CMake) compile mode (Debug or Release). --- lib/grm/logging.c | 12 ------------ lib/grm/logging_int.h | 6 ------ 2 files changed, 18 deletions(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index f0dc7b530..fabb74410 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -22,9 +22,7 @@ /* ========================= functions ============================================================================== */ -#ifndef NDEBUG static void logger_init(void); -#endif /* ######################### internal implementation ################################################################ */ @@ -36,16 +34,13 @@ static void logger_init(void); /* ========================= static variables ======================================================================= */ -#ifndef NDEBUG static int logging_enabled = -1; -#endif /* ========================= functions ============================================================================== */ /* ------------------------- logging -------------------------------------------------------------------------------- */ -#ifndef NDEBUG void logger_init(void) { if (logging_enabled < 0) @@ -55,7 +50,6 @@ void logger_init(void) str_equals_any(getenv(ENABLE_LOGGING_ENV_KEY), 7, "1", "on", "ON", "true", "TRUE", "yes", "YES")); } } -#endif /* ######################### public implementation ################################################################## */ @@ -66,15 +60,10 @@ void logger_init(void) int logger_enabled(void) { -#ifndef NDEBUG logger_init(); return logging_enabled; -#else - return 0; -#endif } -#ifndef NDEBUG void logger1_(FILE *stream, const char *filename, int line_number, const char *current_function) { logger_init(); @@ -110,4 +99,3 @@ void logger2_(FILE *stream, const char *format, ...) va_end(vl); } } -#endif diff --git a/lib/grm/logging_int.h b/lib/grm/logging_int.h index 52b15dc96..24cd89c73 100644 --- a/lib/grm/logging_int.h +++ b/lib/grm/logging_int.h @@ -12,7 +12,6 @@ /* ------------------------- logging -------------------------------------------------------------------------------- */ -#ifndef NDEBUG #define logger(logger_arguments) \ do \ { \ @@ -20,9 +19,6 @@ logger2_ logger_arguments; \ } \ while (0) -#else -#define logger(logger_arguments) -#endif /* ========================= functions ============================================================================== */ @@ -30,10 +26,8 @@ /* ------------------------- logging -------------------------------------------------------------------------------- */ int logger_enabled(void); -#ifndef NDEBUG void logger1_(FILE *stream, const char *filename, int line_number, const char *current_function); void logger2_(FILE *stream, const char *format, ...); -#endif #endif /* ifndef GRM_LOGGING_INT_H_INCLUDED */ From 737922b58fd046dc80a753a28ebe351bc3b4f59b Mon Sep 17 00:00:00 2001 From: Ingo Meyer Date: Fri, 14 Oct 2022 10:52:09 +0200 Subject: [PATCH 16/26] [GRM] Prefix logging messages with `[DEBUG:GRM]` --- lib/grm/logging.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/grm/logging.c b/lib/grm/logging.c index fabb74410..d7b0b4d91 100644 --- a/lib/grm/logging.c +++ b/lib/grm/logging.c @@ -71,16 +71,17 @@ void logger1_(FILE *stream, const char *filename, int line_number, const char *c if (logging_enabled) { #if defined(_WIN32) || defined(__EMSCRIPTEN__) - fprintf(stream, "%s:%d(%s): ", filename, line_number, current_function); + fprintf(stream, "[DEBUG:GRM] %s:%d(%s): ", filename, line_number, current_function); #else if (isatty(fileno(stream))) { - fprintf(stream, "\033[36m%s\033[0m:\033[33m%d\033[0m(\033[34m%s\033[0m): ", filename, line_number, - current_function); + fprintf(stream, + "\033[32;1m[DEBUG:GRM]\033[0m \033[36m%s\033[0m:\033[33m%d\033[0m(\033[34m%s\033[0m): ", filename, + line_number, current_function); } else { - fprintf(stream, "%s:%d(%s): ", filename, line_number, current_function); + fprintf(stream, "[DEBUG:GRM] %s:%d(%s): ", filename, line_number, current_function); } #endif } From 156d204f86b6ea8bd686d59edeec5970bc2e989c Mon Sep 17 00:00:00 2001 From: Jonas Moelle Date: Fri, 4 Nov 2022 11:18:56 +0100 Subject: [PATCH 17/26] Fixed memory leak in create_queues_and_pixmaps --- lib/gr3/gr3_sr.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/gr3/gr3_sr.c b/lib/gr3/gr3_sr.c index b93049404..fef5c4a80 100644 --- a/lib/gr3/gr3_sr.c +++ b/lib/gr3/gr3_sr.c @@ -230,12 +230,33 @@ static void create_queues_and_pixmaps(int width, int height) int i; for (i = 0; i < context_struct_.num_threads; i++) { + if (context_struct_.queues[i]) + { + queue_destroy(context_struct_.queues[i]); + } context_struct_.queues[i] = queue_new(); if (i != 0) { - context_struct_.pixmaps[i] = (unsigned char *)calloc(width * height * 4, sizeof(unsigned char)); + if (context_struct_.pixmaps[i]) + { + context_struct_.pixmaps[i] = + (unsigned char *)realloc(context_struct_.pixmaps[i], width * height * 4 * sizeof(unsigned char)); + memset(context_struct_.pixmaps[i], 0, width * height * 4 * sizeof(unsigned char)); + } + else + { + context_struct_.pixmaps[i] = (unsigned char *)calloc(width * height * 4, sizeof(unsigned char)); + } + } + if (context_struct_.depth_buffers[i]) + { + context_struct_.depth_buffers[i] = + (float *)realloc(context_struct_.depth_buffers[i], width * height * sizeof(float)); + } + else + { + context_struct_.depth_buffers[i] = (float *)malloc(width * height * sizeof(float)); } - context_struct_.depth_buffers[i] = (float *)malloc(width * height * sizeof(float)); } context_struct_.last_height = height; context_struct_.last_width = width; From 6f3a165e4a7b4a106336255faa58ff8f4a11efaa Mon Sep 17 00:00:00 2001 From: Daniel Kaiser Date: Fri, 4 Nov 2022 14:34:00 +0100 Subject: [PATCH 18/26] Fix race condition in threadpool implementation --- lib/gr/gr.c | 1 - lib/gr/threadpool.c | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/gr/gr.c b/lib/gr/gr.c index 5ec30cecd..8651ed76d 100644 --- a/lib/gr/gr.c +++ b/lib/gr/gr.c @@ -14053,7 +14053,6 @@ void gr_cpubasedvolume(int nx, int ny, int nz, double *data, int algorithm, doub y_start = 0; } #ifndef NO_THREADS - threadpool_add_work(tp, jobs + (i - 1) + (j - 1) * n_x); threadpool_destroy(tp); #endif diff --git a/lib/gr/threadpool.c b/lib/gr/threadpool.c index b4b1748b8..91cd04062 100644 --- a/lib/gr/threadpool.c +++ b/lib/gr/threadpool.c @@ -2,6 +2,8 @@ #define NO_THREADS 1 #endif #ifndef NO_THREADS +#include + #include "threadpool.h" #ifndef max @@ -99,13 +101,12 @@ void threadpool_add_work(threadpool_t *tp, void *arg) { pthread_mutex_lock(&(tp->work_mutex)); - if (next_work_item != NULL) - { - pthread_cond_wait(&(tp->work_fetched), &(tp->work_mutex)); - } + assert(next_work_item == NULL); next_work_item = arg; pthread_cond_signal(&(tp->wait_for_work_cond)); + /* wait until `next_work_item` is picked up by a worker thread before returning */ + pthread_cond_wait(&(tp->work_fetched), &(tp->work_mutex)); pthread_mutex_unlock(&(tp->work_mutex)); } From 189db357a29d27fc798b536dbc160b3802157d82 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Mon, 7 Nov 2022 15:48:39 +0100 Subject: [PATCH 19/26] Add missing function --- lib/gr/import.c | 126 +++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/lib/gr/import.c b/lib/gr/import.c index a312427b7..d5b3d8d9f 100644 --- a/lib/gr/import.c +++ b/lib/gr/import.c @@ -48,6 +48,7 @@ static char *format[] = { "polyline:iFF", "polyline3d:iFFF", "polymarker:iFF", + "polymarker3d:iFFF", "quiver:iiFFFFi", "restorestate:", "savestate:", @@ -375,190 +376,193 @@ static void gr(int id) gr_polymarker(i_arg[0], f_arr[0], f_arr[1]); break; case 28: - gr_quiver(i_arg[0], i_arg[1], f_arr[0], f_arr[1], f_arr[2], f_arr[3], i_arg[2]); + gr_polymarker3d(i_arg[0], f_arr[0], f_arr[1], f_arr[2]); break; case 29: - gr_restorestate(); + gr_quiver(i_arg[0], i_arg[1], f_arr[0], f_arr[1], f_arr[2], f_arr[3], i_arg[2]); break; case 30: - gr_savestate(); + gr_restorestate(); break; case 31: - gr_selectclipxform(i_arg[0]); + gr_savestate(); break; case 32: - gr_selectcontext(i_arg[0]); + gr_selectclipxform(i_arg[0]); break; case 33: - gr_selntran(i_arg[0]); + gr_selectcontext(i_arg[0]); break; case 34: - gr_setapproximativecalculation(i_arg[0]); + gr_selntran(i_arg[0]); break; case 35: - gr_setarrowsize(f_arg[0]); + gr_setapproximativecalculation(i_arg[0]); break; case 36: - gr_setarrowstyle(i_arg[0]); + gr_setarrowsize(f_arg[0]); break; case 37: - gr_setbordercolorind(i_arg[0]); + gr_setarrowstyle(i_arg[0]); break; case 38: - gr_setborderwidth(f_arg[0]); + gr_setbordercolorind(i_arg[0]); break; case 39: - gr_setcharexpan(f_arg[0]); + gr_setborderwidth(f_arg[0]); break; case 40: - gr_setcharheight(f_arg[0]); + gr_setcharexpan(f_arg[0]); break; case 41: - gr_setcharspace(f_arg[0]); + gr_setcharheight(f_arg[0]); break; case 42: - gr_setcharup(f_arg[0], f_arg[1]); + gr_setcharspace(f_arg[0]); break; case 43: - gr_setclip(i_arg[0]); + gr_setcharup(f_arg[0], f_arg[1]); break; case 44: - gr_setcolormap(i_arg[0]); + gr_setclip(i_arg[0]); break; case 45: - gr_setcolorrep(i_arg[0], f_arg[0], f_arg[1], f_arg[2]); + gr_setcolormap(i_arg[0]); break; case 46: - gr_setfillcolorind(i_arg[0]); + gr_setcolorrep(i_arg[0], f_arg[0], f_arg[1], f_arg[2]); break; case 47: - gr_setfillintstyle(i_arg[0]); + gr_setfillcolorind(i_arg[0]); break; case 48: - gr_setfillstyle(i_arg[0]); + gr_setfillintstyle(i_arg[0]); break; case 49: - gr_setlinecolorind(i_arg[0]); + gr_setfillstyle(i_arg[0]); break; case 50: - gr_setlinetype(i_arg[0]); + gr_setlinecolorind(i_arg[0]); break; case 51: - gr_setlinewidth(f_arg[0]); + gr_setlinetype(i_arg[0]); break; case 52: - gr_setmarkercolorind(i_arg[0]); + gr_setlinewidth(f_arg[0]); break; case 53: - gr_setmarkersize(f_arg[0]); + gr_setmarkercolorind(i_arg[0]); break; case 54: - gr_setmarkertype(i_arg[0]); + gr_setmarkersize(f_arg[0]); break; case 55: - gr_setorthographicprojection(f_arg[0], f_arg[1], f_arg[2], f_arg[3], f_arg[4], f_arg[5]); + gr_setmarkertype(i_arg[0]); break; case 56: - gr_setperspectiveprojection(f_arg[0], f_arg[1], f_arg[2]); + gr_setorthographicprojection(f_arg[0], f_arg[1], f_arg[2], f_arg[3], f_arg[4], f_arg[5]); break; case 57: - gr_setpicturesizeforvolume(i_arg[0], i_arg[1]); + gr_setperspectiveprojection(f_arg[0], f_arg[1], f_arg[2]); break; case 58: - gr_setprojectiontype(i_arg[0]); + gr_setpicturesizeforvolume(i_arg[0], i_arg[1]); break; case 59: - gr_setresizebehaviour(i_arg[0]); + gr_setprojectiontype(i_arg[0]); break; case 60: - gr_setscale(i_arg[0]); + gr_setresizebehaviour(i_arg[0]); break; case 61: - gr_setscalefactors3d(f_arg[0], f_arg[1], f_arg[2]); + gr_setscale(i_arg[0]); break; case 62: - gr_setspace(f_arg[0], f_arg[1], i_arg[0], i_arg[1]); + gr_setscalefactors3d(f_arg[0], f_arg[1], f_arg[2]); break; case 63: - gr_setspace3d(f_arg[0], f_arg[1], f_arg[2], f_arg[3]); + gr_setspace(f_arg[0], f_arg[1], i_arg[0], i_arg[1]); break; case 64: - gr_settextalign(i_arg[0], i_arg[1]); + gr_setspace3d(f_arg[0], f_arg[1], f_arg[2], f_arg[3]); break; case 65: - gr_settextcolorind(i_arg[0]); + gr_settextalign(i_arg[0], i_arg[1]); break; case 66: - gr_settextencoding(i_arg[0]); + gr_settextcolorind(i_arg[0]); break; case 67: - gr_settextfontprec(i_arg[0], i_arg[1]); + gr_settextencoding(i_arg[0]); break; case 68: - gr_settextpath(i_arg[0]); + gr_settextfontprec(i_arg[0], i_arg[1]); break; case 69: - gr_setthreadnumber(i_arg[0]); + gr_settextpath(i_arg[0]); break; case 70: + gr_setthreadnumber(i_arg[0]); + break; + case 71: gr_settransformationparameters(f_arg[0], f_arg[1], f_arg[2], f_arg[3], f_arg[4], f_arg[5], f_arg[6], f_arg[7], f_arg[8]); break; - case 71: + case 72: gr_settransparency(f_arg[0]); break; - case 72: + case 73: gr_setviewport(f_arg[0], f_arg[1], f_arg[2], f_arg[3]); break; - case 73: + case 74: gr_setvolumebordercalculation(i_arg[0]); break; - case 74: + case 75: gr_setwindow(f_arg[0], f_arg[1], f_arg[2], f_arg[3]); break; - case 75: + case 76: gr_setwindow3d(f_arg[0], f_arg[1], f_arg[2], f_arg[3], f_arg[4], f_arg[5]); break; - case 76: + case 77: gr_setwsviewport(f_arg[0], f_arg[1], f_arg[2], f_arg[3]); break; - case 77: + case 78: gr_setwswindow(f_arg[0], f_arg[1], f_arg[2], f_arg[3]); break; - case 78: + case 79: gr_shadelines(i_arg[0], f_arr[0], f_arr[1], i_arg[1], i_arg[2], i_arg[3]); break; - case 79: + case 80: gr_shadepoints(i_arg[0], f_arr[0], f_arr[1], i_arg[1], i_arg[2], i_arg[3]); break; - case 80: + case 81: gr_spline(i_arg[0], f_arr[0], f_arr[1], i_arg[1], i_arg[2]); break; - case 81: + case 82: gr_surface(i_arg[0], i_arg[1], f_arr[0], f_arr[1], f_arr[2], i_arg[2]); break; - case 82: + case 83: gr_text(f_arg[0], f_arg[1], s_arg[0]); break; - case 83: + case 84: gr_textext(f_arg[0], f_arg[1], s_arg[0]); break; - case 84: + case 85: gr_textx(f_arg[0], f_arg[1], s_arg[0], i_arg[0]); break; - case 85: + case 86: gr_titles3d(s_arg[0], s_arg[1], s_arg[2]); break; - case 86: + case 87: gr_tricontour(i_arg[0], f_arr[0], f_arr[1], f_arr[2], i_arg[2], f_arr[3]); break; - case 87: + case 88: gr_trisurface(i_arg[0], f_arr[0], f_arr[1], f_arr[2]); break; - case 88: + case 89: gr_uselinespec(s_arg[0]); break; - case 89: + case 90: gr_verrorbars(i_arg[0], f_arr[0], f_arr[1], f_arr[2], f_arr[3]); break; } From a74c5d6c3110348de66f821aa2142e2084601a74 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Mon, 7 Nov 2022 15:49:42 +0100 Subject: [PATCH 20/26] Fix typo --- lib/gr/import.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gr/import.c b/lib/gr/import.c index d5b3d8d9f..74f3893a6 100644 --- a/lib/gr/import.c +++ b/lib/gr/import.c @@ -108,7 +108,7 @@ static char *format[] = { "textx:ffsi", "titles3d:sss", "tricont:iFFFiF", - "trisurf:iFFF", + "trisurface:iFFF", "uselinespec:s", "verrorbars:iFFFF", }; From 49dce19744a956b3e351b58a46dd4b986d539ba2 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Mon, 7 Nov 2022 15:50:41 +0100 Subject: [PATCH 21/26] Use correct color indices --- lib/gr/gr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/gr/gr.c b/lib/gr/gr.c index 8651ed76d..a33c55a15 100644 --- a/lib/gr/gr.c +++ b/lib/gr/gr.c @@ -9014,7 +9014,15 @@ void gr_tricontour(int npoints, double *x, double *y, double *z, int nlevels, do setscale(lx.scale_options); colors = (int *)xmalloc(nlevels * sizeof(int)); - for (i = 0; i < nlevels; i++) colors[i] = (int)((double)i / (nlevels - 1) * (last_color - first_color)) + first_color; + if (nlevels > 1) + { + for (i = 0; i < nlevels; i++) + { + colors[i] = first_color + (int)((double)i / (nlevels - 1) * (last_color - first_color)); + } + } + else + colors[0] = 1; gr_draw_tricont(npoints, x, y, z, nlevels, levels, colors); From 878351e19a9681baca4d5db4138a49308f804356 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Mon, 7 Nov 2022 16:23:57 +0100 Subject: [PATCH 22/26] Allow graphics import for multiple plots --- lib/gr/import.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/gr/import.c b/lib/gr/import.c index 74f3893a6..b84932595 100644 --- a/lib/gr/import.c +++ b/lib/gr/import.c @@ -571,7 +571,7 @@ static void gr(int id) int gr_drawgraphics(char *string) { char *s = string, *el, *fmt; - int i, id; + int i, id, clear_flag = 0; for (i = 0; i < 2; i++) { @@ -602,10 +602,20 @@ int gr_drawgraphics(char *string) { fmt = format[id] + strlen(el) + 1; s = xml(s, fmt); + if (clear_flag) + { + gr_clearws(); + clear_flag = 0; + } gr(id); } else if (strcmp(el, "gr") != 0) fprintf(stderr, "%s: unknown XML element\n", el); + else + { + gr_updatews(); + clear_flag = 1; + } } } while (*s && *s != '\n') s++; From f561510ffb850a942185189316cc13efd9184ce5 Mon Sep 17 00:00:00 2001 From: Daniel Kaiser Date: Tue, 8 Nov 2022 14:36:06 +0100 Subject: [PATCH 23/26] gr3_sr: fix thread cleanup when recreating queues --- lib/gr3/gr3_sr.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/gr3/gr3_sr.c b/lib/gr3/gr3_sr.c index fef5c4a80..c5a23c8a5 100644 --- a/lib/gr3/gr3_sr.c +++ b/lib/gr3/gr3_sr.c @@ -232,6 +232,13 @@ static void create_queues_and_pixmaps(int width, int height) { if (context_struct_.queues[i]) { +#ifndef NO_THREADS + args *arg = malloc_arg(i, 0, MAT4x4_INIT_NUL, MAT4x4_INIT_NUL, MAT4x4_INIT_NUL, MAT4x4_INIT_NUL, + MAT3x3_INIT_NUL, NULL, NULL, 0, 0, 2, 0, 0, NULL, NULL, 0); + queue_enqueue(context_struct_.queues[i], arg); + + pthread_join(context_struct_.threads[i], NULL); +#endif queue_destroy(context_struct_.queues[i]); } context_struct_.queues[i] = queue_new(); @@ -2098,10 +2105,10 @@ GR3API void gr3_terminateSR_() free(context_struct_.pixmaps[i]); } free(context_struct_.depth_buffers[i]); +#ifndef NO_THREADS arg = malloc_arg(i, 0, MAT4x4_INIT_NUL, MAT4x4_INIT_NUL, MAT4x4_INIT_NUL, MAT4x4_INIT_NUL, MAT3x3_INIT_NUL, NULL, NULL, 0, 0, 2, 0, 0, NULL, NULL, 0); queue_enqueue(context_struct_.queues[i], arg); -#ifndef NO_THREADS pthread_join(context_struct_.threads[i], NULL); #endif queue_destroy(context_struct_.queues[i]); From 4b4f4eb210225accf0b43d90cc1a69d35bb1486a Mon Sep 17 00:00:00 2001 From: Florian Rhiem Date: Tue, 8 Nov 2022 10:29:38 +0100 Subject: [PATCH 24/26] Add gr3_isosurface function and example --- examples/isosurface.c | 48 ++++++++ lib/gr3/gr3.h | 3 + lib/gr3/gr3_gr.c | 247 +++++++++++++++++++++++++++++++----------- 3 files changed, 235 insertions(+), 63 deletions(-) create mode 100644 examples/isosurface.c diff --git a/examples/isosurface.c b/examples/isosurface.c new file mode 100644 index 000000000..faad5525c --- /dev/null +++ b/examples/isosurface.c @@ -0,0 +1,48 @@ +#include +#include +#include "gr3.h" +#include "gr.h" + +static void ellipsoid_data(int nx, int ny, int nz, float rx, float ry, float rz, float *data, int stride_x, + int stride_y, int stride_z) +{ + int ix, iy, iz; + + for (ix = 0; ix < nx; ix += 1) + { + float x = (2.0 * ix / (nx - 1) - 1.0) / rx; + for (iy = 0; iy < nx; iy += 1) + { + float y = (2.0 * iy / (ny - 1) - 1.0) / ry; + for (iz = 0; iz < nx; iz += 1) + { + float z = (2.0 * iz / (nz - 1) - 1.0) / rz; + int index = stride_x * ix + stride_y * iy + stride_z * iz; + data[index] = sqrt(x * x + y * y + z * z); + } + } + } +} + +int main(void) +{ + int i; + int nx = 20; + int ny = 20; + int nz = 20; + int stride_x = nz * ny; + int stride_y = nz; + int stride_z = 1; + float *data = malloc(nx * ny * nz * sizeof(float)); + + gr_setviewport(0, 1, 0, 1); + for (i = 0; i < 150; i++) + { + ellipsoid_data(nx, ny, nz, 1.5, 1.0, sin(i * 0.05) * 0.5 + 1.0, data, stride_x, stride_y, stride_z); + gr_clearws(); + gr_setspace3d(40, 60, 0, 2.5); + gr_axes3d(0.5, 0.5, 0.5, -1, -1, -1, 2, 2, 2, 0.007); + gr3_isosurface(nx, ny, nz, data, 0.5, NULL, NULL); + gr_updatews(); + } +} diff --git a/lib/gr3/gr3.h b/lib/gr3/gr3.h index 6a02a8f23..36226ca28 100644 --- a/lib/gr3/gr3.h +++ b/lib/gr3/gr3.h @@ -202,6 +202,9 @@ GR3API void gr3_drawsurface(int mesh); GR3API void gr3_surface(int nx, int ny, float *px, float *py, float *pz, int option); +GR3API void gr3_isosurface(int nx, int ny, int nz, const float *data, float isovalue, const float *color, + const int *strides); + GR3API int gr3_drawtubemesh(int n, float *points, float *colors, float *radii, int num_steps, int num_segments); GR3API int gr3_createtubemesh(int *mesh, int n, const float *points, const float *colors, const float *radii, diff --git a/lib/gr3/gr3_gr.c b/lib/gr3/gr3_gr.c index 9666db33b..8dedeb880 100644 --- a/lib/gr3/gr3_gr.c +++ b/lib/gr3/gr3_gr.c @@ -778,17 +778,12 @@ GR3API void gr3_drawmesh_grlike(int mesh, int n, const float *positions, const f free(modelscales); } -/*! - * Convenience function for drawing a surfacemesh - * \param [in] mesh the mesh to be drawn - */ -GR3API void gr3_drawsurface(int mesh) +static void gr3_drawsurface_custom_colors(int mesh, const float *colors) { int projection_type; float directions[3] = {0.0f, 0.0f, 1.0f}; float ups[3] = {0.0f, 1.0f, 0.0f}; float positions[3] = {-1.0f, -1.0f, -1.0f}; - float colors[3] = {1.0f, 1.0f, 1.0f}; float scales[3] = {2.0f, 2.0f, 2.0f}; gr_inqprojectiontype(&projection_type); @@ -814,6 +809,188 @@ GR3API void gr3_drawsurface(int mesh) if (gr3_geterror(0, NULL, NULL)) return; } +/*! + * Convenience function for drawing a surfacemesh + * \param [in] mesh the mesh to be drawn + */ +GR3API void gr3_drawsurface(int mesh) +{ + float colors[3] = {1.0f, 1.0f, 1.0f}; + gr3_drawsurface_custom_colors(mesh, colors); +} + +static void gr3_drawimage_grlike() +{ + int width, height; + double device_pixel_ratio; + double vpxmin, vpxmax, vpymin, vpymax; + double aspect; + int projection_type; + double xmin, xmax, ymin, ymax; + int scale; + + gr_inqwindow(&xmin, &xmax, &ymin, &ymax); + gr_inqscale(&scale); + + if (scale & OPTION_FLIP_X) + { + double tmp = xmin; + xmin = xmax; + xmax = tmp; + } + if (scale & OPTION_FLIP_Y) + { + double tmp = ymin; + ymin = ymax; + ymax = tmp; + } + gr_inqvpsize(&width, &height, &device_pixel_ratio); + width *= device_pixel_ratio; + height *= device_pixel_ratio; + gr_inqviewport(&vpxmin, &vpxmax, &vpymin, &vpymax); + aspect = fabs((vpxmax - vpxmin) / (vpymax - vpymin)); + if (context_struct_.use_default_light_parameters) + { + gr3_setlightparameters(0.8, 0.2, 0.1, 10.0); + context_struct_.use_default_light_parameters = 1; + } + gr_inqprojectiontype(&projection_type); + if (projection_type == GR_PROJECTION_DEFAULT) + { + /* projection type does not consider the viewport aspect ratio */ + aspect = 1; + context_struct_.aspect_override = 1; + } + if (aspect > 1) + { + gr3_drawimage((float)xmin, (float)xmax, (float)ymin, (float)ymax, width, height, GR3_DRAWABLE_GKS); + } + else + { + double fovy = context_struct_.vertical_field_of_view; + context_struct_.vertical_field_of_view = + (float)(atan(tan(context_struct_.vertical_field_of_view / 360 * M_PI) / aspect) / M_PI * 360); + gr3_drawimage((float)xmin, (float)xmax, (float)ymin, (float)ymax, width, height, GR3_DRAWABLE_GKS); + context_struct_.vertical_field_of_view = (float)fovy; + } + context_struct_.aspect_override = 0; + if (context_struct_.use_default_light_parameters) + { + gr3_setdefaultlightparameters(); + } + if (gr3_geterror(0, NULL, NULL)) return; +} + +/*! + * Create an isosurface plot and draw it with GKS + * \param [in] nx number of voxels in x-direction + * \param [in] ny number of voxels in y-direction + * \param [in] nz number of voxels in z-direction + * \param [in] data an array containing the voxel data + * \param [in] isosurface an array containing the y-coordinates + * \param [in] color an array containting the RGB values, or NULL to + * use the default color + * \param [in] strides an array containting the 3 axis strides, or NULL + * to use strides for x-y-z axis order + */ +GR3API void gr3_isosurface(int nx, int ny, int nz, const float *data, float isovalue, const float *color, + const int *strides) +{ + const float DEFAULT_COLOR[3] = {0.0f, 0.5f, 0.8f}; + int mesh; + int ix, iy, iz; + int stride_x, stride_y, stride_z; + const unsigned short MAX_UINT16 = 65535; + unsigned short uint16_isolevel; + float min_value = data[0]; + float max_value = data[0]; + unsigned short *uint16_data = malloc(sizeof(unsigned short) * nx * ny * nz); + assert(uint16_data); + + if (strides) + { + stride_x = strides[0]; + stride_y = strides[1]; + stride_z = strides[2]; + } + else + { + stride_x = nz * ny; + stride_y = nz; + stride_z = 1; + } + + for (ix = 0; ix < nx; ix += 1) + { + for (iy = 0; iy < nx; iy += 1) + { + for (iz = 0; iz < nx; iz += 1) + { + int index = stride_x * ix + stride_y * iy + stride_z * iz; + float value = data[index]; + if (value < min_value) + { + min_value = value; + } + if (value > max_value) + { + max_value = value; + } + } + } + } + + for (ix = 0; ix < nx; ix += 1) + { + for (iy = 0; iy < nx; iy += 1) + { + for (iz = 0; iz < nx; iz += 1) + { + int index = stride_x * ix + stride_y * iy + stride_z * iz; + float value = data[index]; + value = (value - min_value) / (max_value - min_value); + if (value > 1) + { + value = 1; + } + if (value < 0) + { + value = 0; + } + uint16_data[index] = (unsigned short)(value * MAX_UINT16 + 0.5); + } + } + } + + isovalue = (isovalue - min_value) / (max_value - min_value); + if (isovalue > 1) + { + isovalue = 1; + } + if (isovalue < 0) + { + isovalue = 0; + } + uint16_isolevel = (unsigned short)(isovalue * MAX_UINT16 + 0.5); + + /* fall back to default color if color is NULL */ + if (!color) + { + color = &DEFAULT_COLOR[0]; + } + + gr3_createisosurfacemesh(&mesh, uint16_data, uint16_isolevel, nx, ny, nz, stride_x, stride_y, stride_z, + 2.0 / (nx - 1.0), 2.0 / (ny - 1.0), 2 / (nz - 1.0), -1.0, -1.0, -1.0); + free(uint16_data); + if (gr3_geterror(0, NULL, NULL)) return; + gr3_drawsurface_custom_colors(mesh, color); + if (gr3_geterror(0, NULL, NULL)) return; + gr3_deletemesh(mesh); + if (gr3_geterror(0, NULL, NULL)) return; + + gr3_drawimage_grlike(); +} + /*! * Create a surface plot with gr3 and draw it with gks as cellarray * \param [in] nx number of points in x-direction @@ -830,13 +1007,6 @@ GR3API void gr3_surface(int nx, int ny, float *px, float *py, float *pz, int opt (context_struct_.use_software_renderer && option <= OPTION_FILLED_MESH)) { int mesh; - int width, height; - double device_pixel_ratio; - double vpxmin, vpxmax, vpymin, vpymax; - double aspect; - int projection_type; - double xmin, xmax, ymin, ymax; - int scale; int surfaceoption; int previous_option = context_struct_.option; context_struct_.option = option; @@ -866,57 +1036,8 @@ GR3API void gr3_surface(int nx, int ny, float *px, float *py, float *pz, int opt if (gr3_geterror(0, NULL, NULL)) return; gr3_deletemesh(mesh); if (gr3_geterror(0, NULL, NULL)) return; - gr_inqwindow(&xmin, &xmax, &ymin, &ymax); - gr_inqscale(&scale); - - if (scale & OPTION_FLIP_X) - { - double tmp = xmin; - xmin = xmax; - xmax = tmp; - } - if (scale & OPTION_FLIP_Y) - { - double tmp = ymin; - ymin = ymax; - ymax = tmp; - } - gr_inqvpsize(&width, &height, &device_pixel_ratio); - width *= device_pixel_ratio; - height *= device_pixel_ratio; - gr_inqviewport(&vpxmin, &vpxmax, &vpymin, &vpymax); - aspect = fabs((vpxmax - vpxmin) / (vpymax - vpymin)); - if (context_struct_.use_default_light_parameters) - { - gr3_setlightparameters(0.8, 0.2, 0.1, 10.0); - context_struct_.use_default_light_parameters = 1; - } - gr_inqprojectiontype(&projection_type); - if (projection_type == GR_PROJECTION_DEFAULT) - { - /* projection type does not consider the viewport aspect ratio */ - aspect = 1; - context_struct_.aspect_override = 1; - } - if (aspect > 1) - { - gr3_drawimage((float)xmin, (float)xmax, (float)ymin, (float)ymax, width, height, GR3_DRAWABLE_GKS); - } - else - { - double fovy = context_struct_.vertical_field_of_view; - context_struct_.vertical_field_of_view = - (float)(atan(tan(context_struct_.vertical_field_of_view / 360 * M_PI) / aspect) / M_PI * 360); - gr3_drawimage((float)xmin, (float)xmax, (float)ymin, (float)ymax, width, height, GR3_DRAWABLE_GKS); - context_struct_.vertical_field_of_view = (float)fovy; - } + gr3_drawimage_grlike(); context_struct_.option = previous_option; - context_struct_.aspect_override = 0; - if (context_struct_.use_default_light_parameters) - { - gr3_setdefaultlightparameters(); - } - if (gr3_geterror(0, NULL, NULL)) return; } else { From a5fe1945ce28dd870937cfd842cb0fa6a8cfa6e1 Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Tue, 8 Nov 2022 23:07:41 +0100 Subject: [PATCH 25/26] Use static fontfile descriptor --- lib/gks/plugin/qtplugin_impl.cxx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/gks/plugin/qtplugin_impl.cxx b/lib/gks/plugin/qtplugin_impl.cxx index 5e10ace12..790f808de 100644 --- a/lib/gks/plugin/qtplugin_impl.cxx +++ b/lib/gks/plugin/qtplugin_impl.cxx @@ -126,6 +126,8 @@ typedef struct ws_state_list_t static ws_state_list p_, *p = &p_; +static int fontfile = 0; + static const char *fonts[] = { "Times", "Arial", "Courier", "Open Symbol", "Bookman Old Style", "Century Schoolbook", "Century Gothic", "Book Antiqua"}; @@ -720,9 +722,9 @@ static void text(double px, double py, int nchars, char *chars) } else { - if ((tx_prec == GKS_K_TEXT_PRECISION_STROKE || tx_prec == GKS_K_TEXT_PRECISION_CHAR) && gkss->fontfile == 0) + if ((tx_prec == GKS_K_TEXT_PRECISION_STROKE || tx_prec == GKS_K_TEXT_PRECISION_CHAR) && fontfile == 0) { - gkss->fontfile = gks_open_font(); + fontfile = gks_open_font(); } gks_emul_text(px, py, nchars, chars, line_routine, fill_routine); } @@ -1343,17 +1345,18 @@ static void memory_plugin_dl_render(int fctid, int dx, int dy, int dimx, int *ia } return; case 3: - if (gkss->fontfile != 0) + if (fontfile != 0) { - gks_close_font(gkss->fontfile); + gks_close_font(fontfile); + fontfile = 0; } break; case 14: { int tx_prec = gkss->asf[6] ? gkss->txprec : predef_prec[gkss->tindex - 1]; - if ((tx_prec == GKS_K_TEXT_PRECISION_STROKE || tx_prec == GKS_K_TEXT_PRECISION_CHAR) && gkss->fontfile == 0) + if ((tx_prec == GKS_K_TEXT_PRECISION_STROKE || tx_prec == GKS_K_TEXT_PRECISION_CHAR) && fontfile == 0) { - gkss->fontfile = gks_open_font(); + fontfile = gks_open_font(); } } break; @@ -1417,7 +1420,6 @@ static void qt_dl_render(int fctid, int dx, int dy, int dimx, int *ia, int lr1, case 2: memmove(&saved_gkss, gkss, sizeof(gks_state_list_t)); memmove(gkss, *ptr, sizeof(gks_state_list_t)); - gkss->fontfile = saved_gkss.fontfile; if (!p->prevent_resize_by_dl) { @@ -1437,10 +1439,10 @@ static void qt_dl_render(int fctid, int dx, int dy, int dimx, int *ia, int lr1, break; case 3: - if (gkss->fontfile > 0) + if (fontfile > 0) { - gks_close_font(gkss->fontfile); - gkss->fontfile = 0; + gks_close_font(fontfile); + fontfile = 0; } break; From 0c36f70083e127e60b9dfcf04425fc624c80e37f Mon Sep 17 00:00:00 2001 From: Josef Heinen Date: Wed, 9 Nov 2022 15:15:01 +0100 Subject: [PATCH 26/26] gks: improve loading of DLLs on Windows --- lib/gks/plugin.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/gks/plugin.c b/lib/gks/plugin.c index 97626f351..e9c7d9c76 100644 --- a/lib/gks/plugin.c +++ b/lib/gks/plugin.c @@ -5,6 +5,7 @@ #ifdef _WIN32 #include +#include #else #include #include @@ -31,15 +32,15 @@ static void *load_library(const char *name) { - char pathname[MAXPATHLEN], symbol[255]; + char pathname[MAXPATHLEN]; #ifdef _WIN32 + wchar_t grdir[MAX_PATH], w_pathname[MAX_PATH]; HINSTANCE handle; - LPCTSTR grdir; - char grbin[MAXPATHLEN]; #else - void *handle; const char *grdir, *error; + void *handle; #endif + char symbol[255]; void *entry = NULL; snprintf(pathname, MAXPATHLEN, "%s.%s", name, EXTENSION); @@ -47,19 +48,12 @@ static void *load_library(const char *name) handle = LoadLibrary(pathname); if (handle == NULL) { - grdir = gks_getenv("GRDIR"); - if (grdir == NULL) grdir = GRDIR; - snprintf(grbin, MAXPATHLEN, "%s/bin", grdir); - SetDllDirectory(grbin); - handle = LoadLibrary(pathname); + GetEnvironmentVariableW(L"GRDIR", grdir, MAX_PATH); + StringCbPrintfW(w_pathname, MAX_PATH, L"%ws\\bin\\%S.%S", grdir, name, EXTENSION); + handle = LoadLibraryExW(w_pathname, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); } #else handle = dlopen(pathname, RTLD_LAZY); - if (handle == NULL) - { - snprintf(pathname, MAXPATHLEN, "%s/%s.%s", "./", name, EXTENSION); - handle = dlopen(pathname, RTLD_LAZY); - } if (handle == NULL) { grdir = gks_getenv("GRDIR");