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

Function AddMessageToList

scripts/ChrisTest.cpp:175–207  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

173
174// Adds a message to the list
175int AddMessageToList(char *name, char *msg) {
176 int pos;
177
178 // Make sure there is room in the list
179 if (num_messages >= MAX_SCRIPT_MESSAGES)
180 return false;
181
182 // Allocate memory for this message entry
183 pos = num_messages;
184 message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage));
185 if (message_list[pos] == NULL)
186 return false;
187
188 // Allocate memory for the message name
189 message_list[pos]->name = (char *)malloc(strlen(name) + 1);
190 if (message_list[pos]->name == NULL) {
191 free(message_list[pos]);
192 return false;
193 }
194 strcpy(message_list[pos]->name, name);
195
196 // Allocate memory for the message name
197 message_list[pos]->message = (char *)malloc(strlen(msg) + 1);
198 if (message_list[pos]->message == NULL) {
199 free(message_list[pos]->name);
200 free(message_list[pos]);
201 return false;
202 }
203 strcpy(message_list[pos]->message, msg);
204 num_messages++;
205
206 return true;
207}
208
209// Removes any whitespace padding from the end of a string
210void RemoveTrailingWhitespace(char *s) {

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected