@@ -79,6 +79,8 @@ static const char *excp_current_program_id = NULL;
7979static const char * excp_current_section = NULL ;
8080static const char * excp_current_paragraph = NULL ;
8181static struct cb_program * current_prog ;
82+ static size_t * sgmt_sizes = NULL ;
83+ static size_t sgmt_count = 0 ;
8284
8385extern int cb_default_byte_specified ;
8486extern unsigned char cb_default_byte ;
@@ -463,6 +465,7 @@ struct string_literal_cache {
463465 enum cb_string_category category ;
464466 char * var_name ;
465467 struct string_literal_cache * next ;
468+ size_t * segment_sizes ; /* segment sizes for strings concatenated with '&' */
466469};
467470
468471int string_literal_id = 0 ;
@@ -531,7 +534,8 @@ static enum cb_string_category get_string_category(const unsigned char *s,
531534}
532535
533536static void joutput_string_write (const unsigned char * s , int size ,
534- enum cb_string_category category ) {
537+ enum cb_string_category category ,
538+ const size_t * tmp_sgmt_sizes ) {
535539 int i ;
536540
537541#ifdef I18N_UTF8
@@ -552,7 +556,11 @@ static void joutput_string_write(const unsigned char *s, int size,
552556 } else {
553557 joutput ("CobolUtil.stringToBytes(" );
554558 }
555-
559+ if (tmp_sgmt_sizes ) {
560+ joutput_indent_level += 2 ;
561+ joutput_newline ();
562+ joutput_prefix ();
563+ }
556564 joutput ("\"" );
557565
558566#ifdef I18N_UTF8
@@ -568,6 +576,8 @@ static void joutput_string_write(const unsigned char *s, int size,
568576 }
569577#else
570578 int output_multibyte = 0 ;
579+ int sum_sgmt_size = 0 ;
580+ int sgmt_index = 0 ;
571581 for (i = 0 ; i < size ; i ++ ) {
572582 int c = s [i ];
573583 if (!output_multibyte && (c == '\"' || c == '\\' )) {
@@ -577,11 +587,33 @@ static void joutput_string_write(const unsigned char *s, int size,
577587 } else {
578588 joutput ("%c" , c );
579589 }
590+
591+ // insert line breaks between segments concatenated with '&'
592+ if (tmp_sgmt_sizes && i < size - 1 ) {
593+ size_t segment_end_position =
594+ sum_sgmt_size + tmp_sgmt_sizes [sgmt_index ] - 1 ;
595+ if (i == segment_end_position ) {
596+ joutput ("\" + " );
597+ joutput_newline ();
598+ joutput_prefix ();
599+ joutput ("\"" );
600+ sum_sgmt_size += tmp_sgmt_sizes [sgmt_index ];
601+ sgmt_index ++ ;
602+ }
603+ }
580604 output_multibyte = !output_multibyte &&
581605 ((0x81 <= c && c <= 0x9f ) || (0xe0 <= c && c <= 0xef ));
582606 }
583607#endif
584- joutput ("\")" );
608+ if (tmp_sgmt_sizes ) {
609+ joutput ("\"" );
610+ joutput_newline ();
611+ joutput_indent_level -= 2 ;
612+ joutput_prefix ();
613+ joutput (")" );
614+ } else {
615+ joutput ("\")" );
616+ }
585617 } else {
586618 if (param_wrap_string_flag ) {
587619 joutput ("CobolDataStorage.makeCobolDataStorage(" );
@@ -631,6 +663,16 @@ static void joutput_string(const unsigned char *s, int size) {
631663 new_literal_cache -> var_name [var_name_length + 1 + i ] = '\0' ;
632664 }
633665
666+ // set segment sizes to new cache
667+ if (sgmt_sizes ) {
668+ new_literal_cache -> segment_sizes = cobc_malloc (sizeof (size_t ) * sgmt_count );
669+ memcpy (new_literal_cache -> segment_sizes , sgmt_sizes ,
670+ sizeof (size_t ) * sgmt_count );
671+ sgmt_sizes = NULL ;
672+ } else {
673+ new_literal_cache -> segment_sizes = NULL ;
674+ }
675+
634676 // add the new cache to string_literal_list
635677 new_literal_cache -> next = string_literal_list ;
636678 string_literal_list = new_literal_cache ;
@@ -658,7 +700,8 @@ static void joutput_all_string_literals() {
658700 joutput_prefix ();
659701 joutput ("public static final %s %s = " , data_type , l -> var_name );
660702 param_wrap_string_flag = l -> param_wrap_string_flag ;
661- joutput_string_write (l -> string_value , l -> size , l -> category );
703+ joutput_string_write (l -> string_value , l -> size , l -> category ,
704+ l -> segment_sizes );
662705 joutput (";\n" );
663706 l = l -> next ;
664707 }
@@ -2280,6 +2323,13 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) {
22802323 /* Initialize by value */
22812324 if (p -> val && f -> values ) {
22822325 cb_tree value = CB_VALUE (f -> values );
2326+ struct cb_literal * l = CB_LITERAL_P (value ) ? CB_LITERAL (value ) : NULL ;
2327+ // save the size information of '&' concatenated segments
2328+ if (l && l -> segment_count > 0 ) {
2329+ sgmt_sizes = cobc_malloc (sizeof (size_t ) * l -> segment_count );
2330+ memcpy (sgmt_sizes , l -> segment_sizes , sizeof (size_t ) * l -> segment_count );
2331+ sgmt_count = l -> segment_count ;
2332+ }
22832333
22842334 /* NATIONAL also needs no editing but mbchar conversion. */
22852335 if (CB_TREE_CATEGORY (x ) == CB_CATEGORY_NATIONAL ) {
@@ -2340,7 +2390,6 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) {
23402390 /* We do not use joutput_move here because
23412391 we do not want to have the value be edited. */
23422392
2343- struct cb_literal * l = CB_LITERAL (value );
23442393 static char * buff = NULL ;
23452394 static int lastsize = 0 ;
23462395 if (!buff ) {
0 commit comments