Skip to content

Commit 5b16028

Browse files
committed
add the command line "--out=<path>" #17
1 parent 5a1761a commit 5b16028

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ void printHelp()
4141
std::cout << "Set the input file to be compiled" << std::endl;
4242
std::cout << "\tcodeGGcompiler --in=<path>" << std::endl << std::endl;
4343

44+
std::cout << "Set the output file (default is the input path+.cg)" << std::endl;
45+
std::cout << "\tcodeGGcompiler --out=<path>" << std::endl << std::endl;
46+
4447
std::cout << "Print the version (and do nothing else)" << std::endl;
4548
std::cout << "\tcodeGGcompiler --version" << std::endl << std::endl;
4649

@@ -63,6 +66,7 @@ int main(int argc, char **argv)
6366
}
6467

6568
std::string fileInPath;
69+
std::string fileOutPath;
6670

6771
std::vector<std::string> commands(argv, argv + argc);
6872

@@ -103,6 +107,11 @@ int main(int argc, char **argv)
103107
fileInPath = splitedCommand[1];
104108
continue;
105109
}
110+
if ( splitedCommand[0] == "--out")
111+
{
112+
fileOutPath = splitedCommand[1];
113+
continue;
114+
}
106115
}
107116

108117
//Unknown command
@@ -115,6 +124,10 @@ int main(int argc, char **argv)
115124
std::cout << "No input file !" << std::endl;
116125
return -1;
117126
}
127+
if ( fileOutPath.empty() )
128+
{
129+
fileOutPath = fileInPath+".cg";
130+
}
118131

119132
///Opening files
120133
std::ifstream fileIn( fileInPath );
@@ -124,10 +137,10 @@ int main(int argc, char **argv)
124137
return -1;
125138
}
126139

127-
std::ofstream fileOutBinary( fileInPath+".cg", std::ios::binary | std::ios::trunc );
140+
std::ofstream fileOutBinary( fileOutPath, std::ios::binary | std::ios::trunc );
128141
if ( !fileOutBinary )
129142
{
130-
std::cout << "Can't write the file \""<< fileInPath <<".cg\"" << std::endl;
143+
std::cout << "Can't write the file \""<< fileOutPath <<".cg\"" << std::endl;
131144
return -1;
132145
}
133146
std::ofstream fileOutReadable( fileInPath+".rcg", std::ios::trunc );
@@ -138,6 +151,7 @@ int main(int argc, char **argv)
138151
}
139152

140153
std::cout << "Input file : \""<< fileInPath <<"\"" << std::endl;
154+
std::cout << "Output file : \""<< fileOutPath <<"\"" << std::endl;
141155

142156
///Creating default pool
143157
codeg::Pool defaultPool("global");

0 commit comments

Comments
 (0)