summaryrefslogblamecommitdiff
path: root/src/mansdl-applyArgs.cc
blob: 4f8efd5338d91d986580753e673033138e834e47 (plain) (tree)











































































                                                                                                                                                                              
/* Include libraries */
#include <iostream>
#include <string>

/* Include header files */
#include "mansdl.hh"

bool mansdl::applyArgs(fractData* fd, const int argc, const char** argv) {
	if(argc > 1)
		for(int i = 1; i < argc; ++i) {
			std::string arg = argv[i];

			if(arg == "--help") {
				std::cout << "Usage:"                                                  << "\n" <<
				             "        mansdl [arguements]"                             << "\n" <<
				                                                                          "\n" <<
				             "Arguements(1):"                                          << "\n" << /* Arguements that don't require extra arguements */
				             "        --help  Displays this message"                   << "\n" <<
				                                                                          "\n" <<
					     "Arguements(2):"                                          << "\n" << /* Arguements that require extra arguements */
				             "        -f      Sets the fractal"                        << "\n" <<
				             "        -w      Sets the width of the calculated image"  << "\n" <<
				             "        -h      Sets the height of the calculated image" << "\n" <<
				             std::endl;

				return false;
			}

			else if(argc > i + 1) {
				if(arg == "-f") {
					++i;
					arg = argv[i];

					if(arg == "burningShip")
						fd->fract = burningShip;

					else if(arg == "julia")
						fd->fract = julia;

					else if(arg == "mandelbrot")
						fd->fract = mandelbrot;

					else if(arg == "mandelbrot3")
						fd->fract = mandelbrot3;

					else if(arg == "mandelbrot4")
						fd->fract = mandelbrot4;

					else if(arg == "mandelbrot5")
						fd->fract = mandelbrot5;

					else if(arg == "tricorn")
						fd->fract = tricorn;

					else
						std::cout << "\033[035m" << "WARNING!" << "\033[000m" << " Invalid fractal! Continuing with the Mandelbrot Set." << std::endl;
				}

				else if(arg == "-w") {
					++i;
					arg = argv[i];

					if(std::stoul(arg) <= fd->width)
						fd->width = std::stoul(arg);
				} else if(arg == "-h") {
					++i;
					arg = argv[i];

					if(std::stoul(arg) <= fd->height)
						fd->height = std::stoul(arg);
				}
			}
		}

	return true;
}