@@ -50,7 +50,7 @@ std::string GetFilename(const std::string& str);
50
50
FileCategories GetFilecategory (const std::string& in_file);
51
51
FileTypes GetFiletype (const std::string& in_file, std::string& out_extension);
52
52
void PrintReaderError (const std::string data);
53
- int ReaderWriteToFile (const std::string& in, const std::string& out, FileTypes in_type, lcf::EngineVersion engine);
53
+ int ReaderWriteToFile (const std::string& in, const std::string& out, FileTypes in_type, lcf::EngineVersion engine, std::string encoding );
54
54
55
55
int main (int argc, char ** argv)
56
56
{
@@ -60,12 +60,14 @@ int main(int argc, char** argv)
60
60
std::cerr << " Usage: " << argv[0 ] << " [--2k] [--2k3] file1 [... fileN]" << std::endl;
61
61
std::cerr << " \t --2k: Treat files as RPG 2000" << std::endl;
62
62
std::cerr << " \t --2k3: Treat files as RPG 2003 (default)" << std::endl;
63
+ std::cerr << " \t --encoding N: Use encoding N as the file encoding" << std::endl;
63
64
64
65
return 1 ;
65
66
}
66
67
67
68
std::vector<std::string> infiles;
68
69
std::string outfile;
70
+ std::string encoding;
69
71
70
72
FileCategories category = FileCategory_Invalid;
71
73
FileTypes type;
@@ -82,6 +84,10 @@ int main(int argc, char** argv)
82
84
engine = lcf::EngineVersion::e2k3;
83
85
continue ;
84
86
}
87
+ if (!std::strcmp (argv[i], " --encoding" ) && (++i < argc)) {
88
+ encoding = argv[i];
89
+ continue ;
90
+ }
85
91
if (category == FileCategory_Invalid) {
86
92
category = GetFilecategory (argv[i]);
87
93
if (category == FileCategory_Invalid) {
@@ -100,7 +106,7 @@ int main(int argc, char** argv)
100
106
outfile = GetFilename (*it);
101
107
type = GetFiletype (*it, extension);
102
108
outfile += extension;
103
- if (ReaderWriteToFile (*it, outfile, type, engine) != 0 ) {
109
+ if (ReaderWriteToFile (*it, outfile, type, engine, encoding ) != 0 ) {
104
110
errors++;
105
111
}
106
112
}
@@ -241,41 +247,39 @@ void PrintReaderError(const std::string data)
241
247
}
242
248
243
249
/* * Takes data from in and writes converted data into out using liblcf. */
244
- int ReaderWriteToFile (const std::string& in, const std::string& out, FileTypes in_type, lcf::EngineVersion engine)
250
+ int ReaderWriteToFile (const std::string& in, const std::string& out, FileTypes in_type, lcf::EngineVersion engine, std::string encoding )
245
251
{
246
252
std::string path = GetPath (in) + " /" ;
247
- std::string encoding = " " ;
248
253
254
+ if (encoding.empty ()) {
249
255
#ifdef _WIN32
250
- encoding = lcf::ReaderUtil::GetEncoding (path + " RPG_RT.ini" );
256
+ encoding = lcf::ReaderUtil::GetEncoding (path + " RPG_RT.ini" );
251
257
#else
252
- DIR* dir = opendir (path.c_str ());
253
- if (dir) {
254
- struct dirent * ent;
255
- while ((ent = ::readdir (dir)) != NULL ) {
256
- if (ent->d_name [0 ] == ' .' ) { continue ; }
257
- std::string name = ent->d_name ;
258
-
259
- std::transform (name.begin (), name.end (), name.begin (), ::tolower);
260
-
261
- if (name == " rpg_rt.ini" ) {
262
- encoding = lcf::ReaderUtil::GetEncoding (path + ent->d_name );
263
- closedir (dir);
264
- goto dirsuccess;
265
- break ;
258
+ DIR* dir = opendir (path.c_str ());
259
+ if (dir) {
260
+ struct dirent * ent;
261
+ while ((ent = ::readdir (dir)) != NULL ) {
262
+ if (ent->d_name [0 ] == ' .' ) { continue ; }
263
+ std::string name = ent->d_name ;
264
+
265
+ std::transform (name.begin (), name.end (), name.begin (), ::tolower);
266
+
267
+ if (name == " rpg_rt.ini" ) {
268
+ encoding = lcf::ReaderUtil::GetEncoding (path + ent->d_name );
269
+ break ;
270
+ }
266
271
}
272
+ closedir (dir);
267
273
}
268
- closedir (dir);
269
- }
270
- else {
271
- std::cerr << " Failed opening directory " << path << std::endl;
274
+ else {
275
+ std::cerr << " Failed opening directory " << path << std::endl;
276
+ }
277
+ # endif
272
278
}
273
279
274
280
if (encoding.empty ()) {
275
281
encoding = lcf::ReaderUtil::GetLocaleEncoding ();
276
282
}
277
- dirsuccess:
278
- #endif
279
283
280
284
switch (in_type)
281
285
{
0 commit comments