Dumb-ways-to-memorize
2D game
mystrings.h
Go to the documentation of this file.
1 #ifndef __MYSTRINGS_H
2 #define __MYSTRINGS_H
3 
4 #define ALLOC_STR(X) ( (char *) malloc(sizeof(char)*X) )
5 
6 #include <jsmn.h>
7 struct object_s;
8 
9 #define GAME_STATE_SPLASH_STR "Splash"
10 #define GAME_STATE_START_STR "Start"
11 #define GAME_STATE_GUESS_STR "Guess"
12 #define GAME_STATE_CHOOSE_STR "Choose"
13 #define GAME_STATE_PLAYING_STR "Playing"
14 #define GAME_STATE_END_STR "End"
15 
16 /**
17  * Loads string data from a file.
18  *
19  * @param [in,out] file If non-null, filename of the file.
20  *
21  * @return null if it fails, else a char*.
22  *
23  * @author Anthony Rios
24  * @date 1/30/2016
25  */
26 char * FileToString(char *file);
27 
28 /**
29  * Type string from JSON string.
30  *
31  * @param Type The type.
32  *
33  * @return null if it fails, else a char*.
34  *
35  * @author Anthony Rios
36  * @date 1/30/2016
37  */
38 char * TypeFromJSON(jsmntype_t Type);
39 
40 /**
41  * Jsmn to string.
42  *
43  * @param [in,out] token If non-null, the token.
44  * @param [in,out] g_str If non-null, the global string.
45  *
46  * @return null if it fails, else a char*.
47  *
48  * @author Anthony Rios
49  * @date 1/30/2016
50  */
51 char * JsmnToString(jsmntok_t *token, char *g_str);
52 
53 /**
54  * Searches for the a value in the object that matches the key string given.
55  * Recursive.
56  *
57  * @param [in,out] obj If non-null, the object.
58  * @param [in,out] key If non-null, the key.
59  * @param [in,out] g_str If non-null, the string.
60  *
61  * @return null if it fails, else the found value.
62  *
63  * @author Anthony Rios
64  * @date 3/25/2016
65  */
66 char * FindValue(struct object_s * obj, char *key, char *g_str);
67 
68 /**
69  * Jsmn to int.
70  *
71  * @param [in,out] token If non-null, the token.
72  * @param [in,out] str If non-null, the string.
73  * @param [in,out] dst If non-null, destination for the value.
74  *
75  * @author Anthony Rios
76  * @date 2/28/2016
77  */
78 void JsmnToInt(jsmntok_t *token, char *str, int *dst);
79 
80 /**
81  * String to int.
82  *
83  * @param [in,out] str If non-null, the string.
84  *
85  * @return An int.
86  *
87  * @author Anthony Rios
88  * @date 2/28/2016
89  */
90 int StrToInt(char* str);
91 
92 /**
93  * Character to int. A cheap switch statement.
94  *
95  * @param c The character.
96  *
97  * @return An int.
98  *
99  * @author Anthony Rios
100  * @date 2/28/2016
101  */
102 int CharToInt(char c);
103 
104 /**
105  * Searches for the first key that matches given gPlayerName, through through tokens & g_str.
106  *
107  * @param [in,out] token The token.
108  * @param [in,out] key The key.
109  * @param [in,out] g_str The string to get from.
110  *
111  * @return null if it fails, else the found key.
112  *
113  * @author Junji
114  * @date 1/30/2016
115  */
116 jsmntok_t * FindKey(jsmntok_t *token, char *key, char *g_str);
117 
118 
119 /**
120  * Convert file to useable, by setting the storage for string and jsmntokens, give a filename.
121  *
122  * @param [in,out] fileName If non-null, filename of the file.
123  * @param [in,out] parser If non-null, the parser.
124  * @param [in,out] stringStorage If non-null, the string storage.
125  * @param [in,out] jsmnStorage If non-null, the jsmn storage.
126  *
127  * @return The file converted to useable.
128  *
129  * @author Anthony Rios
130  * @date 3/29/2016
131  */
132 int ConvertFileToUseable(char *fileName, jsmn_parser *parser, char **stringStorage, jsmntok_t **jsmnStorage);
133 
134 #endif
Definition: jsmn.h:40
jsmntype_t
Definition: jsmn.h:17
char * TypeFromJSON(jsmntype_t Type)
Definition: mystrings.c:140
jsmntok_t * FindKey(jsmntok_t *token, char *key, char *g_str)
Definition: mystrings.c:10
char * JsmnToString(jsmntok_t *token, char *g_str)
Definition: mystrings.c:34
char * FileToString(char *file)
Definition: mystrings.c:159
char * FindValue(struct object_s *obj, char *key, char *g_str)
Definition: mystrings.c:53
int CharToInt(char c)
Definition: mystrings.c:121
int ConvertFileToUseable(char *fileName, jsmn_parser *parser, char **stringStorage, jsmntok_t **jsmnStorage)
Definition: mystrings.c:192
int StrToInt(char *str)
Definition: mystrings.c:92
void JsmnToInt(jsmntok_t *token, char *str, int *dst)
Definition: mystrings.c:84