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

Function AddMessageToList

scripts/level13.cpp:1339–1371  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

1337
1338// Adds a message to the list
1339int AddMessageToList(char *name, char *msg) {
1340 int pos;
1341
1342 // Make sure there is room in the list
1343 if (num_messages >= MAX_SCRIPT_MESSAGES)
1344 return false;
1345
1346 // Allocate memory for this message entry
1347 pos = num_messages;
1348 message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage));
1349 if (message_list[pos] == NULL)
1350 return false;
1351
1352 // Allocate memory for the message name
1353 message_list[pos]->name = (char *)malloc(strlen(name) + 1);
1354 if (message_list[pos]->name == NULL) {
1355 free(message_list[pos]);
1356 return false;
1357 }
1358 strcpy(message_list[pos]->name, name);
1359
1360 // Allocate memory for the message name
1361 message_list[pos]->message = (char *)malloc(strlen(msg) + 1);
1362 if (message_list[pos]->message == NULL) {
1363 free(message_list[pos]->name);
1364 free(message_list[pos]);
1365 return false;
1366 }
1367 strcpy(message_list[pos]->message, msg);
1368 num_messages++;
1369
1370 return true;
1371}
1372
1373// Removes any whitespace padding from the end of a string
1374void RemoveTrailingWhitespace(char *s) {

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected