Skip to content

Commit 73dab34

Browse files
committedAug 9, 2016
Allow specifying location of colors.txt file
1 parent ab167d1 commit 73dab34

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed
 

Diff for: ‎TileGenerator.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,8 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
230230
{
231231
ifstream in;
232232
in.open(fileName.c_str(), ifstream::in);
233-
if (!in.is_open()) {
234-
return;
235-
}
233+
if (!in.is_open())
234+
throw std::runtime_error("Specified colors file could not be found.");
236235
parseColorsStream(in);
237236
}
238237

Diff for: ‎mapper.cpp

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* =====================================================================
3-
* Version: 1.0
4-
* Created: 22.08.2012 15:15:54
5-
* Author: Miroslav Bendík
6-
* Company: LinuxOS.sk
7-
* =====================================================================
8-
*/
9-
101
#include <cstdlib>
112
#include <getopt.h>
123
#include <iostream>
@@ -16,8 +7,6 @@
167
#include <stdexcept>
178
#include "TileGenerator.h"
189

19-
using namespace std;
20-
2110
void usage()
2211
{
2312
const char *usage_text = "minetestmapper [options]\n"
@@ -37,10 +26,17 @@ void usage()
3726
" --backend <backend>\n"
3827
" --geometry x:y+w+h\n"
3928
" --zoom <zoomlevel>\n"
29+
" --colors <colors.txt>\n"
4030
"Color format: '#000000'\n";
4131
std::cout << usage_text;
4232
}
4333

34+
std::string search_colors()
35+
{
36+
// TBD
37+
return "colors.txt";
38+
}
39+
4440
int main(int argc, char *argv[])
4541
{
4642
static struct option long_options[] =
@@ -61,14 +57,15 @@ int main(int argc, char *argv[])
6157
{"geometry", required_argument, 0, 'g'},
6258
{"min-y", required_argument, 0, 'a'},
6359
{"max-y", required_argument, 0, 'c'},
64-
{"zoom", required_argument, 0, 'z'}
60+
{"zoom", required_argument, 0, 'z'},
61+
{"colors", required_argument, 0, 'C'},
6562
};
6663

67-
string input;
68-
string output;
64+
std::string input;
65+
std::string output;
66+
std::string colors = "";
6967

7068
TileGenerator generator;
71-
generator.parseColorsFile("colors.txt");
7269
int option_index = 0;
7370
int c = 0;
7471
while (1) {
@@ -122,23 +119,23 @@ int main(int argc, char *argv[])
122119
generator.setBackend(optarg);
123120
break;
124121
case 'a': {
125-
istringstream iss;
122+
std::istringstream iss;
126123
iss.str(optarg);
127124
int miny;
128125
iss >> miny;
129126
generator.setMinY(miny);
130127
}
131128
break;
132129
case 'c': {
133-
istringstream iss;
130+
std::istringstream iss;
134131
iss.str(optarg);
135132
int maxy;
136133
iss >> maxy;
137134
generator.setMaxY(maxy);
138135
}
139136
break;
140137
case 'g': {
141-
istringstream geometry;
138+
std::istringstream geometry;
142139
geometry.str(optarg);
143140
int x, y, w, h;
144141
char c;
@@ -151,21 +148,27 @@ int main(int argc, char *argv[])
151148
}
152149
break;
153150
case 'z': {
154-
istringstream iss;
151+
std::istringstream iss;
155152
iss.str(optarg);
156153
int zoom;
157154
iss >> zoom;
158155
generator.setZoom(zoom);
159156
}
160157
break;
158+
case 'C':
159+
colors = optarg;
160+
break;
161161
default:
162162
exit(1);
163163
}
164164
}
165+
if(colors == "")
166+
colors = search_colors();
165167
try {
168+
generator.parseColorsFile(colors);
166169
generator.generate(input, output);
167170
} catch(std::runtime_error e) {
168-
std::cout<<"Exception: "<<e.what()<<std::endl;
171+
std::cerr << "Exception: " << e.what() << std::endl;
169172
return 1;
170173
}
171174
return 0;

0 commit comments

Comments
 (0)
Please sign in to comment.