shithub: libini

ref: 61a400cc2f9b50b4a39537eb9d0981df77347929
dir: /test.c/

View raw version
#include <u.h>
#include <libc.h>
#include "ini.h"

void
parseline(char *section, char *key, char *value, int)
{
	print("section: '%s', key: '%s', value: '%s'\n", section, key, value);
}

void
main(int, char **argv)
{
	char *file = argv[1];
	char *status = nil;
	char *err = "error";
	
	print("Testing forcelower=0\n\n");
	
	if (!parseini(file, parseline, 0, 0)) {
		fprint(2, "error: %r\n");
		status = err;
	}
	
	print("\nTesting forcelower=1\n\n");
	
	if (!parseini(file, parseline, 1, 0)) {
		fprint(2, "error: %r\n");
		status = err;
	}
	
	print("\nTesting iniconfig\n\n");
	int conf = iniconfig(file, 0);
	
	char* v = getinivalue(conf, "Category A", "keyB");
	print("Category A, keyB: %s\n", v);
	
	int num;
	char** values = getiniarray(conf, "Category C", "keyF", &num);
	if (values) {
		for (int i = 0; i < num; i++) {
			print("array: %s\n", values[i]);
		}
	}
	
	v = getinivalue(conf, nil, "nocat");
	print("no category, nocat: %s\n", v);
	
	values = getiniarray(conf, nil, "nocatarr", &num);
	if (values) {
		for (int i = 0; i < num; i++) {
			print("nocatarr: %s\n", values[i]);
		}
	}
	
	exits(status);
}