関数 | |
int | iniparser_getnsec (dictionary *d) |
Get number of sections in a dictionary | |
char * | iniparser_getsecname (dictionary *d, int n) |
Get name for section n in a dictionary. | |
void | iniparser_dump_ini (dictionary *d, FILE *f) |
Save a dictionary to a loadable ini file | |
void | iniparser_dump (dictionary *d, FILE *f) |
Dump a dictionary to an opened file pointer. | |
char * | iniparser_getstr (dictionary *d, const char *key) |
Get the string associated to a key, return NULL if not found | |
char * | iniparser_getstring (dictionary *d, const char *key, char *def) |
Get the string associated to a key | |
int | iniparser_getint (dictionary *d, const char *key, int notfound) |
Get the string associated to a key, convert to an int | |
double | iniparser_getdouble (dictionary *d, char *key, double notfound) |
Get the string associated to a key, convert to a double | |
int | iniparser_getboolean (dictionary *d, const char *key, int notfound) |
Get the string associated to a key, convert to a boolean | |
int | iniparser_setstr (dictionary *ini, char *entry, char *val) |
Set an entry in a dictionary. | |
void | iniparser_unset (dictionary *ini, char *entry) |
Delete an entry in a dictionary | |
int | iniparser_find_entry (dictionary *ini, char *entry) |
Finds out if a given entry exists in a dictionary | |
dictionary * | iniparser_load (const char *ininame) |
Parse an ini file and return an allocated dictionary object | |
void | iniparser_freedict (dictionary *d) |
Free all memory associated to an ini dictionary |
iniparser.h で定義されています。
int iniparser_getnsec | ( | dictionary * | d | ) |
Get number of sections in a dictionary
d | Dictionary to examine |
This clearly fails in the case a section name contains a colon, but this should simply be avoided.
This function returns -1 in case of error.
iniparser.c の 74 行で定義されています。
参照先 _dictionary_::key・_dictionary_::size.
参照元 iniparser_dump_ini().
00075 { 00076 int i ; 00077 int nsec ; 00078 00079 if (d==NULL) return -1 ; 00080 nsec=0 ; 00081 for (i=0 ; i<d->size ; i++) { 00082 if (d->key[i]==NULL) 00083 continue ; 00084 if (strchr(d->key[i], ':')==NULL) { 00085 nsec ++ ; 00086 } 00087 } 00088 return nsec ; 00089 }
char* iniparser_getsecname | ( | dictionary * | d, | |
int | n | |||
) |
Get name for section n in a dictionary.
d | Dictionary to examine | |
n | Section number (from 0 to nsec-1). |
This function returns NULL in case of error.
iniparser.c の 107 行で定義されています。
参照先 _dictionary_::key・_dictionary_::size.
参照元 iniparser_dump_ini().
00108 { 00109 int i ; 00110 int foundsec ; 00111 00112 if (d==NULL || n<0) return NULL ; 00113 foundsec=0 ; 00114 for (i=0 ; i<d->size ; i++) { 00115 if (d->key[i]==NULL) 00116 continue ; 00117 if (strchr(d->key[i], ':')==NULL) { 00118 foundsec++ ; 00119 if (foundsec>n) 00120 break ; 00121 } 00122 } 00123 if (foundsec<=n) { 00124 return NULL ; 00125 } 00126 return d->key[i] ; 00127 }
void iniparser_dump_ini | ( | dictionary * | d, | |
FILE * | f | |||
) |
Save a dictionary to a loadable ini file
d | Dictionary to dump | |
f | Opened file pointer to dump to |
stderr
or stdout
as output files.
iniparser.c の 172 行で定義されています。
参照先 fprintf()・iniparser_getnsec()・iniparser_getsecname()・_dictionary_::key・_dictionary_::size・sprintf()・_dictionary_::val.
00173 { 00174 int i, j ; 00175 char keym[ASCIILINESZ+1]; 00176 int nsec ; 00177 char * secname ; 00178 int seclen ; 00179 00180 if (d==NULL || f==NULL) return ; 00181 00182 nsec = iniparser_getnsec(d); 00183 if (nsec<1) { 00184 /* No section in file: dump all keys as they are */ 00185 for (i=0 ; i<d->size ; i++) { 00186 if (d->key[i]==NULL) 00187 continue ; 00188 fprintf(f, "%s = %s\n", d->key[i], d->val[i]); 00189 } 00190 return ; 00191 } 00192 for (i=0 ; i<nsec ; i++) { 00193 secname = iniparser_getsecname(d, i) ; 00194 seclen = (int)strlen(secname); 00195 fprintf(f, "\n[%s]\n", secname); 00196 sprintf(keym, "%s:", secname); 00197 for (j=0 ; j<d->size ; j++) { 00198 if (d->key[j]==NULL) 00199 continue ; 00200 if (!strncmp(d->key[j], keym, seclen+1)) { 00201 fprintf(f, 00202 "%-30s = %s\n", 00203 d->key[j]+seclen+1, 00204 d->val[j] ? d->val[j] : ""); 00205 } 00206 } 00207 } 00208 fprintf(f, "\n"); 00209 return ; 00210 }
void iniparser_dump | ( | dictionary * | d, | |
FILE * | f | |||
) |
Dump a dictionary to an opened file pointer.
d | Dictionary to dump. | |
f | Opened file pointer to dump to. |
stderr
or stdout
as output files. This function is meant for debugging purposes mostly.
iniparser.c の 143 行で定義されています。
参照先 fprintf()・_dictionary_::key・_dictionary_::size・_dictionary_::val.
参照元 parse_ini_file().
00144 { 00145 int i ; 00146 00147 if (d==NULL || f==NULL) return ; 00148 for (i=0 ; i<d->size ; i++) { 00149 if (d->key[i]==NULL) 00150 continue ; 00151 if (d->val[i]!=NULL) { 00152 fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]); 00153 } else { 00154 fprintf(f, "[%s]=UNDEF\n", d->key[i]); 00155 } 00156 } 00157 return ; 00158 }
char* iniparser_getstr | ( | dictionary * | d, | |
const char * | key | |||
) |
Get the string associated to a key, return NULL if not found
d | Dictionary to search | |
key | Key string to look for |
This function is only provided for backwards compatibility with previous versions of iniparser. It is recommended to use iniparser_getstring() instead.
iniparser.c の 233 行で定義されています。
参照元 _pam_parse()・get_conf_item_string()・parse_ini_file().
00234 { 00235 return iniparser_getstring(d, key, NULL); 00236 }
char* iniparser_getstring | ( | dictionary * | d, | |
const char * | key, | |||
char * | def | |||
) |
Get the string associated to a key
d | Dictionary to search | |
key | Key string to look for | |
def | Default value to return if key not found. |
iniparser.c の 254 行で定義されています。
参照先 dictionary_get()・strdup()・strlwc().
参照元 iniparser_find_entry()・iniparser_getboolean()・iniparser_getdouble()・iniparser_getint()・iniparser_getstr()・parse_gpt_ini()・parse_gpttmpl().
00255 { 00256 char * lc_key ; 00257 char * sval ; 00258 00259 if (d==NULL || key==NULL) 00260 return def ; 00261 00262 if (!(lc_key = strdup(strlwc(key)))) { 00263 return NULL; 00264 } 00265 sval = dictionary_get(d, lc_key, def); 00266 free(lc_key); 00267 return sval ; 00268 }
int iniparser_getint | ( | dictionary * | d, | |
const char * | key, | |||
int | notfound | |||
) |
Get the string associated to a key, convert to an int
d | Dictionary to search | |
key | Key string to look for | |
notfound | Value to return in case of error |
iniparser.c の 285 行で定義されています。
参照元 parse_gpt_ini()・parse_gpttmpl()・parse_gpttmpl_kerberos_policy()・parse_gpttmpl_system_access()・parse_ini_file().
00286 { 00287 char * str ; 00288 00289 str = iniparser_getstring(d, key, INI_INVALID_KEY); 00290 if (str==INI_INVALID_KEY) return notfound ; 00291 return atoi(str); 00292 }
double iniparser_getdouble | ( | dictionary * | d, | |
char * | key, | |||
double | notfound | |||
) |
Get the string associated to a key, convert to a double
d | Dictionary to search | |
key | Key string to look for | |
notfound | Value to return in case of error |
iniparser.c の 308 行で定義されています。
参照元 parse_ini_file().
00309 { 00310 char * str ; 00311 00312 str = iniparser_getstring(d, key, INI_INVALID_KEY); 00313 if (str==INI_INVALID_KEY) return notfound ; 00314 return atof(str); 00315 }
int iniparser_getboolean | ( | dictionary * | d, | |
const char * | key, | |||
int | notfound | |||
) |
Get the string associated to a key, convert to a boolean
d | Dictionary to search | |
key | Key string to look for | |
notfound | Value to return in case of error |
A true boolean is found if one of the following is matched:
A false boolean is found if one of the following is matched:
The notfound value returned if no boolean is identified, does not necessarily have to be 0 or 1.
iniparser.c の 351 行で定義されています。
参照先 c・iniparser_getstring().
参照元 _pam_parse()・parse_gpttmpl()・parse_gpttmpl_kerberos_policy()・parse_gpttmpl_system_access()・parse_ini_file().
00352 { 00353 char * c ; 00354 int ret ; 00355 00356 c = iniparser_getstring(d, key, INI_INVALID_KEY); 00357 if (c==INI_INVALID_KEY) return notfound ; 00358 if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') { 00359 ret = 1 ; 00360 } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') { 00361 ret = 0 ; 00362 } else { 00363 ret = notfound ; 00364 } 00365 return ret; 00366 }
int iniparser_setstr | ( | dictionary * | ini, | |
char * | entry, | |||
char * | val | |||
) |
Set an entry in a dictionary.
ini | Dictionary to modify. | |
entry | Entry to modify (entry name) | |
val | New value to associate to the entry. |
iniparser.c の 410 行で定義されています。
参照先 dictionary_set()・strlwc().
00411 { 00412 dictionary_set(ini, strlwc(entry), val); 00413 return 0 ; 00414 }
void iniparser_unset | ( | dictionary * | ini, | |
char * | entry | |||
) |
Delete an entry in a dictionary
ini | Dictionary to modify | |
entry | Entry to delete (entry name) |
iniparser.c の 426 行で定義されています。
参照先 dictionary_unset()・strlwc().
00427 { 00428 dictionary_unset(ini, strlwc(entry)); 00429 }
int iniparser_find_entry | ( | dictionary * | ini, | |
char * | entry | |||
) |
Finds out if a given entry exists in a dictionary
ini | Dictionary to search | |
entry | Name of the entry to look for |
iniparser.c の 382 行で定義されています。
00386 { 00387 int found=0 ; 00388 if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) { 00389 found = 1 ; 00390 } 00391 return found ; 00392 }
dictionary* iniparser_load | ( | const char * | ininame | ) |
Parse an ini file and return an allocated dictionary object
ininame | Name of the ini file to read. |
The returned dictionary must be freed using iniparser_freedict().
iniparser.c の 447 行で定義されています。
参照先 dictionary_new()・iniparser_add_entry()・strcrop()・strlwc()・strskp().
参照元 _pam_parse()・parse_gpt_ini()・parse_gpttmpl_kerberos_policy()・parse_gpttmpl_system_access()・parse_ini_file().
00448 { 00449 dictionary * d ; 00450 char lin[ASCIILINESZ+1]; 00451 char sec[ASCIILINESZ+1]; 00452 char key[ASCIILINESZ+1]; 00453 char val[ASCIILINESZ+1]; 00454 char * where ; 00455 FILE * ini ; 00456 int lineno ; 00457 00458 if ((ini=fopen(ininame, "r"))==NULL) { 00459 return NULL ; 00460 } 00461 00462 sec[0]=0; 00463 00464 /* 00465 * Initialize a new dictionary entry 00466 */ 00467 if (!(d = dictionary_new(0))) { 00468 fclose(ini); 00469 return NULL; 00470 } 00471 lineno = 0 ; 00472 while (fgets(lin, ASCIILINESZ, ini)!=NULL) { 00473 lineno++ ; 00474 where = strskp(lin); /* Skip leading spaces */ 00475 if (*where==';' || *where=='#' || *where==0) 00476 continue ; /* Comment lines */ 00477 else { 00478 if (sscanf(where, "[%[^]]", sec)==1) { 00479 /* Valid section name */ 00480 strcpy(sec, strlwc(sec)); 00481 iniparser_add_entry(d, sec, NULL, NULL); 00482 } else if (sscanf (where, "%[^=] = \"%[^\"]\"", key, val) == 2 00483 || sscanf (where, "%[^=] = '%[^\']'", key, val) == 2 00484 || sscanf (where, "%[^=] = %[^;#]", key, val) == 2) { 00485 strcpy(key, strlwc(strcrop(key))); 00486 /* 00487 * sscanf cannot handle "" or '' as empty value, 00488 * this is done here 00489 */ 00490 if (!strcmp(val, "\"\"") || !strcmp(val, "''")) { 00491 val[0] = (char)0; 00492 } else { 00493 strcpy(val, strcrop(val)); 00494 } 00495 iniparser_add_entry(d, sec, key, val); 00496 } 00497 } 00498 } 00499 fclose(ini); 00500 return d ; 00501 }
void iniparser_freedict | ( | dictionary * | d | ) |
Free all memory associated to an ini dictionary
d | Dictionary to free |
iniparser.c の 517 行で定義されています。
参照先 dictionary_del().
参照元 _pam_parse()・pam_sm_acct_mgmt()・pam_sm_authenticate()・pam_sm_chauthtok()・pam_sm_close_session()・pam_sm_open_session()・pam_sm_setcred()・parse_gpt_ini()・parse_gpttmpl_kerberos_policy()・parse_gpttmpl_system_access()・parse_ini_file().
00518 { 00519 dictionary_del(d); 00520 }