fixed some inconsistency in moo_fmt_object_().

changed to handle a symbol with a c-style escape sequences enclosed in #""
This commit is contained in:
hyunghwan.chung 2019-05-30 15:44:24 +00:00
parent 5bf79fb4b5
commit a4c13608ef
7 changed files with 113 additions and 87 deletions

View File

@ -90,7 +90,11 @@ class MyObject(Object)
0 priorTo: limit by: 1 do: [ :idx | 0 priorTo: limit by: 1 do: [ :idx |
| tb | | tb |
tb := tc at: idx. tb := tc at: idx.
System log(System.Log.INFO, idx asString, (if (tb value) { ' PASS' } else { ' FAIL' }), S'\n'). System log(System.Log.INFO, idx asString, (if (tb value) { ' PASS' } else { ' FAIL' }), "\n").
]. ].
## TODO:
String format('%s', " 나 는\\\"") dump.
#"a b\nc" dump.
} }
} }

View File

@ -39,7 +39,7 @@ class MyObject(Object)
sg addSemaphore: s3. sg addSemaphore: s3.
s1 signalOnInput: 0. s1 signalOnInput: 0.
s2 signalOnInput: 0. ## this should raise an exception. s2 signalOnInput: 0. ## this should raise an exception as the same file descriptor is added to a different semaphore
s3 signalOnInput: 0. s3 signalOnInput: 0.
[ sg wait. ] fork. [ sg wait. ] fork.

View File

@ -2019,11 +2019,19 @@ retry:
break; break;
case '\'': case '\'':
/* quoted symbol literal */ /* #'XXXX' - quoted symbol literal */
if (get_strlit(moo) <= -1) return -1; /* reuse the string literal tokenizer */ if (get_strlit(moo) <= -1) return -1; /* reuse the string literal tokenizer */
SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); /* change the symbol type to symbol */ SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); /* change the symbol type to symbol */
break; break;
case '"':
/* #"XXXX" - quoted symbol literal with C-style escape sequences.
* if MOO_PRAGMA_QC is set, this part should never be reached */
MOO_ASSERT (moo, !(moo->c->pragma_flags & MOO_PRAGMA_QC));
if (get_string(moo, '"', '\\', 0, 0) <= -1) return -1;
SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); /* change the symbol type to symbol */
break;
case '\\': case '\\':
ADD_TOKEN_CHAR (moo, c); ADD_TOKEN_CHAR (moo, c);
GET_CHAR_TO (moo, c); GET_CHAR_TO (moo, c);

View File

@ -1430,12 +1430,6 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
if (moo_bfmt_out(fmtout, "%.*js", moo->inttostr.xbuf.len, moo->inttostr.xbuf.ptr) <= -1) return -1; if (moo_bfmt_out(fmtout, "%.*js", moo->inttostr.xbuf.len, moo->inttostr.xbuf.ptr) <= -1) return -1;
} }
else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_CHAR) else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_CHAR)
{
if (c == moo->_symbol)
{
if (moo_bfmt_out(fmtout, "#%.*js", MOO_OBJ_GET_SIZE(oop), MOO_OBJ_GET_CHAR_SLOT(oop)) <= -1) return -1;
}
else /*if ((moo_oop_t)c == moo->_string)*/
{ {
moo_ooch_t ch; moo_ooch_t ch;
int escape = 0; int escape = 0;
@ -1443,7 +1437,7 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++)
{ {
ch = MOO_OBJ_GET_CHAR_SLOT(oop)[i]; ch = MOO_OBJ_GET_CHAR_SLOT(oop)[i];
if (ch < ' ') if ((ch >= '\0' && ch < ' ') || ch == '\\' || ch == '\"')
{ {
escape = 1; escape = 1;
break; break;
@ -1454,11 +1448,11 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
{ {
moo_ooch_t escaped; moo_ooch_t escaped;
if (moo_bfmt_out(fmtout, "S'") <= -1) return -1; if (moo_bfmt_out(fmtout, ((c == moo->_symbol)? "#\"": "\"")) <= -1) return -1;
for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++)
{ {
ch = MOO_OBJ_GET_CHAR_SLOT(oop)[i]; ch = MOO_OBJ_GET_CHAR_SLOT(oop)[i];
if (ch < ' ') if (ch >= '\0' && ch < ' ')
{ {
switch (ch) switch (ch)
{ {
@ -1487,18 +1481,17 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
escaped = 'a'; escaped = 'a';
break; break;
default: default:
escaped = ch; /* since it's less than ' ' and greater than or equal to '\0' ,
break; * it should not exceed 0xFF regardless of character mode. %02X should be good enough */
if (moo_bfmt_out(fmtout, "\\x%02X", (moo_oochu_t)ch) <= -1) return -1;
continue;
} }
if (escaped == ch)
{
if (moo_bfmt_out(fmtout, "\\x%X", ch) <= -1) return -1;
}
else
{
if (moo_bfmt_out(fmtout, "\\%jc", escaped) <= -1) return -1; if (moo_bfmt_out(fmtout, "\\%jc", escaped) <= -1) return -1;
} }
else if (ch == '\\' || ch == '\"')
{
if (moo_bfmt_out(fmtout, "\\%jc", ch) <= -1) return -1;
} }
else else
{ {
@ -1506,12 +1499,11 @@ int moo_fmt_object_ (moo_fmtout_t* fmtout, moo_oop_t oop)
} }
} }
if (moo_bfmt_out(fmtout, "'") <= -1) return -1; if (moo_bfmt_out(fmtout, "\"") <= -1) return -1;
} }
else else
{ {
if (moo_bfmt_out(fmtout, "'%.*js'", MOO_OBJ_GET_SIZE(oop), MOO_OBJ_GET_CHAR_SLOT(oop)) <= -1) return -1; if (moo_bfmt_out(fmtout, ((c == moo->_symbol)? "#%.*js": "'%.%js'"), MOO_OBJ_GET_SIZE(oop), MOO_OBJ_GET_CHAR_SLOT(oop)) <= -1) return -1;
}
} }
} }
else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_BYTE) else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_BYTE)

