update: 调整编译器代码结构

This commit is contained in:
msojocs 2022-03-10 20:46:42 +08:00
parent 8f7c81c47d
commit 7684a193ae
6 changed files with 486 additions and 332 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,10 @@
#!/usr/bin/env node #!/usr/bin/env node
// wcsc.exe md5 = "3999c590c57c764b152bc6db3b3288c4" // wcsc.exe md5 = "3999c590c57c764b152bc6db3b3288c4"
const version = "20220308" const version = "20220308";
const { spawn } = require("child_process"); const { spawn } = require("child_process");
const path = require("path"); const path = require("path");
const args = process.argv.slice(2); const args = process.argv.slice(2);
const wcscPath = path.resolve(__dirname, "./wcsc.bin") const wcscPath = path.resolve(__dirname, "./wcsc.bin");
function encode1(s) { function encode1(s) {
return encodeURI(s).replace( return encodeURI(s).replace(
@ -28,7 +28,9 @@ if (args.includes("-ll")) {
}); });
wcsc.on("close", (n) => { wcsc.on("close", (n) => {
if (0 === n) { if (0 === n) {
const str = Buffer.concat(spwanData).toString().replace(/\\\\/g, '\\\\u005c'); const str = Buffer.concat(spwanData)
.toString()
.replace(/\\\\/g, "\\\\u005c");
const resultSplit = encode1(str).split("="); const resultSplit = encode1(str).split("=");
const tempObj = {}; const tempObj = {};
for ( for (
@ -62,21 +64,20 @@ if (args.includes("-ll")) {
result = result.replace(/\\\\/g, "\\"); result = result.replace(/\\\\/g, "\\");
result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) { result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) {
const c = $0 === "\\n" ? "\n" : $0[1]; const c = $0 === "\\n" ? "\n" : $0[1];
return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0") return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0");
}) });
process.stdout.write(result); process.stdout.write(result);
}else{ } else {
process.stderr.write(Buffer.concat(errData).toString()); process.stderr.write(Buffer.concat(errData).toString());
process.exitCode = n process.exitCode = n;
} }
}); });
} else { } else {
const wcsc = spawn(wcscPath, args, { const wcsc = spawn(wcscPath, args, {
cwd: process.cwd(), cwd: process.cwd(),
stdio: "inherit", stdio: "inherit",
}); });
wcsc.on('close', code=>{ wcsc.on("close", (code) => {
process.exitCode = code process.exitCode = code;
}) });
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long