Debian Codegraph @

libgcobol/valconv.cc

raw
1 // This file is included in both the libgcobol and gcc/cobol compilations
2 /*
3 * Copyright (c) 2021-2025 Symas Corporation
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of the Symas Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <cctype>
33 #include <cstdio>
34 #include <cstring>
35
36 #include <algorithm>
37 #include <unordered_map>
38 #include <vector>
39
40 #include "ec.h"
41 #include "common-defs.h"
42 #include "charmaps.h"
43
44 #include "valconv.h"
45 #include "exceptl.h"
46
47 int __gg__decimal_point = '.' ;
48 int __gg__decimal_separator = ',' ;
49 int __gg__quote_character = '"' ;
50 int __gg__low_value_character = 0x00 ;
51 int __gg__high_value_character = 0xFF ;
52 char **__gg__currency_signs ;
53
54 int __gg__default_currency_sign;
55
56 char *__gg__ct_currency_signs[256]; // Compile-time currency signs
57
58 std::unordered_map<size_t, alphabet_state> __gg__alphabet_states;
59
60 extern "C"
61 void
62 __gg__realloc_if_necessary(char **dest, size_t *dest_size, size_t new_size)
63 {
64 if( new_size > *dest_size )
65 {
66 // Find the next power of two bigger than us:
67 new_size |= new_size>>1;
68 new_size |= new_size>>2;
69 new_size |= new_size>>4;
70 new_size |= new_size>>8;
71 new_size |= new_size>>16;
72 new_size |= (new_size>>16)>>16;
73 *dest_size = new_size + 1;
74 *dest = static_cast<char *>(realloc(*dest, *dest_size));
75 }
76 }
77
78 extern "C"
79 void
80 __gg__alphabet_create( cbl_encoding_t encoding,
81 size_t alphabet_index,
82 const unsigned char *alphabet,
83 int low_char,
84 int high_char )
85 {
86 assert( encoding == custom_encoding_e );
87
88 std::unordered_map<size_t, alphabet_state>::const_iterator it =
89 __gg__alphabet_states.find(alphabet_index);
90
91 if( it == __gg__alphabet_states.end() )
92 {
93 alphabet_state new_state;
94 new_state.low_char = low_char;
95 new_state.high_char = high_char;
96
97 for(int i=0; i<256; i++)
98 {
99 if( alphabet[i] != 0xFF )
100 {
101 new_state.collation[i] = alphabet[i] ;
102 }
103 else
104 {
105 // Use a value bigger than HIGH, but which will sort according to the
106 // original character-based order.
107 new_state.collation[i] = 256 + i;
108 }
109 }
110 __gg__alphabet_states[alphabet_index] = new_state;
111 }
112
113 return;
114 }
115
116
117 static int
118 expand_picture(char *dest, const char *picture)
119 {
120 // 'dest' must be of adequate length to hold the expanded picture string,
121 // including any extra characters due to a CURRENCY SIGN expansion.
122
123 int ch;
124 int prior_ch = NULLCH;
125 char *d = dest;
126 const char *p = picture;
127
128 long repeat;
129
130 int currency_symbol = NULLCH;
131
132 while( (ch = (*p++ & 0xFF) ) )
133 {
134 if( ch == ascii_oparen )
135 {
136 // Pick up the number after the left parenthesis
137 char *endchar;
138 repeat = strtol(p, &endchar, 10);
139
140 // We subtract one because we know that the character just before
141 // the parenthesis was already placed in dest
142 repeat -= 1;
143
144 // Update p to the character after the right parenthesis
145 p = endchar + 1;
146 while(repeat--)
147 {
148 *d++ = prior_ch;
149 }
150 }
151 else
152 {
153 prior_ch = ch;
154 *d++ = ch;
155 }
156
157 if( __gg__currency_signs[ch] )
158 {
159 // We are going to be mapping ch to a string in the final result:
160 prior_ch = ch;
161 currency_symbol = ch;
162 }
163 }
164
165 size_t dest_length = d-dest;
166
167 // We have to take into account the possibility that the currency symbol
168 // mapping might be to a string of more than one character:
169
170 if( currency_symbol )
171 {
172 size_t sign_length = strlen(__gg__currency_signs[currency_symbol]) - 1;
173 if( sign_length )
174 {
175 char *pcurrency = strchr(dest, currency_symbol);
176 assert(pcurrency);
177 memmove( pcurrency + sign_length,
178 pcurrency,
179 dest_length - (pcurrency-dest));
180 for(size_t i=0; i<sign_length; i++)
181 {
182 pcurrency[i] = ascii_B;
183 }
184 dest_length += sign_length;
185 }
186 }
187
188 return (int)(dest_length);
189 }
190
191 static int
192 Lindex(const char *dest, int length, char ch)
193 {
194 int retval = -1;
195 for(int i=0; i<length; i++)
196 {
197 if( dest[i] == ch )
198 {
199 // Finds the leftmost
200 retval = i;
201 break;
202 }
203 }
204 return retval;
205 }
206
207 static int
208 Rindex(const char *dest, int length, char ch)
209 {
210 int retval = -1;
211 for(int i=0; i<length; i++)
212 {
213 if( dest[i] == ch )
214 {
215 // Finds the rightmost
216 retval = i;
217 }
218 }
219 return retval;
220 }
221
222 extern "C"
223 bool
224 __gg__string_to_numeric_edited( char * const dest,
225 const char *source, // In source characters
226 int rdigits,
227 int is_negative,
228 const char *picture)
229 {
230 // We need to expand the picture string. We assume that the caller left
231 // enough room in dest to take the expanded picture string.
232
233 int dlength = expand_picture(dest, picture);
234
235 // At the present time, I am taking a liberty. In principle, a 'V'
236 // character is supposed to be logical decimal place rather than a physical
237 // one. In practice, I am not sure what that would mean in a numeric edited
238 // value. So, I am treating V as a decimal point.
239
240 for(int i=0; i<dlength; i++)
241 {
242 if( dest[i] == ascii_v || dest[i] == ascii_V )
243 {
244 dest[i] = __gg__decimal_point;
245 }
246 }
247
248 // This is the length of the source string, which is all digits, and has
249 // an implied decimal point at the rdigits place. We assume that any
250 // source_period or ascii_V in the picture is in the right place
251 const int slength = (int)strlen(source);
252
253 // As a setting up exercise, let's deal with the possibility of a CR/DB:
254 if( dlength >= 2 )
255 {
256 // It's a positive number, so we might have to get rid of a CR or DB:
257 char ch1 = toupper((unsigned char)dest[dlength-2]);
258 char ch2 = toupper((unsigned char)dest[dlength-1]);
259 if( (ch1 == ascii_D && ch2 == ascii_B)
260 || (ch1 == ascii_C && ch2 == ascii_R) )
261 {
262 if( !is_negative )
263 {
264 // Per the spec, because the number is positive, those two
265 // characters become blank:
266 dest[dlength-2] = ascii_space;
267 dest[dlength-1] = ascii_space;
268 }
269 // Trim the dlength by two to reflect those two positions at the
270 // right edge, and from here on out we can ignore them.
271 dlength -= 2;
272 }
273 }
274
275 // We need to know if we have a currency picture symbol in this string:
276 // This is the currency character in the PICTURE
277 unsigned char currency_picture = NULLCH;
278 const char *currency_sign = NULL; // This is the text we output when
279 // // encountering the currency_picture
280 // // character
281 // Note that the currency_picture can be upper- or lower-case, which is why
282 // we can't treat dest[] to toupper. That makes me sad, because I have
283 // to do some tests for upper- and lower-case Z, and so on.
284 for(int i=0; i<dlength; i++)
285 {
286 int ch = (unsigned int)dest[i] & 0xFF;
287 if( __gg__currency_signs[ch] )
288 {
289 currency_picture = ch;
290 currency_sign = __gg__currency_signs[ch];
291 break;
292 }
293 }
294
295 // Calculate the position of the decimal point:
296 int decimal_point_index = slength - rdigits;
297
298 // Find the source position of the leftmost non-zero digit in source
299 int nonzero_index;
300 for(nonzero_index=0; nonzero_index<slength; nonzero_index++)
301 {
302 if( source[nonzero_index] != ascii_zero )
303 {
304 break;
305 }
306 }
307
308 bool is_zero = (nonzero_index == slength);
309
310 // Push nonzero_index to the left to account for explicit ascii_nine
311 // characters:
312 int non_native_zeros = slength - nonzero_index;
313
314 // Count up the number of nines
315 int nines = 0;
316 for(int i=0; i<dlength; i++)
317 {
318 if( dest[i] == ascii_nine )
319 {
320 nines += 1;
321 }
322 }
323 if( nines > non_native_zeros )
324 {
325 non_native_zeros = nines;
326 nonzero_index = slength - non_native_zeros;
327 if( nonzero_index < 0 )
328 {
329 nonzero_index = 0;
330 }
331 }
332 // nonzero_index is now the location of the leftmost digit that we will
333 // output as a digit. Everything to its left is a leading zero, and might
334 // get replaced with a floating replacement.
335
336 // We are now in a position to address specific situations:
337
338 // This is the case of leading zero suppression
339 if( (strchr(picture, ascii_Z)) || (strchr(picture, ascii_z)) )
340 {
341 int leftmost_indexA = Lindex(dest, dlength, ascii_Z);
342 int leftmost_indexB = Lindex(dest, dlength, ascii_z);
343 if( leftmost_indexA == -1 )
344 {
345 leftmost_indexA = leftmost_indexB;
346 }
347 if( leftmost_indexB == -1 )
348 {
349 leftmost_indexB = leftmost_indexA;
350 }
351
352 int rightmost_indexA = Lindex(dest, dlength, ascii_Z);
353 int rightmost_indexB = Lindex(dest, dlength, ascii_z);
354 if( rightmost_indexA == -1 )
355 {
356 rightmost_indexA = leftmost_indexB;
357 }
358 if( rightmost_indexB == -1 )
359 {
360 rightmost_indexB = leftmost_indexA;
361 }
362
363 int leftmost_index = std::min(leftmost_indexA, leftmost_indexB);
364 int rightmost_index = std::max(rightmost_indexA, rightmost_indexB);
365
366 // We are doing replacement editing: leading zeroes get replaced with
367 // spaces.
368 if( is_zero && nines == 0 )
369 {
370 // Corner case: The value is zero, and all numeric positions
371 // are suppressed. The result is all spaces:
372 memset(dest, ascii_space, dlength);
373 }
374 else
375 {
376 int index_s = slength-1; // Index into source string of digits
377 int index_d = dlength-1; // Index into the destination
378 bool reworked_string = false;
379
380 while(index_d >=0)
381 {
382 // Pick up the destination character that we will replace:
383 char ch_d = dest[index_d];
384
385 if( ch_d == currency_picture )
386 {
387 // We are going to lay down the currency string. Keep
388 // in mind that our caller nicely left room for it
389 size_t sign_len = strlen(currency_sign);
390 while(sign_len > 0)
391 {
392 dest[index_d--] = currency_sign[--sign_len];
393 }
394 continue;
395 }
396
397 char ch_s;
398 if( index_s < 0 )
399 {
400 // I don't think this can happen, but just in case:
401 ch_s = ascii_zero;
402 }
403 else
404 {
405 ch_s = source[index_s];
406 }
407
408 if( index_s <= nonzero_index && !reworked_string)
409 {
410 reworked_string = true;
411 // index_s is the location of the leftmost non-zero
412 // digit.
413
414 // So, we are about to enter the world of leading
415 // zeroes.
416
417 // The specification says, at this point, that
418 // all B 0 / , and . inside the floating string
419 // are to be considered part of the floating string:
420
421 // So, we edit dest[] to make that true:
422 int rlim = rightmost_index > index_d ? index_d : rightmost_index;
423
424 for(int i=leftmost_index; i<rlim; i++)
425 {
426 if( dest[i] == ascii_b
427 || dest[i] == ascii_B
428 || dest[i] == ascii_slash
429 || dest[i] == ascii_zero
430 || dest[i] == __gg__decimal_separator )
431 {
432 dest[i] = ascii_space;
433 }
434 }
435 // Any B 0 / , immediately to the right are
436 // also part of the floating_character string
437
438 for(int i=rlim+1; i<index_d; i++)
439 {
440 if( !( dest[i] == ascii_b
441 || dest[i] == ascii_B
442 || dest[i] == ascii_slash
443 || dest[i] == ascii_zero
444 || dest[i] == __gg__decimal_separator))
445 {
446 break;
447 }
448 dest[i] = ascii_space;
449 }
450 }
451
452
453 if( index_s >= decimal_point_index )
454 {
455 // We are to the right of the decimal point, and so we
456 // don't do any replacement. We either insert a character,
457 // or we replace with a digit:
458 switch(ch_d)
459 {
460 // We are to the right of the decimal point, so Z is
461 // a character position
462 case ascii_z:
463 case ascii_Z:
464 case ascii_nine:
465 index_s -= 1;
466 break;
467 case ascii_b:
468 case ascii_B:
469 ch_s = ascii_space;
470 break;
471 case ascii_plus:
472 if( !is_negative )
473 {
474 ch_s = ascii_plus;
475 }
476 else
477 {
478 ch_s = ascii_minus;
479 }
480 break;
481 case ascii_minus:
482 if( !is_negative )
483 {
484 ch_s = ascii_space;
485 }
486 else
487 {
488 ch_s = ascii_minus;
489 }
490 break;
491 case ascii_P:
492 case ascii_p:
493 // P-scaling has been handled by changing the value
494 // and the number of rdigits, so these characters
495 // are ignored here:
496 break;
497 default:
498 // Valid possibilities are 0 / ,
499 // Just leave them be
500 ch_s = ch_d;
501 break;
502 }
503 dest[index_d] = ch_s;
504 }
505 else
506 {
507 // We are to the left of the decimal point:
508 if( ch_d == __gg__decimal_point )
509 {
510 // Do this assignment to handle the situation where
511 // period and comma have been swapped. It's necessary
512 // because the case statement can't take a variable
513 ch_s = __gg__decimal_point;
514 }
515 else
516 {
517 switch(ch_d)
518 {
519 case ascii_nine:
520 index_s -= 1;
521 break;
522 case ascii_v:
523 case ascii_V:
524 ch_s = __gg__decimal_point;
525 break;
526 case ascii_plus:
527 if( !is_negative )
528 {
529 ch_s = ascii_plus;
530 }
531 else
532 {
533 ch_s = ascii_minus;
534 }
535 break;
536 case ascii_minus:
537 if( !is_negative )
538 {
539 ch_s = ascii_space;
540 }
541 else
542 {
543 ch_s = ascii_minus;
544 }
545 break;
546
547 case ascii_z:
548 case ascii_Z:
549 if( index_s < nonzero_index)
550 {
551 // We are in the leading zeroes, so they are
552 // replaced with a space
553 ch_s = ascii_space;
554 }
555 index_s -= 1;
556 break;
557
558 case ascii_b:
559 case ascii_B:
560 ch_s = ascii_space;
561 break;
562
563 default:
564 // Valid possibilities are 0 / , which
565 // at this point all get replaced with spaces:
566 if( index_s < nonzero_index)
567 {
568 // We are in the leading zeroes, so they are
569 // replaced with a space
570 ch_s = ascii_space;
571 }
572 else
573 {
574 // We still have digits to send out, so the output
575 // is a copy of the PICTURE string
576 ch_s = ch_d;
577 }
578 }
579 }
580 dest[index_d] = ch_s;
581 }
582
583 index_d -= 1;
584 }
585 }
586 }
587
588 // This is the case of leading zero replacement:
589 else if( strchr(picture, ascii_asterisk) )
590 {
591 int leftmost_index = Lindex(dest, dlength, ascii_asterisk);
592 int rightmost_index = Rindex(dest, dlength, ascii_asterisk);
593 // We are doing replacement editing: leading zeroes get replaced with
594 // asterisks, except that any decimal point is put into place:
595 if( is_zero && nines == 0 )
596 {
597 // We need to re-initialize dest, because of the possibility
598 // of a CR/DB at the end of the line
599 dlength = expand_picture(dest, picture);
600
601 for(int i=0; i<dlength; i++)
602 {
603 if( dest[i] == ascii_v
604 || dest[i] == ascii_V
605 || dest[i] == __gg__decimal_point )
606 {
607 dest[i] = __gg__decimal_point;
608 }
609 else
610 {
611 dest[i] = ascii_asterisk;
612 }
613 }
614 }
615 else
616 {
617 int index_s = slength-1; // Index into source string of digits
618 int index_d = dlength-1; // Index into the destination
619 bool reworked_string = false;
620
621 while(index_d >=0)
622 {
623 // Pick up the destination character that we will replace:
624 char ch_d = dest[index_d];
625
626 if( ch_d == currency_picture )
627 {
628 // We are going to lay down the currency string. Keep
629 // in mind that our caller nicely left room for it
630 size_t sign_len = strlen(currency_sign);
631 while(sign_len > 0)
632 {
633 dest[index_d--] = currency_sign[--sign_len];
634 }
635 continue;
636 }
637
638 char ch_s;
639 if( index_s < 0 )
640 {
641 // I don't think this can happen, but just in case:
642 ch_s = ascii_zero;
643 }
644 else
645 {
646 ch_s = source[index_s];
647 }
648
649 if( index_s <= nonzero_index && !reworked_string)
650 {
651 reworked_string = true;
652 // index_s is the location of the leftmost non-zero
653 // digit.
654
655 // So, we are about to enter the world of leading
656 // zeroes.
657
658 // The specification says, at this point, that
659 // all B 0 / , and . inside the floating string
660 // are to be considered part of the floating string:
661
662 // So, we edit dest[] to make that true:
663 int rlim = rightmost_index > index_d ? index_d : rightmost_index;
664
665 for(int i=leftmost_index; i<rlim; i++)
666 {
667 if( dest[i] == ascii_b
668 || dest[i] == ascii_B
669 || dest[i] == ascii_slash
670 || dest[i] == ascii_zero
671 || dest[i] == __gg__decimal_separator )
672 {
673 dest[i] = ascii_asterisk;
674 }
675 }
676 // Any B 0 / , immediately to the right are
677 // also part of the floating_character string
678
679 for(int i=rlim+1; i<index_d; i++)
680 {
681 if( !( dest[i] == ascii_b
682 || dest[i] == ascii_B
683 || dest[i] == ascii_slash
684 || dest[i] == ascii_zero
685 || dest[i] == __gg__decimal_separator))
686 {
687 break;
688 }
689 dest[i] = ascii_asterisk;
690 }
691 }
692
693 if( index_s >= decimal_point_index )
694 {
695 // We are to the right of the decimal point, and so we
696 // don't do any replacement. We either insert a character,
697 // or we replace with a digit:
698 switch(ch_d)
699 {
700 // We are to the right of the decimal point, so asterisk
701 // is a a character position
702 case ascii_asterisk:
703 case ascii_nine:
704 index_s -= 1;
705 break;
706 case ascii_b:
707 case ascii_B:
708 ch_s = ascii_space;
709 break;
710 case ascii_plus:
711 if( !is_negative )
712 {
713 ch_s = ascii_plus;
714 }
715 else
716 {
717 ch_s = ascii_minus;
718 }
719 break;
720 case ascii_minus:
721 if( !is_negative )
722 {
723 ch_s = ascii_space;
724 }
725 else
726 {
727 ch_s = ascii_minus;
728 }
729 break;
730 default:
731 // Valid possibilities are 0 / ,
732 // Just leave them be
733 ch_s = ch_d;
734 break;
735 }
736 dest[index_d] = ch_s;
737 }
738 else
739 {
740 // We are to the left of the decimal point:
741 if( ch_d == __gg__decimal_point )
742 {
743 ch_s = __gg__decimal_point;
744 }
745 else
746 {
747 switch(ch_d)
748 {
749 case ascii_nine:
750 index_s -= 1;
751 break;
752 case ascii_v:
753 case ascii_V:
754 ch_s = __gg__decimal_point;
755 break;
756 case ascii_plus:
757 if( !is_negative )
758 {
759 ch_s = ascii_plus;
760 }
761 else
762 {
763 ch_s = ascii_minus;
764 }
765 break;
766 case ascii_minus:
767 if( !is_negative )
768 {
769 ch_s = ascii_space;
770 }
771 else
772 {
773 ch_s = ascii_minus;
774 }
775 break;
776
777 case ascii_asterisk:
778 if( index_s < nonzero_index)
779 {
780 // We are in the leading zeroes, so they are
781 // replaced with an asterisk
782 ch_s = ascii_asterisk;
783 }
784 index_s -= 1;
785 break;
786
787 case ascii_b:
788 case ascii_B:
789 ch_s = ascii_space;
790 break;
791
792 default:
793 // Valid possibilities are 0 / , which
794 // at this point all get replaced with spaces:
795 if( index_s < nonzero_index)
796 {
797 // We are in the leading zeroes, so they are
798 // replaced with our suppression character
799 ch_s = ascii_asterisk;
800 }
801 else
802 {
803 // We still have digits to send out, so the output
804 // is a copy of the PICTURE string
805 ch_s = ch_d;
806 }
807 }
808 }
809 dest[index_d] = ch_s;
810 }
811
812 index_d -= 1;
813 }
814 }
815 }
816 else
817 {
818 // At this point, we check for a floating $$, ++, or --
819 unsigned char floating_character = 0;
820
821 int leftmost_index;
822 int rightmost_index;
823
824 leftmost_index = Lindex(dest, dlength, ascii_plus);
825 rightmost_index = Rindex(dest, dlength, ascii_plus);
826 if( rightmost_index > leftmost_index)
827 {
828 floating_character = ascii_plus;
829 goto got_float;
830 }
831
832 leftmost_index = Lindex(dest, dlength, ascii_minus);
833 rightmost_index = Rindex(dest, dlength, ascii_minus);
834 if( rightmost_index > leftmost_index)
835 {
836 floating_character = ascii_minus;
837 goto got_float;
838 }
839
840 leftmost_index = Lindex(dest, dlength, currency_picture);
841 rightmost_index = Rindex(dest, dlength, currency_picture);
842 if( rightmost_index > leftmost_index)
843 {
844 floating_character = currency_picture;
845 goto got_float;
846 }
847 got_float:
848
849 if( floating_character )
850 {
851 if( is_zero && nines == 0 )
852 {
853 // Special case:
854 memset(dest, ascii_space, dlength);
855 }
856 else
857 {
858 const char *decimal_location = strchr(dest, __gg__decimal_point);
859 if( !decimal_location )
860 {
861 decimal_location = strchr(dest, ascii_v);
862 }
863 if( !decimal_location )
864 {
865 decimal_location = strchr(dest, ascii_V);
866 }
867 if( !decimal_location )
868 {
869 decimal_location = dest + dlength;
870 }
871 int decimal_index = (int)(decimal_location - dest);
872
873 if( rightmost_index > decimal_index )
874 {
875 rightmost_index = decimal_index -1;
876 }
877
878 int index_s = slength-1; // Index into source string of digits
879 int index_d = dlength-1; // Index into the destination
880 bool in_float_string = false;
881 bool reworked_string = false;
882
883 while(index_d >=0)
884 {
885 // Pick up the destination character that we will replace:
886 unsigned char ch_d = dest[index_d];
887 char ch_s = ascii_caret; // Flag this as being replaced
888
889 if( index_d == leftmost_index )
890 {
891 // At this point ch_d is the leftmost floating_character,
892 // which means it *must* go into the output stream,
893 // and that means we are truncating any remaining input.
894
895 // Setting nonzero_index to be one character to the right
896 // means that the following logic will think that any
897 // source characters from here on out are zeroes
898 nonzero_index = index_s+1;
899 }
900
901 if( ch_d != floating_character && ch_d == currency_picture )
902 {
903 // This is a non-floating currency_picture characger
904 // We are going to lay down the currency string. Keep
905 // in mind that our caller nicely left room for it
906 size_t sign_len = strlen(currency_sign);
907 while(sign_len > 0)
908 {
909 dest[index_d--] = currency_sign[--sign_len];
910 }
911 continue;
912 }
913 if( ch_d != floating_character && ch_d == ascii_plus )
914 {
915 // This is a non-floating plus sign
916 if( !is_negative )
917 {
918 ch_s = ascii_plus;
919 }
920 else
921 {
922 ch_s = ascii_minus;
923 }
924 dest[index_d--] = ch_s;
925 continue;
926 }
927 if( ch_d != floating_character && ch_d == ascii_minus )
928 {
929 // This is a non-floating minus sign
930 if( !is_negative )
931 {
932 ch_s = ascii_space;
933 }
934 else
935 {
936 ch_s = ascii_minus;
937 }
938 dest[index_d--] = ch_s;
939 continue;
940 }
941
942 if( index_s < 0 )
943 {
944 // I don't think this can happen, but just in case:
945 ch_s = ascii_zero;
946 }
947 else
948 {
949 ch_s = source[index_s];
950 if( index_s <= nonzero_index && !reworked_string)
951 {
952 reworked_string = true;
953 // index_s is the location of the leftmost non-zero
954 // digit.
955
956 // So, we are about to enter the world of leading
957 // zeroes.
958
959 // The specification says, at this point, that
960 // all B 0 / , and . inside the floating string
961 // are to be considered part of the floating string:
962
963 // So, we edit dest[] to make that true:
964 int rlim = rightmost_index > index_d ? index_d : rightmost_index;
965
966 for(int i=leftmost_index; i<rlim; i++)
967 {
968 if( dest[i] == ascii_b
969 || dest[i] == ascii_B
970 || dest[i] == ascii_slash
971 || dest[i] == ascii_zero
972 || dest[i] == __gg__decimal_separator
973 || dest[i] == __gg__decimal_point )
974 {
975 dest[i] = floating_character;
976 }
977 }
978 // Any B 0 / , immediately to the right are
979 // also part of the floating_character string
980
981 for(int i=rlim+1; i<index_d; i++)
982 {
983 if( !( dest[i] == ascii_b
984 || dest[i] == ascii_B
985 || dest[i] == ascii_slash
986 || dest[i] == ascii_zero
987 || dest[i] == __gg__decimal_separator))
988 {
989 break;
990 }
991 dest[i] = floating_character;
992 }
993 }
994 }
995 if( index_s >= decimal_point_index )
996 {
997 // We are to the right of the decimal point, and so we
998 // don't do any replacement. We either insert a character,
999 // or we replace with a digit:
1000 switch(ch_d)
1001 {
1002 case ascii_nine:
1003 index_s -= 1;
1004 break;
1005 case ascii_b:
1006 case ascii_B:
1007 ch_s = ascii_space;
1008 break;
1009 default:
1010 if( ch_d == floating_character )
1011 {
1012 // We are laying down a digit
1013 index_s -= 1;
1014 }
1015 else
1016 {
1017 // Valid possibilities are 0 / ,
1018 // Just leave them be
1019 ch_s = ch_d;
1020 }
1021 break;
1022 }
1023 dest[index_d] = ch_s;
1024 }
1025 else
1026 {
1027 // We are to the left of the decimal point:
1028
1029 if( ch_d == __gg__decimal_point )
1030 {
1031 ch_s = __gg__decimal_point;
1032 }
1033 else if (ch_d == floating_character)
1034 {
1035 if( index_s < nonzero_index )
1036 {
1037 // We are in the leading zeroes.
1038 if( !in_float_string )
1039 {
1040 in_float_string = true;
1041 // We have arrived at the rightmost floating
1042 // character in the leading zeroes
1043
1044 if( floating_character == currency_picture )
1045 {
1046 size_t sign_len = strlen(currency_sign);
1047 while(sign_len > 0)
1048 {
1049 dest[index_d--] = currency_sign[--sign_len];
1050 }
1051 continue;
1052 }
1053 if( floating_character == ascii_plus )
1054 {
1055 if( !is_negative )
1056 {
1057 ch_s = ascii_plus;
1058 }
1059 else
1060 {
1061 ch_s = ascii_minus;
1062 }
1063 dest[index_d--] = ch_s;
1064 continue;
1065 }
1066 if( floating_character == ascii_minus )
1067 {
1068 if( !is_negative )
1069 {
1070 ch_s = ascii_space;
1071 }
1072 else
1073 {
1074 ch_s = ascii_minus;
1075 }
1076 dest[index_d--] = ch_s;
1077 continue;
1078 }
1079 }
1080 else
1081 {
1082 // We are in the leading zeros and the
1083 // floating character location is to our
1084 // right. So, we put down a space:
1085 dest[index_d--] = ascii_space;
1086 continue;
1087 }
1088 }
1089 else
1090 {
1091 // We hit a floating character, but we aren't
1092 // yet in the leading zeroes
1093 index_s -= 1;
1094 dest[index_d--] = ch_s;
1095 continue;
1096 }
1097 }
1098
1099 if( ch_d == __gg__decimal_point)
1100 {
1101 ch_s = __gg__decimal_point;
1102 }
1103 else
1104 {
1105 switch(ch_d)
1106 {
1107 case ascii_nine:
1108 index_s -= 1;
1109 break;
1110 case ascii_v:
1111 case ascii_V:
1112 ch_s = __gg__decimal_point;
1113 break;
1114 case ascii_b:
1115 case ascii_B:
1116 ch_s = ascii_space;
1117 break;
1118
1119 default:
1120 // Valid possibilities are 0 / , which
1121 // at this point all get replaced with spaces:
1122 if( index_s < nonzero_index)
1123 {
1124 // We are in the leading zeroes, so they are
1125 // replaced with our suppression character
1126 ch_s = ascii_space;
1127 }
1128 else
1129 {
1130 // We still have digits to send out, so the output
1131 // is a copy of the PICTURE string
1132 ch_s = ch_d;
1133 }
1134 }
1135 }
1136 dest[index_d] = ch_s;
1137 }
1138
1139 index_d -= 1;
1140 }
1141 }
1142 }
1143 else
1144 {
1145 // Simple replacement editing
1146 int index_s = slength-1; // Index into source string of digits
1147 int index_d = dlength-1; // Index into the destination
1148
1149 while(index_d >=0)
1150 {
1151 // Pick up the destination character that we will replace:
1152 char ch_d = dest[index_d];
1153
1154 if( ch_d == currency_picture )
1155 {
1156 // We are going to lay down the currency string. Keep
1157 // in mind that our caller nicely left room for it
1158 size_t sign_len = strlen(currency_sign);
1159 while(sign_len > 0)
1160 {
1161 dest[index_d--] = currency_sign[--sign_len];
1162 }
1163 continue;
1164 }
1165
1166 char ch_s;
1167 if( index_s < 0 )
1168 {
1169 // I don't think this can happen, but just in case:
1170 ch_s = ascii_zero;
1171 }
1172 else
1173 {
1174 ch_s = source[index_s];
1175 }
1176 switch(ch_d)
1177 {
1178 // We are to the right of the decimal point, so Z is
1179 // a character position
1180 case ascii_nine:
1181 index_s -= 1;
1182 break;
1183 case ascii_b:
1184 case ascii_B:
1185 ch_s = ascii_space;
1186 break;
1187 case ascii_plus:
1188 if( !is_negative )
1189 {
1190 ch_s = ascii_plus;
1191 }
1192 else
1193 {
1194 ch_s = ascii_minus;
1195 }
1196 break;
1197 case ascii_minus:
1198 if( !is_negative )
1199 {
1200 ch_s = ascii_space;
1201 }
1202 else
1203 {
1204 ch_s = ascii_minus;
1205 }
1206 break;
1207 default:
1208 // Valid possibilities are 0 / ,
1209 // Just leave whatever is here alone
1210 ch_s = ch_d;
1211 break;
1212 }
1213 dest[index_d--] = ch_s;
1214 }
1215 }
1216 }
1217 bool retval = false;
1218
1219 return retval;
1220 }
1221
1222 extern "C"
1223 void
1224 __gg__string_to_alpha_edited( char *dest,
1225 const char *source,
1226 int slength,
1227 const char *picture)
1228 {
1229 // Put the PICTURE into the data area. If the caller didn't leave enough
1230 // room, well, poo on them. Said another way; if they specify disaster,
1231 // disaster is what they will get.
1232
1233 // This routine expands picture into dest using ascii characters, but
1234 // replaces them with internal characters
1235
1236 int destlength = expand_picture(dest, picture);
1237
1238 int dindex = 0;
1239 int sindex = 0;
1240
1241 while( dindex < destlength )
1242 {
1243 char dch = dest[dindex];
1244 char sch;
1245 switch(dch)
1246 {
1247 case ascii_b: // Replaced with space
1248 case ascii_B:
1249 dest[dindex] = internal_space;
1250 break;
1251
1252 case ascii_zero: // These are left alone:
1253 dest[dindex] = ascii_to_internal(ascii_zero);
1254 break;
1255
1256 case ascii_slash:
1257 dest[dindex] = ascii_to_internal(ascii_slash);
1258 break;
1259
1260 default:
1261 // We assume that the parser isn't giving us a bad PICTURE
1262 // string, which means this character should be X, A, or 9
1263 // We don't check; we just replace it:
1264 if(sindex < slength)
1265 {
1266 sch = source[sindex++];
1267 }
1268 else
1269 {
1270 sch = internal_space;
1271 }
1272 dest[dindex] = sch;
1273 }
1274 dindex += 1;
1275 }
1276 }
1277
1278 extern "C"
1279 void
1280 __gg__currency_sign_init()
1281 {
1282 for(int symbol=0; symbol<256; symbol++)
1283 {
1284 if( __gg__currency_signs[symbol] )
1285 {
1286 free(__gg__currency_signs[symbol]);
1287 __gg__currency_signs[symbol] = NULL;
1288 }
1289 }
1290 }
1291
1292 extern "C"
1293 void
1294 __gg__currency_sign(int symbol, const char *sign)
1295 {
1296 __gg__currency_signs[symbol] = strdup(sign);
1297 __gg__default_currency_sign = *sign;
1298 }
1299
1300 extern "C"
1301 void
1302 __gg__remove_trailing_zeroes(char *p)
1303 {
1304 // *p is a floating point number created by strfromN. There will be no
1305 // leading spaces nor unnecessary leading zeroes, but there could be trailing
1306 // zeroes, e.g. 123.456000 or 1.23456000E2
1307 // Remove the trailing zeroes:
1308 if( *p == '-' )
1309 {
1310 p += 1;
1311 }
1312 char *left = p;
1313 char *right;
1314 char *pE = strchr(p, 'E');
1315 if( pE )
1316 {
1317 right = pE - 1;
1318 }
1319 else
1320 {
1321 right = p + strlen(p)-1;
1322 }
1323
1324 if( strchr(left, '.') )
1325 {
1326 while(*right == '0' || *right == internal_space)
1327 {
1328 right -= 1;
1329 }
1330 if( *right == '.' )
1331 {
1332 right -= 1;
1333 }
1334 }
1335
1336 right += 1;
1337 memmove(p, left, right-left);
1338 if( pE )
1339 {
1340 memmove(p + (right-left), pE, strlen(pE)+1);
1341 }
1342 else
1343 {
1344 p[right-left] = '\0';
1345 }
1346 }
1347
1348 // This is a convenient place to put this table, since it is used in both the
1349 // run-time and compile-time code, and this source code module is one of the
1350 // ones that are copied from ./libgcobol to gcc/cobol as part of the build.
1351
1352 ec_descr_t __gg__exception_table[] = {
1353 { ec_all_e, ec_category_none_e,
1354 "EC-ALL", "Any exception" },
1355
1356 { ec_argument_e, ec_category_none_e,
1357 "EC-ARGUMENT", "Argument error" },
1358 { ec_argument_function_e, ec_category_fatal_e,
1359 "EC-ARGUMENT-FUNCTION", "Function argument error" },
1360 { ec_argument_imp_e, uc_category_implementor_e,
1361 "EC-ARGUMENT-IMP", "Implementor-defined argument error" },
1362
1363 { ec_argument_imp_command_e, uc_category_implementor_e,
1364 "EC-ARGUMENT-IMP-COMMAND", "COMMAND-LINE Subscript out of bounds" },
1365 { ec_argument_imp_environment_e, uc_category_implementor_e,
1366 "EC-ARGUMENT-IMP-ENVIRONMENT", "Envrionment Variable is not defined" },
1367
1368 { ec_bound_e, ec_category_none_e,
1369 "EC-BOUND", "Boundary violation" },
1370 { ec_bound_func_ret_value_e, uc_category_nonfatal_e,
1371 "EC-BOUND-FUNC-RET-VALUE",
1372 "Intrinsic function output does not fit in returned value item" },
1373 { ec_bound_imp_e, uc_category_implementor_e,
1374 "EC-BOUND-IMP", "Implementor-defined boundary violation" },
1375 { ec_bound_odo_e, ec_category_fatal_e,
1376 "EC-BOUND-ODO", "OCCURS ... DEPENDING ON data item out of bounds" },
1377 { ec_bound_overflow_e, uc_category_nonfatal_e,
1378 "EC-BOUND-OVERFLOW",
1379 "Current capacity of dynamic-capacity table greater than expected value" },
1380 { ec_bound_ptr_e, uc_category_fatal_e,
1381 "EC-BOUND-PTR", "Data-pointer contains an address that is out of bounds" },
1382 { ec_bound_ref_mod_e, ec_category_fatal_e,
1383 "EC-BOUND-REF-MOD", "Reference modifier out of bounds" },
1384 { ec_bound_set_e, uc_category_nonfatal_e,
1385 "EC-BOUND-SET", "Invalid use of SET to set capacity of "
1386 "dynamic-capacity table above specified maximum" },
1387 { ec_bound_subscript_e, ec_category_fatal_e,
1388 "EC-BOUND-SUBSCRIPT", "Subscript out of bounds" },
1389 { ec_bound_table_limit_e, uc_category_fatal_e,
1390 "EC-BOUND-TABLE-LIMIT",
1391 "Capacity of dynamic-capacity table would exceed implementor's maximum" },
1392
1393 { ec_data_e, ec_category_none_e,
1394 "EC-DATA", "Data exception" },
1395 { ec_data_conversion_e, uc_category_nonfatal_e,
1396 "EC-DATA-CONVERSION",
1397 "Conversion failed because of incomplete character correspondence" },
1398 { ec_data_imp_e, uc_category_implementor_e,
1399 "EC-DATA-IMP", "Implementor-defined data exception" },
1400 { ec_data_incompatible_e, uc_category_fatal_e,
1401 "EC-DATA-INCOMPATIBLE", "Incompatible data exception" },
1402 { ec_data_not_finite_e, uc_category_fatal_e,
1403 "EC-DATA-NOT-FINITE",
1404 "Attempt to use a data item described with a standard floating-point usage "
1405 "when its contents are either a NaN or a representation of infinity" },
1406 { ec_data_overflow_e, uc_category_fatal_e,
1407 "EC-DATA-OVERFLOW",
1408 "Exponent overflow during MOVE to a receiving data item described with a "
1409 "standard floating-point usage" },
1410 { ec_data_ptr_null_e, uc_category_fatal_e,
1411 "EC-DATA-PTR-NULL",
1412 "Based item data-pointer is set to NULL when referenced" },
1413
1414 { ec_external_data_mismatch_e, uc_category_fatal_e,
1415 "EC-EXTERNAL-DATA-MISMATCH",
1416 "File referencing control item conflict because the linage, "
1417 "file status or relative key references are not to the same item " },
1418 { ec_external_file_mismatch_e, uc_category_fatal_e,
1419 "EC-EXTERNAL-FILE-MISMATCH",
1420 "File control SELECT statements are not compatible" },
1421 { ec_external_format_conflict_e, uc_category_fatal_e,
1422 "EC-EXTERNAL-FORMAT-CONFLICT",
1423 "Data definitions definitions do not conform" },
1424
1425 { ec_flow_e, ec_category_none_e,
1426 "EC-FLOW", "Execution control flow violation" },
1427 { ec_flow_global_exit_e, uc_category_fatal_e,
1428 "EC-FLOW-GLOBAL-EXIT", "EXIT PROGRAM in a global Declarative" },
1429 { ec_flow_global_goback_e, uc_category_fatal_e,
1430 "EC-FLOW-GLOBAL-GOBACK", "GOBACK in a global declarative" },
1431 { ec_flow_imp_e, uc_category_implementor_e,
1432 "EC-FLOW-IMP", "Implementor-defined control flow violation" },
1433 { ec_flow_release_e, uc_category_fatal_e,
1434 "EC-FLOW-RELEASE", "RELEASE not in range of SORT" },
1435 { ec_flow_report_e, uc_category_fatal_e,
1436 "EC-FLOW-REPORT",
1437 "GENERATE, INITIATE, or TERMINATE during USE BEFORE REPORTING declarative" },
1438 { ec_flow_return_e, uc_category_fatal_e,
1439 "EC-FLOW-RETURN", "RETURN not in range of MERGE or SORT" },
1440 { ec_flow_search_e, uc_category_fatal_e,
1441 "EC-FLOW-SEARCH",
1442 "Invalid use of SET to change capacity of dynamic- capacity table during "
1443 "SEARCH of same table" },
1444 { ec_flow_use_e, uc_category_fatal_e,
1445 "EC-FLOW-USE", "A USE statement caused another to be executed" },
1446
1447 { ec_function_e, ec_category_none_e,
1448 "EC-FUNCTION", "Function exception" },
1449 { ec_function_not_found_e, uc_category_fatal_e,
1450 "EC-FUNCTION-NOT-FOUND",
1451 "Function not found or function pointer does not point to a function" },
1452 { ec_function_ptr_invalid_e, uc_category_fatal_e,
1453 "EC-FUNCTION-PTR-INVALID", "Signature mismatch" },
1454 { ec_function_ptr_null_e, uc_category_fatal_e,
1455 "EC-FUNCTION-PTR-NULL",
1456 "Function pointer used in calling a function is NULL" },
1457
1458 { ec_io_e, ec_category_none_e,
1459 "EC-IO", "Input-output exception" },
1460 { ec_io_at_end_e, uc_category_nonfatal_e,
1461 "EC-I-O-AT-END", "I-O status 1x" },
1462 { ec_io_eop_e, uc_category_nonfatal_e,
1463 "EC-I-O-EOP", "An end of page condition occurred" },
1464 { ec_io_eop_overflow_e, uc_category_nonfatal_e,
1465 "EC-I-O-EOP-OVERFLOW", "A page overflow condition occurred" },
1466 { ec_io_file_sharing_e, uc_category_nonfatal_e,
1467 "EC-I-O-FILE-SHARING", "I-O status 6x" },
1468 { ec_io_imp_e, uc_category_implementor_e,
1469 "EC-I-O-IMP", "I-O status 9x" },
1470 { ec_io_invalid_key_e, uc_category_nonfatal_e,
1471 "EC-I-O-INVALID-KEY", "I-O status 2x" },
1472 { ec_io_linage_e, uc_category_fatal_e,
1473 "EC-I-O-LINAGE",
1474 "The value of a data item referenced in the LINAGE clause is not within "
1475 "the required range" },
1476 { ec_io_logic_error_e, uc_category_fatal_e,
1477 "EC-I-O-LOGIC-ERROR", "I-O status 4x" },
1478 { ec_io_permanent_error_e, uc_category_fatal_e,
1479 "EC-I-O-PERMANENT-ERROR", "I-O status 3x" },
1480 { ec_io_record_operation_e, uc_category_nonfatal_e,
1481 "EC-I-O-RECORD-OPERATION", "I-O status 5x" },
1482
1483 { ec_imp_e, ec_category_none_e,
1484 "EC-IMP", "Implementor-defined exception condition" },
1485
1486 { ec_imp_suffix_e, ec_category_none_e,
1487 "EC-IMP-SUFFIX", "Imp" },
1488
1489 { ec_locale_e, ec_category_none_e,
1490 "EC-LOCALE", "Any locale related exception" },
1491 { ec_locale_imp_e, uc_category_implementor_e,
1492 "EC-LOCALE-IMP", "Implementor-defined locale related exception" },
1493 { ec_locale_incompatible_e, uc_category_fatal_e,
1494 "EC-LOCALE-INCOMPATIBLE",
1495 "The referenced locale does not specify the expected characters in "
1496 "LC_COLLATE" },
1497 { ec_locale_invalid_e, uc_category_fatal_e,
1498 "EC-LOCALE-INVALID", "Locale content is invalid or incomplete" },
1499 { ec_locale_invalid_ptr_e, uc_category_fatal_e,
1500 "EC-LOCALE-INVALID-PTR", "Pointer does not reference a saved locale" },
1501 { ec_locale_missing_e, uc_category_fatal_e,
1502 "EC-LOCALE-MISSING", "The specified locale is not available" },
1503 { ec_locale_size_e, uc_category_fatal_e,
1504 "EC-LOCALE-SIZE", "Digits were truncated in locale editing" },
1505
1506 { ec_oo_e, ec_category_none_e,
1507 "EC-OO", "Any predefined OO related exception" },
1508 { ec_oo_arg_omitted_e, uc_category_fatal_e,
1509 "EC-OO-ARG-OMITTED", "Reference to an omitted argument" },
1510 { ec_oo_conformance_e, uc_category_fatal_e,
1511 "EC-OO-CONFORMANCE", "Failure for an object-view" },
1512 { ec_oo_exception_e, uc_category_fatal_e,
1513 "EC-OO-EXCEPTION", "An exception object was not handled" },
1514 { ec_oo_imp_e, uc_category_implementor_e,
1515 "EC-OO-IMP", "Implementor-defined OO exception" },
1516 { ec_oo_method_e, uc_category_fatal_e,
1517 "EC-OO-METHOD", "Requested method is not available" },
1518 { ec_oo_null_e, uc_category_fatal_e,
1519 "EC-OO-NULL",
1520 "Method invocation was attempted with a null object reference" },
1521 { ec_oo_resource_e, uc_category_fatal_e,
1522 "EC-OO-RESOURCE", "Insufficient system resources to create the object" },
1523 { ec_oo_universal_e, uc_category_fatal_e,
1524 "EC-OO-UNIVERSAL", "A runtime type check failed" },
1525
1526 { ec_order_e, ec_category_none_e,
1527 "EC-ORDER", "Ordering exception" },
1528 { ec_order_imp_e, uc_category_implementor_e,
1529 "EC-ORDER-IMP", "Implementor-defined ordering exception" },
1530 { ec_order_not_supported_e, uc_category_fatal_e,
1531 "EC-ORDER-NOT-SUPPORTED",
1532 "Cultural ordering table or ordering level specified for "
1533 "STANDARD-COMPARE function not supported" },
1534
1535 { ec_overflow_e, ec_category_none_e,
1536 "EC-OVERFLOW", "Overflow condition" },
1537 { ec_overflow_imp_e, uc_category_implementor_e,
1538 "EC-OVERFLOW-IMP", "Implementor-defined overflow condition" },
1539 { ec_overflow_string_e, uc_category_nonfatal_e,
1540 "EC-OVERFLOW-STRING", "STRING overflow condition" },
1541 { ec_overflow_unstring_e, uc_category_nonfatal_e,
1542 "EC-OVERFLOW-UNSTRING", "UNSTRING overflow condition" },
1543
1544 { ec_program_e, ec_category_none_e,
1545 "EC-PROGRAM", "Inter-program communication exception" },
1546 { ec_program_arg_mismatch_e, uc_category_fatal_e,
1547 "EC-PROGRAM-ARG-MISMATCH", "Parameter mismatch" },
1548 { ec_program_arg_omitted_e, uc_category_fatal_e,
1549 "EC-PROGRAM-ARG-OMITTED", "A reference to an omitted argument" },
1550 { ec_program_cancel_active_e, uc_category_fatal_e,
1551 "EC-PROGRAM-CANCEL-ACTIVE", "Canceled program active" },
1552 { ec_program_imp_e, uc_category_implementor_e,
1553 "EC-PROGRAM-IMP",
1554 "Implementor-defined inter-program communication exception" },
1555 { ec_program_not_found_e, uc_category_fatal_e,
1556 "EC-PROGRAM-NOT-FOUND", "Called program not found" },
1557 { ec_program_ptr_null_e, uc_category_fatal_e,
1558 "EC-PROGRAM-PTR-NULL", "Program-pointer used in CALL is set to NULL" },
1559 { ec_program_recursive_call_e, uc_category_fatal_e,
1560 "EC-PROGRAM-RECURSIVE-CALL", "Called program active" },
1561 { ec_program_resources_e, uc_category_fatal_e,
1562 "EC-PROGRAM-RESOURCES", "Resources not available for called program" },
1563
1564 { ec_raising_e, ec_category_none_e,
1565 "EC-RAISING", "EXIT ... RAISING or GOBACK RAISING exception" },
1566 { ec_raising_imp_e, uc_category_implementor_e,
1567 "EC-RAISING-IMP",
1568 "Implementor-defined EXIT ... RAISING or GOBACK RAISING exception" },
1569 { ec_raising_not_specified_e, uc_category_fatal_e,
1570 "EC-RAISING-NOT-SPECIFIED",
1571 "EXIT ... RAISING or GOBACK RAISING an EC-USER exception condition not "
1572 "specified in RAISING phrase of procedure division header" },
1573
1574 { ec_range_e, ec_category_none_e,
1575 "EC-RANGE", "Range exception" },
1576 { ec_range_imp_e, uc_category_implementor_e,
1577 "EC-RANGE-IMP", "Implementor-defined range exception" },
1578 { ec_range_index_e, uc_category_fatal_e,
1579 "EC-RANGE-INDEX",
1580 "Index set outside the range of values allowed by the implementor" },
1581 { ec_range_inspect_size_e, uc_category_fatal_e,
1582 "EC-RANGE-INSPECT-SIZE", "Size of replace items in INSPECT differs" },
1583 { ec_range_invalid_e, uc_category_nonfatal_e,
1584 "EC-RANGE-INVALID",
1585 "Starting value of THROUGH range greater than ending value" },
1586 { ec_range_perform_varying_e, uc_category_fatal_e,
1587 "EC-RANGE-PERFORM-VARYING",
1588 "Setting of varied item in PERFORM is negative" },
1589 { ec_range_ptr_e, uc_category_fatal_e,
1590 "EC-RANGE-PTR", "Pointer SET UP or DOWN is outside range" },
1591 { ec_range_search_index_e, uc_category_nonfatal_e,
1592 "EC-RANGE-SEARCH-INDEX",
1593 "No table element found in SEARCH because initial index out of range" },
1594 { ec_range_search_no_match_e, uc_category_nonfatal_e,
1595 "EC-RANGE-SEARCH-NO-MATCH",
1596 "No table element found in SEARCH because no element matched criteria" },
1597
1598 { ec_report_e, ec_category_none_e,
1599 "EC-REPORT", "Report writer exception" },
1600 { ec_report_active_e, uc_category_fatal_e,
1601 "EC-REPORT-ACTIVE", "INITIATE on an active report" },
1602 { ec_report_column_overlap_e, uc_category_nonfatal_e,
1603 "EC-REPORT-COLUMN-OVERLAP", "Overlapping report items" },
1604 { ec_report_file_mode_e, uc_category_fatal_e,
1605 "EC-REPORT-FILE-MODE",
1606 "An INITIATE statement was executed for a file connector that was not "
1607 "open in the extend or output mode" },
1608 { ec_report_imp_e, uc_category_implementor_e,
1609 "EC-REPORT-IMP", "Implementor-defined report writer exception" },
1610 { ec_report_inactive_e, uc_category_fatal_e,
1611 "EC-REPORT-INACTIVE", "GENERATE or TERMINATE on an inactive report" },
1612 { ec_report_line_overlap_e, uc_category_nonfatal_e,
1613 "EC-REPORT-LINE-OVERLAP", "Overlapping report lines" },
1614 { ec_report_not_terminated_e, uc_category_nonfatal_e,
1615 "EC-REPORT-NOT-TERMINATED", "Report file closed with active report" },
1616 { ec_report_page_limit_e, uc_category_nonfatal_e,
1617 "EC-REPORT-PAGE-LIMIT", "Vertical page limit exceeded" },
1618 { ec_report_page_width_e, uc_category_nonfatal_e,
1619 "EC-REPORT-PAGE-WIDTH", "Page width exceeded" },
1620 { ec_report_sum_size_e, uc_category_fatal_e,
1621 "EC-REPORT-SUM-SIZE", "Overflow of sum counter" },
1622 { ec_report_varying_e, uc_category_fatal_e,
1623 "EC-REPORT-VARYING", "VARYING clause expression noninteger" },
1624
1625 { ec_screen_e, ec_category_none_e,
1626 "EC-SCREEN", "Screen handling exception" },
1627 { ec_screen_field_overlap_e, uc_category_nonfatal_e,
1628 "EC-SCREEN-FIELD-OVERLAP", "Screen fields overlap" },
1629 { ec_screen_imp_e, uc_category_implementor_e,
1630 "EC-SCREEN-IMP", "Implementor-defined screen handling exception" },
1631 { ec_screen_item_truncated_e, uc_category_nonfatal_e,
1632 "EC-SCREEN-ITEM-TRUNCATED", "Screen field too long for line" },
1633 { ec_screen_line_number_e, uc_category_nonfatal_e,
1634 "EC-SCREEN-LINE-NUMBER",
1635 "Screen item line number exceeds terminal size" },
1636 { ec_screen_starting_column_e, uc_category_nonfatal_e,
1637 "EC-SCREEN-STARTING-COLUMN",
1638 "Screen item starting column exceeds line size" },
1639
1640 { ec_size_e, ec_category_none_e,
1641 "EC-SIZE", "Size error exception" },
1642 { ec_size_address_e, uc_category_fatal_e,
1643 "EC-SIZE-ADDRESS", "Invalid pointer arithmetic" },
1644 { ec_size_exponentiation_e, ec_category_fatal_e,
1645 "EC-SIZE-EXPONENTIATION", "Exponentiation rules violated" },
1646 { ec_size_imp_e, uc_category_implementor_e,
1647 "EC-SIZE-IMP", "Implementor-defined size error exception" },
1648 { ec_size_overflow_e, ec_category_fatal_e,
1649 "EC-SIZE-OVERFLOW", "Arithmetic overflow in calculation" },
1650 { ec_size_truncation_e, ec_category_fatal_e,
1651 "EC-SIZE-TRUNCATION", "Significant digits truncated in store" },
1652 { ec_size_underflow_e, ec_category_fatal_e,
1653 "EC-SIZE-UNDERFLOW", "Floating-point underflow" },
1654 { ec_size_zero_divide_e, ec_category_fatal_e,
1655 "EC-SIZE-ZERO-DIVIDE", "Division by zero" },
1656
1657 { ec_sort_merge_e, ec_category_none_e,
1658 "EC-SORT-MERGE", "SORT or MERGE exception" },
1659 { ec_sort_merge_active_e, uc_category_fatal_e,
1660 "EC-SORT-MERGE-ACTIVE",
1661 "File SORT or MERGE executed when one is already active" },
1662 { ec_sort_merge_file_open_e, ec_category_fatal_e,
1663 "EC-SORT-MERGE-FILE-OPEN",
1664 "A USING or GIVING file is open upon execution of a SORT or MERGE" },
1665 { ec_sort_merge_imp_e, uc_category_implementor_e,
1666 "EC-SORT-MERGE-IMP",
1667 "Implementor-defined SORT or MERGE exception" },
1668 { ec_sort_merge_release_e, uc_category_fatal_e,
1669 "EC-SORT-MERGE-RELEASE", "RELEASE record too long or too short" },
1670 { ec_sort_merge_return_e, uc_category_fatal_e,
1671 "EC-SORT-MERGE-RETURN", "RETURN executed when at end condition exists" },
1672 { ec_sort_merge_sequence_e, uc_category_fatal_e,
1673 "EC-SORT-MERGE-SEQUENCE", "Sequence error on MERGE USING file" },
1674
1675 { ec_storage_e, ec_category_none_e,
1676 "EC-STORAGE", "Storage allocation exception" },
1677 { ec_storage_imp_e, uc_category_implementor_e,
1678 "EC-STORAGE-IMP", "Implementor-defined storage allocation exception" },
1679 { ec_storage_not_alloc_e, uc_category_nonfatal_e,
1680 "EC-STORAGE-NOT-ALLOC",
1681 "The data-pointer specified in a FREE statement does not identify "
1682 "currently allocated storage" },
1683 { ec_storage_not_avail_e, uc_category_nonfatal_e,
1684 "EC-STORAGE-NOT-AVAIL",
1685 "The amount of storage requested by an ALLOCATE statement "
1686 "is not available"},
1687 { ec_user_e, ec_category_none_e,
1688 "EC-USER", "User-defined exception condition" },
1689 { ec_user_suffix_e, uc_category_nonfatal_e,
1690 "EC-USER-SUFFIX", "Level-3 user-defined exception condition" },
1691
1692 { ec_validate_e, ec_category_none_e,
1693 "EC-VALIDATE", "VALIDATE exception" },
1694 { ec_validate_content_e, uc_category_nonfatal_e,
1695 "EC-VALIDATE-CONTENT", "VALIDATE content error" },
1696 { ec_validate_format_e, uc_category_nonfatal_e,
1697 "EC-VALIDATE-FORMAT", "VALIDATE format error" },
1698 { ec_validate_imp_e, uc_category_implementor_e,
1699 "EC-VALIDATE-IMP", "Implementor-defined VALIDATE exception" },
1700 { ec_validate_relation_e, uc_category_nonfatal_e,
1701 "EC-VALIDATE-RELATION", "VALIDATE relation error" },
1702 { ec_validate_varying_e, uc_category_fatal_e,
1703 "EC-VALIDATE-VARYING", "VARYING clause expression noninteger" },
1704 } ;
1705
1706 ec_descr_t *__gg__exception_table_end = __gg__exception_table + COUNT_OF(__gg__exception_table);
1707