1
|
/*
|
2
|
Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
|
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
of this software and associated documentation files (the "Software"), to deal
|
5
|
in the Software without restriction, including without limitation the rights
|
6
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
copies of the Software, and to permit persons to whom the Software is
|
8
|
furnished to do so, subject to the following conditions:
|
9
|
|
10
|
The above copyright notice and this permission notice shall be included in
|
11
|
all copies or substantial portions of the Software.
|
12
|
|
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
SOFTWARE.
|
20
|
*/
|
21
|
|
22
|
using System;
|
23
|
using System.Text;
|
24
|
using System.IO;
|
25
|
|
26
|
namespace PreProcess
|
27
|
{
|
28
|
class Program
|
29
|
{
|
30
|
static void preprocess(string dir, string filein, string fileout, string symbol, string classin, string classout)
|
31
|
{
|
32
|
fileout = Path.Combine(dir, fileout);
|
33
|
string[] contents = File.ReadAllLines(Path.Combine(dir, filein));
|
34
|
string symboldef = "#define " + symbol + "not";
|
35
|
bool equal = File.Exists(fileout);
|
36
|
TextReader oldversion = equal ? new StreamReader(fileout) : null;
|
37
|
for (int lineno = 0; lineno < contents.Length; lineno++)
|
38
|
{
|
39
|
if (contents[lineno].StartsWith(symboldef))
|
40
|
contents[lineno] = "#define " + symbol;
|
41
|
else
|
42
|
contents[lineno] = contents[lineno].Replace(classin, classout);
|
43
|
if (equal)
|
44
|
equal = contents[lineno] == oldversion.ReadLine();
|
45
|
}
|
46
|
if (equal && oldversion.ReadLine() == null)
|
47
|
{
|
48
|
Console.Error.WriteLine("File {0} is up-to-date", fileout);
|
49
|
return;
|
50
|
}
|
51
|
File.WriteAllLines(fileout + "-new", contents);
|
52
|
if (oldversion != null)
|
53
|
{
|
54
|
oldversion.Close();
|
55
|
File.Replace(fileout + "-new", fileout, fileout + ".bak");
|
56
|
Console.Error.WriteLine("Updated {0}", fileout);
|
57
|
}
|
58
|
else
|
59
|
{
|
60
|
File.Move(fileout + "-new", fileout);
|
61
|
Console.Error.WriteLine("Created {0}", fileout);
|
62
|
}
|
63
|
}
|
64
|
static void Main(string[] args)
|
65
|
{
|
66
|
System.Environment.CurrentDirectory = @"..\..\..\C5";
|
67
|
preprocess("trees", "RedBlackTreeSet.cs", "RedBlackTreeBag.cs", "BAG", "TreeSet", "TreeBag");
|
68
|
preprocess("arrays", "ArrayList.cs", "HashedArrayList.cs", "HASHINDEX", "ArrayList", "HashedArrayList");
|
69
|
preprocess("linkedlists", "LinkedList.cs", "HashedLinkedList.cs", "HASHINDEX", "LinkedList", "HashedLinkedList");
|
70
|
}
|
71
|
}
|
72
|
}
|