forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Include config.cfg

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
fr34k*



Joined: 31 Aug 2007
Posts: 17

PostPosted: Sat Sep 01, 2007 7:22 am    Post subject: Include config.cfg Reply with quote

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

Quote:
#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!!!!!
Back to top
View user's profile Send private message
PSPJunkie



Joined: 23 Jan 2007
Posts: 14
Location: Jersey

PostPosted: Sat Sep 01, 2007 2:24 pm    Post subject: Reply with quote

Actually, I believe it is,

Code:

#USETHISCONFIGPLZ "config.cfg"


...
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
fr34k*



Joined: 31 Aug 2007
Posts: 17

PostPosted: Sat Sep 01, 2007 10:01 pm    Post subject: Reply with quote

A very nice joke -.-
I search for the instruction!
_________________
SORRY FOR MY BAD ENGLISH!!!!!
Back to top
View user's profile Send private message
Fanjita



Joined: 28 Sep 2005
Posts: 217

PostPosted: Sat Sep 01, 2007 10:13 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
Drajwer



Joined: 24 Aug 2007
Posts: 6

PostPosted: Sat Sep 01, 2007 11:43 pm    Post subject: Reply with quote

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:

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]);
  }
}
Back to top
View user's profile Send private message
fr34k*



Joined: 31 Aug 2007
Posts: 17

PostPosted: Sun Sep 02, 2007 12:16 am    Post subject: Reply with quote

that's it! Thank you to Fanjita and Drajwer!
_________________
SORRY FOR MY BAD ENGLISH!!!!!
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Sep 02, 2007 2:24 pm    Post subject: Reply with quote

Code:
  cLoginData[0][strlen(cLoginData[0])-1]=0; //dunno why :)

Probably because of the \n or Windows line endings.
Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group