iniparser/src/iniparser.h

Parser for ini files. [詳細]

ソースコードを見る。

関数

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
dictionaryiniparser_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


説明

Parser for ini files.

作者:
N. Devillard
日付:
Mar 2000
バージョン:
Revision
1.20

iniparser.h で定義されています。


関数

int iniparser_getnsec ( dictionary d  ) 

Get number of sections in a dictionary

引数:
d Dictionary to examine
戻り値:
int Number of sections found in dictionary
This function returns the number of sections found in a dictionary. The test to recognize sections is done on the string stored in the dictionary: a section name is given as "section" whereas a key is stored as "section:key", thus the test looks for entries that do not contain a colon.

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.c74 行で定義されています。

参照先 _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).
戻り値:
Pointer to char string
This function locates the n-th section in a dictionary and returns its name as a pointer to a string statically allocated inside the dictionary. Do not free or modify the returned string!

This function returns NULL in case of error.

iniparser.c107 行で定義されています。

参照先 _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
戻り値:
void
This function dumps a given dictionary into a loadable ini file. It is Ok to specify stderr or stdout as output files.

iniparser.c172 行で定義されています。

参照先 fprintf()iniparser_getnsec()iniparser_getsecname()_dictionary_::key_dictionary_::sizesprintf()_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.
戻り値:
void
This function prints out the contents of a dictionary, one element by line, onto the provided file pointer. It is OK to specify stderr or stdout as output files. This function is meant for debugging purposes mostly.

iniparser.c143 行で定義されています。

参照先 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
戻り値:
pointer to statically allocated character string, or NULL.
This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, NULL is returned. The returned char pointer is pointing to a string allocated in the dictionary, do not free or modify it.

This function is only provided for backwards compatibility with previous versions of iniparser. It is recommended to use iniparser_getstring() instead.

iniparser.c233 行で定義されています。

参照先 iniparser_getstring().

参照元 _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.
戻り値:
pointer to statically allocated character string
This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the pointer passed as 'def' is returned. The returned char pointer is pointing to a string allocated in the dictionary, do not free or modify it.

iniparser.c254 行で定義されています。

参照先 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
戻り値:
integer
This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned.

iniparser.c285 行で定義されています。

参照先 iniparser_getstring().

参照元 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
戻り値:
double
This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned.

iniparser.c308 行で定義されています。

参照先 iniparser_getstring().

参照元 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
戻り値:
integer
This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned.

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.c351 行で定義されています。

参照先 ciniparser_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.
戻り値:
int 0 if Ok, -1 otherwise.
If the given entry can be found in the dictionary, it is modified to contain the provided value. If it cannot be found, -1 is returned. It is Ok to set val to NULL.

iniparser.c410 行で定義されています。

参照先 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)
戻り値:
void
If the given entry can be found, it is deleted from the dictionary.

iniparser.c426 行で定義されています。

参照先 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
戻り値:
integer 1 if entry exists, 0 otherwise
Finds out if a given entry exists in the dictionary. Since sections are stored as keys with NULL associated values, this is the only way of querying for the presence of sections in a dictionary.

iniparser.c382 行で定義されています。

参照先 iniparser_getstring().

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.
戻り値:
Pointer to newly allocated dictionary
This is the parser for ini files. This function is called, providing the name of the file to be read. It returns a dictionary object that should not be accessed directly, but through accessor functions instead.

The returned dictionary must be freed using iniparser_freedict().

iniparser.c447 行で定義されています。

参照先 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
戻り値:
void
Free all memory associated to an ini dictionary. It is mandatory to call this function before the dictionary object gets out of the current context.

iniparser.c517 行で定義されています。

参照先 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 }


Sambaに対してSat Aug 29 21:23:35 2009に生成されました。  doxygen 1.4.7