Fix segfault and implement better *cough* fix for locale problems

This commit is contained in:
Mario Hüttel 2019-02-03 22:44:03 +01:00
parent 1fa2d75abd
commit bdb06c4d6e
2 changed files with 7 additions and 9 deletions

View File

@ -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) static void create_csv_line(LayerElement *layer_element, char *line_buffer, size_t max_len)
{ {
int i;
GString *string; GString *string;
gboolean export; gboolean export;
const gchar *name; 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); layer_element_get_color(layer_element, &color);
/* print values to line */ /* 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, layer, color.red, color.green,
color.blue, color.alpha, (export == TRUE ? 1 : 0), name); 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)) { if (string->len > (max_len-1)) {
printf("Layer Definition too long. Please shorten Layer Name!!\n"); printf("Layer Definition too long. Please shorten Layer Name!!\n");

8
main.c
View File

@ -20,7 +20,6 @@
#include <stdio.h> #include <stdio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib.h> #include <glib.h>
#include <locale.h>
#include "main-window.h" #include "main-window.h"
#include "command-line.h" #include "command-line.h"
#include "external-renderer.h" #include "external-renderer.h"
@ -114,7 +113,6 @@ int main(int argc, char **argv)
GOptionContext *context; GOptionContext *context;
gchar *gds_name; gchar *gds_name;
gchar *basename; gchar *basename;
struct lconv *temp_locale;
gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL; gchar *pdfname = NULL, *texname = NULL, *mappingname = NULL, *cellname = NULL, *svgname = NULL;
gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE; gboolean tikz = FALSE, pdf = FALSE, pdf_layers = FALSE, pdf_standalone = FALSE, svg = FALSE;
gchar *custom_library_path = NULL; gchar *custom_library_path = NULL;
@ -122,12 +120,6 @@ int main(int argc, char **argv)
int scale = 1000; int scale = 1000;
int app_status; 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[] = { GOptionEntry entries[] = {
{"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL }, {"tikz", 't', 0, G_OPTION_ARG_NONE, &tikz, "Output TikZ code", NULL },
{"pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL }, {"pdf", 'p', 0, G_OPTION_ARG_NONE, &pdf, "Output PDF document", NULL },