diff options
author | Benny Prijono <bennylp@teluu.com> | 2005-11-21 17:06:21 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2005-11-21 17:06:21 +0000 |
commit | c8974baa51aad3cb810611027e4f03ebf509f740 (patch) | |
tree | 0666e56081169be7dfa54bc414454ffc2d4e33eb /pjlib-util/src/pjlib-util/scanner.c | |
parent | 5721450040bd1b09af00123679577ff190da006b (diff) |
Scanner optimization and added cis_uint backend
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@73 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/src/pjlib-util/scanner.c')
-rw-r--r-- | pjlib-util/src/pjlib-util/scanner.c | 65 |
1 files changed, 20 insertions, 45 deletions
diff --git a/pjlib-util/src/pjlib-util/scanner.c b/pjlib-util/src/pjlib-util/scanner.c index 3a19e9fd..77d2db03 100644 --- a/pjlib-util/src/pjlib-util/scanner.c +++ b/pjlib-util/src/pjlib-util/scanner.c @@ -21,63 +21,31 @@ #include <pj/except.h> #include <pj/os.h> #include <pj/errno.h> +#include <pj/assert.h> #define PJ_SCAN_IS_SPACE(c) ((c)==' ' || (c)=='\t') #define PJ_SCAN_IS_NEWLINE(c) ((c)=='\r' || (c)=='\n') #define PJ_SCAN_CHECK_EOF(s) (s != end) -static void pj_scan_syntax_err(pj_scanner *scanner) -{ - (*scanner->callback)(scanner); -} +#if defined(PJ_SCANNER_USE_BITWISE) && PJ_SCANNER_USE_BITWISE != 0 +# include "scanner_cis_bitwise.c" +#else +# include "scanner_cis_uint.c" +#endif -PJ_DEF(void) pj_cis_buf_init( pj_cis_buf_t *cis_buf) -{ - pj_memset(cis_buf->cis_buf, 0, sizeof(cis_buf->cis_buf)); - cis_buf->use_mask = 0; -} -PJ_DEF(pj_status_t) pj_cis_init(pj_cis_buf_t *cis_buf, pj_cis_t *cis) +static void pj_scan_syntax_err(pj_scanner *scanner) { - unsigned i; - - cis->cis_buf = cis_buf->cis_buf; - - for (i=0; i<PJ_CIS_MAX_INDEX; ++i) { - if ((cis_buf->use_mask & (1 << i)) == 0) { - cis->cis_id = i; - cis_buf->use_mask |= (1 << i); - return PJ_SUCCESS; - } - } - - cis->cis_id = PJ_CIS_MAX_INDEX; - return PJ_ETOOMANY; + (*scanner->callback)(scanner); } -PJ_DEF(pj_status_t) pj_cis_dup( pj_cis_t *new_cis, pj_cis_t *existing) -{ - pj_status_t status; - unsigned i; - - /* Warning: typecasting here! */ - status = pj_cis_init((pj_cis_buf_t*)existing->cis_buf, new_cis); - if (status != PJ_SUCCESS) - return status; - - for (i=0; i<256; ++i) { - if (PJ_CIS_ISSET(existing, i)) - PJ_CIS_SET(new_cis, i); - else - PJ_CIS_CLR(new_cis, i); - } - - return PJ_SUCCESS; -} PJ_DEF(void) pj_cis_add_range(pj_cis_t *cis, int cstart, int cend) { + /* Can not set zero. This is the requirement of the parser. */ + pj_assert(cstart > 0); + while (cstart != cend) { PJ_CIS_SET(cis, cstart); ++cstart; @@ -122,7 +90,8 @@ PJ_DEF(void) pj_cis_del_str( pj_cis_t *cis, const char *str) PJ_DEF(void) pj_cis_invert( pj_cis_t *cis ) { unsigned i; - for (i=0; i<256; ++i) { + /* Can not set zero. This is the requirement of the parser. */ + for (i=1; i<256; ++i) { if (PJ_CIS_ISSET(cis,i)) PJ_CIS_CLR(cis,i); else @@ -284,6 +253,8 @@ PJ_DEF(void) pj_scan_get( pj_scanner *scanner, PJ_CHECK_STACK(); + pj_assert(pj_cis_match(spec,0)==0); + if (pj_scan_is_eof(scanner) || !pj_cis_match(spec, *s)) { pj_scan_syntax_err(scanner); return; @@ -291,7 +262,11 @@ PJ_DEF(void) pj_scan_get( pj_scanner *scanner, do { ++s; - } while (PJ_SCAN_CHECK_EOF(s) && pj_cis_match(spec, *s)); + } while (pj_cis_match(spec, *s)); + /* No need to check EOF here (PJ_SCAN_CHECK_EOF(s)) because + * buffer is NULL terminated and pj_cis_match(spec,0) should be + * false. + */ pj_strset3(out, scanner->curptr, s); |