Created
September 23, 2010 10:43
-
-
Save DanielG/593458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
// Very simple c/++ preprocessor for replacing binary(0b10101) with the hexer decimal representation | |
var fs = require('fs'); | |
process.argv = process.argv.slice(2, process.argv.length); | |
console.log('Arguments:', process.argv); | |
process.argv.forEach(function(val, index, array){ | |
if(val.match(/[a-zA-Z._-]*/)) { | |
process.nextTick(function (){ | |
fs.readFile(val, function (err, data){ | |
if (err) throw err; | |
var data = data.toString().replace(/0b([01]*)/g, function (match, capture){ | |
var replace = parseInt(capture, 2).toString(16); | |
return '0x' + parseInt(capture, 2).toString(16); | |
}); | |
console.log('New data:', data); | |
fs.writeFile(val, data, function(err){ | |
if(err) throw err; | |
console.log('data written'); | |
}); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment