From 1fa2d75abd9dafba4f3a1e10cc0d7009a561f3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 3 Feb 2019 22:29:06 +0100 Subject: [PATCH 1/4] Fix broken layer mapping if locale is different than english --- main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 5309c4d..cdf2b19 100644 --- a/main.c +++ b/main.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "main-window.h" #include "command-line.h" #include "external-renderer.h" @@ -85,8 +86,6 @@ static int start_gui(int argc, char **argv) g_application_register(G_APPLICATION(gapp), NULL, NULL); g_signal_connect(gapp, "activate", G_CALLBACK(gapp_activate), &appdata); - - menu = g_menu_new(); m_quit = g_menu_new(); m_about = g_menu_new(); @@ -115,6 +114,7 @@ int main(int argc, char **argv) GOptionContext *context; gchar *gds_name; gchar *basename; + struct lconv *temp_locale; gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL; gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE; gchar *custom_library_path = NULL; @@ -122,6 +122,11 @@ int main(int argc, char **argv) int scale = 1000; int app_status; + /* Set locale for layer mapping file */ + setlocale(LC_NUMERIC, ""); + temp_locale = localeconv(); + strcpy(temp_locale->decimal_point, "."); + strcpy(temp_locale->thousands_sep, "'"); GOptionEntry entries[] = { {"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL }, From bdb06c4d6e36b8889842fe1ada67a7fe54f2aaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 3 Feb 2019 22:44:03 +0100 Subject: [PATCH 2/4] Fix segfault and implement better *cough* fix for locale problems --- layer-selector.c | 8 +++++++- main.c | 8 -------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/layer-selector.c b/layer-selector.c index baee88b..3218096 100644 --- a/layer-selector.c +++ b/layer-selector.c @@ -321,6 +321,7 @@ static void load_mapping_clicked(GtkWidget *button, gpointer user_data) */ static void create_csv_line(LayerElement *layer_element, char *line_buffer, size_t max_len) { + int i; GString *string; gboolean export; const gchar *name; @@ -336,9 +337,14 @@ static void create_csv_line(LayerElement *layer_element, char *line_buffer, size layer_element_get_color(layer_element, &color); /* print values to line */ - g_string_printf(string, "%d,%lf,%lf,%lf,%lf,%d,%s\n", + g_string_printf(string, "%d:%lf:%lf:0%lf:%lf:%d:%s\n", layer, color.red, color.green, color.blue, color.alpha, (export == TRUE ? 1 : 0), name); + /* Fix broken locale settings */ + for (i = 0; string->str[i]; i++) { + if (string->str[i] == ':') + string->str[i] = ','; + } if (string->len > (max_len-1)) { printf("Layer Definition too long. Please shorten Layer Name!!\n"); diff --git a/main.c b/main.c index cdf2b19..1cee472 100644 --- a/main.c +++ b/main.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "main-window.h" #include "command-line.h" #include "external-renderer.h" @@ -114,7 +113,6 @@ int main(int argc, char **argv) GOptionContext *context; gchar *gds_name; gchar *basename; - struct lconv *temp_locale; gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL; gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE; gchar *custom_library_path = NULL; @@ -122,12 +120,6 @@ int main(int argc, char **argv) int scale = 1000; int app_status; - /* Set locale for layer mapping file */ - setlocale(LC_NUMERIC, ""); - temp_locale = localeconv(); - strcpy(temp_locale->decimal_point, "."); - strcpy(temp_locale->thousands_sep, "'"); - GOptionEntry entries[] = { {"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL }, {"pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL }, From 1f281119dfef3a0e25bd92367f0cc366411a5543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 3 Feb 2019 22:47:34 +0100 Subject: [PATCH 3/4] Fix the better solution. This makes it an even better solution --- layer-selector.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/layer-selector.c b/layer-selector.c index 3218096..cac149b 100644 --- a/layer-selector.c +++ b/layer-selector.c @@ -341,6 +341,11 @@ static void create_csv_line(LayerElement *layer_element, char *line_buffer, size layer, color.red, color.green, color.blue, color.alpha, (export == TRUE ? 1 : 0), name); /* Fix broken locale settings */ + for (i = 0; string->str[i]; i++) { + if (string->str[i] == ',') + string->str[i] = '.'; + } + for (i = 0; string->str[i]; i++) { if (string->str[i] == ':') string->str[i] = ','; From 9f2544ee94ae280dce7ac7203fccdb0039da34c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 3 Feb 2019 22:50:34 +0100 Subject: [PATCH 4/4] fix double 0 in layer mapping --- layer-selector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layer-selector.c b/layer-selector.c index cac149b..f63559b 100644 --- a/layer-selector.c +++ b/layer-selector.c @@ -337,7 +337,7 @@ static void create_csv_line(LayerElement *layer_element, char *line_buffer, size layer_element_get_color(layer_element, &color); /* print values to line */ - g_string_printf(string, "%d:%lf:%lf:0%lf:%lf:%d:%s\n", + g_string_printf(string, "%d:%lf:%lf:%lf:%lf:%d:%s\n", layer, color.red, color.green, color.blue, color.alpha, (export == TRUE ? 1 : 0), name); /* Fix broken locale settings */