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

Function AddMessageToList

scripts/RudeAwakening.cpp:237–269  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

235
236// Adds a message to the list
237int AddMessageToList(char *name, char *msg) {
238 int pos;
239
240 // Make sure there is room in the list
241 if (num_messages >= MAX_SCRIPT_MESSAGES)
242 return false;
243
244 // Allocate memory for this message entry
245 pos = num_messages;
246 message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage));
247 if (message_list[pos] == NULL)
248 return false;
249
250 // Allocate memory for the message name
251 message_list[pos]->name = (char *)malloc(strlen(name) + 1);
252 if (message_list[pos]->name == NULL) {
253 free(message_list[pos]);
254 return false;
255 }
256 strcpy(message_list[pos]->name, name);
257
258 // Allocate memory for the message name
259 message_list[pos]->message = (char *)malloc(strlen(msg) + 1);
260 if (message_list[pos]->message == NULL) {
261 free(message_list[pos]->name);
262 free(message_list[pos]);
263 return false;
264 }
265 strcpy(message_list[pos]->message, msg);
266 num_messages++;
267
268 return true;
269}
270
271// Removes any whitespace padding from the end of a string
272void RemoveTrailingWhitespace(char *s) {

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected