scmno****@osdn*****
scmno****@osdn*****
Wed Jun 13 06:27:12 JST 2018
changeset a7a40690d92b in quipu/quipu details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=a7a40690d92b user: Agustina Arzille <avarz****@riseu*****> date: Tue Jun 12 18:27:03 2018 -0300 description: Minor corrections in string parsing diffstat: bvector.cpp | 3 +- io.cpp | 80 +++++++++++++++++++-------------------------------------- memory.cpp | 16 ----------- utils/chmask.h | 4 +- 4 files changed, 30 insertions(+), 73 deletions(-) diffs (163 lines): diff -r 61350b8ffc08 -r a7a40690d92b bvector.cpp --- a/bvector.cpp Tue Jun 12 16:43:54 2018 -0300 +++ b/bvector.cpp Tue Jun 12 18:27:03 2018 -0300 @@ -460,8 +460,7 @@ if ((idx < 0 && (idx += sp->len) < 0) || idx >= sp->len + off) interp->raise_oob ("get:string", idx, sp->len); - *p = idx; - return (stridx (sp, idx)); + return (stridx (sp, *p = idx)); } static bvector* diff -r 61350b8ffc08 -r a7a40690d92b io.cpp --- a/io.cpp Tue Jun 12 16:43:54 2018 -0300 +++ b/io.cpp Tue Jun 12 18:27:03 2018 -0300 @@ -667,6 +667,27 @@ qp_return (*ret); } +static inline int +escape_char (int ch) +{ + if (ch == 'n') + return ('\n'); + else if (ch == 't') + return ('\t'); + else if (ch == 'r') + return ('\r'); + else if (ch == 'a') + return ('\a'); + else if (ch == 'b') + return ('\b'); + else if (ch == '\\' || ch == '"') + return (ch); + else if (ch == '0') + return (0); + else + return (-1); +} + object rdstate::read_bvector () { int bsz = 16; @@ -708,33 +729,8 @@ byte = (b1 - '0') * 16 + (b2 - '0'); } - else - switch (byte) - { - case 'n': - byte = '\n'; - break; - case 't': - byte = '\t'; - break; - case 'a': - byte = '\a'; - break; - case 'b': - byte = '\b'; - break; - case 'r': - byte = '\r'; - break; - case '"': - byte = '"'; - break; - case '\\': - byte = '\\'; - break; - default: - goto eilseq; - } + else if ((byte = escape_char (byte)) < 0) + goto eilseq; } if (ret->nbytes + 1 >= bsz) @@ -820,32 +816,10 @@ else { ch.len = 1; - switch (ch.uc) - { - case 'n': - *ch.buf = '\n'; - break; - case 't': - *ch.buf = '\t'; - break; - case 'a': - *ch.buf = '\a'; - break; - case 'b': - *ch.buf = '\b'; - break; - case 'r': - *ch.buf = '\r'; - break; - case '"': - *ch.buf = '"'; - break; - case '\\': - *ch.buf = '\\'; - break; - default: - goto eilseq; - } + if ((n = escape_char (ch.uc)) < 0) + goto eilseq; + + *ch.buf = n; } } diff -r 61350b8ffc08 -r a7a40690d92b memory.cpp --- a/memory.cpp Tue Jun 12 16:43:54 2018 -0300 +++ b/memory.cpp Tue Jun 12 18:27:03 2018 -0300 @@ -102,22 +102,6 @@ oom_fatal (); return (ensure_mask (ret, TYPE_SHIFT)); -} - -#elif defined (QP_PLATFORM_OS2) -# define INCL_DOSMISC -# define INCL_DOSMEMMGR - #include <os2.h> - -static inline void* -alloc_npages (unsigned int n, unsigned int ps) -{ - void *ret = nullptr; - if (DosAllocMem (&ret, ps * n, - PAG_COMMIT | PAG_READ | PAG_WRITE) != 0) - oom_fatal (); - - return (ensure_mask (ret, TYPE_SHIFT)); } #endif diff -r 61350b8ffc08 -r a7a40690d92b utils/chmask.h --- a/utils/chmask.h Tue Jun 12 16:43:54 2018 -0300 +++ b/utils/chmask.h Tue Jun 12 18:27:03 2018 -0300 @@ -19,14 +19,14 @@ { this->reset (); for (; *s != '\0'; ++s) - this->set (*s); + this->set ((uint8_t)*s); } chmask (const char *s, int n) { this->reset (); for (int i = 0; i < n; ++i) - this->set (s[i]); + this->set ((uint8_t)s[i]); } void reset ()