Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions cobj/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,31 +234,56 @@ static void get_java_identifier_helper(struct cb_field *f, char *buf) {
}

static void strcpy_identifier_cobol_to_java(char *buf, const char *identifier) {
int all_ascii = 1;
unsigned char *p = (unsigned char *)identifier;
for (; *p; ++p) {
unsigned char c = *p;
if (c < 0x0A || 0x80 <= c) {
all_ascii = 0;
break;
if (cb_flag_var_name_hex) {
int all_ascii = 1;
unsigned char *p = (unsigned char *)identifier;
for (; *p; ++p) {
unsigned char c = *p;
if (c < 0x0A || 0x80 <= c) {
all_ascii = 0;
break;
}
}
}

if (all_ascii) {
for (; *identifier; ++identifier, ++buf) {
if (*identifier == '-') {
*buf = '_';
} else {
*buf = *identifier;
if (all_ascii) {
for (; *identifier; ++identifier, ++buf) {
if (*identifier == '-') {
*buf = '_';
} else {
*buf = *identifier;
}
}
} else {
for (; *identifier; ++identifier) {
sprintf(buf, "%02x", (unsigned char)*identifier);
buf += 2;
}
}
*buf = '\0';
} else {
for (; *identifier; ++identifier) {
sprintf(buf, "%02x", (unsigned char)*identifier);
buf += 2;
unsigned char *src = (unsigned char *)identifier;
unsigned char *dst = (unsigned char *)buf;
while (*src) {
// ASCII characters
if (*src < 0x80) {
*dst = (*src == '-') ? '_' : *src;
++dst;
++src;
// Shift_JIS characters
} else {
if (src[0] == 0x81 && src[1] == 0x7C) {
dst[0] = 0x81;
dst[1] = 0x51;
} else {
dst[0] = src[0];
dst[1] = src[1];
}
dst += 2;
src += 2;
}
}
*dst = '\0';
}
*buf = '\0';
}

struct cb_label_id_map {
Expand Down
3 changes: 3 additions & 0 deletions cobj/flag-help.def
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ CB_FLAG (cb_flag_functions_all, "functions-all",
CB_FLAG (cb_flag_mfcomment, "mfcomment",
N_("'*' or '/' in column 1 treated as comment (FIXED only)"))

CB_FLAG (cb_flag_var_name_hex, "var-name-hex",
N_("Use hexdecimal representation for variable names that contains non-ASCII characters"))

//CB_FLAG (cb_flag_no_cobol_comment, "no-cobol-comment",
// N_("Do not generate COBOL comments into Java programs"))
3 changes: 3 additions & 0 deletions cobj/flag.def
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ CB_FLAG (cb_flag_serial_variable, "serial-variable",
CB_FLAG (cb_flag_short_variable, "short-variable",
N_("Use short variable names in Java source code. This feature may cause compilation errors"))

CB_FLAG (cb_flag_var_name_hex, "var-name-hex",
N_("Use hexdecimal representation for variable names that contains non-ASCII characters"))

//CB_FLAG (cb_flag_no_cobol_comment, "no-cobol-comment",
// N_("Do not generate COBOL comments into Java programs"))
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ command_line_options_DEPENDENCIES = \
command-line-options.src/Wtruncate.at \
command-line-options.src/Wunreachable.at \
command-line-options.src/ftrace-ftraceall.at \
command-line-options.src/fvar-name-hex.at \
command-line-options.src/fsyntax-only.at \
command-line-options.src/fserial-variable.at \
command-line-options.src/fshort-variable.at \
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ command_line_options_DEPENDENCIES = \
command-line-options.src/Wtruncate.at \
command-line-options.src/Wunreachable.at \
command-line-options.src/ftrace-ftraceall.at \
command-line-options.src/fvar-name-hex.at \
command-line-options.src/fsyntax-only.at \
command-line-options.src/fserial-variable.at \
command-line-options.src/fshort-variable.at \
Expand Down
1 change: 1 addition & 0 deletions tests/command-line-options.at
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ m4_include([Wterminator.at])
m4_include([Wtruncate.at])
m4_include([Wunreachable.at])
m4_include([ftrace-ftraceall.at])
m4_include([fvar-name-hex.at])
m4_include([fsyntax-only.at])
m4_include([fserial-variable.at])
m4_include([ffold-copy.at])
Expand Down
68 changes: 68 additions & 0 deletions tests/command-line-options.src/fvar-name-hex.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
AT_SETUP([-fvar-name-hex])

AT_DATA([prog.cbl], [ IDENTIFICATION DIVISION.
PROGRAM-ID. prog.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 �V�h PIC x(5) VALUE "00000".
01 ���l�|�P PIC x(5) VALUE "11111".
01 �b�{�|2 PIC x(5) VALUE "22222".
01 �F�s�{�P PIC x(5) VALUE "33333".
01 ���2 PIC x(5) VALUE "44444".
PROCEDURE DIVISION.
�������x��.
DISPLAY �V�h.
�_�ސ�|�P���x��.
DISPLAY ���l�|�P.
�R���|2���x��.
DISPLAY �b�{�|2.
�Ȗ؂P���x��.
DISPLAY �F�s�{�P.
�{��2���x��.
DISPLAY ���2.
])


AT_CHECK([${COMPILE} prog.cbl])
AT_CHECK([${RUN_MODULE} prog], [0],
[00000
11111
22222
33333
44444
])
AT_CHECK([cat prog.java | grep "�V�h" > /dev/null])
AT_CHECK([cat prog.java | grep "���l�|�P" > /dev/null])
AT_CHECK([cat prog.java | grep "�b�{�|2" > /dev/null])
AT_CHECK([cat prog.java | grep "�F�s�{�P" > /dev/null])
AT_CHECK([cat prog.java | grep "���2" > /dev/null])

AT_CHECK([cat prog.java | grep "�������x��" > /dev/null])
AT_CHECK([cat prog.java | grep "�_�ސ�|�P���x��" > /dev/null])
AT_CHECK([cat prog.java | grep "�R���|2���x��" > /dev/null])
AT_CHECK([cat prog.java | grep "�Ȗ؂P���x��" > /dev/null])
AT_CHECK([cat prog.java | grep "�{��2���x��" > /dev/null])

AT_CHECK([${COMPILE} -fvar-name-hex prog.cbl])
AT_CHECK([${RUN_MODULE} prog], [0],
[00000
11111
22222
33333
44444
])

AT_CHECK([cat prog.java | grep "90568f68" > /dev/null])
AT_CHECK([cat prog.java | grep "89a1956c817c8250" > /dev/null])
AT_CHECK([cat prog.java | grep "8d62957b817c32" > /dev/null])
AT_CHECK([cat prog.java | grep "894693738b7b8250" > /dev/null])
AT_CHECK([cat prog.java | grep "90e591e432" > /dev/null])

AT_CHECK([cat prog.java | grep "938c8b9e83898378838b" > /dev/null])
AT_CHECK([cat prog.java | grep "905f93de90ec817c825083898378838b" > /dev/null])
AT_CHECK([cat prog.java | grep "8e52979c817c3283898378838b" > /dev/null])
AT_CHECK([cat prog.java | grep "93c896d8825083898378838b" > /dev/null])
AT_CHECK([cat prog.java | grep "8b7b8fe93283898378838b" > /dev/null])

AT_CLEANUP