blob: 9a411a337047551df5fb4770aed65b8da91d6550 (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
import java.io.*;
import java.util.StringTokenizer;
/** This class converts the #define statements into java
* public static final int statements.
*
* Additionally it converts some mframe_t statements, when the filename
* starts with "jake2/game/M_" .
*/
public class ConvertDefines
{
public static String convertDefine(String in)
{
StringBuffer out= new StringBuffer();
StringTokenizer tk= new StringTokenizer(in);
while (tk.hasMoreElements())
{
String token= tk.nextToken();
// finds the define
if (token.equals("#define"))
{
out.append(" public final static int ");
out.append(tk.nextToken());
out.append("= ");
out.append(tk.nextToken());
out.append(";\t");
// append rest and out.
while (tk.hasMoreElements())
{
out.append(tk.nextToken());
out.append(" ");
}
}
else
{
out.append(token);
out.append(" ");
}
}
return out.toString();
}
/********************************************/
public static void main(String args[])
{
try
{
System.out.println("\n".trim().length());
String line;
String filename;
boolean m_doc = true;
if (args.length == 0)
{
filename= "jake2/Defines.java";
}
else
filename= args[0];
if (filename.startsWith("jake2/game/M_"))
m_doc = true;
else m_doc = false;
FileWriter fw= new FileWriter(filename + ".new");
FileReader fr= new FileReader(filename);
BufferedReader br= new BufferedReader(fr);
while (br.ready())
{
line= br.readLine();
if (line.indexOf("#define") != -1)
fw.write(convertDefine(line) + "\n");
else if (m_doc && line.trim().startsWith("mframe_t ") && line.indexOf("new") == -1)
{
fw.write(" static " + line + " new mframe_t[] \n");
while (br.ready())
{
line= br.readLine();
// opening brace
if (line.indexOf("{")!=-1)
fw.write(line + "\n");
// opening brace
else if (line.indexOf("}")!=-1)
{
fw.write(line + "\n");
break;
}
else if (line.trim().length()==0)
fw.write("\n");
else
{
String comma ="";
String line1 = line;
if (line.endsWith(","))
{
line1=line.substring(0,line1.length()-1);
comma = ",";
}
fw.write("\tnew mframe_t (" + line1 + ")" + comma + "\n");
}
}
}
else if (m_doc && line.trim().startsWith("mmove_t"))
{
int pos1 = line.indexOf("{");
int pos2 = line.indexOf("}");
String seg1 = line.substring(0,pos1);
String seg2 = line.substring(pos1+1, pos2);
String seg3 = line.substring(pos2+1, line.length());
fw.write("static " + seg1 + " new mmove_t (" + seg2 + ")" + seg3 + "\n\n");
//fw.write(line);
}
else
fw.write(line + "\n");
}
fr.close();
fw.close();
//System.out.println(convertDefine("#define IT_WEAPON 1 // use makes active weapon"));
//System.out.println(convertDefine("#define IT_AMMO 2"));
}
catch (Exception e)
{
System.err.println("Exception:" + e);
}
}
}
|