This commit is contained in:
Raven Scott
2026-04-03 23:42:47 -04:00
parent d8e580d1af
commit 2ef56ac314
43 changed files with 1941 additions and 553 deletions
+13 -12
View File
@@ -514,12 +514,13 @@ function bareSedMatchAddr(
/**
* @param {string[]} lines
* @param {string[]} scripts
* @param {{ silent?: boolean, extended?: boolean, readFile?: (p: string) => string | null, writeFile?: (p: string, chunk: string) => void, lastLineHint?: number }} opts
* @param {{ silent?: boolean, extended?: boolean, nullData?: boolean, readFile?: (p: string) => string | null, writeFile?: (p: string, chunk: string) => void, lastLineHint?: number }} opts
* @returns {string}
*/
function bareSedRun(lines, scripts, opts) {
const silent = !!opts.silent
const extended = !!opts.extended
const eol = opts.nullData ? '\0' : '\n'
const readF = opts.readFile || (() => null)
const writeF = opts.writeFile || (() => {})
const fullScript = scripts.join('\n')
@@ -608,7 +609,7 @@ function bareSedRun(lines, scripts, opts) {
}
if (count) {
ps = res + str.slice(pos)
if (fl.p) emit(ps + '\n')
if (fl.p) emit(ps + eol)
}
break
}
@@ -637,15 +638,15 @@ function bareSedRun(lines, scripts, opts) {
break
}
case 'print':
emit(ps + '\n')
emit(ps + eol)
break
case 'printFirst': {
const nl = ps.indexOf('\n')
emit((nl === -1 ? ps : ps.slice(0, nl)) + '\n')
emit((nl === -1 ? ps : ps.slice(0, nl)) + eol)
break
}
case 'nextLine':
if (autoPrint && !silent) emit(ps + '\n')
if (autoPrint && !silent) emit(ps + eol)
lineIdx++
nextRead = true
ci = cmds.length
@@ -674,25 +675,25 @@ function bareSedRun(lines, scripts, opts) {
break
}
case 'quit':
if (autoPrint && !silent) emit(ps + '\n')
if (autoPrint && !silent) emit(ps + eol)
quit = /** @type {number} */ (cmd.quitCode) || 0
break
case 'list':
emit(bareSedListLine(ps) + '\n')
emit(bareSedListLine(ps) + eol)
break
case 'lineNum':
emit(String(lineNo) + '\n')
emit(String(lineNo) + eol)
break
case 'readFile': {
const text = readF(/** @type {string} */ (cmd.path))
if (text) emit(text.endsWith('\n') ? text : text + '\n')
if (text) emit(text.endsWith(eol) ? text : text + eol)
break
}
case 'writeFile':
writeF(/** @type {string} */ (cmd.path), ps + '\n')
break
case 'append':
emit(/** @type {string} */ (cmd.text) + '\n')
emit(/** @type {string} */ (cmd.text) + eol)
break
case 'insert':
/* handled as emit before line — approximated by prepending to output before autoPrint */
@@ -700,7 +701,7 @@ function bareSedRun(lines, scripts, opts) {
break
case 'change':
autoPrint = false
emit(/** @type {string} */ (cmd.text) + '\n')
emit(/** @type {string} */ (cmd.text) + eol)
delLine = true
break
case 'b': {
@@ -726,7 +727,7 @@ function bareSedRun(lines, scripts, opts) {
if (quit) break
if (nextRead) continue
if (!delLine && autoPrint) emit(ps + '\n')
if (!delLine && autoPrint) emit(ps + eol)
lineIdx++
}