Skip to content

Commit b812d71

Browse files
Fix non-ASCII characters in external items and external file descriptors (#629)
1 parent 76cb6a9 commit b812d71

File tree

2 files changed

+126
-64
lines changed

2 files changed

+126
-64
lines changed

cobj/codegen.c

Lines changed: 24 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -839,15 +839,8 @@ static void joutput_base(struct cb_field *f) {
839839

840840
// EDIT
841841
/* Base name */
842-
if (top->flag_external) {
843-
strcpy(name, top->name);
844-
char *nmp;
845-
for (nmp = name; *nmp; nmp++) {
846-
if (*nmp == '-') {
847-
*nmp = '_';
848-
}
849-
}
850-
} else {
842+
strcpy_identifier_cobol_to_java(name, top->name);
843+
if (!top->flag_external) {
851844
register_data_storage_list(f, top);
852845
}
853846

@@ -2249,9 +2242,7 @@ static void joutput_initialize_fp(cb_tree x, struct cb_field *f) {
22492242
}
22502243

22512244
static void joutput_initialize_external(cb_tree x, struct cb_field *f) {
2252-
unsigned char *p;
22532245
cb_tree file;
2254-
char name[COB_MINI_BUFF];
22552246

22562247
joutput_prefix();
22572248
joutput_data(x);
@@ -2260,22 +2251,10 @@ static void joutput_initialize_external(cb_tree x, struct cb_field *f) {
22602251
f->size);
22612252
} else if (f->storage == CB_STORAGE_FILE) {
22622253
file = CB_TREE(f->file);
2263-
strcpy(name, CB_FILE(file)->record->name);
2264-
for (p = (unsigned char *)name; *p; p++) {
2265-
if (*p == '-') {
2266-
*p = '_';
2267-
}
2268-
}
2269-
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", name,
2270-
f->size);
2254+
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n",
2255+
CB_FILE(file)->record->name, f->size);
22712256
} else {
2272-
strcpy(name, f->name);
2273-
for (p = (unsigned char *)name; *p; p++) {
2274-
if (islower(*p)) {
2275-
*p = (unsigned char)toupper(*p);
2276-
}
2277-
}
2278-
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", name,
2257+
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", f->name,
22792258
f->size);
22802259
}
22812260
}
@@ -4401,13 +4380,11 @@ static void joutput_internal_function(struct cb_program *prog,
44014380
cb_tree l;
44024381
struct cb_field *f;
44034382
struct cb_file *fl;
4404-
char *p;
44054383
int i;
44064384
// int n;
44074385
int parmnum = 0;
44084386
// int seen = 0;
44094387
// int anyseen;
4410-
char name[COB_MINI_BUFF];
44114388

44124389
/* Program function */
44134390
// output ("static int\n%s_ (const int entry", prog->program_id);
@@ -4654,15 +4631,11 @@ static void joutput_internal_function(struct cb_program *prog,
46544631
for (l = prog->file_list; l; l = CB_CHAIN(l)) {
46554632
f = CB_FILE(CB_VALUE(l))->record;
46564633
if (f->flag_external) {
4657-
strcpy(name, f->name);
4658-
for (p = name; *p; p++) {
4659-
if (*p == '-') {
4660-
*p = '_';
4661-
}
4662-
}
4663-
joutput_line("%s%s = CobolExternal.getStorageAddress (\"%s\", %d);",
4664-
CB_PREFIX_BASE, name, name,
4665-
CB_FILE(CB_VALUE(l))->record_max);
4634+
joutput_prefix();
4635+
joutput_base(f);
4636+
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->name,
4637+
CB_FILE(CB_VALUE(l))->record_max);
4638+
joutput_newline();
46664639
}
46674640
}
46684641
joutput_initial_values(prog->working_storage);
@@ -4752,15 +4725,10 @@ static void joutput_internal_function(struct cb_program *prog,
47524725
for (l = prog->file_list; l; l = CB_CHAIN(l)) {
47534726
f = CB_FILE(CB_VALUE(l))->record;
47544727
if (f->flag_external) {
4755-
strcpy(name, f->name);
4756-
for (p = name; *p; p++) {
4757-
if (*p == '-') {
4758-
*p = '_';
4759-
}
4760-
}
4761-
joutput_line("%s%s = CobolExternal.getStorageAddress (\"%s\", %d);",
4762-
CB_PREFIX_BASE, name, name,
4763-
CB_FILE(CB_VALUE(l))->record_max);
4728+
joutput_prefix();
4729+
joutput_base(f);
4730+
joutput_line(" = CobolExternal.getStorageAddress (\"%s\", %d);",
4731+
f->name, CB_FILE(CB_VALUE(l))->record_max);
47644732
}
47654733
}
47664734
joutput_initial_values(prog->working_storage);
@@ -5492,8 +5460,6 @@ static void joutput_declare_member_variables(struct cb_program *prog,
54925460
struct base_list *blp;
54935461
const char *prevprog;
54945462
struct cb_field *f;
5495-
char *p;
5496-
char name[COB_MINI_BUFF];
54975463

54985464
/* CobolDecimal型変数の宣言 */
54995465
if (prog->decimal_index_max) {
@@ -5611,27 +5577,21 @@ static void joutput_declare_member_variables(struct cb_program *prog,
56115577
/* External items */
56125578
for (f = prog->working_storage; f; f = f->sister) {
56135579
if (f->flag_external) {
5614-
strcpy(name, f->name);
5615-
for (p = name; *p; p++) {
5616-
if (*p == '-') {
5617-
*p = '_';
5618-
}
5619-
}
5620-
joutput("private CobolDataStorage\t%s%s = null;", CB_PREFIX_BASE, name);
5621-
joutput(" /* %s */\n", f->name);
5580+
joutput_prefix();
5581+
joutput("private CobolDataStorage ");
5582+
joutput_base(f);
5583+
joutput(" = null; /* %s */", f->name);
5584+
joutput_newline();
56225585
}
56235586
}
56245587
for (l = prog->file_list; l; l = CB_CHAIN(l)) {
56255588
f = CB_FILE(CB_VALUE(l))->record;
56265589
if (f->flag_external) {
5627-
strcpy(name, f->name);
5628-
for (p = name; *p; p++) {
5629-
if (*p == '-') {
5630-
*p = '_';
5631-
}
5632-
}
5633-
joutput("private CobolDataStorage\t%s%s = null;", CB_PREFIX_BASE, name);
5634-
joutput(" /* %s */\n", f->name);
5590+
joutput_prefix();
5591+
joutput("private CobolDataStorage ");
5592+
joutput_base(f);
5593+
joutput(" = null; /* %s */", f->name);
5594+
joutput_newline();
56355595
}
56365596
}
56375597

tests/misc.src/fd-external.at

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,105 @@ AT_CHECK([java prog], [0],
6666
])
6767

6868
AT_CLEANUP
69+
70+
AT_SETUP([FD EXTERNAL nihongo])
71+
72+
AT_DATA([prog1.cbl], [
73+
IDENTIFICATION DIVISION.
74+
PROGRAM-ID. prog1.
75+
environment division.
76+
input-output section.
77+
file-control.
78+
select f assign to 'file.txt'
79+
organization is line sequential
80+
access mode is sequential.
81+
DATA DIVISION.
82+
file section.
83+
fd f is external.
84+
01 �a�b�|�P pic x(5).
85+
working-storage section.
86+
01 �a�b�|�Q pic x(5) external.
87+
PROCEDURE DIVISION.
88+
initialize �a�b�|�P.
89+
initialize �a�b�|�Q.
90+
91+
open output f.
92+
call "sub".
93+
close f.
94+
95+
open input f.
96+
read f.
97+
close f.
98+
99+
display �a�b�|�P.
100+
display �a�b�|�Q.
101+
STOP RUN.
102+
])
103+
104+
AT_DATA([prog2.cbl], [
105+
IDENTIFICATION DIVISION.
106+
PROGRAM-ID. prog2 is initial.
107+
108+
environment division.
109+
input-output section.
110+
file-control.
111+
select f assign to 'file.txt'
112+
organization is line sequential
113+
access mode is sequential.
114+
DATA DIVISION.
115+
file section.
116+
fd f is external.
117+
01 �a�b�|�P pic x(5).
118+
working-storage section.
119+
01 �a�b�|�Q pic x(5) external.
120+
PROCEDURE DIVISION.
121+
initialize �a�b�|�P.
122+
initialize �a�b�|�Q.
123+
124+
open output f.
125+
call "sub".
126+
close f.
127+
128+
open input f.
129+
read f.
130+
close f.
131+
132+
display �a�b�|�P.
133+
display �a�b�|�Q.
134+
STOP RUN.
135+
])
136+
137+
AT_DATA([sub.cbl], [
138+
IDENTIFICATION DIVISION.
139+
PROGRAM-ID. sub.
140+
environment division.
141+
input-output section.
142+
file-control.
143+
select f assign to "file.txt"
144+
organization is line sequential
145+
access mode is sequential.
146+
DATA DIVISION.
147+
file section.
148+
fd f is external.
149+
01 �a�b�|�P pic x(5).
150+
working-storage section.
151+
01 �a�b�|�Q pic x(5) external.
152+
PROCEDURE DIVISION.
153+
move "abcde" to �a�b�|�P.
154+
write �a�b�|�P.
155+
move "12345" to �a�b�|�Q.
156+
goback.
157+
])
158+
159+
AT_CHECK([${COBJ} prog1.cbl prog2.cbl sub.cbl])
160+
AT_CHECK([java prog1], [0],
161+
[abcde
162+
12345
163+
])
164+
165+
AT_CHECK([java prog2], [0],
166+
[abcde
167+
12345
168+
])
169+
170+
AT_CLEANUP

0 commit comments

Comments
 (0)