- #include <libcx/ini.h>
- int main()
- {
- FILE* f_ini;
- int i;
- INI* init =NULL;
- //Open ini file
- f_ini = fopen("./test.ini","r");
- if(!f_ini)
- {
- printf("Ini file not found\n");
- return -1;
- }
- // now parse it
- i = ini_parse(&init ,f_ini);
- if(i!=0)
- {
- switch(i)
- {
- case -1:
- printf("Error during init : ini file can't be open or not "
- "found, default values will be applied\n");
- break;
- case -2:
- printf("Error during init : ini file is invalid or contains "
- "errors, default values will be applied\n");
- break;
- default:
- printf("Unknow Error during reading ini file err=%d, default"
- " values "
- "will be applied\n",i);
- break;
- }
- fclose(f_ini);
- return -1;//or apply your default values.
- }
- /*
- now you can do your work with the ini file "playing" with INI *init structure.
- */
- //and close
- ini_release(&init);
- fclose(f_ini);
- return 0;
- }
-
- /*
- Supposons que notre fichier contient les infos suivantes :
- [network] # the network section
- protocol = "http"
- url = "www.libcx.net"
- port = 80
-
- Voici comment y accéder:
- */
- char* protocol = NULL;
- char* url = NULL;
- unsigned port = 0;
- ini_value* v;
- // in is an opened and parsed INI * structure
- // reading the url string
- v = ini_get(in,"network","url",0);
- if(v && v->type == INI_VAL_STRING)
- url = xcpystr(url,v->sval) ;
- // reading the port number
- v = ini_get(in,"network","port",0);
- if(v && v->type == INI_VAL_INT)
- port = v->ival ;
-
-
-
-
#include <libcx/ini.h>
int main()
{
FILE* f_ini;
int i;
INI* init =NULL;
//Open ini file
f_ini = fopen("./test.ini","r");
if(!f_ini)
{
printf("Ini file not found\n");
return -1;
}
// now parse it
i = ini_parse(&init ,f_ini);
if(i!=0)
{
switch(i)
{
case -1:
printf("Error during init : ini file can't be open or not "
"found, default values will be applied\n");
break;
case -2:
printf("Error during init : ini file is invalid or contains "
"errors, default values will be applied\n");
break;
default:
printf("Unknow Error during reading ini file err=%d, default"
" values "
"will be applied\n",i);
break;
}
fclose(f_ini);
return -1;//or apply your default values.
}
/*
now you can do your work with the ini file "playing" with INI *init structure.
*/
//and close
ini_release(&init);
fclose(f_ini);
return 0;
}
/*
Supposons que notre fichier contient les infos suivantes :
[network] # the network section
protocol = "http"
url = "www.libcx.net"
port = 80
Voici comment y accéder:
*/
char* protocol = NULL;
char* url = NULL;
unsigned port = 0;
ini_value* v;
// in is an opened and parsed INI * structure
// reading the url string
v = ini_get(in,"network","url",0);
if(v && v->type == INI_VAL_STRING)
url = xcpystr(url,v->sval) ;
// reading the port number
v = ini_get(in,"network","port",0);
if(v && v->type == INI_VAL_INT)
port = v->ival ;