diff options
author | Günther Deschner <gd@samba.org> | 2006-04-11 14:34:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:15:58 -0500 |
commit | f340b2fa367d7a888c0dc24ff57f2aed7e9c88bb (patch) | |
tree | 84149b4ff19bd0119057cce6834a60f1a0d33879 /source3/iniparser/test | |
parent | 262ffd9750f58f2c5f2268932b45c4d7b05a5fca (diff) | |
download | samba-f340b2fa367d7a888c0dc24ff57f2aed7e9c88bb.tar.gz samba-f340b2fa367d7a888c0dc24ff57f2aed7e9c88bb.tar.bz2 samba-f340b2fa367d7a888c0dc24ff57f2aed7e9c88bb.zip |
r15037: Adding iniParser (http://ndevilla.free.fr/iniparser/), a free inifile
parsing library under the MIT licence.
This is required to have a configuration ini-file for pam_winbind
without using loadparm in the next step.
Guenther
(This used to be commit 6658e0a9886ee5a361361bc9b26c136ec91aea72)
Diffstat (limited to 'source3/iniparser/test')
-rw-r--r-- | source3/iniparser/test/Makefile | 24 | ||||
-rw-r--r-- | source3/iniparser/test/iniexample.c | 117 |
2 files changed, 141 insertions, 0 deletions
diff --git a/source3/iniparser/test/Makefile b/source3/iniparser/test/Makefile new file mode 100644 index 0000000000..aa8fcb24b5 --- /dev/null +++ b/source3/iniparser/test/Makefile @@ -0,0 +1,24 @@ +# +# iniparser tests Makefile +# + +CC = gcc +CFLAGS = -g -I../src +LFLAGS = -L.. -liniparser +AR = ar +ARFLAGS = rcv +RM = rm -f + + +default: all + +all: iniexample + +iniexample: iniexample.c + $(CC) $(CFLAGS) -o iniexample iniexample.c -I../src -L.. -liniparser + +clean veryclean: + $(RM) iniexample example.ini + + + diff --git a/source3/iniparser/test/iniexample.c b/source3/iniparser/test/iniexample.c new file mode 100644 index 0000000000..5e8e71cdf0 --- /dev/null +++ b/source3/iniparser/test/iniexample.c @@ -0,0 +1,117 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "iniparser.h" + +void create_example_ini_file(void); +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 ; +} + +void create_example_ini_file(void) +{ + FILE * ini ; + + ini = fopen("example.ini", "w"); + fprintf(ini, "\n\ +#\n\ +# This is an example of ini file\n\ +#\n\ +\n\ +[Pizza]\n\ +\n\ +Ham = yes ;\n\ +Mushrooms = TRUE ;\n\ +Capres = 0 ;\n\ +Cheese = NO ;\n\ +\n\ +\n\ +[Wine]\n\ +\n\ +Grape = Cabernet Sauvignon ;\n\ +Year = 1989 ;\n\ +Country = Spain ;\n\ +Alcohol = 12.5 ;\n\ +\n\ +#\n\ +# end of file\n\ +#\n"); + + 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]", 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_getstr(ini, "wine:grape"); + if (s) { + printf("grape: [%s]\n", s); + } else { + printf("grape: not found\n"); + } + i = iniparser_getint(ini, "wine:year", -1); + if (i>0) { + printf("year: [%d]\n", i); + } else { + printf("year: not found\n"); + } + s = iniparser_getstr(ini, "wine:country"); + if (s) { + printf("country: [%s]\n", s); + } else { + printf("country: not found\n"); + } + d = iniparser_getdouble(ini, "wine:alcohol", -1.0); + if (d>0.0) { + printf("alcohol: [%g]\n", d); + } else { + printf("alcohol: not found\n"); + } + + iniparser_freedict(ini); + return 0 ; +} + + |