commit f652931011b761b1a5eb96ea1a2684c3a903d1b5
parent 6c413067e172ab887c46e24f73013700294d29bc
Author: Ben Webb <ben@salilab.org>
Date: Tue, 17 Sep 2002 09:33:04 +0000
Handle non-ASCII characters properly by adding suitable casts; test for
isascii() before using isprint() so as not to fail on systems for which
isprint() is undefined for non-ASCII characters.
Diffstat:
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/configfile.c b/src/configfile.c
@@ -48,12 +48,13 @@ static void PrintEscaped(FILE *fp, gchar *str)
guint i;
for (i = 0; i < strlen(str); i++) {
- switch(str[i]) {
+ int ch = (int)(guchar)str[i];
+ switch(ch) {
case '"':
case '\'':
case '\\':
fputc('\\', fp);
- fputc(str[i], fp);
+ fputc(ch, fp);
break;
case '\n':
fputs("\\n", fp);
@@ -71,10 +72,10 @@ static void PrintEscaped(FILE *fp, gchar *str)
fputs("\\f", fp);
break;
default:
- if (isprint(str[i])) {
- fputc(str[i], fp);
+ if (isascii(ch) && isprint(ch)) {
+ fputc(ch, fp);
} else {
- fprintf(fp, "\\%o", (int)(guchar)str[i]);
+ fprintf(fp, "\\%o", ch);
}
}
}