enhanced a special form FS to affect record reading in bytes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
51
lib/rio.c
51
lib/rio.c
@ -737,10 +737,16 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo
|
||||
hawk_rio_arg_t* p;
|
||||
hawk_rio_impl_t handler;
|
||||
int ret;
|
||||
int esc_lq_rq;
|
||||
int quoted;
|
||||
hawk_bch_t esc, lq, rq;
|
||||
|
||||
hawk_val_t* brs;
|
||||
hawk_bcs_t rrs;
|
||||
|
||||
hawk_val_t* bfs;
|
||||
hawk_bcs_t ffs;
|
||||
|
||||
hawk_oow_t line_len = 0;
|
||||
hawk_bch_t c = '\0', pc;
|
||||
|
||||
@ -762,12 +768,35 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo
|
||||
brs = hawk_rtx_getgbl(rtx, HAWK_GBL_RS);
|
||||
hawk_rtx_refupval(rtx, brs);
|
||||
|
||||
bfs = hawk_rtx_getgbl(rtx, HAWK_GBL_FS);
|
||||
hawk_rtx_refupval(rtx, bfs);
|
||||
|
||||
if (resolve_brs(rtx, brs, &rrs) <= -1)
|
||||
{
|
||||
hawk_rtx_refdownval(rtx, brs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (resolve_brs(rtx, bfs, &ffs) <= -1)
|
||||
{
|
||||
hawk_rtx_refdownval(rtx, bfs);
|
||||
hawk_rtx_refdownval(rtx, brs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* RS set to @nil, FS set to a special string starting with ?, followed by esc lq rq */
|
||||
esc_lq_rq = 0;
|
||||
quoted = 0;
|
||||
if (ffs.len == 5 && ffs.ptr[0] == '?' && !rrs.ptr)
|
||||
{
|
||||
esc = ffs.ptr[2];
|
||||
lq = ffs.ptr[3];
|
||||
rq = ffs.ptr[4];
|
||||
|
||||
esc_lq_rq = 1;
|
||||
esc_lq_rq += (esc == lq && esc == rq);
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
/* call the I/O handler */
|
||||
@ -859,6 +888,27 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo
|
||||
c = p->in.u.bbuf[p->in.pos++];
|
||||
end_pos = p->in.pos;
|
||||
|
||||
if (esc_lq_rq == 2)
|
||||
{
|
||||
/* if FS is something like [?,"""] and RS is @nil,
|
||||
* it supports multi-line quoted vlaues. */
|
||||
if (quoted == 2)
|
||||
{
|
||||
quoted = (c == rq);
|
||||
/* no continue here as c could be a new line */
|
||||
}
|
||||
else if (quoted == 1)
|
||||
{
|
||||
if (c == rq) quoted = 2;
|
||||
continue;
|
||||
}
|
||||
else if (c == lq)
|
||||
{
|
||||
quoted = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: handle different line terminator */
|
||||
/* separate by a new line */
|
||||
if (c == '\n')
|
||||
@ -1044,6 +1094,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, hawk_in_type_t in_type, const hawk_oo
|
||||
}
|
||||
|
||||
if (rrs.ptr && HAWK_RTX_GETVALTYPE(rtx, brs) != HAWK_VAL_MBS) hawk_rtx_freemem(rtx, rrs.ptr);
|
||||
hawk_rtx_refdownval(rtx, bfs);
|
||||
hawk_rtx_refdownval(rtx, brs);
|
||||
|
||||
return ret;
|
||||
|
@ -24,7 +24,8 @@ check_ERRORS = e-001.err
|
||||
##noinst_SCRIPTS = $(check_SCRIPTS)
|
||||
EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) tap.inc err.sh \
|
||||
journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \
|
||||
bibtex-to-html.hawk bibtex-to-html.out
|
||||
bibtex-to-html.hawk bibtex-to-html.out \
|
||||
fs-test.hawk fs-test.in fs-test.out
|
||||
|
||||
check_PROGRAMS = t-001 t-002 t-003 t-004 t-005 t-006 t-007 t-008 t-009
|
||||
|
||||
|
@ -648,7 +648,8 @@ check_SCRIPTS = $(am__append_1) h-003.hawk h-004.hawk h-009.hawk
|
||||
check_ERRORS = e-001.err
|
||||
EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) tap.inc err.sh \
|
||||
journal-toc.hawk journal-toc.in journal-toc.out journal-toc-html.out \
|
||||
bibtex-to-html.hawk bibtex-to-html.out
|
||||
bibtex-to-html.hawk bibtex-to-html.out \
|
||||
fs-test.hawk fs-test.in fs-test.out
|
||||
|
||||
t_001_SOURCES = t-001.c tap.h
|
||||
t_001_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
|
9
t/fs-test.hawk
Normal file
9
t/fs-test.hawk
Normal file
@ -0,0 +1,9 @@
|
||||
BEGIN {
|
||||
## `FS` with a question mark(`?`) followed by four characters. the last three are equal.
|
||||
FS="?,\"\"\"";
|
||||
}
|
||||
|
||||
{
|
||||
for (i = 0; i <= NF; i++) print i, "[" $i "]";
|
||||
}
|
||||
|
8
t/fs-test.in
Normal file
8
t/fs-test.in
Normal file
@ -0,0 +1,8 @@
|
||||
"Product ID","Product Name","Description","Price","Available Sizes","Notes"
|
||||
101,"Deluxe Widget","A versatile widget for various applications. Features include:
|
||||
- Enhanced durability
|
||||
- Multi-functional design
|
||||
- Easy to use",29.99,"Small,Medium,Large","Customer feedback suggests excellent performance."
|
||||
102,"Super Gadget","The ultimate gadget for tech enthusiasts.",49.99,"One Size","Limited stock, order soon!"
|
||||
103,"Basic Tool Set","A comprehensive set of essential tools, including a hammer, screwdriver, and wrench.
|
||||
Perfect for home DIY projects.",35.50,"N/A","Tools are made from high-quality steel."
|
36
t/fs-test.out
Normal file
36
t/fs-test.out
Normal file
@ -0,0 +1,36 @@
|
||||
0 ["Product ID","Product Name","Description","Price","Available Sizes","Notes"]
|
||||
1 [Product ID]
|
||||
2 [Product Name]
|
||||
3 [Description]
|
||||
4 [Price]
|
||||
5 [Available Sizes]
|
||||
6 [Notes]
|
||||
0 [101,"Deluxe Widget","A versatile widget for various applications. Features include:
|
||||
- Enhanced durability
|
||||
- Multi-functional design
|
||||
- Easy to use",29.99,"Small,Medium,Large","Customer feedback suggests excellent performance."]
|
||||
1 [101]
|
||||
2 [Deluxe Widget]
|
||||
3 [A versatile widget for various applications. Features include:
|
||||
- Enhanced durability
|
||||
- Multi-functional design
|
||||
- Easy to use]
|
||||
4 [29.99]
|
||||
5 [Small,Medium,Large]
|
||||
6 [Customer feedback suggests excellent performance.]
|
||||
0 [102,"Super Gadget","The ultimate gadget for tech enthusiasts.",49.99,"One Size","Limited stock, order soon!"]
|
||||
1 [102]
|
||||
2 [Super Gadget]
|
||||
3 [The ultimate gadget for tech enthusiasts.]
|
||||
4 [49.99]
|
||||
5 [One Size]
|
||||
6 [Limited stock, order soon!]
|
||||
0 [103,"Basic Tool Set","A comprehensive set of essential tools, including a hammer, screwdriver, and wrench.
|
||||
Perfect for home DIY projects.",35.50,"N/A","Tools are made from high-quality steel."]
|
||||
1 [103]
|
||||
2 [Basic Tool Set]
|
||||
3 [A comprehensive set of essential tools, including a hammer, screwdriver, and wrench.
|
||||
Perfect for home DIY projects.]
|
||||
4 [35.50]
|
||||
5 [N/A]
|
||||
6 [Tools are made from high-quality steel.]
|
@ -80,6 +80,7 @@ function main()
|
||||
run_test("journal-toc", "", @nil, 0, @nil);
|
||||
run_test("journal-toc", "-vHTML=1", "journal-toc", 0, "journal-toc-html");
|
||||
run_test("bibtex-to-html", "", "journal-toc", 1, "bibtex-to-html");
|
||||
run_test("fs-test", "", "fs-test", 0, "fs-test");
|
||||
|
||||
tap_end ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user