2
* msvc-generate.js - string transformation
4
* Copyright (C) 2008-2012 Alon Bar-Lev <alon.barlev@gmail.com>
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are met:
11
* o Redistributions of source code must retain the above copyright notice,
12
* this list of conditions and the following disclaimer.
13
* o Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
16
* o Neither the name of the Alon Bar-Lev nor the names of its
17
* contributors may be used to endorse or promote products derived from
18
* this software without specific prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
35
var fso = new ActiveXObject("Scripting.FileSystemObject");
38
var files = new Array();
39
var env = new Array();
41
function initialize() {
42
for (var i=0;i<WScript.Arguments.length;i++) {
43
var arg = WScript.Arguments(i);
44
if (arg.match(/^--input=(.*)$/)) {
47
else if (arg.match(/^--output=(.*)$/)) {
50
else if (arg.match(/^--config=(.*)$/)) {
51
files.push(RegExp.$1);
53
else if (arg.match(/^--var=([^=]*)=(.*)$/)) {
54
env[RegExp.$1] = RegExp.$2;
59
function process_config(vars, file) {
61
var fin = fso.OpenTextFile(file, ForReading);
63
while (!fin.AtEndOfStream) {
64
var content = fin.ReadLine();
65
if (content.match(/^[ \t]*define\(\[(.*)\],[ \t]*\[(.*)\]\)[ \t]*/)) {
66
vars[RegExp.$1] = RegExp.$2;
71
throw new Error(1, "Cannot process '" + file + "'.");
75
function process_file(vars, input, output) {
76
var fin = fso.OpenTextFile(input, ForReading);
77
var fout = fso.CreateTextFile(output);
78
var content = fin.ReadAll();
81
content = content.replace(new RegExp("@"+i+"@", "g"), vars[i]);
87
function build_vars() {
88
var vars = new Array();
89
for (var f in files) {
90
process_config(vars, files[f]);
102
var vars = build_vars();
113
WScript.Echo("ERROR: when procssing " + output + ": " + e.description);