Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Shafer committed Nov 7, 2014
2 parents e214bfd + c96200f commit fd0761c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
33 changes: 20 additions & 13 deletions libxo/libxo.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct xo_handle_s {
unsigned short xo_indent; /* Indent level (if pretty) */
unsigned short xo_indent_by; /* Indent amount (tab stop) */
xo_write_func_t xo_write; /* Write callback */
xo_close_func_t xo_close; /* Clo;se callback */
xo_close_func_t xo_close; /* Close callback */
xo_formatter_t xo_formatter; /* Custom formating function */
xo_checkpointer_t xo_checkpointer; /* Custom formating support function */
void *xo_opaque; /* Opaque data for write function */
Expand Down Expand Up @@ -1912,6 +1912,7 @@ xo_format_string (xo_handle_t *xop, xo_buffer_t *xbp, xo_xff_flags_t flags,
xo_format_t *xfp)
{
static char null[] = "(null)";

char *cp = NULL;
wchar_t *wcp = NULL;
int len, cols = 0, rc = 0;
Expand All @@ -1922,16 +1923,33 @@ xo_format_string (xo_handle_t *xop, xo_buffer_t *xbp, xo_xff_flags_t flags,
if (xo_check_conversion(xop, xfp->xf_enc, need_enc))
return 0;

len = xfp->xf_width[XF_WIDTH_SIZE];

if (xfp->xf_enc == XF_ENC_WIDE) {
wcp = va_arg(xop->xo_vap, wchar_t *);
if (xfp->xf_skip)
return 0;

/*
* Dont' deref NULL; use the traditional "(null)" instead
* of the more accurate "who's been a naughty boy, then?".
*/
if (wcp == NULL) {
cp = null;
len = sizeof(null) - 1;
}

} else {
cp = va_arg(xop->xo_vap, char *); /* UTF-8 or native */
if (xfp->xf_skip)
return 0;

/* Echo "Dont' deref NULL" logic */
if (cp == NULL) {
cp = null;
len = sizeof(null) - 1;
}

/*
* Optimize the most common case, which is "%s". We just
* need to copy the complete string to the output buffer.
Expand All @@ -1957,17 +1975,6 @@ xo_format_string (xo_handle_t *xop, xo_buffer_t *xbp, xo_xff_flags_t flags,
}
}

len = xfp->xf_width[XF_WIDTH_SIZE];

/*
* Dont' deref NULL; use the traditional "(null)" instead
* of the more accurate "who's been a naughty boy, then?".
*/
if (cp == NULL && wcp == NULL) {
cp = null;
len = sizeof(null) - 1;
}

cols = xo_format_string_direct(xop, xbp, flags, wcp, cp, len,
xfp->xf_width[XF_WIDTH_MAX],
need_enc, xfp->xf_enc);
Expand Down Expand Up @@ -3859,7 +3866,7 @@ xo_close_list_h (xo_handle_t *xop, const char *name)
rc = xo_printf(xop, "%s%*s]", pre_nl, xo_indent(xop), "");
xop->xo_stack[xop->xo_depth].xs_flags |= XSF_NOT_FIRST;

return 0;
return rc;
}

int
Expand Down
4 changes: 2 additions & 2 deletions tests/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_07_test_SOURCES = test_07.c

# TEST_CASES := $(shell cd ${srcdir} ; echo *.c )

bin_PROGRAMS = ${TEST_CASES:.c=.test}
noinst_PROGRAMS = ${TEST_CASES:.c=.test}

LDADD = \
${top_builddir}/libxo/libxo.la
Expand Down Expand Up @@ -66,7 +66,7 @@ valgrind:

TEST_ONE = \
LIBXO_OPTIONS=:W$$fmt \
${CHECKER} $$base.test ${TEST_OPTS} \
${CHECKER} ./$$base.test ${TEST_OPTS} \
> out/$$base.$$fmt.out 2> out/$$base.$$fmt.err ; \
${DIFF} -Nu ${srcdir}/saved/$$base.$$fmt.out out/$$base.$$fmt.out ${S2O} ; \
${DIFF} -Nu ${srcdir}/saved/$$base.$$fmt.err out/$$base.$$fmt.err ${S2O}
Expand Down
2 changes: 1 addition & 1 deletion tests/core/saved/test_07.J.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"employees": {"v1":"γιγνώσκειν","v2":"ὦ ἄνδρες ᾿Αθηναῖοι","columns":28,"columns":2,"v1":"ახლავე გაიაროთ რეგისტრაცია","v2":"Unicode-ის მეათე საერთაშორისო","columns":55, "employee": ["columns":0, {"first-name":"Jim","nic-name":"\"რეგტ\"","last-name":"გთხოვთ ახ","department":431,"percent-time":90,"columns":23,"benefits":"full"}, {"first-name":"Terry","nic-name":"\"<one\"","last-name":"Οὐχὶ ταὐτὰ παρίσταταί μοι Jones","department":660,"percent-time":90,"columns":47,"benefits":"full"}, {"first-name":"Leslie","nic-name":"\"Les\"","last-name":"Patterson","department":341,"percent-time":60,"columns":25,"benefits":"full"}, {"first-name":"Ashley","nic-name":"\"Ash\"","last-name":"Meter & Smith","department":1440,"percent-time":40,"columns":30}, {"first-name":"0123456789","nic-name":"\"0123456789\"","last-name":"012345678901234567890","department":1440,"percent-time":40,"columns":49}, {"first-name":"ახლა","nic-name":"\"გაიარო\"","last-name":"საერთაშორისო","department":123,"percent-time":90,"columns":29,"benefits":"full"}]}
{"employees": {"test": [{"filename":"(null)"}],"v1":"γιγνώσκειν","v2":"ὦ ἄνδρες ᾿Αθηναῖοι","columns":28,"columns":2,"v1":"ახლავე გაიაროთ რეგისტრაცია","v2":"Unicode-ის მეათე საერთაშორისო","columns":55, "employee": ["columns":0, {"first-name":"Jim","nic-name":"\"რეგტ\"","last-name":"გთხოვთ ახ","department":431,"percent-time":90,"columns":23,"benefits":"full"}, {"first-name":"Terry","nic-name":"\"<one\"","last-name":"Οὐχὶ ταὐτὰ παρίσταταί μοι Jones","department":660,"percent-time":90,"columns":47,"benefits":"full"}, {"first-name":"Leslie","nic-name":"\"Les\"","last-name":"Patterson","department":341,"percent-time":60,"columns":25,"benefits":"full"}, {"first-name":"Ashley","nic-name":"\"Ash\"","last-name":"Meter & Smith","department":1440,"percent-time":40,"columns":30}, {"first-name":"0123456789","nic-name":"\"0123456789\"","last-name":"012345678901234567890","department":1440,"percent-time":40,"columns":49}, {"first-name":"ახლა","nic-name":"\"გაიარო\"","last-name":"საერთაშორისო","department":123,"percent-time":90,"columns":29,"benefits":"full"}]}
}
5 changes: 5 additions & 0 deletions tests/core/saved/test_07.JP.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"employees": {
"test": [
{
"filename": "(null)"
}
],
"v1": "γιγνώσκειν",
"v2": "ὦ ἄνδρες ᾿Αθηναῖοι",
"columns": 28,
Expand Down
2 changes: 1 addition & 1 deletion tests/core/saved/test_07.X.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<employees><v1>γιγνώσκειν</v1><v2>ὦ ἄνδρες ᾿Αθηναῖοι</v2><columns>28</columns><columns>2</columns><v1>ახლავე გაიაროთ რეგისტრაცია</v1><v2>Unicode-ის მეათე საერთაშორისო</v2><columns>55</columns><columns>0</columns><employee><first-name>Jim</first-name><nic-name>"რეგტ"</nic-name><last-name>გთხოვთ ახ</last-name><department>431</department><percent-time>90</percent-time><columns>23</columns><benefits full-time="honest &amp; for true">full</benefits></employee><employee><first-name>Terry</first-name><nic-name>"&lt;one"</nic-name><last-name>Οὐχὶ ταὐτὰ παρίσταταί μοι Jones</last-name><department>660</department><percent-time>90</percent-time><columns>47</columns><benefits full-time="honest &amp; for true">full</benefits></employee><employee><first-name>Leslie</first-name><nic-name>"Les"</nic-name><last-name>Patterson</last-name><department>341</department><percent-time>60</percent-time><columns>25</columns><benefits full-time="honest &amp; for true">full</benefits></employee><employee><first-name>Ashley</first-name><nic-name>"Ash"</nic-name><last-name>Meter &amp; Smith</last-name><department>1440</department><percent-time>40</percent-time><columns>30</columns></employee><employee><first-name>0123456789</first-name><nic-name>"0123456789"</nic-name><last-name>012345678901234567890</last-name><department>1440</department><percent-time>40</percent-time><columns>49</columns></employee><employee><first-name>ახლა</first-name><nic-name>"გაიარო"</nic-name><last-name>საერთაშორისო</last-name><department>123</department><percent-time>90</percent-time><columns>29</columns><benefits full-time="honest &amp; for true">full</benefits></employee></employees>
<employees><test><filename>(null)</filename></test><v1>γιγνώσκειν</v1><v2>ὦ ἄνδρες ᾿Αθηναῖοι</v2><columns>28</columns><columns>2</columns><v1>ახლავე გაიაროთ რეგისტრაცია</v1><v2>Unicode-ის მეათე საერთაშორისო</v2><columns>55</columns><columns>0</columns><employee><first-name>Jim</first-name><nic-name>"რეგტ"</nic-name><last-name>გთხოვთ ახ</last-name><department>431</department><percent-time>90</percent-time><columns>23</columns><benefits full-time="honest &amp; for true">full</benefits></employee><employee><first-name>Terry</first-name><nic-name>"&lt;one"</nic-name><last-name>Οὐχὶ ταὐτὰ παρίσταταί μοι Jones</last-name><department>660</department><percent-time>90</percent-time><columns>47</columns><benefits full-time="honest &amp; for true">full</benefits></employee><employee><first-name>Leslie</first-name><nic-name>"Les"</nic-name><last-name>Patterson</last-name><department>341</department><percent-time>60</percent-time><columns>25</columns><benefits full-time="honest &amp; for true">full</benefits></employee><employee><first-name>Ashley</first-name><nic-name>"Ash"</nic-name><last-name>Meter &amp; Smith</last-name><department>1440</department><percent-time>40</percent-time><columns>30</columns></employee><employee><first-name>0123456789</first-name><nic-name>"0123456789"</nic-name><last-name>012345678901234567890</last-name><department>1440</department><percent-time>40</percent-time><columns>49</columns></employee><employee><first-name>ახლა</first-name><nic-name>"გაიარო"</nic-name><last-name>საერთაშორისო</last-name><department>123</department><percent-time>90</percent-time><columns>29</columns><benefits full-time="honest &amp; for true">full</benefits></employee></employees>
3 changes: 3 additions & 0 deletions tests/core/saved/test_07.XP.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<employees>
<test>
<filename>(null)</filename>
</test>
<v1>γιγνώσκειν</v1>
<v2>ὦ ἄνδρες ᾿Αθηναῖοι</v2>
<columns>28</columns>
Expand Down
6 changes: 6 additions & 0 deletions tests/core/test_07.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ main (int argc, char **argv)

xo_open_container("employees");

xo_open_list("test");
xo_open_instance("test");
xo_emit("{ek:filename/%s}", NULL);
xo_close_instance("test");
xo_close_list("test");

rc = xo_emit("Οὐχὶ ταὐτὰ παρίσταταί μοι {:v1/%s}, {:v2/%s}\n",
"γιγνώσκειν", "ὦ ἄνδρες ᾿Αθηναῖοι");
rc = xo_emit("{:columns/%d}\n", rc);
Expand Down

0 comments on commit fd0761c

Please sign in to comment.