Adds a message to the list
| 1485 | |
| 1486 | // Adds a message to the list |
| 1487 | int AddMessageToList(char *name, char *msg) { |
| 1488 | int pos; |
| 1489 | |
| 1490 | // Make sure there is room in the list |
| 1491 | if (num_messages >= MAX_SCRIPT_MESSAGES) |
| 1492 | return false; |
| 1493 | |
| 1494 | // Allocate memory for this message entry |
| 1495 | pos = num_messages; |
| 1496 | message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage)); |
| 1497 | if (message_list[pos] == NULL) |
| 1498 | return false; |
| 1499 | |
| 1500 | // Allocate memory for the message name |
| 1501 | message_list[pos]->name = (char *)malloc(strlen(name) + 1); |
| 1502 | if (message_list[pos]->name == NULL) { |
| 1503 | free(message_list[pos]); |
| 1504 | return false; |
| 1505 | } |
| 1506 | strcpy(message_list[pos]->name, name); |
| 1507 | |
| 1508 | // Allocate memory for the message name |
| 1509 | message_list[pos]->message = (char *)malloc(strlen(msg) + 1); |
| 1510 | if (message_list[pos]->message == NULL) { |
| 1511 | free(message_list[pos]->name); |
| 1512 | free(message_list[pos]); |
| 1513 | return false; |
| 1514 | } |
| 1515 | strcpy(message_list[pos]->message, msg); |
| 1516 | num_messages++; |
| 1517 | |
| 1518 | return true; |
| 1519 | } |
| 1520 | |
| 1521 | // Removes any whitespace padding from the end of a string |
| 1522 | void RemoveTrailingWhitespace(char *s) { |