Include config.cfg

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
fr34k*
Posts: 17
Joined: Fri Aug 31, 2007 6:19 am

Include config.cfg

Post by fr34k* »

Hi how can in include config.cfg in my prx file?
#include config.cfg

Is it right?

And what must stay in the config.cfg?
Must I use spezial commands in the config.cfg?
SORRY FOR MY BAD ENGLISH!!!!!
PSPJunkie
Posts: 14
Joined: Tue Jan 23, 2007 12:55 pm
Location: Jersey
Contact:

Post by PSPJunkie »

Actually, I believe it is,

Code: Select all

#USETHISCONFIGPLZ "config.cfg"
...
fr34k*
Posts: 17
Joined: Fri Aug 31, 2007 6:19 am

Post by fr34k* »

A very nice joke -.-
I search for the instruction!
SORRY FOR MY BAD ENGLISH!!!!!
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

Assuming that you want the config to apply at run-time, rather than at compile-time, then you're going to need to write some code in your program to open the file, read it and parse it.

If you want to see some really crap code for doing this, then the PiKey source code contains some simple and small config reading code, but you can almost certainly find better on the internet.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
Drajwer
Posts: 6
Joined: Fri Aug 24, 2007 5:32 pm

Post by Drajwer »

I wrote a simple INI parser for my MMO. Im sure you know how INI file looks, so here is the code:
(this parser skips comment lines too.)

Code: Select all

void LoadConfig() {
 FILE* f;
  f=fopen("config.ini","r");
  int i;
  if (!f) {
          printf("FAIL!\n");
  }
  else {
    char line[100];  
    char l2[100];    
    char value[100];
    while (!feof(f)) {
   	fgets(line,100,f);
	char *tmp;
	
	if (line[0] == '#')
		continue;
	if (line[0] == '[') {
		tmp = strchr(line, ']');
		if (!tmp)
			continue;
		*tmp = 0;
		memset(l2,0,100);
		strcat(l2,line+1);
		continue;
	}
	if ((tmp = strchr(line, '='))) {
		*tmp = 0;
		tmp++;
		
	memset(value,0,100);
        strcat(value,tmp);
        //l2 = SECTION
        //line = ident
        //value = value :)
	if (strcmp(l2,"ACCOUNT") == 0) {
           if (strcmp(line,"login")==0) { memset(cLoginData[0],0,20); strcat(cLoginData[0],value); }
           if (strcmp(line,"password")==0) { memset(cLoginData[1],0,20); strcat(cLoginData[1],value); }
        }                                       
	}
  }
  fclose(f);
  printf("OK!\n");
  value[i]=0;
  cLoginData[0][strlen(cLoginData[0])-1]=0; //dunno why :)
  cLoginData[1][strlen(cLoginData[1])-1]=0;    
  //printf("Login: %s Password: %s\n",cLoginData[0],cLoginData[1]);
  }
}
fr34k*
Posts: 17
Joined: Fri Aug 31, 2007 6:19 am

Post by fr34k* »

that's it! Thank you to Fanjita and Drajwer!
SORRY FOR MY BAD ENGLISH!!!!!
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Code: Select all

  cLoginData[0][strlen(cLoginData[0])-1]=0; //dunno why :) 
Probably because of the \n or Windows line endings.
Jim
Post Reply