all-in-one: format source code

This commit is contained in:
Bert Belder 2017-09-09 20:53:35 +02:00
parent 6e1e6fc83e
commit 0534ee9077
2 changed files with 7 additions and 7 deletions

View File

@ -7,7 +7,7 @@ function load(filename) {
if (/[\/\\]/.test(filename)) if (/[\/\\]/.test(filename))
return fs.readFileSync(filename, 'utf8'); return fs.readFileSync(filename, 'utf8');
var PATH = [ '.', 'include', 'src' ]; var PATH = ['.', 'include', 'src'];
for (;;) { for (;;) {
var dir = PATH.shift(); var dir = PATH.shift();
try { try {
@ -50,14 +50,14 @@ function lines(filename) {
} }
function comment(s) { function comment(s) {
return ''; //'/* ' + s + '*/' return ''; //'/* ' + s + '*/'
} }
function include(line, filename) { function include(line, filename) {
var key = path.basename(filename).toLowerCase(); var key = path.basename(filename).toLowerCase();
if (included[key]) if (included[key])
return comment(line); return comment(line);
console.error("Including: " + key); console.error('Including: ' + key);
included[key] = true; included[key] = true;
return lines(filename); return lines(filename);
} }
@ -78,8 +78,8 @@ for (var i = 2; i < process.argv.length; i++) {
} }
var patterns = [ var patterns = [
{re : /^\s*#include\s*"([^"]*)".*$/, fn : include}, {re: /^\s*#include\s*"([^"]*)".*$/, fn: include},
{re : /^\s*#include\s*<([^"]*)>.*$/, fn : include_sys} {re: /^\s*#include\s*<([^"]*)>.*$/, fn: include_sys}
] ]
restart: for (var lno = 0; lno < source.length;) { restart: for (var lno = 0; lno < source.length;) {
@ -90,7 +90,7 @@ restart: for (var lno = 0; lno < source.length;) {
if (match) { if (match) {
var repl = pattern.fn.apply(null, match); var repl = pattern.fn.apply(null, match);
if (repl != null && repl !== line) { if (repl != null && repl !== line) {
source.splice.apply(source, [ lno, 1 ].concat(repl)); source.splice.apply(source, [lno, 1].concat(repl));
continue restart; continue restart;
} }
} }