@@ -177,6 +177,60 @@ static void joutput_alphabet_name_initialization(struct cb_alphabet_name *p);
177
177
const int L_initextern_addr = 2000000000 ;
178
178
int param_wrap_string_flag = 0 ;
179
179
180
+ static char * get_java_identifier_field (struct cb_field * f );
181
+ static char * get_java_identifier_base (struct cb_field * f );
182
+ static void get_java_identifier_helper (struct cb_field * f , char * buf );
183
+ static void strcpy_identifier_cobol_to_java (char * buf , char * identifier );
184
+ //#define ENABLE_EMBED_ORIGINAL_VARIABLE_NAME 1
185
+
186
+ static char *
187
+ get_java_identifier_field (struct cb_field * f ) {
188
+ char * buf = malloc (COB_SMALL_BUFF );
189
+ if (cb_flag_embed_var_name ) {
190
+ strcpy (buf , CB_PREFIX_FIELD );
191
+ get_java_identifier_helper (f , buf + strlen (CB_PREFIX_FIELD ));
192
+ } else {
193
+ sprintf (buf , "%s%d" , CB_PREFIX_FIELD , f -> id );
194
+ }
195
+ return buf ;
196
+ }
197
+
198
+ static char *
199
+ get_java_identifier_base (struct cb_field * f ) {
200
+ char * buf = malloc (COB_SMALL_BUFF );
201
+ if (cb_flag_embed_var_name ) {
202
+ strcpy (buf , CB_PREFIX_BASE );
203
+ get_java_identifier_helper (f , buf + strlen (CB_PREFIX_BASE ));
204
+ } else {
205
+ sprintf (buf , "%s%d" , CB_PREFIX_BASE , f -> id );
206
+ }
207
+ return buf ;
208
+ }
209
+
210
+ static void
211
+ get_java_identifier_helper (struct cb_field * f , char * buf ) {
212
+ static const char * of = "_of_" ;
213
+ strcpy_identifier_cobol_to_java (buf , f -> name );
214
+ buf += strlen (f -> name );
215
+ if (f -> parent != NULL ) {
216
+ strcpy (buf , of );
217
+ buf += strlen (of );
218
+ get_java_identifier_helper (f -> parent , buf );
219
+ }
220
+ }
221
+
222
+ static void strcpy_identifier_cobol_to_java (char * buf , char * identifier ) {
223
+ for (; * identifier != '\0' ; ++ identifier , ++ buf ) {
224
+ if (* identifier == '-' ) {
225
+ * buf = '_' ;
226
+ } else {
227
+ * buf = * identifier ;
228
+ }
229
+ }
230
+ * buf = '\0' ;
231
+ }
232
+
233
+
180
234
static void
181
235
lookup_call (const char * p )
182
236
{
@@ -467,7 +521,8 @@ joutput_base (struct cb_field *f)
467
521
struct cb_field * v ;
468
522
struct base_list * bl ;
469
523
char * nmp ;
470
- char name [COB_MINI_BUFF ];
524
+ char name [COB_SMALL_BUFF ];
525
+ char * base_name ;
471
526
472
527
f01 = cb_field_founder (f );
473
528
@@ -480,6 +535,7 @@ joutput_base (struct cb_field *f)
480
535
f01 = f01 -> redefines ;
481
536
}
482
537
538
+ //EDIT
483
539
/* Base name */
484
540
if (f01 -> flag_external ) {
485
541
strcpy (name , f01 -> name );
@@ -489,7 +545,9 @@ joutput_base (struct cb_field *f)
489
545
}
490
546
}
491
547
} else {
492
- sprintf (name , "%d" , f01 -> id );
548
+ //sprintf (name, "%d", f01->id);
549
+ base_name = get_java_identifier_base (f01 );
550
+ strcpy (name , base_name );
493
551
}
494
552
495
553
if (!f01 -> flag_base ) {
@@ -502,6 +560,8 @@ joutput_base (struct cb_field *f)
502
560
base_cache = bl ;
503
561
} else {
504
562
if (current_prog -> flag_global_use ) {
563
+ joutput_local ("unsigned char\t\t*%s%s = NULL;" ,
564
+ CB_PREFIX_BASE , name );
505
565
joutput_local ("unsigned char\t\t*%s%s = NULL;" ,
506
566
CB_PREFIX_BASE , name );
507
567
joutput_local ("\t/* %s */\n" , f01 -> name );
@@ -516,7 +576,13 @@ joutput_base (struct cb_field *f)
516
576
}
517
577
f01 -> flag_base = 1 ;
518
578
}
519
- joutput ("%s%s" , CB_PREFIX_BASE , name );
579
+
580
+ if (f01 -> flag_external ) {
581
+ joutput ("%s%s" , CB_PREFIX_BASE , name );
582
+ } else {
583
+ joutput (name );
584
+ free (base_name );
585
+ }
520
586
521
587
if (cb_field_variable_address (f )) {
522
588
for (p = f -> parent ; p ; f = f -> parent , p = f -> parent ) {
@@ -1307,22 +1373,26 @@ joutput_param (cb_tree x, int id)
1307
1373
joutput_target = savetarget ;
1308
1374
}
1309
1375
if (f -> flag_local ) {
1376
+ char * field_name = get_java_identifier_field (f );
1310
1377
if (f -> flag_any_length && f -> flag_anylen_done ) {
1311
- joutput ( "%s%d" , CB_PREFIX_FIELD , f -> id );
1378
+ joutput ( field_name );
1312
1379
} else {
1313
1380
joutput ("new GetAbstractCobolField() { " );
1314
- joutput ("public AbstractCobolField run() { %s%d .setDataStorage(" , CB_PREFIX_FIELD , f -> id );
1381
+ joutput ("public AbstractCobolField run() { %s.setDataStorage(" , field_name );
1315
1382
joutput_data (x );
1316
- joutput ("); return %s%d ; }}.run()" , CB_PREFIX_FIELD , f -> id );
1383
+ joutput ("); return %s; }}.run()" , field_name );
1317
1384
if (f -> flag_any_length ) {
1318
1385
f -> flag_anylen_done = 1 ;
1319
1386
}
1320
1387
}
1388
+ free (field_name );
1321
1389
} else {
1322
1390
if (screenptr && f -> storage == CB_STORAGE_SCREEN ) {
1323
1391
joutput ("s_%d" , f -> id );
1324
1392
} else {
1325
- joutput ("%s%d" , CB_PREFIX_FIELD , f -> id );
1393
+ char * field_name = get_java_identifier_field (f );
1394
+ joutput (field_name );
1395
+ free (field_name );
1326
1396
}
1327
1397
}
1328
1398
} else {
@@ -4111,8 +4181,13 @@ joutput_internal_function (struct cb_program *prog, cb_tree parameter_list)
4111
4181
if (!prog -> flag_chained ) {
4112
4182
int k ;
4113
4183
for (k = 0 , l = parameter_list ; l ; l = CB_CHAIN (l ), ++ k ) {
4114
- joutput_line ("this.%s%d = %d < argStorages.length ? argStorages[%d] : null;" ,
4115
- CB_PREFIX_BASE , cb_field (CB_VALUE (l ))-> id , k , k );
4184
+ //EDIT
4185
+ char * base_name = get_java_identifier_base (cb_field (CB_VALUE (l )));
4186
+ //joutput_line("this.%s%d = %d < argStorages.length ? argStorages[%d] : null;",
4187
+ //CB_PREFIX_BASE, cb_field (CB_VALUE (l))->id, k, k);
4188
+ joutput_line ("this.%s = %d < argStorages.length ? argStorages[%d] : null;" ,
4189
+ base_name , k , k );
4190
+ free (base_name );
4116
4191
parmnum ++ ;
4117
4192
}
4118
4193
}
@@ -4787,7 +4862,10 @@ joutput_internal_function (struct cb_program *prog, cb_tree parameter_list)
4787
4862
for (k = field_cache ; k ; k = k -> next ) {
4788
4863
if (k -> f -> flag_item_external ) {
4789
4864
joutput_prefix ();
4790
- joutput ("\t%s%d.setDataStorage(" , CB_PREFIX_FIELD , k -> f -> id );
4865
+ //EDIT
4866
+ char * field_name = get_java_identifier_field (k -> f );
4867
+ joutput ("\t%s.setDataStorage(" , k -> f );
4868
+ free (field_name );
4791
4869
joutput_data (k -> x );
4792
4870
joutput (");\n" );
4793
4871
}
@@ -4936,21 +5014,28 @@ void joutput_init_method(struct cb_program *prog) {
4936
5014
joutput_line ("cob_unifunc = null;\n" );
4937
5015
base_cache = list_cache_sort (base_cache , & base_cache_cmp );
4938
5016
prevprog = NULL ;
5017
+ //EDIT
4939
5018
for (blp = base_cache ; blp ; blp = blp -> next ) {
5019
+ char * base_name = get_java_identifier_base (blp -> f );
4940
5020
if (blp -> curr_prog != prevprog ) {
4941
5021
prevprog = blp -> curr_prog ;
4942
5022
joutput_prefix ();
4943
5023
joutput ("/* PROGRAM-ID : %s */\n" , prevprog );
4944
5024
joutput_prefix ();
4945
- joutput ("%s%d = new CobolDataStorage(%d);" ,
4946
- CB_PREFIX_BASE , blp -> f -> id ,
5025
+ //joutput ("%s%d = new CobolDataStorage(%d);",
5026
+ //CB_PREFIX_BASE, blp->f->id,
5027
+ joutput ("%s = new CobolDataStorage(%d);" ,
5028
+ base_name ,
4947
5029
blp -> f -> memory_size );
4948
5030
} else {
4949
5031
joutput_prefix ();
4950
- joutput ("%s%d = new CobolDataStorage(%d);" ,
4951
- CB_PREFIX_BASE , blp -> f -> id ,
5032
+ //joutput ("%s%d = new CobolDataStorage(%d);",
5033
+ //CB_PREFIX_BASE, blp->f->id,
5034
+ joutput ("%s = new CobolDataStorage(%d);" ,
5035
+ base_name ,
4952
5036
blp -> f -> memory_size );
4953
5037
}
5038
+ free (base_name );
4954
5039
joutput ("\t/* %s */\n" , blp -> f -> name );
4955
5040
}
4956
5041
joutput ("\n" );
@@ -4974,8 +5059,9 @@ void joutput_init_method(struct cb_program *prog) {
4974
5059
}
4975
5060
4976
5061
joutput_prefix ();
4977
- joutput ("%s%d\t= " , CB_PREFIX_FIELD ,
4978
- k -> f -> id );
5062
+ char * field_name = get_java_identifier_field (k -> f );
5063
+ joutput ("%s\t= " , field_name );
5064
+ free (field_name );
4979
5065
if (!k -> f -> flag_local && !k -> f -> flag_item_external ) {
4980
5066
joutput_field (k -> x );
4981
5067
} else {
@@ -5298,20 +5384,27 @@ void joutput_declare_member_variables(struct cb_program *prog, cb_tree parameter
5298
5384
base_cache = list_cache_sort (base_cache , & base_cache_cmp );
5299
5385
prevprog = NULL ;
5300
5386
for (blp = base_cache ; blp ; blp = blp -> next ) {
5387
+ //EDIT
5388
+ char * base_name = get_java_identifier_base (blp -> f );
5301
5389
if (blp -> curr_prog != prevprog ) {
5302
5390
prevprog = blp -> curr_prog ;
5303
5391
joutput_prefix ();
5304
5392
joutput ("/* PROGRAM-ID : %s */\n" , prevprog );
5305
5393
joutput_prefix ();
5306
- joutput ("private CobolDataStorage %s%d;" ,
5307
- CB_PREFIX_BASE , blp -> f -> id ,
5394
+ //joutput ("private CobolDataStorage %s%d;",
5395
+ //CB_PREFIX_BASE, blp->f->id,
5396
+ joutput ("private CobolDataStorage %s;" ,
5397
+ base_name ,
5308
5398
blp -> f -> memory_size );
5309
5399
} else {
5310
5400
joutput_prefix ();
5311
- joutput ("private CobolDataStorage %s%d;" ,
5312
- CB_PREFIX_BASE , blp -> f -> id ,
5401
+ //joutput ("private CobolDataStorage %s%d;",
5402
+ //CB_PREFIX_BASE, blp->f->id,
5403
+ joutput ("private CobolDataStorage %s;" ,
5404
+ base_name ,
5313
5405
blp -> f -> memory_size );
5314
5406
}
5407
+ free (base_name );
5315
5408
joutput ("\t/* %s */\n" , blp -> f -> name );
5316
5409
}
5317
5410
joutput ("\n" );
@@ -5320,8 +5413,12 @@ void joutput_declare_member_variables(struct cb_program *prog, cb_tree parameter
5320
5413
5321
5414
joutput_line ("/* Call parameters */" );
5322
5415
for (l = parameter_list ; l ; l = CB_CHAIN (l )) {
5323
- joutput_line ("private CobolDataStorage %s%d;" ,
5324
- CB_PREFIX_BASE , cb_field (CB_VALUE (l ))-> id );
5416
+ char * base_name = get_java_identifier_base (cb_field (CB_VALUE (l ))-> id );
5417
+ //joutput_line("private CobolDataStorage %s%d;",
5418
+ //CB_PREFIX_BASE, cb_field (CB_VALUE (l))->id);
5419
+ joutput_line ("private CobolDataStorage %s;" ,
5420
+ base_name );
5421
+ free (base_name );
5325
5422
}
5326
5423
5327
5424
/* External items */
@@ -5365,8 +5462,9 @@ void joutput_declare_member_variables(struct cb_program *prog, cb_tree parameter
5365
5462
prevprog );
5366
5463
}
5367
5464
joutput_prefix ();
5368
- joutput ("private AbstractCobolField %s%d;" , CB_PREFIX_FIELD ,
5369
- k -> f -> id );
5465
+ char * field_name = get_java_identifier_field (k -> f );
5466
+ joutput ("private AbstractCobolField %s;" , field_name );
5467
+ free (field_name );
5370
5468
joutput ("\t/* %s */\n" , k -> f -> name );
5371
5469
}
5372
5470
joutput ("\n" );
0 commit comments