Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Suppressed all tabs from sources, replaced by blanks

  • Loading branch information...
commit 322369e90f0dc70d8acc5b9864c6ec2c51e6692e 1 parent ca68e9d
@ndevilla authored
View
65 doc/iniparser.main
@@ -1,10 +1,10 @@
/**
- @mainpage iniparser documentation
+ @mainpage iniparser documentation
- @section welcome Introduction
+ @section welcome Introduction
iniParser is a simple C library offering ini file parsing services.
The library is pretty small (less than 1500 lines of C) and robust, and
@@ -12,7 +12,7 @@
in ANSI C and should compile on most platforms without difficulty.
- @section inidef What is an ini file?
+ @section inidef What is an ini file?
An ini file is an ASCII file describing simple parameters
(character strings, integers, floating-point values or booleans)
@@ -23,7 +23,7 @@
@verbatim
[Section Name]
- @endverbatim
+ @endverbatim
i.e. the section name enclosed in square brackets, alone on a
line. Sections names are allowed to contain any character but
@@ -34,7 +34,7 @@
@verbatim
Key = value ; comment
- @endverbatim
+ @endverbatim
The key is any string (possibly containing blanks). The value is
any character on the right side of the equal sign. Values can be
@@ -46,7 +46,7 @@
@verbatim
Hello = "this is a long string value" ; comment
Hello = this is a long string value ; comment
- @endverbatim
+ @endverbatim
The semicolon and comment at the end of the line are optional. If
there is a comment, it starts from the first character after the
@@ -71,29 +71,29 @@
- Comments given on value lines after the semicolon (if present)
- @section install Compiling/installing the library
+ @section install Compiling/installing the library
- Edit the Makefile to indicate the C compiler you want to use, the
- options to provide to compile ANSI C, and possibly the options to pass
- to the ar program on your machine to build a library (.a) from a set
- of object (.o) files.
+ Edit the Makefile to indicate the C compiler you want to use, the
+ options to provide to compile ANSI C, and possibly the options to pass
+ to the ar program on your machine to build a library (.a) from a set
+ of object (.o) files.
- Defaults are set for the gcc compiler and the standard ar library
- builder.
+ Defaults are set for the gcc compiler and the standard ar library
+ builder.
- Type 'make', that should do it.
+ Type 'make', that should do it.
- To use the library in your programs, add the following line on top
- of your module:
+ To use the library in your programs, add the following line on top
+ of your module:
- @code
- #include "iniparser.h"
- @endcode
+ @code
+ #include "iniparser.h"
+ @endcode
- And link your program with the iniparser library by adding
- @c -liniparser.a to the compile line.
+ And link your program with the iniparser library by adding
+ @c -liniparser.a to the compile line.
- See the file test/initest.c for an example.
+ See the file test/initest.c for an example.
iniparser is an ANSI C library. If you want to compile it
with a C++ compiler you will likely run into compatibility
@@ -105,16 +105,15 @@
C code in a C++ environment. You have been warned.
- @section reference Library reference
+ @section reference Library reference
- The library is completely documented in its header file. On-line
- documentation has been generated and can be consulted here:
+ The library is completely documented in its header file. On-line
+ documentation has been generated and can be consulted here:
- - iniparser.h
+ - iniparser.h
-
- @section usage Using the parser
+ @section usage Using the parser
Comments are discarded by the parser. Then sections are
identified, and in each section a new entry is created for every
@@ -123,13 +122,13 @@
@verbatim
[Section]
Keyword = value ; comment
- @endverbatim
+ @endverbatim
is converted to the following key pair:
@verbatim
("section:keyword", "value")
- @endverbatim
+ @endverbatim
This means that if you want to retrieve the value that was stored
in the section called @c Pizza, in the keyword @c Cheese,
@@ -179,7 +178,7 @@
@endverbatim
- @section implementation A word about the implementation
+ @section implementation A word about the implementation
The dictionary structure is a pretty simple dictionary
implementation which might find some uses in other applications.
@@ -200,9 +199,9 @@
available on the net to replace this one.
- @section authors Authors
+ @section authors Authors
- Nicolas Devillard (ndevilla AT free DOT fr).
+ Nicolas Devillard (ndevilla AT free DOT fr).
*/
View
340 src/dictionary.c
@@ -1,10 +1,10 @@
/*-------------------------------------------------------------------------*/
/**
- @file dictionary.c
- @author N. Devillard
- @date Sep 2007
- @version $Revision: 1.27 $
- @brief Implements a dictionary for string variables.
+ @file dictionary.c
+ @author N. Devillard
+ @date Sep 2007
+ @version $Revision: 1.27 $
+ @brief Implements a dictionary for string variables.
This module implements a simple dictionary object, i.e. a list
of string/string associations. This object is useful to store e.g.
@@ -13,11 +13,11 @@
/*--------------------------------------------------------------------------*/
/*
- $Id: dictionary.c,v 1.27 2007-11-23 21:39:18 ndevilla Exp $
- $Revision: 1.27 $
+ $Id: dictionary.c,v 1.27 2007-11-23 21:39:18 ndevilla Exp $
+ $Revision: 1.27 $
*/
/*---------------------------------------------------------------------------
- Includes
+ Includes
---------------------------------------------------------------------------*/
#include "dictionary.h"
@@ -27,16 +27,16 @@
#include <unistd.h>
/** Maximum value size for integers and doubles. */
-#define MAXVALSZ 1024
+#define MAXVALSZ 1024
/** Minimal allocated number of entries in a dictionary */
-#define DICTMINSZ 128
+#define DICTMINSZ 128
/** Invalid key token */
#define DICT_INVALID_KEY ((char*)-1)
/*---------------------------------------------------------------------------
- Private functions
+ Private functions
---------------------------------------------------------------------------*/
/* Doubles the allocated size associated to a pointer */
@@ -77,13 +77,13 @@ static char * xstrdup(char * s)
}
/*---------------------------------------------------------------------------
- Function codes
+ Function codes
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/**
- @brief Compute the hash key for a string.
- @param key Character string to use for key.
- @return 1 unsigned int on at least 32 bits.
+ @brief Compute the hash key for a string.
+ @param key Character string to use for key.
+ @return 1 unsigned int on at least 32 bits.
This hash function has been taken from an Article in Dr Dobbs Journal.
This is normally a collision-free function, distributing keys evenly.
@@ -93,27 +93,27 @@ static char * xstrdup(char * s)
/*--------------------------------------------------------------------------*/
unsigned dictionary_hash(char * key)
{
- int len ;
- unsigned hash ;
- int i ;
-
- len = strlen(key);
- for (hash=0, i=0 ; i<len ; i++) {
- hash += (unsigned)key[i] ;
- hash += (hash<<10);
- hash ^= (hash>>6) ;
- }
- hash += (hash <<3);
- hash ^= (hash >>11);
- hash += (hash <<15);
- return hash ;
+ int len ;
+ unsigned hash ;
+ int i ;
+
+ len = strlen(key);
+ for (hash=0, i=0 ; i<len ; i++) {
+ hash += (unsigned)key[i] ;
+ hash += (hash<<10);
+ hash ^= (hash>>6) ;
+ }
+ hash += (hash <<3);
+ hash ^= (hash >>11);
+ hash += (hash <<15);
+ return hash ;
}
/*-------------------------------------------------------------------------*/
/**
- @brief Create a new dictionary object.
- @param size Optional initial size of the dictionary.
- @return 1 newly allocated dictionary objet.
+ @brief Create a new dictionary object.
+ @param size Optional initial size of the dictionary.
+ @return 1 newly allocated dictionary objet.
This function allocates a new dictionary object of given size and returns
it. If you do not know in advance (roughly) the number of entries in the
@@ -122,55 +122,55 @@ unsigned dictionary_hash(char * key)
/*--------------------------------------------------------------------------*/
dictionary * dictionary_new(int size)
{
- dictionary * d ;
-
- /* If no size was specified, allocate space for DICTMINSZ */
- if (size<DICTMINSZ) size=DICTMINSZ ;
-
- if (!(d = (dictionary *)calloc(1, sizeof(dictionary)))) {
- return NULL;
- }
- d->size = size ;
- d->val = (char **)calloc(size, sizeof(char*));
- d->key = (char **)calloc(size, sizeof(char*));
- d->hash = (unsigned int *)calloc(size, sizeof(unsigned));
- return d ;
+ dictionary * d ;
+
+ /* If no size was specified, allocate space for DICTMINSZ */
+ if (size<DICTMINSZ) size=DICTMINSZ ;
+
+ if (!(d = (dictionary *)calloc(1, sizeof(dictionary)))) {
+ return NULL;
+ }
+ d->size = size ;
+ d->val = (char **)calloc(size, sizeof(char*));
+ d->key = (char **)calloc(size, sizeof(char*));
+ d->hash = (unsigned int *)calloc(size, sizeof(unsigned));
+ return d ;
}
/*-------------------------------------------------------------------------*/
/**
- @brief Delete a dictionary object
- @param d dictionary object to deallocate.
- @return void
+ @brief Delete a dictionary object
+ @param d dictionary object to deallocate.
+ @return void
Deallocate a dictionary object and all memory associated to it.
*/
/*--------------------------------------------------------------------------*/
void dictionary_del(dictionary * d)
{
- int i ;
-
- if (d==NULL) return ;
- for (i=0 ; i<d->size ; i++) {
- if (d->key[i]!=NULL)
- free(d->key[i]);
- if (d->val[i]!=NULL)
- free(d->val[i]);
- }
- free(d->val);
- free(d->key);
- free(d->hash);
- free(d);
- return ;
+ int i ;
+
+ if (d==NULL) return ;
+ for (i=0 ; i<d->size ; i++) {
+ if (d->key[i]!=NULL)
+ free(d->key[i]);
+ if (d->val[i]!=NULL)
+ free(d->val[i]);
+ }
+ free(d->val);
+ free(d->key);
+ free(d->hash);
+ free(d);
+ return ;
}
/*-------------------------------------------------------------------------*/
/**
- @brief Get a value from a dictionary.
- @param d dictionary object to search.
- @param key Key to look for in the dictionary.
+ @brief Get a value from a dictionary.
+ @param d dictionary object to search.
+ @param key Key to look for in the dictionary.
@param def Default value to return if key not found.
- @return 1 pointer to internally allocated character string.
+ @return 1 pointer to internally allocated character string.
This function locates a key in a dictionary and returns a pointer to its
value, or the passed 'def' pointer if no such key can be found in
@@ -180,22 +180,22 @@ void dictionary_del(dictionary * d)
/*--------------------------------------------------------------------------*/
char * dictionary_get(dictionary * d, char * key, char * def)
{
- unsigned hash ;
- int i ;
+ unsigned hash ;
+ int i ;
- hash = dictionary_hash(key);
- for (i=0 ; i<d->size ; i++) {
+ hash = dictionary_hash(key);
+ for (i=0 ; i<d->size ; i++) {
if (d->key[i]==NULL)
continue ;
/* Compare hash */
- if (hash==d->hash[i]) {
+ if (hash==d->hash[i]) {
/* Compare string, to avoid hash collisions */
if (!strcmp(key, d->key[i])) {
- return d->val[i] ;
- }
- }
- }
- return def ;
+ return d->val[i] ;
+ }
+ }
+ }
+ return def ;
}
/*-------------------------------------------------------------------------*/
@@ -226,45 +226,45 @@ char * dictionary_get(dictionary * d, char * key, char * def)
/*--------------------------------------------------------------------------*/
int dictionary_set(dictionary * d, char * key, char * val)
{
- int i ;
- unsigned hash ;
-
- if (d==NULL || key==NULL) return -1 ;
-
- /* Compute hash for this key */
- hash = dictionary_hash(key) ;
- /* Find if value is already in dictionary */
- if (d->n>0) {
- for (i=0 ; i<d->size ; i++) {
+ int i ;
+ unsigned hash ;
+
+ if (d==NULL || key==NULL) return -1 ;
+
+ /* Compute hash for this key */
+ hash = dictionary_hash(key) ;
+ /* Find if value is already in dictionary */
+ if (d->n>0) {
+ for (i=0 ; i<d->size ; i++) {
if (d->key[i]==NULL)
continue ;
- if (hash==d->hash[i]) { /* Same hash value */
- if (!strcmp(key, d->key[i])) { /* Same key */
- /* Found a value: modify and return */
- if (d->val[i]!=NULL)
- free(d->val[i]);
+ if (hash==d->hash[i]) { /* Same hash value */
+ if (!strcmp(key, d->key[i])) { /* Same key */
+ /* Found a value: modify and return */
+ if (d->val[i]!=NULL)
+ free(d->val[i]);
d->val[i] = val ? xstrdup(val) : NULL ;
/* Value has been modified: return */
- return 0 ;
- }
- }
- }
- }
- /* Add a new value */
- /* See if dictionary needs to grow */
- if (d->n==d->size) {
-
- /* Reached maximum size: reallocate dictionary */
- d->val = (char **)mem_double(d->val, d->size * sizeof(char*)) ;
- d->key = (char **)mem_double(d->key, d->size * sizeof(char*)) ;
- d->hash = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ;
+ return 0 ;
+ }
+ }
+ }
+ }
+ /* Add a new value */
+ /* See if dictionary needs to grow */
+ if (d->n==d->size) {
+
+ /* Reached maximum size: reallocate dictionary */
+ d->val = (char **)mem_double(d->val, d->size * sizeof(char*)) ;
+ d->key = (char **)mem_double(d->key, d->size * sizeof(char*)) ;
+ d->hash = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ;
if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL)) {
/* Cannot grow dictionary */
return -1 ;
}
- /* Double size */
- d->size *= 2 ;
- }
+ /* Double size */
+ d->size *= 2 ;
+ }
/* Insert key in the first empty slot */
for (i=0 ; i<d->size ; i++) {
@@ -273,19 +273,19 @@ int dictionary_set(dictionary * d, char * key, char * val)
break ;
}
}
- /* Copy key */
- d->key[i] = xstrdup(key);
+ /* Copy key */
+ d->key[i] = xstrdup(key);
d->val[i] = val ? xstrdup(val) : NULL ;
- d->hash[i] = hash;
- d->n ++ ;
- return 0 ;
+ d->hash[i] = hash;
+ d->n ++ ;
+ return 0 ;
}
/*-------------------------------------------------------------------------*/
/**
- @brief Delete a key in a dictionary
- @param d dictionary object to modify.
- @param key Key to remove.
+ @brief Delete a key in a dictionary
+ @param d dictionary object to modify.
+ @param key Key to remove.
@return void
This function deletes a key in a dictionary. Nothing is done if the
@@ -294,26 +294,26 @@ int dictionary_set(dictionary * d, char * key, char * val)
/*--------------------------------------------------------------------------*/
void dictionary_unset(dictionary * d, char * key)
{
- unsigned hash ;
- int i ;
+ unsigned hash ;
+ int i ;
- if (key == NULL) {
- return;
- }
+ if (key == NULL) {
+ return;
+ }
- hash = dictionary_hash(key);
- for (i=0 ; i<d->size ; i++) {
+ hash = dictionary_hash(key);
+ for (i=0 ; i<d->size ; i++) {
if (d->key[i]==NULL)
continue ;
/* Compare hash */
- if (hash==d->hash[i]) {
+ if (hash==d->hash[i]) {
/* Compare string, to avoid hash collisions */
if (!strcmp(key, d->key[i])) {
/* Found key */
break ;
- }
- }
- }
+ }
+ }
+ }
if (i>=d->size)
/* Key not found */
return ;
@@ -331,10 +331,10 @@ void dictionary_unset(dictionary * d, char * key)
/*-------------------------------------------------------------------------*/
/**
- @brief Dump a dictionary to an opened file pointer.
- @param d Dictionary to dump
- @param f Opened file pointer.
- @return void
+ @brief Dump a dictionary to an opened file pointer.
+ @param d Dictionary to dump
+ @param f Opened file pointer.
+ @return void
Dumps a dictionary onto an opened file pointer. Key pairs are printed out
as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
@@ -343,21 +343,21 @@ void dictionary_unset(dictionary * d, char * key)
/*--------------------------------------------------------------------------*/
void dictionary_dump(dictionary * d, FILE * out)
{
- int i ;
-
- if (d==NULL || out==NULL) return ;
- if (d->n<1) {
- fprintf(out, "empty dictionary\n");
- return ;
- }
- for (i=0 ; i<d->size ; i++) {
+ int i ;
+
+ if (d==NULL || out==NULL) return ;
+ if (d->n<1) {
+ fprintf(out, "empty dictionary\n");
+ return ;
+ }
+ for (i=0 ; i<d->size ; i++) {
if (d->key[i]) {
fprintf(out, "%20s\t[%s]\n",
d->key[i],
d->val[i] ? d->val[i] : "UNDEF");
}
- }
- return ;
+ }
+ return ;
}
@@ -366,40 +366,40 @@ void dictionary_dump(dictionary * d, FILE * out)
#define NVALS 20000
int main(int argc, char *argv[])
{
- dictionary * d ;
- char * val ;
- int i ;
- char cval[90] ;
-
- /* Allocate dictionary */
- printf("allocating...\n");
- d = dictionary_new(0);
-
- /* Set values in dictionary */
- printf("setting %d values...\n", NVALS);
- for (i=0 ; i<NVALS ; i++) {
- sprintf(cval, "%04d", i);
- dictionary_set(d, cval, "salut");
- }
- printf("getting %d values...\n", NVALS);
- for (i=0 ; i<NVALS ; i++) {
- sprintf(cval, "%04d", i);
- val = dictionary_get(d, cval, DICT_INVALID_KEY);
- if (val==DICT_INVALID_KEY) {
- printf("cannot get value for key [%s]\n", cval);
- }
- }
+ dictionary * d ;
+ char * val ;
+ int i ;
+ char cval[90] ;
+
+ /* Allocate dictionary */
+ printf("allocating...\n");
+ d = dictionary_new(0);
+
+ /* Set values in dictionary */
+ printf("setting %d values...\n", NVALS);
+ for (i=0 ; i<NVALS ; i++) {
+ sprintf(cval, "%04d", i);
+ dictionary_set(d, cval, "salut");
+ }
+ printf("getting %d values...\n", NVALS);
+ for (i=0 ; i<NVALS ; i++) {
+ sprintf(cval, "%04d", i);
+ val = dictionary_get(d, cval, DICT_INVALID_KEY);
+ if (val==DICT_INVALID_KEY) {
+ printf("cannot get value for key [%s]\n", cval);
+ }
+ }
printf("unsetting %d values...\n", NVALS);
- for (i=0 ; i<NVALS ; i++) {
- sprintf(cval, "%04d", i);
- dictionary_unset(d, cval);
- }
+ for (i=0 ; i<NVALS ; i++) {
+ sprintf(cval, "%04d", i);
+ dictionary_unset(d, cval);
+ }
if (d->n != 0) {
printf("error deleting values\n");
}
- printf("deallocating...\n");
- dictionary_del(d);
- return 0 ;
+ printf("deallocating...\n");
+ dictionary_del(d);
+ return 0 ;
}
#endif
/* vim: set ts=4 et sw=4 tw=75 */
View
26 src/dictionary.h
@@ -14,17 +14,17 @@
/*--------------------------------------------------------------------------*/
/*
- $Id: dictionary.h,v 1.12 2007-11-23 21:37:00 ndevilla Exp $
- $Author: ndevilla $
- $Date: 2007-11-23 21:37:00 $
- $Revision: 1.12 $
+ $Id: dictionary.h,v 1.12 2007-11-23 21:37:00 ndevilla Exp $
+ $Author: ndevilla $
+ $Date: 2007-11-23 21:37:00 $
+ $Revision: 1.12 $
*/
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_
/*---------------------------------------------------------------------------
- Includes
+ Includes
---------------------------------------------------------------------------*/
#include <stdio.h>
@@ -33,13 +33,13 @@
#include <unistd.h>
/*---------------------------------------------------------------------------
- New types
+ New types
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/**
- @brief Dictionary object
+ @brief Dictionary object
This object contains a list of string/string associations. Each
association is identified by a unique string key. Looking up values
@@ -48,16 +48,16 @@
*/
/*-------------------------------------------------------------------------*/
typedef struct _dictionary_ {
- int n ; /** Number of entries in dictionary */
- int size ; /** Storage size */
- char ** val ; /** List of string values */
- char ** key ; /** List of string keys */
- unsigned * hash ; /** List of hash values for keys */
+ int n ; /** Number of entries in dictionary */
+ int size ; /** Storage size */
+ char ** val ; /** List of string values */
+ char ** key ; /** List of string keys */
+ unsigned * hash ; /** List of hash values for keys */
} dictionary ;
/*---------------------------------------------------------------------------
- Function prototypes
+ Function prototypes
---------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
View
40 src/iniparser.c
@@ -38,9 +38,9 @@ typedef enum _line_status_ {
/*-------------------------------------------------------------------------*/
/**
- @brief Convert a string to lowercase.
- @param s String to convert.
- @return ptr to statically allocated string.
+ @brief Convert a string to lowercase.
+ @param s String to convert.
+ @return ptr to statically allocated string.
This function returns a pointer to a statically allocated string
containing a lowercased version of the input string. Do not free
@@ -66,9 +66,9 @@ static char * strlwc(char * s)
/*-------------------------------------------------------------------------*/
/**
- @brief Remove blanks at the beginning and the end of a string.
- @param s String to parse.
- @return ptr to statically allocated string.
+ @brief Remove blanks at the beginning and the end of a string.
+ @param s String to parse.
+ @return ptr to statically allocated string.
This function returns a pointer to a statically allocated string,
which is identical to the input string, except that all blank
@@ -81,21 +81,21 @@ static char * strlwc(char * s)
static char * strstrip(char * s)
{
static char l[ASCIILINESZ+1];
- char * last ;
-
+ char * last ;
+
if (s==NULL) return NULL ;
- while (isspace((int)*s) && *s) s++;
- memset(l, 0, ASCIILINESZ+1);
- strcpy(l, s);
- last = l + strlen(l);
- while (last > l) {
- if (!isspace((int)*(last-1)))
- break ;
- last -- ;
- }
- *last = (char)0;
- return (char*)l ;
+ while (isspace((int)*s) && *s) s++;
+ memset(l, 0, ASCIILINESZ+1);
+ strcpy(l, s);
+ last = l + strlen(l);
+ while (last > l) {
+ if (!isspace((int)*(last-1)))
+ break ;
+ last -- ;
+ }
+ *last = (char)0;
+ return (char*)l ;
}
/*-------------------------------------------------------------------------*/
@@ -444,7 +444,7 @@ void iniparser_unset(dictionary * ini, char * entry)
/*-------------------------------------------------------------------------*/
/**
- @brief Load a single line from an INI file
+ @brief Load a single line from an INI file
@param input_line Input line, may be concatenated multi-line input
@param section Output space to store section
@param key Output space to store key
View
6 src/iniparser.h
@@ -10,15 +10,15 @@
/*--------------------------------------------------------------------------*/
/*
- $Id: iniparser.h,v 1.26 2011-03-02 20:15:13 ndevilla Exp $
- $Revision: 1.26 $
+ $Id: iniparser.h,v 1.26 2011-03-02 20:15:13 ndevilla Exp $
+ $Revision: 1.26 $
*/
#ifndef _INIPARSER_H_
#define _INIPARSER_H_
/*---------------------------------------------------------------------------
- Includes
+ Includes
---------------------------------------------------------------------------*/
#include <stdio.h>
View
96 test/iniexample.c
@@ -10,23 +10,23 @@ int parse_ini_file(char * ini_name);
int main(int argc, char * argv[])
{
- int status ;
-
- if (argc<2) {
- create_example_ini_file();
- status = parse_ini_file("example.ini");
- } else {
- status = parse_ini_file(argv[1]);
- }
- return status ;
+ int status ;
+
+ if (argc<2) {
+ create_example_ini_file();
+ status = parse_ini_file("example.ini");
+ } else {
+ status = parse_ini_file(argv[1]);
+ }
+ return status ;
}
void create_example_ini_file(void)
{
- FILE * ini ;
+ FILE * ini ;
- ini = fopen("example.ini", "w");
- fprintf(ini,
+ ini = fopen("example.ini", "w");
+ fprintf(ini,
"#\n"
"# This is an example of ini file\n"
"#\n"
@@ -46,55 +46,55 @@ void create_example_ini_file(void)
"Country = Spain ;\n"
"Alcohol = 12.5 ;\n"
"\n");
- fclose(ini);
+ fclose(ini);
}
int parse_ini_file(char * ini_name)
{
- dictionary * ini ;
-
- /* Some temporary variables to hold query results */
- int b ;
- int i ;
- double d ;
- char * s ;
-
- ini = iniparser_load(ini_name);
- if (ini==NULL) {
- fprintf(stderr, "cannot parse file: %s\n", ini_name);
- return -1 ;
- }
- iniparser_dump(ini, stderr);
-
- /* Get pizza attributes */
- printf("Pizza:\n");
-
- b = iniparser_getboolean(ini, "pizza:ham", -1);
- printf("Ham: [%d]\n", b);
- b = iniparser_getboolean(ini, "pizza:mushrooms", -1);
- printf("Mushrooms: [%d]\n", b);
- b = iniparser_getboolean(ini, "pizza:capres", -1);
- printf("Capres: [%d]\n", b);
- b = iniparser_getboolean(ini, "pizza:cheese", -1);
- printf("Cheese: [%d]\n", b);
-
- /* Get wine attributes */
- printf("Wine:\n");
- s = iniparser_getstring(ini, "wine:grape", NULL);
+ dictionary * ini ;
+
+ /* Some temporary variables to hold query results */
+ int b ;
+ int i ;
+ double d ;
+ char * s ;
+
+ ini = iniparser_load(ini_name);
+ if (ini==NULL) {
+ fprintf(stderr, "cannot parse file: %s\n", ini_name);
+ return -1 ;
+ }
+ iniparser_dump(ini, stderr);
+
+ /* Get pizza attributes */
+ printf("Pizza:\n");
+
+ b = iniparser_getboolean(ini, "pizza:ham", -1);
+ printf("Ham: [%d]\n", b);
+ b = iniparser_getboolean(ini, "pizza:mushrooms", -1);
+ printf("Mushrooms: [%d]\n", b);
+ b = iniparser_getboolean(ini, "pizza:capres", -1);
+ printf("Capres: [%d]\n", b);
+ b = iniparser_getboolean(ini, "pizza:cheese", -1);
+ printf("Cheese: [%d]\n", b);
+
+ /* Get wine attributes */
+ printf("Wine:\n");
+ s = iniparser_getstring(ini, "wine:grape", NULL);
printf("Grape: [%s]\n", s ? s : "UNDEF");
-
+
i = iniparser_getint(ini, "wine:year", -1);
printf("Year: [%d]\n", i);
- s = iniparser_getstring(ini, "wine:country", NULL);
+ s = iniparser_getstring(ini, "wine:country", NULL);
printf("Country: [%s]\n", s ? s : "UNDEF");
-
+
d = iniparser_getdouble(ini, "wine:alcohol", -1.0);
printf("Alcohol: [%g]\n", d);
- iniparser_freedict(ini);
- return 0 ;
+ iniparser_freedict(ini);
+ return 0 ;
}
View
10 test/parse.c
@@ -10,15 +10,15 @@ int main(int argc, char * argv[])
dictionary * ini ;
char * ini_name ;
- if (argc<2) {
+ if (argc<2) {
ini_name = "twisted.ini";
- } else {
- ini_name = argv[1] ;
- }
+ } else {
+ ini_name = argv[1] ;
+ }
ini = iniparser_load(ini_name);
iniparser_dump(ini, stdout);
iniparser_freedict(ini);
- return 0 ;
+ return 0 ;
}
Please sign in to comment.
Something went wrong with that request. Please try again.