-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN.c
84 lines (73 loc) · 2.42 KB
/
MAIN.c
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
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include "shapes.h"
#include "IO.h"
#include "painting.h"
#include <string.h>
#include <time.h>
int main(int argc, char const *argv[]){
/*Pointer to the name of the txt file informed in execution and passed as
an argument in the main function*/
char const *fileNameTXT = argv[1];
//The string that will store the first word of a command in the txt file
char functionName[10];
//Variable that will store the image in a matrix
Image picture;
//The color that is set in the moment
Pixel currentColor;
//File pointer for the txt file
FILE *fileTXT;
//Opening the txt file for reading
fileTXT = fopen(fileNameTXT, "r");
if(fileTXT == NULL){
printf("Error in opening the txt file.\n");
exit(EXIT_FAILURE);
}
/*Setting the "seed" of the rand function to be the current time. This will
be useful in the randCurve function*/
srand(time(NULL));
/*Reading the first word of a command and calling its corresponding function
until the file ends (EOF)*/
while(fscanf(fileTXT, "%s", functionName) != EOF){
if (strcmp(functionName, "image") == 0){
picture = newImage(fileTXT);
}
else if (strcmp(functionName, "clear") == 0){
picture = clear(picture, fileTXT, currentColor);
}
else if (strcmp(functionName, "color") == 0){
currentColor = color(fileTXT, currentColor);
}
else if (strcmp(functionName, "line") == 0){
picture = line(picture, currentColor, fileTXT);
}
else if (strcmp(functionName, "polygon") == 0){
picture = polygon(picture, fileTXT, currentColor);
}
else if(strcmp(functionName, "rpolygon") == 0){
picture = regPolygon(picture, fileTXT, currentColor);
}
else if (strcmp(functionName, "circle") == 0){
picture = circle(picture, currentColor, fileTXT);
}
else if (strcmp(functionName, "rect") == 0){
picture = rect(picture, currentColor, fileTXT);
}
else if (strcmp(functionName, "fill") == 0){
picture = fill(picture, fileTXT, currentColor);
}
else if(strcmp(functionName, "curve") == 0){
picture = curve(picture, fileTXT, currentColor);
}
else if(strcmp(functionName, "randcurve") == 0){
picture = randCurve(picture, fileTXT, currentColor);
}
else if (strcmp(functionName, "save") == 0){
save(picture, fileTXT);
}
}
//Closing the txt file
fclose(fileTXT);
return 0;
}