関数 | |
void | create_example_ini_file (void) |
int | parse_ini_file (char *ini_name) |
int | main (int argc, char *argv[]) |
void create_example_ini_file | ( | void | ) |
iniexample.c の 24 行で定義されています。
参照先 fprintf().
参照元 main().
00025 { 00026 FILE * ini ; 00027 00028 ini = fopen("example.ini", "w"); 00029 fprintf(ini, "\n\ 00030 #\n\ 00031 # This is an example of ini file\n\ 00032 #\n\ 00033 \n\ 00034 [Pizza]\n\ 00035 \n\ 00036 Ham = yes ;\n\ 00037 Mushrooms = TRUE ;\n\ 00038 Capres = 0 ;\n\ 00039 Cheese = NO ;\n\ 00040 \n\ 00041 \n\ 00042 [Wine]\n\ 00043 \n\ 00044 Grape = Cabernet Sauvignon ;\n\ 00045 Year = 1989 ;\n\ 00046 Country = Spain ;\n\ 00047 Alcohol = 12.5 ;\n\ 00048 \n\ 00049 #\n\ 00050 # end of file\n\ 00051 #\n"); 00052 00053 fclose(ini); 00054 }
int parse_ini_file | ( | char * | ini_name | ) |
iniexample.c の 57 行で定義されています。
参照先 fprintf()・iniparser_dump()・iniparser_freedict()・iniparser_getboolean()・iniparser_getdouble()・iniparser_getint()・iniparser_getstr()・iniparser_load()・printf().
参照元 main().
00058 { 00059 dictionary * ini ; 00060 00061 /* Some temporary variables to hold query results */ 00062 int b ; 00063 int i ; 00064 double d ; 00065 char * s ; 00066 00067 ini = iniparser_load(ini_name); 00068 if (ini==NULL) { 00069 fprintf(stderr, "cannot parse file [%s]", ini_name); 00070 return -1 ; 00071 } 00072 iniparser_dump(ini, stderr); 00073 00074 /* Get pizza attributes */ 00075 printf("Pizza:\n"); 00076 00077 b = iniparser_getboolean(ini, "pizza:ham", -1); 00078 printf("Ham: [%d]\n", b); 00079 b = iniparser_getboolean(ini, "pizza:mushrooms", -1); 00080 printf("Mushrooms: [%d]\n", b); 00081 b = iniparser_getboolean(ini, "pizza:capres", -1); 00082 printf("Capres: [%d]\n", b); 00083 b = iniparser_getboolean(ini, "pizza:cheese", -1); 00084 printf("Cheese: [%d]\n", b); 00085 00086 /* Get wine attributes */ 00087 printf("Wine:\n"); 00088 s = iniparser_getstr(ini, "wine:grape"); 00089 if (s) { 00090 printf("grape: [%s]\n", s); 00091 } else { 00092 printf("grape: not found\n"); 00093 } 00094 i = iniparser_getint(ini, "wine:year", -1); 00095 if (i>0) { 00096 printf("year: [%d]\n", i); 00097 } else { 00098 printf("year: not found\n"); 00099 } 00100 s = iniparser_getstr(ini, "wine:country"); 00101 if (s) { 00102 printf("country: [%s]\n", s); 00103 } else { 00104 printf("country: not found\n"); 00105 } 00106 d = iniparser_getdouble(ini, "wine:alcohol", -1.0); 00107 if (d>0.0) { 00108 printf("alcohol: [%g]\n", d); 00109 } else { 00110 printf("alcohol: not found\n"); 00111 } 00112 00113 iniparser_freedict(ini); 00114 return 0 ; 00115 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
iniexample.c の 11 行で定義されています。
参照先 create_example_ini_file()・parse_ini_file()・status.
00012 { 00013 int status ; 00014 00015 if (argc<2) { 00016 create_example_ini_file(); 00017 status = parse_ini_file("example.ini"); 00018 } else { 00019 status = parse_ini_file(argv[1]); 00020 } 00021 return status ; 00022 }