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

Function AddMessageToList

scripts/myPowerHouse.cpp:157–189  ·  view source on GitHub ↗

Adds a message to the list

Source from the content-addressed store, hash-verified

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

Callers 1

ReadMessageFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected