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

Function AddMessageToList

scripts/CellTestLevel.cpp:150–182  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

148
149// Adds a message to the list
150int AddMessageToList(char *name, char *msg) {
151 int pos;
152
153 // Make sure there is room in the list
154 if (num_messages >= MAX_SCRIPT_MESSAGES)
155 return false;
156
157 // Allocate memory for this message entry
158 pos = num_messages;
159 message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage));
160 if (message_list[pos] == NULL)
161 return false;
162
163 // Allocate memory for the message name
164 message_list[pos]->name = (char *)malloc(strlen(name) + 1);
165 if (message_list[pos]->name == NULL) {
166 free(message_list[pos]);
167 return false;
168 }
169 strcpy(message_list[pos]->name, name);
170
171 // Allocate memory for the message name
172 message_list[pos]->message = (char *)malloc(strlen(msg) + 1);
173 if (message_list[pos]->message == NULL) {
174 free(message_list[pos]->name);
175 free(message_list[pos]);
176 return false;
177 }
178 strcpy(message_list[pos]->message, msg);
179 num_messages++;
180
181 return true;
182}
183
184// Removes any whitespace padding from the end of a string
185void RemoveTrailingWhitespace(char *s) {

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected