Adds a message to the list
| 146 | |
| 147 | // Adds a message to the list |
| 148 | int AddMessageToList(char *name, char *msg) { |
| 149 | int pos; |
| 150 | |
| 151 | // Make sure there is room in the list |
| 152 | if (num_messages >= MAX_SCRIPT_MESSAGES) |
| 153 | return false; |
| 154 | |
| 155 | // Allocate memory for this message entry |
| 156 | pos = num_messages; |
| 157 | message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage)); |
| 158 | if (message_list[pos] == NULL) |
| 159 | return false; |
| 160 | |
| 161 | // Allocate memory for the message name |
| 162 | message_list[pos]->name = (char *)malloc(strlen(name) + 1); |
| 163 | if (message_list[pos]->name == NULL) { |
| 164 | free(message_list[pos]); |
| 165 | return false; |
| 166 | } |
| 167 | strcpy(message_list[pos]->name, name); |
| 168 | |
| 169 | // Allocate memory for the message name |
| 170 | message_list[pos]->message = (char *)malloc(strlen(msg) + 1); |
| 171 | if (message_list[pos]->message == NULL) { |
| 172 | free(message_list[pos]->name); |
| 173 | free(message_list[pos]); |
| 174 | return false; |
| 175 | } |
| 176 | strcpy(message_list[pos]->message, msg); |
| 177 | num_messages++; |
| 178 | |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | // Removes any whitespace padding from the end of a string |
| 183 | void RemoveTrailingWhitespace(char *s) { |