# HG changeset patch # User David Demelier # Date 1336689458 -7200 # Node ID 24efccba44e40fe9424c13f83720ef7430c37539 # Parent 594ca7f7139bed8f492d353894061ec75e76cd51 Remove tests diff -r 594ca7f7139b -r 24efccba44e4 ini.c --- a/ini.c Fri May 11 00:12:08 2012 +0200 +++ b/ini.c Fri May 11 00:37:38 2012 +0200 @@ -160,6 +160,12 @@ fputc('\n', stdout); } + if (F_FAILERROR(cg)) { + va_start(ap, fmt); + vsnprintf(cg->pv->error, sizeof (cg->pv->error), fmt, ap); + va_end(ap); + } + va_end(ap); } @@ -499,8 +505,12 @@ if (!cg && errno != 0) return strerror(errno); - if (cg->pv->error[0] == '\0') + if (cg->pv->error[0] == '\0') { + if (errno != 0) + return strerror(errno); + return "No error"; + } return cg->pv->error; } diff -r 594ca7f7139b -r 24efccba44e4 tests/ini_test.c --- a/tests/ini_test.c Fri May 11 00:12:08 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -#include -#include -#include -#include -#include - -#include "ini.h" - -#define LENGTH(x) (sizeof (x)/ sizeof (x[0])) - -/* - * Use this test file with the ini_test.conf like this : - * - * # - * # config file ini_test.conf - * # - * [general] - * nickname = "markand" - * email = "markand@malikania.fr" - * - * [ui] - * verbose = true - * editor = vim - * - * # multiple definition - * [host] - * alias = "freenode" - * host = "irc.freenode.net" - * port = 6667 - * - * [host] - * alias = "malikania" - * host = "irc.malikania.fr" - * port = 6667 - */ - -static void -list_servers(const INI_Config *config) -{ - /* Server parameters */ - char *alias = NULL, *host = NULL; - int port = 0; - - /* Extract server information */ - INI_Handler settings[] = { - /* option, destination, conversion function */ - { "alias", &alias, &ini_convert_string }, - { "host", &host, &ini_convert_string }, - { "port", &port, &ini_convert_int } - }; - - INI_Section *sc; - - /* - * All sections are added as linked list, so you can just - * seek all and keep only the ones you want. - */ - for (sc = config->sections; sc != NULL; sc = sc->next) { - /* Keep only [host] */ - if (strcmp(sc->key, "host") != 0) - continue; - - ini_dispatch(sc, settings, LENGTH(settings)); - printf("-- new server\n"); - printf("-> alias = %s\n", (alias != NULL) ? alias : ""); - printf("-> host = %s\n", (host != NULL) ? host : ""); - printf("-> port = %d\n", port); - - free(alias); alias = NULL; - free(host); host = NULL; - } -} - -static void -list_options(const INI_Config *config) -{ - char *nickname = NULL, *email = NULL, *editor = NULL; - bool verbose = 0; - - /* Extract [general] to their values */ - INI_Handler general[] = { - /* option, destination, conversion function */ - { "nickname", &nickname, &ini_convert_string }, - { "email", &email, &ini_convert_string } - }; - - /* Extract [ui] to their values */ - INI_Handler ui[] = { - /* option, destination, conversion function */ - { "verbose", &verbose, &ini_convert_bool }, - { "editor", &editor, &ini_convert_string } - }; - - INI_Section *sc; - - /* Always check if the section is present before dispatching */ - if ((sc = ini_select_section(config, "general")) != NULL) - ini_dispatch(sc, general, LENGTH(general)); - if ((sc = ini_select_section(config, "ui")) != NULL) - ini_dispatch(sc, ui, LENGTH(ui)); - - printf("-- general\n"); - printf("-> nickname = %s\n", (nickname != NULL) ? nickname : ""); - printf("-> email = %s\n", (email != NULL) ? email : ""); - printf("-- ui\n"); - printf("-> verbose = %s\n", (verbose) ? "true" : "false"); - printf("-> editor = %s\n", (editor != NULL) ? editor : ""); - - free(nickname); free(email); free(editor); -} - -static void -list_raw(const INI_Config *config) -{ - INI_Section *sc; - INI_Option *opt; - - printf("-- dump of config\n"); - for (sc = config->sections; sc != NULL; sc = sc->next) - for (opt = sc->options; opt != NULL; opt = opt->next) - printf("%s.%s = %s\n", sc->key, opt->key, - (opt->value == NULL) ? "" : opt->value); -} - -int -main(void) -{ - INI_Config *config; - - /* - * 1. Try to load the file, it may fails (not found, permissions, - * memory, ...) so check everytime. - * - * INI_VERBOSE flag is great to tell the user about typo in file - */ - if ((config = ini_load("ini_test.conf", INI_VERBOSE)) == NULL) - errx(1, "%s", ini_get_error()); - - /* 2. List all servers found as [host] */ - list_servers(config); - - /* 3. List options from [general] and [ui] */ - list_options(config); - - /* 4. List all options from all sections */ - list_raw(config); - - /* Finally free everything */ - ini_free(config, 1, 1); - - return 0; -} diff -r 594ca7f7139b -r 24efccba44e4 tests/ini_test.conf --- a/tests/ini_test.conf Fri May 11 00:12:08 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -# -# config file ini_test.conf -# -[general] -nickname = "markand" -email = "markand@malikania.fr" - -[ui] -verbose = true -editor = vim - -# multiple definition -[host] -alias = "freenode" -host = "irc.freenode.net" -port = 6667 - -[host] -alias = "malikania" -host = "irc.malikania.fr" -port = 6667 - -# vim: set syntax=cfg: