From: Perl 5 Porters Date: Wed, 3 Jan 1996 23:03:37 +0000 (+0000) Subject: perl 5.002beta1h patch: miniperlmain.c X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28e44ed9749d8684067f67623a63b70fce87c3b8;p=p5sagit%2Fp5-mst-13.2.git perl 5.002beta1h patch: miniperlmain.c Better locale handling, courtesy of jhi. Include a proper cast of NULL for non-prototyping compilers. --- diff --git a/miniperlmain.c b/miniperlmain.c index 2c1e0b6..95e9c49 100644 --- a/miniperlmain.c +++ b/miniperlmain.c @@ -20,6 +20,36 @@ static void xs_init _((void)); static PerlInterpreter *my_perl; int +i18nl14n() +{ + char * lang = getenv("LANG"); +#if defined(HAS_SETLOCALE) && defined(LC_CTYPE) + { + char * lc_ctype = getenv("LC_CTYPE"); + int i; + + if (setlocale(LC_CTYPE, "") == NULL && (lc_ctype || lang)) { + fprintf(stderr, + "warning: setlocale(LC_CTYPE, \"\") failed, LC_CTYPE = \"%s\", LANG = \"%s\",\n", + lc_ctype ? lc_ctype : "(null)", + lang ? lang : "(null)" + ); + fprintf(stderr, + "warning: falling back to the \"C\" locale.\n"); + setlocale(LC_CTYPE, "C"); + } + + for (i = 0; i < 256; i++) { + if (isUPPER(i)) fold[i] = toLOWER(i); + else if (isLOWER(i)) fold[i] = toUPPER(i); + else fold[i] = i; + } + + } +#endif +} + +int #ifndef CAN_PROTOTYPE main(argc, argv, env) int argc; @@ -40,13 +70,9 @@ main(int argc, char **argv, char **env) getredirection(&argc,&argv); #endif -#if defined(HAS_SETLOCALE) && defined(LC_CTYPE) - if (setlocale(LC_CTYPE, "") == NULL) { - fprintf(stderr, - "setlocale(LC_CTYPE, \"\") failed (LC_CTYPE = \"%s\").\n", - getenv("LC_CTYPE")); - exit(1); - } +/* here a union of the cpp #if:s inside i18nl14n() */ +#if (defined(HAS_SETLOCALE) && defined(LC_CTYPE)) + i18nl14n(); #endif if (!do_undump) { @@ -56,7 +82,7 @@ main(int argc, char **argv, char **env) perl_construct( my_perl ); } - exitstatus = perl_parse( my_perl, xs_init, argc, argv, NULL ); + exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL ); if (exitstatus) exit( exitstatus );