| 1 | package oEdtk::dataEdtk; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | 1 | ▶ | use oEdtk::Main 0.42; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use oEdtk::libDev 0.3094; | ||
| 8 | use oEdtk::logger 1.03; | ||
| 9 | |||
| 10 | use Exporter (); | ||
| 11 | use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK); | ||
| 12 | |||
| 13 | $VERSION = 2.1126; | ||
| 14 | @ISA = qw (Exporter); | ||
| 15 | @EXPORT = qw (unpackCopygroup cpyOccurs); | ||
| 16 | } | ||
| 17 | |||
| 18 | sub unpackCopygroup () { # NO LONGER USED? dependency on the old gen_appEdtk.pl | ||
| 19 | # receives a reference to a cobol Picture string (no comment line) | ||
| 20 | # reformats the cobol pictures according to their type | ||
| 21 | # PIC X : alphanumeric type variable | ||
| 22 | # PIC 9 : numeric type variable | ||
| 23 | # PIC S9 : signed numeric type variable | ||
| 24 | |||
| 25 | # V99 | ||
| 26 | # V9(m) | ||
| 27 | |||
| 28 | # PIC X -> %s | ||
| 29 | # PIC X(n) -> %s | ||
| 30 | # PIC XXXX -> %s | ||
| 31 | # PIC 9 -> %1.0f | ||
| 32 | # PIC 9(n) -> %n.0f | ||
| 33 | # PIC 9999 -> %4.0f | ||
| 34 | # PIC S9 -> %1.0f | ||
| 35 | # PIC S9(n) -> %n.0f | ||
| 36 | # PIC S9999 -> %4.0f | ||
| 37 | |||
| 38 | # OCCURS nn | ||
| 39 | # VALUE 'X' | ||
| 40 | # VALUE ZERO | ||
| 41 | |||
| 42 | my $rRecord = shift; | ||
| 43 | my $rangCol = 0; | ||
| 44 | my $nomCol = ""; | ||
| 45 | my $lenCol = 0; | ||
| 46 | my $typCol = ""; | ||
| 47 | my $signCol = 0; | ||
| 48 | my $decimCol = 0; | ||
| 49 | my $colOccur = 1; | ||
| 50 | |||
| 51 | # SIMPLIFY THE HANDLING OF FIELD NAMES: | ||
| 52 | # THE '_' CHARACTER IS PART OF THE \w CHARACTER CLASS | ||
| 53 | ${$rRecord} =~ s/\-/\_/g; | ||
| 54 | oe_trimp_space($rRecord); | ||
| 55 | |||
| 56 | if ( ${$rRecord} =~ /^\s*(\d{1,2})\s+(\w+)(.*)/ ) { | ||
| 57 | |||
| 58 | # 01 ACPDB_RECORD. | ||
| 59 | # 05 ACPDB_FD_TRANS_CN PIC XX. | ||
| 60 | $rangCol = $1; | ||
| 61 | $nomCol = $2; | ||
| 62 | ${$rRecord} = $3; | ||
| 63 | } | ||
| 64 | |||
| 65 | # OCCURS HANDLING CHECK | ||
| 66 | if ( ${$rRecord} =~ /(.*)OCCURS\s+(\d+)/ ) { | ||
| 67 | ${$rRecord} = $1; | ||
| 68 | $colOccur = $2; | ||
| 69 | die &logger( $NOK, "The data descriptor contains an unhandled OCCURS clause" ); | ||
| 70 | } | ||
| 71 | |||
| 72 | if ( ${$rRecord} =~ /(.*)V9\((\d+)\)(.*)/ ) { | ||
| 73 | |||
| 74 | # V9(m) | ||
| 75 | ${$rRecord} = "$1 $3"; | ||
| 76 | $decimCol = $2; | ||
| 77 | } | ||
| 78 | elsif ( ${$rRecord} =~ /(.*)V(9+)(.*)/ ) { | ||
| 79 | |||
| 80 | # V9999 | ||
| 81 | ${$rRecord} = "$1 $3"; | ||
| 82 | $decimCol = length($2); | ||
| 83 | } | ||
| 84 | |||
| 85 | if ( ${$rRecord} =~ /PIC\s+X(.*)/ ) { | ||
| 86 | |||
| 87 | # PIC X -> %s | ||
| 88 | ${$rRecord} = $1; | ||
| 89 | $lenCol = 1; | ||
| 90 | $typCol = "s"; | ||
| 91 | if ( ${$rRecord} =~ /\((\d+)\)(.*)/ ) { | ||
| 92 | |||
| 93 | # PIC X)(n) ... -> %s | ||
| 94 | $lenCol = $1; | ||
| 95 | ${$rRecord} = $2; | ||
| 96 | } | ||
| 97 | elsif ( ${$rRecord} =~ /(X+)(.*)/ ) { | ||
| 98 | |||
| 99 | # PIC X)XXX ... -> %s | ||
| 100 | $lenCol = length($1) + 1; | ||
| 101 | ${$rRecord} = $2; | ||
| 102 | } | ||
| 103 | |||
| 104 | } | ||
| 105 | elsif ( ${$rRecord} =~ /PIC\s+9(.*)/ ) { | ||
| 106 | |||
| 107 | # PIC 9 -> %1.mf | ||
| 108 | ${$rRecord} = $1; | ||
| 109 | $lenCol = 1 + $decimCol; | ||
| 110 | $typCol = "1.${decimCol}f"; | ||
| 111 | if ( ${$rRecord} =~ /\((\d+)\)(.*)/ ) { | ||
| 112 | |||
| 113 | # PIC 9)(n) ... -> %n.mf | ||
| 114 | $lenCol = $1 + $decimCol; | ||
| 115 | ${$rRecord} = $2; | ||
| 116 | $typCol = "$lenCol.${decimCol}f"; | ||
| 117 | } | ||
| 118 | elsif ( ${$rRecord} =~ /(9+)(.*)/ ) { | ||
| 119 | |||
| 120 | # PIC 9)999 ... -> %n.mf | ||
| 121 | $lenCol = length($1) + 1 + $decimCol; | ||
| 122 | ${$rRecord} = $2; | ||
| 123 | $typCol = "$lenCol.${decimCol}f"; | ||
| 124 | } | ||
| 125 | |||
| 126 | } | ||
| 127 | elsif ( ${$rRecord} =~ /PIC\s+S(.*)/ ) { | ||
| 128 | |||
| 129 | # PIC S9 -> %1.mf | ||
| 130 | ${$rRecord} = $1; | ||
| 131 | $lenCol = 1 + $decimCol; | ||
| 132 | $typCol = "1.${decimCol}f"; | ||
| 133 | $signCol = 1; | ||
| 134 | if ( ${$rRecord} =~ /\((\d+)\)(.*)/ ) { | ||
| 135 | |||
| 136 | # PIC S)[9](n) ... -> %n.mf | ||
| 137 | $lenCol = $1 + $decimCol; | ||
| 138 | ${$rRecord} = $2; | ||
| 139 | $typCol = "$lenCol.${decimCol}f"; | ||
| 140 | } | ||
| 141 | elsif ( ${$rRecord} =~ /(9+)(.*)/ ) { | ||
| 142 | |||
| 143 | # PIC S)9999 ... -> %n.mf | ||
| 144 | $lenCol = length($1) + $decimCol; | ||
| 145 | ${$rRecord} = $2; | ||
| 146 | $typCol = "$lenCol.${decimCol}f"; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | return $rangCol, $nomCol, $lenCol, $typCol, $decimCol, $signCol, ${$rRecord}, $colOccur; | ||
| 151 | } | ||
| 152 | |||
| 153 | { # OCCURS HANDLING | ||
| 154 | # DEFINE VARIABLES LOCAL TO OCCURS HANDLING | ||
| 155 | |||
| 156 | my $flagOccur = 0; | ||
| 157 | my $occurBuff = 1; | ||
| 158 | my $buff = ""; | ||
| 159 | my $buffComment = ""; | ||
| 160 | my $rLignesTab; | ||
| 161 | |||
| 162 | sub cpyOccurs { # NO LONGER USED? dependency on the old gen_appEdtk.pl | ||
| 163 | $rLignesTab = shift; | ||
| 164 | my $ligne = ""; | ||
| 165 | my $rangCol = 0; | ||
| 166 | my $lastRangCol = 0; | ||
| 167 | my $nbOccursImbriquees = 0; | ||
| 168 | |||
| 169 | push( @{$rLignesTab}, " * START TRT IN $rLignesTab" ); | ||
| 170 | |||
| 171 | DEFS: while ( $ligne = shift @{$rLignesTab} ) { | ||
| 172 | &logger( 7, " 150 line=$ligne" ); | ||
| 173 | if ( $ligne eq " * START TRT IN $rLignesTab" ) { | ||
| 174 | last DEFS; | ||
| 175 | } | ||
| 176 | |||
| 177 | $ligne =~ /^\s*(\d+)/; | ||
| 178 | &logger( 7, " 156 line=$ligne" ); | ||
| 179 | $rangCol = $1 if $1; | ||
| 180 | |||
| 181 | if ( $flagOccur > 0 && $rangCol <= $lastRangCol ) { | ||
| 182 | &cpyEditOccurs(); | ||
| 183 | } | ||
| 184 | |||
| 185 | if ( $flagOccur == 0 && $ligne =~ /OCCURS\s+(\d+)/i ) { | ||
| 186 | $occurBuff = $1; | ||
| 187 | $flagOccur = 1; | ||
| 188 | &logger( 7, "Nesting=$nbOccursImbriquees flagOcc=$flagOccur && OCC line" ); | ||
| 189 | &logger( 7, " 167 line=$ligne" ); | ||
| 190 | $ligne =~ s/(.*)(OCCURS\s+\d+)(.*)/$1$3/io; | ||
| 191 | push( @{$rLignesTab}, $ligne ); | ||
| 192 | $lastRangCol = $rangCol; | ||
| 193 | |||
| 194 | } | ||
| 195 | elsif ( $flagOccur > 0 && $rangCol > $lastRangCol ) { | ||
| 196 | if ( $ligne =~ /^\s*\*+/ ) { | ||
| 197 | |||
| 198 | # COMMENTED LINES COME BEFORE THE FIELD DESCRIPTORS, | ||
| 199 | # KEEP THEM IN MEMORY TO OUTPUT THEM WITH THE OCCURS | ||
| 200 | $buffComment .= $ligne; | ||
| 201 | &logger( 7, " 177 line=$ligne" ); | ||
| 202 | } | ||
| 203 | else { | ||
| 204 | if ( $ligne =~ /OCCURS/ ) { | ||
| 205 | $nbOccursImbriquees++; | ||
| 206 | &logger( 7, " * Nesting=$nbOccursImbriquees : $ligne" ); | ||
| 207 | } | ||
| 208 | $buff .= $ligne; | ||
| 209 | &logger( 7, " 184 line=$ligne" ); | ||
| 210 | } | ||
| 211 | |||
| 212 | } | ||
| 213 | else { | ||
| 214 | push( @{$rLignesTab}, $ligne ); | ||
| 215 | &logger( 7, " 189 line=$ligne" ); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | &cpyEditOccurs() if ($buff); | ||
| 220 | &logger( 7, "nbOccursImbriquees = $nbOccursImbriquees" ); | ||
| 221 | return $nbOccursImbriquees; | ||
| 222 | } | ||
| 223 | |||
| 224 | sub cpyEditOccurs() { # NO LONGER USED? internal dependency | ||
| 225 | $buff .= "\t*\n"; | ||
| 226 | push( @{$rLignesTab}, split( /\n/, $buffComment ) . "\n" ); | ||
| 227 | |||
| 228 | # for each line of $buff, insert into the array | ||
| 229 | #push (@{$rLignesTab}, split (/\n/, $buff x $occurBuff)."\n"); | ||
| 230 | foreach my $element ( split( /\n/, $buff x $occurBuff ) ) { | ||
| 231 | push( @{$rLignesTab}, "$element\n" ); | ||
| 232 | &logger( 7, " 205 element=$element" ); | ||
| 233 | } | ||
| 234 | |||
| 235 | $buffComment = ""; | ||
| 236 | $buff = ""; | ||
| 237 | $flagOccur = 0; | ||
| 238 | 1; | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | END { } | ||
| 243 | 1; | ||
| 244 | |||
| 245 | =head1 NAME | ||
| 246 | |||
| 247 | oEdtk::dataEdtk - legacy COBOL descriptor helpers | ||
| 248 | |||
| 249 | =head1 SYNOPSIS | ||
| 250 | |||
| 251 | use oEdtk::dataEdtk qw(unpackCopygroup cpyOccurs); | ||
| 252 | |||
| 253 | =head1 DESCRIPTION | ||
| 254 | |||
| 255 | Legacy helpers that reformat COBOL C<PIC> descriptors into Perl C<unpack> and | ||
| 256 | C<printf> descriptions and expand C<OCCURS> blocks. They depend on the old | ||
| 257 | C<gen_appEdtk.pl> generator and are believed to be no longer used; they are | ||
| 258 | kept for reference. | ||
| 259 | |||
| 260 | =head1 FUNCTIONS | ||
| 261 | |||
| 262 | =head2 unpackCopygroup | ||
| 263 | |||
| 264 | my @parts = unpackCopygroup(\$record); | ||
| 265 | |||
| 266 | Read a COBOL C<PIC> string (C<X>, C<9> or C<S9>, with C<V9(n)> and C<OCCURS> | ||
| 267 | clauses) and return the column rank, name, length, Perl type, decimals, sign, | ||
| 268 | remaining text and occurrence count. An unhandled C<OCCURS> clause is an error. | ||
| 269 | |||
| 270 | =head2 cpyOccurs | ||
| 271 | |||
| 272 | my $n = cpyOccurs($rLignesTab); | ||
| 273 | |||
| 274 | Expand the C<OCCURS> blocks in the array of lines referenced by C<$rLignesTab> | ||
| 275 | and return the number of nested C<OCCURS>. The internal helper C<cpyEditOccurs> | ||
| 276 | duplicates the buffered lines; it is not part of the public API. | ||
| 277 | |||
| 278 | =head1 AUTHOR | ||
| 279 | |||
| 280 | The oEdtk team. | ||
| 281 | |||
| 282 | =cut | ||