Updates
This commit is contained in:
+154
-41
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -143,11 +142,33 @@ function bareAwkLex(src, st) {
|
||||
}
|
||||
|
||||
const two = src.slice(st.i, st.i + 2)
|
||||
if (two === '<=' || two === '>=' || two === '==' || two === '!=' || two === '++' || two === '--' || two === '+=' || two === '-=' || two === '*=' || two === '/=' || two === '%=' || two === '~!' || two === '&&' || two === '||') {
|
||||
if (
|
||||
two === '<=' ||
|
||||
two === '>=' ||
|
||||
two === '==' ||
|
||||
two === '!=' ||
|
||||
two === '++' ||
|
||||
two === '--' ||
|
||||
two === '+=' ||
|
||||
two === '-=' ||
|
||||
two === '*=' ||
|
||||
two === '/=' ||
|
||||
two === '%=' ||
|
||||
two === '~!' ||
|
||||
two === '&&' ||
|
||||
two === '||'
|
||||
) {
|
||||
if (two === '~!') {
|
||||
/* not used */
|
||||
}
|
||||
if (two === '&&' || two === '||' || two === '==' || two === '!=' || two === '<=' || two === '>=') {
|
||||
if (
|
||||
two === '&&' ||
|
||||
two === '||' ||
|
||||
two === '==' ||
|
||||
two === '!=' ||
|
||||
two === '<=' ||
|
||||
two === '>='
|
||||
) {
|
||||
st.i += 2
|
||||
return { kind: 'OP', value: two, line }
|
||||
}
|
||||
@@ -177,8 +198,27 @@ function bareAwkLex(src, st) {
|
||||
|
||||
if (/[A-Za-z_]/.test(c)) {
|
||||
let id = ''
|
||||
while (st.i < src.length && /[A-Za-z0-9_]/.test(src[st.i])) id += src[st.i++]
|
||||
if (id === 'BEGIN' || id === 'END' || id === 'if' || id === 'else' || id === 'while' || id === 'for' || id === 'in' || id === 'do' || id === 'break' || id === 'continue' || id === 'next' || id === 'exit' || id === 'print' || id === 'printf' || id === 'return' || id === 'function' || id === 'getline') {
|
||||
while (st.i < src.length && /[A-Za-z0-9_]/.test(src[st.i]))
|
||||
id += src[st.i++]
|
||||
if (
|
||||
id === 'BEGIN' ||
|
||||
id === 'END' ||
|
||||
id === 'if' ||
|
||||
id === 'else' ||
|
||||
id === 'while' ||
|
||||
id === 'for' ||
|
||||
id === 'in' ||
|
||||
id === 'do' ||
|
||||
id === 'break' ||
|
||||
id === 'continue' ||
|
||||
id === 'next' ||
|
||||
id === 'exit' ||
|
||||
id === 'print' ||
|
||||
id === 'printf' ||
|
||||
id === 'return' ||
|
||||
id === 'function' ||
|
||||
id === 'getline'
|
||||
) {
|
||||
return { kind: 'KW', value: id, line }
|
||||
}
|
||||
return { kind: 'ID', value: id, line }
|
||||
@@ -192,7 +232,8 @@ function bareAwkLex(src, st) {
|
||||
if (ch === '/') {
|
||||
st.i++
|
||||
let flags = ''
|
||||
while (st.i < src.length && /[igmsuy]/.test(src[st.i])) flags += src[st.i++]
|
||||
while (st.i < src.length && /[igmsuy]/.test(src[st.i]))
|
||||
flags += src[st.i++]
|
||||
return { kind: 'REGEX', value: pat, flags, line }
|
||||
}
|
||||
if (ch === '\\' && st.i + 1 < src.length) {
|
||||
@@ -240,7 +281,8 @@ class BareAwkParser {
|
||||
|
||||
eat(kind, val) {
|
||||
const t = this.peek()
|
||||
if (kind && t.kind !== kind) bareAwkError('expected ' + kind + ' got ' + t.kind)
|
||||
if (kind && t.kind !== kind)
|
||||
bareAwkError('expected ' + kind + ' got ' + t.kind)
|
||||
if (val != null && t.value !== val) bareAwkError('expected ' + val)
|
||||
this.p++
|
||||
return t
|
||||
@@ -315,7 +357,10 @@ class BareAwkParser {
|
||||
parseStmtList() {
|
||||
/** @type {BareAwkNode[]} */
|
||||
const out = []
|
||||
while (this.peek().kind !== 'EOF' && !(this.peek().kind === 'OP' && this.peek().value === '}')) {
|
||||
while (
|
||||
this.peek().kind !== 'EOF' &&
|
||||
!(this.peek().kind === 'OP' && this.peek().value === '}')
|
||||
) {
|
||||
if (this.peek().kind === 'NL') {
|
||||
this.p++
|
||||
continue
|
||||
@@ -366,18 +411,24 @@ class BareAwkParser {
|
||||
return { t: 'forin', iv, arr, body }
|
||||
}
|
||||
let init = null
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';')) init = this.parseExpr()
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';'))
|
||||
init = this.parseExpr()
|
||||
this.eat('OP', ';')
|
||||
let cond = null
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';')) cond = this.parseExpr()
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';'))
|
||||
cond = this.parseExpr()
|
||||
this.eat('OP', ';')
|
||||
let step = null
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ')')) step = this.parseExpr()
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ')'))
|
||||
step = this.parseExpr()
|
||||
this.eat('OP', ')')
|
||||
const body = this.parseStmt()
|
||||
return { t: 'for', init, cond, step, body }
|
||||
}
|
||||
if (t.kind === 'KW' && (t.value === 'next' || t.value === 'break' || t.value === 'continue')) {
|
||||
if (
|
||||
t.kind === 'KW' &&
|
||||
(t.value === 'next' || t.value === 'break' || t.value === 'continue')
|
||||
) {
|
||||
this.p++
|
||||
this.optSemi()
|
||||
return { t: t.value }
|
||||
@@ -385,7 +436,10 @@ class BareAwkParser {
|
||||
if (t.kind === 'KW' && t.value === 'exit') {
|
||||
this.p++
|
||||
let code = null
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';') && this.peek().kind !== 'NL')
|
||||
if (
|
||||
!(this.peek().kind === 'OP' && this.peek().value === ';') &&
|
||||
this.peek().kind !== 'NL'
|
||||
)
|
||||
code = this.parseExpr()
|
||||
this.optSemi()
|
||||
return { t: 'exit', code }
|
||||
@@ -393,7 +447,10 @@ class BareAwkParser {
|
||||
if (t.kind === 'KW' && t.value === 'return') {
|
||||
this.p++
|
||||
let e = null
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';') && this.peek().kind !== 'NL')
|
||||
if (
|
||||
!(this.peek().kind === 'OP' && this.peek().value === ';') &&
|
||||
this.peek().kind !== 'NL'
|
||||
)
|
||||
e = this.parseExpr()
|
||||
this.optSemi()
|
||||
return { t: 'return', e }
|
||||
@@ -402,7 +459,10 @@ class BareAwkParser {
|
||||
this.p++
|
||||
/** @type {BareAwkNode[]} */
|
||||
const args = []
|
||||
if (!(this.peek().kind === 'OP' && this.peek().value === ';') && this.peek().kind !== 'NL') {
|
||||
if (
|
||||
!(this.peek().kind === 'OP' && this.peek().value === ';') &&
|
||||
this.peek().kind !== 'NL'
|
||||
) {
|
||||
args.push(this.parseExpr())
|
||||
while (this.peek().value === ',') {
|
||||
this.p++
|
||||
@@ -432,7 +492,10 @@ class BareAwkParser {
|
||||
}
|
||||
this.eat('OP', ')')
|
||||
let redir = null
|
||||
if (this.peek().kind === 'OP' && (this.peek().value === '>' || this.peek().value === '>>')) {
|
||||
if (
|
||||
this.peek().kind === 'OP' &&
|
||||
(this.peek().value === '>' || this.peek().value === '>>')
|
||||
) {
|
||||
const op = this.peek().value
|
||||
this.p++
|
||||
redir = { op, file: this.parseExpr() }
|
||||
@@ -463,10 +526,19 @@ class BareAwkParser {
|
||||
parseAssign() {
|
||||
let n = this.parseCond()
|
||||
const t = this.peek()
|
||||
if (t.kind === 'OP' && (t.value === '=' || t.value === '+=' || t.value === '-=' || t.value === '*=' || t.value === '/=' || t.value === '%=')) {
|
||||
if (
|
||||
t.kind === 'OP' &&
|
||||
(t.value === '=' ||
|
||||
t.value === '+=' ||
|
||||
t.value === '-=' ||
|
||||
t.value === '*=' ||
|
||||
t.value === '/=' ||
|
||||
t.value === '%=')
|
||||
) {
|
||||
const op = t.value
|
||||
this.p++
|
||||
if (n.t !== 'var' && n.t !== 'field' && n.t !== 'index') bareAwkError('bad lvalue')
|
||||
if (n.t !== 'var' && n.t !== 'field' && n.t !== 'index')
|
||||
bareAwkError('bad lvalue')
|
||||
const rhs = this.parseAssign()
|
||||
return { t: 'assign', op, left: n, right: rhs }
|
||||
}
|
||||
@@ -519,7 +591,10 @@ class BareAwkParser {
|
||||
parseCmp() {
|
||||
let n = this.parseAdd()
|
||||
const ops = ['==', '!=', '<', '>', '<=', '>=']
|
||||
while (this.peek().kind === 'OP' && ops.includes(String(this.peek().value))) {
|
||||
while (
|
||||
this.peek().kind === 'OP' &&
|
||||
ops.includes(String(this.peek().value))
|
||||
) {
|
||||
const op = String(this.peek().value)
|
||||
this.p++
|
||||
n = { t: 'binop', op, a: n, b: this.parseAdd() }
|
||||
@@ -539,7 +614,11 @@ class BareAwkParser {
|
||||
|
||||
parseMul() {
|
||||
let n = this.parseUnary()
|
||||
while (this.peek().value === '*' || this.peek().value === '/' || this.peek().value === '%') {
|
||||
while (
|
||||
this.peek().value === '*' ||
|
||||
this.peek().value === '/' ||
|
||||
this.peek().value === '%'
|
||||
) {
|
||||
const op = String(this.peek().value)
|
||||
this.p++
|
||||
n = { t: 'binop', op, a: n, b: this.parseUnary() }
|
||||
@@ -790,7 +869,8 @@ class BareAwkRuntime {
|
||||
const v = this.environ[k]
|
||||
return v != null ? v : ''
|
||||
}
|
||||
const arr = this.arrays[n.name] || (this.arrays[n.name] = Object.create(null))
|
||||
const arr =
|
||||
this.arrays[n.name] || (this.arrays[n.name] = Object.create(null))
|
||||
return arr[k] != null ? arr[k] : ''
|
||||
}
|
||||
case 'binop': {
|
||||
@@ -800,7 +880,9 @@ class BareAwkRuntime {
|
||||
const bn = Number(b)
|
||||
switch (n.op) {
|
||||
case '+':
|
||||
return (Number.isFinite(an) ? an : 0) + (Number.isFinite(bn) ? bn : 0)
|
||||
return (
|
||||
(Number.isFinite(an) ? an : 0) + (Number.isFinite(bn) ? bn : 0)
|
||||
)
|
||||
case '-':
|
||||
return an - bn
|
||||
case '*':
|
||||
@@ -832,9 +914,16 @@ class BareAwkRuntime {
|
||||
return 0
|
||||
}
|
||||
case '||':
|
||||
return this.truthy(this.evalExpr(n.a)) ? 1 : this.truthy(this.evalExpr(n.b)) ? 1 : 0
|
||||
return this.truthy(this.evalExpr(n.a))
|
||||
? 1
|
||||
: this.truthy(this.evalExpr(n.b))
|
||||
? 1
|
||||
: 0
|
||||
case '&&':
|
||||
return this.truthy(this.evalExpr(n.a)) && this.truthy(this.evalExpr(n.b)) ? 1 : 0
|
||||
return this.truthy(this.evalExpr(n.a)) &&
|
||||
this.truthy(this.evalExpr(n.b))
|
||||
? 1
|
||||
: 0
|
||||
case 'match': {
|
||||
const s = String(this.evalExpr(n.a))
|
||||
const rhs = n.b
|
||||
@@ -860,7 +949,9 @@ class BareAwkRuntime {
|
||||
return rx.test(s) ? 0 : 1
|
||||
}
|
||||
case '?:':
|
||||
return this.truthy(this.evalExpr(n.n)) ? this.evalExpr(n.a) : this.evalExpr(n.b)
|
||||
return this.truthy(this.evalExpr(n.n))
|
||||
? this.evalExpr(n.a)
|
||||
: this.evalExpr(n.b)
|
||||
case 'assign': {
|
||||
const v = this.evalExpr(n.right)
|
||||
this.assign(n.left, n.op, v)
|
||||
@@ -917,7 +1008,8 @@ class BareAwkRuntime {
|
||||
else if (op === '%=') base = nv === 0 ? 0 : cur % nv
|
||||
}
|
||||
if (left.t === 'index') {
|
||||
const arr = this.arrays[left.name] || (this.arrays[left.name] = Object.create(null))
|
||||
const arr =
|
||||
this.arrays[left.name] || (this.arrays[left.name] = Object.create(null))
|
||||
arr[String(this.evalExpr(left.idx))] = base
|
||||
return
|
||||
}
|
||||
@@ -955,7 +1047,10 @@ class BareAwkRuntime {
|
||||
return parts.length
|
||||
}
|
||||
case 'sprintf':
|
||||
return bareAwkSprintf(String(a(0)), args.slice(1).map((x) => this.evalExpr(x)))
|
||||
return bareAwkSprintf(
|
||||
String(a(0)),
|
||||
args.slice(1).map((x) => this.evalExpr(x))
|
||||
)
|
||||
case 'int':
|
||||
return Math.trunc(Number(a(0)))
|
||||
case 'tolower':
|
||||
@@ -974,7 +1069,8 @@ class BareAwkRuntime {
|
||||
}
|
||||
case 'sub':
|
||||
case 'gsub': {
|
||||
const rx = args[0].t === 'rxLit' ? args[0].rx : bareAwkMakeRx(String(a(0)), '')
|
||||
const rx =
|
||||
args[0].t === 'rxLit' ? args[0].rx : bareAwkMakeRx(String(a(0)), '')
|
||||
const rep = String(a(1))
|
||||
let target = args[2] ? String(a(2)) : this.$0
|
||||
let n = 0
|
||||
@@ -982,7 +1078,10 @@ class BareAwkRuntime {
|
||||
rx.lastIndex = 0
|
||||
const m = rx.exec(target)
|
||||
if (m) {
|
||||
target = target.slice(0, m.index) + rep + target.slice(m.index + m[0].length)
|
||||
target =
|
||||
target.slice(0, m.index) +
|
||||
rep +
|
||||
target.slice(m.index + m[0].length)
|
||||
n = 1
|
||||
}
|
||||
} else {
|
||||
@@ -999,7 +1098,8 @@ class BareAwkRuntime {
|
||||
}
|
||||
case 'match': {
|
||||
const s = String(a(0))
|
||||
const rx = args[1].t === 'rxLit' ? args[1].rx : bareAwkMakeRx(String(a(1)), '')
|
||||
const rx =
|
||||
args[1].t === 'rxLit' ? args[1].rx : bareAwkMakeRx(String(a(1)), '')
|
||||
rx.lastIndex = 0
|
||||
const m = rx.exec(s)
|
||||
if (!m) {
|
||||
@@ -1200,7 +1300,8 @@ function bareAwkSprintf(fmt, args) {
|
||||
else if (spec === 'f' || spec === 'g') o += String(Number(arg))
|
||||
else if (spec === 'o') o += (Math.trunc(Number(arg)) >>> 0).toString(8)
|
||||
else if (spec === 'x') o += (Math.trunc(Number(arg)) >>> 0).toString(16)
|
||||
else if (spec === 'X') o += (Math.trunc(Number(arg)) >>> 0).toString(16).toUpperCase()
|
||||
else if (spec === 'X')
|
||||
o += (Math.trunc(Number(arg)) >>> 0).toString(16).toUpperCase()
|
||||
else o += String(arg)
|
||||
i = j
|
||||
}
|
||||
@@ -1217,7 +1318,11 @@ async function bareAwkRun(program, opts, io) {
|
||||
const rt = new BareAwkRuntime(ast, opts, io)
|
||||
|
||||
for (const rule of ast.rules) {
|
||||
if (rule.pattern && rule.pattern.t === 'pat' && rule.pattern.k === 'BEGIN') {
|
||||
if (
|
||||
rule.pattern &&
|
||||
rule.pattern.t === 'pat' &&
|
||||
rule.pattern.k === 'BEGIN'
|
||||
) {
|
||||
for (const st of rule.stmts) {
|
||||
const r = rt.execStmt(st)
|
||||
await rt.flushWrites()
|
||||
@@ -1333,7 +1438,9 @@ async function run(ctx, argv) {
|
||||
}
|
||||
const program = progParts.join('\n')
|
||||
if (!program.trim()) {
|
||||
ctx.console.error('usage: awk [-F fs] [-v k=v] [-f file] program [file ...]')
|
||||
ctx.console.error(
|
||||
'usage: awk [-F fs] [-v k=v] [-f file] program [file ...]'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
@@ -1356,7 +1463,9 @@ async function run(ctx, argv) {
|
||||
},
|
||||
async writeFile(path, data, append) {
|
||||
const prev = append ? await ctx.vfs.readFile(path) : null
|
||||
const merged = prev ? ctx.b4a.concat([prev, ctx.b4a.from(data)]) : ctx.b4a.from(data)
|
||||
const merged = prev
|
||||
? ctx.b4a.concat([prev, ctx.b4a.from(data)])
|
||||
: ctx.b4a.from(data)
|
||||
await ctx.vfs.writeFile(path, merged)
|
||||
},
|
||||
readFile(path) {
|
||||
@@ -1366,12 +1475,16 @@ async function run(ctx, argv) {
|
||||
}
|
||||
|
||||
try {
|
||||
const code = await bareAwkRun(program, {
|
||||
fs: fsVal != null ? fsVal : ' ',
|
||||
argc: awkArgv.length,
|
||||
argv: awkArgv,
|
||||
environ: { ...ctx.vfs.env }
|
||||
}, io)
|
||||
const code = await bareAwkRun(
|
||||
program,
|
||||
{
|
||||
fs: fsVal != null ? fsVal : ' ',
|
||||
argc: awkArgv.length,
|
||||
argv: awkArgv,
|
||||
environ: { ...ctx.vfs.env }
|
||||
},
|
||||
io
|
||||
)
|
||||
ctx.exitCode = code || 0
|
||||
} catch (e) {
|
||||
ctx.console.error((e && e.message) || String(e))
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+5
-4
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -88,7 +87,7 @@ function bareChmodSymbolic(curPerm, spec) {
|
||||
if (ch === 'x' || ch === 's' || ch === 't') bits |= who & 0o111
|
||||
if (ch === 'X') wantX = true
|
||||
}
|
||||
if (wantX && (m & 0o111)) bits |= who & 0o111
|
||||
if (wantX && m & 0o111) bits |= who & 0o111
|
||||
if (op === '=') m = (m & ~who) | bits
|
||||
else if (op === '+') m |= bits
|
||||
else if (op === '-') m &= ~bits
|
||||
@@ -100,7 +99,9 @@ async function run(ctx, argv) {
|
||||
const modeStr = argv[1]
|
||||
const files = argv.slice(2)
|
||||
if (!modeStr || !files.length) {
|
||||
ctx.console.error('usage: chmod MODE FILE...\n MODE is octal (e.g. 644) or symbolic (e.g. u+rw)')
|
||||
ctx.console.error(
|
||||
'usage: chmod MODE FILE...\n MODE is octal (e.g. 644) or symbolic (e.g. u+rw)'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
+4
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -191,7 +190,9 @@ async function run(ctx, argv) {
|
||||
} else {
|
||||
const pu = parseIdSpec(ownSpec, env)
|
||||
uid = pu.uid
|
||||
uname = /^\d+$/.test(ownSpec.trim()) ? undefined : ownSpec.trim() || undefined
|
||||
uname = /^\d+$/.test(ownSpec.trim())
|
||||
? undefined
|
||||
: ownSpec.trim() || undefined
|
||||
gid = Number.parseInt(String(env.GID ?? '65534'), 10)
|
||||
gname = env.GROUP || env.USER
|
||||
}
|
||||
|
||||
+4
-6
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -111,16 +110,15 @@ const BARE_CKSUM_TAB = new Uint32Array([
|
||||
function barePosixCksum(u8) {
|
||||
let crc = 0
|
||||
for (let i = 0; i < u8.length; i++) {
|
||||
crc =
|
||||
(BARE_CKSUM_TAB[(u8[i] ^ ((crc >>> 24) & 0xff))] ^ (crc << 8)) >>> 0
|
||||
crc = (BARE_CKSUM_TAB[u8[i] ^ ((crc >>> 24) & 0xff)] ^ (crc << 8)) >>> 0
|
||||
}
|
||||
let n = u8.length
|
||||
while (n > 0) {
|
||||
crc =
|
||||
(BARE_CKSUM_TAB[((n & 0xff) ^ ((crc >>> 24) & 0xff))] ^ (crc << 8)) >>> 0
|
||||
(BARE_CKSUM_TAB[(n & 0xff) ^ ((crc >>> 24) & 0xff)] ^ (crc << 8)) >>> 0
|
||||
n >>>= 8
|
||||
}
|
||||
return (~crc >>> 0)
|
||||
return ~crc >>> 0
|
||||
}
|
||||
|
||||
async function run(ctx, argv) {
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+4
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -69,7 +68,9 @@ async function run(ctx, argv) {
|
||||
const rest = argv.slice(1)
|
||||
|
||||
if (rest.length === 0) {
|
||||
ctx.console.error('crontab: usage: crontab -l | crontab -r | crontab <file>')
|
||||
ctx.console.error(
|
||||
'crontab: usage: crontab -l | crontab -r | crontab <file>'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
+2
-5
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -116,9 +115,7 @@ async function run(ctx, argv) {
|
||||
for (const line of lines) {
|
||||
if (line === '' && lines.length === 1) continue
|
||||
const cols =
|
||||
delim === ''
|
||||
? [...line]
|
||||
: line.split(delim === '\\t' ? '\t' : delim)
|
||||
delim === '' ? [...line] : line.split(delim === '\\t' ? '\t' : delim)
|
||||
const out = []
|
||||
for (const n of [...want].sort((a, b) => a - b)) {
|
||||
out.push(cols[n - 1] != null ? cols[n - 1] : '')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+11
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -65,7 +64,16 @@ function barePosixBlocks(size) {
|
||||
* curDepth is distance from the search root directory (0 at the initial path).
|
||||
* Printed paths use gnu-like depth curDepth + 1 (immediate children of the root are depth 1).
|
||||
*/
|
||||
async function walk(ctx, dir, nameRe, pathRe, wantType, maxDepth, minDepth, curDepth) {
|
||||
async function walk(
|
||||
ctx,
|
||||
dir,
|
||||
nameRe,
|
||||
pathRe,
|
||||
wantType,
|
||||
maxDepth,
|
||||
minDepth,
|
||||
curDepth
|
||||
) {
|
||||
if (maxDepth >= 0 && curDepth > maxDepth) return
|
||||
let names
|
||||
try {
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+6
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -331,7 +330,11 @@ async function run(ctx, argv) {
|
||||
|
||||
if (!countOnly && !listFiles) {
|
||||
if (onlyMatching && !invert) {
|
||||
const parts = extractOnlyMatching(line, patterns, { fixed, icase, word })
|
||||
const parts = extractOnlyMatching(line, patterns, {
|
||||
fixed,
|
||||
icase,
|
||||
word
|
||||
})
|
||||
for (const part of parts) {
|
||||
let chunk = part
|
||||
if (numbers) chunk = lineNum + ':' + chunk
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1959
-1939
File diff suppressed because it is too large
Load Diff
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+2
-7
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -93,11 +92,7 @@ async function run(ctx, argv) {
|
||||
try {
|
||||
const stT = await vfs.lstat(t)
|
||||
if (stT && stT.type !== 'directory') {
|
||||
const leaf = t
|
||||
.replace(/\/+$/, '')
|
||||
.split('/')
|
||||
.filter(Boolean)
|
||||
.pop()
|
||||
const leaf = t.replace(/\/+$/, '').split('/').filter(Boolean).pop()
|
||||
names = [leaf || t]
|
||||
singleEntryPath = t
|
||||
} else {
|
||||
|
||||
+29
-15
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -146,7 +145,10 @@ function bareManFlushBlock(lines, width, prefixFirst, prefixRest) {
|
||||
const out = []
|
||||
let first = true
|
||||
for (const line of lines) {
|
||||
const wrapped = bareManWrap(line, width - (first ? prefixFirst.length : prefixRest.length))
|
||||
const wrapped = bareManWrap(
|
||||
line,
|
||||
width - (first ? prefixFirst.length : prefixRest.length)
|
||||
)
|
||||
for (let i = 0; i < wrapped.length; i++) {
|
||||
const p = i === 0 && first ? prefixFirst : prefixRest
|
||||
out.push(p + wrapped[i])
|
||||
@@ -194,13 +196,7 @@ function bareManRenderPage(page, ctx, width) {
|
||||
) + '\n'
|
||||
for (const ex of page.examples) {
|
||||
if (ex.caption) {
|
||||
s +=
|
||||
bareManFlushBlock(
|
||||
['# ' + ex.caption],
|
||||
width,
|
||||
'',
|
||||
' '
|
||||
) + '\n'
|
||||
s += bareManFlushBlock(['# ' + ex.caption], width, '', ' ') + '\n'
|
||||
}
|
||||
s += bareManRenderExampleCode(ex.code, width) + '\n\n'
|
||||
}
|
||||
@@ -232,7 +228,12 @@ function bareManRenderPage(page, ctx, width) {
|
||||
if (b.options && b.options.length) {
|
||||
for (const o of b.options) {
|
||||
const head = o.flag + '\t'
|
||||
s += bareManFlushBlock([o.meaning], width, ' ' + head, ' ')
|
||||
s += bareManFlushBlock(
|
||||
[o.meaning],
|
||||
width,
|
||||
' ' + head,
|
||||
' '
|
||||
)
|
||||
}
|
||||
}
|
||||
if (b.examples && b.examples.length) {
|
||||
@@ -376,11 +377,17 @@ async function run(ctx, argv) {
|
||||
}
|
||||
function listCategoryOf(p) {
|
||||
const c = p.listCategory
|
||||
if (c === 'coreutils' || c === 'extra' || c === 'handbook' || c === 'devguide')
|
||||
if (
|
||||
c === 'coreutils' ||
|
||||
c === 'extra' ||
|
||||
c === 'handbook' ||
|
||||
c === 'devguide'
|
||||
)
|
||||
return c
|
||||
if (p.section === 7) {
|
||||
const n = p.name
|
||||
if (n.startsWith('devguide-') || n === 'bare-os-developer-guide') return 'devguide'
|
||||
if (n.startsWith('devguide-') || n === 'bare-os-developer-guide')
|
||||
return 'devguide'
|
||||
return 'handbook'
|
||||
}
|
||||
if (p.name === 'git' || p.name === 'bare-os-shell') return 'extra'
|
||||
@@ -459,7 +466,10 @@ async function run(ctx, argv) {
|
||||
name = rest[1]
|
||||
}
|
||||
|
||||
if (sectionExplicit !== null && (sectionExplicit < 1 || sectionExplicit > 8)) {
|
||||
if (
|
||||
sectionExplicit !== null &&
|
||||
(sectionExplicit < 1 || sectionExplicit > 8)
|
||||
) {
|
||||
ctx.console.error('man: section must be between 1 and 8')
|
||||
ctx.exitCode = 2
|
||||
return
|
||||
@@ -475,7 +485,11 @@ async function run(ctx, argv) {
|
||||
const page = db.pages[idx]
|
||||
if (sectionExplicit !== null && page.section !== sectionExplicit) {
|
||||
ctx.console.error(
|
||||
'man: no entry for ' + name + ' in section ' + sectionExplicit + ' (see man -l)'
|
||||
'man: no entry for ' +
|
||||
name +
|
||||
' in section ' +
|
||||
sectionExplicit +
|
||||
' (see man -l)'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+4
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -70,7 +69,9 @@ async function run(ctx, argv) {
|
||||
}
|
||||
const ipc = ctx.bareOsIpc
|
||||
if (!ipc) {
|
||||
ctx.console.error('mkfifo: simulated FIFOs are not available in this environment')
|
||||
ctx.console.error(
|
||||
'mkfifo: simulated FIFOs are not available in this environment'
|
||||
)
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+2
-6
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -119,10 +118,7 @@ async function run(ctx, argv) {
|
||||
try {
|
||||
const st = await ctx.vfs.lstat(src)
|
||||
const singleFileToFile =
|
||||
sources.length === 1 &&
|
||||
!destIsDir &&
|
||||
st &&
|
||||
st.type === 'file'
|
||||
sources.length === 1 && !destIsDir && st && st.type === 'file'
|
||||
if (singleFileToFile) {
|
||||
const buf = await ctx.vfs.readFile(src)
|
||||
if (!buf) throw new Error('cannot read source')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+7
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -88,7 +87,12 @@ async function run(ctx, argv) {
|
||||
.map((x) => (x >= 32 && x < 127 ? String.fromCharCode(x) : '.'))
|
||||
.join('')
|
||||
ctx.console.log(
|
||||
off.toString(8).padStart(7, '0') + ' ' + hex.padEnd(47, ' ') + ' |' + asc + '|'
|
||||
off.toString(8).padStart(7, '0') +
|
||||
' ' +
|
||||
hex.padEnd(47, ' ') +
|
||||
' |' +
|
||||
asc +
|
||||
'|'
|
||||
)
|
||||
off += 16
|
||||
}
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+3
-3
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -82,7 +81,8 @@ function barePrintfFormat(fmt, args) {
|
||||
else if (spec === 'd' || spec === 'i') o += String(Math.trunc(Number(arg)))
|
||||
else if (spec === 'u') o += String(Math.trunc(Number(arg)) >>> 0)
|
||||
else if (spec === 'x') o += (Math.trunc(Number(arg)) >>> 0).toString(16)
|
||||
else if (spec === 'X') o += (Math.trunc(Number(arg)) >>> 0).toString(16).toUpperCase()
|
||||
else if (spec === 'X')
|
||||
o += (Math.trunc(Number(arg)) >>> 0).toString(16).toUpperCase()
|
||||
else if (spec === 'o') o += (Math.trunc(Number(arg)) >>> 0).toString(8)
|
||||
else if (spec === 'c') o += String.fromCharCode(Number(arg) || 0)
|
||||
else if (spec === 'f') o += String(Number(arg))
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+103
-22
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
@@ -160,7 +159,8 @@ function bareSedListLine(s) {
|
||||
if (code === 10) o += '\\n'
|
||||
else if (code === 9) o += '\\t'
|
||||
else if (code === 92) o += '\\\\'
|
||||
else if (code < 32 || code > 126) o += '\\' + code.toString(8).padStart(3, '0')
|
||||
else if (code < 32 || code > 126)
|
||||
o += '\\' + code.toString(8).padStart(3, '0')
|
||||
else o += s[i]
|
||||
}
|
||||
return o + '$'
|
||||
@@ -308,9 +308,15 @@ function bareSedParseScript(script, extended) {
|
||||
i++
|
||||
skipWs()
|
||||
let path = ''
|
||||
while (i < len && script[i] !== '\n' && script[i] !== ';') path += script[i++]
|
||||
while (i < len && script[i] !== '\n' && script[i] !== ';')
|
||||
path += script[i++]
|
||||
path = path.replace(/[ \t]+$/, '')
|
||||
cmds.push({ type: ty === 'r' ? 'readFile' : 'writeFile', path, neg, addr: addr1 })
|
||||
cmds.push({
|
||||
type: ty === 'r' ? 'readFile' : 'writeFile',
|
||||
path,
|
||||
neg,
|
||||
addr: addr1
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -329,7 +335,12 @@ function bareSedParseScript(script, extended) {
|
||||
text += '\n' + cont
|
||||
if (i < len && script[i] === '\n') i++
|
||||
}
|
||||
cmds.push({ type: ty === 'a' ? 'append' : ty === 'i' ? 'insert' : 'change', text, neg, addr: addr1 })
|
||||
cmds.push({
|
||||
type: ty === 'a' ? 'append' : ty === 'i' ? 'insert' : 'change',
|
||||
text,
|
||||
neg,
|
||||
addr: addr1
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -370,7 +381,8 @@ function bareSedParseScript(script, extended) {
|
||||
const to = bareSedReadDelimited(delim, script, i)
|
||||
if (!to) throw new Error('sed: unterminated y')
|
||||
i = to.end
|
||||
if (from.raw.length !== to.raw.length) throw new Error('sed: y strings must be same length')
|
||||
if (from.raw.length !== to.raw.length)
|
||||
throw new Error('sed: y strings must be same length')
|
||||
cmds.push({ type: 'y', from: from.raw, to: to.raw, neg, addr: addr1 })
|
||||
continue
|
||||
}
|
||||
@@ -421,7 +433,8 @@ function bareSedParseScript(script, extended) {
|
||||
function bareSedAddrSimple(addr, lineNo, lastLine, ps) {
|
||||
if (addr == null) return true
|
||||
if (typeof addr === 'object' && addr.kind === 'num') return lineNo === addr.n
|
||||
if (typeof addr === 'object' && addr.kind === 'last') return lineNo === lastLine
|
||||
if (typeof addr === 'object' && addr.kind === 'last')
|
||||
return lineNo === lastLine
|
||||
if (typeof addr === 'object' && addr.kind === 're') {
|
||||
addr.rx.lastIndex = 0
|
||||
return addr.rx.test(ps)
|
||||
@@ -444,21 +457,48 @@ function bareSedAddrSimple(addr, lineNo, lastLine, ps) {
|
||||
* @param {Map<number, { active: boolean }>} rangeStates
|
||||
* @param {number} cmdIndex
|
||||
*/
|
||||
function bareSedAddrMatchFull(addr, lineNo, lastLine, ps, rangeStates, cmdIndex) {
|
||||
function bareSedAddrMatchFull(
|
||||
addr,
|
||||
lineNo,
|
||||
lastLine,
|
||||
ps,
|
||||
rangeStates,
|
||||
cmdIndex
|
||||
) {
|
||||
if (addr == null) return true
|
||||
if (typeof addr === 'object' && addr.kind === 'range') {
|
||||
const a = addr.a
|
||||
const b = addr.b
|
||||
if (typeof a === 'object' && a.kind === 'num' && typeof b === 'object' && b.kind === 'num') {
|
||||
if (
|
||||
typeof a === 'object' &&
|
||||
a.kind === 'num' &&
|
||||
typeof b === 'object' &&
|
||||
b.kind === 'num'
|
||||
) {
|
||||
return lineNo >= a.n && lineNo <= b.n
|
||||
}
|
||||
if (typeof a === 'object' && a.kind === 'num' && typeof b === 'object' && b.kind === 'last') {
|
||||
if (
|
||||
typeof a === 'object' &&
|
||||
a.kind === 'num' &&
|
||||
typeof b === 'object' &&
|
||||
b.kind === 'last'
|
||||
) {
|
||||
return lineNo >= a.n && lineNo <= lastLine
|
||||
}
|
||||
if (typeof a === 'object' && a.kind === 'last' && typeof b === 'object' && b.kind === 'num') {
|
||||
if (
|
||||
typeof a === 'object' &&
|
||||
a.kind === 'last' &&
|
||||
typeof b === 'object' &&
|
||||
b.kind === 'num'
|
||||
) {
|
||||
return lineNo >= lastLine && lineNo <= b.n
|
||||
}
|
||||
if (typeof a === 'object' && a.kind === 're' && typeof b === 'object' && b.kind === 're') {
|
||||
if (
|
||||
typeof a === 'object' &&
|
||||
a.kind === 're' &&
|
||||
typeof b === 'object' &&
|
||||
b.kind === 're'
|
||||
) {
|
||||
let st = rangeStates.get(cmdIndex)
|
||||
if (!st) {
|
||||
st = { active: false }
|
||||
@@ -473,7 +513,12 @@ function bareSedAddrMatchFull(addr, lineNo, lastLine, ps, rangeStates, cmdIndex)
|
||||
if (st.active && hitB) st.active = false
|
||||
return inRange
|
||||
}
|
||||
if (typeof a === 'object' && a.kind === 'num' && typeof b === 'object' && b.kind === 're') {
|
||||
if (
|
||||
typeof a === 'object' &&
|
||||
a.kind === 'num' &&
|
||||
typeof b === 'object' &&
|
||||
b.kind === 're'
|
||||
) {
|
||||
let st = rangeStates.get(cmdIndex)
|
||||
if (!st) {
|
||||
st = { active: false }
|
||||
@@ -486,7 +531,12 @@ function bareSedAddrMatchFull(addr, lineNo, lastLine, ps, rangeStates, cmdIndex)
|
||||
if (st.active && hitB) st.active = false
|
||||
return inRange
|
||||
}
|
||||
if (typeof a === 'object' && a.kind === 're' && typeof b === 'object' && b.kind === 'num') {
|
||||
if (
|
||||
typeof a === 'object' &&
|
||||
a.kind === 're' &&
|
||||
typeof b === 'object' &&
|
||||
b.kind === 'num'
|
||||
) {
|
||||
let st = rangeStates.get(cmdIndex)
|
||||
if (!st) {
|
||||
st = { active: false }
|
||||
@@ -503,8 +553,23 @@ function bareSedAddrMatchFull(addr, lineNo, lastLine, ps, rangeStates, cmdIndex)
|
||||
return bareSedAddrSimple(addr, lineNo, lastLine, ps)
|
||||
}
|
||||
|
||||
function bareSedMatchAddr(addr, neg, lineNo, lastLine, ps, rangeStates, cmdIndex) {
|
||||
const m = bareSedAddrMatchFull(addr, lineNo, lastLine, ps, rangeStates, cmdIndex)
|
||||
function bareSedMatchAddr(
|
||||
addr,
|
||||
neg,
|
||||
lineNo,
|
||||
lastLine,
|
||||
ps,
|
||||
rangeStates,
|
||||
cmdIndex
|
||||
) {
|
||||
const m = bareSedAddrMatchFull(
|
||||
addr,
|
||||
lineNo,
|
||||
lastLine,
|
||||
ps,
|
||||
rangeStates,
|
||||
cmdIndex
|
||||
)
|
||||
return neg ? !m : m
|
||||
}
|
||||
|
||||
@@ -524,7 +589,8 @@ function bareSedRun(lines, scripts, opts) {
|
||||
/** @type {Record<string, number>} */
|
||||
const labels = {}
|
||||
for (let ci = 0; ci < cmds.length; ci++) {
|
||||
if (cmds[ci].type === 'label') labels[/** @type {string} */ (cmds[ci].name)] = ci
|
||||
if (cmds[ci].type === 'label')
|
||||
labels[/** @type {string} */ (cmds[ci].name)] = ci
|
||||
}
|
||||
|
||||
const lastLine = opts.lastLineHint != null ? opts.lastLineHint : lines.length
|
||||
@@ -556,7 +622,17 @@ function bareSedRun(lines, scripts, opts) {
|
||||
continue
|
||||
}
|
||||
const addr = cmd.addr
|
||||
if (!bareSedMatchAddr(addr, !!cmd.neg, lineNo, lastLine, ps, rangeStates, ci)) {
|
||||
if (
|
||||
!bareSedMatchAddr(
|
||||
addr,
|
||||
!!cmd.neg,
|
||||
lineNo,
|
||||
lastLine,
|
||||
ps,
|
||||
rangeStates,
|
||||
ci
|
||||
)
|
||||
) {
|
||||
ci++
|
||||
continue
|
||||
}
|
||||
@@ -566,7 +642,9 @@ function bareSedRun(lines, scripts, opts) {
|
||||
lastSubst = false
|
||||
const rx = /** @type {RegExp} */ (cmd.rx)
|
||||
const rep = /** @type {string} */ (cmd.rep)
|
||||
const fl = /** @type {{ g?: boolean, p?: boolean, n?: number }} */ (cmd.flags)
|
||||
const fl = /** @type {{ g?: boolean, p?: boolean, n?: number }} */ (
|
||||
cmd.flags
|
||||
)
|
||||
let count = 0
|
||||
let res = ''
|
||||
let pos = 0
|
||||
@@ -602,7 +680,8 @@ function bareSedRun(lines, scripts, opts) {
|
||||
const map = {}
|
||||
for (let j = 0; j < from.length; j++) map[from[j]] = to[j]
|
||||
let ns = ''
|
||||
for (let j = 0; j < ps.length; j++) ns += map[ps[j]] != null ? map[ps[j]] : ps[j]
|
||||
for (let j = 0; j < ps.length; j++)
|
||||
ns += map[ps[j]] != null ? map[ps[j]] : ps[j]
|
||||
ps = ns
|
||||
break
|
||||
}
|
||||
@@ -845,7 +924,9 @@ async function run(ctx, argv) {
|
||||
for (const [p, data] of Object.entries(wAccum)) {
|
||||
try {
|
||||
const prev = await ctx.vfs.readFile(p)
|
||||
const merged = prev ? ctx.b4a.concat([prev, ctx.b4a.from(data)]) : ctx.b4a.from(data)
|
||||
const merged = prev
|
||||
? ctx.b4a.concat([prev, ctx.b4a.from(data)])
|
||||
: ctx.b4a.from(data)
|
||||
await ctx.vfs.writeFile(p, merged)
|
||||
} catch (e) {
|
||||
ctx.console.error('sed: ' + p + ': ' + ((e && e.message) || e))
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
+1
-2
@@ -6,8 +6,7 @@ function bareStdin(ctx) {
|
||||
|
||||
/** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */
|
||||
function bareFormatModeString(mode, type) {
|
||||
const typeChar =
|
||||
type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-'
|
||||
const perm = mode & 0o777
|
||||
const r = (bit) => (perm & bit ? 'r' : '-')
|
||||
const w = (bit) => (perm & bit ? 'w' : '-')
|
||||
|
||||
Reference in New Issue
Block a user