diff --git a/main.cpp b/main.cpp index f61ac57..f662156 100644 --- a/main.cpp +++ b/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 . */ +#include #include "graphics.h" 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(); return 0;