From 09a3670d642bbaae008790936f10e0edb704c8f0 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 8 Jun 2011 18:09:03 +0100 Subject: [PATCH] Clean up signs when reading --- includes/misc.h | 2 ++ src/main.c | 1 + src/misc.c | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/includes/misc.h b/includes/misc.h index f504a7b82..2ca0ac6da 100644 --- a/includes/misc.h +++ b/includes/misc.h @@ -44,6 +44,8 @@ void strlist_free(struct strlist **list); void save_presets(int do_update); +void clean_text(char *text, int vwidth); + void load_presets(void); void save_string(FILE *f, char *str); diff --git a/src/main.c b/src/main.c index 7c681df3e..76e0282d1 100644 --- a/src/main.c +++ b/src/main.c @@ -1036,6 +1036,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char { memcpy(signs[k].text, d+p, x); signs[k].text[x] = 0; + clean_text(signs[k].text, 158-14 /* Current max sign length */); } p += x; } diff --git a/src/misc.c b/src/misc.c index 73d60709c..f2b713f74 100644 --- a/src/misc.c +++ b/src/misc.c @@ -99,6 +99,19 @@ void strlist_free(struct strlist **list) } } +void clean_text(char *text, int vwidth) +{ + int i = 0; + if(textwidth(text) > vwidth){ + text[textwidthx(text, vwidth)] = 0; + } + for(i = 0; i < strlen(text); i++){ + if(! (text[i]>=' ' && text[i]<127)){ + text[i] = ' '; + } + } +} + void save_presets(int do_update) { FILE *f=fopen("powder.def", "wb");