From d4d9491f3c0b19a044556f7fdc3e34d425d256f7 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 4 Mar 2018 14:43:23 +0000 Subject: [PATCH] exported hcl_readchar() and hcl_unreadchar() --- lib/hcl.h | 16 ++++++++++++++++ lib/read.c | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/hcl.h b/lib/hcl.h index 5de3098..dbde917 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1497,6 +1497,7 @@ HCL_EXPORT hcl_oop_t hcl_read ( hcl_t* hcl ); + HCL_EXPORT int hcl_print ( hcl_t* hcl, hcl_oop_t obj @@ -1513,6 +1514,21 @@ HCL_EXPORT int hcl_decode ( hcl_ooi_t end ); + +/* if you should read charcters from the input stream before hcl_read(), + * you can call hcl_readchar() */ +HCL_EXPORT hcl_iolxc_t* hcl_readchar ( + hcl_t* hcl +); + +/* If you use hcl_readchar() to read the input stream, you may use + * hcl_unreadchar() to put back characters read for hcl_readchar() + * to return before reading the stream again. */ +HCL_EXPORT int hcl_unreadchar ( + hcl_t* hcl, + const hcl_iolxc_t* c +); + /* ========================================================================= * SYNTAX ERROR HANDLING * ========================================================================= */ diff --git a/lib/read.c b/lib/read.c index 893ef8f..0c47865 100644 --- a/lib/read.c +++ b/lib/read.c @@ -2402,3 +2402,22 @@ void hcl_detachio (hcl_t* hcl) } } } + +hcl_iolxc_t* hcl_readchar (hcl_t* hcl) +{ + int n = get_char(hcl); + if (n <= -1) return HCL_NULL; + return &hcl->c->lxc; +} + +int hcl_unreadchar (hcl_t* hcl, const hcl_iolxc_t* c) +{ + if (hcl->c->nungots >= HCL_COUNTOF(hcl->c->ungot)) + { + hcl_seterrnum (hcl, HCL_EBUFFULL); + return -1; + } + + unget_char (hcl, c); + return 0; +}