// gcc `pkg-config --cflags libconfig` example1.c -o myprogram `pkg-config --libs libconfig` #include #include #include #define CONFIG_FILE jmccrohan-example.cfg int main(int argc, char **argv) { config_t cfg; config_setting_t *setting; const char *str; config_init(&cfg); fprintf(stderr, "__FILE__"); /* Read the file. If there is an error, report it and exit. */ if(! config_read_file(&cfg, "CONFIG_FILE")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return(EXIT_FAILURE); } /* Get the store name. */ if(config_lookup_string(&cfg, "version", &str)) printf("Store name: %s\n\n", str); else fprintf(stderr, "No 'version' setting in configuration file.\n"); /* Output a list of all books in the inventory. */ setting = config_lookup(&cfg, "inventory.books"); if(setting != NULL) { int count = config_setting_length(setting); int i; printf("%-30s %-30s %-6s %s\n", "TITLE", "AUTHOR", "PRICE", "QTY"); for(i = 0; i < count; ++i) { config_setting_t *book = config_setting_get_elem(setting, i); /* Only output the record if all of the expected fields are present. */ const char *title, *author; double price; int qty; if(!(config_setting_lookup_string(book, "title", &title) && config_setting_lookup_string(book, "author", &author) && config_setting_lookup_float(book, "price", &price) && config_setting_lookup_int(book, "qty", &qty))) continue; printf("%-30s %-30s $%6.2f %3d\n", title, author, price, qty); } putchar('\n'); } /* Output a list of all movies in the inventory. */ setting = config_lookup(&cfg, "inventory.movies"); if(setting != NULL) { unsigned int count = config_setting_length(setting); unsigned int i; printf("%-30s %-10s %-6s %s\n", "TITLE", "MEDIA", "PRICE", "QTY"); for(i = 0; i < count; ++i) { config_setting_t *movie = config_setting_get_elem(setting, i); /* Only output the record if all of the expected fields are present. */ const char *title, *media; double price; int qty; if(!(config_setting_lookup_string(movie, "title", &title) && config_setting_lookup_string(movie, "media", &media) && config_setting_lookup_float(movie, "price", &price) && config_setting_lookup_int(movie, "qty", &qty))) continue; printf("%-30s %-10s $%6.2f %3d\n", title, media, price, qty); } putchar('\n'); } config_destroy(&cfg); return(EXIT_SUCCESS); } /* eof */ c?id=1645d61018c24013525f3953613aaea56714bab4&follow=1'>Collapse)AuthorFilesLines 2000-07-31[lcd4linux @ 2000-07-31 10:43:44 by reinelt]reinelt8-91/+235 some changes to support kernel-2.4 (different layout of various files in /proc) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@60 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-07-31[lcd4linux @ 2000-07-31 06:46:35 by reinelt]reinelt4-5/+15 eliminated some compiler warnings with glibc git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@59 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-06-04[lcd4linux @ 2000-06-04 21:43:50 by herp]herp1-2/+9 minor bugfix (zero length) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@58 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-05-21[lcd4linux @ 2000-05-21 06:20:35 by reinelt]reinelt7-35/+148 added ppp throughput token is '%t[iomt]' at the moment, but this will change in the near future git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@57 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-05-03[lcd4linux @ 2000-05-03 17:14:51 by herp]herp1-1/+1 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@56 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-05-03[lcd4linux @ 2000-05-03 09:37:32 by herp]herp3-0/+658 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@55 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-05-02[lcd4linux @ 2000-05-02 23:07:48 by herp]herp4-15/+24 Crystalfontz initial coding git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@54 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-05-02[lcd4linux @ 2000-05-02 06:05:00 by reinelt]reinelt5-7/+312 driver for 3Com Palm Pilot added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@53 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-30[lcd4linux @ 2000-04-30 06:40:42 by reinelt]reinelt2-17/+37 bars for Beckmann+Egle driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@52 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-28[lcd4linux @ 2000-04-28 05:19:55 by reinelt]reinelt5-12/+554 first release of the Beckmann+Egle driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@51 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-20[lcd4linux @ 2000-04-20 05:48:42 by reinelt]reinelt2-0/+18 added documentation to EXTRA_DIST so that they go into the tarball git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@50 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-19[lcd4linux @ 2000-04-19 04:44:20 by reinelt]reinelt1-2/+2 README for HD44780 driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@49 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-17[lcd4linux @ 2000-04-17 05:14:27 by reinelt]reinelt3-5/+119 added README.44780 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@48 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-15[lcd4linux @ 2000-04-15 16:56:52 by reinelt]reinelt7-58/+197 moved delay loops to udelay.c renamed -d (debugging) switch to -v (verbose) new switch -d to calibrate delay loop 'Delay' entry for HD44780 back again delay loops will not calibrate automatically, because this will fail with hich CPU load git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@47 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-15[lcd4linux @ 2000-04-15 11:56:35 by reinelt]reinelt4-10/+60 more debug messages git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@46 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-15[lcd4linux @ 2000-04-15 11:13:54 by reinelt]reinelt10-28/+144 added '-d' (debugging) switch added several debugging messages removed config entry 'Delay' for HD44780 driver delay loop for HD44780 will be calibrated automatically git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@45 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-13[lcd4linux @ 2000-04-13 06:09:52 by reinelt]reinelt5-54/+126 added BogoMips() to system.c (not used by now, maybe sometimes we can calibrate our delay loop with this value) added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully no compiler will optimize away the delay loop! git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@44 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-12[lcd4linux @ 2000-04-12 08:05:45 by reinelt]reinelt6-24/+535 first version of the HD44780 driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@43 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-10[lcd4linux @ 2000-04-10 04:40:53 by reinelt]reinelt5-31/+65 minor changes and cleanups git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@42 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-07[lcd4linux @ 2000-04-07 05:42:20 by reinelt]reinelt6-17/+266 UUCP style lockfiles for the serial port git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@41 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2000-04-05[lcd4linux @ 2000-04-05 05:58:36 by reinelt]reinelt4-17/+65 fixed bug in XWindow.c: union semun isn't defined with glibc-2.1 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@40 3ae390bd-cb1e-0410-b409-cd5a39f66f1f