Commit d155dc30 authored by Erick's avatar Erick

use the LANG variable to determine if we use utf8 (rather than fixing it to...

use the LANG variable to determine if we use utf8 (rather than fixing it to true by default as before)
parent 3f24f6c0
/*
* stklos.c -- STklos interpreter main function
*
* Copyright © 1999-2011 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
* Copyright © 1999-2012 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
*
*
* This program is free software; you can redistribute it and/or modify
......@@ -21,10 +21,11 @@
*
* Author: Erick Gallesio [eg@unice.fr]
* Creation date: 28-Dec-1999 21:19 (eg)
* Last file update: 10-Aug-2011 00:27 (eg)
* Last file update: 1-Jan-2012 19:33 (eg)
*/
#include <stklos.h>
#include <langinfo.h>
#include "gnu-getopt.h"
......@@ -98,7 +99,7 @@ static void Usage(char *progname, int only_version)
" -d, --debug add informations to ease debugging\n"
" -s, --stack-size=n use a stack of size n (default %d)\n"
" -c, --case-sensitive be case sensitive (default is #f)\n"
" -u, --utf8-encoding=yes|no use/don't use UTF-8 encoding (default is yes)\n"
" -u, --utf8-encoding=yes|no use/don't use UTF-8 encoding (instead of default)\n"
" -v, --version print program version and exit\n"
" -h, --help print this help and exit\n"
"All the arguments given after options are passed to the Scheme program.\n",
......@@ -129,7 +130,7 @@ static int process_program_arguments(int argc, char *argv[])
case 'q': vanilla = 1; break;
case 's': stack_size = atoi(optarg); break;
case 'c': STk_read_case_sensitive = 1; break;
case 'u': STk_use_utf8 = (int) strspn(optarg, "yY1"); break;
case 'u': STk_use_utf8 = strspn(optarg, "yY1"); break;
case '?': /* message error is printed by getopt */
fprintf(stderr, "Try `%s --help' for more information\n", *argv);
exit(1);
......@@ -168,12 +169,6 @@ int main(int argc, char *argv[])
int ret;
char *argv0 = *argv;
if (!setlocale(LC_CTYPE, "")) {
fprintf(stderr, "Can't set the specified locale! "
"Check LANG, LC_CTYPE, LC_ALL.\n");
return 1;
}
/* Initialize the Garbage Collector */
#if (defined(__CYGWIN32__) && defined(GC_DLL)) || defined(_AIX)
# error GC problem
......@@ -185,6 +180,18 @@ int main(int argc, char *argv[])
argc -= ret;
argv += ret;
/* See if we use UTF8 encoding */
if (!setlocale(LC_CTYPE, "")) {
fprintf(stderr, "Can't set the specified locale! "
"Check LANG, LC_CTYPE, LC_ALL.\n");
return 1;
} else {
if (STk_use_utf8 == -1) {
/* user didn't force the encoding. Determine it from environment */
STk_use_utf8 = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0);
}
}
/* Hack: to give the illusion that there is no VM under the scene */
if (*program_file) argv0 = program_file;
......
/*
* utf8.c -- UTF-8 support functions
*
* Copyright © 2011 Erick Gallesio - Polytech'Nice-Sophia <eg@unice.fr>
* Copyright © 2011-2012 Erick Gallesio - Polytech'Nice-Sophia <eg@unice.fr>
*
*
* This program is free software; you can redistribute it and/or modify
......@@ -21,12 +21,12 @@
*
* Author: Erick Gallesio [eg@unice.fr]
* Creation date: 30-Apr-2011 19:46 (eg)
* Last file update: 9-Sep-2011 14:43 (eg)
* Last file update: 1-Jan-2012 19:07 (eg)
*/
#include "stklos.h"
int STk_use_utf8 = 1;
int STk_use_utf8 = -1;
static void error_bad_sequence(char *str)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment