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

Function AddMessageToList

scripts/Y2K.cpp:160–192  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

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

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected