Adds a message to the list
| 199 | |
| 200 | // Adds a message to the list |
| 201 | int AddMessageToList(char *name, char *msg) { |
| 202 | int pos; |
| 203 | |
| 204 | // Make sure there is room in the list |
| 205 | if (num_messages >= MAX_SCRIPT_MESSAGES) |
| 206 | return false; |
| 207 | |
| 208 | // Allocate memory for this message entry |
| 209 | pos = num_messages; |
| 210 | message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage)); |
| 211 | if (message_list[pos] == NULL) |
| 212 | return false; |
| 213 | |
| 214 | // Allocate memory for the message name |
| 215 | message_list[pos]->name = (char *)malloc(strlen(name) + 1); |
| 216 | if (message_list[pos]->name == NULL) { |
| 217 | free(message_list[pos]); |
| 218 | return false; |
| 219 | } |
| 220 | strcpy(message_list[pos]->name, name); |
| 221 | |
| 222 | // Allocate memory for the message name |
| 223 | message_list[pos]->message = (char *)malloc(strlen(msg) + 1); |
| 224 | if (message_list[pos]->message == NULL) { |
| 225 | free(message_list[pos]->name); |
| 226 | free(message_list[pos]); |
| 227 | return false; |
| 228 | } |
| 229 | strcpy(message_list[pos]->message, msg); |
| 230 | num_messages++; |
| 231 | |
| 232 | return true; |
| 233 | } |
| 234 | |
| 235 | // Removes any whitespace padding from the end of a string |
| 236 | void RemoveTrailingWhitespace(char *s) { |