2 *** QADRT/QADRTMAIN2 substitution program.
3 *** This is needed because the IBM-provided QADRTMAIN2 does not
4 *** properly translate arguments by default or if no locale is provided.
6 *** See Copyright for the status of this software.
8 *** Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.
17 /* Do not use qadrt.h since it defines unneeded static procedures. */
18 extern void QadrtInit(void);
19 extern int QadrtFreeConversionTable(void);
20 extern int QadrtFreeEnviron(void);
21 extern char * setlocale_a(int, const char *);
24 /* The ASCII main program. */
25 extern int main_a(int argc, char * * argv);
27 /* Global values of original EBCDIC arguments. */
33 main(int argc, char * * argv)
51 /* Build the encoding converter. */
52 strncpy(tocode, "IBMCCSID01208", sizeof tocode);
53 strncpy(fromcode, "IBMCCSID000000000010", sizeof fromcode);
54 cd = iconv_open(tocode, fromcode);
56 /* Measure the arguments. */
57 for (i = 0; i < argc; i++) {
62 outbytesleft = sizeof dummybuf;
64 &inbuf, &inbytesleft, &outbuf, &outbytesleft);
65 bytecount += outbuf - dummybuf;
66 } while (j == -1 && errno == E2BIG);
67 /* Reset the shift state. */
68 iconv(cd, NULL, &inbytesleft, &outbuf, &outbytesleft);
71 /* Allocate memory for the ASCII arguments and vector. */
72 argv = (char * *) malloc((argc + 1) * sizeof *argv + bytecount);
74 /* Build the vector and convert argument encoding. */
75 outbuf = (char *) (argv + argc + 1);
76 outbytesleft = bytecount;
78 for (i = 0; i < argc; i++) {
80 inbuf = ebcdic_argv[i];
82 iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
83 iconv(cd, NULL, &inbytesleft, &outbuf, &outbytesleft);
89 /* Try setting the locale regardless of QADRT_ENV_LOCALE. */
90 setlocale_a(LC_ALL, "");
92 /* Call the program. */
93 i = main_a(argc, argv);
95 /* Clean-up allocated items. */
97 QadrtFreeConversionTable();