Skip to content

Commit 3acf3e4

Browse files
Convert string literals containing SJIS characters to Java string literals (#561)
* fix: convert SJIS string literals to ordinary Java string literals * test: add test suites
1 parent 0700bac commit 3acf3e4

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

cobj/codegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ static void joutput_string_write(const unsigned char *s, int size,
505505
enum cb_string_category category) {
506506
int i;
507507

508-
if (category == CB_STRING_CATEGORY_ALL_ASCII) {
508+
if (category == CB_STRING_CATEGORY_ALL_ASCII ||
509+
category == CB_STRING_CATEGORY_ALL_SJIS) {
509510
if (param_wrap_string_flag) {
510511
joutput("new CobolDataStorage(");
511512
} else {

tests/i18n_sjis.src/pic-x.at

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,62 @@ AT_CHECK([cobj prog.cob], [0])
483483
AT_CHECK([java prog], [0], [02])
484484

485485
AT_CLEANUP
486+
487+
AT_SETUP([Readable string literals])
488+
# Older compilers converts string literals "���{��" in COBOL source code
489+
# to `CobolUtil.toBytes((byte)0x93, (byte)0xfa, (byte)0x96, (byte)0x7b, (byte)0x8c, (byte)0xea)` in Java source code.
490+
# The following tests check that the compiler converts the string literals to readable ones.
491+
492+
AT_DATA([prog1.cob], [
493+
IDENTIFICATION DIVISION.
494+
PROGRAM-ID. prog1.
495+
DATA DIVISION.
496+
WORKING-STORAGE SECTION.
497+
01 F0 PIC X(30) VALUE "����1".
498+
PROCEDURE DIVISION.
499+
MOVE "����2" TO F0.
500+
DISPLAY "����3".
501+
])
502+
503+
AT_CHECK([cobj prog1.cob])
504+
AT_CHECK([grep '����1' < prog1.java > /dev/null])
505+
AT_CHECK([grep '����2' < prog1.java > /dev/null])
506+
AT_CHECK([grep '����3' < prog1.java > /dev/null])
507+
508+
# '�@' is the first multi-byte Shift-JIS character with respect to the byte order
509+
# see http://charset.7jp.net/sjis.html
510+
AT_DATA([prog2.cob], [
511+
IDENTIFICATION DIVISION.
512+
PROGRAM-ID. prog2.
513+
DATA DIVISION.
514+
WORKING-STORAGE SECTION.
515+
01 F0 PIC X(30) VALUE "�@1".
516+
PROCEDURE DIVISION.
517+
MOVE "�@2" TO F0.
518+
DISPLAY "�@3".
519+
])
520+
521+
AT_CHECK([cobj prog2.cob])
522+
AT_CHECK([grep '�@1' < prog2.java > /dev/null])
523+
AT_CHECK([grep '�@2' < prog2.java > /dev/null])
524+
AT_CHECK([grep '�@3' < prog2.java > /dev/null])
525+
526+
# '�' is the last printable Shift-JIS character with respect to the byte order.
527+
# See http://charset.7jp.net/sjis.html
528+
AT_DATA([prog3.cob], [
529+
IDENTIFICATION DIVISION.
530+
PROGRAM-ID. prog3.
531+
DATA DIVISION.
532+
WORKING-STORAGE SECTION.
533+
01 F0 PIC X(30) VALUE "�1".
534+
PROCEDURE DIVISION.
535+
MOVE "�2" TO F0.
536+
DISPLAY "�3".
537+
])
538+
539+
AT_CHECK([cobj prog3.cob])
540+
AT_CHECK([grep '�1' < prog3.java > /dev/null])
541+
AT_CHECK([grep '�2' < prog3.java > /dev/null])
542+
AT_CHECK([grep '�3' < prog3.java > /dev/null])
543+
544+
AT_CLEANUP

0 commit comments

Comments
 (0)