MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / AddMessageToList

Function AddMessageToList

scripts/merc5.cpp:1035–1067  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

1033
1034// Adds a message to the list
1035int AddMessageToList(char *name, char *msg) {
1036 int pos;
1037
1038 // Make sure there is room in the list
1039 if (num_messages >= MAX_SCRIPT_MESSAGES)
1040 return false;
1041
1042 // Allocate memory for this message entry
1043 pos = num_messages;
1044 message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage));
1045 if (message_list[pos] == NULL)
1046 return false;
1047
1048 // Allocate memory for the message name
1049 message_list[pos]->name = (char *)malloc(strlen(name) + 1);
1050 if (message_list[pos]->name == NULL) {
1051 free(message_list[pos]);
1052 return false;
1053 }
1054 strcpy(message_list[pos]->name, name);
1055
1056 // Allocate memory for the message name
1057 message_list[pos]->message = (char *)malloc(strlen(msg) + 1);
1058 if (message_list[pos]->message == NULL) {
1059 free(message_list[pos]->name);
1060 free(message_list[pos]);
1061 return false;
1062 }
1063 strcpy(message_list[pos]->message, msg);
1064 num_messages++;
1065
1066 return true;
1067}
1068
1069// Removes any whitespace padding from the end of a string
1070void RemoveTrailingWhitespace(char *s) {

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected