/* Copyright (C) 2026 iceyrazor This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . */ #include #include #include #define str_size 30000 void str_replace(char* str, char* replace, char* new) { char* findstr = strstr(str, replace); if (findstr) { char right[str_size]; strncpy(right, &findstr[strlen(replace)], str_size); findstr[0] = '\0'; strncat(str, new, str_size); strncat(str, right, str_size); } } int main(int argc, char** argv) { // open mod-loader.def.c char buffer[str_size] = { 0 }; FILE* mod_loader_file; mod_loader_file = fopen("src/mod-loader.def.c", "r"); fread(buffer, str_size, 1, mod_loader_file); fclose(mod_loader_file); buffer[str_size - 1] = '\0'; //look for mods. DIR* dir; struct dirent* ent; char include_mods_str[str_size]; char init_mods_str[str_size]; if ((dir = opendir("src/mods")) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir(dir)) != NULL) { if( strcmp(ent->d_name,".") == 0 || strcmp(ent->d_name,"..") == 0 ) continue; strncat(include_mods_str,"#include \"mods/",str_size); strncat(include_mods_str,ent->d_name,str_size); strncat(include_mods_str,"\"\n",str_size); char *name=&(ent->d_name[4]); char *name_stripped=strstr(name,".c"); name_stripped[0]='\0'; strncat(init_mods_str,"init_",str_size); strncat(init_mods_str,name,str_size); strncat(init_mods_str,"();\n",str_size); } closedir(dir); } else { /* could not open directory */ perror(""); } str_replace(buffer, "//", include_mods_str); str_replace(buffer, "//", init_mods_str); mod_loader_file=fopen("src/mod-loader.c","w"); fwrite(buffer,sizeof(char),strlen(buffer),mod_loader_file); fclose(mod_loader_file); return 0; }