-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip.js
57 lines (44 loc) · 1.18 KB
/
strip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
const { serialize } = require('v8');
function strp_file(f) {
code = fs.readFileSync(f, 'utf-8')
initial_code = code;
if (!code.match(/^[ \t]*SERIALIZE\(/m) || !code.match(/\/\*##+[A-Za-z@%0-9\/\+]*\*\/$/m))
{
return;
}
console.log(f);
let crlf = false;
if (code.indexOf('\r') >= 0) {
code.replace('\r', '');
crlf = true;
}
code = code.replace(/\s*\/\*##+[A-Za-z@%0-9\/\+]*\*\/$/gm, '');
code = code.replace(/[ \t]+$/gm, '');
code = code.replace(/^[ \t]*SERIALIZE\(.*$/gm, 'ø');
code = code.replace(/\{(\nø)+\n(?=\n)/g, '{');
code = code.replace(/\n(\nø)+\n(?=\n)/g, '\n');
code = code.replace(/(\nø)+\n(?=\n)/g, '\n');
code = code.replace(/\n(\nø)+(?=\n)/g, '\n');
code = code.replace(/(\nø)+(?=\n)/g, '\n');
if (crlf) {
code = code.replace('\n', '\r\n');
}
fs.writeFileSync(f, code);
}
function strip_dir(dir)
{
for (let file of fs.readdirSync(dir)) {
let path = `${dir}/${file}`;
if (fs.lstatSync(path).isDirectory()) {
strip_dir(path);
} else if (file.endsWith('.c')) {
strp_file(path);
}
}
}
if (process.argv.length < 3) {
console.log('USAGE: node strip.js directory');
process.exit(1);
}
strip_dir(process.argv[2]);