| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| #include "IBM390lib.h" |
| 6 |
|
| #define SHORTY_SIZE 2048 |
| 7 |
|
| |
| 8 |
|
| /*---- Translation tables ----*/ |
| 9 |
|
| |
| 10 |
|
| static unsigned char a2e_table[256] = { |
| 11 |
|
| 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, |
| 12 |
|
| 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, |
| 13 |
|
| 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, |
| 14 |
|
| 0x1e, 0x1f, 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, |
| 15 |
|
| 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, 0xf0, 0xf1, |
| 16 |
|
| 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, |
| 17 |
|
| 0x4c, 0x7e, 0x6e, 0x6f, 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, |
| 18 |
|
| 0xc6, 0xc7, 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, |
| 19 |
|
| 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, |
| 20 |
|
| 0xe9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d, 0x79, 0x81, 0x82, 0x83, |
| 21 |
|
| 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, |
| 22 |
|
| 0x95, 0x96, 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, |
| 23 |
|
| 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, 0x20, 0x21, |
| 24 |
|
| 0x22, 0x23, 0x24, 0x25, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, |
| 25 |
|
| 0x2c, 0x09, 0x0a, 0x1b, 0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, |
| 26 |
|
| 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xff, |
| 27 |
|
| 0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, 0xbb, 0xb4, |
| 28 |
|
| 0x9a, 0x8a, 0xb0, 0xca, 0xaf, 0xbc, 0x90, 0x8f, 0xea, 0xfa, |
| 29 |
|
| 0xbe, 0xa0, 0xb6, 0xb3, 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, |
| 30 |
|
| 0xb9, 0xab, 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, |
| 31 |
|
| 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, 0xac, 0x69, |
| 32 |
|
| 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, 0x80, 0xfd, 0xfe, 0xfb, |
| 33 |
|
| 0xfc, 0xba, 0xae, 0x59, 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, |
| 34 |
|
| 0x9c, 0x48, 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, |
| 35 |
|
| 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, 0x70, 0xdd, |
| 36 |
|
| 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf }; |
| 37 |
|
| |
| 38 |
|
| static unsigned char e2a_table[256] = { |
| 39 |
|
| 0x00, 0x01, 0x02, 0x03, 0x9c, 0x09, 0x86, 0x7f, 0x97, 0x8d, |
| 40 |
|
| 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, |
| 41 |
|
| 0x9d, 0x0a, 0x08, 0x87, 0x18, 0x19, 0x92, 0x8f, 0x1c, 0x1d, |
| 42 |
|
| 0x1e, 0x1f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x17, 0x1b, |
| 43 |
|
| 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, 0x90, 0x91, |
| 44 |
|
| 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, 0x98, 0x99, 0x9a, 0x9b, |
| 45 |
|
| 0x14, 0x15, 0x9e, 0x1a, 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, |
| 46 |
|
| 0xe3, 0xe5, 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, |
| 47 |
|
| 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, 0xec, 0xdf, |
| 48 |
|
| 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e, 0x2d, 0x2f, 0xc2, 0xc4, |
| 49 |
|
| 0xc0, 0xc1, 0xc3, 0xc5, 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, |
| 50 |
|
| 0x3e, 0x3f, 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, |
| 51 |
|
| 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, 0xd8, 0x61, |
| 52 |
|
| 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0xab, 0xbb, |
| 53 |
|
| 0xf0, 0xfd, 0xfe, 0xb1, 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, |
| 54 |
|
| 0x6f, 0x70, 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, |
| 55 |
|
| 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, |
| 56 |
|
| 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae, 0xac, 0xa3, 0xa5, 0xb7, |
| 57 |
|
| 0xa9, 0xa7, 0xb6, 0xbc, 0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, |
| 58 |
|
| 0xb4, 0xd7, 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, |
| 59 |
|
| 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, 0x7d, 0x4a, |
| 60 |
|
| 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0xb9, 0xfb, |
| 61 |
|
| 0xfc, 0xf9, 0xfa, 0xff, 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, |
| 62 |
|
| 0x57, 0x58, 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, |
| 63 |
|
| 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
| 64 |
|
| 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f }; |
| 65 |
|
| |
| 66 |
|
| static unsigned char e2ap_table[256] = { |
| 67 |
|
| " " |
| 68 |
|
| " .<(+|& !$*); -/ ,%_>? `:#@'=\"" |
| 69 |
|
| " abcdefghi jklmnopqr ~stuvwxyz [ ] " |
| 70 |
|
| "{ABCDEFGHI }JKLMNOPQR \\ STUVWXYZ 0123456789 "}; |
| 71 |
|
| |
| 72 |
|
| /*---- End of tables ----*/ |
| 73 |
|
| |
| 74 |
|
| #ifdef OLD_INTERNAL |
| 75 |
|
| #define UNDEF_PTR &sv_undef |
| 76 |
|
| #else |
| 77 |
|
| #define UNDEF_PTR &PL_sv_undef |
| 78 |
|
| #endif |
| 79 |
|
| |
| 80 |
|
| /* 36KB may seem small, but on MVS most records are 32KB or less. */ |
| 81 |
|
| #define OUTSTRING_MEM 36864 |
| 82 |
|
| /* Macro: catenate a string to the end of an existing string |
| 83 |
|
| * and move the pointer up. */ |
| 84 |
|
| #define memcat(target,offset,source,len) \ |
| 85 |
|
| memcpy((target+offset), source, len); \ |
| 86 |
|
| offset += len; |
| 87 |
|
| |
| 88 |
|
| #ifndef min |
| 89 |
|
| #define min(x,y) (((x) < (y)) ? (x) : (y)) |
| 90 |
|
| #endif |
| 91 |
|
| |
| 92 |
|
| static int |
| 93 |
0 |
| not_here(char *s) |
| 94 |
|
| { |
| 95 |
0 |
| croak("%s not implemented on this architecture", s); |
| 96 |
|
| return -1; |
| 97 |
|
| } |
| 98 |
|
| |
| 99 |
|
| static double |
| 100 |
0 |
| constant(char *name, int len, int arg) |
| 101 |
|
| { |
| 102 |
0 |
| errno = EINVAL; |
| 103 |
0 |
| return 0; |
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
|
| |
| 107 |
|
| MODULE = Convert::IBM390 PACKAGE = Convert::IBM390 |
| 108 |
|
| |
| 109 |
|
| |
| 110 |
|
| void |
| 111 |
|
| asc2eb(instring_sv) |
| 112 |
|
| SV * instring_sv |
| 113 |
|
| PROTOTYPE: $ |
| 114 |
|
| PREINIT: |
| 115 |
|
| STRLEN ilength; |
| 116 |
|
| char * instring; |
| 117 |
|
| char * outstring_wk; |
| 118 |
|
| /* To avoid allocating small amounts of storage: */ |
| 119 |
|
| char shorty[SHORTY_SIZE]; |
| 120 |
|
| |
| 121 |
|
| PPCODE: |
| 122 |
3 |
| instring = SvPV(instring_sv, ilength); |
| 123 |
|
| #ifdef DEBUG390 |
| 124 |
|
| fprintf(stderr, "*D* asc2eb: beginning; length %d\n", ilength); |
| 125 |
|
| #endif |
| 126 |
3 |
▶ | if (ilength <= SHORTY_SIZE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ilength <= SHORTY_SIZE) { |
3 |
0 |
3 |
|
| 127 |
3 |
| CF_fcs_xlate(shorty, instring, ilength, a2e_table); |
| 128 |
3 |
| PUSHs(sv_2mortal(newSVpvn(shorty, ilength))); |
| 129 |
|
| } else { |
| 130 |
0 |
| New(0, outstring_wk, ilength, char); |
| 131 |
0 |
| CF_fcs_xlate(outstring_wk, instring, ilength, a2e_table); |
| 132 |
0 |
| PUSHs(sv_2mortal(newSVpvn(outstring_wk, ilength))); |
| 133 |
0 |
| Safefree(outstring_wk); |
| 134 |
|
| } |
| 135 |
|
| #ifdef DEBUG390 |
| 136 |
|
| fprintf(stderr, "*D* asc2eb: returning\n"); |
| 137 |
|
| #endif |
| 138 |
|
| |
| 139 |
|
| void |
| 140 |
|
| eb2asc(instring_sv) |
| 141 |
|
| SV * instring_sv |
| 142 |
|
| PROTOTYPE: $ |
| 143 |
|
| PREINIT: |
| 144 |
|
| STRLEN ilength; |
| 145 |
|
| char * instring; |
| 146 |
|
| char * outstring_wk; |
| 147 |
|
| /* To avoid allocating small amounts of storage: */ |
| 148 |
|
| char shorty[SHORTY_SIZE]; |
| 149 |
|
| |
| 150 |
|
| PPCODE: |
| 151 |
3 |
| instring = SvPV(instring_sv, ilength); |
| 152 |
|
| #ifdef DEBUG390 |
| 153 |
|
| fprintf(stderr, "*D* eb2asc: beginning; length %d\n", ilength); |
| 154 |
|
| #endif |
| 155 |
3 |
▶ | if (ilength <= SHORTY_SIZE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ilength <= SHORTY_SIZE) { |
3 |
0 |
3 |
|
| 156 |
3 |
| CF_fcs_xlate(shorty, instring, ilength, e2a_table); |
| 157 |
3 |
| PUSHs(sv_2mortal(newSVpvn(shorty, ilength))); |
| 158 |
|
| } else { |
| 159 |
0 |
| New(0, outstring_wk, ilength, char); |
| 160 |
0 |
| CF_fcs_xlate(outstring_wk, instring, ilength, e2a_table); |
| 161 |
0 |
| PUSHs(sv_2mortal(newSVpvn(outstring_wk, ilength))); |
| 162 |
0 |
| Safefree(outstring_wk); |
| 163 |
|
| } |
| 164 |
|
| #ifdef DEBUG390 |
| 165 |
|
| fprintf(stderr, "*D* eb2asc: returning\n"); |
| 166 |
|
| #endif |
| 167 |
|
| |
| 168 |
|
| void |
| 169 |
|
| eb2ascp(instring_sv) |
| 170 |
|
| SV * instring_sv |
| 171 |
|
| PROTOTYPE: $ |
| 172 |
|
| PREINIT: |
| 173 |
|
| STRLEN ilength; |
| 174 |
|
| char * instring; |
| 175 |
|
| char * outstring_wk; |
| 176 |
|
| /* To avoid allocating small amounts of storage: */ |
| 177 |
|
| char shorty[SHORTY_SIZE]; |
| 178 |
|
| |
| 179 |
|
| PPCODE: |
| 180 |
2 |
| instring = SvPV(instring_sv, ilength); |
| 181 |
|
| #ifdef DEBUG390 |
| 182 |
|
| fprintf(stderr, "*D* eb2ascp: beginning; length %d\n", ilength); |
| 183 |
|
| #endif |
| 184 |
2 |
▶ | if (ilength <= SHORTY_SIZE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ilength <= SHORTY_SIZE) { |
2 |
0 |
2 |
|
| 185 |
2 |
| CF_fcs_xlate(shorty, instring, ilength, e2ap_table); |
| 186 |
2 |
| PUSHs(sv_2mortal(newSVpvn(shorty, ilength))); |
| 187 |
|
| } else { |
| 188 |
0 |
| New(0, outstring_wk, ilength, char); |
| 189 |
0 |
| CF_fcs_xlate(outstring_wk, instring, ilength, e2ap_table); |
| 190 |
0 |
| PUSHs(sv_2mortal(newSVpvn(outstring_wk, ilength))); |
| 191 |
0 |
| Safefree(outstring_wk); |
| 192 |
|
| } |
| 193 |
|
| #ifdef DEBUG390 |
| 194 |
|
| fprintf(stderr, "*D* eb2ascp: returning\n"); |
| 195 |
|
| #endif |
| 196 |
|
| |
| 197 |
|
| |
| 198 |
|
| # // Much of the following code is shamelessly stolen from Perl's |
| 199 |
|
| # // built-in pack and unpack functions (pp.c). |
| 200 |
|
| # // packeb -- Pack a list of values into an EBCDIC record |
| 201 |
|
| void |
| 202 |
|
| packeb(pat, ...) |
| 203 |
|
| char * pat |
| 204 |
|
| PREINIT: |
| 205 |
|
| char outstring[OUTSTRING_MEM]; |
| 206 |
|
| |
| 207 |
|
| SV * item; |
| 208 |
|
| STRLEN item_len; |
| 209 |
|
| int ii; /* ii = item index */ |
| 210 |
|
| int oi; /* oi = outstring index */ |
| 211 |
|
| char datumtype; |
| 212 |
|
| register char * patend; |
| 213 |
|
| register int len; |
| 214 |
|
| int j, ndec, num_ok; |
| 215 |
|
| |
| 216 |
|
| static char null10[] = {0,0,0,0,0,0,0,0,0,0}; |
| 217 |
|
| /* space10 = native spaces. espace10 = EBCDIC spaces. */ |
| 218 |
|
| static char space10[] = " "; |
| 219 |
|
| static char espace10[] = |
| 220 |
|
| { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 }; |
| 221 |
|
| |
| 222 |
|
| I32 along; |
| 223 |
|
| char *aptr; |
| 224 |
|
| double adouble; |
| 225 |
|
| /* The eb_work area is long, but what the heck? Memory is cheap. */ |
| 226 |
|
| char eb_work[32800]; |
| 227 |
|
| |
| 228 |
|
| PPCODE: |
| 229 |
|
| #ifdef DEBUG390 |
| 230 |
|
| fprintf(stderr, "*D* packeb: beginning\n"); |
| 231 |
|
| #endif |
| 232 |
3 |
| ii = 1; |
| 233 |
3 |
| oi = 0; |
| 234 |
3 |
| patend = pat + strlen(pat); |
| 235 |
|
| |
| 236 |
29 |
▶ | while (pat < patend) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (pat < patend) { |
28 |
1 |
29 |
|
| 237 |
|
| /* Have we gone past the end of the list of values? If so, stop. */ |
| 238 |
28 |
▶ | if (ii >= items) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ii >= items) |
0 |
28 |
28 |
|
| 239 |
0 |
| break; |
| 240 |
28 |
▶ | if (oi >= OUTSTRING_MEM) |
Branch: 1 branch
| Branch | True | False | Total |
| if (oi >= OUTSTRING_MEM) |
0 |
28 |
28 |
|
| 241 |
0 |
| croak("Output structure too large in packeb"); |
| 242 |
|
| |
| 243 |
28 |
| datumtype = *pat++; |
| 244 |
28 |
▶ | if (isSPACE(datumtype)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (isSPACE(datumtype)) |
3 |
25 |
28 |
|
| 245 |
3 |
| continue; |
| 246 |
25 |
▶ | if (*pat == '*') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*pat == '*') { |
1 |
24 |
25 |
|
| 247 |
2 |
▶ | len = strchr("pz", datumtype) ? 8 : |
Branch: 1 branch
| Branch | True | False | Total |
| len = strchr("pz", datumtype) ? 8 : |
1 |
0 |
1 |
|
| 248 |
1 |
▶ | (strchr("@x", datumtype) ? 0 : items - ii + 1); |
Branch: 1 branch
| Branch | True | False | Total |
| (strchr("@x", datumtype) ? 0 : items - ii + 1); |
1 |
0 |
1 |
|
| 249 |
1 |
| pat++; |
| 250 |
24 |
▶ | } else if (isDIGIT(*pat)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (isDIGIT(*pat)) { |
22 |
2 |
24 |
|
| 251 |
22 |
| len = *pat++ - '0'; |
| 252 |
25 |
▶ | while (isDIGIT(*pat)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isDIGIT(*pat)) |
3 |
22 |
25 |
|
| 253 |
3 |
| len = (len * 10) + (*pat++ - '0'); |
| 254 |
|
| /* Decimal places (this result will be ignored if the |
| 255 |
|
| datumtype is not packed or zoned). */ |
| 256 |
22 |
| ndec = 0; |
| 257 |
22 |
▶ | if (*pat == '.') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*pat == '.') { |
2 |
20 |
22 |
|
| 258 |
2 |
| pat++; |
| 259 |
4 |
▶ | while (isDIGIT(*pat)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isDIGIT(*pat)) |
2 |
2 |
4 |
|
| 260 |
2 |
| ndec = (ndec * 10) + (*pat++ - '0'); |
| 261 |
|
| } |
| 262 |
|
| } else { |
| 263 |
2 |
▶ | len = strchr("pz", datumtype) ? 8 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| len = strchr("pz", datumtype) ? 8 : 1; |
0 |
2 |
2 |
|
| 264 |
|
| } |
| 265 |
|
| |
| 266 |
25 |
▶ | if (len > 32767) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 32767) { |
0 |
25 |
25 |
|
| 267 |
0 |
| croak("Field length too large in packeb: %c%d", |
| 268 |
|
| datumtype, len); |
| 269 |
|
| } |
| 270 |
|
| #ifdef DEBUG390 |
| 271 |
|
| fprintf(stderr, "*D* packeb: datumtype/len %c%d\n", |
| 272 |
|
| datumtype, len); |
| 273 |
|
| #endif |
| 274 |
|
| |
| 275 |
25 |
| switch(datumtype) { |
| 276 |
1 |
| case '@': |
| 277 |
1 |
▶ | if (len > OUTSTRING_MEM || len < 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (len > OUTSTRING_MEM || len < 0) |
1 |
0 |
1 |
| if (len > OUTSTRING_MEM || len < 0) |
0 |
1 |
1 |
|
| 278 |
0 |
| croak("@ position outside string"); |
| 279 |
1 |
| oi = len; |
| 280 |
1 |
| break; |
| 281 |
2 |
| case 'x': |
| 282 |
2 |
▶ | while (len >= 10) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len >= 10) { |
0 |
2 |
2 |
|
| 283 |
0 |
| memcat(outstring, oi, null10, 10); |
| 284 |
0 |
| len -= 10; |
| 285 |
|
| } |
| 286 |
2 |
| memcat(outstring, oi, null10, len); |
| 287 |
2 |
| break; |
| 288 |
|
| |
| 289 |
|
| /* [Ee]: EBCDIC character string */ |
| 290 |
3 |
| case 'E': |
| 291 |
|
| case 'e': |
| 292 |
3 |
| item = ST(ii); |
| 293 |
3 |
| ii++; |
| 294 |
3 |
| aptr = SvPV(item, item_len); |
| 295 |
3 |
▶ | if (pat[-1] == '*') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pat[-1] == '*') { |
0 |
3 |
3 |
|
| 296 |
0 |
| len = item_len; |
| 297 |
0 |
▶ | if (len > sizeof(eb_work)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > sizeof(eb_work)) |
0 |
0 |
0 |
|
| 298 |
0 |
| croak("String too long in packeb: %c*", datumtype); |
| 299 |
|
| } |
| 300 |
3 |
| CF_fcs_xlate(eb_work, aptr, min(len, item_len), a2e_table); |
| 301 |
|
| |
| 302 |
3 |
▶ | if (item_len > len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (item_len > len) { |
0 |
3 |
3 |
|
| 303 |
0 |
| memcat(outstring, oi, eb_work, len); |
| 304 |
|
| } else { |
| 305 |
3 |
| memcat(outstring, oi, eb_work, item_len); |
| 306 |
3 |
| len -= item_len; |
| 307 |
3 |
▶ | if (datumtype == 'E') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (datumtype == 'E') { |
1 |
2 |
3 |
|
| 308 |
1 |
▶ | while (len >= 10) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len >= 10) { |
0 |
1 |
1 |
|
| 309 |
0 |
| memcat(outstring, oi, espace10, 10); |
| 310 |
0 |
| len -= 10; |
| 311 |
|
| } |
| 312 |
1 |
| memcat(outstring, oi, espace10, len); |
| 313 |
|
| } |
| 314 |
|
| else { |
| 315 |
2 |
▶ | while (len >= 10) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len >= 10) { |
0 |
2 |
2 |
|
| 316 |
0 |
| memcat(outstring, oi, null10, 10); |
| 317 |
0 |
| len -= 10; |
| 318 |
|
| } |
| 319 |
2 |
| memcat(outstring, oi, null10, len); |
| 320 |
|
| } |
| 321 |
|
| } |
| 322 |
3 |
| break; |
| 323 |
|
| |
| 324 |
|
| /* [Cc]: characters without translation. If space padding |
| 325 |
|
| is requested, we pad with native spaces, not x'40'. */ |
| 326 |
2 |
| case 'C': |
| 327 |
|
| case 'c': |
| 328 |
2 |
| item = ST(ii); |
| 329 |
2 |
| ii++; |
| 330 |
2 |
| aptr = SvPV(item, item_len); |
| 331 |
2 |
▶ | if (pat[-1] == '*') |
Branch: 1 branch
| Branch | True | False | Total |
| if (pat[-1] == '*') |
1 |
1 |
2 |
|
| 332 |
1 |
| len = item_len; |
| 333 |
2 |
▶ | if (item_len > len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (item_len > len) { |
0 |
2 |
2 |
|
| 334 |
0 |
| memcat(outstring, oi, aptr, len); |
| 335 |
|
| } else { |
| 336 |
2 |
| memcat(outstring, oi, aptr, item_len); |
| 337 |
2 |
| len -= item_len; |
| 338 |
2 |
▶ | if (datumtype == 'C') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (datumtype == 'C') { |
1 |
1 |
2 |
|
| 339 |
1 |
▶ | while (len >= 10) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len >= 10) { |
0 |
1 |
1 |
|
| 340 |
0 |
| memcat(outstring, oi, space10, 10); |
| 341 |
0 |
| len -= 10; |
| 342 |
|
| } |
| 343 |
1 |
| memcat(outstring, oi, space10, len); |
| 344 |
|
| } |
| 345 |
|
| else { |
| 346 |
1 |
▶ | while (len >= 10) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len >= 10) { |
0 |
1 |
1 |
|
| 347 |
0 |
| memcat(outstring, oi, null10, 10); |
| 348 |
0 |
| len -= 10; |
| 349 |
|
| } |
| 350 |
1 |
| memcat(outstring, oi, null10, len); |
| 351 |
|
| } |
| 352 |
|
| } |
| 353 |
2 |
| break; |
| 354 |
|
| |
| 355 |
|
| /* [pP]: S/390 packed decimal. In this case, the length |
| 356 |
|
| given in the template is the length of a single field, |
| 357 |
|
| not a number of repetitions. */ |
| 358 |
6 |
| case 'p': |
| 359 |
|
| case 'P': |
| 360 |
6 |
▶ | if (len > 16) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 16) { |
0 |
6 |
6 |
|
| 361 |
0 |
| croak("Field length too large in packeb: %c%d", datumtype, len); |
| 362 |
|
| } |
| 363 |
6 |
| item = ST(ii); |
| 364 |
6 |
| ii++; |
| 365 |
6 |
| adouble = SvNV(item); |
| 366 |
|
| |
| 367 |
6 |
| num_ok = CF_num2packed(eb_work, adouble, len, ndec, |
| 368 |
|
| datumtype=='P'); |
| 369 |
6 |
▶ | if (! num_ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! num_ok) { |
1 |
5 |
6 |
|
| 370 |
1 |
| croak("Number %g too long for packed decimal", adouble); |
| 371 |
|
| } |
| 372 |
5 |
| item = ST(ii); |
| 373 |
5 |
| memcat(outstring, oi, eb_work, len); |
| 374 |
5 |
| break; |
| 375 |
|
| |
| 376 |
|
| /* i: S/390 fullword (signed). */ |
| 377 |
2 |
| case 'i': |
| 378 |
13 |
▶ | for (j = 0; j < len; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < len; j++) { |
11 |
2 |
13 |
|
| 379 |
11 |
| item = ST(ii); |
| 380 |
11 |
| ii++; |
| 381 |
11 |
| along = SvIV(item); |
| 382 |
11 |
| _to_S390fw(eb_work, along); |
| 383 |
11 |
| memcat(outstring, oi, eb_work, 4); |
| 384 |
|
| } |
| 385 |
2 |
| break; |
| 386 |
|
| |
| 387 |
|
| /* [sS]: S/390 halfword (signed/unsigned). */ |
| 388 |
4 |
| case 's': |
| 389 |
|
| case 'S': |
| 390 |
15 |
▶ | for (j = 0; j < len; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < len; j++) { |
11 |
4 |
15 |
|
| 391 |
11 |
| item = ST(ii); |
| 392 |
11 |
| ii++; |
| 393 |
11 |
| along = SvIV(item); |
| 394 |
11 |
▶ | if (datumtype == 's') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (datumtype == 's') { |
10 |
1 |
11 |
|
| 395 |
10 |
| _to_S390hw(eb_work, along); |
| 396 |
10 |
| memcat(outstring, oi, eb_work, 2); |
| 397 |
|
| } else { |
| 398 |
1 |
| _to_S390fw(eb_work, along); |
| 399 |
1 |
| memcat(outstring, oi, eb_work+2, 2); |
| 400 |
|
| } |
| 401 |
|
| } |
| 402 |
4 |
| break; |
| 403 |
|
| |
| 404 |
|
| /* [zZ]: S/390 zoned decimal. In this case, the length given |
| 405 |
|
| in the template is the length of a single field, not a |
| 406 |
|
| number of repetitions. */ |
| 407 |
4 |
| case 'z': |
| 408 |
|
| case 'Z': |
| 409 |
4 |
▶ | if (len > 32) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 32) { |
0 |
4 |
4 |
|
| 410 |
0 |
| croak("Field length too large in packeb: z%d", len); |
| 411 |
|
| } |
| 412 |
4 |
| item = ST(ii); |
| 413 |
4 |
| ii++; |
| 414 |
4 |
| adouble = SvNV(item); |
| 415 |
|
| |
| 416 |
4 |
| num_ok = CF_num2zoned(eb_work, adouble, len, ndec, datumtype=='Z'); |
| 417 |
4 |
▶ | if (! num_ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! num_ok) { |
1 |
3 |
4 |
|
| 418 |
1 |
| croak("Number %g too long for zoned decimal", adouble); |
| 419 |
|
| } |
| 420 |
3 |
| memcat(outstring, oi, eb_work, len); |
| 421 |
3 |
| break; |
| 422 |
|
| |
| 423 |
1 |
| case 'H': |
| 424 |
|
| case 'h': |
| 425 |
|
| { |
| 426 |
|
| char *hexstring; |
| 427 |
|
| I32 workbyte, xi; /* xi = index into hexstring */ |
| 428 |
|
| unsigned char hexbyte, final_byte; |
| 429 |
|
| |
| 430 |
1 |
| item = ST(ii); |
| 431 |
1 |
| ii++; |
| 432 |
1 |
| hexstring = SvPV(item, item_len); |
| 433 |
1 |
▶ | if (pat[-1] == '*') |
Branch: 1 branch
| Branch | True | False | Total |
| if (pat[-1] == '*') |
0 |
1 |
1 |
|
| 434 |
0 |
| len = item_len; |
| 435 |
1 |
▶ | if (len < 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 2) |
0 |
1 |
1 |
|
| 436 |
0 |
| len = 2; |
| 437 |
1 |
▶ | if (len > item_len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > item_len) |
0 |
1 |
1 |
|
| 438 |
0 |
| len = item_len; |
| 439 |
1 |
| workbyte = 0; |
| 440 |
7 |
▶ | for (xi = 0; xi < len; xi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (xi = 0; xi < len; xi++) { |
6 |
1 |
7 |
|
| 441 |
6 |
| hexbyte = (unsigned char) hexstring[xi]; |
| 442 |
6 |
▶ | if (isALPHA(hexbyte)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (isALPHA(hexbyte)) |
4 |
2 |
6 |
|
| 443 |
4 |
| workbyte |= ((hexbyte & 15) + 9) & 15; |
| 444 |
|
| else |
| 445 |
2 |
| workbyte |= hexbyte & 15; |
| 446 |
6 |
▶ | if (! (xi & 1)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (! (xi & 1)) |
3 |
3 |
6 |
|
| 447 |
3 |
| workbyte <<= 4; |
| 448 |
|
| else { |
| 449 |
3 |
| final_byte = workbyte & 0xFF; |
| 450 |
3 |
| memcat(outstring, oi, &final_byte, 1); |
| 451 |
3 |
| workbyte = 0; |
| 452 |
|
| } |
| 453 |
|
| } |
| 454 |
1 |
▶ | if (xi & 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xi & 1) { |
0 |
1 |
1 |
|
| 455 |
0 |
| final_byte = workbyte & 0xFF; |
| 456 |
0 |
| memcat(outstring, oi, &final_byte, 1); |
| 457 |
|
| } |
| 458 |
|
| } |
| 459 |
1 |
| break; |
| 460 |
|
| |
| 461 |
0 |
| default: |
| 462 |
0 |
| croak("Invalid type in packeb: '%c'", datumtype); |
| 463 |
|
| } |
| 464 |
|
| } |
| 465 |
|
| |
| 466 |
1 |
| PUSHs(sv_2mortal(newSVpvn(outstring, oi))); |
| 467 |
|
| #ifdef DEBUG390 |
| 468 |
|
| fprintf(stderr, "*D* packeb: returning\n"); |
| 469 |
|
| #endif |
| 470 |
|
| |
| 471 |
|
| |
| 472 |
|
| # unpackeb -- Unpack an EBCDIC record into a list |
| 473 |
|
| # Note that the EBCDIC data may contain nulls and other unprintable |
| 474 |
|
| # stuff, so we need an SV*, not just a char*. |
| 475 |
|
| void |
| 476 |
|
| unpackeb(pat, ebrecord) |
| 477 |
|
| char * pat |
| 478 |
|
| SV * ebrecord |
| 479 |
|
| PROTOTYPE: $$ |
| 480 |
|
| PREINIT: |
| 481 |
|
| SV *sv; |
| 482 |
|
| STRLEN rlen; |
| 483 |
|
| |
| 484 |
|
| register char *s; |
| 485 |
|
| char *sbegin; |
| 486 |
|
| char *tail; |
| 487 |
|
| char *strend; |
| 488 |
|
| register char *patend; |
| 489 |
|
| char datumtype; |
| 490 |
|
| register I32 len, outlen; |
| 491 |
2 |
| register I32 bits = 0; |
| 492 |
|
| int i, j, ndec, fieldlen; |
| 493 |
2 |
▶ | char hexdigit[16] = "0123456789abcdef"; |
Branch: 1 branch
| Branch | True | False | Total |
| char hexdigit[16] = "0123456789abcdef"; |
2 |
0 |
2 |
|
| 494 |
|
| |
| 495 |
|
| /* Work fields */ |
| 496 |
|
| I32 along; |
| 497 |
|
| unsigned long aulong; |
| 498 |
|
| /* Some day we may want to support S/390 floats.... */ |
| 499 |
|
| /*float afloat;*/ |
| 500 |
|
| double adouble; |
| 501 |
|
| /* The eb_work area is long, but what the heck? Memory is cheap. */ |
| 502 |
|
| char eb_work[32800]; |
| 503 |
|
| |
| 504 |
|
| PPCODE: |
| 505 |
|
| #ifdef DEBUG390 |
| 506 |
|
| fprintf(stderr, "*D* unpackeb: beginning\n"); |
| 507 |
|
| #endif |
| 508 |
2 |
| s = sbegin = SvPV(ebrecord, rlen); |
| 509 |
2 |
| strend = s + rlen; |
| 510 |
2 |
| patend = pat + strlen(pat); |
| 511 |
|
| |
| 512 |
31 |
▶ | while (pat < patend) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (pat < patend) { |
29 |
2 |
31 |
|
| 513 |
29 |
| datumtype = *pat++; |
| 514 |
29 |
▶ | if (isSPACE(datumtype)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (isSPACE(datumtype)) |
2 |
27 |
29 |
|
| 515 |
2 |
| continue; |
| 516 |
27 |
| ndec = 0; |
| 517 |
27 |
▶ | if (pat >= patend) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (pat >= patend) { |
1 |
26 |
27 |
|
| 518 |
1 |
| len = 1; |
| 519 |
|
| } |
| 520 |
26 |
▶ | else if (*pat == '*') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*pat == '*') { |
0 |
26 |
26 |
|
| 521 |
0 |
| len = strend - s; |
| 522 |
0 |
▶ | if (datumtype == 'i' || datumtype == 'I') len = len / 4; |
Branch: 2 branches
| Branch | True | False | Total |
| if (datumtype == 'i' || datumtype == 'I') len = len / 4; |
0 |
0 |
0 |
| if (datumtype == 'i' || datumtype == 'I') len = len / 4; |
0 |
0 |
0 |
|
| 523 |
0 |
▶ | if (datumtype == 's' || datumtype == 'S') len = len / 2; |
Branch: 2 branches
| Branch | True | False | Total |
| if (datumtype == 's' || datumtype == 'S') len = len / 2; |
0 |
0 |
0 |
| if (datumtype == 's' || datumtype == 'S') len = len / 2; |
0 |
0 |
0 |
|
| 524 |
0 |
| pat++; |
| 525 |
|
| } |
| 526 |
26 |
▶ | else if (isDIGIT(*pat)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (isDIGIT(*pat)) { |
22 |
4 |
26 |
|
| 527 |
22 |
| len = *pat++ - '0'; |
| 528 |
23 |
▶ | while (isDIGIT(*pat)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isDIGIT(*pat)) |
1 |
22 |
23 |
|
| 529 |
1 |
| len = (len * 10) + (*pat++ - '0'); |
| 530 |
|
| /* Decimal places (this result will be ignored if the |
| 531 |
|
| datumtype is not packed or zoned). */ |
| 532 |
22 |
| ndec = 0; |
| 533 |
22 |
▶ | if (*pat == '.') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*pat == '.') { |
1 |
21 |
22 |
|
| 534 |
1 |
| pat++; |
| 535 |
2 |
▶ | while (isDIGIT(*pat)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (isDIGIT(*pat)) |
1 |
1 |
2 |
|
| 536 |
1 |
| ndec = (ndec * 10) + (*pat++ - '0'); |
| 537 |
|
| } |
| 538 |
|
| } |
| 539 |
|
| else { |
| 540 |
4 |
| len = 1; |
| 541 |
|
| } |
| 542 |
27 |
▶ | if (len > 32767) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 32767) { |
0 |
27 |
27 |
|
| 543 |
0 |
| croak("Field length too large in unpackeb: %c%d", |
| 544 |
|
| datumtype, len); |
| 545 |
|
| } |
| 546 |
|
| #ifdef DEBUG390 |
| 547 |
|
| fprintf(stderr, "*D* unpackeb: datumtype/len %c%d\n", |
| 548 |
|
| datumtype, len); |
| 549 |
|
| #endif |
| 550 |
27 |
| switch(datumtype) { |
| 551 |
|
| /* @: absolute offset */ |
| 552 |
1 |
| case '@': |
| 553 |
1 |
▶ | if (len >= rlen || len < 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (len >= rlen || len < 0) |
1 |
0 |
1 |
| if (len >= rlen || len < 0) |
0 |
1 |
1 |
|
| 554 |
0 |
| croak("Absolute offset is outside string: @%d", len); |
| 555 |
1 |
| s = sbegin + len; |
| 556 |
1 |
| break; |
| 557 |
|
| |
| 558 |
|
| /* [eE]: EBCDIC character string. In this case, the length |
| 559 |
|
| given in the template is the length of a single field, not |
| 560 |
|
| a number of repetitions. */ |
| 561 |
2 |
| case 'e': |
| 562 |
|
| case 'E': |
| 563 |
2 |
▶ | if (len > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > strend - s) |
0 |
2 |
2 |
|
| 564 |
0 |
| len = strend - s; |
| 565 |
2 |
| CF_fcs_xlate(eb_work, s, len, e2a_table); |
| 566 |
2 |
| outlen = len; |
| 567 |
2 |
▶ | if (len < 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 1) |
0 |
2 |
2 |
|
| 568 |
0 |
| eb_work[0] = 0x00; /* Force an empty string. */ |
| 569 |
2 |
▶ | if (datumtype == 'E') { /* Strip nulls and spaces */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (datumtype == 'E') { /* Strip nulls and spaces */ |
1 |
1 |
2 |
|
| 570 |
1 |
| tail = eb_work + len - 1; |
| 571 |
3 |
▶ | while (tail >= eb_work && (*tail==' ' || *tail=='\0')) |
Branch: 3 branches
| Branch | True | False | Total |
| while (tail >= eb_work && (*tail==' ' || *tail=='\0')) |
3 |
0 |
3 |
| while (tail >= eb_work && (*tail==' ' || *tail=='\0')) |
2 |
1 |
3 |
| while (tail >= eb_work && (*tail==' ' || *tail=='\0')) |
0 |
1 |
1 |
|
| 572 |
2 |
| tail--; |
| 573 |
1 |
| outlen = tail - eb_work + 1; |
| 574 |
|
| } |
| 575 |
|
| |
| 576 |
2 |
▶ | XPUSHs(sv_2mortal(newSVpvn(eb_work, outlen))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(eb_work, outlen))); |
0 |
2 |
2 |
|
| 577 |
2 |
| s += len; |
| 578 |
2 |
| break; |
| 579 |
|
| |
| 580 |
|
| /* p: S/390 packed decimal. In this case, the length given |
| 581 |
|
| in the template is the length of a single field, not a |
| 582 |
|
| number of repetitions. */ |
| 583 |
4 |
| case 'p': |
| 584 |
4 |
▶ | if (len > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > strend - s) |
0 |
4 |
4 |
|
| 585 |
0 |
| len = strend - s; |
| 586 |
4 |
▶ | if (len > 16) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 16) { |
0 |
4 |
4 |
|
| 587 |
0 |
| croak("Field length too large in unpackeb: p%d", len); |
| 588 |
|
| } |
| 589 |
4 |
| adouble = CF_packed2num(s, len, ndec); |
| 590 |
4 |
▶ | if ( adouble == INVALID_390NUM ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( adouble == INVALID_390NUM ) { |
1 |
3 |
4 |
|
| 591 |
1 |
| sv = UNDEF_PTR; |
| 592 |
|
| } else { |
| 593 |
3 |
| sv = newSVnv(adouble); |
| 594 |
|
| } |
| 595 |
|
| |
| 596 |
4 |
▶ | XPUSHs(sv_2mortal(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(sv)); |
0 |
4 |
4 |
|
| 597 |
4 |
| s += len; |
| 598 |
4 |
| break; |
| 599 |
|
| |
| 600 |
|
| /* z: S/390 zoned decimal. In this case, the length given |
| 601 |
|
| in the template is the length of a single field, not a |
| 602 |
|
| number of repetitions. */ |
| 603 |
1 |
| case 'z': |
| 604 |
1 |
▶ | if (len > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > strend - s) |
0 |
1 |
1 |
|
| 605 |
0 |
| len = strend - s; |
| 606 |
1 |
▶ | if (len > 32) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 32) { |
0 |
1 |
1 |
|
| 607 |
0 |
| croak("Field length too large in unpackeb: z%d", len); |
| 608 |
|
| } |
| 609 |
1 |
| adouble = CF_zoned2num(s, len, ndec); |
| 610 |
1 |
▶ | if ( adouble == INVALID_390NUM ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( adouble == INVALID_390NUM ) { |
0 |
1 |
1 |
|
| 611 |
0 |
| sv = UNDEF_PTR; |
| 612 |
|
| } else { |
| 613 |
1 |
| sv = newSVnv(adouble); |
| 614 |
|
| } |
| 615 |
|
| |
| 616 |
1 |
▶ | XPUSHs(sv_2mortal(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(sv)); |
0 |
1 |
1 |
|
| 617 |
1 |
| s += len; |
| 618 |
1 |
| break; |
| 619 |
|
| |
| 620 |
|
| /* [Cc]: characters without translation */ |
| 621 |
1 |
| case 'C': |
| 622 |
|
| case 'c': |
| 623 |
1 |
▶ | if (len > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > strend - s) |
0 |
1 |
1 |
|
| 624 |
0 |
| len = strend - s; |
| 625 |
1 |
▶ | XPUSHs(sv_2mortal(newSVpvn(s, len))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(s, len))); |
0 |
1 |
1 |
|
| 626 |
1 |
| s += len; |
| 627 |
1 |
| break; |
| 628 |
|
| |
| 629 |
|
| /* i: integer (System/390 fullword) */ |
| 630 |
5 |
| case 'i': |
| 631 |
5 |
▶ | if (len > (strend - s) / 4) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > (strend - s) / 4) |
0 |
5 |
5 |
|
| 632 |
0 |
| len = (strend - s) / 4; |
| 633 |
30 |
▶ | for (i=0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < len; i++) { |
25 |
5 |
30 |
|
| 634 |
25 |
| along = 0; |
| 635 |
25 |
| along = (signed char) *s; s++; |
| 636 |
100 |
▶ | for (j=1; j < 4; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=1; j < 4; j++) { |
75 |
25 |
100 |
|
| 637 |
75 |
| along <<= 8; |
| 638 |
75 |
| along += (unsigned char) *s; s++; |
| 639 |
|
| } |
| 640 |
|
| |
| 641 |
25 |
▶ | XPUSHs(sv_2mortal(newSViv(along))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(along))); |
0 |
25 |
25 |
|
| 642 |
|
| } |
| 643 |
5 |
| break; |
| 644 |
|
| |
| 645 |
|
| /* s: short integer (System/390 halfword) */ |
| 646 |
4 |
| case 's': |
| 647 |
4 |
▶ | if (len > (strend - s) / 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > (strend - s) / 2) |
0 |
4 |
4 |
|
| 648 |
0 |
| len = (strend - s) / 2; |
| 649 |
15 |
▶ | for (i=0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < len; i++) { |
11 |
4 |
15 |
|
| 650 |
11 |
| along = _halfword(s); |
| 651 |
|
| |
| 652 |
11 |
▶ | XPUSHs(sv_2mortal(newSViv(along))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(along))); |
0 |
11 |
11 |
|
| 653 |
11 |
| s += 2; |
| 654 |
|
| } |
| 655 |
4 |
| break; |
| 656 |
|
| |
| 657 |
|
| /* [hH]: unpack to printable hex digits. The length given |
| 658 |
|
| in the template is the length of a single field, not |
| 659 |
|
| a number of repetitions. */ |
| 660 |
1 |
| case 'h': |
| 661 |
|
| case 'H': |
| 662 |
1 |
▶ | if (len > (strend - s) * 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > (strend - s) * 2) |
0 |
1 |
1 |
|
| 663 |
0 |
| len = (strend - s) * 2; |
| 664 |
1 |
▶ | if (len < 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len < 1) |
0 |
1 |
1 |
|
| 665 |
0 |
| eb_work[0] = 0x00; /* Force an empty string. */ |
| 666 |
1 |
| i = 0; |
| 667 |
1 |
| along = len; |
| 668 |
5 |
▶ | for (len = 0; len < along; len++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (len = 0; len < along; len++) { |
4 |
1 |
5 |
|
| 669 |
4 |
▶ | if (len & 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len & 1) |
2 |
2 |
4 |
|
| 670 |
2 |
| bits <<= 4; |
| 671 |
|
| else |
| 672 |
2 |
| bits = *s++; |
| 673 |
4 |
| eb_work[i++] = hexdigit[(bits >> 4) & 15]; |
| 674 |
|
| } |
| 675 |
1 |
| eb_work[i] = '\0'; |
| 676 |
1 |
▶ | XPUSHs(sv_2mortal(newSVpvn(eb_work, len))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn(eb_work, len))); |
0 |
1 |
1 |
|
| 677 |
1 |
| break; |
| 678 |
|
| |
| 679 |
|
| /* v: varchar EBCDIC character string; i.e., a string of |
| 680 |
|
| EBCDIC characters preceded by a halfword length field (as |
| 681 |
|
| in DB2/MVS, for instance). 'len' here is a repeat count, |
| 682 |
|
| but don't go beyond the end of the record. */ |
| 683 |
2 |
| case 'v': |
| 684 |
5 |
▶ | for (i=0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < len; i++) { |
3 |
2 |
5 |
|
| 685 |
3 |
▶ | if (s >= strend) |
Branch: 1 branch
| Branch | True | False | Total |
| if (s >= strend) |
0 |
3 |
3 |
|
| 686 |
0 |
| break; |
| 687 |
3 |
| fieldlen = _halfword(s); |
| 688 |
3 |
| s += 2; |
| 689 |
|
| |
| 690 |
3 |
▶ | if (fieldlen > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fieldlen > strend - s) |
0 |
3 |
3 |
|
| 691 |
0 |
| fieldlen = strend - s; |
| 692 |
3 |
▶ | if (fieldlen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fieldlen > 0) { |
1 |
2 |
3 |
|
| 693 |
1 |
| CF_fcs_xlate(eb_work, s, fieldlen, e2a_table); |
| 694 |
1 |
| sv = newSVpvn(eb_work, fieldlen); |
| 695 |
2 |
▶ | } else if (fieldlen == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (fieldlen == 0) { |
1 |
1 |
2 |
|
| 696 |
1 |
| sv = newSVpvn("", 0); |
| 697 |
|
| } else { |
| 698 |
1 |
| sv = UNDEF_PTR; |
| 699 |
|
| } |
| 700 |
3 |
▶ | XPUSHs(sv_2mortal(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(sv)); |
0 |
3 |
3 |
|
| 701 |
3 |
| s += fieldlen; |
| 702 |
|
| } |
| 703 |
2 |
| break; |
| 704 |
|
| |
| 705 |
|
| /* V: varchar string with a halfword length but a fixed field |
| 706 |
|
| size. 'len' here is the length of the field exclusive of the |
| 707 |
|
| leading halfword. */ |
| 708 |
2 |
| case 'V': |
| 709 |
2 |
▶ | if (len > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > strend - s) |
0 |
2 |
2 |
|
| 710 |
0 |
| len = strend - s; |
| 711 |
2 |
| fieldlen = _halfword(s); |
| 712 |
2 |
| s += 2; |
| 713 |
|
| |
| 714 |
2 |
▶ | if (fieldlen > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fieldlen > strend - s) |
0 |
2 |
2 |
|
| 715 |
0 |
| fieldlen = strend - s; |
| 716 |
2 |
▶ | if (fieldlen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fieldlen > 0) { |
1 |
1 |
2 |
|
| 717 |
1 |
| CF_fcs_xlate(eb_work, s, fieldlen, e2a_table); |
| 718 |
1 |
| sv = newSVpvn(eb_work, fieldlen); |
| 719 |
1 |
▶ | } else if (fieldlen == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (fieldlen == 0) { |
1 |
0 |
1 |
|
| 720 |
1 |
| sv = newSVpvn("", 0); |
| 721 |
|
| } else { |
| 722 |
0 |
| sv = UNDEF_PTR; |
| 723 |
|
| } |
| 724 |
2 |
▶ | XPUSHs(sv_2mortal(sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(sv)); |
0 |
2 |
2 |
|
| 725 |
2 |
| s += len; |
| 726 |
2 |
| break; |
| 727 |
|
| |
| 728 |
|
| /* x: ignore these bytes (do not return an element) */ |
| 729 |
1 |
| case 'x': |
| 730 |
1 |
▶ | if (len > strend - s) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > strend - s) |
0 |
1 |
1 |
|
| 731 |
0 |
| len = strend - s; |
| 732 |
1 |
| s += len; |
| 733 |
1 |
| break; |
| 734 |
|
| |
| 735 |
|
| /* I: unsigned integer (fullword) */ |
| 736 |
|
| /* On most systems, integer = long = 32 bits, signed. |
| 737 |
|
| Therefore, to be safe, we compute this as an unsigned long |
| 738 |
|
| and then cast it to a double. */ |
| 739 |
1 |
| case 'I': |
| 740 |
1 |
▶ | if (len > (strend - s) / 4) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > (strend - s) / 4) |
0 |
1 |
1 |
|
| 741 |
0 |
| len = (strend - s) / 4; |
| 742 |
|
| if (sizeof(unsigned long) < 4) { |
| 743 |
|
| warn("Unsigned integer results may be invalid"); |
| 744 |
|
| } |
| 745 |
2 |
▶ | for (i=0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < len; i++) { |
1 |
1 |
2 |
|
| 746 |
1 |
| aulong = 0; |
| 747 |
5 |
▶ | for (j=0; j < 4; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j < 4; j++) { |
4 |
1 |
5 |
|
| 748 |
4 |
| aulong <<= 8; |
| 749 |
4 |
| aulong += (unsigned char) *s; s++; |
| 750 |
|
| } |
| 751 |
|
| |
| 752 |
1 |
▶ | XPUSHs(sv_2mortal(newSVnv((double) aulong))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVnv((double) aulong))); |
0 |
1 |
1 |
|
| 753 |
|
| } |
| 754 |
1 |
| break; |
| 755 |
|
| |
| 756 |
|
| /* S: unsigned short integer (halfword) */ |
| 757 |
2 |
| case 'S': |
| 758 |
2 |
▶ | if (len > (strend - s) / 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > (strend - s) / 2) |
0 |
2 |
2 |
|
| 759 |
0 |
| len = (strend - s) / 2; |
| 760 |
4 |
▶ | for (i=0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < len; i++) { |
2 |
2 |
4 |
|
| 761 |
2 |
| along = 0; |
| 762 |
2 |
| along = ((unsigned char) *s) << 8; s++; |
| 763 |
2 |
| along += (unsigned char) *s; s++; |
| 764 |
|
| |
| 765 |
2 |
▶ | XPUSHs(sv_2mortal(newSViv(along))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(along))); |
0 |
2 |
2 |
|
| 766 |
|
| } |
| 767 |
2 |
| break; |
| 768 |
|
| |
| 769 |
0 |
| default: |
| 770 |
0 |
| croak("Invalid type in unpackeb: '%c'", datumtype); |
| 771 |
|
| } |
| 772 |
|
| } |
| 773 |
|
| #ifdef DEBUG390 |
| 774 |
|
| fprintf(stderr, "*D* unpackeb: returning\n"); |
| 775 |
|
| #endif |
| 776 |
|
| |
| 777 |
|
| void |
| 778 |
|
| _set_translation(a2e_sv, e2a_sv, e2ap_sv) |
| 779 |
|
| SV * a2e_sv |
| 780 |
|
| SV * e2a_sv |
| 781 |
|
| SV * e2ap_sv |
| 782 |
|
| PROTOTYPE: DISABLE |
| 783 |
|
| PREINIT: |
| 784 |
|
| STRLEN ilength; |
| 785 |
|
| char * a2e_string; |
| 786 |
|
| char * e2a_string; |
| 787 |
|
| char * e2ap_string; |
| 788 |
|
| |
| 789 |
|
| CODE: |
| 790 |
2 |
| a2e_string = SvPVbyte(a2e_sv, ilength); |
| 791 |
2 |
▶ | if (ilength != 256) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ilength != 256) { |
0 |
2 |
2 |
|
| 792 |
0 |
| croak("a2e table must be 256 bytes, not %d", ilength); |
| 793 |
|
| } |
| 794 |
|
| |
| 795 |
2 |
| e2a_string = SvPVbyte(e2a_sv, ilength); |
| 796 |
2 |
▶ | if (ilength != 256) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ilength != 256) { |
0 |
2 |
2 |
|
| 797 |
0 |
| croak("e2a table must be 256 bytes, not %d", ilength); |
| 798 |
|
| } |
| 799 |
|
| |
| 800 |
2 |
| e2ap_string = SvPVbyte(e2ap_sv, ilength); |
| 801 |
2 |
▶ | if (ilength != 256) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ilength != 256) { |
0 |
2 |
2 |
|
| 802 |
0 |
| croak("e2ap table must be 256 bytes, not %d", ilength); |
| 803 |
|
| } |
| 804 |
|
| |
| 805 |
2 |
| memcpy(a2e_table, a2e_string, 256); |
| 806 |
2 |
| memcpy(e2a_table, e2a_string, 256); |
| 807 |
2 |
| memcpy(e2ap_table, e2ap_string, 256); |