Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Rework libucl import
Baptiste Daroussin committed 12 years ago
commit d5cb0f3acefafd7dfef131959ab779bc52a9ba6f
parent bbbd957
34 files changed +1916 -34
deleted external/libucl/Makefile
@@ -1,34 +0,0 @@
-
.include <bsd.own.mk>
-

-
LIB=	ucl
-
INTERNALLIB=
-

-
SRCS=	src/ucl_emitter.c \
-
	src/ucl_parser.c \
-
	src/ucl_util.c \
-
	src/ucl_hash.c \
-
	src/xxhash.c
-

-
CFLAGS=	-I${.CURDIR}/uthash \
-
	-I${.CURDIR}/include \
-
	-I${.CURDIR}/src
-

-
.if defined(TARGET_ARCH)
-
ARCH=	${TARGET_ARCH}
-
.else
-
ARCH=	${MACHINE_ARCH}
-
.endif
-

-
.if ${ARCH} == amd64 || ${ARCH} == x86_64
-
CFLAGS+=	-fPIC
-
.endif
-

-
OSVERSION!=	/sbin/sysctl -n kern.osreldate
-

-
.if ${OSVERSION} < 901000
-
.c.o:
-
	${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
-
.endif
-

-
WARNS=	1
-
.include <bsd.lib.mk>
added external/libucl/Makefile.unix
@@ -0,0 +1,79 @@
+
CC ?= gcc
+
DESTDIR ?= /usr/local
+
LD ?= gcc
+
C_COMMON_FLAGS ?= -fPIC -Wall -W -Wno-unused-parameter -Wno-pointer-sign -I./include -I./uthash -I./src
+
MAJOR_VERSION = 0
+
MINOR_VERSION = 2
+
PATCH_VERSION = 8
+
VERSION = "$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)"
+
SONAME = libucl.so
+
SONAME_FULL = $(SONAME).$(MAJOR_VERSION)
+
OBJDIR ?= .obj
+
TESTDIR ?= tests
+
SRCDIR ?= src
+
INCLUDEDIR ?= include
+
MKDIR ?= mkdir
+
INSTALL ?= install
+
RM ?= rm
+
RMDIR ?= rmdir
+
LN ?= ln
+
LD_SHARED_FLAGS ?= -Wl,-soname,$(SONAME) -shared -lm
+
LD_UCL_FLAGS ?= -L$(OBJDIR) -Wl,-rpath,$(OBJDIR) -lucl
+
LD_ADD ?= -lrt
+
COPT_FLAGS ?= -O2
+
HDEPS = $(SRCDIR)/ucl_hash.h $(SRCDIR)/ucl_chartable.h $(SRCDIR)/ucl_internal.h $(INCLUDEDIR)/ucl.h $(SRCDIR)/xxhash.h
+
OBJECTS = $(OBJDIR)/ucl_hash.o $(OBJDIR)/ucl_util.o $(OBJDIR)/ucl_parser.o $(OBJDIR)/ucl_emitter.o $(OBJDIR)/xxhash.o
+

+
all: $(OBJDIR) $(OBJDIR)/$(SONAME)
+

+
$(OBJDIR)/$(SONAME): $(OBJDIR)/$(SONAME_FULL)
+
	$(LN) -sf $(SONAME_FULL) $(OBJDIR)/$(SONAME)
+

+
$(OBJDIR)/$(SONAME_FULL): $(OBJECTS)
+
	$(CC) -o $(OBJDIR)/$(SONAME_FULL) $(OBJECTS) $(LD_SHARED_FLAGS) $(LDFLAGS) $(SSL_LIBS) $(FETCH_LIBS)
+

+
$(OBJDIR):
+
	@$(MKDIR) -p $(OBJDIR)
+

+
# Compile rules
+
$(OBJDIR)/ucl_util.o: $(SRCDIR)/ucl_util.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_util.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_util.c
+
$(OBJDIR)/ucl_parser.o: $(SRCDIR)/ucl_parser.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_parser.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_parser.c
+
$(OBJDIR)/ucl_emitter.o: $(SRCDIR)/ucl_emitter.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_emitter.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_emitter.c
+
$(OBJDIR)/ucl_hash.o: $(SRCDIR)/ucl_hash.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_hash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_hash.c
+
$(OBJDIR)/xxhash.o: $(SRCDIR)/xxhash.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/xxhash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/xxhash.c
+

+
clean:
+
	$(RM) $(OBJDIR)/*.o $(OBJDIR)/$(SONAME_FULL) $(OBJDIR)/$(SONAME) $(OBJDIR)/chargen $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/objdump $(OBJDIR)/test_generate
+
	$(RMDIR) $(OBJDIR)
+
	
+
# Utils
+

+
chargen: utils/chargen.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/chargen $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/chargen.c
+
objdump: utils/objdump.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/objdump $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/objdump.c $(LD_UCL_FLAGS)
+

+
# Tests
+

+
test: $(OBJDIR) $(OBJDIR)/$(SONAME) $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate
+

+
run-test: test
+
	TEST_DIR=$(TESTDIR) $(TESTDIR)/run_tests.sh $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate
+
	
+
$(OBJDIR)/test_basic: $(TESTDIR)/test_basic.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/test_basic $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_basic.c $(LD_UCL_FLAGS)
+
$(OBJDIR)/test_speed: $(TESTDIR)/test_speed.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/test_speed $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_speed.c $(LD_UCL_FLAGS) $(LD_ADD)
+
$(OBJDIR)/test_generate: $(TESTDIR)/test_generate.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/test_generate $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_generate.c $(LD_UCL_FLAGS) $(LD_ADD)
+

+
install: $(OBJDIR)/$(SONAME)
+
	$(INSTALL) -m0755 $(SONAME) $(DESTDIR)/lib/$(SONAME)
+
	$(INSTALL) -m0644 include/ucl.h $(DESTDIR)/include/ucl.h
+

+
.PHONY: clean $(OBJDIR)
added external/libucl/Makefile.w32
@@ -0,0 +1,79 @@
+
CC ?= gcc
+
DESTDIR ?= /usr/local
+
LD ?= gcc
+
C_COMMON_FLAGS ?= -fPIC -Wall -W -Wno-unused-parameter -Wno-pointer-sign -I./include -I./uthash -I./src
+
MAJOR_VERSION = 0
+
MINOR_VERSION = 2
+
PATCH_VERSION = 8
+
VERSION = "$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)"
+
SONAME = libucl.dll
+
OBJDIR ?= .obj
+
TESTDIR ?= tests
+
SRCDIR ?= src
+
INCLUDEDIR ?= include
+
MKDIR ?= mkdir
+
INSTALL ?= install
+
RM ?= rm
+
RMDIR ?= rmdir
+
ifeq (Windows_NT, $(OS))
+
LN ?= ln
+
else
+
LN ?= rem ln
+
endif
+
LD_SHARED_FLAGS ?= -Wl,-soname,$(SONAME) -shared -lm
+
LD_UCL_FLAGS ?= -L$(OBJDIR) -Wl,-rpath,$(OBJDIR) -lucl
+
LD_ADD ?= -lrt
+
COPT_FLAGS ?= -O2
+
HDEPS = $(SRCDIR)/ucl_hash.h $(SRCDIR)/ucl_chartable.h $(SRCDIR)/ucl_internal.h $(INCLUDEDIR)/ucl.h $(SRCDIR)/xxhash.h
+
OBJECTS = $(OBJDIR)/ucl_hash.o $(OBJDIR)/ucl_util.o $(OBJDIR)/ucl_parser.o $(OBJDIR)/ucl_emitter.o $(OBJDIR)/xxhash.o
+

+
all: $(OBJDIR) $(OBJDIR)/$(SONAME)
+

+
$(OBJDIR)/$(SONAME): $(OBJECTS)
+
	$(CC) -o $(OBJDIR)/$(SONAME) $(OBJECTS) $(LD_SHARED_FLAGS) $(LDFLAGS) $(SSL_LIBS) $(FETCH_LIBS)
+

+
$(OBJDIR):
+
	@$(MKDIR) -p $(OBJDIR)
+

+
# Compile rules
+
$(OBJDIR)/ucl_util.o: $(SRCDIR)/ucl_util.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_util.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_util.c
+
$(OBJDIR)/ucl_parser.o: $(SRCDIR)/ucl_parser.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_parser.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_parser.c
+
$(OBJDIR)/ucl_emitter.o: $(SRCDIR)/ucl_emitter.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_emitter.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_emitter.c
+
$(OBJDIR)/ucl_hash.o: $(SRCDIR)/ucl_hash.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/ucl_hash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/ucl_hash.c
+
$(OBJDIR)/xxhash.o: $(SRCDIR)/xxhash.c $(HDEPS)
+
	$(CC) -o $(OBJDIR)/xxhash.o $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) -c $(SRCDIR)/xxhash.c
+

+
clean:
+
	$(RM) $(OBJDIR)/*.o $(OBJDIR)/$(SONAME) $(OBJDIR)/$(SONAME) $(OBJDIR)/chargen $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/objdump $(OBJDIR)/test_generate
+
	$(RMDIR) $(OBJDIR)
+
	
+
# Utils
+

+
chargen: utils/chargen.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/chargen $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/chargen.c
+
objdump: utils/objdump.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/objdump $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) utils/objdump.c $(LD_UCL_FLAGS)
+

+
# Tests
+

+
test: $(OBJDIR) $(OBJDIR)/$(SONAME) $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate
+

+
run-test: test
+
	TEST_DIR=$(TESTDIR) $(TESTDIR)/run_tests.sh $(OBJDIR)/test_basic $(OBJDIR)/test_speed $(OBJDIR)/test_generate
+
	
+
$(OBJDIR)/test_basic: $(TESTDIR)/test_basic.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/test_basic $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_basic.c $(LD_UCL_FLAGS)
+
$(OBJDIR)/test_speed: $(TESTDIR)/test_speed.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/test_speed $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_speed.c $(LD_UCL_FLAGS) $(LD_ADD)
+
$(OBJDIR)/test_generate: $(TESTDIR)/test_generate.c $(OBJDIR)/$(SONAME)
+
	$(CC) -o $(OBJDIR)/test_generate $(CPPFLAGS) $(COPT_FLAGS) $(CFLAGS) $(C_COMMON_FLAGS) $(SSL_CFLAGS) $(FETCH_FLAGS) $(LDFLAGS) $(TESTDIR)/test_generate.c $(LD_UCL_FLAGS) $(LD_ADD)
+

+
install: $(OBJDIR)/$(SONAME)
+
	$(INSTALL) -m0755 $(SONAME) $(DESTDIR)/lib/$(SONAME)
+
	$(INSTALL) -m0644 include/ucl.h $(DESTDIR)/include/ucl.h
+

+
.PHONY: clean $(OBJDIR)
added external/libucl/README.md
@@ -0,0 +1,300 @@
+
## Introduction
+

+
This document describes the main features and principles of the configuration
+
language called `UCL` - universal configuration language.
+

+
If you are looking for the libucl API documentation you can find it at [this page](doc/api.md).
+

+
## Basic structure
+

+
UCL is heavily infused by `nginx` configuration as the example of a convenient configuration
+
system. However, UCL is fully compatible with `JSON` format and is able to parse json files.
+
For example, you can write the same configuration in the following ways:
+

+
* in nginx like:
+

+
```nginx
+
param = value;
+
section {
+
    param = value;
+
    param1 = value1;
+
    flag = true;
+
    number = 10k;
+
    time = 0.2s;
+
    string = "something";
+
    subsection {
+
        host = {
+
            host = "hostname"; 
+
            port = 900;
+
        }
+
        host = {
+
            host = "hostname";
+
            port = 901;
+
        }
+
    }
+
}
+
```
+

+
* or in JSON:
+

+
```json
+
{
+
    "param": "value",
+
    "param1": "value1",
+
    "flag": true,
+
    "subsection": {
+
        "host": [
+
        {
+
            "host": "hostname",
+
            "port": 900
+
        },
+
        {
+
            "host": "hostname",
+
            "port": 901
+
        }
+
        ]
+
    }
+
}
+
```
+

+
## Improvements to the json notation.
+

+
There are various things that make ucl configuration more convenient for editing than strict json:
+

+
### General syntax sugar
+

+
* Braces are not necessary to enclose a top object: it is automatically treated as an object:
+

+
```json
+
"key": "value"
+
```
+
is equal to:
+
```json
+
{"key": "value"}
+
```
+

+
* There is no requirement of quotes for strings and keys, moreover, `:` may be replaced `=` or even be skipped for objects:
+

+
```nginx
+
key = value;
+
section {
+
    key = value;
+
}
+
```
+
is equal to:
+
```json
+
{
+
    "key": "value",
+
    "section": {
+
        "key": "value"
+
    }
+
}
+
```
+

+
* No commas mess: you can safely place a comma or semicolon for the last element in an array or an object:
+

+
```json
+
{
+
    "key1": "value",
+
    "key2": "value",
+
}
+
```
+
### Automatic arrays creation
+

+
* Non-unique keys in an object are allowed and are automatically converted to the arrays internally:
+

+
```json
+
{
+
    "key": "value1",
+
    "key": "value2"
+
}
+
```
+
is converted to:
+
```json
+
{
+
    "key": ["value1", "value2"]
+
}
+
```
+

+
### Named keys hierarchy
+

+
UCL accepts named keys and organize them into objects hierarchy internally. Here is an example of this process:
+
```nginx
+
section "blah" {
+
	key = value;
+
}
+
section foo {
+
	key = value;
+
}
+
```
+

+
is converted to the following object:
+

+
```nginx
+
section {
+
	blah {
+
			key = value;
+
	}
+
	foo {
+
			key = value;
+
	}
+
}
+
```
+
    
+
Plain definitions may be more complex and contain more than a single level of nested objects:
+
   
+
```nginx
+
section "blah" "foo" {
+
	key = value;
+
}
+
```
+

+
is presented as:
+

+
```nginx    
+
section {
+
	blah {
+
			foo {
+
					key = value;
+
			}
+
	}
+
}
+
```
+

+
### Convenient numbers and booleans
+

+
* Numbers can have suffixes to specify standard multipliers:
+
    + `[kKmMgG]` - standard 10 base multipliers (so `1k` is translated to 1000)
+
    + `[kKmMgG]b` - 2 power multipliers (so `1kb` is translated to 1024)
+
    + `[s|min|d|w|y]` - time multipliers, all time values are translated to float number of seconds, for example `10min` is translated to 600.0 and `10ms` is translated to 0.01
+
* Hexadecimal integers can be used by `0x` prefix, for example `key = 0xff`. However, floating point values can use decimal base only.
+
* Booleans can be specified as `true` or `yes` or `on` and `false` or `no` or `off`.
+
* It is still possible to treat numbers and booleans as strings by enclosing them in double quotes.
+

+
## General improvements
+

+
### Commments
+

+
UCL supports different style of comments:
+

+
* single line: `#` 
+
* multiline: `/* ... */`
+

+
Multiline comments may be nested:
+
```c
+
# Sample single line comment
+
/* 
+
 some comment
+
 /* nested comment */
+
 end of comment
+
*/
+
```
+

+
### Macros support
+

+
UCL supports external macros both multiline and single line ones:
+
```nginx
+
.macro "sometext";
+
.macro {
+
     Some long text
+
     ....
+
};
+
```
+
There are two internal macros provided by UCL:
+

+
* `include` - read a file `/path/to/file` or an url `http://example.com/file` and include it to the current place of
+
UCL configuration;
+
* `try\_include` - try to read a file or url and include it but do not create a fatal error if a file or url is not accessible;
+
* `includes` - read a file or an url like the previous macro, but fetch and check the signature file (which is obtained
+
by `.sig` suffix appending).
+

+
Public keys which are used for the last command are specified by the concrete UCL user.
+

+
### Variables support
+

+
UCL supports variables in input. Variables are registered by a user of the UCL parser and can be presented in the following forms:
+

+
* `${VARIABLE}`
+
* `$VARIABLE`
+

+
UCL currently does not support nested variables. To escape variables one could use double dollar signs:
+

+
* `$${VARIABLE}` is converted to `${VARIABLE}`
+
* `$$VARIABLE` is converted to `$VARIABLE`
+

+
However, if no valid variables are found in a string, no expansion will be performed (and `$$` thus remains unchanged). This may be a subject
+
to change in future libucl releases.
+

+
### Multiline strings
+

+
UCL can handle multiline strings as well as single line ones. It uses shell/perl like notation for such objects:
+
```
+
key = <<EOD
+
some text
+
splitted to
+
lines
+
EOD
+
```
+

+
In this example `key` will be interpreted as the following string: `some text\nsplitted to\nlines`.
+
Here are some rules for this syntax:
+

+
* Multiline terminator must start just after `<<` symbols and it must consist of capital letters only (e.g. `<<eof` or `<< EOF` won't work);
+
* Terminator must end with a single newline character (and no spaces are allowed between terminator and newline character);
+
* To finish multiline string you need to include a terminator string just after newline and followed by a newline (no spaces or other characters are allowed as well);
+
* The initial and the final newlines are not inserted to the resulting string, but you can still specify newlines at the begin and at the end of a value, for example:
+

+
```
+
key <<EOD
+

+
some
+
text
+

+
EOD
+
```
+

+
## Emitter
+

+
Each UCL object can be serialized to one of the three supported formats:
+

+
* `JSON` - canonic json notation (with spaces indented structure);
+
* `Compacted JSON` - compact json notation (without spaces or newlines);
+
* `Configuration` - nginx like notation;
+
* `YAML` - yaml inlined notation.
+

+
## Performance
+

+
Are UCL parser and emitter fast enough? Well, there are some numbers.
+
I got a 19Mb file that consist of ~700 thousands lines of json (obtained via
+
http://www.json-generator.com/). Then I checked jansson library that performs json
+
parsing and emitting and compared it with UCL. Here are results:
+

+
```
+
jansson: parsed json in 1.3899 seconds
+
jansson: emitted object in 0.2609 seconds
+

+
ucl: parsed input in 0.6649 seconds
+
ucl: emitted config in 0.2423 seconds
+
ucl: emitted json in 0.2329 seconds
+
ucl: emitted compact json in 0.1811 seconds
+
ucl: emitted yaml in 0.2489 seconds
+
```
+

+
So far, UCL seems to be significantly faster than jansson on parsing and slightly faster on emitting. Moreover,
+
UCL compiled with optimizations (-O3) performs significantly faster:
+
```
+
ucl: parsed input in 0.3002 seconds
+
ucl: emitted config in 0.1174 seconds
+
ucl: emitted json in 0.1174 seconds
+
ucl: emitted compact json in 0.0991 seconds
+
ucl: emitted yaml in 0.1354 seconds
+
```
+

+
You can do your own benchmarks by running `make test` in libucl top directory.
+

+
## Conclusion
+

+
UCL has clear design that should be very convenient for reading and writing. At the same time it is compatible with
+
JSON language and therefore can be used as a simple JSON parser. Macroes logic provides an ability to extend configuration
+
language (for example by including some lua code) and comments allows to disable or enable the parts of a configuration
+
quickly.
added external/libucl/doc/api.md
@@ -0,0 +1,348 @@
+
Synopsis
+
========
+

+
`#include <ucl.h>`
+

+
Description
+
===========
+

+
Libucl is a parser and `C` API to parse and generate `ucl` objects. Libucl consist of several groups of functions:
+

+
### Parser functions
+
Used to parse `ucl` files and provide interface to extract `ucl` object
+

+
### Emitting functions
+
Convert `ucl` objects to some textual or binary representation.
+

+
### Conversion functions
+
Help to convert `ucl` objects to C types
+

+
### Generation functions
+
Allow creating of `ucl` objects from C types
+

+
### Iteration functions
+
Iterate over `ucl` objects
+

+
### Utility functions
+
Provide basic utilities to manage `ucl` objects
+

+
# Parser functions
+

+
Parser functions operates with `struct ucl_parser`.
+

+
### ucl_parser_new
+

+
~~~C
+
struct ucl_parser* ucl_parser_new (int flags);
+
~~~
+

+
Creates new parser with the specified flags:
+

+
- `UCL_PARSER_KEY_LOWERCASE` - lowercase keys parsed
+
- `UCL_PARSER_ZEROCOPY` - try to use zero-copy mode when reading files (in zero-copy mode text chunk being parsed without copying strings so it should exist till any object parsed is used)
+

+
### ucl_parser_register_macro
+

+
~~~C
+
void ucl_parser_register_macro (struct ucl_parser *parser,
+
    const char *macro, ucl_macro_handler handler, void* ud);
+
~~~
+

+
Register new macro with name .`macro` parsed by handler `handler` that accepts opaque data pointer `ud`. Macro handler should be of the following type:
+

+
~~~C
+
bool (*ucl_macro_handler) (const unsigned char *data,
+
    size_t len, void* ud);`
+
~~~
+

+
Handler function accepts macro text `data` of length `len` and the opaque pointer `ud`. If macro is parsed successfully the handler should return `true`. `false` indicates parsing failure and the parser can be terminated.
+

+
### ucl_parser_register_variable
+

+
~~~C
+
void ucl_parser_register_variable (struct ucl_parser *parser,
+
    const char *var, const char *value);
+
~~~
+

+
Register new variable $`var` that should be replaced by the parser to the `value` string.
+

+
### ucl_parser_add_chunk
+

+
~~~C
+
bool ucl_parser_add_chunk (struct ucl_parser *parser, 
+
    const unsigned char *data, size_t len);
+
~~~
+

+
Add new text chunk with `data` of length `len` to the parser. At the moment, `libucl` parser is not a streamlined parser and chunk *must* contain the *valid* ucl object. For example, this object should be valid:
+

+
~~~json
+
{ "var": "value" }
+
~~~
+

+
while this one won't be parsed correctly:
+

+
~~~json
+
{ "var": 
+
~~~
+

+
This limitation may possible be removed in future.
+

+
### ucl_parser_add_file
+

+
~~~C
+
bool ucl_parser_add_file (struct ucl_parser *parser, 
+
    const char *filename);
+
~~~
+

+
Load file `filename` and parse it with the specified `parser`. This function uses `mmap` call to load file, therefore, it should not be `shrinked` during parsing. Otherwise, `libucl` can cause memory corruption and terminate the calling application. This function is also used by the internal handler of `include` macro, hence, this macro has the same limitation.
+

+
### ucl_parser_get_object
+

+
~~~C
+
ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser);
+
~~~
+

+
If the `ucl` data has been parsed correctly this function returns the top object for the parser. Otherwise, this function returns the `NULL` pointer. The reference count for `ucl` object returned is increased by one, therefore, a caller should decrease reference by using `ucl_object_unref` to free object after usage.
+

+
### ucl_parser_get_error
+

+
~~~C
+
const char *ucl_parser_get_error(struct ucl_parser *parser);
+
~~~
+

+
Returns the constant error string for the parser object. If no error occurred during parsing a `NULL` object is returned. A caller should not try to free or modify this string.
+

+
### ucl_parser_free
+

+
~~~C
+
void ucl_parser_free (struct ucl_parser *parser);
+
~~~
+

+
Frees memory occupied by the parser object. The reference count for top object is decreased as well, however if the function `ucl_parser_get_object` was called previously then the top object won't be freed.
+

+
### ucl_pubkey_add
+

+
~~~C
+
bool ucl_pubkey_add (struct ucl_parser *parser, 
+
    const unsigned char *key, size_t len);
+
~~~
+

+
This function adds a public key from text blob `key` of length `len` to the `parser` object. This public key should be in the `PEM` format and can be used by `.includes` macro for checking signatures of files included. `Openssl` support should be enabled to make this function working. If a key cannot be added (e.g. due to format error) or `openssl` was not linked to `libucl` then this function returns `false`.
+

+
### ucl_parser_set_filevars
+

+
~~~C
+
bool ucl_parser_set_filevars (struct ucl_parser *parser, 
+
    const char *filename, bool need_expand);
+
~~~
+

+
Add the standard file variables to the `parser` based on the `filename` specified:
+

+
- `$FILENAME` - a filename of `ucl` input
+
- `$CURDIR` - a current directory of the input
+

+
For example, if a `filename` param is `../something.conf` then the variables will have the following values:
+

+
- `$FILENAME` - "../something.conf"
+
- `$CURDIR` - ".."
+

+
if `need_expand` parameter is `true` then all relative paths are expanded using `realpath` call. In this example if `..` is `/etc/dir` then variables will have these values:
+

+
- `$FILENAME` - "/etc/something.conf"
+
- `$CURDIR` - "/etc"
+

+
## Parser usage example
+

+
The following example loads, parses and extracts `ucl` object from stdin using `libucl` parser functions (the length of input is limited to 8K):
+

+
~~~C
+
char inbuf[8192];
+
struct ucl_parser *parser = NULL;
+
int ret = 0, r = 0;
+
ucl_object_t *obj = NULL;
+
FILE *in;
+

+
in = stdin;
+
parser = ucl_parser_new (0);
+
while (!feof (in) && r < (int)sizeof (inbuf)) {
+
	r += fread (inbuf + r, 1, sizeof (inbuf) - r, in);
+
}
+
ucl_parser_add_chunk (parser, inbuf, r);
+
fclose (in);
+

+
if (ucl_parser_get_error (parser)) {
+
	printf ("Error occured: %s\n", ucl_parser_get_error (parser));
+
	ret = 1;
+
}
+
else {
+
    obj = ucl_parser_get_object (parser);
+
}
+

+
if (parser != NULL) {
+
	ucl_parser_free (parser);
+
}
+
if (obj != NULL) {
+
	ucl_object_unref (obj);
+
}
+
return ret;
+
~~~
+

+
# Emitting functions
+

+
Libucl can transform UCL objects to a number of tectual formats:
+

+
- configuration (`UCL_EMIT_CONFIG`) - nginx like human readable configuration file where implicit arrays are transformed to the duplicate keys
+
- compact json: `UCL_EMIT_JSON_COMPACT` - single line valid json without spaces
+
- formatted json: `UCL_EMIT_JSON` - pretty formatted JSON with newlines and spaces
+
- compact yaml: `UCL_EMIT_YAML` - compact YAML output
+

+
Moreover, libucl API allows to select a custom set of emitting functions allowing 
+
efficent and zero-copy output of libucl objects. Libucl uses the following structure to support this feature:
+

+
~~~C
+
struct ucl_emitter_functions {
+
	/** Append a single character */
+
	int (*ucl_emitter_append_character) (unsigned char c, size_t nchars, void *ud);
+
	/** Append a string of a specified length */
+
	int (*ucl_emitter_append_len) (unsigned const char *str, size_t len, void *ud);
+
	/** Append a 64 bit integer */
+
	int (*ucl_emitter_append_int) (int64_t elt, void *ud);
+
	/** Append floating point element */
+
	int (*ucl_emitter_append_double) (double elt, void *ud);
+
	/** Opaque userdata pointer */
+
	void *ud;
+
};
+
~~~
+

+
This structure defines the following callbacks:
+

+
- `ucl_emitter_append_character` - a function that is called to append `nchars` characters equal to `c`
+
- `ucl_emitter_append_len` - used to append a string of length `len` starting from pointer `str`
+
- `ucl_emitter_append_int` - this function applies to integer numbers
+
- `ucl_emitter_append_double` - this function is intended to output floating point variable
+

+
The set of these functions could be used to output text formats of `UCL` objects to different structures or streams.
+

+
Libucl provides the following functions for emitting UCL objects:
+

+
### ucl_object_emit
+

+
~~~C
+
unsigned char *ucl_object_emit (ucl_object_t *obj, enum ucl_emitter emit_type);
+
~~~
+

+
Allocate a string that is suitable to fit the underlying UCL object `obj` and fill it with the textual representation of the object `obj` according to style `emit_type`. The caller should free the returned string after using.
+

+
### ucl_object_emit_full
+

+
~~~C
+
bool ucl_object_emit_full (ucl_object_t *obj, enum ucl_emitter emit_type,
+
		struct ucl_emitter_functions *emitter);
+
~~~
+

+
This function is similar to the previous with the exception that it accepts the additional argument `emitter` that defines the concrete set of output functions. This emit function could be useful for custom structures or streams emitters (including C++ ones, for example).
+

+
# Conversion functions
+

+
Conversion functions are used to convert UCL objects to primitive types, such as strings, numbers or boolean values. There are two types of conversion functions:
+

+
- safe: try to convert an ucl object to a primitive type and fail if such a conversion is not possible
+
- unsafe: return primitive type without additional checks, if the object cannot be converted then some reasonable default is returned (NULL for strings and 0 for numbers)
+

+
Also there is a single `ucl_object_tostring_forced` function that converts any UCL object (including compound types - arrays and objects) to a string representation. For compound and numeric types this function performs emitting to a compact json format actually.
+

+
Here is a list of all conversion functions:
+

+
- `ucl_object_toint` - returns `int64_t` of UCL object
+
- `ucl_object_todouble` - returns `double` of UCL object
+
- `ucl_object_toboolean` - returns `bool` of UCL object
+
- `ucl_object_tostring` - returns `const char *` of UCL object (this string is NULL terminated)
+
- `ucl_object_tolstring` - returns `const char *` and `size_t` len of UCL object (string can be not NULL terminated)
+
- `ucl_object_tostring_forced` - returns string representation of any UCL object
+

+
Strings returned by these pointers are associated with the UCL object and exist over its lifetime. A caller should not free this memory.
+

+
# Generation functions
+

+
It is possible to generate UCL objects from C primitive types. Moreover, libucl permits to create and modify complex UCL objects, such as arrays or associative objects. 
+

+
## ucl_object_new
+
~~~C
+
ucl_object_t * ucl_object_new (void)
+
~~~
+

+
Creates new object of type `UCL_NULL`. This object should be released by caller.
+

+
## ucl_object_typed_new
+
~~~C
+
ucl_object_t * ucl_object_typed_new (unsigned int type)
+
~~~
+

+
Create an object of a specified type:
+
- `UCL_OBJECT` - UCL object - key/value pairs
+
- `UCL_ARRAY` - UCL array
+
- `UCL_INT` - integer number
+
- `UCL_FLOAT` - floating point number
+
- `UCL_STRING` - NULL terminated string
+
- `UCL_BOOLEAN` - boolean value
+
- `UCL_TIME` - time value (floating point number of seconds)
+
- `UCL_USERDATA` - opaque userdata pointer (may be used in macros)
+
- `UCL_NULL` - null value
+

+
This object should be released by caller.
+

+
## Primitive objects generation
+
Libucl provides the functions similar to inverse conversion functions called with the specific C type:
+
- `ucl_object_fromint` - converts `int64_t` to UCL object
+
- `ucl_object_fromdouble` - converts `double` to UCL object
+
- `ucl_object_fromboolean` - converts `bool` to UCL object
+
- `ucl_object_fromstring` - converts `const char *` to UCL object (this string is NULL terminated)
+
- `ucl_object_fromlstring` - converts `const char *` and `size_t` len to UCL object (string can be not NULL terminated)
+

+
Also there is a function to generate UCL object from a string performing various parsing or conversion operations called `ucl_object_fromstring_common`.
+

+
## ucl_object_fromstring_common
+
~~~C
+
ucl_object_t * ucl_object_fromstring_common (const char *str, 
+
	size_t len, enum ucl_string_flags flags)
+
~~~
+

+
This function is used to convert a string `str` of size `len` to an UCL objects applying `flags` conversions. If `len` is equal to zero then a `str` is assumed as NULL-terminated. This function supports the following flags (a set of flags can be specified using logical `OR` operation):
+

+
- `UCL_STRING_ESCAPE` - perform JSON escape
+
- `UCL_STRING_TRIM` - trim leading and trailing whitespaces
+
- `UCL_STRING_PARSE_BOOLEAN` - parse passed string and detect boolean
+
- `UCL_STRING_PARSE_INT` - parse passed string and detect integer number
+
- `UCL_STRING_PARSE_DOUBLE` - parse passed string and detect integer or float number
+
- `UCL_STRING_PARSE_NUMBER` - parse passed string and detect number (both float or integer types)
+
- `UCL_STRING_PARSE` - parse passed string (and detect booleans and numbers)
+
- `UCL_STRING_PARSE_BYTES` - assume that numeric multipliers are in bytes notation, for example `10k` means `10*1024` and not `10*1000` as assumed without this flag
+

+
If parsing operations fail then the resulting UCL object will be a `UCL_STRING`. A caller should always check the type of the returned object and release it after using.
+

+
# Iteration function
+

+
Iteration are used to iterate over UCL compound types: arrays and objects. Moreover, iterations could be performed over the keys with multiple values (implicit arrays). To iterate over an object, an array or a key with multiple values there is a function `ucl_iterate_object`.
+

+
## ucl_iterate_object
+
~~~C
+
ucl_object_t* ucl_iterate_object (ucl_object_t *obj, 
+
	ucl_object_iter_t *iter, bool expand_values);
+
~~~
+

+
This function accept opaque iterator pointer `iter`. In the first call this iterator *must* be initialized to `NULL`. Iterator is changed by this function call. `ucl_iterate_object` returns the next UCL object in the compound object `obj` or `NULL` if all objects have been iterated. The reference count of the object returned is not increased, so a caller should not unref the object or modify its content (e.g. by inserting to another compound object). The object `obj` should not be changed during the iteration process as well. `expand_values` flag speicifies whether `ucl_iterate_object` should expand keys with multiple values. The general rule is that if you need to iterate throught the *object* or *explicit array*, then you always need to set this flag to `true`. However, if you get some key in the object and want to extract all its values then you should set `expand_values` to `false`. Mixing of iteration types are not permitted since the iterator is set according to the iteration type and cannot be reused. Here is an example of iteration over the objects using libucl API (assuming that `top` is `UCL_OBJECT` in this example):
+

+
~~~C
+
ucl_object_iter_t it = NULL, it_obj = NULL;
+
ucl_object_t *cur, *tmp;
+

+
/* Iterate over the object */
+
while ((obj = ucl_iterate_object (top, &it, true))) {
+
	printf ("key: \"%s\"\n", ucl_object_key (obj));
+
	/* Iterate over the values of a key */
+
	while ((cur = ucl_iterate_object (obj, &it_obj, false))) {
+
		printf ("value: \"%s\"\n", 
+
			ucl_object_tostring_forced (cur));
+
	}
+
}
+
~~~

\ No newline at end of file
modified external/libucl/src/ucl_internal.h
@@ -25,7 +25,9 @@
#define UCL_INTERNAL_H_

#include <sys/types.h>
+
#ifndef _WIN32
#include <sys/mman.h>
+
#endif
#include <sys/stat.h>
#include <sys/param.h>

added external/libucl/tests/1.in
@@ -0,0 +1,14 @@
+
{
+
"key1": value;
+
"key1": value2;
+
"key1": "value;"
+
"key1": 1.0,
+
"key1": -0xdeadbeef
+
"key1": 0xdeadbeef.1
+
"key1": 0xreadbeef
+
"key1": -1e-10,
+
"key1": 1
+
"key1": true
+
"key1": no
+
"key1": yes
+
}
added external/libucl/tests/1.res
@@ -0,0 +1,13 @@
+
key1 = "value";
+
key1 = "value2";
+
key1 = "value;";
+
key1 = 1.0;
+
key1 = -3735928559;
+
key1 = "0xdeadbeef.1";
+
key1 = "0xreadbeef";
+
key1 = -1e-10;
+
key1 = 1;
+
key1 = true;
+
key1 = false;
+
key1 = true;
+

added external/libucl/tests/2.in
@@ -0,0 +1,24 @@
+
section1 { param1 = value; param2 = value, 
+
section3 {param = value; param2 = value, param3 = ["value1", value2, 100500]}}
+
section2 { param1 = {key = value}, param1 = ["key"]}
+

+
# Numbers
+
key1 = 1s
+
key2 = 1min
+
key3 = 1kb
+
key4 = 5M
+
key5 = 10mS
+
key6 = 10y
+

+
# Strings
+
key1 = "some string";
+
key2 = /some/path;
+
key3 = 111some,
+
key4: s1,
+
"key5": "\n\r123"
+

+
# Variables
+
keyvar = "$ABItest";
+
keyvar = "${ABI}$ABI${ABI}${$ABI}";
+
keyvar = "${some}$no${}$$test$$$$$$$";
+
keyvar = "$ABI$$ABI$$$ABI$$$$";
added external/libucl/tests/2.res
@@ -0,0 +1,37 @@
+
section1 {
+
    param1 = "value";
+
    param2 = "value";
+
    section3 {
+
        param = "value";
+
        param2 = "value";
+
        param3 [
+
            "value1",
+
            "value2",
+
            100500,
+
        ]
+
    }
+
}
+
section2 {
+
    param1 {
+
        key = "value";
+
    }
+
    param1 [
+
        "key",
+
    ]
+
}
+
key1 = 1.0;
+
key1 = "some string";
+
key2 = 60.0;
+
key2 = "/some/path";
+
key3 = 1024;
+
key3 = "111some";
+
key4 = 5000000;
+
key4 = "s1";
+
key5 = 0.010000;
+
key5 = "\n\r123";
+
key6 = 2207520000.000000;
+
keyvar = "unknowntest";
+
keyvar = "unknownunknownunknown${unknown}";
+
keyvar = "${some}$no${}$$test$$$$$$$";
+
keyvar = "unknown$ABI$unknown$$";
+

added external/libucl/tests/3.in
@@ -0,0 +1,31 @@
+
/*
+
 * Pkg conf
+
 */
+

+
#packagesite http//pkg.freebsd.org/freebsd-9-amd64/latest
+
#packagesite http//pkg.freebsd.org/freebsd-9-amd64/latest
+
packagesite: http://pkg-test.freebsd.org/pkg-test/${ABI}/latest
+
squaretest: some[]value
+
ALIAS             : {
+
  all-depends: query %dn-%dv,
+
  annotations: info -A,
+
  build-depends: info -qd,
+
  download: fetch,
+
  iinfo: info -i -g -x,
+
  isearch: search -i -g -x,
+
  leaf: query -e '%a == 0' '%n-%v',
+
  leaf: query -e '%a == 0' '%n-%v',
+
  list: info -ql,
+
  origin: info -qo,
+
  provided-depends: info -qb,
+
  raw: info -R,
+
  required-depends: info -qr,
+
  shared-depends: info -qB,
+
  show: info -f -k,
+
  size: info -sq,
+
  }
+

+
repo_dirs : [
+
  /home/bapt,
+
  /usr/local/etc
+
]
added external/libucl/tests/3.res
@@ -0,0 +1,25 @@
+
packagesite = "http://pkg-test.freebsd.org/pkg-test/unknown/latest";
+
squaretest = "some[]value";
+
alias {
+
    all-depends = "query %dn-%dv";
+
    annotations = "info -A";
+
    build-depends = "info -qd";
+
    download = "fetch";
+
    iinfo = "info -i -g -x";
+
    isearch = "search -i -g -x";
+
    leaf = "query -e '%a == 0' '%n-%v'";
+
    leaf = "query -e '%a == 0' '%n-%v'";
+
    list = "info -ql";
+
    origin = "info -qo";
+
    provided-depends = "info -qb";
+
    raw = "info -R";
+
    required-depends = "info -qr";
+
    shared-depends = "info -qB";
+
    show = "info -f -k";
+
    size = "info -sq";
+
}
+
repo_dirs [
+
    "/home/bapt",
+
    "/usr/local/etc",
+
]
+

added external/libucl/tests/4.in
@@ -0,0 +1,47 @@
+
name : "pkgconf"
+
version : "0.9.3"
+
origin : "devel/pkgconf"
+
comment : "Utility to help to configure compiler and linker flags"
+
arch : "freebsd:9:x86:64"
+
maintainer : "bapt@FreeBSD.org"
+
prefix : "/usr/local"
+
licenselogic : "single"
+
licenses : [
+
    "BSD",
+
]
+
flatsize : 60523
+
desc : "pkgconf is a program which helps to configure compiler and linker flags for\ndevelopment frameworks. It is similar to pkg-config, but was written from\nscratch in Summer of 2011 to replace pkg-config, which now needs itself to build\nitself.\n\nWWW: https://github.com/pkgconf/pkgconf"
+
categories : [
+
    "devel",
+
]
+
files : {
+
    /usr/local/bin/pkg-config : "-",
+
    /usr/local/bin/pkgconf : "4a0fc53e5ad64e8085da2e61652d61c50b192a086421d865703f1de9f724da38",
+
    /usr/local/share/aclocal/pkg.m4 : "cffab33d659adfe36497ec57665eec36fa6fb7b007e578e6ac2434cc28be8820",
+
    /usr/local/share/licenses/pkgconf-0.9.3/BSD : "85e7a53b5e2d3e350e2d084fed2f94b7f63005f8e1168740e1e84aa9fa5d48ce",
+
    /usr/local/share/licenses/pkgconf-0.9.3/LICENSE : "d9cce0db43502eb1bd8fbef7e960cfaa43b5647186f7f7379923b336209fd77b",
+
    /usr/local/share/licenses/pkgconf-0.9.3/catalog.mk : "e7b131acce7c3d3c61f2214607b11b34526e03b05afe89a608f50586a898e2ef",
+
}
+
directories : {
+
    /usr/local/share/licenses/pkgconf-0.9.3/ : false,
+
    /usr/local/share/licenses/ : true,
+
}
+
scripts : {
+
    post-install : "cd /usr/local\nn",
+
    pre-deinstall : "cd /usr/local\nn",
+
    post-deinstall : "cd /usr/local\nn",
+
}
+
multiline-key : <<EOD
+
test
+
test
+
test\n
+
/* comment like */
+
# Some invalid endings
+
 EOD
+
EOD   
+
EOF
+
# Valid ending + empty string
+

+
EOD
+

+
normal-key : <<EODnot
added external/libucl/tests/4.res
@@ -0,0 +1,36 @@
+
name = "pkgconf";
+
version = "0.9.3";
+
origin = "devel/pkgconf";
+
comment = "Utility to help to configure compiler and linker flags";
+
arch = "freebsd:9:x86:64";
+
maintainer = "bapt@FreeBSD.org";
+
prefix = "/usr/local";
+
licenselogic = "single";
+
licenses [
+
    "BSD",
+
]
+
flatsize = 60523;
+
desc = "pkgconf is a program which helps to configure compiler and linker flags for\ndevelopment frameworks. It is similar to pkg-config, but was written from\nscratch in Summer of 2011 to replace pkg-config, which now needs itself to build\nitself.\n\nWWW: https://github.com/pkgconf/pkgconf";
+
categories [
+
    "devel",
+
]
+
files {
+
    /usr/local/bin/pkg-config = "-";
+
    /usr/local/bin/pkgconf = "4a0fc53e5ad64e8085da2e61652d61c50b192a086421d865703f1de9f724da38";
+
    /usr/local/share/aclocal/pkg.m4 = "cffab33d659adfe36497ec57665eec36fa6fb7b007e578e6ac2434cc28be8820";
+
    /usr/local/share/licenses/pkgconf-0.9.3/bsd = "85e7a53b5e2d3e350e2d084fed2f94b7f63005f8e1168740e1e84aa9fa5d48ce";
+
    /usr/local/share/licenses/pkgconf-0.9.3/license = "d9cce0db43502eb1bd8fbef7e960cfaa43b5647186f7f7379923b336209fd77b";
+
    /usr/local/share/licenses/pkgconf-0.9.3/catalog.mk = "e7b131acce7c3d3c61f2214607b11b34526e03b05afe89a608f50586a898e2ef";
+
}
+
directories {
+
    /usr/local/share/licenses/pkgconf-0.9.3/ = false;
+
    /usr/local/share/licenses/ = true;
+
}
+
scripts {
+
    post-install = "cd /usr/local\nn";
+
    pre-deinstall = "cd /usr/local\nn";
+
    post-deinstall = "cd /usr/local\nn";
+
}
+
multiline-key = "test\ntest\ntest\\n\n/* comment like */\n# Some invalid endings\n EOD\nEOD   \nEOF\n# Valid ending + empty string\n";
+
normal-key = "<<EODnot";
+

added external/libucl/tests/5.in
@@ -0,0 +1 @@
+
# test
added external/libucl/tests/5.res
@@ -0,0 +1 @@
+

added external/libucl/tests/6.in
@@ -0,0 +1,4 @@
+

+
# test
+
#
+
key = value
added external/libucl/tests/6.res
@@ -0,0 +1,2 @@
+
key = "value";
+

added external/libucl/tests/7.in
added external/libucl/tests/7.res
@@ -0,0 +1 @@
+

added external/libucl/tests/8.in
@@ -0,0 +1,23 @@
+
section blah { # test
+
	param = "value"
+
}
+
section test {
+
	key = test;
+
	subsection testsub {
+
		flag on;
+
		subsubsection testsubsub1 testsubsub2 {
+
			key = [1, 2, 3];
+
		}
+
	}
+
}
+

+
section test {
+
	/* Empty */
+
}
+

+

+
section foo { # test
+
	param = 123.2;
+
}
+

+
array = []
added external/libucl/tests/8.res
@@ -0,0 +1,38 @@
+
section {
+
    blah {
+
        param = "value";
+
    }
+
}
+
section {
+
    test {
+
        key = "test";
+
        subsection {
+
            testsub {
+
                flag = true;
+
                subsubsection {
+
                    testsubsub1 {
+
                        testsubsub2 {
+
                            key [
+
                                1,
+
                                2,
+
                                3,
+
                            ]
+
                        }
+
                    }
+
                }
+
            }
+
        }
+
    }
+
}
+
section {
+
    test {
+
    }
+
}
+
section {
+
    foo {
+
        param = 123.200000;
+
    }
+
}
+
array [
+
]
+

added external/libucl/tests/9-comment.inc
@@ -0,0 +1 @@
+
#key = value
added external/libucl/tests/9-empty.inc
added external/libucl/tests/9.in
@@ -0,0 +1,13 @@
+
.include "$CURDIR/9.inc"
+
.include "$CURDIR/9-empty.inc"
+
.include "$CURDIR/9-comment.inc"
+
#.include "$CURDIR/9.inc"
+
.include "$CURDIR/9.inc"
+

+
key = value;
+
.include "$CURDIR/9.inc"
+

+
.try_include "/non/existent"
+
#.try_include "$CURDIR/9.incorrect.inc"
+
# 9.incorrect.inc contains '{}}'
+
#key = value;
added external/libucl/tests/9.inc
@@ -0,0 +1 @@
+
key1 = value
added external/libucl/tests/9.res
@@ -0,0 +1,5 @@
+
key1 = "value";
+
key1 = "value";
+
key1 = "value";
+
key = "value";
+

added external/libucl/tests/generate.res
@@ -0,0 +1,20 @@
+
key1 = "test string";
+
key2 = "test \\nstring";
+
key3 = "  test string    \n";
+
key4 [
+
    9.999000,
+
    10,
+
    10.100000,
+
]
+
key4 = true;
+
key5 = "";
+
key6 = "";
+
key7 = "   \\n";
+
key8 = 1048576;
+
key9 = 3.140000;
+
key10 = true;
+
key11 = false;
+
key12 = "gslin@gslin.org";
+
key13 = "#test";
+
"k=3" = true;
+

added external/libucl/tests/run_tests.sh
@@ -0,0 +1,58 @@
+
#!/bin/sh
+

+
if [ $# -lt 1 ] ; then
+
	echo 'Specify binary to run as the first argument'
+
	exit 1
+
fi
+

+

+
for _tin in ${TEST_DIR}/*.in ; do
+
	_t=`echo $_tin | sed -e 's/.in$//'`
+
	$1 $_t.in $_t.out
+
	if [ $? -ne 0 ] ; then
+
		echo "Test: $_t failed, output:"
+
		cat $_t.out
+
		rm $_t.out
+
		exit 1
+
	fi
+
	if [ -f $_t.res ] ; then
+
	diff -s $_t.out $_t.res -u 2>/dev/null
+
		if [ $? -ne 0 ] ; then
+
			rm $_t.out
+
			echo "Test: $_t output missmatch"
+
			exit 1
+
		fi
+
	fi
+
	rm $_t.out
+
done
+

+
if [ $# -gt 2 ] ; then
+
	$3 ${TEST_DIR}/generate.out
+
	diff -s ${TEST_DIR}/generate.out ${TEST_DIR}/generate.res -u 2>/dev/null
+
	if [ $? -ne 0 ] ; then
+
		rm ${TEST_DIR}/generate.out
+
		echo "Test: generate.res output missmatch"
+
    	exit 1
+
	fi
+
	rm ${TEST_DIR}/generate.out
+
fi
+

+
sh -c "xz -c < /dev/null > /dev/null"
+
if [ $? -eq 0 -a $# -gt 1 ] ; then
+
	echo 'Running speed tests'
+
	for _tin in ${TEST_DIR}/*.xz ; do
+
		echo "Unpacking $_tin..."
+
		xz -cd < $_tin > ${TEST_DIR}/test_file
+
		# Preread file to cheat benchmark!
+
		cat ${TEST_DIR}/test_file > /dev/null
+
		echo "Starting benchmarking for $_tin..."
+
		$2 ${TEST_DIR}/test_file
+
		if [ $? -ne 0 ] ; then
+
			echo "Test: $_tin failed"
+
			rm ${TEST_DIR}/test_file
+
			exit 1
+
		fi
+
		rm ${TEST_DIR}/test_file
+
	done
+
fi
+

added external/libucl/tests/test_basic.c
@@ -0,0 +1,151 @@
+
/* Copyright (c) 2013, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <stdio.h>
+
#include <errno.h>
+
#include <unistd.h>
+
#include "ucl.h"
+

+
int
+
main (int argc, char **argv)
+
{
+
	char inbuf[8192], *test_in = NULL;
+
	struct ucl_parser *parser = NULL, *parser2 = NULL;
+
	ucl_object_t *obj;
+
	FILE *in, *out;
+
	unsigned char *emitted = NULL;
+
	const char *fname_in = NULL, *fname_out = NULL;
+
	int ret = 0, inlen, opt, json = 0;
+

+
	while ((opt = getopt(argc, argv, "j")) != -1) {
+
		switch (opt) {
+
		case 'j':
+
			json = 1;
+
			break;
+
		default: /* '?' */
+
			fprintf (stderr, "Usage: %s [-j] [in] [out]\n",
+
					argv[0]);
+
			exit (EXIT_FAILURE);
+
		}
+
	}
+

+
	argc -= optind;
+
	argv += optind;
+

+
	switch (argc) {
+
	case 1:
+
		fname_in = argv[0];
+
		break;
+
	case 2:
+
		fname_in = argv[0];
+
		fname_out = argv[1];
+
		break;
+
	}
+

+
	if (fname_in != NULL) {
+
		in = fopen (fname_in, "r");
+
		if (in == NULL) {
+
			exit (-errno);
+
		}
+
	}
+
	else {
+
		in = stdin;
+
	}
+
	parser = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE);
+
	ucl_parser_register_variable (parser, "ABI", "unknown");
+

+
	if (fname_in != NULL) {
+
		ucl_parser_set_filevars (parser, fname_in, true);
+
	}
+

+
	while (!feof (in)) {
+
		memset (inbuf, 0, sizeof (inbuf));
+
		(void)fread (inbuf, sizeof (inbuf) - 1, 1, in);
+
		inlen = strlen (inbuf);
+
		test_in = malloc (inlen);
+
		memcpy (test_in, inbuf, inlen);
+
		ucl_parser_add_chunk (parser, test_in, inlen);
+
	}
+
	fclose (in);
+

+
	if (fname_out != NULL) {
+
		out = fopen (fname_out, "w");
+
		if (out == NULL) {
+
			exit (-errno);
+
		}
+
	}
+
	else {
+
		out = stdout;
+
	}
+
	if (ucl_parser_get_error(parser) != NULL) {
+
		fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser));
+
		ret = 1;
+
		goto end;
+
	}
+
	obj = ucl_parser_get_object (parser);
+
	if (json) {
+
		emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
+
	}
+
	else {
+
		emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
+
	}
+
	ucl_parser_free (parser);
+
	ucl_object_unref (obj);
+
	parser2 = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE);
+
	ucl_parser_add_chunk (parser2, emitted, strlen (emitted));
+

+
	if (ucl_parser_get_error(parser2) != NULL) {
+
		fprintf (out, "Error occurred: %s\n", ucl_parser_get_error(parser2));
+
		fprintf (out, "%s\n", emitted);
+
		ret = 1;
+
		goto end;
+
	}
+
	if (emitted != NULL) {
+
		free (emitted);
+
	}
+
	obj = ucl_parser_get_object (parser2);
+
	if (json) {
+
		emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
+
	}
+
	else {
+
		emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
+
	}
+

+
	fprintf (out, "%s\n", emitted);
+
	ucl_object_unref (obj);
+

+
end:
+
	if (emitted != NULL) {
+
		free (emitted);
+
	}
+
	if (parser2 != NULL) {
+
		ucl_parser_free (parser2);
+
	}
+
	if (test_in != NULL) {
+
		free (test_in);
+
	}
+

+
	fclose (out);
+

+
	return ret;
+
}
added external/libucl/tests/test_generate.c
@@ -0,0 +1,126 @@
+
/* Copyright (c) 2013, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <stdio.h>
+
#include <errno.h>
+
#include <assert.h>
+
#include "ucl.h"
+

+
int
+
main (int argc, char **argv)
+
{
+
	ucl_object_t *obj, *cur, *ar;
+
	FILE *out;
+
	unsigned char *emitted;
+
	const char *fname_out = NULL;
+
	int ret = 0;
+

+
	switch (argc) {
+
	case 2:
+
		fname_out = argv[1];
+
		break;
+
	}
+

+

+
	if (fname_out != NULL) {
+
		out = fopen (fname_out, "w");
+
		if (out == NULL) {
+
			exit (-errno);
+
		}
+
	}
+
	else {
+
		out = stdout;
+
	}
+

+
	obj = ucl_object_typed_new (UCL_OBJECT);
+
	/* Create some strings */
+
	cur = ucl_object_fromstring_common ("  test string    ", 0, UCL_STRING_TRIM);
+
	obj = ucl_object_insert_key (obj, cur, "key1", 0, false);
+
	cur = ucl_object_fromstring_common ("  test \nstring\n    ", 0, UCL_STRING_TRIM | UCL_STRING_ESCAPE);
+
	obj = ucl_object_insert_key (obj, cur, "key2", 0, false);
+
	cur = ucl_object_fromstring_common ("  test string    \n", 0, 0);
+
	obj = ucl_object_insert_key (obj, cur, "key3", 0, false);
+
	/* Array of numbers */
+
	cur = ucl_object_fromint (10);
+
	ar = ucl_array_append (NULL, cur);
+
	cur = ucl_object_fromdouble (10.1);
+
	ar = ucl_array_append (ar, cur);
+
	cur = ucl_object_fromdouble (9.999);
+
	ar = ucl_array_prepend (ar, cur);
+

+
	/* Removing from an array */
+
	cur = ucl_object_fromdouble (1.0);
+
	ar = ucl_array_append (ar, cur);
+
	cur = ucl_array_delete (ar, cur);
+
	assert (ucl_object_todouble (cur) == 1.0);
+
	ucl_object_unref (cur);
+
	cur = ucl_object_fromdouble (2.0);
+
	ar = ucl_array_append (ar, cur);
+
	cur = ucl_array_pop_last (ar);
+
	assert (ucl_object_todouble (cur) == 2.0);
+
	ucl_object_unref (cur);
+
	cur = ucl_object_fromdouble (3.0);
+
	ar = ucl_array_prepend (ar, cur);
+
	cur = ucl_array_pop_first (ar);
+
	assert (ucl_object_todouble (cur) == 3.0);
+
	ucl_object_unref (cur);
+

+
	obj = ucl_object_insert_key (obj, ar, "key4", 0, false);
+
	cur = ucl_object_frombool (true);
+
	obj = ucl_object_insert_key (obj, cur, "key4", 0, false);
+
	/* Empty strings */
+
	cur = ucl_object_fromstring_common ("      ", 0, UCL_STRING_TRIM);
+
	obj = ucl_object_insert_key (obj, cur, "key5", 0, false);
+
	cur = ucl_object_fromstring_common ("", 0, UCL_STRING_ESCAPE);
+
	obj = ucl_object_insert_key (obj, cur, "key6", 0, false);
+
	cur = ucl_object_fromstring_common ("   \n", 0, UCL_STRING_ESCAPE);
+
	obj = ucl_object_insert_key (obj, cur, "key7", 0, false);
+
	/* Numbers and booleans */
+
	cur = ucl_object_fromstring_common ("1mb", 0, UCL_STRING_ESCAPE | UCL_STRING_PARSE);
+
	obj = ucl_object_insert_key (obj, cur, "key8", 0, false);
+
	cur = ucl_object_fromstring_common ("3.14", 0, UCL_STRING_PARSE);
+
	obj = ucl_object_insert_key (obj, cur, "key9", 0, false);
+
	cur = ucl_object_fromstring_common ("true", 0, UCL_STRING_PARSE);
+
	obj = ucl_object_insert_key (obj, cur, "key10", 0, false);
+
	cur = ucl_object_fromstring_common ("  off  ", 0, UCL_STRING_PARSE | UCL_STRING_TRIM);
+
	obj = ucl_object_insert_key (obj, cur, "key11", 0, false);
+
	cur = ucl_object_fromstring_common ("gslin@gslin.org", 0, UCL_STRING_PARSE_INT);
+
	obj = ucl_object_insert_key (obj, cur, "key12", 0, false);
+
	cur = ucl_object_fromstring_common ("#test", 0, UCL_STRING_PARSE_INT);
+
	obj = ucl_object_insert_key (obj, cur, "key13", 0, false);
+
	cur = ucl_object_frombool (true);
+
	obj = ucl_object_insert_key (obj, cur, "k=3", 0, false);
+

+

+
	emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
+

+
	fprintf (out, "%s\n", emitted);
+
	ucl_object_unref (obj);
+

+
	if (emitted != NULL) {
+
		free (emitted);
+
	}
+
	fclose (out);
+

+
	return ret;
+
}
added external/libucl/tests/test_speed.c
@@ -0,0 +1,149 @@
+
/* Copyright (c) 2013, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <sys/types.h>
+
#include <sys/mman.h>
+
#include <sys/stat.h>
+
#include <sys/time.h>
+
#include <stdio.h>
+
#include <errno.h>
+
#include <unistd.h>
+
#include <fcntl.h>
+
#include <time.h>
+

+
#ifdef __APPLE__
+
#include <mach/mach_time.h>
+
#endif
+

+
#include "ucl.h"
+

+
static double
+
get_ticks (void)
+
{
+
	double res;
+

+
#ifdef __APPLE__
+
	res = mach_absolute_time () / 1000000000.;
+
#else
+
	struct timespec ts;
+
	clock_gettime (CLOCK_MONOTONIC, &ts);
+

+
	res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.;
+
#endif
+

+
	return res;
+
}
+

+
int
+
main (int argc, char **argv)
+
{
+
	void *map;
+
	struct ucl_parser *parser;
+
	ucl_object_t *obj;
+
	int fin;
+
	unsigned char *emitted;
+
	struct stat st;
+
	const char *fname_in = NULL;
+
	int ret = 0;
+
	double start, end, seconds;
+

+
	switch (argc) {
+
	case 2:
+
		fname_in = argv[1];
+
		break;
+
	}
+

+
	fin = open (fname_in, O_RDONLY);
+
	if (fin == -1) {
+
		perror ("open failed");
+
		exit (EXIT_FAILURE);
+
	}
+
	parser = ucl_parser_new (UCL_PARSER_ZEROCOPY);
+

+
	(void)fstat (fin, &st);
+
	map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fin, 0);
+
	if (map == MAP_FAILED) {
+
		perror ("mmap failed");
+
		exit (EXIT_FAILURE);
+
	}
+

+
	close (fin);
+

+
	start = get_ticks ();
+
	ucl_parser_add_chunk (parser, map, st.st_size);
+

+
	obj = ucl_parser_get_object (parser);
+
	end = get_ticks ();
+

+
	seconds = end - start;
+
	printf ("ucl: parsed input in %.4f seconds\n", seconds);
+
	if (ucl_parser_get_error(parser)) {
+
		printf ("Error occurred: %s\n", ucl_parser_get_error(parser));
+
		ret = 1;
+
		goto err;
+
	}
+

+
	start = get_ticks ();
+
	emitted = ucl_object_emit (obj, UCL_EMIT_CONFIG);
+
	end = get_ticks ();
+

+
	seconds = end - start;
+
	printf ("ucl: emitted config in %.4f seconds\n", seconds);
+

+
	free (emitted);
+

+
	start = get_ticks ();
+
	emitted = ucl_object_emit (obj, UCL_EMIT_JSON);
+
	end = get_ticks ();
+

+
	seconds = end - start;
+
	printf ("ucl: emitted json in %.4f seconds\n", seconds);
+

+
	free (emitted);
+

+
	start = get_ticks ();
+
	emitted = ucl_object_emit (obj, UCL_EMIT_JSON_COMPACT);
+
	end = get_ticks ();
+

+
	seconds = end - start;
+
	printf ("ucl: emitted compact json in %.4f seconds\n", seconds);
+

+
	free (emitted);
+

+
	start = get_ticks ();
+
	emitted = ucl_object_emit (obj, UCL_EMIT_YAML);
+
	end = get_ticks ();
+

+
	seconds = end - start;
+
	printf ("ucl: emitted yaml in %.4f seconds\n", seconds);
+

+
	free (emitted);
+

+
	ucl_parser_free (parser);
+
	ucl_object_unref (obj);
+

+
err:
+
	munmap (map, st.st_size);
+

+
	return ret;
+
}
added external/libucl/utils/chargen.c
@@ -0,0 +1,128 @@
+
/* Copyright (c) 2013, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
/**
+
 * @file this utility generates character table for ucl
+
 */
+

+
#include <stdio.h>
+
#include <ctype.h>
+
#include <stdbool.h>
+

+
static inline int
+
print_flag (const char *flag, bool *need_or, char *val)
+
{
+
	int res;
+
	res = sprintf (val, "%s%s", *need_or ? "|" : "", flag);
+

+
	*need_or |= true;
+

+
	return res;
+
}
+

+
int
+
main (int argc, char **argv)
+
{
+
	int i, col, r;
+
	const char *name = "ucl_chartable";
+
	bool need_or;
+
	char valbuf[2048];
+

+
	col = 0;
+

+
	if (argc > 1) {
+
		name = argv[1];
+
	}
+

+
	printf ("static const unsigned int %s[255] = {\n", name);
+

+
	for (i = 0; i < 255; i ++) {
+
		need_or = false;
+
		r = 0;
+
		/* UCL_CHARACTER_VALUE_END */
+

+
		if (i == ' ' || i == '\t') {
+
			r += print_flag ("UCL_CHARACTER_WHITESPACE", &need_or, valbuf + r);
+
		}
+
		if (isspace (i)) {
+
			r += print_flag ("UCL_CHARACTER_WHITESPACE_UNSAFE", &need_or, valbuf + r);
+
		}
+
		if (isalnum (i) || i >= 0x80 || i == '/' || i == '_') {
+
			r += print_flag ("UCL_CHARACTER_KEY_START", &need_or, valbuf + r);
+
		}
+
		if (isalnum (i) || i == '-' || i == '_' || i == '/' || i == '.' || i >= 0x80) {
+
			r += print_flag ("UCL_CHARACTER_KEY", &need_or, valbuf + r);
+
		}
+
		if (i == 0 || i == '\r' || i == '\n' || i == ']' || i == '}' || i == ';' || i == ',' || i == '#') {
+
			r += print_flag ("UCL_CHARACTER_VALUE_END", &need_or, valbuf + r);
+
		}
+
		else {
+
			if (isprint (i) || i >= 0x80) {
+
				r += print_flag ("UCL_CHARACTER_VALUE_STR", &need_or, valbuf + r);
+
			}
+
			if (isdigit (i) || i == '-') {
+
				r += print_flag ("UCL_CHARACTER_VALUE_DIGIT_START", &need_or, valbuf + r);
+
			}
+
			if (isalnum (i) || i == '.' || i == '-' || i == '+') {
+
				r += print_flag ("UCL_CHARACTER_VALUE_DIGIT", &need_or, valbuf + r);
+
			}
+
		}
+
		if (i == '"' || i == '\\' || i == '/' || i == 'b' ||
+
			i == 'f' || i == 'n' || i == 'r' || i == 't' || i == 'u') {
+
			r += print_flag ("UCL_CHARACTER_ESCAPE", &need_or, valbuf + r);
+
		}
+
		if (i == ' ' || i == '\t' || i == ':' || i == '=') {
+
			r += print_flag ("UCL_CHARACTER_KEY_SEP", &need_or, valbuf + r);
+
		}
+
		if (i == '\n' || i == '\r' || i == '\\' || i == '\b' || i == '\t' ||
+
				i == '"' || i == '\f') {
+
			r += print_flag ("UCL_CHARACTER_JSON_UNSAFE", &need_or, valbuf + r);
+
		}
+
		if (i == '\n' || i == '\r' || i == '\\' || i == '\b' || i == '\t' ||
+
				i == '"' || i == '\f' || i == '=' || i == ':' || i == '{' || i == '[' || i == ' ') {
+
			r += print_flag ("UCL_CHARACTER_UCL_UNSAFE", &need_or, valbuf + r);
+
		}
+

+
		if (!need_or) {
+
			r += print_flag ("UCL_CHARACTER_DENIED", &need_or, valbuf + r);
+
		}
+

+
		if (isprint (i)) {
+
			r += sprintf (valbuf + r, " /* %c */", i);
+
		}
+
		if (i != 254) {
+
			r += sprintf (valbuf + r, ", ");
+
		}
+
		col += r;
+
		if (col > 80) {
+
			printf ("\n%s", valbuf);
+
			col = r;
+
		}
+
		else {
+
			printf ("%s", valbuf);
+
		}
+
	}
+
	printf ("\n}\n");
+

+
	return 0;
+
}
added external/libucl/utils/objdump.c
@@ -0,0 +1,159 @@
+
/* Copyright (c) 2013, Dmitriy V. Reshetnikov
+
 * Copyright (c) 2013, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <stdio.h>
+
#include <errno.h>
+

+
#include "ucl.h"
+

+
void
+
ucl_obj_dump(ucl_object_t *obj, unsigned int shift)
+
{
+
	int num = shift * 4 + 5;
+
	char *pre = (char *) malloc (num * sizeof(char));
+
	ucl_object_t *cur, *tmp;
+
	ucl_object_iter_t it = NULL, it_obj = NULL;
+

+
	pre[--num] = 0x00;
+
	while (num--)
+
		pre[num] = 0x20;
+

+
	tmp = obj;
+

+
	while ((obj = ucl_iterate_object (tmp, &it, false))) {
+
		printf ("%sucl object address: %p\n", pre + 4, obj);
+
		if (obj->key != NULL) {
+
			printf ("%skey: \"%s\"\n", pre, ucl_object_key (obj));
+
		}
+
		printf ("%sref: %hd\n", pre, obj->ref);
+
		printf ("%slen: %u\n", pre, obj->len);
+
		printf ("%sprev: %p\n", pre, obj->prev);
+
		printf ("%snext: %p\n", pre, obj->next);
+
		if (obj->type == UCL_OBJECT) {
+
			printf ("%stype: UCL_OBJECT\n", pre);
+
			printf ("%svalue: %p\n", pre, obj->value.ov);
+
			while ((cur = ucl_iterate_object (obj, &it_obj, true))) {
+
				ucl_obj_dump (cur, shift + 2);
+
			}
+
		}
+
		else if (obj->type == UCL_ARRAY) {
+
			printf ("%stype: UCL_ARRAY\n", pre);
+
			printf ("%svalue: %p\n", pre, obj->value.av);
+
			ucl_obj_dump (obj->value.av, shift + 2);
+
		}
+
		else if (obj->type == UCL_INT) {
+
			printf ("%stype: UCL_INT\n", pre);
+
			printf ("%svalue: %ld\n", pre, ucl_object_toint (obj));
+
		}
+
		else if (obj->type == UCL_FLOAT) {
+
			printf ("%stype: UCL_FLOAT\n", pre);
+
			printf ("%svalue: %f\n", pre, ucl_object_todouble (obj));
+
		}
+
		else if (obj->type == UCL_STRING) {
+
			printf ("%stype: UCL_STRING\n", pre);
+
			printf ("%svalue: \"%s\"\n", pre, ucl_object_tostring (obj));
+
		}
+
		else if (obj->type == UCL_BOOLEAN) {
+
			printf ("%stype: UCL_BOOLEAN\n", pre);
+
			printf ("%svalue: %s\n", pre, ucl_object_tostring_forced (obj));
+
		}
+
		else if (obj->type == UCL_TIME) {
+
			printf ("%stype: UCL_TIME\n", pre);
+
			printf ("%svalue: %f\n", pre, ucl_object_todouble (obj));
+
		}
+
		else if (obj->type == UCL_USERDATA) {
+
			printf ("%stype: UCL_USERDATA\n", pre);
+
			printf ("%svalue: %p\n", pre, obj->value.ud);
+
		}
+
	}
+

+
	free (pre);
+
}
+

+
int
+
main(int argc, char **argv)
+
{
+
	const char *fn = NULL;
+
	char inbuf[8192];
+
	struct ucl_parser *parser;
+
	int k, ret = 0, r = 0;
+
	ucl_object_t *obj = NULL;
+
	ucl_object_t *par;
+
	FILE *in;
+

+
	if (argc > 1) {
+
		fn = argv[1];
+
	}
+

+
	if (fn != NULL) {
+
		in = fopen (fn, "r");
+
		if (in == NULL) {
+
			exit (-errno);
+
		}
+
	}
+
	else {
+
		in = stdin;
+
	}
+

+
	parser = ucl_parser_new (0);
+
	while (!feof (in) && r < (int)sizeof (inbuf)) {
+
		r += fread (inbuf + r, 1, sizeof (inbuf) - r, in);
+
	}
+
	ucl_parser_add_chunk (parser, inbuf, r);
+
	fclose (in);
+
	if (ucl_parser_get_error(parser)) {
+
		printf ("Error occured: %s\n", ucl_parser_get_error(parser));
+
		ret = 1;
+
		goto end;
+
	}
+

+
	obj = ucl_parser_get_object (parser);
+
	if (ucl_parser_get_error(parser)) {
+
		printf ("Error occured: %s\n", ucl_parser_get_error(parser));
+
		ret = 1;
+
		goto end;
+
	}
+

+
	if (argc > 2) {
+
		for (k = 2; k < argc; k++) {
+
			printf ("search for \"%s\"... ", argv[k]);
+
			par = ucl_object_find_key (obj, argv[k]);
+
			printf ("%sfound\n", (par == NULL )?"not ":"");
+
			ucl_obj_dump (par, 0);
+
		}
+
	}
+
	else {
+
		ucl_obj_dump (obj, 0);
+
	}
+

+
end:
+
	if (parser != NULL) {
+
		ucl_parser_free (parser);
+
	}
+
	if (obj != NULL) {
+
		ucl_object_unref (obj);
+
	}
+

+
	return ret;
+
}