summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2018-03-15 11:29:52 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2018-03-15 12:12:23 (GMT)
commit58a8936d30bbb18b8ad93fecfe3fe2210d1c18b2 (patch) (side-by-side diff)
tree01fcd1416af582e2429f0ae8d120e2af39b8f9d9
parent677473cdfc42b9fd83623902e80de946f108825c (diff)
downloadeclat-58a8936d30bbb18b8ad93fecfe3fe2210d1c18b2.tar.gz
eclat-58a8936d30bbb18b8ad93fecfe3fe2210d1c18b2.tar.bz2
Upgrade grecs
* grecs: pull * configure.ac: Enable json * lib/Makefile.am (AM_CPPFLAGS): Use @GRECS_INCLUDES@ (libeclat_a_SOURCES): Remove json sources. * src/Makefile.am (AM_CPPFLAGS): Use @GRECS_INCLUDES@ * tests/Makefile.am: Likewise. * lib/json.h: Remove. * lib/jsongrm.y: Remove. * lib/jsonlex.l: Remove. * tests/tjson.c: Remove. * src/config.c (eclat_kw): Mark statically initialized memory locations as such. * src/mktags.c (process_tags): Use wordsplit to process quoted arguments. * lib/bidimap.c (bidimap_config): Fill allocated memory with 0's * lib/filemap.c (filemap_config): Likewise. * lib/gdbmmap.c (gdbm_map_config): Likewise. * lib/seqmap.c (seqmap_config): Likewise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--configure.ac2
m---------grecs0
-rw-r--r--lib/Makefile.am11
-rw-r--r--lib/bidimap.c4
-rw-r--r--lib/filemap.c4
-rw-r--r--lib/forlangrm.y4
-rw-r--r--lib/forlanlex.l15
-rw-r--r--lib/gdbmmap.c4
-rw-r--r--lib/json.h66
-rw-r--r--lib/jsongrm.y316
-rw-r--r--lib/jsonlex.l183
-rw-r--r--lib/map.c6
-rw-r--r--lib/req2url.c6
-rw-r--r--lib/reqcreat.c2
-rw-r--r--lib/reqencode.c4
-rw-r--r--lib/reqsign.c8
-rw-r--r--lib/seqmap.c4
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am6
-rw-r--r--src/config.c7
-rw-r--r--src/eclat.h2
-rw-r--r--src/ispeek.c26
-rw-r--r--src/mktags.c32
-rw-r--r--src/util.c43
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/tjson.c116
26 files changed, 97 insertions, 780 deletions
diff --git a/configure.ac b/configure.ac
index 1673dbb..72aee3e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,7 +114,7 @@ AM_CONDITIONAL([COND_LDAP],[test $status_ldap = yes])
# Grecs subsystem
-GRECS_SETUP([grecs],[tests getopt git2chg])
+GRECS_SETUP([grecs],[tests getopt json git2chg])
#
AC_ARG_ENABLE([split-format],
diff --git a/grecs b/grecs
-Subproject 6331e7708f13efed852e6b85aa17ac21dc158ad
+Subproject 27ca9f5819d0e44173a5f61a241cd066ad15713
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 711bc98..e1ed1c3 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of Eclat
-# Copyright (C) 2012-2015 Sergey Poznyakoff
+# Copyright (C) 2012-2018 Sergey Poznyakoff
#
# Eclat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -43,10 +43,6 @@ libeclat_a_SOURCES=\
forlangrm.y\
forlanlex.l\
istore.c\
- json.h\
- jsongrm.h\
- jsongrm.y\
- jsonlex.l\
getans.c\
getyn.c\
hmac_sha1.c\
@@ -71,14 +67,11 @@ libeclat_a_SOURCES=\
$(maps)
AM_LDFLAGS = $(CURL_LIBS)
-AM_CPPFLAGS = -I$(top_srcdir)/grecs/src/ $(CURL_CFLAGS)
+AM_CPPFLAGS = @GRECS_INCLUDES@ $(CURL_CFLAGS)
forlanlex.c: forlangrm.h
forlangrm.c forlangrm.h: forlangrm.y
-jsonlex.c: jsongrm.h
-jsongrm.c jsongrm.h: jsongrm.y
-
AM_YFLAGS=-tdv
AM_LFLAGS=-dp
diff --git a/lib/bidimap.c b/lib/bidimap.c
index fc601c8..aafc736 100644
--- a/lib/bidimap.c
+++ b/lib/bidimap.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -100,7 +100,7 @@ bidimap_config(int dbg, struct grecs_node *node, void *data)
struct bidimap *map, **return_map = data;
int i;
- map = grecs_malloc(sizeof(*map));
+ map = grecs_zalloc(sizeof(*map));
for (i = 0; bidimap_kw[i].ident; i++)
bidimap_kw[i].varptr = map;
if (grecs_tree_process(node->down, bidimap_kw)) {
diff --git a/lib/filemap.c b/lib/filemap.c
index 6c5e286..26582ec 100644
--- a/lib/filemap.c
+++ b/lib/filemap.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ filemap_config(int dbg, struct grecs_node *node, void *data)
int i;
struct grecs_node *p;
- filemap = grecs_malloc(sizeof(*filemap));
+ filemap = grecs_zalloc(sizeof(*filemap));
for (i = 0; filemap_kw[i].ident; i++)
filemap_kw[i].varptr = filemap;
if (grecs_tree_process(node->down, filemap_kw)) {
diff --git a/lib/forlangrm.y b/lib/forlangrm.y
index ecfbf25..2db1274 100644
--- a/lib/forlangrm.y
+++ b/lib/forlangrm.y
@@ -1,6 +1,6 @@
%{
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
#include "libeclat.h"
#include <grecs.h>
-#include <grecs-locus.h>
+#include <grecs/locus.h>
#include "forlangrm.h"
#include "forlan.h"
#include <string.h>
diff --git a/lib/forlanlex.l b/lib/forlanlex.l
index db893df..62265cb 100644
--- a/lib/forlanlex.l
+++ b/lib/forlanlex.l
@@ -1,6 +1,6 @@
%{
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
#include <sysexits.h>
#include <ctype.h>
#include <grecs.h>
-#include <grecs-locus.h>
+#include <grecs/locus.h>
#include "forlangrm.h"
#include "forlan.h"
@@ -100,15 +100,18 @@ continue return CONTINUE;
\"[^\\"\n]*\\\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1);
+ yyleng - 1,
+ &yylloc);
grecs_locus_point_advance_line(grecs_current_locus_point); }
\"[^\\"\n]*\\. { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1); }
-<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng);
+ yyleng - 1,
+ &yylloc); }
+<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng,
+ &yylloc);
grecs_locus_point_advance_line(grecs_current_locus_point); }
-<STR>[^\\"\n]*\\. { grecs_line_acc_grow_unescape_last(yytext, yyleng); }
+<STR>[^\\"\n]*\\. { grecs_line_acc_grow_unescape_last(yytext, yyleng, &yylloc); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
grecs_line_add(yytext, yyleng - 1);
diff --git a/lib/gdbmmap.c b/lib/gdbmmap.c
index dde6b02..a2887df 100644
--- a/lib/gdbmmap.c
+++ b/lib/gdbmmap.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -69,7 +69,7 @@ gdbm_map_config(int dbg, struct grecs_node *node, void *data)
struct grecs_node *p;
int i;
- gdbm_map = grecs_malloc(sizeof(*gdbm_map));
+ gdbm_map = grecs_zalloc(sizeof(*gdbm_map));
for (i = 0; gdbm_map_kw[i].ident; i++)
gdbm_map_kw[i].varptr = gdbm_map;
if (grecs_tree_process(node->down, gdbm_map_kw)) {
diff --git a/lib/json.h b/lib/json.h
deleted file mode 100644
index 36ca243..0000000
--- a/lib/json.h
+++ b/dev/null
@@ -1,66 +0,0 @@
-/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
-
- Eclat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- Eclat is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <grecs.h>
-
-enum json_object_type
-{
- json_null,
- json_bool,
- json_number,
- json_string,
- json_arr,
- json_obj
-};
-
-struct json_object;
-struct json_array {
- size_t oc;
- struct json_object **ov;
-};
-
-struct json_object {
- enum json_object_type type;
- union {
- int b; /* json_bool */
- double n; /* json_number */
- char *s; /* json_string */
- struct json_array *a; /* json_arr */
- struct grecs_symtab *o; /* json_o */
- } v;
-};
-
-struct json_pair {
- char *k;
- struct json_object *v;
-};
-
-extern char const *json_err_diag;
-extern char const *json_err_ptr;
-extern struct json_object *json_return_obj;
-
-void jsonlex_setup(char const *s, size_t l);
-void jsonlex_diag(const char *s, size_t off);
-struct json_object *json_object_create(int type);
-struct grecs_symtab *json_assoc_create(void);
-void json_object_free(struct json_object *obj);
-
-struct json_object *json_parse_string(char const *input, size_t len);
-
-struct json_object *json_object_lookup(struct json_object *obj,
- const char *ident);
-
-
diff --git a/lib/jsongrm.y b/lib/jsongrm.y
deleted file mode 100644
index 398d2e7..0000000
--- a/lib/jsongrm.y
+++ b/dev/null
@@ -1,316 +0,0 @@
-%{
-/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
-
- Eclat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- Eclat is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "libeclat.h"
-#include <string.h>
-#include "jsongrm.h"
-#include "json.h"
-
-struct json_object *json_return_obj;
-
-static int yyerror(char const *s);
-
-static struct json_pair *
-pairdup(struct json_pair *in)
-{
- struct json_pair *out = grecs_malloc(sizeof(*out));
- out->k = in->k;
- out->v = in->v;
- return out;
-}
-
-static void
-pairfree(void *ptr)
-{
- struct json_pair *p = ptr;
- free(p->k);
- json_object_free(p->v);
- free(p);
-}
-
-static void
-objfree(void *ptr)
-{
- struct json_object *o = ptr;
- json_object_free(o);
-}
-
-%}
-%token <n> T_NUMBER
-%token <s> T_STRING
-%token <b> T_BOOL
-%token T_NULL T_ERR
-
-%type <a> array
-%type <list> objects objlist pairs pairlist
-%type <p> pair
-%type <obj> object
-%type <o> assoc
-
-%union {
- int b;
- double n;
- char *s;
- struct json_array *a;
- struct grecs_symtab *o;
- struct json_object *obj;
- struct grecs_list *list;
- struct json_pair *p;
-}
-%%
-
-input : object
- {
- json_return_obj = $1;
- }
- ;
-
-object : T_NUMBER
- {
- $$ = json_object_create(json_number);
- $$->v.n = $1;
- }
- | T_STRING
- {
- $$ = json_object_create(json_string);
- $$->v.s = $1;
- }
- | T_BOOL
- {
- $$ = json_object_create(json_bool);
- $$->v.b = $1;
- }
- | T_NULL
- {
- $$ = json_object_create(json_null);
- }
- | array
- {
- $$ = json_object_create(json_arr);
- $$->v.a = $1;
- }
- | assoc
- {
- $$ = json_object_create(json_obj);
- $$->v.o = $1;
- }
- ;
-
-array : '[' objects ']'
- {
- struct json_array *a = grecs_malloc(sizeof(*a));
- if (!$2) {
- a->oc = 0;
- a->ov = NULL;
- } else {
- size_t i;
- struct grecs_list_entry *ep;
- a->oc = $2->count;
- a->ov = grecs_calloc(a->oc, sizeof(a->ov));
- for (i = 0, ep = $2->head; ep; i++, ep = ep->next) {
- struct json_object *p = ep->data;
- a->ov[i] = p;
- }
- }
- $$ = a;
- }
- ;
-
-objects : /* empty */
- {
- $$ = NULL;
- }
- | objlist
- ;
-
-objlist : object
- {
- $$ = grecs_list_create();
- $$->free_entry = objfree;
- grecs_list_append($$, $1);
- }
- | objlist ',' object
- {
- grecs_list_append($1, $3);
- }
- ;
-
-assoc : '{' pairs '}'
- {
- struct grecs_symtab *s;
-
- s = json_assoc_create();
- if ($2) {
- struct grecs_list_entry *ep;
- for (ep = $2->head; ep; ep = ep->next) {
- struct json_pair *p = ep->data;
- int install = 1;
- grecs_symtab_lookup_or_install(s, p, &install);
- if (install) {
- p->k = NULL;
- p->v = NULL;
- }
- }
- grecs_list_free($2);
- }
- $$ = s;
- }
- ;
-
-pairs : /* empty */
- {
- $$ = NULL;
- }
- | pairlist
- ;
-
-pairlist: pair
- {
- $$ = grecs_list_create();
- $$->free_entry = pairfree;
- grecs_list_append($$, $1);
- }
- | pairlist ',' pair
- {
- grecs_list_append($1, $3);
- }
- ;
-
-pair : T_STRING ':' object
- {
- struct json_pair *p = grecs_malloc(sizeof(*p));
- p->k = $1;
- p->v = $3;
- $$ = p;
- }
- ;
-%%
-
-static int
-yyerror(char const *s)
-{
- jsonlex_diag(s, 0);
- return 0;
-}
-
-struct json_object *
-json_object_create(int type)
-{
- struct json_object *obj = grecs_zalloc(sizeof(*obj));
- obj->type = type;
- return obj;
-}
-
-void
-json_object_free(struct json_object *obj)
-{
- size_t i;
-
- if (!obj)
- return;
-
- switch (obj->type) {
- case json_bool:
- case json_number:
- break;
- case json_string:
- free(obj->v.s);
- break;
- case json_arr:
- for (i = 0; i < obj->v.a->oc; i++)
- json_object_free(obj->v.a->ov[i]);
- free(obj->v.a);
- break;
- case json_obj:
- grecs_symtab_free(obj->v.o);
- }
- free(obj);
-}
-
-static unsigned
-json_st_hash(void *data, unsigned long n_buckets)
-{
- struct json_pair *p = data;
- return grecs_hash_string(p->k, n_buckets);
-}
-
-static int
-json_st_cmp(const void *a, const void *b)
-{
- struct json_pair const *pa = a;
- struct json_pair const *pb = b;
- return strcmp(pa->k, pb->k);
-}
-
-static int
-json_st_copy(void *a, void *b)
-{
- struct json_pair *pa = a;
- struct json_pair *pb = b;
- memcpy(pa, pb, sizeof(*pa));
- return 0;
-}
-
-static void
-json_st_free(void *ptr)
-{
- struct json_pair *p = ptr;
-// printf("FREE %s\n", p->k);
- free(p->k);
- json_object_free(p->v);
- free(p);
-}
-
-struct grecs_symtab *
-json_assoc_create()
-{
- return grecs_symtab_create(sizeof(struct json_pair),
- json_st_hash,
- json_st_cmp,
- json_st_copy,
- NULL,
- json_st_free);
-}
-
-struct json_object *
-json_parse_string(char const *input, size_t len)
-{
- jsonlex_setup(input, len);
- if (yyparse()) {
- /* FIXME: error recovery */
- return NULL;
- }
- return json_return_obj;
-}
-
-struct json_object *
-json_object_lookup(struct json_object *obj, const char *ident)
-{
- struct json_pair key, *p;
- if (!obj || obj->type != json_obj)
- return NULL;
- key.k = ident;
- p = grecs_symtab_lookup_or_install(obj->v.o, &key, NULL);
- if (!p)
- return NULL;
- return p->v;
-}
-
-
-
-
-
diff --git a/lib/jsonlex.l b/lib/jsonlex.l
deleted file mode 100644
index 322b05d..0000000
--- a/lib/jsonlex.l
+++ b/dev/null
@@ -1,183 +0,0 @@
-%{
-/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
-
- Eclat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- Eclat is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "libeclat.h"
-#include "jsongrm.h"
-#include "json.h"
-
-static char const *input_ptr;
-static size_t input_size;
-
-char const *json_err_diag;
-char const *json_err_ptr;
-
-#undef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
- do { \
- size_t n = (max_size > input_size) ? input_size : max_size; \
- if (n) { \
- memcpy(buf, input_ptr, n); \
- input_ptr += n; \
- input_size -= n; \
- } \
- result = n; \
- } while(0)
-
-void
-jsonlex_setup(char const *s, size_t l)
-{
- input_ptr = s;
- input_size = l;
- json_err_diag = NULL;
- json_err_ptr = NULL;
- yy_flex_debug = 0;
-}
-
-void
-jsonlex_diag(const char *s, size_t off)
-{
- if (!json_err_diag) {
- json_err_diag = s;
- json_err_ptr = input_ptr - off;
- }
-}
-
-static int
-utf8_wctomb(char *u)
-{
- unsigned int wc = strtoul(u, NULL, 16);
- int count;
- char r[6];
-
- if (wc < 0x80)
- count = 1;
- else if (wc < 0x800)
- count = 2;
- else if (wc < 0x10000)
- count = 3;
- else if (wc < 0x200000)
- count = 4;
- else if (wc < 0x4000000)
- count = 5;
- else if (wc <= 0x7fffffff)
- count = 6;
- else
- return -1;
-
- switch (count) {
- /* Note: code falls through cases! */
- case 6:
- r[5] = 0x80 | (wc & 0x3f);
- wc = wc >> 6;
- wc |= 0x4000000;
- case 5:
- r[4] = 0x80 | (wc & 0x3f);
- wc = wc >> 6;
- wc |= 0x200000;
- case 4:
- r[3] = 0x80 | (wc & 0x3f);
- wc = wc >> 6;
- wc |= 0x10000;
- case 3:
- r[2] = 0x80 | (wc & 0x3f);
- wc = wc >> 6;
- wc |= 0x800;
- case 2:
- r[1] = 0x80 | (wc & 0x3f);
- wc = wc >> 6;
- wc |= 0xc0;
- case 1:
- r[0] = wc;
- }
- grecs_line_acc_grow(r, count);
- return count;
-}
-
-static int
-unescape(int c, int *o)
-{
- static char transtab[] = "\\\\\"\"//b\bf\fn\nr\rt\t";
- char *p;
-
- for (p = transtab; *p; p += 2) {
- if (*p == c) {
- *o = p[1];
- return 0;
- }
- }
- return -1;
-}
-
-#define YY_SKIP_YYWRAP 1
-static int
-yywrap()
-{
- return 1;
-}
-%}
-D [0-9]
-X [0-9a-fA-F]
-%x STR
-%%
-"-"?{D}{D}*(.{D}{D}*)?([eE][-+]?{D}{D}*)? {
- yylval.n = strtod(yytext, NULL);
- return T_NUMBER;
- }
-\"[^\\\"]*\" { grecs_line_begin();
- grecs_line_add(yytext + 1, yyleng - 2);
- yylval.s = grecs_line_finish();
- return T_STRING; }
-\"[^\\\"]*\\{X}{4} { BEGIN(STR);
- grecs_line_begin();
- grecs_line_add(yytext + 1, yyleng - 5);
- utf8_wctomb(yytext + yyleng - 4);
- }
-\"[^\\\"]*\\. { int c;
- BEGIN(STR);
- grecs_line_begin();
- grecs_line_acc_grow(yytext + 1, yyleng - 2);
- if (unescape(yytext[yyleng - 1], &c)) {
- jsonlex_diag("invalid UTF-8 codepoint", 5);
- return T_ERR;
- }
- grecs_line_acc_grow_char(c);
- }
-<STR>[^\\\"]*\" { BEGIN(INITIAL);
- if (yyleng > 1)
- grecs_line_acc_grow(yytext, yyleng - 1);
- yylval.s = grecs_line_finish();
- return T_STRING; }
-<STR>[^\\\"]*\\{X}{4} {
- grecs_line_add(yytext, yyleng - 5);
- utf8_wctomb(yytext + yyleng - 4);
-}
-<STR>[^\\\"]*\\. {
- int c;
- grecs_line_acc_grow(yytext, yyleng - 2);
- if (unescape(yytext[yyleng - 1], &c)) {
- jsonlex_diag("invalid UTF-8 codepoint", 5);
- return T_ERR;
- }
- grecs_line_acc_grow_char(c); }
-
-null { return T_NULL; }
-true { yylval.b = 1; return T_BOOL; }
-false { yylval.b = 0; return T_BOOL; }
-"{"|"}"|"["|"]"|":"|"," return yytext[0];
-[ \t\n]* ;
-. { jsonlex_diag("bogus character", 0);
- return T_ERR; }
diff --git a/lib/map.c b/lib/map.c
index bbede97..c16ecd0 100644
--- a/lib/map.c
+++ b/lib/map.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -323,7 +323,7 @@ eclat_map_foreach(int (*fun)(struct eclat_map *, void *), void *data)
cl.fun = fun;
cl.data = data;
- grecs_symtab_enumerate(openmap_symtab, map_foreach, &cl);
+ grecs_symtab_foreach(openmap_symtab, map_foreach, &cl);
}
void
@@ -348,7 +348,7 @@ drv_help(void *data, void *unused)
void
eclat_map_confhelp()
{
- grecs_symtab_enumerate(mapdrv_symtab, drv_help, NULL);
+ grecs_symtab_foreach(mapdrv_symtab, drv_help, NULL);
}
int
diff --git a/lib/req2url.c b/lib/req2url.c
index b9d7512..c97d321 100644
--- a/lib/req2url.c
+++ b/lib/req2url.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ eclat_request_to_url(struct ec2_request *req)
/* Add parameters */
pc.acc = acc;
pc.delim = '?';
- grecs_symtab_enumerate(req->params, add_param, &pc);
+ grecs_symtab_foreach(req->params, add_param, &pc);
grecs_txtacc_grow_char(acc, 0);
url = grecs_txtacc_finish(acc, 1);
@@ -80,7 +80,7 @@ eclat_request_finalize(struct ec2_request *req)
eclat_request_encode(req);
pc.acc = grecs_txtacc_create();
pc.delim = 0;
- grecs_symtab_enumerate(req->params, add_param, &pc);
+ grecs_symtab_foreach(req->params, add_param, &pc);
grecs_txtacc_grow_char(pc.acc, 0);
req->postdata = grecs_txtacc_finish(pc.acc, 1);
grecs_txtacc_free(pc.acc);
diff --git a/lib/reqcreat.c b/lib/reqcreat.c
index 753a415..8bfca56 100644
--- a/lib/reqcreat.c
+++ b/lib/reqcreat.c
@@ -79,7 +79,7 @@ eclat_request_dup(struct ec2_request const *src)
NULL,
ec2_param_free);
- grecs_symtab_enumerate(src->params, ec2_param_dup, dst);
+ grecs_symtab_foreach(src->params, ec2_param_dup, dst);
if (src->headers == NULL) {
dst->headers = NULL;
} else {
diff --git a/lib/reqencode.c b/lib/reqencode.c
index 70ac16d..c5a9655 100644
--- a/lib/reqencode.c
+++ b/lib/reqencode.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -37,6 +37,6 @@ encode_param(void *sym, void *data)
void
eclat_request_encode(struct ec2_request *req)
{
- grecs_symtab_enumerate(req->params, encode_param, NULL);
+ grecs_symtab_foreach(req->params, encode_param, NULL);
}
diff --git a/lib/reqsign.c b/lib/reqsign.c
index 05988ed..fee5adb 100644
--- a/lib/reqsign.c
+++ b/lib/reqsign.c
@@ -74,11 +74,11 @@ requestsign2(struct ec2_request *req, char *secret)
eclat_request_encode(req);
/* Collect and sort parameter names */
- n = grecs_symtab_count_entries(req->params);
+ n = grecs_symtab_count(req->params);
pnames = grecs_calloc(n, sizeof(pnames[0]));
pn.i = 0;
pn.a = pnames;
- grecs_symtab_enumerate(req->params, get_param_name, &pn);
+ grecs_symtab_foreach(req->params, get_param_name, &pn);
qsort(pnames, n, sizeof(pnames[0]), compnames);
verb = (req->flags & EC2_RF_POST) ? "POST" : "GET";
@@ -203,11 +203,11 @@ requestsign4(struct ec2_request *req, char *secret)
eclat_request_encode(req);
/* Collect and sort parameter names */
- n = grecs_symtab_count_entries(req->params);
+ n = grecs_symtab_count(req->params);
pnames = grecs_calloc(n, sizeof(pnames[0]));
pn.i = 0;
pn.a = pnames;
- grecs_symtab_enumerate(req->params, get_param_name, &pn);
+ grecs_symtab_foreach(req->params, get_param_name, &pn);
qsort(pnames, n, sizeof(pnames[0]), compnames);
/* Create a canonical request */
diff --git a/lib/seqmap.c b/lib/seqmap.c
index ae00bc6..c50d848 100644
--- a/lib/seqmap.c
+++ b/lib/seqmap.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -71,7 +71,7 @@ seqmap_config(int dbg, struct grecs_node *node, void *data)
struct seqmap *seqmap, **return_seqmap = data;
int i;
- seqmap = grecs_malloc(sizeof(*seqmap));
+ seqmap = grecs_zalloc(sizeof(*seqmap));
for (i = 0; seqmap_kw[i].ident; i++)
seqmap_kw[i].varptr = seqmap;
if (grecs_tree_process(node->down, seqmap_kw)) {
diff --git a/src/.gitignore b/src/.gitignore
index 38b001a..71b6685 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,5 +1,6 @@
cmdline.h
*-cl.h
eclat
+ispeek
comtab.man
xref.man
diff --git a/src/Makefile.am b/src/Makefile.am
index f772c79..e78461c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of Eclat
-# Copyright (C) 2012-2015 Sergey Poznyakoff
+# Copyright (C) 2012-2018 Sergey Poznyakoff
#
# Eclat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -79,7 +79,7 @@ ispeek_SOURCES = \
LDADD=../lib/libeclat.a @LIBOBJS@ ../grecs/src/libgrecs.a $(CURL_LIBS) @MAPLIBS@
AM_CPPFLAGS = \
- -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib $(CURL_CFLAGS)\
+ @GRECS_INCLUDES@ -I$(top_srcdir)/lib $(CURL_CFLAGS)\
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
-DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
@@ -134,7 +134,7 @@ EXTRA_DIST=\
SUFFIXES=.opt .c .h
.opt.h:
- $(AM_V_GEN)m4 -s $(top_srcdir)/grecs/build-aux/getopt.m4 eclatcl.m4 $< | sed '1d' > $@
+ $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 eclatcl.m4 $< | sed '1d' > $@
comtab.man: eclat.c
$(AM_V_GEN)if test -f eclat.c; then\
diff --git a/src/config.c b/src/config.c
index 069ddd0..01379f3 100644
--- a/src/config.c
+++ b/src/config.c
@@ -380,13 +380,13 @@ static struct grecs_keyword instance_store_kw[] = {
static struct grecs_keyword eclat_kw[] = {
{ "default-endpoint", "hostname",
"Set default EC2 endpoint",
- grecs_type_string, GRECS_DFLT, &endpoint },
+ grecs_type_string, GRECS_CONST, &endpoint },
{ "region", "<name: string> <endpoint: string>",
"Define a region",
grecs_type_string, GRECS_MULT, NULL, 0, cb_region },
{ "signature-version", "version",
"Signature version",
- grecs_type_string, GRECS_DFLT, &signature_version },
+ grecs_type_string, GRECS_CONST, &signature_version },
{ "authentication-provider", "<type: file|instance-store> <arg: string>",
"Define authentication provider.",
grecs_type_string, GRECS_DFLT, NULL, 0, cb_authentication_provider },
@@ -468,7 +468,8 @@ config_init()
DEFAULT_INCLUDE_DIR, NULL);
grecs_preprocessor = DEFAULT_PREPROCESSOR;
grecs_log_to_stderr = 1;
- grecs_adjust_string_locations = 1;
+ grecs_parser_options = GRECS_OPTION_ADJUST_STRING_LOCATIONS
+ | GRECS_OPTION_QUOTED_STRING_CONCAT;
grecs_print_diag_fun = grecs_print_diag;
ec2_regtab = grecs_symtab_create_default(sizeof(struct ec2_param));
diff --git a/src/eclat.h b/src/eclat.h
index 221347f..21e89e1 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -25,7 +25,7 @@
#include <curl/curl.h>
#include <expat.h>
#include "grecs.h"
-#include "grecsopt.h"
+#include "grecs/opt.h"
#include "wordsplit.h"
#include "libeclat.h"
#include "forlan.h"
diff --git a/src/ispeek.c b/src/ispeek.c
index e602125..9e4f8e3 100644
--- a/src/ispeek.c
+++ b/src/ispeek.c
@@ -24,10 +24,10 @@
#include <string.h>
#include <curl/curl.h>
#include "grecs.h"
-#include "grecsopt.h"
+#include "grecs/opt.h"
#include "wordsplit.h"
#include "libeclat.h"
-#include "json.h"
+#include "grecs/json.h"
const char *base_url = "http://169.254.169.254/latest";
@@ -128,29 +128,31 @@ print_file(const char *path, struct closure *cl)
if (argv[0]) {
char *key;
- struct json_object *obj;
+ struct json_value *obj;
static char typestr[] = {
[json_null] = '0',
[json_bool] = 'b',
[json_number] = 'n',
[json_string] = 's',
[json_arr] = 'a',
- [json_obj] = 'o'
+ [json_object] = 'o'
};
obj = json_parse_string(text, strlen(text));
- if (!obj)
- die(EX_DATAERR,
- "%s: near %s",
- json_err_diag,
- json_err_ptr);
+ if (!obj) {
+ char *str = NULL;
+ size_t len = 0;
+ grecs_asprint_locus(&str, &len, &json_err_locus);
+ die(EX_DATAERR, "%s: %s", str, json_err_diag);
+ }
+
while (key = *argv++) {
- struct json_object *p;
+ struct json_value *p;
char *s;
if (print_options & PRINT_NAME)
printf("%s%s", key, delim);
- p = json_object_lookup(obj, key);
+ p = json_value_lookup(obj, key);
if (p) {
if (print_options & PRINT_TYPE)
printf("%c%s", typestr[p->type], delim);
@@ -181,7 +183,7 @@ print_file(const char *path, struct closure *cl)
case json_arr:
printf("array");
break;
- case json_obj:
+ case json_object:
printf("object");
break;
}
diff --git a/src/mktags.c b/src/mktags.c
index 6fb3b10..27ea327 100644
--- a/src/mktags.c
+++ b/src/mktags.c
@@ -1,5 +1,5 @@
/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
+ Copyright (C) 2012-2018 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -52,6 +52,8 @@ process_tags(eclat_command_env_t *env, int argc, char **argv, int require_tags)
size_t insize = 0;
ssize_t rc;
char *p;
+ struct wordsplit ws;
+ int wsflags;
if (strcmp(from_file, "-") == 0) {
from_file = "<stdin>";
@@ -63,32 +65,28 @@ process_tags(eclat_command_env_t *env, int argc, char **argv, int require_tags)
from_file, strerror(errno));
}
+ wsflags = WRDSF_DEFFLAGS|WRDSF_NOSPLIT;
while ((rc = grecs_getline(&inbuf, &insize, fp)) > 0) {
- eclat_trimnl(inbuf);
- if (inbuf[0] == '#' || inbuf[0] == 0)
- continue;
- p = strchr(inbuf, '=');
+ char *text;
+ if (wordsplit(inbuf, &ws, wsflags)) {
+ die(EX_SOFTWARE, "%s", wordsplit_strerror(&ws));
+ }
+ wsflags |= WRDSF_REUSE;
+ text = ws.ws_wordv[0];
+ p = strchr(text, '=');
if (p)
*p++ = 0;
grecs_asprintf(&bufptr, &bufsize, "Tag.%d.Key", j);
- eclat_request_add_param(q, bufptr, inbuf);
+ eclat_request_add_param(q, bufptr, text);
if (p) {
grecs_asprintf(&bufptr, &bufsize,
"Tag.%d.Value", j);
- if (*p == '"' && p[strlen(p)-1] == '"') {
- size_t len = strlen(p);
- char *copy = grecs_malloc(len);
-
- wordsplit_c_unquote_copy(copy, p + 1,
- len - 2);
- eclat_request_add_param(q, bufptr,
- copy);
- free(copy);
- } else
- eclat_request_add_param(q, bufptr, p);
+ eclat_request_add_param(q, bufptr, p);
}
++j;
}
+ if (wsflags & WRDSF_REUSE)
+ wordsplit_free(&ws);
fclose(fp);
free(inbuf);
diff --git a/src/util.c b/src/util.c
index 43b27ef..54a2e39 100644
--- a/src/util.c
+++ b/src/util.c
@@ -15,7 +15,7 @@
along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
#include "eclat.h"
-#include "json.h"
+#include "grecs/json.h"
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
@@ -501,7 +501,7 @@ char *
eclat_get_instance_zone()
{
char *doc;
- struct json_object *obj, *p;
+ struct json_value *obj, *p;
char *retval = NULL;
CURL *curl;
char *url;
@@ -522,17 +522,17 @@ eclat_get_instance_zone()
if (!doc)
return NULL;
obj = json_parse_string(doc, strlen(doc));
- if (!obj)
- die(EX_DATAERR,
- "%s: near %s",
- json_err_diag,
- json_err_ptr);
-
- p = json_object_lookup(obj, "region");
+ if (!obj) {
+ char *str = NULL;
+ size_t len = 0;
+ grecs_asprint_locus(&str, &len, &json_err_locus);
+ die(EX_DATAERR, "%s: %s", str, json_err_diag);
+ }
+ p = json_value_lookup(obj, "region");
if (p && p->type == json_string)
retval = grecs_strdup(p->v.s);
grecs_txtacc_free(acc);
- json_object_free(obj);
+ json_value_free(obj);
return retval;
}
@@ -544,7 +544,7 @@ eclat_get_instance_creds(char *id, char **access_key_ptr, char **secret_key_ptr,
char *url = NULL;
char *s;
char *doc;
- struct json_object *obj, *p;
+ struct json_value *obj, *p;
int err = 0;
struct grecs_txtacc *acc;
@@ -579,32 +579,33 @@ eclat_get_instance_creds(char *id, char **access_key_ptr, char **secret_key_ptr,
free(url);
obj = json_parse_string(doc, strlen(doc));
- if (!obj)
- die(EX_DATAERR,
- "%s: near %s",
- json_err_diag,
- json_err_ptr);
-
- p = json_object_lookup(obj, "AccessKeyId");
+ if (!obj) {
+ char *str = NULL;
+ size_t len = 0;
+ grecs_asprint_locus(&str, &len, &json_err_locus);
+ die(EX_DATAERR, "%s: %s", str, json_err_diag);
+ }
+
+ p = json_value_lookup(obj, "AccessKeyId");
if (p && p->type == json_string)
*access_key_ptr = grecs_strdup(p->v.s);
else
err = 1;
- p = json_object_lookup(obj, "SecretAccessKey");
+ p = json_value_lookup(obj, "SecretAccessKey");
if (p && p->type == json_string)
*secret_key_ptr = grecs_strdup(p->v.s);
else
err = 1;
- p = json_object_lookup(obj, "Token");
+ p = json_value_lookup(obj, "Token");
if (p && p->type == json_string)
*token_ptr = grecs_strdup(p->v.s);
else
err = 1;
grecs_txtacc_free(acc);
- json_object_free(obj);
+ json_value_free(obj);
if (err)
die(EX_DATAERR, "security credentials missing");
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7ba167c..61046ba 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of Eclat
-# Copyright (C) 2012-2015 Sergey Poznyakoff
+# Copyright (C) 2012-2018 Sergey Poznyakoff
#
# Eclat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -117,14 +117,13 @@ endif
noinst_PROGRAMS = \
$(GDBMLOAD)\
tforlan\
- tjson\
thmac\
trws\
turlenc\
txml
LDADD = ../lib/libeclat.a ../grecs/src/libgrecs.a
-AM_CPPFLAGS = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib
+AM_CPPFLAGS = @GRECS_INCLUDES@ -I$(top_srcdir)/lib
gdbmload_LDADD=../lib/libeclat.a ../grecs/src/libgrecs.a @MAPLIBS@
diff --git a/tests/tjson.c b/tests/tjson.c
deleted file mode 100644
index bfc6d05..0000000
--- a/tests/tjson.c
+++ b/dev/null
@@ -1,116 +0,0 @@
-/* This file is part of Eclat.
- Copyright (C) 2012-2015 Sergey Poznyakoff.
-
- Eclat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- Eclat is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#ifdef HAVE_GETOPT_H
-# include <getopt.h>
-#endif
-#include <errno.h>
-#include <sysexits.h>
-#include <libeclat.h>
-#include <json.h>
-
-void
-usage()
-{
- printf("usage: %s [OPTIONS] FILE [INPUT]\n", program_name);
-}
-
-static char *
-readfile(FILE *fp)
-{
- char inbuf[4096];
- char *buf;
- size_t bufsize = 0;
- size_t bufmax;
- size_t n;
-
- bufmax = sizeof(inbuf);
- buf = grecs_malloc(bufmax);
-
- while (n = fread(inbuf, 1, sizeof(inbuf), fp)) {
- if (bufsize + n >= bufmax) {
- bufmax *= 2;
- buf = grecs_realloc(buf, bufmax);
- }
- memcpy(buf + bufsize, inbuf, n);
- bufsize += n;
- }
- if (ferror(fp))
- die(EX_NOINPUT, "read error");
- if (bufsize + 1 >= bufmax) {
- bufmax++;
- buf = grecs_realloc(buf, bufmax);
- }
- buf[bufsize] = 0;
- return buf;
-}
-
-
-
-int
-main(int argc, char **argv)
-{
- char *file = "-";
- FILE *fp;
- int rc;
- char *input;
- struct json_object *obj;
-
- set_program_name(argv[0]);
- while ((rc = getopt(argc, argv, "f:h")) != EOF) {
- switch (rc) {
- case 'f':
- file = optarg;
- break;
- case 'h':
- usage();
- return 0;
- default:
- exit(EX_USAGE);
- }
- }
- argc -= optind;
- argv += optind;
-
- //FIXME: process args
-
- if (strcmp(file, "-") == 0)
- fp = stdin;
- else {
- fp = fopen(file, "r");
- if (!fp)
- die(EX_NOINPUT, "cannot open input file \"%s\": %s",
- file, strerror(errno));
- }
-
- input = readfile(fp);
- obj = json_parse_string(input, strlen(input));
- if (!obj)
- die(EX_DATAERR,
- "%s: near %s",
- json_err_diag,
- json_err_ptr);
-
- json_object_free(obj);
- return 0;
-}
-
-

Return to:

Send suggestions and report system problems to the System administrator.