summaryrefslogtreecommitdiff
path: root/src/mansdl-applyArgs.cc
blob: 4f8efd5338d91d986580753e673033138e834e47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* 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;
}