odcey
Version:
Converter to plain text Oberon document binary format, used by the BlackBox Component Builder.
2,173 lines (1,904 loc) • 148 kB
JavaScript
#!/usr/bin/env node
var o7;
(function(o7) { "use strict";
var utf8Enc, utf8Dec, u8array, toUtf8, utf8Cache, utf8ToStr, proc;
utf8Cache = [];
o7.export = {};
o7.import = o7.export;
if (typeof process === 'undefined' || !process.exit) {
proc = {exit : function(code) { if (code != 0) throw code; }};
} else {
proc = process;
}
function assert(check, msg) {
if (check) {
;
} else if (msg) {
throw new Error(msg);
} else {
throw new Error("assertion is false");
}
}
o7.assert = assert;
function indexOut(index, array) {
return new RangeError("array index - " + index + " out of bounds - 0 .. " + (array.length - 1));
}
function array() {
var lens;
lens = arguments;
function create(li) {
var a, len, i;
len = lens[li];
a = new Array(len);
li += 1;
if (li < lens.length) {
for (i = 0; i < len; i += 1) {
a[i] = create(li);
}
}
return a;
}
return create(0);
}
o7.array = array;
function arrayOfRec() {
var lens, lim, rec;
lens = arguments;
lim = lens.length - 1;
rec = lens[lim];
function create(li) {
var a, len, i;
len = lens[li];
a = new Array(len);
li += 1;
if (li < lim) {
for (i = 0; i < len; i += 1) {
a[i] = create(li);
}
} else {
for (i = 0; i < len; i += 1) {
a[i] = new rec();
}
}
return a;
}
return create(0);
}
o7.arrayOfRec = arrayOfRec;
Array.prototype.at = function(index) {
if (0 <= index && index < this.length) {
return this[index];
} else {
throw indexOut(index, this);
}
};
Array.prototype.put = function(index, val) {
if (0 <= index && index < this.length) {
this[index] = val;
} else {
throw indexOut(index, this);
}
};
Array.prototype.inc = function(index, val) {
if (0 <= index && index < this.length) {
this[index] = add(this[index], val);
} else {
throw indexOut(index, this);
}
};
Array.prototype.incl = function(index, val) {
if (0 <= index && index < this.length) {
this[index] |= incl(val);
} else {
throw indexOut(index, this);
}
};
Array.prototype.excl = function(index, val) {
if (0 <= index && index < this.length) {
this[index] &= excl(val);
} else {
throw indexOut(index, this);
}
};
o7.at = function(array, index) {
if (0 <= index && index < array.length) {
return array[index];
} else {
throw indexOut(index, array);
}
};
o7.put = function(array, index, value) {
if (0 <= index && index < array.length) {
array[index] = value;
} else {
throw indexOut(index, array);
}
};
function ind(index, length) {
if (0 <= index && index < length) {
return value;
} else {
throw indexOut(index, length);
}
}
o7.ind = ind;
o7.caseFail = function(val) {
throw new RangeError("Unexpected value in case = " + val);
};
o7.cti = function(char) {
return char.charCodeAt(0);
};
o7.itc = function(int) {
if (0 <= int && int < 0x100) {
return int;
} else {
throw new RangeError("Char range overflow during cast from " + int);
}
};
o7.bti = function(bool) {
var i;
if (bool) {
i = 1;
} else {
i = 0;
}
return i;
};
o7.sti = function(bitset) {
if (0 <= bitset && bitset < 0x80000000) {
return bitset;
} else {
throw new RangeError("Set " + bitset + " can not be converted to integer");
}
};
o7.itb = function(int) {
if (0 <= int && int < 0x100) {
return int;
} else {
throw new RangeError("Byte range is overflowed during cast from " + int);
}
};
o7.floor = function(double) {
var v;
v = Math.floor(double);
if ((-0x80000000 < v) && (v < 0x80000000)) {
return v;
} else {
throw new RangeError("floor overflow " + v);
}
};
o7.flt = function(int) {
/* TODO */
return int;
};
o7.scalb = function(double, int) {
/* TODO */
return double * Math.pow(2, int);
};
o7.frexp = function(d, n, n_i) {
/* TODO */
var abs, exp, x;
if (d !== 0.0) {
abs = Math.abs(d);
exp = Math.max(-1023, Math.floor(Math.log(abs) * Math.LOG2E) + 1);
x = abs * Math.pow(2, -exp);
while (x < 1.0) {
x *= 2.0;
exp -= 1;
}
while (x >= 2.0) {
x /= 2.0;
exp += 1;
}
if (d < 0.0) {
x = -x;
}
n[n_i] = exp;
} else {
x = 0.0;
n[n_i] = 0.0;
}
return x;
}
o7.in = function(n, st) {
assert((0 <= n) && (n <= 31));
return 0 != (st & (1 << n));
};
if (typeof Uint8Array !== 'undefined') {
Uint8Array.prototype.at = Array.prototype.at;
Uint8Array.prototype.put = Array.prototype.put;
u8array = function(array) {
return new Uint8Array(array);
}
} else {
u8array = function(array) {
return array;
};
}
function arrayUtf8ToStr(bytes) {
var str, buf, i, len, ch, ch1, ch2, ch3, ok;
buf = [];
len = bytes.length;
i = 0;
ok = true;
while (i < len && bytes[i] != 0) {
ch = bytes[i];
i += 1;
if (ch < 0x80) {
buf.push(String.fromCharCode(ch));
} else if (ch < 0xC0) {
ok = false;
} else if (ch < 0xE0) {
if (i < len) {
ch1 = bytes[i];
i += 1;
if ((ch1 >> 6) == 2) {
buf.push(String.fromCharCode(((ch & 0x1F) << 6) | (ch1 & 0x3F)));
} else {
ok = false;
}
} else {
ok = false;
}
} else if (ch < 0xF0) {
if (i + 1 < len) {
ch1 = bytes[i];
ch2 = bytes[i + 1];
i += 2;
if (((ch1 >> 6) == 2) && ((ch2 >> 6) == 2)) {
buf.push(String.fromCharCode(((ch & 0xF) << 12) | ((ch1 & 0x3F) << 6) | (ch2 & 0x3F)));
} else {
ok = false;
}
} else {
ok = false;
}
} else {
if (i + 2 < len) {
ch1 = bytes[i];
ch2 = bytes[i + 1];
ch3 = bytes[i + 2];
i += 3;
if (((ch1 >> 6) == 2) && ((ch2 >> 6) == 2) && ((ch3 >> 6) == 2)) {
buf.push(String.fromCodePoint(((ch & 0x7) << 18) | ((ch1 & 0x3F) << 12) | ((ch2 & 0x3F) << 6) | (ch3 & 0x3F)));
} else {
ok = false;
}
} else {
ok = false;
}
}
}
if (ok) {
str = buf.join('');
} else {
str = null;
}
return str;
};
if (typeof TextDecoder !== 'undefined') {
utf8Enc = new TextEncoder('utf-8');
utf8Dec = new TextDecoder('utf-8');
if (utf8Enc.encode("!").push) {
toUtf8 = function(str) {
var a;
a = utf8Enc.encode(str);
a.push(0);
return u8array(a);
};
} else {
toUtf8 = function(str) {
var a, b;
a = utf8Enc.encode(str);
b = new Uint8Array(a.length + 1);
b.set(a, 0);
b[a.length] = 0;
return u8array(b);
};
}
utf8ToStr = function(bytes) {
var str;
if (bytes instanceof Uint8Array) {
str = utf8Dec.decode(bytes);
} else {
str = arrayUtf8ToStr(bytes);
}
return str;
};
} else {
/* str must be correct utf16 string */
toUtf8 = function(str) {
var bytes, si, ch, len;
bytes = [];
si = 0;
len = str.length;
while (si < len) {
ch = str.charCodeAt(si);
if (ch < 0x80) {
bytes.push(ch);
} else if (ch < 0x800) {
bytes.push((ch >> 6) | 0xC0,
(ch & 0x3F) | 0x80);
} else if ((ch & 0xFC00) == 0xD800) {
si += 1;
ch = 0x10000 | ((ch & 0x3FF) << 10) | (str.charCodeAt(si) & 0x3FF);
bytes.push((ch >> 18) | 0xF0,
((ch >> 12) & 0x3F) | 0x80,
((ch >> 6 ) & 0x3F) | 0x80,
(ch & 0x3F) | 0x80);
} else {
bytes.push((ch >> 12) | 0xE0,
((ch >> 6) & 0x3F) | 0x80,
(ch & 0x3F) | 0x80);
}
si += 1;
}
bytes.push(0x0);
return u8array(bytes);
};
utf8ToStr = arrayUtf8ToStr;
}
o7.utf8ToStr = utf8ToStr;
o7.toUtf8 = function(str) {
var utf;
utf = utf8Cache[str];
if (!utf) {
utf = toUtf8(str);
utf8Cache[str] = utf;
}
return utf;
};
o7.utf8ByOfsToStr = function(bytes, ofs) {
if (ofs > 0) {
bytes = bytes.slice(ofs);
}
return utf8ToStr(bytes);
}
/* str must be correct 7bit ASCII string */
o7.toAscii = function(str) {
var bytes, len, i;
len = str.length;
bytes = new Uint8Array(len);
for (i = 0; i < len; i += 1) {
/* assert str.charCodeAt(i) < 0x80 */
bytes[i] = str.charCodeAt(i);
}
return bytes;
};
o7.extend = function(ext, base) {
function proto() {}
proto.prototype = base.prototype;
ext.prototype = new proto();
ext.base = base;
return ext;
};
function add(a, b) {
var r;
r = a + b;
if (-0x80000000 < r && r < 0x80000000) {
return r;
} else {
throw new RangeError("integer overflow in " + a + " + " + b + " = " + r);
}
}
o7.add = add;
o7.sub = function(a, b) {
var r;
r = a - b;
if (-0x80000000 < r && r < 0x80000000) {
return r;
} else {
throw new RangeError("integer overflow in " + a + " - " + b + " = " + r);
}
};
o7.mul = function(a, b) {
var r;
r = a * b;
if (-0x80000000 < r && r < 0x80000000) {
return r;
} else {
throw new RangeError("integer overflow in " + a + " * " + b + " = " + r);
}
};
o7.div = function(a, b) {
var mask;
if (b > 0) {
mask = a >> 31;
return mask ^ ((mask ^ a) / b);
} else {
throw new RangeError("Integer divider can't be < 1");
}
};
o7.mod = function(a, b) {
var mask;
if (b > 0) {
mask = a >> 31;
return (b & mask) + (mask ^ ((mask ^ a) % b));
} else {
throw new RangeError("Integer divider can't be < 1");
}
};
function fadd(a, b) {
var s;
s = a + b;
if (isFinite(s)) {
return s;
} else {
/* TODO */
throw new RangeError("Fraction out of range in " + a + " + " + b + " = " + s);
}
}
o7.fadd = fadd;
function fsub(a, b) {
var s;
s = a - b;
if (isFinite(s)) {
return s;
} else {
/* TODO */
throw new RangeError("Fraction out of range in " + a + " - " + b + " = " + s);
}
}
o7.fsub = fsub;
function fmul(a, b) {
var s;
s = a * b;
if (isFinite(s)) {
return s;
} else {
/* TODO */
throw new RangeError("Fraction out of range in " + a + " * " + b + " = " + s);
}
}
o7.fmul = fmul;
function fdiv(a, b) {
var s;
s = a / b;
if (isFinite(s)) {
return s;
} else {
/* TODO */
throw new RangeError("Fraction out of range in " + a + " / " + b + " = " + s);
}
}
o7.fdiv = fdiv;
o7.set = function(low, high) {
if (high > 31) {
throw new RangeError("high limit = " + high + " > 31");
} else if (high < 0) {
throw new RangeError("high limit = " + high + " < 0");
} else if (low > 31) {
throw new RangeError("low limit = " + low + " > 31");
} else if (low < 0) {
throw new RangeError("low limit = " + low + " < 0");
} else {
return (~0 << low) & (~0 >>> (31 - high));
}
};
function setRangeError(val) {
return new RangeError("set item = " + val + " out of range 0 .. 31");
}
function incl(val) {
if (0 <= val && val <= 31) {
return 1 << val;
} else {
throw setRangeError(val);
}
}
o7.incl = incl;
function excl(val) {
if (0 <= val && val <= 31) {
return ~(1 << val);
} else {
throw setRangeError(val);
}
}
o7.excl = excl;
o7.ror = function(n, shift) {
assert(n >= 0);
assert(shift >= 0);
shift &= 31;
n = (n >>> shift) | (n << (32 - shift));
assert(n >= 0);
return n;
}
o7.asr = function(n, shift) {
if (shift >= 31) { shift = 31; }
else { assert(shift >= 0); }
return n >> shift;
}
function inited(val) {
if (isFinite(val)) {
return val;
} else {
throw new RangeError("Uninitialized variable");
}
}
o7.inited = inited;
o7.cmp = function(a, b) {
var d;
d = a - b;
if (isFinite(d)) {
;
} else if (a < b) {
d = -1;
} else {
inited(d);
}
return d;
}
o7.strcmp = function(s1, s2) {
var i;
i = 0;
while ((s1[i] == s2[i]) && (s1[i] != 0)) {
i += 1;
}
return inited(s1[i] - s2[i]);
};
function strchcmp(s1, c2) {
var c1, ret;
c1 = s1[0];
ret = c1 - c2;
if (ret != 0) {
inited(ret);
} else if (c1 != 0 && s1[1] != 0) {
ret = inited(s1[1]);
}
return ret;
}
o7.strchcmp = strchcmp;
o7.chstrcmp = function(c1, s2) {
return -strchcmp(s2, c1);
};
/* Copy chars */
o7.strcpy = function(d, s) {
var len, i;
len = s.length;
assert(d.length >= len);
for (i = 0; i < len; i += 1) {
d[i] = s[i];
}
assert(d[len - 1] == 0);
};
o7.memcpy = function(d, di, s, si, len) {
var lim;
lim = di + len;
assert(d.length >= lim);
while (di < lim) {
d[di] = s[si];
di += 1; si += 1;
}
};
function copy(d, s) {
var i, len;
len = s.length;
assert(d.length >= len);
if (Array.isArray(s[0])) {
for (i = 0; i < len; i += 1) {
copy(d[i], s[i]);
}
} else {
for (i = 0; i < len; i += 1) {
d[i] = s[i];
}
}
}
o7.copy = copy;
function copyAor(d, s) {
var i, len;
len = s.length;
assert(d.length >= len);
if (Array.isArray(s[0])) {
for (i = 0; i < len; i += 1) {
copyAor(d[i], s[i]);
}
} else {
for (i = 0; i < len; i += 1) {
d[i].assign(s[i]);
}
}
}
o7.copyAor = copyAor;
o7.exit_code = 0;
o7.main = function(main) {
main();
if (o7.exit_code != 0) {
proc.exit(o7.exit_code);
}
};
}) (o7 || (o7 = {}));
/* Generated by Vostok - Oberon-07 translator */
/* Base extensible records
* Copyright (C) 2016 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*)
(* база всего сущего, авось пригодится для чего-нибудь эдакого */
(function() { 'use strict';
var module = {};
o7.export.V = module;
function Message() {}
Message.prototype.assign = function(r) {
}
module.Message = Message;
module.Message = Message;
function Base() {
Message.call(this);
this.do_ = undefined;
}
o7.extend(Base, Message);
Base.prototype.assign = function(r) {
this.do_ = r.do_;
}
module.Base = Base;
module.Base = Base;
function Error() {
Base.call(this);
}
o7.extend(Error, Base);
Error.prototype.assign = function(r) {
Base.prototype.assign.call(this, r);
}
module.Error = Error;
module.Error = Error;
function MsgFinalize() {
Base.call(this);
}
o7.extend(MsgFinalize, Base);
MsgFinalize.prototype.assign = function(r) {
Base.prototype.assign.call(this, r);
}
module.MsgFinalize = MsgFinalize;
module.MsgFinalize = MsgFinalize;
function MsgNeedMemory() {
Base.call(this);
}
o7.extend(MsgNeedMemory, Base);
MsgNeedMemory.prototype.assign = function(r) {
Base.prototype.assign.call(this, r);
}
module.MsgNeedMemory = MsgNeedMemory;
module.MsgNeedMemory = MsgNeedMemory;
function MsgCopy() {
Base.call(this);
this.copy = undefined;
}
o7.extend(MsgCopy, Base);
MsgCopy.prototype.assign = function(r) {
Base.prototype.assign.call(this, r);
this.copy = r.copy;
}
module.MsgCopy = MsgCopy;
module.MsgCopy = MsgCopy;
function MsgLinks() {
Base.call(this);
this.diff = NaN;
this.count = NaN;
}
o7.extend(MsgLinks, Base);
MsgLinks.prototype.assign = function(r) {
Base.prototype.assign.call(this, r);
this.diff = r.diff;
this.count = r.count;
}
module.MsgLinks = MsgLinks;
module.MsgLinks = MsgLinks;
function MsgHash() {
Base.call(this);
this.hash = NaN;
}
o7.extend(MsgHash, Base);
MsgHash.prototype.assign = function(r) {
Base.prototype.assign.call(this, r);
this.hash = r.hash;
}
module.MsgHash = MsgHash;
module.MsgHash = MsgHash;
function Nothing(this_, mes) {
return false;
}
function Init(base) {
base.do_ = Nothing;
}
module.Init = Init;
function SetDo(base, do_) {
var nothing;
nothing = Nothing;
o7.assert(base.do_ == nothing);
base.do_ = do_;
}
module.SetDo = SetDo;
function Do(handler, message) {
return handler.do_(handler, message);
}
module.Do = Do;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
/* Abstract interfaces for data input and output
*
* Copyright (C) 2016-2019,2022-2023 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var V = o7.import.V;
var module = {};
o7.export.VDataStream = module;
function Stream() {
V.Base.call(this);
this.close = undefined;
}
o7.extend(Stream, V.Base);
Stream.prototype.assign = function(r) {
V.Base.prototype.assign.call(this, r);
this.close = r.close;
}
module.Stream = Stream;
module.Stream = Stream;
function In() {
Stream.call(this);
this.read = undefined;
this.readChars = undefined;
}
o7.extend(In, Stream);
In.prototype.assign = function(r) {
Stream.prototype.assign.call(this, r);
this.read = r.read;
this.readChars = r.readChars;
}
module.In = In;
module.In = In;
function InOpener() {
V.Base.call(this);
this.open = undefined;
}
o7.extend(InOpener, V.Base);
InOpener.prototype.assign = function(r) {
V.Base.prototype.assign.call(this, r);
this.open = r.open;
}
module.InOpener = InOpener;
module.InOpener = InOpener;
function Out() {
Stream.call(this);
this.write = undefined;
this.writeChars = undefined;
}
o7.extend(Out, Stream);
Out.prototype.assign = function(r) {
Stream.prototype.assign.call(this, r);
this.write = r.write;
this.writeChars = r.writeChars;
}
module.Out = Out;
module.Out = Out;
function OutOpener() {
V.Base.call(this);
this.open = undefined;
}
o7.extend(OutOpener, V.Base);
OutOpener.prototype.assign = function(r) {
V.Base.prototype.assign.call(this, r);
this.open = r.open;
}
module.OutOpener = OutOpener;
module.OutOpener = OutOpener;
function EmptyClose(stream) {
o7.assert(stream instanceof Stream);
}
function Init(stream, close) {
V.Init(stream);
if (close == null) {
stream.close = EmptyClose;
} else {
stream.close = close;
}
}
function Close(stream) {
if (stream != null) {
stream.close(stream);
}
}
module.Close = Close;
function InitIn(in_, read, readChars, close) {
o7.assert((read != null) || (readChars != null));
Init(in_, close);
in_.read = read;
in_.readChars = readChars;
}
module.InitIn = InitIn;
function CloseIn(in_, in__ai) {
if (in_.at(in__ai) != null) {
in_.at(in__ai).close(in_.at(in__ai));
in_.put(in__ai, null);
}
}
module.CloseIn = CloseIn;
function Read(in_, buf, ofs, count) {
var r;
o7.assert((0 <= ofs) && (0 <= count) && (ofs <= o7.sub(buf.length, count)));
r = in_.read(in_, buf, ofs, count);
o7.assert((0 <= r) && (r <= count));
return r;
}
module.Read = Read;
function ReadWhole(in_, buf) {
return Read(in_, buf, 0, buf.length);
}
module.ReadWhole = ReadWhole;
function ReadChars(in_, buf, ofs, count) {
var r;
o7.assert((0 <= ofs) && (0 <= count) && (ofs <= o7.sub(buf.length, count)));
r = in_.readChars(in_, buf, ofs, count);
o7.assert((0 <= r) && (r <= count));
return r;
}
module.ReadChars = ReadChars;
function ReadCharsWhole(in_, buf) {
return ReadChars(in_, buf, 0, buf.length);
}
module.ReadCharsWhole = ReadCharsWhole;
function Skip(in_, count) {
function ByRead(in_, count) {
var buf = o7.array(4096);
var r;
var read;
read = in_.read;
r = 4096;
while ((count >= 4096) && (r == 4096)) {
r = read(in_, buf, 0, 4096);
count = o7.sub(count, r);
}
o7.assert((0 <= r) && (r <= 4096));
if (count > 0) {
r = read(in_, buf, 0, count);
o7.assert((0 <= r) && (r <= count));
count = o7.sub(count, r);
}
return count;
}
o7.assert(count >= 0);
return o7.sub(count, ByRead(in_, count));
}
module.Skip = Skip;
function InitOut(out, write, writeChars, close) {
o7.assert((write != null) || (writeChars != null));
Init(out, close);
out.write = write;
out.writeChars = writeChars;
}
module.InitOut = InitOut;
function CloseOut(out, out__ai) {
if (out.at(out__ai) != null) {
out.at(out__ai).close(out.at(out__ai));
out.put(out__ai, null);
}
}
module.CloseOut = CloseOut;
function Write(out, buf, ofs, count) {
var w;
o7.assert((0 <= ofs) && (0 <= count) && (ofs <= o7.sub(buf.length, count)));
w = out.write(out, buf, ofs, count);
o7.assert((0 <= w) && (w <= count));
return w;
}
module.Write = Write;
function WriteChars(out, buf, ofs, count) {
var w;
o7.assert((0 <= ofs) && (0 <= count) && (ofs <= o7.sub(buf.length, count)));
w = out.writeChars(out, buf, ofs, count);
o7.assert((0 <= w) && (w <= count));
return w;
}
module.WriteChars = WriteChars;
function WriteCharsWhole(out, buf) {
return WriteChars(out, buf, 0, buf.length);
}
module.WriteCharsWhole = WriteCharsWhole;
function InitInOpener(opener, open) {
o7.assert(open != null);
V.Init(opener);
opener.open = open;
}
module.InitInOpener = InitInOpener;
function InitOutOpener(opener, open) {
o7.assert(open != null);
V.Init(opener);
opener.open = open;
}
module.InitOutOpener = InitOutOpener;
/* TODO проработать ошибки операций */
function OpenIn(opener) {
return opener.open(opener);
}
module.OpenIn = OpenIn;
function OpenOut(opener) {
return opener.open(opener);
}
module.OpenOut = OpenOut;
return module;
})();
/* Copyright 2019-2021,2023 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var module = {};
o7.export.CFiles = module;
var getjsa, utf8ByOfsToStr, fs, proc;
var KiB = 1024;
module.KiB = KiB;
var MiB = 1024 * KiB;
module.MiB = MiB;
var GiB = 1024 * MiB;
module.GiB = GiB;
function File() {}
File.prototype.assign = function(r) {}
utf8ByOfsToStr = o7.utf8ByOfsToStr;
if (typeof require !== 'undefined' && typeof process !== 'undefined') {
fs = require('fs');
} else {
fs = null;
}
function wrapFile1(file) {
var f;
f = new File();
f.fd = file.fd;
f.notsync = true;
return f;
}
/* TODO сохранение буфера до Сlose */
function bufGet(size) {
var data;
if (Buffer.allocUnsafe) {
data = Buffer.allocUnsafe(size);
} else {
data = new Buffer(size);
}
return data;
}
function wrapFile2(file) {
var f;
f = new File();
f.f = file;
return f;
}
if (fs != null) {
module.in_ = wrapFile1(process.stdin);
module.out = wrapFile1(process.stdout);
module.err = wrapFile1(process.stderr);
module.Open = function(bytes_name, ofs, mode) {
var f, name, fd, smode, i;
f = null;
name = utf8ByOfsToStr(bytes_name, ofs);
if (name != null) {
smode = "r";
for (i = 0; i < mode.length; i += 1) {
if (mode[i] == 'w'.charCodeAt(0)) {
smode = "w+";
}
}
try {
fd = fs.openSync(name, smode, 6 * 64 + 6 * 8 + 6);
} catch (exc) {
fd = -1;
}
if (fd != -1) {
f = new File();
f.fd = fd;
}
}
return f;
}
module.Close = function(file, file_ai) {
if (file[file_ai]) {
fs.closeSync(file[file_ai].fd);
file[file_ai] = null;
}
}
module.Read = function(file, buf, ofs, count) {
var data, read, i;
if (typeof buf !== 'Uint8Array') {
data = bufGet(count);
read = fs.readSync(file.fd, data, 0, count, null);
for (i = 0; i < read; i += 1) {
buf[i + ofs] = data[i];
}
} else {
read = fs.readSync(file.fd, buf, ofs, count, null);
}
return read;
}
module.Write = function(file, buf, ofs, count) {
var data, write, i;
if (typeof buf !== 'Uint8Array') {
data = bufGet(count);
for (i = 0; i < count; i += 1) {
data[i] = buf[i + ofs];
}
write = fs.writeSync(file.fd, data, 0, count);
} else {
write = fs.writeSync(file.fd, buf, ofs, count);
}
return write;
}
module.Flush = function(file) {
return file.notsync || 0 === fs.fdatasyncSync(file.fd);
}
module.Remove = function(name, ofs) {
var str;
str = utf8ByOfsToStr(name, ofs);
if (str != null) {
fs.unlinkSync(str);
}
/* TODO недостаточное условие */
return str != null;
}
module.Exist = function(name, ofs) {
var str;
str = utf8ByOfsToStr(name, ofs);
return str != null && fs.existsSync(str);
}
module.Rename = function(src, sofs, dest, dofs) {
var s, d;
s = utf8ByOfsToStr(src, sofs);
d = utf8ByOfsToStr(dest, dofs);
fs.renameSync(s, d);
/* TODO */
return true;
}
} else if (typeof std !== 'undefined') {
module.in_ = wrapFile2(std.in);
module.out = wrapFile2(std.out);
module.err = wrapFile2(std.err);
module.Open = function(bytes_name, ofs, mode) {
var f, name, file, smode;
f = null;
name = utf8ByOfsToStr(bytes_name, ofs);
smode = utf8ByOfsToStr(mode, 0);
if (name != null && smode != null) {
file = std.open(name, smode);
if (file != null) {
f = new File();
f.f = file;
}
}
return f;
}
module.Close = function(file, file_ai) {
if (file[file_ai]) {
file[file_ai].f.close();
file[file_ai] = null;
}
}
module.Read = function(file, buf, ofs, count) {
var data, read, i;
data = new ArrayBuffer(count);
read = file.f.read(data, 0, count);
if (read > 0) {
data = new Uint8Array(data);
for (i = 0; i < read; i += 1) {
buf[i + ofs] = data[i];
}
}
return read;
}
module.Write = function(file, buf, ofs, count) {
var ab, data, i;
ab = new ArrayBuffer(count);
data = new Uint8Array(ab);
for (i = 0; i < count; i += 1) {
data[i] = buf[i + ofs];
}
return file.f.write(ab, 0, count);
}
module.Flush = function(file) { return file.flush() == 0; }
module.Remove = function(name, ofs) {
var str;
str = utf8ByOfsToStr(name, ofs);
return (str != null) && (os.remove(str) == 0);
}
module.Exist = function(name, ofs) {
var name, f;
name = utf8ByOfsToStr(name, ofs);
f = null;
if (name != null) {
f = std.open(name, "rb");
if (f != null) {
f.close();
}
}
return f != null;
}
module.Seek = function(file, gibs, bytes) {
o7.assert(gibs >= 0);
o7.assert(bytes >= 0 && bytes <= GiB);
return 0 == file.seek(BigInt(gibs) * BigInt(GiB) + BigInt(bytes), std.SEEK_SET);
}
module.Tell = function(file, gibs, gibs_ai, bytes, bytes_ai) {
var pos, ok;
pos = file.tello();
ok = pos >= BigInt(0);
if (ok) {
gibs[gibs_ai] = Number(pos / BigInt(GiB));
bytes[bytes_ai] = Number(pos % BigInt(GiB));
}
return ok;
}
module.Rename = function(src, sofs, dest, dofs) {
var s, d;
s = utf8ByOfsToStr(src, sofs);
d = utf8ByOfsToStr(dest, dofs);
return 0 == os.rename(s, d);
}
} else {
module.in_ = new File();
module.out = new File();
module.err = new File();
module.Open = function(bytes_name, ofs, mode) { return null; }
module.Close = function(file, file_ai) {}
module.Read = function(file, buf, ofs, count) { return 0; }
module.Write = function(file, buf, ofs, count) { return 0; }
module.Flush = function(file) { return false; }
module.Remove = function(name, ofs) { return false; }
module.Exist = function(name, ofs) { return false; }
module.Rename = function(src, sofs, dest, dofs) { return false; }
}
module.ReadChars = function(file, buf, ofs, count) {
return module.Read(file, buf, ofs, count);
}
module.WriteChars = function(file, buf, ofs, count) {
return module.Write(file, buf, ofs, count);
}
if (!module.Seek) {
module.Seek = function(file, gibs, bytes) { return false; };
module.Tell = function(file, gibs, gibs_ai, bytes, bytes_ai) { return false; };
}
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
/* Implementations of Data Stream interfaces by CFiles
*
* Copyright (C) 2016,2019,2021-2022 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var V = o7.import.V;
var Stream = o7.import.VDataStream;
var CFiles = o7.import.CFiles;
var module = {};
o7.export.VFileStream = module;
function RIn() {
Stream.In.call(this);
this.file = o7.array(1);
}
o7.extend(RIn, Stream.In);
RIn.prototype.assign = function(r) {
Stream.In.prototype.assign.call(this, r);
o7.copy(this.file, r.file);
}
module.RIn = RIn;
function ROut() {
Stream.Out.call(this);
this.file = o7.array(1);
}
o7.extend(ROut, Stream.Out);
ROut.prototype.assign = function(r) {
Stream.Out.prototype.assign.call(this, r);
o7.copy(this.file, r.file);
}
module.ROut = ROut;
var out = undefined;
module.out = out;
var in_ = undefined;
module.in_ = in_;
function Read(i, buf, ofs, count) {
return CFiles.Read(i.file[0], buf, ofs, count);
}
function ReadChars(i, buf, ofs, count) {
return CFiles.ReadChars(i.file[0], buf, ofs, count);
}
function CloseRIn(i) {
CFiles.Close(i.file, 0);
}
function OpenIn(name) {
var i;
var file;
i = new RIn();
if (i != null) {
file = CFiles.Open(name, 0, [114,98,0]);
if (file == null) {
i = null;
} else {
Stream.InitIn(i, Read, ReadChars, CloseRIn);
i.file[0] = file;
}
}
return i;
}
module.OpenIn = OpenIn;
function CloseIn(i, i__ai) {
if (i.at(i__ai) != null) {
if (i.at(i__ai) != module.in_) {
CFiles.Close(i.at(i__ai).file, 0);
}
i.put(i__ai, null);
}
}
module.CloseIn = CloseIn;
function Write(o, buf, ofs, count) {
return CFiles.Write(o.file[0], buf, ofs, count);
}
function WriteChars(o, buf, ofs, count) {
return CFiles.WriteChars(o.file[0], buf, ofs, count);
}
function CloseROut(o) {
CFiles.Close(o.file, 0);
}
function OpenOutFile(name, attr) {
var o;
var file;
o = new ROut();
if (o != null) {
file = CFiles.Open(name, 0, attr);
if (file == null) {
o = null;
} else {
Stream.InitOut(o, Write, WriteChars, CloseROut);
o.file[0] = file;
}
}
return o;
}
function OpenOut(name) {
return OpenOutFile(name, [119,98,0]);
}
module.OpenOut = OpenOut;
function OpenForAppend(name) {
return OpenOutFile(name, [97,98,0]);
}
module.OpenForAppend = OpenForAppend;
function CloseOut(o, o__ai) {
if (o.at(o__ai) != null) {
if (o.at(o__ai) != module.out) {
CFiles.Close(o.at(o__ai).file, 0);
}
o.put(o__ai, null);
}
}
module.CloseOut = CloseOut;
function WrapOut() {
module.out = new ROut();
if (module.out != null) {
Stream.InitOut(module.out, Write, WriteChars, null);
module.out.file[0] = CFiles.out;
}
}
function WrapIn() {
module.in_ = new RIn();
if (module.in_ != null) {
Stream.InitIn(module.in_, Read, ReadChars, null);
module.in_.file[0] = CFiles.in_;
}
}
WrapOut();
WrapIn();
return module;
})();
/* Copyright 2019,2021-2022,2024 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var nos, platform;
var module = {};
o7.export.Platform = module;
if (typeof require !== 'undefined') {
nos = require("os");
if (nos) {
platform = nos.platform();
nos = undefined;
}
} else if (typeof os !== 'undefined') {
platform = os.platform;
}
module.Linux = platform == 'linux' || platform == 'android';
module.Bsd = platform == 'openbsd' || platform == 'freebsd';
module.Dos = false;
module.Windows = platform == 'win32';
module.Darwin = platform == 'darwin';
module.Posix = module.Linux || module.Bsd || module.Darwin || platform == 'sunos';
module.Wasm = false;
module.Wasi = false;
module.C = false;
module.Java = false;
module.JavaScript = true;
module.LittleEndian = 1;
module.BigEndian = 2;
module.ByteOrder = 1;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
(function() { 'use strict';
var module = {};
o7.export.Windows = module;
var Cp866 = 866;
module.Cp866 = Cp866;
var Cp1251 = 1251;
module.Cp1251 = Cp1251;
var Utf8 = 65001;
module.Utf8 = Utf8;
/* Неполный список MS-LSID */
var LangNeutral = 0;
module.LangNeutral = LangNeutral;
var Arabic = 1;
module.Arabic = Arabic;
var Bulgarian = 2;
module.Bulgarian = Bulgarian;
var Catalan = 3;
module.Catalan = Catalan;
var Chinese = 4;
module.Chinese = Chinese;
var Czech = 5;
module.Czech = Czech;
var Danish = 6;
module.Danish = Danish;
var Geramn = 7;
module.Geramn = Geramn;
var Greek = 8;
module.Greek = Greek;
var English = 9;
module.English = English;
var Spanish = 10;
module.Spanish = Spanish;
var Finnish = 11;
module.Finnish = Finnish;
var French = 12;
module.French = French;
var Hebrew = 13;
module.Hebrew = Hebrew;
var Hungarian = 14;
module.Hungarian = Hungarian;
var Icelandic = 15;
module.Icelandic = Icelandic;
var Italian = 16;
module.Italian = Italian;
var Japanese = 17;
module.Japanese = Japanese;
var Korean = 18;
module.Korean = Korean;
var Dutch = 19;
module.Dutch = Dutch;
var Norwegian = 20;
module.Norwegian = Norwegian;
var Polish = 21;
module.Polish = Polish;
var Portuguese = 22;
module.Portuguese = Portuguese;
var Romansh = 23;
module.Romansh = Romansh;
var Romanian = 24;
module.Romanian = Romanian;
var Russian = 25;
module.Russian = Russian;
var Croatian = 26;
module.Croatian = Croatian;
var Slovak = 27;
module.Slovak = Slovak;
var Albanian = 28;
module.Albanian = Albanian;
var Swedish = 29;
module.Swedish = Swedish;
var Thai = 30;
module.Thai = Thai;
var Turkish = 31;
module.Turkish = Turkish;
var Urdu = 32;
module.Urdu = Urdu;
var Indonesian = 33;
module.Indonesian = Indonesian;
var Ukrainian = 34;
module.Ukrainian = Ukrainian;
var Belarusian = 35;
module.Belarusian = Belarusian;
var Slovenian = 36;
module.Slovenian = Slovenian;
var Estonian = 37;
module.Estonian = Estonian;
var Latvian = 38;
module.Latvian = Latvian;
var Lithuanian = 39;
module.Lithuanian = Lithuanian;
var Tajik = 40;
module.Tajik = Tajik;
var Farsi = 41;
module.Farsi = Farsi;
var Vietnamese = 42;
module.Vietnamese = Vietnamese;
var Armenian = 43;
module.Armenian = Armenian;
var Azeri = 44;
module.Azeri = Azeri;
var Basque = 45;
module.Basque = Basque;
/* TODO more*/
var Macedonian = 47;
module.Macedonian = Macedonian;
var Afrikaans = 48;
module.Afrikaans = Afrikaans;
var Georgian = 55;
module.Georgian = Georgian;
var Faeroese = 56;
module.Faeroese = Faeroese;
var Hindi = 57;
module.Hindi = Hindi;
var Kazakh = 63;
module.Kazakh = Kazakh;
var Kyrgyz = 64;
module.Kyrgyz = Kyrgyz;
var Uzbek = 67;
module.Uzbek = Uzbek;
var Tatar = 68;
module.Tatar = Tatar;
/* Возвращает MS-LCID */
function GetUserDefaultUILanguage() {
return LangNeutral;
}
module.GetUserDefaultUILanguage = GetUserDefaultUILanguage;
function SetConsoleCP(code) {
return false;
}
module.SetConsoleCP = SetConsoleCP;
function SetConsoleOutputCP(code) {
return false;
}
module.SetConsoleOutputCP = SetConsoleOutputCP;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
/* Default input and output
*
* Copyright (C) 2019,2021-2022 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var Stream = o7.import.VDataStream;
var Files = o7.import.VFileStream;
var Platform = o7.import.Platform;
var Windows = o7.import.Windows;
var module = {};
o7.export.VDefaultIO = module;
var in_ = undefined;
var out = undefined;
function OpenIn() {
var s;
var ignore;
if (in_ == null) {
s = Files.in_;
ignore = Platform.Windows && Windows.SetConsoleCP(Windows.Utf8);
} else {
s = Stream.OpenIn(in_);
}
return s;
}
module.OpenIn = OpenIn;
function OpenOut() {
var s;
var ignore;
if (out == null) {
s = Files.out;
ignore = Platform.Windows && Windows.SetConsoleOutputCP(Windows.Utf8);
} else {
s = Stream.OpenOut(out);
}
return s;
}
module.OpenOut = OpenOut;
function SetIn(s) {
in_ = s;
}
module.SetIn = SetIn;
function SetOut(s) {
out = s;
}
module.SetOut = SetOut;
in_ = null;
out = null;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
/* Copyright 2016-2018 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*)
(* Oberon-07 types limits / Численные границы стандартных типов Oberon-07 */
(function() { 'use strict';
var module = {};
o7.export.TypesLimits = module;
var IntegerMax = 2147483647;
module.IntegerMax = IntegerMax;
/* минимальное значение в дополнительном коде (-1 - IntegerMax) не входит
в основной диапазон для упрощения работы с целыми числами без
необходимости учёта особого отрицательного значения, а также для
использования в качестве недопустимого значения */
var IntegerMin = - IntegerMax;
module.IntegerMin = IntegerMin;
var CharMax = 0xFF;
module.CharMax = CharMax;
var ByteMax = 255;
module.ByteMax = ByteMax;
var SetMax = 31;
module.SetMax = SetMax;
function InByteRange(v) {
return (0 <= v) && (v <= ByteMax);
}
module.InByteRange = InByteRange;
function InCharRange(v) {
return (0 <= v) && (v <= 0xFF);
}
module.InCharRange = InCharRange;
function InSetRange(v) {
return (0 <= v) && (v <= SetMax);
}
module.InSetRange = InSetRange;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
/* Some constants and subroutines for Utf-8/ASC II
*
* Copyright (C) 2016,2020-2023 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var TypesLimits = o7.import.TypesLimits;
var module = {};
o7.export.Utf8 = module;
var Null = 0x00;
module.Null = Null;
var TransmissionEnd = 0x04;
module.TransmissionEnd = TransmissionEnd;
var Bell = 0x07;
module.Bell = Bell;
var BackSpace = 0x08;
module.BackSpace = BackSpace;
var Tab = 0x09;
module.Tab = Tab;
var NewLine = 0x0A;
module.NewLine = NewLine;
var NewPage = 0x0C;
module.NewPage = NewPage;
var CarRet = 0x0D;
module.CarRet = CarRet;
var Idle = 0x16;
module.Idle = Idle;
var Space = 0x20;
module.Space = Space;
var DQuote = 0x22;
module.DQuote = DQuote;
var Delete = 0x7F;
module.Delete = Delete;
function R() {
this.val = o7.array(1);
this.len = NaN;
}
R.prototype.assign = function(r) {
o7.copy(this.val, r.val);
this.len = r.len;
}
module.R = R;
module.R = R;
function Up(ch) {
if (((0xFF & 0x61) <= (0xFF & ch)) && ((0xFF & ch) <= (0xFF & 0x7A))) {
ch = o7.itc(o7.sub(ch, (0x61 - 0x41)));
}
return ch;
}
module.Up = Up;
function Down(ch) {
if (((0xFF & 0x41) <= (0xFF & ch)) && ((0xFF & ch) <= (0xFF & 0x5A))) {
ch = o7.itc(o7.add(ch, (0x61 - 0x41)));
}
return ch;
}
module.Down = Down;
function EqualIgnoreCase(a, b) {
var equal;
if (a == b) {
equal = true;
} else if (((0xFF & 0x61) <= (0xFF & a)) && ((0xFF & a) <= (0xFF & 0x7A))) {
equal = 0x61 - 0x41 == o7.sub(a, b);
} else if (((0xFF & 0x41) <= (0xFF & a)) && ((0xFF & a) <= (0xFF & 0x5A))) {
equal = 0x61 - 0x41 == o7.sub(b, a);
} else {
equal = false;
}
return equal;
}
module.EqualIgnoreCase = EqualIgnoreCase;
function DecodeFirst(first, rest, rest__ai) {
var v;
var b;
var l;
v = first;
if (v < 128) {
l = 1;
rest.put(rest__ai, v);
} else if (v >= 192) {
v = o7.sub(v, 192);
l = 2;
b = 32;
while (v > b) {
v = o7.sub(v, b);
l = o7.add(l, 1);
b = o7.div(b, 2);
}
if (v == b) {
l = o7.add(l, 1);
v = o7.sub(v, b);
}
rest.put(rest__ai, v);
} else {
l = 0;
rest.put(rest__ai, - 1);
}
return l;
}
function Len(first) {
var rest = o7.array(1);
return DecodeFirst(first, rest, 0);
}
module.Len = Len;
function Begin(state, first) {
state.len = o7.sub(DecodeFirst(first, state.val, 0), 1);
return o7.cmp(state.len, 0) > 0;
}
module.Begin = Begin;
function Next(state, src) {
var v;
o7.assert(o7.cmp(state.len, 0) > 0);
v = src;
if ((o7.div(v, 64) == 2) && (o7.cmp(state.val[0], o7.div(TypesLimits.IntegerMax, 64)) <= 0)) {
state.val[0] = o7.add(o7.mul(state.val[0], 64), o7.mod(v, 64));
state.len = o7.sub(state.len, 1);
} else {
state.len = o7.sub(0, state.len);
state.val[0] = o7.sub(o7.sub(0, 1), state.val[0]);
}
return o7.cmp(state.len, 0) > 0;
}
module.Next = Next;
function IsBegin(ch) {
return o7.div(ch, 64) != 2;
}
module.IsBegin = IsBegin;
function FromCode(utf8, ofs, ofs__ai, val) {
var ok;
var i;
o7.assert((0 <= val) && (val < 1114112));
i = o7.inited(ofs.at(ofs__ai));
if (val < 128) {
ok = i < utf8.length;
if (ok) {
utf8.put(i, o7.itc(val));
ofs.put(ofs__ai, o7.add(i, 1));
}
} else if (val < 2048) {
ok = i < o7.sub(utf8.length, 1);
if (ok) {
utf8.put(i, o7.itc(o7.add(192, o7.div(val, 64))));
utf8.put(o7.add(i, 1), o7.itc(o7.add(128, o7.mod(val, 64))));
ofs.put(ofs__ai, o7.add(i, 2));
}
} else if (val < 65536) {
ok = i < o7.sub(utf8.length, 2);
if (ok) {
utf8.put(i, o7.itc(o7.add(224, o7.div(val, 4096))));
utf8.put(o7.add(i, 1), o7.itc(o7.add(128, o7.mod(o7.div(val, 64), 64))));
utf8.put(o7.add(i, 2), o7.itc(o7.add(128, o7.mod(val, 64))));
ofs.put(ofs__ai, o7.add(i, 3));
}
} else {
ok = i < o7.sub(utf8.length, 3);
if (ok) {
utf8.put(i, o7.itc(o7.add(240, o7.div(val, 262144))));
utf8.put(o7.add(i, 1), o7.itc(o7.add(128, o7.mod(o7.div(val, 4096), 64))));
utf8.put(o7.add(i, 2), o7.itc(o7.add(128, o7.mod(o7.div(val, 64), 64))));
utf8.put(o7.add(i, 3), o7.itc(o7.add(128, o7.mod(val, 64))));
ofs.put(ofs__ai, o7.add(i, 4));
}
}
return ok;
}
module.FromCode = FromCode;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
(function() { 'use strict';
var module = {};
o7.export.ArrayFill = module;
function Char(a, ofs, ch, n) {
var i;
o7.assert(0 <= n);
o7.assert((0 <= ofs) && (ofs <= o7.sub(a.length, n)));
n = o7.add(n, o7.sub(ofs, 1));
for (i = ofs; i <= n; ++i) {
a.put(i, ch);
}
}
module.Char = Char;
function Char0(a, ofs, n) {
Char(a, ofs, 0x00, n);
}
module.Char0 = Char0;
function Byte(a, ofs, b, n) {
var i;
o7.assert(0 <= n);
o7.assert((0 <= ofs) && (ofs <= o7.sub(a.length, n)));
n = o7.add(n, o7.sub(ofs, 1));
for (i = ofs; i <= n; ++i) {
a.put(i, b);
}
}
module.Byte = Byte;
function Byte0(a, ofs, n) {
Byte(a, ofs, o7.itb(0), n);
}
module.Byte0 = Byte0;
return module;
})();
/* Generated by Vostok - Oberon-07 translator */
/* Copying arrays of chars and bytes in any direction
*
* Copyright 2019,2021 ComdivByZero
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() { 'use strict';
var module = {};
o7.export.ArrayCopy = module;
var FromChars = 0;
module.FromChars = FromChars;
var FromBytes = 1;
module.FromBytes = FromBytes;
var ToChars = 0;
module.ToChars = ToChars;
var ToBytes = 2;
module.ToBytes = ToBytes;
var FromCharsToChars = FromChars + ToChars;
module.FromCharsToChars = FromCharsToChars;
var FromCharsToBytes = FromChars + ToBytes;
module.FromCharsToBytes = FromCharsToBytes;
var FromBytesToChars = FromBytes + ToChars;
module.FromBytesToChars = FromBytesToChars;
var FromBytesToBytes = FromBytes + ToBytes;
module.FromBytesToBytes = FromBytesToBytes;
function Check(destLen, destOfs, srcLen, srcOfs, count) {
o7.assert(count > 0);
o7.assert((0 <= destOfs) && (destOfs <= o7.sub(destLen, count)));
o7.assert((0 <= srcOfs) && (srcOfs <= o7.sub(srcLen, count)));
}
function Chars(dest, destOfs, src, srcOfs, count) {
var di;
var si;
var last;
Check(dest.length, destOfs, src.length, srcOfs, count);
last = o7.sub(o7.add(destOfs, count), 1);
if (destOfs == srcOfs) {
for (di = destOfs; di <= last; ++di) {
dest.put(di, o7.inited(src.at(di)));
}
} else {
si = srcOfs;
for (di = destOfs; di <= last; ++di) {
dest.put(di, o7.inited(src.at(si)));
si = o7.add(si, 1);
}
}
}
module.Chars = Chars;
function Bytes(dest, destOfs, src, srcOfs, count) {
var di;
var si;
var last;
Check(dest.length, destOfs, src.length, srcOfs, count);
last = o7.sub(o7.add(destOfs, count), 1);
if (destOfs == srcOfs) {
for (di = destOfs; di <= last; ++di) {
dest.put(di, o7.inited(src.at(di)));
}
} else {
si = sr