-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.c
36 lines (28 loc) · 851 Bytes
/
common.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
#include <string.h>
#include "specs/common.h"
/*
converts a string into a COLOR enum.
parameters: string with a color written
returns: the color enum, with RED as default
if it is an invalid string
*/
COLOR conv_color ( const char *color ){
if (strcmp("red", color ) == 0 ) return RED;
else if (strcmp("green", color) == 0 ) return GREEN;
else if (strcmp("yellow", color) == 0) return YELLOW;
else if (strcmp("blue", color) == 0) return BLUE;
else return RED;
}
/*
converts a COLOR enum into a string.
parameters: a COLOR enum
returns: the string of the color, with
"none" returned if the COLOR is invalid
*/
char *color_to_string (COLOR color) {
if (color == RED) return "red";
else if (color == BLUE) return "blue";
else if (color == GREEN) return "green";
else if (color == YELLOW) return "yellow";
else return "none";
}