Commit | Line | Data |
---|---|---|
a0d0e21e LW |
1 | /* |
2 | * "The Road goes ever on and on, down from the door where it began." | |
3 | */ | |
4 | ||
4633a7c4 LW |
5 | #ifdef __cplusplus |
6 | extern "C" { | |
7 | #endif | |
8 | ||
ecfc5424 | 9 | #include "EXTERN.h" |
2304df62 AD |
10 | #include "perl.h" |
11 | ||
4633a7c4 LW |
12 | #ifdef __cplusplus |
13 | } | |
14 | # define EXTERN_C extern "C" | |
15 | #else | |
16 | # define EXTERN_C extern | |
17 | #endif | |
18 | ||
a0d0e21e LW |
19 | static void xs_init _((void)); |
20 | static PerlInterpreter *my_perl; | |
21 | ||
c07a80fd | 22 | int |
23 | perl_init_i18nl14n(printwarn) /* XXX move to perl.c */ | |
24 | int printwarn; | |
28e44ed9 | 25 | { |
c07a80fd | 26 | int ok = 1; |
27 | /* returns | |
28 | * 1 = set ok or not applicable, | |
29 | * 0 = fallback to C locale, | |
30 | * -1 = fallback to C locale failed | |
31 | */ | |
28e44ed9 | 32 | #if defined(HAS_SETLOCALE) && defined(LC_CTYPE) |
c07a80fd | 33 | char * lang = getenv("LANG"); |
37b42002 | 34 | char * lc_all = getenv("LC_ALL"); |
28e44ed9 | 35 | char * lc_ctype = getenv("LC_CTYPE"); |
36 | int i; | |
37 | ||
37b42002 | 38 | if (setlocale(LC_CTYPE, "") == NULL && (lc_all || lc_ctype || lang)) { |
c07a80fd | 39 | if (printwarn) { |
40 | fprintf(stderr, "warning: setlocale(LC_CTYPE, \"\") failed.\n"); | |
41 | fprintf(stderr, | |
37b42002 | 42 | "warning: LC_ALL = \"%s\", LC_CTYPE = \"%s\", LANG = \"%s\",\n", |
43 | lc_all ? lc_all : "(null)", | |
28e44ed9 | 44 | lc_ctype ? lc_ctype : "(null)", |
45 | lang ? lang : "(null)" | |
46 | ); | |
c07a80fd | 47 | fprintf(stderr, "warning: falling back to the \"C\" locale.\n"); |
48 | } | |
49 | ok = 0; | |
50 | if (setlocale(LC_CTYPE, "C") == NULL) | |
51 | ok = -1; | |
28e44ed9 | 52 | } |
53 | ||
54 | for (i = 0; i < 256; i++) { | |
c07a80fd | 55 | if (isUPPER(i)) fold[i] = toLOWER(i); |
56 | else if (isLOWER(i)) fold[i] = toUPPER(i); | |
57 | else fold[i] = i; | |
28e44ed9 | 58 | } |
28e44ed9 | 59 | #endif |
c07a80fd | 60 | return ok; |
28e44ed9 | 61 | } |
62 | ||
c07a80fd | 63 | |
28e44ed9 | 64 | int |
4633a7c4 | 65 | #ifndef CAN_PROTOTYPE |
2304df62 AD |
66 | main(argc, argv, env) |
67 | int argc; | |
68 | char **argv; | |
69 | char **env; | |
4633a7c4 LW |
70 | #else /* def(CAN_PROTOTYPE) */ |
71 | main(int argc, char **argv, char **env) | |
72 | #endif /* def(CAN_PROTOTYPE) */ | |
2304df62 AD |
73 | { |
74 | int exitstatus; | |
2304df62 | 75 | |
c07a80fd | 76 | PERL_SYS_INIT(&argc,&argv); |
4633a7c4 | 77 | |
c07a80fd | 78 | perl_init_i18nl14n(1); |
4633a7c4 | 79 | |
a0d0e21e LW |
80 | if (!do_undump) { |
81 | my_perl = perl_alloc(); | |
82 | if (!my_perl) | |
83 | exit(1); | |
84 | perl_construct( my_perl ); | |
85 | } | |
2304df62 | 86 | |
28e44ed9 | 87 | exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL ); |
2304df62 AD |
88 | if (exitstatus) |
89 | exit( exitstatus ); | |
90 | ||
91 | exitstatus = perl_run( my_perl ); | |
92 | ||
748a9306 | 93 | perl_destruct( my_perl ); |
2304df62 AD |
94 | perl_free( my_perl ); |
95 | ||
96 | exit( exitstatus ); | |
97 | } | |
98 | ||
99 | /* Register any extra external extensions */ | |
100 | ||
4633a7c4 LW |
101 | /* Do not delete this line--writemain depends on it */ |
102 | ||
a0d0e21e LW |
103 | static void |
104 | xs_init() | |
2304df62 | 105 | { |
2304df62 | 106 | } |