/* This example reads the configuration file 'example.cfg' and displays
* some of its contents.
*/
int main(int argc, char **argv)
{
config_t cfg;
config_setting_t *setting;
const char *str;
config_init(&cfg);
/* Read the file. If there is an error, report it and exit. */
if(! config_read_file(&cfg, "example.cfg"))
{
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, "name", &str))
printf("Store name: %s\n\n", str);
else
fprintf(stderr, "No 'name' 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 */
2bgit20170425.fb5fe05-1&id=55e47784648c3489faec7e1faaaa4bacb415c238&showmsg=1&follow=1'>Expand)Author | Files | Lines |
2015-05-05 | d/control: various fixes found by libconfig-model-dpkg-perl | Jonathan McCrohan | 2 | -5/+13 |
2015-04-01 | Release 0+git20150208.f2053b3-1 | Jonathan McCrohan | 1 | -2/+2 |
2015-04-01 | Describe changes made in snapshot | Jonathan McCrohan | 1 | -0/+3 |
2015-04-01 | New Upstream Snapshot (commit f2053b3) | Jonathan McCrohan | 1 | -0/+6 |
2015-04-01 | Imported Upstream version 0+git20150208.f2053b3upstream/0+git20150208.f2053b3 | Jonathan McCrohan | 32 | -333/+483 |
2014-12-28 | Release 0+git20141218.b46a22c-1debian/0+git20141218.b46a22c-1 | Jonathan McCrohan | 1 | -2/+2 |
2014-12-28 | Updated AU DVB-T files; Thanks Brian Burch! (Closes LP: #1393280) | Jonathan McCrohan | 1 | -0/+1 |
2014-12-28 | New Upstream Snapshot (commit b46a22c) | Jonathan McCrohan | 1 | -0/+6 |
2014-12-28 | Imported Upstream version 0+git20141218.b46a22cupstream/0+git20141218.b46a22c | Jonathan McCrohan | 535 | -639/+317 |
2014-10-20 | Release 0+git20141009.d26b627-1debian/0+git20141009.d26b627-1 | Jonathan McCrohan | 1 | -2/+2 |
2014-10-20 | Fix up packaging to account for move to DVBv5 | Jonathan McCrohan | 2 | -2/+6 |
2014-10-20 | delete d/dtv-scan-files.install; Upstream now supplies a Makefile | Jonathan McCrohan | 2 | -4/+1 |
2014-10-15 | d/control: update Standards Version to 3.9.6 | Jonathan McCrohan | 2 | -1/+3 |
2014-10-15 | d/control: add Build-Depends on dvb-tools | Jonathan McCrohan | 2 | -1/+2 |
2014-10-15 | New Upstream Snapshot (commit d26b627) | Jonathan McCrohan | 1 | -0/+10 |
2014-10-15 | Imported Upstream version 0+git20141009.d26b627upstream/0+git20141009.d26b627 | Jonathan McCrohan | 2010 | -11120/+159271 |
2014-07-23 | Release 0+git20140611.14bd6c7-1debian/0+git20140611.14bd6c7-1 | Jonathan McCrohan | 1 | -2/+2 |
2014-07-23 | New Upstream Snapshot (commit 14bd6c7) | Jonathan McCrohan | 1 | -2/+3 |
2014-07-23 | Imported Upstream version 0+git20140611.14bd6c7upstream/0+git20140611.14bd6c7 | Jonathan McCrohan | 7 | -11/+60 |
2014-05-13 | New Upstream Snapshot (commit 1246b27) | Jonathan McCrohan | 1 | -0/+6 |
2014-05-13 | Imported Upstream version 0+git20140512.1246b27upstream/0+git20140512.1246b27 | Jonathan McCrohan | 391 | -301/+3983 |
2014-04-05 | Release 0+git20140326.cfc2975-1debian/0+git20140326.cfc2975-1 | Jonathan McCrohan | 1 | -2/+2 |
2014-04-05 | d/control: update Homepage (upstream has moved from Gitweb to cgit) | Jonathan McCrohan | 2 | -1/+2 |
2014-04-05 | New Upstream Snapshot (commit cfc2975) | Jonathan McCrohan | 1 | -0/+6 |
2014-04-05 | Imported Upstream version 0+git20140326.cfc2975upstream/0+git20140326.cfc2975 | Jonathan McCrohan | 118 | -656/+877 |
2014-01-16 | Release 0+git20140107.1850cf8-1debian/0+git20140107.1850cf8-1 | Jonathan McCrohan | 1 | -2/+2 |
2014-01-16 | Update Standards Version to 3.9.5 | Jonathan McCrohan | 2 | -1/+9 |