This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathareaconvert.c
232 lines (192 loc) · 5.63 KB
/
areaconvert.c
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
* Copyright Matt Goff (Kline) 2009
* If you use my code, please give credit where it is due.
* Support provided at www.ackmud.net
*/
#include "h/areaconvert.h"
/* Store variables for all formats we will support, just don't write the ones we don't need later :) */
/*
* format: ack431 format: ackfuss
*
* #AREA #AREA
* name Revision
* Q -- revision CanRead none~
* K -- keyword CanWrite none~
* L -- level_label Flags EOL~
* N -- ignore Keyword none~
* I -- min_level, max_level LevLabel none~
* V -- min_vnum, max_vnum LevRange 1 20
* X -- offset Name none~
* F -- reset_rate Owner none~
* U -- reset_msg ResetMsg none~
* O -- owner ResetRate 15
* R -- can_read VnumRange 1 100
* W -- can_write End
* T -- flag TELEPORT
* P -- flag PAY_AREA
* M -- flag NO_ROOM_AFF
* B -- flag BUILDING
* S -- flag NO_SHOW
*/
area_data area;
list<room_data *> room_list;
list<npc_data *> npc_list;
list<obj_data *> obj_list;
list<shop_data *> shop_list;
list<reset_data *> reset_list;
int main( int argc, char *argv[] )
{
string filename, source, dest;
ifstream infile;
ofstream outfile;
int typein = TYPE_NONE, typeout = TYPE_NONE;
if ( argc < 2 || argc > 4 )
{
display_help();
return 0;
}
if ( argc >= 2 )
filename = argv[1];
if ( argc >= 3 )
source = argv[2];
if ( argc == 4 )
dest = argv[3];
if ( !infile_init(filename, infile) || !outfile_init(filename, outfile) )
{
cleanup_outfile(filename);
return 0;
}
if ( !typein_init(source, typein) || !typeout_init(dest, typeout) )
{
cleanup_outfile(filename);
return 0;
}
if ( typein == typeout )
{
cout << "You can not have the same source and destination format. Aborting." << endl;
cleanup_outfile(filename);
return 0;
}
process_infile(infile, typein);
flag_handler(typein, typeout);
process_outfile(outfile, typein, typeout);
infile.close();
outfile.close();
shutdown_cleanup();
return 0;
}
void display_help( void )
{
cout << endl << STRING_VERS << endl;
cout << STRING_SPACER << endl;
cout << "areaconvert filename [source format] [dest format]" << endl;
cout << STRING_SPACER << endl;
cout << "filename will be saved as filename.converted" << endl;
cout << "default options are listed in (parenthesis)" << endl;
cout << STRING_SPACER << endl;
cout << "if a bit/flag is not converted you will receive" << endl;
cout << "a list of them so you may manually attempt to" << endl;
cout << STRING_SPACER << endl;
cout << STRING_SUPPORTED_SRC << endl;
cout << STRING_SUPPORTED_DST << endl << endl;
return;
}
void cleanup_outfile( string filename )
{
string cmd = "rm -f ";
filename += ".converted";
cmd += filename; /* system returns different values on different platforms */
if ( system(cmd.c_str()) ) {} /* so we wrap it inside an if() to silence ignore the return result */
return;
}
bool infile_init( string filename, ifstream &file )
{
file.open(filename.c_str(), ios::in);
if ( file.is_open() )
return true;
cout << "Unable to open input file [" << filename << "]. Aborting." << endl;
return false;
}
bool outfile_init( string filename, ofstream &file )
{
filename += ".converted";
file.open(filename.c_str(), ios::out);
if ( file.is_open() )
return true;
cout << "Unable to open output file [" << filename << "]. Aborting." << endl;
return false;
}
bool typein_init( string name, int &type )
{
if ( name.empty() )
type = TYPE_INPUT_DEFAULT;
else
{
if ( name == "ack431" )
type = TYPE_ACK431;
if ( type == TYPE_NONE )
{
cout << "Unknown input type [" << name << "]. Aborting." << endl;
return false;
}
}
return true;
}
bool typeout_init( string name, int &type )
{
if ( name.empty() )
type = TYPE_OUTPUT_DEFAULT;
else
{
if ( name == "ackfuss" )
type = TYPE_ACKFUSS;
if ( type == TYPE_NONE )
{
cout << "Unknown output type [" << name << "]. Aborting." << endl;
return false;
}
}
return true;
}
void process_infile( ifstream &file, int type )
{
switch ( type )
{
case TYPE_ACK431: read_ack431(file); break;
}
return;
}
void process_outfile( ofstream &file, int typein, int typeout )
{
switch ( typeout )
{
case TYPE_ACKFUSS: write_ackfuss(file, typein); break;
}
return;
}
void shutdown_cleanup( void )
{
if ( !area.flags_found.empty() )
cout << "The following area flags were not converted: " << area.flags_found << endl;
else
cout << "Area converted successfully." << endl;
for_each(room_list.begin(), room_list.end(), DeleteObject());
for_each(npc_list.begin(), npc_list.end(), DeleteObject());
for_each(obj_list.begin(), obj_list.end(), DeleteObject());
for_each(shop_list.begin(), shop_list.end(), DeleteObject());
for_each(reset_list.begin(), reset_list.end(), DeleteObject());
return;
}
int str2int( string &str )
{
stringstream ss(str);
int i = 0;
ss >> i;
return i;
}
string int2str( int i )
{
stringstream ss;
ss << i;
return ss.str();
}