Refactor for _static pattern; no Keeps
This commit is contained in:
1 parent
800161fd6d
commit
ec86d41244
1 file changed
+16
-22
+16
-22
@@ -29,8 +29,6 @@
|
||||
export
|
||||
class XXD {
|
||||
exec() {
|
||||
const _static = new XXD.Keeps;
|
||||
|
||||
const { EOF } = XXD;
|
||||
|
||||
const { HEX_NORMAL } = XXD;
|
||||
@@ -42,10 +40,11 @@ class XXD {
|
||||
const { COLS } = XXD;
|
||||
const { LLEN } = XXD;
|
||||
|
||||
const _puts = ((...args) => (this._putOrDie(...args)));
|
||||
const _exit = ((...args) => (this._exit(...args)));
|
||||
|
||||
const $ = ((c) => (c.charCodeAt(0)));
|
||||
const $$ = ((s) => (Uint8Array.from(s, $)));
|
||||
const $puts = ((...args) => (this._putOrDie(...args)));
|
||||
const $exit = ((...args) => (this._exit(...args)));
|
||||
|
||||
const hexx = $$("0123456789abcdef0123456789ABCDEF");
|
||||
|
||||
@@ -210,28 +209,30 @@ class XXD {
|
||||
_xxdline(fpo, l, -1);
|
||||
}
|
||||
|
||||
function _xxdline(fp, l, nz, _ = _static) {
|
||||
if (!nz && _.s == 1) {
|
||||
_strcpy(_.z, l);
|
||||
function _xxdline(fp, l, nz, _static = _xxdline) {
|
||||
if (!nz && (_static .s) == 1) {
|
||||
_strcpy(_static .z, l);
|
||||
}
|
||||
|
||||
if (nz || !_.s++) {
|
||||
if (nz || !(_static .s++)) {
|
||||
if (nz) {
|
||||
if (nz < 0) _.s--;
|
||||
if (_.s == 2) $puts(_.z, fp);
|
||||
if (_.s > 2) $puts($$("*\n"), fp);
|
||||
if (nz < 0) (_static .s)--;
|
||||
if ((_static .s) == 2) _puts(_static .z, fp);
|
||||
if ((_static .s) > 2) _puts($$("*\n"), fp);
|
||||
}
|
||||
if (nz >= 0 || _.s > 0) $puts(l, fp);
|
||||
if (nz) _.s = 0;
|
||||
if (nz >= 0 || (_static .s) > 0) _puts(l, fp);
|
||||
if (nz) _static .s = 0;
|
||||
}
|
||||
}
|
||||
_static: _xxdline .s = 0; // was `zero_seen` in C
|
||||
_static: _xxdline .z = new Uint8Array(LLEN + 1);
|
||||
|
||||
function _strcpy(dest, src) {
|
||||
let stop = src.indexOf(0);
|
||||
if (stop >= 0) {
|
||||
dest.set(new Uint8Array(src.buffer, 0, stop));
|
||||
} else {
|
||||
return void $exit(XXD.IMPLEMENTATION_ERROR); // XXX
|
||||
return void _exit(XXD.IMPLEMENTATION_ERROR); // XXX
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +242,7 @@ class XXD {
|
||||
bytes.set($$(what));
|
||||
return what.length;
|
||||
}
|
||||
return void $exit(XXD.UNIMPLEMENTED); // XXX
|
||||
return void _exit(XXD.UNIMPLEMENTED); // XXX
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,13 +278,6 @@ class XXD {
|
||||
}
|
||||
}
|
||||
|
||||
XXD.Keeps = class {
|
||||
constructor() {
|
||||
this.s = 0; // was `zero_seen` in C
|
||||
this.z = new Uint8Array(XXD.LLEN + 1);
|
||||
}
|
||||
}
|
||||
|
||||
XXD.HEX_NORMAL = 0;
|
||||
XXD.HEX_POSTSCRIPT = 1;
|
||||
XXD.HEX_CINCLUDE = 2;
|
||||
|
||||
Reference in new issue
Block a user