View File

@ -419,7 +419,7 @@ struct moo_initv_t
enum moo_pragma_flag_t enum moo_pragma_flag_t
{ {
MOO_PRAGMA_QC = (1 << 0) MOO_PRAGMA_QC = (1 << 0) /* quoted commented. treat a double quoted text as a comment */
}; };
enum moo_cunit_type_t enum moo_cunit_type_t

View File

@ -191,7 +191,7 @@ static moo_pfrc_t pf_write (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
ucsrem -= ucslen; ucsrem -= ucslen;
} }
#else #else
write (con->fd, MOO_GET_OBJ_CHAR_SLOT(msg), MOO_OBJ_GET_SIZE(msg)); /* TODO: error handling. incomplete write handling */ write (con->fd, MOO_OBJ_GET_CHAR_SLOT(msg), MOO_OBJ_GET_SIZE(msg)); /* TODO: error handling. incomplete write handling */
#endif #endif
MOO_STACK_SETRETTORCV (moo, nargs); /* TODO: change return code */ MOO_STACK_SETRETTORCV (moo, nargs); /* TODO: change return code */

View File

@ -99,6 +99,7 @@ static moo_pfrc_t pf_open_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
} }
bl = MOO_OBJ_GET_SIZE(np); bl = MOO_OBJ_GET_SIZE(np);
#if defined(MOO_OOCH_IS_UCH)
dispname = moo_dupootobcstr(moo, MOO_OBJ_GET_CHAR_SLOT(np), &bl); dispname = moo_dupootobcstr(moo, MOO_OBJ_GET_CHAR_SLOT(np), &bl);
if (!dispname) if (!dispname)
{ {
@ -106,6 +107,9 @@ static moo_pfrc_t pf_open_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
MOO_STACK_SETRETTOERRNUM (moo, nargs); MOO_STACK_SETRETTOERRNUM (moo, nargs);
goto oops; goto oops;
} }
#else
dispname = MOO_OBJ_GET_CHAR_SLOT(np);
#endif
} }
} }
@ -150,13 +154,17 @@ static moo_pfrc_t pf_open_display (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
x11->display = MOO_SMPTR_TO_OOP(disp); x11->display = MOO_SMPTR_TO_OOP(disp);
MOO_STACK_SETRETTORCV (moo, nargs); MOO_STACK_SETRETTORCV (moo, nargs);
#if defined(MOO_OOCH_IS_UCH)
if (dispname) moo_freemem (moo, dispname); if (dispname) moo_freemem (moo, dispname);
#endif
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
oops: oops:
if (disp) XCloseDisplay (disp); if (disp) XCloseDisplay (disp);
if (event) moo_freemem (moo, event); if (event) moo_freemem (moo, event);
#if defined(MOO_OOCH_IS_UCH)
if (dispname) moo_freemem (moo, dispname); if (dispname) moo_freemem (moo, dispname);
#endif
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
@ -724,7 +732,7 @@ static moo_pfrc_t pf_draw_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, bb, &bcslen); moo_convootobchars (moo, MOO_OBJ_GET_CHAR_SLOT(a3), &oocslen, bb, &bcslen);
#else #else
bb = MOO_OBJ_GET_CHAR_SLOT(a3); bb = MOO_OBJ_GET_CHAR_SLOT(a3);
bcslen = oocslen; bcslen = MOO_OBJ_GET_SIZE(a3);
#endif #endif
XmbTextExtents(MOO_OOP_TO_SMPTR(gc->font_set), bb, bcslen, MOO_NULL, &r); XmbTextExtents(MOO_OOP_TO_SMPTR(gc->font_set), bb, bcslen, MOO_NULL, &r);
@ -741,6 +749,7 @@ static moo_pfrc_t pf_draw_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
} }
else else
{ {
#if defined(MOO_OOCH_IS_UCH)
XChar2b* stptr; XChar2b* stptr;
moo_oow_t stlen; moo_oow_t stlen;
int ascent = 0; int ascent = 0;
@ -765,6 +774,19 @@ static moo_pfrc_t pf_draw_string (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, stptr, stlen); MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, stptr, stlen);
moo_freemem (moo, stptr); moo_freemem (moo, stptr);
#else
int ascent = 0;
if (MOO_OOP_IS_SMPTR(gc->font_ptr))
{
int direction, descent;
XCharStruct overall;
XTextExtents16 (MOO_OOP_TO_SMPTR(gc->font_ptr), MOO_OBJ_GET_CHAR_SLOT(a3), MOO_OBJ_GET_SIZE(a3), &direction, &ascent, &descent, &overall);
}
XDrawString (disp, (Window)MOO_OOP_TO_SMOOI(((oop_x11_widget_t)gc->widget)->window_handle), MOO_OOP_TO_SMPTR(gc->gc_handle),
MOO_OOP_TO_SMOOI(a1), MOO_OOP_TO_SMOOI(a2) + ascent, MOO_OBJ_GET_CHAR_SLOT(a3), MOO_OBJ_GET_SIZE(a3));
#endif
} }
MOO_STACK_SETRETTORCV (moo, nargs); MOO_STACK_SETRETTORCV (moo, nargs);