aboutsummaryrefslogtreecommitdiff
path: root/contrib/libucl/utils
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libucl/utils')
-rw-r--r--contrib/libucl/utils/CMakeLists.txt12
-rw-r--r--contrib/libucl/utils/Makefile.am23
-rw-r--r--contrib/libucl/utils/chargen.c128
-rw-r--r--contrib/libucl/utils/objdump.c185
-rw-r--r--contrib/libucl/utils/ucl-tool.c170
5 files changed, 0 insertions, 518 deletions
diff --git a/contrib/libucl/utils/CMakeLists.txt b/contrib/libucl/utils/CMakeLists.txt
deleted file mode 100644
index 4de95fd7b4b0..000000000000
--- a/contrib/libucl/utils/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-
-PROJECT(libucl-utils C)
-
-FUNCTION(MAKE_UTIL UTIL_NAME UTIL_SRCS)
- ADD_EXECUTABLE(${UTIL_NAME} ${UTIL_SRCS})
- TARGET_LINK_LIBRARIES(${UTIL_NAME} ucl)
- INSTALL(TARGETS ${UTIL_NAME} DESTINATION bin)
-ENDFUNCTION()
-
-MAKE_UTIL(ucl_chargen chargen.c)
-MAKE_UTIL(ucl_objdump objdump.c)
-MAKE_UTIL(ucl_tool ucl-tool.c)
diff --git a/contrib/libucl/utils/Makefile.am b/contrib/libucl/utils/Makefile.am
deleted file mode 100644
index ec85aaa5e372..000000000000
--- a/contrib/libucl/utils/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
-common_utils_cflags = -I$(top_srcdir)/include \
- -I$(top_srcdir)/src \
- -I$(top_srcdir)/uthash
-common_utils_ldadd = $(top_builddir)/src/libucl.la
-
-ucl_chargen_SOURCES = chargen.c
-ucl_chargen_LDADD = $(common_utils_ldadd)
-ucl_chargen_CFLAGS = $(common_utils_cflags)
-
-ucl_objdump_SOURCES = objdump.c
-ucl_objdump_LDADD = $(common_utils_ldadd)
-ucl_objdump_CFLAGS = $(common_utils_cflags)
-
-ucl_tool_SOURCES = ucl-tool.c
-ucl_tool_LDADD = $(common_utils_ldadd)
-ucl_tool_CFLAGS = $(common_utils_cflags)
-
-if UTILS
-UTL = ucl_chargen ucl_objdump ucl_tool
-else
-UTL =
-endif
-bin_PROGRAMS = $(UTL)
diff --git a/contrib/libucl/utils/chargen.c b/contrib/libucl/utils/chargen.c
deleted file mode 100644
index 398134054c21..000000000000
--- a/contrib/libucl/utils/chargen.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* 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[256] = {\n", name);
-
- for (i = 0; i < 256; 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 != 255) {
- r += sprintf (valbuf + r, ", ");
- }
- col += r;
- if (col > 80) {
- printf ("\n%s", valbuf);
- col = r;
- }
- else {
- printf ("%s", valbuf);
- }
- }
- printf ("\n}\n");
-
- return 0;
-}
diff --git a/contrib/libucl/utils/objdump.c b/contrib/libucl/utils/objdump.c
deleted file mode 100644
index 416eca7c87e0..000000000000
--- a/contrib/libucl/utils/objdump.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/* 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.
- */
-
-#if defined(_MSC_VER)
- #include <BaseTsd.h>
-
- typedef SSIZE_T ssize_t;
-#endif
-
-#include "ucl.h"
-
-void
-ucl_obj_dump (const ucl_object_t *obj, unsigned int shift)
-{
- int num = shift * 4 + 5;
- char *pre = (char *) malloc (num * sizeof(char));
- const 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_object_iterate (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: %u\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);
- it_obj = NULL;
- while ((cur = ucl_object_iterate (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);
- it_obj = NULL;
- while ((cur = ucl_object_iterate (obj, &it_obj, true))) {
- ucl_obj_dump (cur, shift + 2);
- }
- }
- else if (obj->type == UCL_INT) {
- printf ("%stype: UCL_INT\n", pre);
- printf ("%svalue: %jd\n", pre, (intmax_t)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;
- unsigned char *inbuf;
- struct ucl_parser *parser;
- int k, ret = 0;
- ssize_t bufsize, r = 0;
- ucl_object_t *obj = NULL;
- const ucl_object_t *par;
- FILE *in;
-
- if (argc > 1) {
- fn = argv[1];
- }
-
- if (fn != NULL) {
- in = fopen (fn, "r");
- if (in == NULL) {
- exit (EXIT_FAILURE);
- }
- }
- else {
- in = stdin;
- }
-
- parser = ucl_parser_new (0);
- inbuf = malloc (BUFSIZ);
- bufsize = BUFSIZ;
- r = 0;
-
- while (!feof (in) && !ferror (in)) {
- if (r == bufsize) {
- inbuf = realloc (inbuf, bufsize * 2);
- bufsize *= 2;
- if (inbuf == NULL) {
- perror ("realloc");
- exit (EXIT_FAILURE);
- }
- }
- r += fread (inbuf + r, 1, bufsize - r, in);
- }
-
- if (ferror (in)) {
- fprintf (stderr, "Failed to read the input file.\n");
- exit (EXIT_FAILURE);
- }
-
- ucl_parser_add_chunk (parser, inbuf, r);
- fclose (in);
- if (ucl_parser_get_error(parser)) {
- printf ("Error occurred: %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 occurred: %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_lookup (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;
-}
diff --git a/contrib/libucl/utils/ucl-tool.c b/contrib/libucl/utils/ucl-tool.c
deleted file mode 100644
index 9b807d35c092..000000000000
--- a/contrib/libucl/utils/ucl-tool.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/* Copyright (c) 2015, Cesanta Software
- *
- * 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 "ucl.h"
-
-void usage(const char *name, FILE *out) {
- fprintf(out, "Usage: %s [--help] [-i|--in file] [-o|--out file]\n", name);
- fprintf(out, " [-s|--schema file] [-f|--format format]\n\n");
- fprintf(out, " --help - print this message and exit\n");
- fprintf(out, " --in - specify input filename "
- "(default: standard input)\n");
- fprintf(out, " --out - specify output filename "
- "(default: standard output)\n");
- fprintf(out, " --schema - specify schema file for validation\n");
- fprintf(out, " --format - output format. Options: ucl (default), "
- "json, compact_json, yaml, msgpack\n");
-}
-
-int main(int argc, char **argv) {
- int i;
- char ch;
- FILE *in = stdin, *out = stdout;
- const char *schema = NULL, *parm, *val;
- unsigned char *buf = NULL;
- size_t size = 0, r = 0;
- struct ucl_parser *parser = NULL;
- ucl_object_t *obj = NULL;
- ucl_emitter_t emitter = UCL_EMIT_CONFIG;
-
- for (i = 1; i < argc; ++i) {
- parm = argv[i];
- val = ((i + 1) < argc) ? argv[++i] : NULL;
-
- if ((strcmp(parm, "--help") == 0) || (strcmp(parm, "-h") == 0)) {
- usage(argv[0], stdout);
- exit(0);
-
- } else if ((strcmp(parm, "--in") == 0) || (strcmp(parm, "-i") == 0)) {
- if (!val)
- goto err_val;
-
- in = fopen(val, "r");
- if (in == NULL) {
- perror("fopen on input file");
- exit(EXIT_FAILURE);
- }
- } else if ((strcmp(parm, "--out") == 0) || (strcmp(parm, "-o") == 0)) {
- if (!val)
- goto err_val;
-
- out = fopen(val, "w");
- if (out == NULL) {
- perror("fopen on output file");
- exit(EXIT_FAILURE);
- }
- } else if ((strcmp(parm, "--schema") == 0) || (strcmp(parm, "-s") == 0)) {
- if (!val)
- goto err_val;
- schema = val;
-
- } else if ((strcmp(parm, "--format") == 0) || (strcmp(parm, "-f") == 0)) {
- if (!val)
- goto err_val;
-
- if (strcmp(val, "ucl") == 0) {
- emitter = UCL_EMIT_CONFIG;
- } else if (strcmp(val, "json") == 0) {
- emitter = UCL_EMIT_JSON;
- } else if (strcmp(val, "yaml") == 0) {
- emitter = UCL_EMIT_YAML;
- } else if (strcmp(val, "compact_json") == 0) {
- emitter = UCL_EMIT_JSON_COMPACT;
- } else if (strcmp(val, "msgpack") == 0) {
- emitter = UCL_EMIT_MSGPACK;
- } else {
- fprintf(stderr, "Unknown output format: %s\n", val);
- exit(EXIT_FAILURE);
- }
- } else {
- usage(argv[0], stderr);
- exit(EXIT_FAILURE);
- }
- }
-
- parser = ucl_parser_new(0);
- buf = malloc(BUFSIZ);
- size = BUFSIZ;
- while (!feof(in) && !ferror(in)) {
- if (r == size) {
- buf = realloc(buf, size*2);
- size *= 2;
- if (buf == NULL) {
- perror("realloc");
- exit(EXIT_FAILURE);
- }
- }
- r += fread(buf + r, 1, size - r, in);
- }
- if (ferror(in)) {
- fprintf(stderr, "Failed to read the input file.\n");
- exit(EXIT_FAILURE);
- }
- fclose(in);
- if (!ucl_parser_add_chunk(parser, buf, r)) {
- fprintf(stderr, "Failed to parse input file: %s\n",
- ucl_parser_get_error(parser));
- exit(EXIT_FAILURE);
- }
- if ((obj = ucl_parser_get_object(parser)) == NULL) {
- fprintf(stderr, "Failed to get root object: %s\n",
- ucl_parser_get_error(parser));
- exit(EXIT_FAILURE);
- }
- if (schema != NULL) {
- struct ucl_parser *schema_parser = ucl_parser_new(0);
- ucl_object_t *schema_obj = NULL;
- struct ucl_schema_error error;
-
- if (!ucl_parser_add_file(schema_parser, schema)) {
- fprintf(stderr, "Failed to parse schema file: %s\n",
- ucl_parser_get_error(schema_parser));
- exit(EXIT_FAILURE);
- }
- if ((schema_obj = ucl_parser_get_object(schema_parser)) == NULL) {
- fprintf(stderr, "Failed to get root object: %s\n",
- ucl_parser_get_error(schema_parser));
- exit(EXIT_FAILURE);
- }
- if (!ucl_object_validate(schema_obj, obj, &error)) {
- fprintf(stderr, "Validation failed: %s\n", error.msg);
- exit(EXIT_FAILURE);
- }
- }
-
- if (emitter != UCL_EMIT_MSGPACK) {
- fprintf(out, "%s\n", ucl_object_emit(obj, emitter));
- } else {
- size_t len;
- unsigned char *res;
-
- res = ucl_object_emit_len(obj, emitter, &len);
- fwrite(res, 1, len, out);
- }
-
- return 0;
-
-err_val:
- fprintf(stderr, "Parameter %s is missing mandatory value\n", parm);
- usage(argv[0], stderr);
- exit(EXIT_FAILURE);
-}