Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » trouble loading config file

This thread is locked; no one can reply to it. rss feed Print
trouble loading config file
William Labbett
Member #4,486
March 2004
avatar

Hi,

just trying to get a config file to load.

Here's the bit of code which calls the load function :

/**********************************************************************/
   /**************** Section : load configuration file. ******************/
   /**********************************************************************/
   
   config_manager.load_config_file("configuration/tpos_configuration_file.cfg", log);
   
   if(config_manager.init_okay() != GREEN_FLAG)
   {
     /* add clear up code */
     return 0;
   }

Here's the class with the load function :

#SelectExpand
1class ConfigManagerClass 2{ 3 4 ALLEGRO_CONFIG *cfg; 5 6 int init_okay_flag; 7 8 public: 9 10 ConfigManagerClass() : cfg(NULL) 11 { 12 13 14 } 15 16 void load_config_file(const char *filename, Rabbit_Log& log) 17 { 18 cfg = al_load_config_file(filename); 19 20 log.write_message_number(); 21 log.write_string("About to load configuration file ("); 22 log.write_string(filename); 23 log.write_string(")."); 24 log.end_message(); 25 26 log.write_message_number(); 27 if( cfg == NULL ) 28 { 29 log.write_string("Failed to load it."); 30 init_okay_flag = RED_FLAG; 31 32 } 33 else 34 { 35 log.write_string("Loaded it successfully."); 36 init_okay_flag = GREEN_FLAG; 37 38 } 39 log.end_message(); 40 41 } 42 43 int get_integer(const char *key, int *integer_to_get) 44 { 45 const char *string = NULL; 46 47 string = al_get_config_value( cfg, NULL, "p1"); 48 49 if(string == NULL) 50 { 51 return ERROR_1; 52 } 53 else 54 { 55 return atoi(string); 56 } 57 58 } 59 60 61 int init_okay() 62 { 63 return init_okay_flag; 64 } 65 66};

Here's the log file :

MESSAGE :    0   : Log file opened
MESSAGE :    1   : Initialised Allegro System.
MESSAGE :    2   : Initialised true type font addon.
MESSAGE :    3   : Finished initialising InitialisationClass.
MESSAGE :    4   : Initialising Primes_Manager class.
MESSAGE :    5   : Initialised PhysFS successfully.
MESSAGE :    6   : Initialising Display.
MESSAGE :    7   : Unable to load font SIRCLIVE.ttf.
MESSAGE :    8   : Successfully initialised the Display.
MESSAGE :    9   : About to load configuration file (configuration/tpos_configuration_file.cfg).
MESSAGE :   10   : Failed to load it.

Here's my directory structure (for some evidence so you've something to go on) :
https://www.allegro.cc/files/attachment/609444
{"name":"609444","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/c\/fc0677891bf25af8316192bc2ff131f7.png","w":400,"h":256,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/c\/fc0677891bf25af8316192bc2ff131f7"}609444

{"name":"609445","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/d\/2d4eeb6dbf45968c2460959871e262c4.png","w":400,"h":149,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/d\/2d4eeb6dbf45968c2460959871e262c4"}609445

Any allegro code detectives fancy helping me work out why the cfg file won't load??

Chris Katko
Member #1,881
January 2002
avatar

Windows uses

folder\myfoler

*NIX uses:

folder/subfolder

So for windows you would write "folder\\myfolder" in the c string (two \\ = one because you're escaping the first backslash, IIRC)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

William Labbett
Member #4,486
March 2004
avatar

Cheers Chris :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

It's Allegro he's passing the string to, and it understands both separators I believe. Windows does too. *nix is case-sensitive, but that doesn't look like the problem either.

You can try posting your cfg file and we can look at it and try loading it ourselves, because your tpos_001 exe is in the directory above your config file, and so it looks like it should work. Oh yeah, please stop hiding your file name extensions, and attach the full size image next time, it's too hard to read.

Chris Katko
Member #1,881
January 2002
avatar

It's Allegro he's passing the string to, and it understands both separators I believe. Windows does too. *nix is case-sensitive, but that doesn't look like the problem either.

You sure about that? I'm pretty sure I've had (back)slashes, and "./subdirectory/file" vs /subdirectory/file" (no dot) both cause me problems in A4 and A5 before.

Otherwise, why would this exist?

char *fix_filename_slashes(char *path);

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

RPG Hacker
Member #12,492
January 2011
avatar

I always use forward slahes on Windows and never had problems with this before. Most native Windows C and C++ functions should treat / and \\ equally for pathes.

I'm pretty sure I've had (back)slashes, and "./subdirectory/file" vs /subdirectory/file" (no dot) both cause me problems in A4 and A5 before.

The problem here, I believe, is that any path starting with a / is interpreted as an absolute path on Unix. Using "subdirectory/file" should work on all systems and represent a relative path.

Go to: