add command line options
This commit is contained in:
parent
874a8f21f8
commit
572e28c32f
49
main.cpp
49
main.cpp
@ -17,13 +17,58 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
using namespace Mandelbrot;
|
using namespace Mandelbrot;
|
||||||
|
|
||||||
int main()
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Graphics g = Graphics(1800, 1200, "Mandelbrot set visualizer");
|
char c;
|
||||||
|
std::string targ, iarg;
|
||||||
|
int tcount = 0;
|
||||||
|
int maxiter = 0;
|
||||||
|
|
||||||
|
while ((c = getopt(argc, argv, "t::i::")) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 't':
|
||||||
|
targ = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
iarg = optarg;
|
||||||
|
break;
|
||||||
|
case ':':
|
||||||
|
std::cout << "option needs a value." << std::endl;
|
||||||
|
exit(1);
|
||||||
|
case '?':
|
||||||
|
if (optopt == 't' || optopt == 'i')
|
||||||
|
fprintf(stderr, "Option -%c requires an argument.\n",
|
||||||
|
optopt);
|
||||||
|
else if (isprint (optopt))
|
||||||
|
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
|
||||||
|
else
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unknown option character `\\x%x'.\n",
|
||||||
|
optopt);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
tcount = std::stoi(targ);
|
||||||
|
maxiter = std::stoi(iarg);
|
||||||
|
} catch(...) {
|
||||||
|
std::cout << "Invalid arguments." << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcount == 0 || tcount < 0)
|
||||||
|
tcount = 4;
|
||||||
|
|
||||||
|
if (maxiter == 0 || maxiter < 0)
|
||||||
|
maxiter = 100;
|
||||||
|
|
||||||
|
Graphics g = Graphics(1800, 1200, "Mandelbrot set visualizer", tcount, maxiter);
|
||||||
g.mainLoop();
|
g.mainLoop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user