Skip to content

Commit

Permalink
Merge pull request #119 from halcyon-tech/fix/fixed_position
Browse files Browse the repository at this point in the history
Fix/fixed position
  • Loading branch information
worksofliam authored Aug 30, 2022
2 parents f095521 + 609b5ab commit 1de9839
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 21 deletions.
54 changes: 34 additions & 20 deletions src/language/models/fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports.parseDLine = (line) => {
line = line.padEnd(80);
const potentialName = line.substring(6).trim();
const name = line.substr(6, 15).trim();
const pos = line.substr(19, 3).trim();
const pos = line.substr(25, 7).trim();
const len = line.substr(32, 7).trim();
const type = line.substr(39, 1).trim();
const decimals = line.substr(40, 3).trim();
Expand Down Expand Up @@ -96,6 +96,11 @@ exports.parsePLine = (line) => {
*/
exports.getPrettyType = (lineData) => {
let outType = ``;
let length = Number(lineData.len);

if (lineData.pos) {
length = length - Number(lineData.pos) + 1;
}

switch (lineData.type.toUpperCase()) {
case `A`:
Expand All @@ -104,7 +109,7 @@ exports.getPrettyType = (lineData) => {
} else {
outType = `Char`;
}
outType += `(` + lineData.len + `)`;
outType += `(` + length + `)`;
break;
case `B`:
if (lineData.pos != ``) {
Expand Down Expand Up @@ -138,43 +143,52 @@ exports.getPrettyType = (lineData) => {
outType += `(` + lineData.len + `)`;
break;
case `I`:
switch (lineData.len) {
case `1`:
switch (length) {
case 1:
outType = `Int(3)`;
break;
case `2`:
case 2:
outType = `Int(5)`;
break;
case `4`:
case 4:
outType = `Int(10)`;
break;
case `8`:
case 8:
outType = `Int(20)`;
break;
default:
outType = `Int(` + lineData.len + `)`;
outType = `Int(` + length + `)`;
}
break;
case `N`:
outType = `Ind`;
break;
case `P`:
if (lineData.pos != ``) {
// When using positions packed lineData.length is one less than double the bytes
outType = `Packed` + `(` + String(Number(lineData.len)) + `:` + lineData.decimals + `)`;
} else {
// Not using positions, then the lineData.length is correct
outType = `Packed` + `(` + lineData.len + `:` + lineData.decimals + `)`;
}
outType = `Packed` + `(` + length + `:` + lineData.decimals + `)`;
break;
case `S`:
outType = `Zoned` + `(` + lineData.len + `:` + lineData.decimals + `)`;
outType = `Zoned` + `(` + length + `:` + lineData.decimals + `)`;
break;
case `T`:
outType = `Time`;
break;
case `U`:
outType = `Uns` + `(` + lineData.len + `)`;
switch (length) {
case 1:
outType = `Uns(3)`;
break;
case 2:
outType = `Uns(5)`;
break;
case 4:
outType = `Uns(10)`;
break;
case 8:
outType = `Uns(20)`;
break;
default:
outType = `Uns(` + length + `)`;
}
break;
case `Z`:
outType = `Timestamp`;
Expand All @@ -192,14 +206,14 @@ exports.getPrettyType = (lineData) => {
} else {
outType = `Char`;
}
outType += `(` + lineData.len + `)`;
outType += `(` + length + `)`;
} else {
if (lineData.field === ``) {
// Means it's a subfield.
outType = `Zoned` + `(` + lineData.len + `:` + lineData.decimals + `)`;
outType = `Zoned` + `(` + length + `:` + lineData.decimals + `)`;
} else {
// Means it's a standalone.
outType = `Packed` + `(` + lineData.len + `:` + lineData.decimals + `)`;
outType = `Packed` + `(` + length + `:` + lineData.decimals + `)`;
}
}
}
Expand Down
68 changes: 67 additions & 1 deletion tests/suite/fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,70 @@ exports.comments1 = async () => {
start: 25,
end: 28
});
};
};

exports.ranges = async () => {
const lines = [
` D******************************************************************`,
` D*Record structure for QUSRJOBI JOBI1000 format`,
` D******************************************************************`,
` DQUSI1000 DS`,
` D* Qwc JOBI1000`,
` D QUSBR12 1 4I 0`,
` D* Bytes Return`,
` D QUSBA12 5 8I 0`,
` D* Bytes Avail`,
` D QUSJN16 9 18`,
` D* Job Name`,
` D QUSUN19 19 28`,
` D* User Name`,
` D QUSJNBR15 29 34`,
` D* Job Number`,
` D QUSIJID13 35 50`,
` D* Int Job ID`,
` D QUSJS25 51 60`,
` D* Job Status`,
` D QUSJT13 61 61`,
` D* Job Type`,
` D QUSJS26 62 62`,
` D* Job Subtype`,
` D QUSERVED50 63 64`,
` D* Reserved`,
` D QUSET01 65 72U 0`,
` D* Elapsed Time`,
` D QUSTDIOC 73 80U 0`,
` D* Total DiskIO Count`,
` D QUSADIOC 81 88U 0`,
` D* Async DiskIO Count`,
` D QUSSDIOC 89 96U 0`,
` D* Sync DiskIO Count`,
` D QUSIRT 97 100I 0`,
` D* Int Response Time`,
` D QUSITC 101 104I 0`,
` D* Int Trans Count`,
` D QUSCPUUP 105 108I 0`,
` D* CPU Used Percent`,
` D QUSUUDBP 109 112I 0`,
` D* CPU Used DB Percent`,
` D QUSCPUUT 113 120U 0`,
` D* CPU Used Time`,
` D QUSUUDBT 121 128U 0`,
` D* CPU Used DB Time`,
` D QUSLWT 129 136U 0`,
` D* Lock Wait Time`,
` D QUSPFC 137 144U 0`,
` D* Page Fault Count`,
].join(`\n`);

const parser = new Parser();
const cache = await parser.getDocs(uri, lines);

const QUSLWT = cache.find(`QUSLWT`);
assert.strictEqual(QUSLWT.keyword[`UNS`], `20`);

const QUSUUDBP = cache.find(`QUSUUDBP`);
assert.strictEqual(QUSUUDBP.keyword[`INT`], `10`);

const QUSUN19 = cache.find(`QUSUN19`);
assert.strictEqual(QUSUN19.keyword[`CHAR`], `10`);
}

0 comments on commit 1de9839

Please sign in to comment.