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

Function AddScriptBlockToScript

editor/ObjCScript.cpp:601–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

599#define SCRIPT_FORMAT "// %s\r\n//\t<comments here>\r\n%s\r\n\r\n\r\nendscript\r\n\r\n\r\n"
600
601char *AddScriptBlockToScript(char *script, const char *newname, const char *type_str) {
602 char *newsrc, *strline;
603 char newhdr[128];
604 char newblk[384];
605 int slot, line = 0, type = 0;
606
607 strline = script;
608 while (strline) {
609 line++;
610 strline = strchr(strline, '\n');
611 if (strline)
612 strline++;
613 }
614 if (!strcmp(type_str, "object"))
615 type = REF_OBJTYPE;
616 else if (!strcmp(type_str, "trigger"))
617 type = REF_TRIGTYPE;
618 else if (!strcmp(type_str, "level"))
619 type = REF_LEVELTYPE;
620
621 sprintf(newhdr, SCRHDR_FORMAT, type_str, newname);
622 sprintf(newblk, SCRIPT_FORMAT, newname, newhdr);
623
624 newsrc = (char *)mem_malloc(strlen(script) + strlen(newblk) + 1);
625 if (!newsrc) {
626 mprintf(1, "Allocation failure in creating new script buffer.\n");
627 return NULL;
628 }
629
630 sprintf(newsrc, "%s%s", script, newblk);
631 slot = AddScriptToList((char *)newname, type, false);
632 Script_names[slot].line = line;
633
634 return newsrc;
635}
636
637#define EVT_STATEMENT "\r\n\r\nevent '%s'\r\n//insert code here\r\ncomplete\r\n"
638

Callers 2

OnAddScriptMethod · 0.85
OnScriptselAddMethod · 0.85

Calls 1

AddScriptToListFunction · 0.85

Tested by

no test coverage detected