MCPcopy Create free account
hub / github.com/TurningWheel/Barony / loadConfig

Function loadConfig

src/interface/interface.cpp:768–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

766-------------------------------------------------------------------------------*/
767
768int loadConfig(char* filename)
769{
770 char str[1024];
771 File* fp;
772 bool mallocd = false;
773
774 printlog("Loading config '%s'...\n", filename);
775
776 if ( strstr(filename, ".cfg") == NULL )
777 {
778 char* filename2 = filename;
779 filename = (char*) malloc(sizeof(char) * 256);
780 strcpy(filename, filename2);
781 mallocd = true;
782 strcat(filename, ".cfg");
783 }
784
785 // open the config file
786 if ( (fp = FileIO::open(filename, "rb")) == NULL )
787 {
788 printlog("note: config file '%s' does not exist!\n", filename);
789 defaultConfig(); //Set up the game with the default config.
790 return 0;
791 }
792
793 // read commands from it
794 while ( fp->gets2(str, 1024) != NULL )
795 {
796 if ( str[0] != '#' && str[0] != '\n' && str[0] != '\r' ) // if this line is not white space or a comment
797 {
798 // execute command
799 consoleCommand(str);
800 }
801 }
802 FileIO::close(fp);
803 if ( mallocd )
804 {
805 free(filename);
806 }
807
808 return 0;
809}
810
811int loadDefaultConfig()
812{

Callers 1

loadDefaultConfigFunction · 0.85

Calls 4

printlogFunction · 0.85
defaultConfigFunction · 0.85
consoleCommandFunction · 0.85
gets2Method · 0.80

Tested by

no test coverage detected