summaryrefslogtreecommitdiff
path: root/pjlib-util/src
diff options
context:
space:
mode:
Diffstat (limited to 'pjlib-util/src')
-rw-r--r--pjlib-util/src/pjlib-util-test/test.c2
-rw-r--r--pjlib-util/src/pjlib-util/scanner.c65
-rw-r--r--pjlib-util/src/pjlib-util/scanner_cis_bitwise.c68
-rw-r--r--pjlib-util/src/pjlib-util/scanner_cis_uint.c43
-rw-r--r--pjlib-util/src/pjlib-util/xml.c2
5 files changed, 133 insertions, 47 deletions
diff --git a/pjlib-util/src/pjlib-util-test/test.c b/pjlib-util/src/pjlib-util-test/test.c
index 991c1c39..ca1a140f 100644
--- a/pjlib-util/src/pjlib-util-test/test.c
+++ b/pjlib-util/src/pjlib-util-test/test.c
@@ -74,7 +74,7 @@ int test_main(void)
PJ_TRY {
return test_inner();
}
- PJ_DEFAULT {
+ PJ_CATCH_ANY {
int id = PJ_GET_EXCEPTION();
PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
id, pj_exception_id_name(id)));
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);
diff --git a/pjlib-util/src/pjlib-util/scanner_cis_bitwise.c b/pjlib-util/src/pjlib-util/scanner_cis_bitwise.c
new file mode 100644
index 00000000..7ff758c9
--- /dev/null
+++ b/pjlib-util/src/pjlib-util/scanner_cis_bitwise.c
@@ -0,0 +1,68 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * THIS FILE IS INCLUDED BY scanner.c.
+ * DO NOT COMPILE THIS FILE ALONE!
+ */
+
+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)
+{
+ 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;
+}
+
+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;
+}
+
diff --git a/pjlib-util/src/pjlib-util/scanner_cis_uint.c b/pjlib-util/src/pjlib-util/scanner_cis_uint.c
new file mode 100644
index 00000000..46486c6b
--- /dev/null
+++ b/pjlib-util/src/pjlib-util/scanner_cis_uint.c
@@ -0,0 +1,43 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * THIS FILE IS INCLUDED BY scanner.c.
+ * DO NOT COMPILE THIS FILE ALONE!
+ */
+
+
+PJ_DEF(void) pj_cis_buf_init( pj_cis_buf_t *cis_buf)
+{
+ /* Do nothing. */
+}
+
+PJ_DEF(pj_status_t) pj_cis_init(pj_cis_buf_t *cis_buf, pj_cis_t *cis)
+{
+ pj_memset(cis->cis_buf, 0, sizeof(cis->cis_buf));
+ return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pj_cis_dup( pj_cis_t *new_cis, pj_cis_t *existing)
+{
+ pj_memcpy(new_cis, existing, sizeof(pj_cis_t));
+ return PJ_SUCCESS;
+}
+
+
diff --git a/pjlib-util/src/pjlib-util/xml.c b/pjlib-util/src/pjlib-util/xml.c
index 140c64c7..35ec96c5 100644
--- a/pjlib-util/src/pjlib-util/xml.c
+++ b/pjlib-util/src/pjlib-util/xml.c
@@ -171,7 +171,7 @@ PJ_DEF(pj_xml_node*) pj_xml_parse( pj_pool_t *pool, char *msg, pj_size_t len)
PJ_TRY {
node = xml_parse_node(pool, &scanner);
}
- PJ_DEFAULT {
+ PJ_CATCH_ANY {
PJ_LOG(4,(THIS_FILE, "Syntax error parsing XML in line %d column %d",
scanner.line, scanner.col));
}