From 78b284446eddac410ad0d12429877124fd277531 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Sat, 6 Jan 2018 18:14:58 +0100 Subject: [PATCH] SSE implementation improvement --- CODE_OF_CONDUCT.md | 1085 +---------- CONTRIBUTING.md | 970 +--------- configure | 8 +- examples/IR/ir_web.cpp | 89 +- examples/WiAuth/wi_auth.cpp | 7 +- include/ulib/base/base.h | 19 +- include/ulib/examples/wi_auth_declaration.h | 2 +- include/ulib/file.h | 12 +- include/ulib/net/server/server.h | 148 ++ include/ulib/string.h | 20 +- include/ulib/utility/uhttp.h | 58 +- m4/ac_compilation_options.m4 | 8 +- src/ulib/net/server/plugin/mod_nocat.cpp | 4 +- .../net/server/plugin/usp/usp_translator.cpp | 139 +- src/ulib/net/server/server.cpp | 369 +++- src/ulib/notifier.cpp | 5 +- src/ulib/process.cpp | 11 +- src/ulib/string.cpp | 32 +- src/ulib/utility/uhttp.cpp | 208 ++- tests/examples/sse_example/get_ticker.usp | 31 +- tests/examples/sse_example/get_ticker1.usp | 2 + tests/examples/sse_example/index.html | 1 - tests/examples/sse_example/index1.html | 24 + tests/examples/sse_example/jquery.min.js | 4 - tests/examples/sse_example/set_ticker.usp | 6 + tests/examples/web_server.sh | 10 +- tests/examples/web_server_proxy.test | 9 + tests/ulib/inp/json/fail1.json | 1 - tests/ulib/inp/json/fail18.json | 1 - tests/ulib/inp/json/fail2.json | 1 - tests/ulib/inp/json/fail3.json | 1 - tests/ulib/inp/json/fail4.json | 1 - tests/ulib/inp/json/fail5.json | 1 - tests/ulib/inp/json/fail6.json | 1 - tests/ulib/inp/json/fail7.json | 1 - tests/ulib/inp/json/fail8.json | 1 - tests/ulib/inp/json/fail9.json | 1 - tests/ulib/inp/json/pass1.json | 58 - tests/ulib/inp/json/pass2.json | 1 - tests/ulib/inp/json/pass3.json | 6 - tests/ulib/test_bison.yy | 131 -- tests/ulib/test_bison_flexer.cc | 1563 ---------------- tests/ulib/test_bison_flexer.ll | 53 - tests/ulib/test_flexer.cc | 1656 ----------------- tests/ulib/test_flexer.ll | 89 - tests/ulib/test_vector.cpp | 103 +- tests/ulib/vector.test | 6 +- 47 files changed, 1129 insertions(+), 5828 deletions(-) create mode 100644 tests/examples/sse_example/get_ticker1.usp create mode 100644 tests/examples/sse_example/index1.html delete mode 100644 tests/examples/sse_example/jquery.min.js create mode 100644 tests/examples/sse_example/set_ticker.usp delete mode 100644 tests/ulib/inp/json/fail1.json delete mode 100644 tests/ulib/inp/json/fail18.json delete mode 100644 tests/ulib/inp/json/fail2.json delete mode 100644 tests/ulib/inp/json/fail3.json delete mode 100644 tests/ulib/inp/json/fail4.json delete mode 100644 tests/ulib/inp/json/fail5.json delete mode 100644 tests/ulib/inp/json/fail6.json delete mode 100644 tests/ulib/inp/json/fail7.json delete mode 100644 tests/ulib/inp/json/fail8.json delete mode 100644 tests/ulib/inp/json/fail9.json delete mode 100644 tests/ulib/inp/json/pass1.json delete mode 100644 tests/ulib/inp/json/pass2.json delete mode 100644 tests/ulib/inp/json/pass3.json delete mode 100644 tests/ulib/test_bison.yy delete mode 100644 tests/ulib/test_bison_flexer.cc delete mode 100644 tests/ulib/test_bison_flexer.ll delete mode 100644 tests/ulib/test_flexer.cc delete mode 100644 tests/ulib/test_flexer.ll diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d750667d..cb287e1d 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,1011 +1,74 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ULib/CODE_OF_CONDUCT.md at master · stefanocasazza/ULib · GitHub - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content -
- - - - - - - - - - -
- -
- -
-
- - - -
-
-
- - - - - - - - -
-
- - - Permalink - - - - - - - -
- - - 84e39e9 - - Sep 4, 2017 - - - -
- - -
- - -
- - -
-
-
- -
- Raw - Blame - History -
- - - - -
- -
- 47 lines (28 sloc) - - 3.15 KB -
-
- - -
-

Contributor Covenant Code of Conduct

-

Our Pledge

-

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

-

Our Standards

-

Examples of behavior that contributes to creating a positive environment include:

-
    -
  • Using welcoming and inclusive language
  • -
  • Being respectful of differing viewpoints and experiences
  • -
  • Gracefully accepting constructive criticism
  • -
  • Focusing on what is best for the community
  • -
  • Showing empathy towards other community members
  • -
-

Examples of unacceptable behavior by participants include:

-
    -
  • The use of sexualized language or imagery and unwelcome sexual attention or advances
  • -
  • Trolling, insulting/derogatory comments, and personal or political attacks
  • -
  • Public or private harassment
  • -
  • Publishing others' private information, such as a physical or electronic address, without explicit permission
  • -
  • Other conduct which could reasonably be considered inappropriate in a professional setting
  • -
-

Our Responsibilities

-

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

-

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

-

Scope

-

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

-

Enforcement

-

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at stefano,casazza@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

-

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

-

Attribution

-

This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4

-
-
- -
- - - - -
- -
- -
-
- -
- - - - - - -
- - - You can't perform that action at this time. -
- - - - - - - - - - -
- - You signed in with another tab or window. Reload to refresh your session. - You signed out in another tab or window. Reload to refresh your session. -
- - - - - - +Contributor Covenant Code of Conduct + +Our Pledge + + In the interest of fostering an open and welcoming environment, we as + contributors and maintainers pledge to making participation in our + project and our community a harassment-free experience for everyone, + regardless of age, body size, disability, ethnicity, gender identity + and expression, level of experience, nationality, personal appearance, + race, religion, or sexual identity and orientation. + +Our Standards + + Examples of behavior that contributes to creating a positive + environment include: + * Using welcoming and inclusive language + * Being respectful of differing viewpoints and experiences + * Gracefully accepting constructive criticism + * Focusing on what is best for the community + * Showing empathy towards other community members + + Examples of unacceptable behavior by participants include: + * The use of sexualized language or imagery and unwelcome sexual + attention or advances + * Trolling, insulting/derogatory comments, and personal or political + attacks + * Public or private harassment + * Publishing others' private information, such as a physical or + electronic address, without explicit permission + * Other conduct which could reasonably be considered inappropriate in + a professional setting + +Our Responsibilities + + Project maintainers are responsible for clarifying the standards of + acceptable behavior and are expected to take appropriate and fair + corrective action in response to any instances of unacceptable + behavior. + + Project maintainers have the right and responsibility to remove, edit, + or reject comments, commits, code, wiki edits, issues, and other + contributions that are not aligned to this Code of Conduct, or to ban + temporarily or permanently any contributor for other behaviors that + they deem inappropriate, threatening, offensive, or harmful. + +Scope + + This Code of Conduct applies both within project spaces and in public + spaces when an individual is representing the project or its community. + Examples of representing a project or community include using an + official project e-mail address, posting via an official social media + account, or acting as an appointed representative at an online or + offline event. Representation of a project may be further defined and + clarified by project maintainers. + +Enforcement + + Instances of abusive, harassing, or otherwise unacceptable behavior may + be reported by contacting the project team at [stefano](stefano.casazza@gmail.com). + The project team will review and investigate all complaints, and will + respond in a way that it deems appropriate to the circumstances. + The project team is obligated to maintain confidentiality with regard to + the reporter of an incident. Further details of specific enforcement + policies may be posted separately. + + Project maintainers who do not follow or enforce the Code of Conduct in + good faith may face temporary or permanent repercussions as determined + by other members of the project's leadership. + +Attribution + + This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org/), + version 1.4, available at + [http://contributor-covenant.org/version/1/4](http://contributor-covenant.org/version/1/4/) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9cb907e6..b5f1a888 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,965 +1,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ULib/CONTRIBUTING.md at master · stefanocasazza/ULib · GitHub - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Skip to content -
- - - - - - - - - - -
- -
- -
-
- - - -
-
-
- - - - - - - - -
-
- - - Permalink - - - - - - - -
- Fetching contributors… -
- -
- - Cannot retrieve contributors at this time -
-
- -
-
-
- -
- Raw - Blame - History -
- - - - -
- -
- 6 lines (5 sloc) - - 274 Bytes -
-
- - -
-
    -
  1. Fork it ( http://github.com//ULib/fork )
  2. -
  3. Create your feature branch (git checkout -b my-new-feature)
  4. -
  5. Commit your changes (git commit -am 'Add some feature')
  6. -
  7. Push to the branch (git push origin my-new-feature)
  8. -
  9. Create new Pull Request
  10. -
-
-
- -
- - - - -
- -
- -
-
- -
- - - - - - -
- - - You can't perform that action at this time. -
- - - - - - - - - - -
- - You signed in with another tab or window. Reload to refresh your session. - You signed out in another tab or window. Reload to refresh your session. -
- - - - - - +1. Fork it ( [http://github.com](http://github.com)/ULib/fork ) +2. Create your feature branch (git checkout -b my-new-feature) +3. Commit your changes (git commit -am 'Add some feature') +4. Push to the branch (git push origin my-new-feature) +5. Create new Pull Request diff --git a/configure b/configure index d001ba04..f76c2d31 100755 --- a/configure +++ b/configure @@ -1805,7 +1805,7 @@ Optional Features: --enable-GSDS enable GDB Stack Dump Support [default=no] --enable-HCRS enable Cache Request Support [default=no] --enable-HPRS enable Homogeneous Pipeline Request Support [default=no] - --enable-SSE enable Server-Sent Events Support [default=yes] + --enable-SSE enable Server-Sent Events Support [default=no] --enable-http2 enable HTTP/2 support [default=no] --enable-check-time enable server check time between request for parallelization [default=no] --enable-classic enable server classic model support [default=no] @@ -28336,11 +28336,7 @@ if test "${enable_SSE+set}" = set; then : fi if test -z "$enable_SSE"; then - if test "$USP_FLAGS" = "-DAS_cpoll_cppsp_DO"; then - enable_SSE="no" - else - enable_SSE="yes" - fi + enable_SSE="no" fi if test "$enable_SSE" = "yes"; then diff --git a/examples/IR/ir_web.cpp b/examples/IR/ir_web.cpp index 61f15312..f4636e89 100644 --- a/examples/IR/ir_web.cpp +++ b/examples/IR/ir_web.cpp @@ -3,57 +3,44 @@ #include #include "ir_session.h" - #include - - #define IR_SESSION (*(IRDataSession*)UHTTP::data_session) - - static IR* ir; - static Query* query; - static UCrono* crono; - static UString* footer; - - static void usp_init_ir_web() - { - U_TRACE(5, "::usp_init_ir_web()") - - U_INTERNAL_ASSERT_EQUALS(ir, U_NULLPTR) - U_INTERNAL_ASSERT_EQUALS(query, U_NULLPTR) - U_INTERNAL_ASSERT_EQUALS(crono, U_NULLPTR) - U_INTERNAL_ASSERT_EQUALS(footer, U_NULLPTR) - - U_NEW(IR, ir, IR); - U_NEW(Query, query, Query); - U_NEW(UCrono, crono, UCrono); - U_NEW(UString, footer, UString(200U)); - - ir->loadFileConfig(); - - if (ir->openCDB(false) == false) - { - U_ERROR("usp_init() of servlet ir_web failed"); - } - - footer->snprintf(U_CONSTANT_TO_PARAM("ver. %.*s, with %u documents and %u words."), U_CONSTANT_TO_TRACE(ULIB_VERSION), cdb_names->size(), cdb_words->size()); - - U_NEW(IRDataSession, UHTTP::data_session, IRDataSession); - - UHTTP::initSession(); - } - - static void usp_end_ir_web() - { - U_TRACE(5, "::usp_end_ir_web()") - - U_INTERNAL_ASSERT_POINTER(ir) - U_INTERNAL_ASSERT_POINTER(query) - U_INTERNAL_ASSERT_POINTER(crono) - U_INTERNAL_ASSERT_POINTER(footer) - - delete ir; - delete query; - delete crono; - delete footer; - } +#include +#define IR_SESSION (*(IRDataSession*)UHTTP::data_session) +static IR* ir; +static Query* query; +static UCrono* crono; +static UString* footer; +static void usp_init_ir_web() +{ + U_TRACE(5, "::usp_init_ir_web()") + U_INTERNAL_ASSERT_EQUALS(ir, U_NULLPTR) + U_INTERNAL_ASSERT_EQUALS(query, U_NULLPTR) + U_INTERNAL_ASSERT_EQUALS(crono, U_NULLPTR) + U_INTERNAL_ASSERT_EQUALS(footer, U_NULLPTR) + U_NEW(IR, ir, IR); + U_NEW(Query, query, Query); + U_NEW(UCrono, crono, UCrono); + U_NEW(UString, footer, UString(200U)); + ir->loadFileConfig(); + if (ir->openCDB(false) == false) + { + U_ERROR("usp_init() of servlet ir_web failed"); + } + footer->snprintf(U_CONSTANT_TO_PARAM("ver. %.*s, with %u documents and %u words."), U_CONSTANT_TO_TRACE(ULIB_VERSION), cdb_names->size(), cdb_words->size()); + U_NEW(IRDataSession, UHTTP::data_session, IRDataSession); + UHTTP::initSession(); +} +static void usp_end_ir_web() +{ + U_TRACE(5, "::usp_end_ir_web()") + U_INTERNAL_ASSERT_POINTER(ir) + U_INTERNAL_ASSERT_POINTER(query) + U_INTERNAL_ASSERT_POINTER(crono) + U_INTERNAL_ASSERT_POINTER(footer) + delete ir; + delete query; + delete crono; + delete footer; +} extern "C" { extern U_EXPORT void runDynamicPage_ir_web(int param); diff --git a/examples/WiAuth/wi_auth.cpp b/examples/WiAuth/wi_auth.cpp index a9497a09..d0d038bd 100644 --- a/examples/WiAuth/wi_auth.cpp +++ b/examples/WiAuth/wi_auth.cpp @@ -3,10 +3,9 @@ #include static void usp_end_wi_auth(); - static void usp_init_wi_auth(); - static void usp_sighup_wi_auth(); - - #include +static void usp_init_wi_auth(); +static void usp_sighup_wi_auth(); +#include extern "C" { extern U_EXPORT void runDynamicPage_wi_auth(int param); diff --git a/include/ulib/base/base.h b/include/ulib/base/base.h index bd385b69..60cf2d5d 100644 --- a/include/ulib/base/base.h +++ b/include/ulib/base/base.h @@ -93,19 +93,19 @@ U_DO_PRAGMA(message ("Sorry I was compiled without thread enabled so I cannot us # endif #endif #if defined(U_THROTTLING_SUPPORT) && !defined(U_HTTP2_DISABLE) -# undef U_THROTTLING_SUPPORT +# undef U_THROTTLING_SUPPORT U_DO_PRAGMA(message ("Sorry I was compiled with http2 enabled so I cannot support bandwidth throttling")) #endif #if defined(U_SERVER_CHECK_TIME_BETWEEN_REQUEST) && !defined(U_HTTP2_DISABLE) -# undef U_SERVER_CHECK_TIME_BETWEEN_REQUEST +# undef U_SERVER_CHECK_TIME_BETWEEN_REQUEST U_DO_PRAGMA(message ("Sorry I was compiled with http2 enabled so I cannot support check time between request")) #endif #if !defined(U_CACHE_REQUEST_DISABLE) && !defined(U_HTTP2_DISABLE) -# define U_CACHE_REQUEST_DISABLE +# define U_CACHE_REQUEST_DISABLE U_DO_PRAGMA(message ("Sorry I was compiled with http2 enabled so I cannot support cache request")) #endif #if defined(U_HTTP_INOTIFY_SUPPORT) && defined(U_SERVER_CAPTIVE_PORTAL) -# undef U_HTTP_INOTIFY_SUPPORT +# undef U_HTTP_INOTIFY_SUPPORT U_DO_PRAGMA(message ("Sorry I was compiled with server captive portal mode enabled so I cannot support http inotify")) #endif #if defined(HAVE_CXX17) && defined(__GNUC__) && !defined(HAVE_CONFIG_H) @@ -114,6 +114,15 @@ U_DO_PRAGMA(message ("ULib is configured with C++17 support, so you must use the #if defined(USE_HARDWARE_CRC32) && defined(__GNUC__) && !defined(HAVE_CONFIG_H) /* The built-in functions __builtin_ia32_crc32 are available when -mcrc32 is used */ U_DO_PRAGMA(message ("ULib is configured with crc32 intrinsics support, so you must use the -mcrc32 g++ option for compilation")) #endif +#ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) +# ifndef U_LINUX +# undef U_SSE_ENABLE +U_DO_PRAGMA(message ("Sorry I was not compiled on Linux so I cannot use SSE")) +# elif !defined(ENABLE_THREAD) +# undef U_SSE_ENABLE +U_DO_PRAGMA(message ("Sorry I was compiled without thread enabled so I cannot use SSE")) +# endif +#endif #include #include @@ -247,7 +256,7 @@ extern U_EXPORT uint32_t u_buffer_len; /* assert that u_buffer is busy if u_buff /* Startup */ -extern U_EXPORT pid_t u_pid; +extern U_EXPORT pid_t u_pid; extern U_EXPORT char u_pid_str[10]; extern U_EXPORT uint32_t u_pid_str_len; extern U_EXPORT uint32_t u_progname_len; diff --git a/include/ulib/examples/wi_auth_declaration.h b/include/ulib/examples/wi_auth_declaration.h index d3d04c1a..698d88bd 100644 --- a/include/ulib/examples/wi_auth_declaration.h +++ b/include/ulib/examples/wi_auth_declaration.h @@ -5711,7 +5711,7 @@ loop: (void) nodog_rec->sendRequestToNodog(U_CONSTANT_TO_PARAM("check"), 0); { db_nodog->callForAllEntryWithVector(WiAuthNodog::checkAccessPoint); - if ((U_SRV_CNT_USR4++ % 10) == 0) resync(); + if ((U_SRV_CNT_WIAUTH++ % 10) == 0) resync(); } USSIPlugIn::setAlternativeResponse(); diff --git a/include/ulib/file.h b/include/ulib/file.h index 2b15dff8..c807f42e 100644 --- a/include/ulib/file.h +++ b/include/ulib/file.h @@ -40,13 +40,9 @@ // File-permission-bit symbols -#define U_PERM__rw_r__r__ 0644 -#define U_PERM__r________ 0400 -#define U_PERM__r__r__r__ 0444 -#define U_PERM__r_xr_xr_x 0555 - -#define PERM_FILE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) // rw_rw_r__ -#define PERM_DIRECTORY S_IRWXU // rwx +#define PERM_FILE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) // rw_rw_r__ +#define PERM_FIFO (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) // rw_rw_rw_ +#define PERM_DIRECTORY S_IRWXU // rwx // NB: the UString pathname maybe not writeable so path_relativ[path_relativ_len] maybe != '\0' (not null-terminate)... @@ -980,7 +976,7 @@ public: // make a FIFO special file (a named pipe) - static bool mkfifo(const char* _pathname, mode_t mode = S_IRUSR | S_IWUSR) + static bool mkfifo(const char* _pathname, mode_t mode = PERM_FIFO) { U_TRACE(1, "UFile::mkfifo(%S,%d)", _pathname, mode) diff --git a/include/ulib/net/server/server.h b/include/ulib/net/server/server.h index 11757e32..88fe768a 100644 --- a/include/ulib/net/server/server.h +++ b/include/ulib/net/server/server.h @@ -105,6 +105,8 @@ class USSLSocket; class USSIPlugIn; class UWebSocket; class USocketExt; +class USSEClient; +class USSEThread; class Application; class UTimeThread; class UFileConfig; @@ -321,6 +323,13 @@ public: sem_t lock_ocsp_staple; # endif // ------------------------------------------------------------------------------ +# endif + // ------------------------------------------------------------------------------ +# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + sem_t lock_sse; +# ifdef USE_LIBSSL + sem_t lock_sse_ssl; +# endif # endif // ------------------------------------------------------------------------------ # if defined(U_LINUX) && defined(ENABLE_THREAD) @@ -352,6 +361,10 @@ public: #define U_SRV_CNT_USR7 UServer_Base::ptr_shared_data->cnt_usr7 #define U_SRV_CNT_USR8 UServer_Base::ptr_shared_data->cnt_usr8 #define U_SRV_CNT_USR9 UServer_Base::ptr_shared_data->cnt_usr9 +#define U_SRV_CNT_NOCAT UServer_Base::ptr_shared_data->cnt_usr7 +#define U_SRV_CNT_WIAUTH UServer_Base::ptr_shared_data->cnt_usr7 +#define U_SRV_SSE_CNT1 UServer_Base::ptr_shared_data->cnt_usr8 +#define U_SRV_SSE_CNT2 UServer_Base::ptr_shared_data->cnt_usr9 #define U_SRV_MY_LOAD UServer_Base::ptr_shared_data->my_load #define U_SRV_FLAG_SIGTERM UServer_Base::ptr_shared_data->flag_sigterm #define U_SRV_LEN_OCSP_STAPLE UServer_Base::ptr_shared_data->len_ocsp_staple @@ -362,6 +375,8 @@ public: #define U_SRV_CNT_PARALLELIZATION UServer_Base::ptr_shared_data->cnt_parallelization #define U_SRV_LOCK_USER1 &(UServer_Base::ptr_shared_data->lock_user1) #define U_SRV_LOCK_USER2 &(UServer_Base::ptr_shared_data->lock_user2) +#define U_SRV_LOCK_SSE &(UServer_Base::ptr_shared_data->lock_sse) +#define U_SRV_LOCK_SSE_SSL &(UServer_Base::ptr_shared_data->lock_sse_ssl) #define U_SRV_LOCK_THROTTLING &(UServer_Base::ptr_shared_data->lock_throttling) #define U_SRV_LOCK_RDB_SERVER &(UServer_Base::ptr_shared_data->lock_rdb_server) #define U_SRV_LOCK_SSL_SESSION &(UServer_Base::ptr_shared_data->lock_ssl_session) @@ -637,6 +652,109 @@ public: } #endif +#ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + static ULock* lock_sse; +# ifdef USE_LIBSSL + static ULock* lock_sse_ssl; +# endif + + static void setLockSSE() + { + U_TRACE_NO_PARAM(0, "UServer_Base::setLockSSE()") + +# ifdef USE_LIBSSL + if (bssl) + { + U_INTERNAL_ASSERT_EQUALS(lock_sse_ssl, U_NULLPTR) + + U_NEW(ULock, lock_sse_ssl, ULock); + + lock_sse_ssl->init(&(ptr_shared_data->lock_sse_ssl)); + } + else +# endif + { + U_INTERNAL_ASSERT_EQUALS(lock_sse, U_NULLPTR) + + U_NEW(ULock, lock_sse, ULock); + + lock_sse->init(&(ptr_shared_data->lock_sse)); + } + } + + static void lockSSE() + { + U_TRACE_NO_PARAM(0, "UServer_Base::lockSSE()") + +# ifdef USE_LIBSSL + if (bssl) lock_sse_ssl->lock(); + else +# endif + lock_sse->lock(); + } + + static void unlockSSE() + { + U_TRACE_NO_PARAM(0, "UServer_Base::unlockSSE()") + +# ifdef USE_LIBSSL + if (bssl) lock_sse_ssl->unlock(); + else +# endif + lock_sse->unlock(); + } + + static UString printSSE(uint32_t id, const UString& data, UString* pevent = U_NULLPTR) + { + U_TRACE(0, "UServer_Base::printSSE(%u,%V,%p)", id, data.rep, pevent) + + U_ASSERT_EQUALS(u_find(U_STRING_TO_PARAM(data),"\n",1), U_NULLPTR) + + UString buffer(U_CAPACITY); + + if (pevent == U_NULLPTR) buffer.snprintf(U_CONSTANT_TO_PARAM("id:%u\ndata:%v\n\n"), id, data.rep); + else buffer.snprintf(U_CONSTANT_TO_PARAM("id:%u\nevent:%v\ndata:%v\n\n"), id, pevent->rep, data.rep); + + U_RETURN_STRING(buffer); + } + + static void eventSSE(const char* format, uint32_t fmt_size, ...) + { + U_TRACE(0, "UServer_Base::eventSSE(%.*S,%u)", fmt_size, format, fmt_size) + + U_INTERNAL_ASSERT_POINTER(format) + U_INTERNAL_ASSERT_DIFFERS(sse_event_fd, -1) + + uint32_t len; + char buffer[4096]; + + va_list argp; + va_start(argp, fmt_size); + + len = u__vsnprintf(buffer, sizeof(buffer), format, fmt_size, argp); + + va_end(argp); + + lockSSE(); + + (void) U_SYSCALL(write, "%u,%S,%u", sse_event_fd, buffer, len); + } + + static void sendToAllSSE(const UString& data) + { + U_TRACE(0, "UServer_Base::sendToAllSSE(%V)", data.rep) + + eventSSE(U_CONSTANT_TO_PARAM("*=%v\n"), data.rep); + } + + static void sendToAllExceptSSE(const UString& data) + { + U_TRACE(0, "UServer_Base::sendToAllExceptSSE(%V)", data.rep) + + eventSSE(U_CONSTANT_TO_PARAM("%v-%v=%v\n"), (sse_event ? sse_event : str_asterisk)->rep, sse_id->rep, data.rep); + } +#endif + // DEBUG #if defined(DEBUG) && defined(U_STDCPP_ENABLE) @@ -837,6 +955,34 @@ protected: static bool checkHitStats(const char* key, uint32_t key_len, uint32_t interval, uint32_t count); #endif +#ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + struct ucmsghdr { + size_t cmsg_len; /* Length data in cmsg_data + length of cmsghdr struct */ + int cmsg_level; /* Originating protocol. */ + int cmsg_type; /* Protocol specific type. */ + int cmsg_data; /* Ancillary data. */ + }; + + static UThread* pthread_sse; + static UString* sse_id; + static UString* sse_event; + static struct msghdr msg; + static struct iovec iov[1]; + static struct ucmsghdr cmsg; + static UString* str_asterisk; + static uint32_t sse_fifo_pos; + static UVector* sse_vclient; + static char sse_fifo_name[256], iovbuf[1]; + static int sse_event_fd, sse_socketpair[2]; + + static void setFIFOForSSE(const UString& id) + { + U_TRACE(0, "UServer_Base::setFIFOForSSE(%V)", id.rep) + + (void) u__snprintf(sse_fifo_name+sse_fifo_pos, 256-sse_fifo_pos, U_CONSTANT_TO_PARAM("%v"), id.rep); + } +#endif + UServer_Base(UFileConfig* pcfg = U_NULLPTR); virtual ~UServer_Base(); @@ -976,6 +1122,8 @@ private: friend class USSIPlugIn; friend class UWebSocket; friend class USocketExt; + friend class USSEClient; + friend class USSEThread; friend class Application; friend class UTimeThread; friend class UHttpPlugIn; diff --git a/include/ulib/string.h b/include/ulib/string.h index 692d40b6..c10c3f27 100644 --- a/include/ulib/string.h +++ b/include/ulib/string.h @@ -1840,28 +1840,10 @@ public: // The `find' function searches string for a specified string (possibly a single character) and returns // its starting position. You can supply the parameter pos to specify the position where search must begin + uint32_t find(unsigned char c, uint32_t pos = 0, uint32_t how_much = U_NOT_FOUND) const __pure; uint32_t find(const char* s, uint32_t pos, uint32_t s_len, uint32_t how_much = U_NOT_FOUND) const __pure; uint32_t find(const UString& str, uint32_t pos = 0, uint32_t how_much = U_NOT_FOUND) const { return find(str.data(), pos, str.size(), how_much); } - uint32_t find(unsigned char c, uint32_t pos = 0) const - { - U_TRACE(0, "UString::find(%C,%u)", c, pos) - - uint32_t sz = size(), - ret = U_NOT_FOUND; - - if (pos < sz) - { - const char* str = rep->str; - - void* p = (void*) memchr(str + pos, c, sz - pos); - - if (p) ret = (const char*)p - str; - } - - U_RETURN(ret); - } - // The `rfind' function searches from end to beginning string for a specified string (possibly a single character) // and returns its starting position. You can supply the parameter pos to specify the position where search must begin diff --git a/include/ulib/utility/uhttp.h b/include/ulib/utility/uhttp.h index d978f8dc..dc4344e8 100644 --- a/include/ulib/utility/uhttp.h +++ b/include/ulib/utility/uhttp.h @@ -679,55 +679,27 @@ public: } #ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) - static bool bsse; + typedef UString (*strPF)(); - static uint32_t getSSELastEventID() + static strPF sse_func; + static int sse_pipe_fd; + static const char* sse_corsbase; + + static void readSSE(int timeoutMS) __noreturn; + static void sendSSE(const UString& data) { - U_TRACE_NO_PARAM(0, "UHTTP::getSSELastEventID()") + U_TRACE(0, "UHTTP::sendSSE(%V)", data.rep) - U_INTERNAL_ASSERT(bsse) + UString buffer = UServer_Base::printSSE(U_SRV_SSE_CNT1, data, UServer_Base::sse_event); - const char* ptr = UHTTP::getHeaderValuePtr(U_CONSTANT_TO_PARAM("last-event-id"), true); + uint32_t sz = buffer.size(); - uint32_t last_event_id = (ptr ? u_atoi(ptr) : 0); - - U_RETURN(last_event_id); - } - - static void writeSSE(uint32_t id, const UString& data, const UString* pevent = U_NULLPTR) - { - U_TRACE(0, "UHTTP::writeSSE(%u,%V,%p)", id, data.rep, pevent) - - if (pevent) UClientImage_Base::wbuffer->snprintf_add(U_CONSTANT_TO_PARAM("id:%u\nevent:%v\ndata:"), id, pevent->rep); - else UClientImage_Base::wbuffer->snprintf_add(U_CONSTANT_TO_PARAM("id:%u\ndata:"), id); - - UVector vec(data, '\n'); - - UClientImage_Base::wbuffer->append(vec[0]); - - for (uint32_t i = 1, n = vec.size(); i < n; ++i) + if (USocketExt::write(UServer_Base::csocket, buffer.data(), sz, UServer_Base::timeoutMS) != (int32_t)sz) { - UClientImage_Base::wbuffer->snprintf_add(U_CONSTANT_TO_PARAM("\ndata:%v"), vec[i].rep); + UServer_Base::eventSSE(U_CONSTANT_TO_PARAM("DEL %v\n"), UServer_Base::sse_id->rep); + + UServer_Base::endNewChild(); // no return } - - UClientImage_Base::wbuffer->append(U_CONSTANT_TO_PARAM("\n\n")); - } - - static void sendSSE(uint32_t id, const UString& data, const UString* pevent = U_NULLPTR) - { - U_TRACE(0, "UHTTP::sendSSE(%u,%V,%p)", id, data.rep, pevent) - - U_INTERNAL_ASSERT(bsse) - - UClientImage_Base::wbuffer->setBuffer(U_CAPACITY); - - writeSSE(id, data, pevent); - - uint32_t sz = UClientImage_Base::wbuffer->size(); - - U_SRV_LOG_WITH_ADDR("send message (%u bytes) %#.*S to", sz, sz, UClientImage_Base::wbuffer->data()); - - if (USocketExt::write(UServer_Base::csocket, UClientImage_Base::wbuffer->data(), sz, UServer_Base::timeoutMS) != (int32_t)sz) UServer_Base::endNewChild(); // no return } #endif @@ -1399,8 +1371,6 @@ private: { U_TRACE(0, "UHTTP::checkForCompression(%u)", size) - U_INTERNAL_ASSERT_MAJOR(size, 0) - U_INTERNAL_DUMP("U_http_is_accept_gzip = %b U_http_is_accept_brotli = %b", U_http_is_accept_gzip, U_http_is_accept_brotli) if (size > U_MIN_SIZE_FOR_DEFLATE) diff --git a/m4/ac_compilation_options.m4 b/m4/ac_compilation_options.m4 index 420b8960..f98d52ec 100644 --- a/m4/ac_compilation_options.m4 +++ b/m4/ac_compilation_options.m4 @@ -211,13 +211,9 @@ AC_DEFUN([AC_COMPILATION_OPTIONS],[ AC_MSG_CHECKING(if you want to enable Server-Sent Events support) AC_ARG_ENABLE(SSE, - [ --enable-SSE enable Server-Sent Events Support [[default=yes]]]) + [ --enable-SSE enable Server-Sent Events Support [[default=no]]]) if test -z "$enable_SSE"; then - if test "$USP_FLAGS" = "-DAS_cpoll_cppsp_DO"; then - enable_SSE="no" - else - enable_SSE="yes" - fi + enable_SSE="no" fi if test "$enable_SSE" = "yes"; then AC_DEFINE(U_SSE_ENABLE, 1, [enable Server-Sent Events support]) diff --git a/src/ulib/net/server/plugin/mod_nocat.cpp b/src/ulib/net/server/plugin/mod_nocat.cpp index 7683d4f5..83e0d7e4 100644 --- a/src/ulib/net/server/plugin/mod_nocat.cpp +++ b/src/ulib/net/server/plugin/mod_nocat.cpp @@ -2309,8 +2309,8 @@ int UNoCatPlugIn::handlerFork() UString msg(300U), output(U_CAPACITY), allowed_web_hosts(U_CAPACITY); - msg.snprintf(U_CONSTANT_TO_PARAM("/start_ap?ap=%v@%v&public=%v%%3A%u&pid=%u"), label->rep, hostname->rep, IP_address_trust->rep, UServer_Base::port, U_SRV_CNT_USR9); - U_SRV_CNT_USR9 = u_pid; + msg.snprintf(U_CONSTANT_TO_PARAM("/start_ap?ap=%v@%v&public=%v%%3A%u&pid=%u"), label->rep, hostname->rep, IP_address_trust->rep, UServer_Base::port, U_SRV_CNT_NOCAT); + U_SRV_CNT_NOCAT = u_pid; for (i = 0, n = vauth_url->size(); i < n; ++i) { diff --git a/src/ulib/net/server/plugin/usp/usp_translator.cpp b/src/ulib/net/server/plugin/usp/usp_translator.cpp index daa1fe94..e7def9ed 100644 --- a/src/ulib/net/server/plugin/usp/usp_translator.cpp +++ b/src/ulib/net/server/plugin/usp/usp_translator.cpp @@ -123,7 +123,13 @@ public: if (pos != U_NOT_FOUND) { - output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\tif (%v.empty()) %v = U_STRING_FROM_CONSTANT(%.*s);\n"), id.rep, id.rep, tmp.size()-pos-2, tmp.c_pointer(pos+1)); + uint32_t sz = tmp.size()-pos-2; + const char* ptr = tmp.c_pointer(pos+1); + const char* quote = (*ptr == '"' ? "" : "\""); + + U_INTERNAL_ASSERT_MAJOR(sz, 0) + + output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\tif (%v.empty()) %v = U_STRING_FROM_CONSTANT(%s%.*s%s);\n"), id.rep, id.rep, quote, sz, ptr, quote); } # ifdef DEBUG @@ -152,8 +158,7 @@ public: * * * - * - * + * * * * @@ -249,7 +254,7 @@ public: U_INTERNAL_ASSERT(token) - declaration = UStringExt::substitute(token, '\n', U_CONSTANT_TO_PARAM("\n\t")); + declaration = token; } else if (strncmp(directive, U_CONSTANT_TO_PARAM("session")) == 0) { @@ -368,80 +373,73 @@ public: output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\t%v\n\t\n"), token.rep); } - else if (strncmp(directive, U_CONSTANT_TO_PARAM("ssecode")) == 0) // SSE code + else if (strncmp(directive, U_CONSTANT_TO_PARAM("sse")) == 0) // SSE code { - U_ASSERT(output2.empty()) + U_ASSERT(sseloop.empty()) U_ASSERT(http_header.empty()) U_INTERNAL_ASSERT_EQUALS(bfirst_pass, false) - setDirectiveItem(directive, U_CONSTANT_SIZE("ssecode")); + (void) sseloop.reserve(100U); + (void) http_header.reserve(300U + basename_sz + basename_sz); - U_INTERNAL_ASSERT(token) - - token = UStringExt::substitute(token, '\n', U_CONSTANT_TO_PARAM("\n\t\t")); - - /** - * we must insert: - * - * - */ - - (void) http_header.reserve(1000U + token.size()); - - (void) http_header.snprintf(U_CONSTANT_TO_PARAM( + (void) http_header.append(U_CONSTANT_TO_PARAM( "\n\tif (U_http_accept_len != U_CONSTANT_SIZE(\"text/event-stream\") ||" - " u_get_unalignedp64(U_http_info.accept) != U_MULTICHAR_CONSTANT64('t','e','x','t','/','e','v','e')) UHTTP::setBadRequest();" - "\n\telse" + "\n\t u_get_unalignedp64(U_http_info.accept) != U_MULTICHAR_CONSTANT64('t','e','x','t','/','e','v','e'))" "\n\t\t{" - "\n\t\tUHTTP::bsse = true;" - "\n\t\t(void) UServer_Base::csocket->shutdown(SHUT_RD);" - "\n\t\tU_INTERNAL_ASSERT_EQUALS(UClientImage_Base::wbuffer->findEndHeader(),false)" - "\n\t\tU_http_info.endHeader = 61;" - "\n\t\t(void) UClientImage_Base::wbuffer->insert(0, U_CONSTANT_TO_PARAM(\"Content-Type: text/event-stream\\r\\nCache-Control: no-cache\\r\\n\\r\\n\"));" - "\n\t\tU_http_content_type_len = 1;" - "\n\t\t%v" - "\n\t\t}"), token.rep); - } - else if (strncmp(directive, U_CONSTANT_TO_PARAM("sseloop")) == 0) // SSE loop - { - U_ASSERT(sseloop.empty()) - U_INTERNAL_ASSERT_EQUALS(bfirst_pass, false) + "\n\t\tUHTTP::setBadRequest();" + "\n\t\treturn;" + "\n\t\t}")); - setDirectiveItem(directive, U_CONSTANT_SIZE("sseloop")); + setDirectiveItem(directive, U_CONSTANT_SIZE("sse")); - U_INTERNAL_ASSERT(token) - - uint32_t sz = token.size(); - const char* data = token.data(); - - uint32_t sse_time_to_sleep = 1; - - if (*data == ':') + if (token.empty()) { - ++data; + (void) declaration.reserve(100U + basename_sz); - sse_time_to_sleep = u_strtoulp(&data); + declaration.snprintf(U_CONSTANT_TO_PARAM("\n#ifdef USE_LIBSSL\nstatic UString sse_%.*s() { return UString::getStringNull(); }\n#endif"), basename_sz, basename_ptr); - sz = token.remain(data); + (void) sseloop.append(U_CONSTANT_TO_PARAM("\n\t\tif (UHTTP::sse_func) UHTTP::readSSE(-1);")); + + http_header.snprintf(U_CONSTANT_TO_PARAM( + "\n#ifdef USE_LIBSSL" + "\n\tif (UServer_Base::bssl) UHTTP::sse_func = sse_%.*s;" + "\n\telse" + "\n#endif" + "\n\tUHTTP::sse_func = (UHTTP::strPF)(void*)1L;"), basename_sz, basename_ptr); } + else + { + const char* data = token.data(); + uint32_t sz = token.size(), sse_timeout = 1000; - char buffer[200]; + if (*data == ':') + { + ++data; - (void) vars.append(buffer, u__snprintf(buffer, sizeof(buffer), U_CONSTANT_TO_PARAM("\n\tUTimeVal sse_time_to_sleep(%u, 0L);\n"), sse_time_to_sleep)); + sse_timeout *= u_strtoulp(&data); - sseloop = UStringExt::substitute(data, sz, '\n', U_CONSTANT_TO_PARAM("\n\t")); + sz = token.remain(data); + } - (void) output2.reserve(200U + sseloop.size()); + UString sse_code = UStringExt::substitute(data, sz, '\n', U_CONSTANT_TO_PARAM("\n\t")); - output2.snprintf(U_CONSTANT_TO_PARAM( - "\n\treturn;\n\t\n" - "sseloop:" - "\n\tsse_time_to_sleep.nanosleep();" - "\n\t%v" - "\n\tgoto sseloop;"), sseloop.rep); + (void) declaration.reserve(100U + basename_sz + basename_sz + sse_code.size()); + + declaration.snprintf_add(U_CONSTANT_TO_PARAM( + "\nstatic UString sse_%.*s()" + "\n{" + "\n\tU_TRACE(5, \"::sse_%.*s()\")" + "\n\tUString sse_data;" + "\n\t%v" + "\n\tU_RETURN_STRING(sse_data);" + "\n}"), + basename_sz, basename_ptr, + basename_sz, basename_ptr, sse_code.rep); + + sseloop.snprintf(U_CONSTANT_TO_PARAM("\n\t\tif (UHTTP::sse_func) UHTTP::readSSE(%u);"), sse_timeout); + + http_header.snprintf_add(U_CONSTANT_TO_PARAM("\n\tUHTTP::sse_func = sse_%.*s;"), basename_sz, basename_ptr); + } } else if (strncmp(directive, U_CONSTANT_TO_PARAM("header")) == 0) { @@ -678,6 +676,11 @@ loop: distance = t.getDistance(); bfirst_pass = true; // NB: we check for and + UString basename = UStringExt::basename(filename); + + basename_sz = basename.size() - U_CONSTANT_SIZE(".usp"); + basename_ptr = basename.data(); + processUSP(); # ifdef DEBUG @@ -699,7 +702,6 @@ loop: distance = t.getDistance(); bsighup, // usp_sighup bfork; // usp_fork - const char* ptr0 = (sseloop ? "\n\t\tif (UHTTP::bsse) goto sseloop;\n" : ""); char ptr1[100] = { '\0' }; char ptr2[100] = { '\0' }; char ptr3[100] = { '\0' }; @@ -707,7 +709,7 @@ loop: distance = t.getDistance(); char ptr5[100] = { '\0' }; const char* ptr6 = ""; const char* ptr7 = ""; - + # ifndef U_CACHE_REQUEST_DISABLE if (usp.c_char(4) == '#' && u__isspace(usp.c_char(5)) && @@ -717,11 +719,6 @@ loop: distance = t.getDistance(); } # endif - UString basename = UStringExt::basename(filename); - - uint32_t basename_sz = basename.size() - U_CONSTANT_SIZE(".usp"); - const char* basename_ptr = basename.data(); - if (declaration) { binit = (U_STRING_FIND(declaration, 0, "static void usp_init_") != U_NOT_FOUND); @@ -799,7 +796,7 @@ loop: distance = t.getDistance(); (void) http_header.append(U_CONSTANT_TO_PARAM("\n\tU_http_info.endHeader = 0;\n")); } - UString result(1024U + declaration.size() + http_header.size() + output0.size() + output1.size() + output2.size() + sseloop.size() + vars.size()); + UString result(1024U + declaration.size() + http_header.size() + output0.size() + output1.size() + output2.size() + vars.size()); result.snprintf(U_CONSTANT_TO_PARAM( "// %.*s.cpp - dynamic page translation (%.*s.usp => %.*s.cpp)\n" @@ -818,7 +815,7 @@ loop: distance = t.getDistance(); "\t\n" "\tif (param)\n" "\t\t{\n" - "%s" + "%v" "%s" "%s" "%s" @@ -844,7 +841,7 @@ loop: distance = t.getDistance(); basename_sz, basename_ptr, basename_sz, basename_ptr, vars.rep, - ptr0, + sseloop.rep, ptr1, ptr2, ptr3, @@ -869,6 +866,8 @@ private: UTokenizer t; UVector vdefine; UString pinclude, usp, token, output0, output1, output2, declaration, vcode, http_header, sseloop, vars; + const char* basename_ptr; + uint32_t basename_sz; bool bvar, bsession, bstorage, bfirst_pass, is_html, test_if_html, bpreprocessing_failed; U_DISALLOW_COPY_AND_ASSIGN(Application) diff --git a/src/ulib/net/server/server.cpp b/src/ulib/net/server/server.cpp index 1a0a94f1..64d3fe0a 100644 --- a/src/ulib/net/server/server.cpp +++ b/src/ulib/net/server/server.cpp @@ -1339,6 +1339,306 @@ private: ULock* UServer_Base::lock_ocsp_staple; UThread* UServer_Base::pthread_ocsp; # endif + +# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) +int UServer_Base::sse_event_fd; +int UServer_Base::sse_socketpair[2]; +char UServer_Base::iovbuf[1] = { 0 }; +char UServer_Base::sse_fifo_name[256]; +ULock* UServer_Base::lock_sse; +uint32_t UServer_Base::sse_fifo_pos; +UThread* UServer_Base::pthread_sse; +UString* UServer_Base::sse_id; +UString* UServer_Base::sse_event; +UString* UServer_Base::str_asterisk; +struct iovec UServer_Base::iov[1] = { { iovbuf, 1 } }; +struct msghdr UServer_Base::msg = { 0, 0, iov, 1, &cmsg, sizeof(struct ucmsghdr), 0 }; + +UVector* UServer_Base::sse_vclient; +struct UServer_Base::ucmsghdr UServer_Base::cmsg = { sizeof(struct ucmsghdr), SOL_SOCKET, SCM_RIGHTS, 0 }; + +#ifdef USE_LIBSSL +ULock* UServer_Base::lock_sse_ssl; +#endif + +class USSEThread; + +class U_NO_EXPORT USSEClient { +public: + + // Check for memory error + U_MEMORY_TEST + + // Allocator e Deallocator + U_MEMORY_ALLOCATOR + U_MEMORY_DEALLOCATOR + + USSEClient(const UString& id, const UString& subscribe, int _fd, bool process) : sub(subscribe), uniq_id(id), fd(_fd), bprocess(process) + { + U_TRACE_REGISTER_OBJECT(0, USSEClient, "%V,%V,%d,%b", id.rep, subscribe.rep, _fd, process) + + U_INTERNAL_ASSERT_DIFFERS(fd, -1) + } + + ~USSEClient() + { + U_TRACE_UNREGISTER_OBJECT(0, USSEClient) + + UFile::close(fd); + + if (bprocess) + { + UServer_Base::setFIFOForSSE(uniq_id); + + (void) UFile::_unlink(UServer_Base::sse_fifo_name); + } + } + +#if defined(DEBUG) && defined(U_STDCPP_ENABLE) + const char* dump(bool _reset) const { return ""; } +#endif + +protected: + UString sub, // Token of subscribe (optional). Can be set by parameter "subscribe" + uniq_id; // unique client id (optional). Can be set by parameter "id" + int fd; + bool bprocess; + +private: + friend class USSEThread; +}; + +class USSEThread : public UThread { +public: + + USSEThread() : UThread(PTHREAD_CREATE_DETACHED) {} + + virtual void run() U_DECL_FINAL + { + U_TRACE_NO_PARAM(0, "USSEThread::run()") + + int fd; + const char* ptr; + USSEClient* client; + UVector vec; + bool ball, bprocess, err; + UVector vmessage; + uint32_t pos, mr, sz, last_event_id, i, n, k, start = 0, end = 0; + UString input(U_CAPACITY), output(U_CAPACITY), row, _id, token, rID, message, tmp; + + while (U_SRV_FLAG_SIGTERM == false) + { + if (UNotifier::waitForRead(UServer_Base::sse_event_fd) == 1 && + UServices::read(UServer_Base::sse_event_fd, input)) + { + /** + * NEW + * DEL + * + * LIST - List clients to /tmp/SSE_list.txt + * + * = - Send message to the subscribers of + * -= - Send message to the subscribers of (* => all) except + */ + + for (k = 0, sz = vec.split(input); k < sz; ++k) + { + row = vec[k]; + + pos = row.find('='); + + if (pos > 32) + { + ptr = row.data(); + + if (u_get_unalignedp32(ptr) == U_MULTICHAR_CONSTANT32('N','E','W',' ')) // NEW + { + _id = vec[k+1]; + token = vec[k+2]; + last_event_id = vec[k+3].strtoul(); + bprocess = vec[k+4].strtoul(); + + U_INTERNAL_DUMP("_id = %V token = %V bprocess = %b last_event_id = %u U_SRV_SSE_CNT1 = %u", _id.rep, token.rep, bprocess, last_event_id, U_SRV_SSE_CNT1) + + if ((ball = token.equal(*UServer_Base::str_asterisk))) token = *UServer_Base::str_asterisk; + else token.duplicate(); + + if (last_event_id && + last_event_id < U_SRV_SSE_CNT1) + { + if (last_event_id < start) last_event_id = start; + + for (i = last_event_id; i < end; ++i) + { + message = vmessage[i % vmessage.capacity()]; + + pos = message.find('='); + + U_INTERNAL_DUMP("vmessage[%u] = %V pos = %u", i % vmessage.capacity(), message.rep, pos) + + if (ball || + token.equal(message.data(), pos)) + { + (void) output.append(UServer_Base::printSSE(i+1, message.substr(pos+1), (ball ? U_NULLPTR : &token))); + } + } + + output.push('\n'); + + (void) U_SYSCALL(write, "%u,%S,%u", UServer_Base::sse_event_fd, U_STRING_TO_PARAM(output)); + + output.setEmpty(); + } + + if (bprocess == false) fd = (U_SYSCALL(recvmsg, "%u,%p,%u", UServer_Base::sse_socketpair[0], &UServer_Base::msg, 0) == 1 ? UServer_Base::cmsg.cmsg_data : -1); + else + { + UServer_Base::setFIFOForSSE(_id); + + (void) UFile::mkfifo(UServer_Base::sse_fifo_name); + + fd = UFile::open(UServer_Base::sse_fifo_name, O_WRONLY, 0); + + if (fd == -1) U_ERROR("Error on opening SSE FIFO: %S", UServer_Base::sse_fifo_name); + } + + U_NEW(USSEClient, client, USSEClient(_id.copy(), token, fd, bprocess)); + + UServer_Base::sse_vclient->push(client); + + k += 4; + } + else if (u_get_unalignedp32(ptr) == U_MULTICHAR_CONSTANT32('D','E','L',' ')) // DEL + { + _id = vec[k+1]; + + U_INTERNAL_DUMP("_id = %V", _id.rep) + + for (i = 0, n = UServer_Base::sse_vclient->size(); i < n; ++i) + { + client = UServer_Base::sse_vclient->at(i); + + U_INTERNAL_DUMP("sse_vclient[%u]->uniq_id = %V", i, client->uniq_id.rep) + + if (client->uniq_id == _id) + { + --n; + + delete UServer_Base::sse_vclient->remove(i--); + + break; + } + } + + k += 1; + } +# ifdef DEBUG + else if (u_get_unalignedp32(ptr) == U_MULTICHAR_CONSTANT32('L','I','S','T')) + { + UString row1(U_CAPACITY); + + for (i = 0, n = UServer_Base::sse_vclient->size(); i < n; ++i) + { + client = UServer_Base::sse_vclient->at(i); + + row1.snprintf(U_CONSTANT_TO_PARAM("uniq_id: %V sub: %V fd: %u proc: %b\n"), client->uniq_id.rep, client->sub.rep, client->fd, client->bprocess); + + (void) output.append(row1); + } + + (void) UFile::writeToTmp(U_STRING_TO_PARAM(output), O_RDWR | O_TRUNC, U_CONSTANT_TO_PARAM("SSE_client.txt"), 0); + + output = vmessage.join('\n'); + + (void) UFile::writeToTmp(U_STRING_TO_PARAM(output), O_RDWR | O_TRUNC, U_CONSTANT_TO_PARAM("SSE_message.txt"), 0); + + output.setEmpty(); + + ++k; + } +# endif + else + { + U_WARNING("Wrong formatted message from SSE FIFO, ignored: row = %V", row.rep); + + ++k; + } + } + else + { + mr = row.find('-', 0, pos); + + if (mr == U_NOT_FOUND) token = row.substr(0U, pos); + else + { + token = row.substr(0U, mr); + rID = row.substr(mr+1, pos-mr-1); + } + + message = row.substr(pos+1); + + U_SRV_SSE_CNT1++; + + U_INTERNAL_DUMP("token = %V rID = %V message = %V U_SRV_SSE_CNT1 = %u", token.rep, rID.rep, message.rep, U_SRV_SSE_CNT1) + + U_SRV_LOG("[sse] send message(%u) to subscribers of %V%.*s%.*s: %V", U_SRV_SSE_CNT1, token.rep, + rID ? U_CONSTANT_SIZE(" except SSE_") : 0, " except SSE_", rID ? rID.size() : 0, rID.data(), message.rep); + + tmp = ((ball = token.equal(*UServer_Base::str_asterisk)) ? "*="+message : token+'='+message); + + if (end < vmessage.capacity()) vmessage.push_back(tmp); + else + { + ++start; + + vmessage.replace(end % vmessage.capacity(), tmp); + } + + ++end; + + for (i = 0, n = UServer_Base::sse_vclient->size(); i < n; ++i) + { + client = UServer_Base::sse_vclient->at(i); + + if (rID != client->uniq_id && + (ball || + client->sub.equal(token))) + { + if (client->bprocess) err = (U_SYSCALL(write, "%u,%S,%u", client->fd, U_STRING_TO_PARAM(message)) <= 0); + else + { + U_INTERNAL_ASSERT_EQUALS(UServer_Base::bssl, false) + + tmp = UServer_Base::printSSE(U_SRV_SSE_CNT1, message, (ball ? U_NULLPTR : &token)); + + err = (U_SYSCALL(write, "%u,%S,%u", client->fd, U_STRING_TO_PARAM(tmp)) <= 0); + } + + if (err) + { + --n; + + delete UServer_Base::sse_vclient->remove(i--); + } + } + } + } + } + + UServer_Base::unlockSSE(); + + vec.clear(); + rID.clear(); + token.clear(); + input.setEmpty(); + } + } + } + +private: + U_DISALLOW_COPY_AND_ASSIGN(USSEThread) +}; +# endif #endif #ifdef U_LINUX @@ -1443,9 +1743,17 @@ UServer_Base::~UServer_Base() USSLSocket::cleanupStapling(); - if (UServer_Base::lock_ocsp_staple) delete UServer_Base::lock_ocsp_staple; + if (lock_ocsp_staple) delete lock_ocsp_staple; } # endif + +# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + if (lock_sse) delete lock_sse; +# ifdef USE_LIBSSL + if (lock_sse_ssl) delete lock_sse_ssl; +# endif + if (pthread_sse) delete (USSEThread*)pthread_sse; +# endif # endif #endif @@ -3099,6 +3407,45 @@ next: initEvasive(); #endif +#ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) +# ifdef USERVER_UDP + if (budp == false) +# endif + { + sse_fifo_pos = u__snprintf(sse_fifo_name, 256, U_CONSTANT_TO_PARAM("%s/SSE_%s_EVENT"), u_tmpdir, bssl ? "SSL" : "TCP") - U_CONSTANT_SIZE("EVENT"); + + (void) UFile::mkfifo(sse_fifo_name, PERM_FILE); + + sse_event_fd = UFile::open(sse_fifo_name, O_RDWR, PERM_FILE); + + if (sse_event_fd == -1) U_ERROR("Error on opening SSE FIFO: %S", sse_fifo_name); + +# ifndef DEBUG + (void) UFile::_unlink(sse_fifo_name); +# endif + + setLockSSE(); + + U_INTERNAL_ASSERT_EQUALS(sse_id, U_NULLPTR) + U_INTERNAL_ASSERT_EQUALS(sse_vclient, U_NULLPTR) + U_INTERNAL_ASSERT_EQUALS(pthread_sse, U_NULLPTR) + U_INTERNAL_ASSERT_EQUALS(str_asterisk, U_NULLPTR) + + U_NEW(UString, sse_id, UString); + U_NEW(USSEThread, pthread_sse, USSEThread); + U_NEW(UString, str_asterisk, U_STRING_FROM_CONSTANT("*")); + U_NEW(UVector, sse_vclient, UVector); + + pthread_sse->start(0); + + (void) U_SYSCALL(socketpair, "%d,%d,%d,%p", AF_UNIX, SOCK_STREAM, 0, sse_socketpair); + + U_INTERNAL_DUMP("sse_socketpair[0] = %u sse_socketpair[1] = %u", sse_socketpair[0], sse_socketpair[1]) + + U_SRV_LOG("SSE thread activated: %s(%d)", sse_fifo_name, sse_event_fd); + } +#endif + if (cfg) cfg->clear(); UInterrupt::syscall_restart = false; @@ -3150,6 +3497,10 @@ void UServer_Base::sendSignalToAllChildren(int signo, sighandler_t handler) # if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB) if (pthread_ocsp) pthread_ocsp->suspend(); # endif + +# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + if (pthread_sse) pthread_sse->suspend(); +# endif #endif // NB: we can't use UInterrupt::erase() because it restore the old action (UInterrupt::init)... @@ -3169,9 +3520,13 @@ void UServer_Base::sendSignalToAllChildren(int signo, sighandler_t handler) #if defined(U_LINUX) && defined(ENABLE_THREAD) if (u_pthread_time) ((UTimeThread*)u_pthread_time)->resume(); -# if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB) +# if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB) if (pthread_ocsp) pthread_ocsp->resume(); -# endif +# endif + +# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + if (pthread_sse) pthread_sse->resume(); +# endif #endif } @@ -4214,6 +4569,10 @@ void UServer_Base::run() if (proc->child()) { +# ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + UFile::close(sse_socketpair[0]); +# endif + U_INTERNAL_DUMP("child = %P UNotifier::num_connection = %d", UNotifier::num_connection) # if defined(HAVE_SCHED_GETAFFINITY) && (!defined(U_SERVER_CAPTIVE_PORTAL) || defined(ENABLE_THREAD)) @@ -4412,6 +4771,10 @@ stop: closeLog(); } +#ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) + if (pthread_sse) sse_vclient->clear(); +#endif + #ifdef DEBUG pthis->deallocate(); #endif diff --git a/src/ulib/notifier.cpp b/src/ulib/notifier.cpp index 1794826b..9614be0a 100644 --- a/src/ulib/notifier.cpp +++ b/src/ulib/notifier.cpp @@ -1416,8 +1416,9 @@ int UNotifier::read(int fd, char* buffer, int count, int timeoutMS) { U_TRACE(1, "UNotifier::read(%d,%p,%d,%d)", fd, buffer, count, timeoutMS) - if (fd < 0 && - timeoutMS != -1 && + U_INTERNAL_ASSERT_DIFFERS(fd, -1) + + if (timeoutMS != -1 && waitForRead(fd, timeoutMS) != 1) { U_RETURN(-1); diff --git a/src/ulib/process.cpp b/src/ulib/process.cpp index 1442eb7d..08dab98c 100644 --- a/src/ulib/process.cpp +++ b/src/ulib/process.cpp @@ -37,13 +37,16 @@ bool UProcess::fork() _pid = U_FORK(); - if (child()) u_setPid(); + if ((running = (_pid != -1))) + { + if (child()) u_setPid(); - running = (_pid != -1); + U_INTERNAL_DUMP("_pid = %u u_pid = %u %%P = %P running = %b", _pid, u_pid, running) - U_INTERNAL_DUMP("%P running = %b", running) + U_RETURN(true); + } - U_RETURN(running); + U_RETURN(false); } // inlining failed in call to 'UProcess::setStdInOutErr(bool, bool, bool)': call is unlikely and code size would grow diff --git a/src/ulib/string.cpp b/src/ulib/string.cpp index b3584065..b40799f0 100644 --- a/src/ulib/string.cpp +++ b/src/ulib/string.cpp @@ -1388,6 +1388,29 @@ void UString::resize(uint32_t n, unsigned char c) // The `find' function searches string for a specified string (possibly a single character) and returns // its starting position. You can supply the parameter pos to specify the position where search must begin +__pure uint32_t UString::find(unsigned char c, uint32_t pos, uint32_t how_much) const +{ + U_TRACE(0, "UString::find(%C,%u,%u)", c, pos, how_much) + + uint32_t n = rep->fold(pos, how_much); + + U_INTERNAL_DUMP("rep->_length = %u", rep->_length) + + U_INTERNAL_ASSERT(n <= rep->_length) + + const char* str = rep->str; + const char* ptr = (const char*) memchr(str + pos, c, n); + + if (ptr) + { + n = ptr - str; + + U_RETURN(n); + } + + U_RETURN(U_NOT_FOUND); +} + __pure uint32_t UString::find(const char* s, uint32_t pos, uint32_t s_len, uint32_t how_much) const { U_TRACE(0, "UString::find(%.*S,%u,%u,%u)", s_len, s, pos, s_len, how_much) @@ -1406,9 +1429,14 @@ __pure uint32_t UString::find(const char* s, uint32_t pos, uint32_t s_len, uint3 const char* str = rep->str; const char* ptr = (const char*) u_find(str + pos, n, s, s_len); - n = (ptr ? ptr - str : U_NOT_FOUND); + if (ptr) + { + n = ptr - str; - U_RETURN(n); + U_RETURN(n); + } + + U_RETURN(U_NOT_FOUND); } __pure uint32_t UString::findnocase(const char* s, uint32_t pos, uint32_t s_len, uint32_t how_much) const diff --git a/src/ulib/utility/uhttp.cpp b/src/ulib/utility/uhttp.cpp index 37a59b40..032bd817 100644 --- a/src/ulib/utility/uhttp.cpp +++ b/src/ulib/utility/uhttp.cpp @@ -169,7 +169,9 @@ UVector* UHTTP::vallow_IP; URDBObjectHandler* UHTTP::db_session_ssl; #endif #ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) -bool UHTTP::bsse; +int UHTTP::sse_pipe_fd; +const char* UHTTP::sse_corsbase = "*"; +UHTTP::strPF UHTTP::sse_func; #endif #ifdef USE_LOAD_BALANCE UClient* UHTTP::client_http; @@ -5312,19 +5314,15 @@ void UHTTP::setEndRequestProcessing() U_ClientImage_request, U_http_info.nResponseCode, U_ClientImage_request_is_cached, U_http_info.startHeader) #ifdef U_SSE_ENABLE - U_INTERNAL_DUMP("bsse = %b", bsse) + U_INTERNAL_DUMP("sse_func = %p", sse_func) - if (bsse) + if (sse_func) { - U_INTERNAL_DUMP("Accept: = %.*S", U_HTTP_ACCEPT_TO_TRACE) - - U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(U_http_info.accept+8), U_MULTICHAR_CONSTANT64('n','t','-','s','t','r','e','a')) - if (UServer_Base::startParallelization()) { // parent - bsse = false; + sse_func = U_NULLPTR; return; } @@ -5334,6 +5332,24 @@ void UHTTP::setEndRequestProcessing() U_SET_MODULE_NAME(sse); + UServer_Base::setFIFOForSSE(*UServer_Base::sse_id); + +loop: sse_pipe_fd = UFile::open(UServer_Base::sse_fifo_name, O_RDONLY, 0); + + if (sse_pipe_fd == -1) + { + U_INTERNAL_DUMP("errno = %u u_errno = %u", errno, u_errno) + + if (errno == ENOENT) + { + (void) UFile::mkfifo(UServer_Base::sse_fifo_name); + + goto loop; + } + + U_ERROR("Error on opening SSE FIFO: %S", UServer_Base::sse_fifo_name); + } + usp->runDynamicPage(1); } #endif @@ -7082,15 +7098,176 @@ void UHTTP::setUnAuthorized() // end HTTP main error message // -------------------------------------------------------------------------------------------------------------------------------------- +#ifdef U_SSE_ENABLE // SERVER SENT EVENTS (SSE) +__noreturn void UHTTP::readSSE(int timeoutMS) +{ + U_TRACE(0, "UHTTP::readSSE(%d)", timeoutMS) + + UString input(U_CAPACITY), sse_data; + + while (true) + { + if (UServices::read(sse_pipe_fd, input, U_SINGLE_READ, timeoutMS)) + { + U_INTERNAL_ASSERT(input) + + // external + + sendSSE(input); + + input.setEmpty(); + + continue; + } + + if (U_SRV_FLAG_SIGTERM) U_EXIT(0); + +# ifdef USE_LIBSSL + if (UServer_Base::bssl == false) +# endif + { + U_INTERNAL_ASSERT_POINTER(sse_func) + U_INTERNAL_ASSERT_DIFFERS(timeoutMS, -1) + + // timeout (internal) + + sse_data = sse_func(); + + if (sse_data) + { + UServer_Base::sendToAllExceptSSE(sse_data); + + sendSSE(sse_data); + } + } + } +} +#endif + void UHTTP::setDynamicResponse() { - U_TRACE_NO_PARAM(0, "UHTTP::setDynamicResponse()") + U_TRACE_NO_PARAM(1, "UHTTP::setDynamicResponse()") U_INTERNAL_DUMP("U_http_info.endHeader = %u U_http_content_type_len = %u mime_index(%d) = %C UClientImage_Base::wbuffer(%u) = %V", U_http_info.endHeader, U_http_content_type_len, mime_index, mime_index, UClientImage_Base::wbuffer->size(), UClientImage_Base::wbuffer->rep) U_INTERNAL_ASSERT_MAJOR(U_http_info.nResponseCode, 0) +#ifdef U_SSE_ENABLE + U_INTERNAL_DUMP("sse_func = %p", sse_func) + + if (sse_func) + { + U_INTERNAL_DUMP("Accept: = %.*S", U_HTTP_ACCEPT_TO_TRACE) + + U_ASSERT(isGET()) + U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(U_http_info.accept+8), U_MULTICHAR_CONSTANT64('n','t','-','s','t','r','e','a')) + + /** + * we must insert: + * + * + * + * + */ + + UString subscribe; + bool bprocess = (sse_func != (void*)1L); + const char* ptr = getHeaderValuePtr(U_CONSTANT_TO_PARAM("last-event-id"), true); + uint32_t last_event_id = (ptr ? u_atoi(ptr) : 0); + + UServer_Base::sse_id->clear(); + + if (UServer_Base::bssl == false) (void) UServer_Base::csocket->shutdown(SHUT_RD); + + (void) UClientImage_Base::wbuffer->snprintf(U_CONSTANT_TO_PARAM("Access-Control-Allow-Origin: %s\r\n" + "Access-Control-Allow-Methods: GET\r\n" + "Access-Control-Allow-Headers: cache-control, last-event-id, X-Requested-With\r\n" + "Content-Type: text/event-stream\r\n" + "Cache-Control: no-cache\r\n\r\n"), sse_corsbase); + + if (processForm()) + { + getFormValue(subscribe, 1); + getFormValue(*UServer_Base::sse_id, 3); + } + + if (subscribe) UServer_Base::sse_event = &subscribe; + else + { + subscribe = *UServer_Base::str_asterisk; + UServer_Base::sse_event = U_NULLPTR; + } + + if (UServer_Base::sse_id->empty()) + { + U_SRV_SSE_CNT2++; + + U_INTERNAL_DUMP("U_SRV_SSE_CNT2 = %u", U_SRV_SSE_CNT2) + + *UServer_Base::sse_id = UStringExt::numberToString(U_SRV_SSE_CNT2); + } + + U_INTERNAL_DUMP("last_event_id = %u U_SRV_SSE_CNT1 = %u", last_event_id, U_SRV_SSE_CNT1) + + UServer_Base::eventSSE(U_CONSTANT_TO_PARAM("NEW %v %v %u %u\n"), UServer_Base::sse_id->rep, subscribe.rep, last_event_id, bprocess); + + if (ptr && + last_event_id < U_SRV_SSE_CNT1) + { + UString buffer(U_CAPACITY); + + (void) UServices::read(UServer_Base::sse_event_fd, buffer); + + uint32_t sz = buffer.size(); + + if (sz > 1) + { + U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp16(buffer.data()), U_MULTICHAR_CONSTANT16('i','d')) + + UClientImage_Base::wbuffer->append(buffer.data(), sz-1); + } + } + + if (bprocess) + { + UString sse_data = sse_func(); + + if (sse_data) + { + UServer_Base::sendToAllExceptSSE(sse_data); + + UClientImage_Base::wbuffer->append(UServer_Base::printSSE(U_SRV_SSE_CNT1, sse_data, UServer_Base::sse_event)); + } + } + else + { + sse_func = U_NULLPTR; + + UServer_Base::cmsg.cmsg_data = UServer_Base::csocket->getFd(); + + (void) U_SYSCALL(sendmsg, "%u,%p,%u", UServer_Base::sse_socketpair[1], &UServer_Base::msg, 0); + + UClientImage_Base::resetPipelineAndSetCloseConnection(); + } + + *ext = *UClientImage_Base::wbuffer; + + handlerResponse(); + + return; + } +#endif + char* ptr; const char* pEndHeader; uint32_t clength = UClientImage_Base::wbuffer->size(); @@ -7128,19 +7305,6 @@ void UHTTP::setDynamicResponse() } # endif -# ifdef U_SSE_ENABLE - U_INTERNAL_DUMP("bsse = %b", bsse) - - if (bsse) - { - *ext = *UClientImage_Base::wbuffer; - - handlerResponse(); - - return; - } -# endif - if (bcompress == false) { (void) UClientImage_Base::body->replace(pEndHeader + U_http_info.endHeader, clength); diff --git a/tests/examples/sse_example/get_ticker.usp b/tests/examples/sse_example/get_ticker.usp index 62d177e9..4a82889b 100644 --- a/tests/examples/sse_example/get_ticker.usp +++ b/tests/examples/sse_example/get_ticker.usp @@ -1,27 +1,12 @@ - - - diff --git a/tests/examples/sse_example/get_ticker1.usp b/tests/examples/sse_example/get_ticker1.usp new file mode 100644 index 00000000..49c7b49d --- /dev/null +++ b/tests/examples/sse_example/get_ticker1.usp @@ -0,0 +1,2 @@ + diff --git a/tests/examples/sse_example/index.html b/tests/examples/sse_example/index.html index f6a66aa7..59764f59 100644 --- a/tests/examples/sse_example/index.html +++ b/tests/examples/sse_example/index.html @@ -1,7 +1,6 @@ - SSE example diff --git a/tests/examples/sse_example/index1.html b/tests/examples/sse_example/index1.html new file mode 100644 index 00000000..3657b41b --- /dev/null +++ b/tests/examples/sse_example/index1.html @@ -0,0 +1,24 @@ + + + + SSE example + + +

Stock Price

+ +

Price:

+ diff --git a/tests/examples/sse_example/jquery.min.js b/tests/examples/sse_example/jquery.min.js deleted file mode 100644 index 16ad06c5..00000000 --- a/tests/examples/sse_example/jquery.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! jQuery v1.7.2 jquery.com | jquery.org/license */ -(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ck||(ck=c.createElement("iframe"),ck.frameBorder=ck.width=ck.height=0),b.appendChild(ck);if(!cl||!ck.createElement)cl=(ck.contentWindow||ck.contentDocument).document,cl.write((f.support.boxModel?"":"")+""),cl.close();d=cl.createElement(a),cl.body.appendChild(d),e=f.css(d,"display"),b.removeChild(ck)}cj[a]=e}return cj[a]}function ct(a,b){var c={};f.each(cp.concat.apply([],cp.slice(0,b)),function(){c[this]=a});return c}function cs(){cq=b}function cr(){setTimeout(cs,0);return cq=f.now()}function ci(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ch(){try{return new a.XMLHttpRequest}catch(b){}}function cb(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!=="border")for(;e=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?+d:j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.2",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){if(typeof c!="string"||!c)return null;var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c
a",d=p.getElementsByTagName("*"),e=p.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=p.getElementsByTagName("input")[0],b={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName("tbody").length,htmlSerialize:!!p.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:p.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,pixelMargin:!0},f.boxModel=b.boxModel=c.compatMode==="CSS1Compat",i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete p.test}catch(r){b.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent("onclick",function(){b.noCloneEvent=!1}),p.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),i.setAttribute("name","t"),p.appendChild(i),j=c.createDocumentFragment(),j.appendChild(p.lastChild),b.checkClone=j.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,j.removeChild(i),j.appendChild(p);if(p.attachEvent)for(n in{submit:1,change:1,focusin:1})m="on"+n,o=m in p,o||(p.setAttribute(m,"return;"),o=typeof p[m]=="function"),b[n+"Bubbles"]=o;j.removeChild(p),j=g=h=p=i=null,f(function(){var d,e,g,h,i,j,l,m,n,q,r,s,t,u=c.getElementsByTagName("body")[0];!u||(m=1,t="padding:0;margin:0;border:",r="position:absolute;top:0;left:0;width:1px;height:1px;",s=t+"0;visibility:hidden;",n="style='"+r+t+"5px solid #000;",q="
"+""+"
",d=c.createElement("div"),d.style.cssText=s+"width:0;height:0;position:static;top:0;margin-top:"+m+"px",u.insertBefore(d,u.firstChild),p=c.createElement("div"),d.appendChild(p),p.innerHTML="
t
",k=p.getElementsByTagName("td"),o=k[0].offsetHeight===0,k[0].style.display="",k[1].style.display="none",b.reliableHiddenOffsets=o&&k[0].offsetHeight===0,a.getComputedStyle&&(p.innerHTML="",l=c.createElement("div"),l.style.width="0",l.style.marginRight="0",p.style.width="2px",p.appendChild(l),b.reliableMarginRight=(parseInt((a.getComputedStyle(l,null)||{marginRight:0}).marginRight,10)||0)===0),typeof p.style.zoom!="undefined"&&(p.innerHTML="",p.style.width=p.style.padding="1px",p.style.border=0,p.style.overflow="hidden",p.style.display="inline",p.style.zoom=1,b.inlineBlockNeedsLayout=p.offsetWidth===3,p.style.display="block",p.style.overflow="visible",p.innerHTML="
",b.shrinkWrapBlocks=p.offsetWidth!==3),p.style.cssText=r+s,p.innerHTML=q,e=p.firstChild,g=e.firstChild,i=e.nextSibling.firstChild.firstChild,j={doesNotAddBorder:g.offsetTop!==5,doesAddBorderForTableAndCells:i.offsetTop===5},g.style.position="fixed",g.style.top="20px",j.fixedPosition=g.offsetTop===20||g.offsetTop===15,g.style.position=g.style.top="",e.style.overflow="hidden",e.style.position="relative",j.subtractsBorderForOverflowNotVisible=g.offsetTop===-5,j.doesNotIncludeMarginInBodyOffset=u.offsetTop!==m,a.getComputedStyle&&(p.style.marginTop="1%",b.pixelMargin=(a.getComputedStyle(p,null)||{marginTop:0}).marginTop!=="1%"),typeof d.style.zoom!="undefined"&&(d.style.zoom=1),u.removeChild(d),l=p=d=null,f.extend(b,j))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e1,null,!1)},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){var d=2;typeof a!="string"&&(c=a,a="fx",d--);if(arguments.length1)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,f.prop,a,b,arguments.length>1)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.type]||f.valHooks[this.nodeName.toLowerCase()];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.type]||f.valHooks[g.nodeName.toLowerCase()];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h,i=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;i=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/(?:^|\s)hover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function( -a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler,g=p.selector),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&j.push({elem:this,matches:d.slice(e)});for(k=0;k0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));o.match.globalPOS=p;var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/]","i"),bd=/checked\s*(?:[^=]|=\s*.checked.)/i,be=/\/(java|ecma)script/i,bf=/^\s*",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div
","
"]),f.fn.extend({text:function(a){return f.access(this,function(a){return a===b?f.text(this):this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a))},null,a,arguments.length)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f -.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){return f.access(this,function(a){var c=this[0]||{},d=0,e=this.length;if(a===b)return c.nodeType===1?c.innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1>");try{for(;d1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||f.isXMLDoc(a)||!bc.test("<"+a.nodeName+">")?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g,h,i,j=[];b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);for(var k=0,l;(l=a[k])!=null;k++){typeof l=="number"&&(l+="");if(!l)continue;if(typeof l=="string")if(!_.test(l))l=b.createTextNode(l);else{l=l.replace(Y,"<$1>");var m=(Z.exec(l)||["",""])[1].toLowerCase(),n=bg[m]||bg._default,o=n[0],p=b.createElement("div"),q=bh.childNodes,r;b===c?bh.appendChild(p):U(b).appendChild(p),p.innerHTML=n[1]+l+n[2];while(o--)p=p.lastChild;if(!f.support.tbody){var s=$.test(l),t=m==="table"&&!s?p.firstChild&&p.firstChild.childNodes:n[1]===""&&!s?p.childNodes:[];for(i=t.length-1;i>=0;--i)f.nodeName(t[i],"tbody")&&!t[i].childNodes.length&&t[i].parentNode.removeChild(t[i])}!f.support.leadingWhitespace&&X.test(l)&&p.insertBefore(b.createTextNode(X.exec(l)[0]),p.firstChild),l=p.childNodes,p&&(p.parentNode.removeChild(p),q.length>0&&(r=q[q.length-1],r&&r.parentNode&&r.parentNode.removeChild(r)))}var u;if(!f.support.appendChecked)if(l[0]&&typeof (u=l.length)=="number")for(i=0;i1)},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=by(a,"opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bu.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(by)return by(a,c)},swap:function(a,b,c){var d={},e,f;for(f in b)d[f]=a.style[f],a.style[f]=b[f];e=c.call(a);for(f in b)a.style[f]=d[f];return e}}),f.curCSS=f.css,c.defaultView&&c.defaultView.getComputedStyle&&(bz=function(a,b){var c,d,e,g,h=a.style;b=b.replace(br,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b))),!f.support.pixelMargin&&e&&bv.test(b)&&bt.test(c)&&(g=h.width,h.width=c,c=e.width,h.width=g);return c}),c.documentElement.currentStyle&&(bA=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f==null&&g&&(e=g[b])&&(f=e),bt.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),by=bz||bA,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){if(c)return a.offsetWidth!==0?bB(a,b,d):f.swap(a,bw,function(){return bB(a,b,d)})},set:function(a,b){return bs.test(b)?b+"px":b}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bq.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bp,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bp.test(g)?g.replace(bp,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){return f.swap(a,{display:"inline-block"},function(){return b?by(a,"margin-right"):a.style.marginRight})}})}),f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)}),f.each({margin:"",padding:"",border:"Width"},function(a,b){f.cssHooks[a+b]={expand:function(c){var d,e=typeof c=="string"?c.split(" "):[c],f={};for(d=0;d<4;d++)f[a+bx[d]+b]=e[d]||e[d-2]||e[0];return f}}});var bC=/%20/g,bD=/\[\]$/,bE=/\r?\n/g,bF=/#.*$/,bG=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bH=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bI=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bJ=/^(?:GET|HEAD)$/,bK=/^\/\//,bL=/\?/,bM=/)<[^<]*)*<\/script>/gi,bN=/^(?:select|textarea)/i,bO=/\s+/,bP=/([?&])_=[^&]*/,bQ=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bR=f.fn.load,bS={},bT={},bU,bV,bW=["*/"]+["*"];try{bU=e.href}catch(bX){bU=c.createElement("a"),bU.href="",bU=bU.href}bV=bQ.exec(bU.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bR)return bR.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("
").append(c.replace(bM,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bN.test(this.nodeName)||bH.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bE,"\r\n")}}):{name:b.name,value:c.replace(bE,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b$(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b$(a,b);return a},ajaxSettings:{url:bU,isLocal:bI.test(bV[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bW},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bY(bS),ajaxTransport:bY(bT),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?ca(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cb(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bF,"").replace(bK,bV[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bO),d.crossDomain==null&&(r=bQ.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bV[1]&&r[2]==bV[2]&&(r[3]||(r[1]==="http:"?80:443))==(bV[3]||(bV[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),bZ(bS,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bJ.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bL.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bP,"$1_="+x);d.url=y+(y===d.url?(bL.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bW+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bZ(bT,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join("&").replace(bC,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cc=f.now(),cd=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cc++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=typeof b.data=="string"&&/^application\/x\-www\-form\-urlencoded/.test(b.contentType);if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(cd.test(b.url)||e&&cd.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(cd,l),b.url===j&&(e&&(k=k.replace(cd,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ce=a.ActiveXObject?function(){for(var a in cg)cg[a](0,1)}:!1,cf=0,cg;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ch()||ci()}:ch,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ce&&delete cg[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n);try{m.text=h.responseText}catch(a){}try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cf,ce&&(cg||(cg={},f(a).unload(ce)),cg[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cj={},ck,cl,cm=/^(?:toggle|show|hide)$/,cn=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,co,cp=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cq;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(ct("show",3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,c){var d=/Y/.test(c);f.fn[a]=function(e){return f.access(this,function(a,e,g){var h=cy(a);if(g===b)return h?c in h?h[c]:f.support.boxModel&&h.document.documentElement[e]||h.document.body[e]:a[e];h?h.scrollTo(d?f(h).scrollLeft():g,d?g:f(h).scrollTop()):a[e]=g},a,e,arguments.length,null)}}),f.each({Height:"height",Width:"width"},function(a,c){var d="client"+a,e="scroll"+a,g="offset"+a;f.fn["inner"+a]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,c,"padding")):this[c]():null},f.fn["outer"+a]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,c,a?"margin":"border")):this[c]():null},f.fn[c]=function(a){return f.access(this,function(a,c,h){var i,j,k,l;if(f.isWindow(a)){i=a.document,j=i.documentElement[d];return f.support.boxModel&&j||i.body&&i.body[d]||j}if(a.nodeType===9){i=a.documentElement;if(i[d]>=i[e])return i[d];return Math.max(a.body[e],i[e],a.body[g],i[g])}if(h===b){k=f.css(a,c),l=parseFloat(k);return f.isNumeric(l)?l:k}f(a).css(c,h)},c,a,arguments.length,null)}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window); \ No newline at end of file diff --git a/tests/examples/sse_example/set_ticker.usp b/tests/examples/sse_example/set_ticker.usp new file mode 100644 index 00000000..2c0a0d55 --- /dev/null +++ b/tests/examples/sse_example/set_ticker.usp @@ -0,0 +1,6 @@ + + diff --git a/tests/examples/web_server.sh b/tests/examples/web_server.sh index f03c4d38..cfc22b34 100755 --- a/tests/examples/web_server.sh +++ b/tests/examples/web_server.sh @@ -4,8 +4,8 @@ (cd benchmark; rm -f db; creat_link FrameworkBenchmarks/ULib/db db) - DOC_ROOT=docroot -#DOC_ROOT=sse_example +#DOC_ROOT=docroot + DOC_ROOT=sse_example #DOC_ROOT=ruby/blog #DOC_ROOT=benchmark/docroot #DOC_ROOT=ShivShankarDayal/docroot @@ -18,10 +18,12 @@ rm -f tmp/usp_compile.sh.err /tmp/*.hpack.* \ UTRACE="0 50M 0" UTRACE_SIGNAL="0 50M 0" + UTRACE_FOLDER=/tmp + TMPDIR=/tmp #UOBJDUMP="0 10M 100" #USIMERR="error.sim" #UMEMUSAGE=yes -export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE +export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE UTRACE_FOLDER TMPDIR SOCK1=tmp/fcgi.socket @@ -69,7 +71,7 @@ userver { #LOAD_BALANCE_CLUSTER 10.30.0.1,10.30.0.2 #LOAD_BALANCE_DEVICE_NETWORK enp0s20u1 #LOAD_BALANCE_LOADAVG_THRESHOLD 4.0 - PREFORK_CHILD 0 + PREFORK_CHILD 2 #CRASH_COUNT 1 #CRASH_EMAIL_NOTIFY mail.unirel.com:stefano.casazza@unirel.com #DOS_SITE_COUNT 1 diff --git a/tests/examples/web_server_proxy.test b/tests/examples/web_server_proxy.test index d3ad5aaa..87ae5467 100755 --- a/tests/examples/web_server_proxy.test +++ b/tests/examples/web_server_proxy.test @@ -2,6 +2,12 @@ . ../.function +# set -x + +## web_server_proxy.test -- Test web server proxy feature + +start_msg web_server_proxy + DOC_ROOT1=benchmark/docroot DOC_ROOT2=docroot @@ -87,3 +93,6 @@ pkill userver_tcp 2>/dev/null cat err/userver_tcp.err >> err/webserver_proxy.err rm err/userver_tcp.err + +# Test against expected output +test_output_wc l webserver_proxy diff --git a/tests/ulib/inp/json/fail1.json b/tests/ulib/inp/json/fail1.json deleted file mode 100644 index 6216b865..00000000 --- a/tests/ulib/inp/json/fail1.json +++ /dev/null @@ -1 +0,0 @@ -"A JSON payload should be an object or array, not a string." \ No newline at end of file diff --git a/tests/ulib/inp/json/fail18.json b/tests/ulib/inp/json/fail18.json deleted file mode 100644 index edac9271..00000000 --- a/tests/ulib/inp/json/fail18.json +++ /dev/null @@ -1 +0,0 @@ -[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] \ No newline at end of file diff --git a/tests/ulib/inp/json/fail2.json b/tests/ulib/inp/json/fail2.json deleted file mode 100644 index 6b7c11e5..00000000 --- a/tests/ulib/inp/json/fail2.json +++ /dev/null @@ -1 +0,0 @@ -["Unclosed array" \ No newline at end of file diff --git a/tests/ulib/inp/json/fail3.json b/tests/ulib/inp/json/fail3.json deleted file mode 100644 index 168c81eb..00000000 --- a/tests/ulib/inp/json/fail3.json +++ /dev/null @@ -1 +0,0 @@ -{unquoted_key: "keys must be quoted"} \ No newline at end of file diff --git a/tests/ulib/inp/json/fail4.json b/tests/ulib/inp/json/fail4.json deleted file mode 100644 index 9de168bf..00000000 --- a/tests/ulib/inp/json/fail4.json +++ /dev/null @@ -1 +0,0 @@ -["extra comma",] \ No newline at end of file diff --git a/tests/ulib/inp/json/fail5.json b/tests/ulib/inp/json/fail5.json deleted file mode 100644 index ddf3ce3d..00000000 --- a/tests/ulib/inp/json/fail5.json +++ /dev/null @@ -1 +0,0 @@ -["double extra comma",,] \ No newline at end of file diff --git a/tests/ulib/inp/json/fail6.json b/tests/ulib/inp/json/fail6.json deleted file mode 100644 index ed91580e..00000000 --- a/tests/ulib/inp/json/fail6.json +++ /dev/null @@ -1 +0,0 @@ -[ , "<-- missing value"] \ No newline at end of file diff --git a/tests/ulib/inp/json/fail7.json b/tests/ulib/inp/json/fail7.json deleted file mode 100644 index 8a96af3e..00000000 --- a/tests/ulib/inp/json/fail7.json +++ /dev/null @@ -1 +0,0 @@ -["Comma after the close"], \ No newline at end of file diff --git a/tests/ulib/inp/json/fail8.json b/tests/ulib/inp/json/fail8.json deleted file mode 100644 index b28479c6..00000000 --- a/tests/ulib/inp/json/fail8.json +++ /dev/null @@ -1 +0,0 @@ -["Extra close"]] \ No newline at end of file diff --git a/tests/ulib/inp/json/fail9.json b/tests/ulib/inp/json/fail9.json deleted file mode 100644 index 5815574f..00000000 --- a/tests/ulib/inp/json/fail9.json +++ /dev/null @@ -1 +0,0 @@ -{"Extra comma": true,} \ No newline at end of file diff --git a/tests/ulib/inp/json/pass1.json b/tests/ulib/inp/json/pass1.json deleted file mode 100644 index 12b09498..00000000 --- a/tests/ulib/inp/json/pass1.json +++ /dev/null @@ -1,58 +0,0 @@ -[ - "JSON Test Pattern pass1", - {"object with 1 member":["array with 1 element"]}, - {}, - [], - -42, - true, - false, - null, - { - "integer": 1234567890, - "real": -9876.543210, - "e": 0.123456789e-12, - "E": 1.234567890E+34, - "": 23456789012E66, - "zero": 0, - "one": 1, - "space": " ", - "quote": "\"", - "backslash": "\\", - "controls": "\b\f\n\r\t", - "slash": "/ & \/", - "alpha": "abcdefghijklmnopqrstuvwyz", - "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", - "digit": "0123456789", - "0123456789": "digit", - "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", - "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", - "true": true, - "false": false, - "null": null, - "array":[ ], - "object":{ }, - "address": "50 St. James Street", - "url": "http://www.JSON.org/", - "comment": "// /* */": " ", - " s p a c e d " :[1,2 , 3 - -, - -4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], - "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", - "quotes": "" \u0022 %22 0x22 034 "", - "\/\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" -: "A key can be any string" - }, - 0.5 ,98.6 -, -99.44 -, - -1066, -1e1, -0.1e1, -1e-1, -1e00,2e+00,2e-00 -,"rosebud"] diff --git a/tests/ulib/inp/json/pass2.json b/tests/ulib/inp/json/pass2.json deleted file mode 100644 index d3c63c7a..00000000 --- a/tests/ulib/inp/json/pass2.json +++ /dev/null @@ -1 +0,0 @@ -[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] \ No newline at end of file diff --git a/tests/ulib/inp/json/pass3.json b/tests/ulib/inp/json/pass3.json deleted file mode 100644 index 4528d51f..00000000 --- a/tests/ulib/inp/json/pass3.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "JSON Test Pattern pass3": { - "The outermost value": "must be an object or array.", - "In this test": "It is an object." - } -} diff --git a/tests/ulib/test_bison.yy b/tests/ulib/test_bison.yy deleted file mode 100644 index d5eede28..00000000 --- a/tests/ulib/test_bison.yy +++ /dev/null @@ -1,131 +0,0 @@ -/* Infix notation calculator-calc */ - -%{ -#define YYDEBUG 1 -/* -#define DEBUG_DEBUG -*/ -#include -#include -#include -int yyerror(void*, char*); -#define yylex ((UBison*)obj)->UFlexer::yylex -%} - -/* BISON Declarations */ - -%lex-param { void* obj } -%parse-param { void* obj } - -%union { - int number; - UFlexerReference ref; -} - -%token NUM -%left '-' '+' -%left '*' '/' -%left NEG /* negation--unary minus */ -%right '^' /* exponentiation */ - -%type exp - -/* Grammar follows */ - -%% - -input: /* empty string */ - | input line -; - -line: '\n' - | exp '\n' -{ - printf("\t%d\n", $1); - - U_INTERNAL_TRACE("UBison::yyparse() %d", $1); -} -; - -exp: NUM -{ - $$ = $1; - - U_INTERNAL_TRACE("UBison::yyparse() %d", $1); -} - | exp '+' exp -{ - $$ = $1 + $3; - - U_INTERNAL_TRACE("UBison::yyparse() %d + %d", $1, $3); -} - | exp '-' exp -{ - $$ = $1 - $3; - - U_INTERNAL_TRACE("UBison::yyparse() %d - %d", $1, $3); -} - | exp '*' exp -{ - $$ = $1 * $3; - - U_INTERNAL_TRACE("UBison::yyparse() %d * %d", $1, $3); -} - | exp '/' exp -{ - $$ = $1 / $3; - - U_INTERNAL_TRACE("UBison::yyparse() %d / %d", $1, $3); -} - | '-' exp %prec NEG -{ - $$ = -$2; - - U_INTERNAL_TRACE("UBison::yyparse() %d", $2); -} - | exp '^' exp -{ - $$ = (int) ::pow((float)$1, (float)$3); - - U_INTERNAL_TRACE("UBison::yyparse() %d ^ %d", $1, $3); -} - | '(' exp ')' -{ - $$ = $2; - - U_INTERNAL_TRACE("UBison::yyparse() %d", $2); -} -; - -%% - -int yyerror(void* p, char* s) -{ - U_INTERNAL_TRACE("yyerror(\"%p,%s\")", p, s); - - /** - * extern int yylineno; - * - * U_INTERNAL_TRACE("yylineno=%d", yylineno) - */ - - return -1; -} - -#include - -int main(int argc, char* argv[]) -{ - U_ULIB_INIT(argv); - - U_TRACE(5, "main(%d)", argc) - - UBison parser(UFile::contentOf(argv[1])); - - /* - */ - extern int yydebug; - yydebug = 1; - - parser.parse(); -} diff --git a/tests/ulib/test_bison_flexer.cc b/tests/ulib/test_bison_flexer.cc deleted file mode 100644 index 94d448e4..00000000 --- a/tests/ulib/test_bison_flexer.cc +++ /dev/null @@ -1,1563 +0,0 @@ - -#line 3 "test_bison_flexer.ccc" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 39 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - - /* The c++ scanner is a mess. The FlexLexer.h header file relies on the - * following macro. This is required in order to pass the c++-multiple-scanners - * test in the regression suite. We get reports that it breaks inheritance. - * We will address this in a future release of flex, or omit the C++ scanner - * altogether. - */ - #define yyFlexLexer yyFlexLexer - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* begin standard C++ headers. */ -#include -#include -#include -#include -#include -/* end standard C++ headers. */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#define YY_BUF_SIZE 16384 -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - - std::istream* yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - yy_size_t yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -#define yytext_ptr yytext - -#include - -int yyFlexLexer::yywrap() { return 1; } -int yyFlexLexer::yylex() - { - LexerError( "yyFlexLexer::yylex invoked but %option yyclass used" ); - return 0; - } - -#define YY_DECL int UFlexer::yylex() - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 5 -#define YY_END_OF_BUFFER 6 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[22] = - { 0, - 0, 0, 6, 4, 1, 3, 4, 4, 2, 1, - 0, 2, 2, 2, 0, 0, 0, 2, 0, 2, - 0 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 4, 1, 4, 5, 1, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 7, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[8] = - { 0, - 1, 1, 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int16_t yy_base[22] = - { 0, - 0, 0, 28, 29, 25, 29, 3, 20, 5, 23, - 18, 0, 7, 16, 11, 14, 16, 15, 13, 10, - 29 - } ; - -static yyconst flex_int16_t yy_def[22] = - { 0, - 21, 1, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 9, 21, 13, 21, 21, 21, 21, 21, 21, - 0 - } ; - -static yyconst flex_int16_t yy_nxt[37] = - { 0, - 4, 5, 6, 7, 8, 9, 4, 11, 12, 14, - 12, 15, 13, 16, 17, 20, 18, 19, 20, 20, - 18, 18, 15, 13, 10, 13, 10, 21, 3, 21, - 21, 21, 21, 21, 21, 21 - } ; - -static yyconst flex_int16_t yy_chk[37] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 7, 7, 9, - 9, 9, 13, 13, 15, 20, 15, 16, 19, 16, - 18, 17, 14, 11, 10, 8, 5, 3, 21, 21, - 21, 21, 21, 21, 21, 21 - } ; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -#line 1 "test_bison_flexer.ll" -#line 2 "test_bison_flexer.ll" -/* -#define DEBUG_DEBUG -*/ -#undef YY_DECL -#include -#include -#define YY_DECL int UFlexer::yylex(void* yyval) -#define YY_USER_ACTION ((YYSTYPE*)yyval)->ref.offset = parsed_chars; \ - ((YYSTYPE*)yyval)->ref.length = yyleng; parsed_chars += yyleng; \ - ((YYSTYPE*)yyval)->ref.ptr = yytext; - -int line_num = 1; -#line 440 "test_bison_flexer.ccc" - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -#define ECHO LexerOutput( yytext, yyleng ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ -\ - if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) LexerError( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 -#define YY_DECL int yyFlexLexer::yylex() -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = & std::cin; - - if ( ! yyout ) - yyout = & std::cout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 31 "test_bison_flexer.ll" - - -#line 570 "test_bison_flexer.ccc" - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 22 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_current_state != 21 ); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 33 "test_bison_flexer.ll" -/* skip blanks and tabs */ - YY_BREAK -case 2: -YY_RULE_SETUP -#line 35 "test_bison_flexer.ll" -{ - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %d number <%s>", line_num, yytext); - - yylval.number = strtol(yytext, 0, 0); - - return NUM; -} - YY_BREAK -case 3: -/* rule 3 can match eol */ -YY_RULE_SETUP -#line 43 "test_bison_flexer.ll" -{ - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %d new line", line_num); - - ++line_num; - - return '\n'; -} - YY_BREAK -case 4: -YY_RULE_SETUP -#line 51 "test_bison_flexer.ll" -return yytext[0]; - YY_BREAK -case 5: -YY_RULE_SETUP -#line 53 "test_bison_flexer.ll" -ECHO; - YY_BREAK -#line 661 "test_bison_flexer.ccc" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* The contents of this function are C++ specific, so the () macro is not used. - */ -yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout ) -{ - yyin = arg_yyin; - yyout = arg_yyout; - yy_c_buf_p = 0; - yy_init = 0; - yy_start = 0; - yy_flex_debug = 0; - yylineno = 1; // this will only get updated if %option yylineno - - yy_did_buffer_switch_on_eof = 0; - - yy_looking_for_trail_begin = 0; - yy_more_flag = 0; - yy_more_len = 0; - yy_more_offset = yy_prev_more_offset = 0; - - yy_start_stack_ptr = yy_start_stack_depth = 0; - yy_start_stack = NULL; - - yy_buffer_stack = 0; - yy_buffer_stack_top = 0; - yy_buffer_stack_max = 0; - - yy_state_buf = 0; - -} - -/* The contents of this function are C++ specific, so the () macro is not used. - */ -yyFlexLexer::~yyFlexLexer() -{ - delete [] yy_state_buf; - yyfree(yy_start_stack ); - yy_delete_buffer( YY_CURRENT_BUFFER ); - yyfree(yy_buffer_stack ); -} - -/* The contents of this function are C++ specific, so the () macro is not used. - */ -void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out ) -{ - if ( new_in ) - { - yy_delete_buffer( YY_CURRENT_BUFFER ); - yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); - } - - if ( new_out ) - yyout = new_out; -} - -#ifdef YY_INTERACTIVE -int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) -#else -int yyFlexLexer::LexerInput( char* buf, int max_size ) -#endif -{ - if ( yyin->eof() || yyin->fail() ) - return 0; - -#ifdef YY_INTERACTIVE - yyin->get( buf[0] ); - - if ( yyin->eof() ) - return 0; - - if ( yyin->bad() ) - return -1; - - return 1; - -#else - (void) yyin->read( buf, max_size ); - - if ( yyin->bad() ) - return -1; - else - return yyin->gcount(); -#endif -} - -void yyFlexLexer::LexerOutput( const char* buf, int size ) -{ - (void) yyout->write( buf, size ); -} - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -int yyFlexLexer::yy_get_next_buffer() -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - yy_state_type yyFlexLexer::yy_get_previous_state() -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 22 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) -{ - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 22 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 21); - - return yy_is_jam ? 0 : yy_current_state; -} - - void yyFlexLexer::yyunput( int c, register char* yy_bp) -{ - register char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - - int yyFlexLexer::yyinput() -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyFlexLexer::yyrestart( std::istream* input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - - void yyFlexLexer::yy_load_buffer_state() -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file ) - -{ - int oerrno = errno; - - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yyFlexLexer::yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -void yyFlexLexer::yyensure_buffer_stack(void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - - void yyFlexLexer::yy_push_state( int new_state ) -{ - if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) - { - yy_size_t new_size; - - (yy_start_stack_depth) += YY_START_STACK_INCR; - new_size = (yy_start_stack_depth) * sizeof( int ); - - if ( ! (yy_start_stack) ) - (yy_start_stack) = (int *) yyalloc(new_size ); - - else - (yy_start_stack) = (int *) yyrealloc((void *) (yy_start_stack),new_size ); - - if ( ! (yy_start_stack) ) - YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); - } - - (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; - - BEGIN(new_state); -} - - void yyFlexLexer::yy_pop_state() -{ - if ( --(yy_start_stack_ptr) < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); -} - - int yyFlexLexer::yy_top_state() -{ - return (yy_start_stack)[(yy_start_stack_ptr) - 1]; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -void yyFlexLexer::LexerError( yyconst char msg[] ) -{ - std::cerr << msg << std::endl; - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 53 "test_bison_flexer.ll" - - - diff --git a/tests/ulib/test_bison_flexer.ll b/tests/ulib/test_bison_flexer.ll deleted file mode 100644 index ee775343..00000000 --- a/tests/ulib/test_bison_flexer.ll +++ /dev/null @@ -1,53 +0,0 @@ -%{ -/* -#define DEBUG_DEBUG -*/ -#undef YY_DECL -#include -#include -#define YY_DECL int UFlexer::yylex(void* yyval) -#define YY_USER_ACTION ((YYSTYPE*)yyval)->ref.offset = parsed_chars; \ - ((YYSTYPE*)yyval)->ref.length = yyleng; parsed_chars += yyleng; \ - ((YYSTYPE*)yyval)->ref.ptr = yytext; - -int line_num = 1; -%} - -%option c++ -%option yyclass="UFlexer" caseless -%option nounput -%option nostack -%option noreject -%option never-interactive -%option noyywrap -%option noyymore - -dig [0-9] -num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)? -num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)? -number {num1}|{num2} -ws [ \f\t\r]+ - -%% - -{ws} /* skip blanks and tabs */ - -{number} { - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %d number <%s>", line_num, yytext); - - yylval.number = strtol(yytext, 0, 0); - - return NUM; -} - -\n { - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %d new line", line_num); - - ++line_num; - - return '\n'; -} - -. return yytext[0]; - -%% diff --git a/tests/ulib/test_flexer.cc b/tests/ulib/test_flexer.cc deleted file mode 100644 index 85abbf04..00000000 --- a/tests/ulib/test_flexer.cc +++ /dev/null @@ -1,1656 +0,0 @@ - -#line 3 "test_flexer.ccc" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 39 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - - /* The c++ scanner is a mess. The FlexLexer.h header file relies on the - * following macro. This is required in order to pass the c++-multiple-scanners - * test in the regression suite. We get reports that it breaks inheritance. - * We will address this in a future release of flex, or omit the C++ scanner - * altogether. - */ - #define yyFlexLexer yyFlexLexer - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* begin standard C++ headers. */ -#include -#include -#include -#include -#include -/* end standard C++ headers. */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -/* C99 requires __STDC__ to be defined as 1. */ -#if defined (__STDC__) - -#define YY_USE_CONST - -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#define YY_BUF_SIZE 16384 -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern yy_size_t yyleng; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - - std::istream* yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - yy_size_t yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ -#define YY_SKIP_YYWRAP - -typedef unsigned char YY_CHAR; - -#define yytext_ptr yytext - -#include - -int yyFlexLexer::yywrap() { return 1; } -int yyFlexLexer::yylex() - { - LexerError( "yyFlexLexer::yylex invoked but %option yyclass used" ); - return 0; - } - -#define YY_DECL int UFlexer::yylex() - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 13 -#define YY_END_OF_BUFFER 14 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[52] = - { 0, - 0, 0, 7, 7, 14, 12, 1, 2, 12, 4, - 12, 12, 12, 3, 7, 8, 9, 12, 1, 12, - 0, 4, 12, 3, 3, 6, 3, 3, 4, 7, - 8, 9, 10, 9, 11, 5, 5, 3, 12, 12, - 3, 12, 4, 3, 3, 12, 3, 4, 4, 3, - 0 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 4, 1, 5, 1, 1, 1, 1, - 1, 6, 7, 1, 8, 9, 10, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 1, 1, 1, - 1, 1, 1, 1, 12, 12, 12, 12, 13, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 1, 1, 1, 1, 14, 1, 12, 12, 12, 12, - - 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[15] = - { 0, - 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, - 1, 1, 1, 1 - } ; - -static yyconst flex_int16_t yy_base[58] = - { 0, - 0, 0, 12, 13, 92, 0, 83, 110, 18, 22, - 28, 73, 72, 31, 71, 110, 42, 0, 71, 39, - 65, 0, 57, 44, 36, 0, 43, 0, 51, 61, - 110, 60, 110, 11, 110, 0, 110, 54, 64, 69, - 68, 50, 49, 40, 39, 35, 27, 75, 14, 13, - 110, 86, 90, 94, 98, 101, 105 - } ; - -static yyconst flex_int16_t yy_def[58] = - { 0, - 51, 1, 52, 52, 51, 53, 51, 51, 54, 51, - 53, 53, 53, 10, 55, 51, 56, 53, 51, 54, - 57, 10, 53, 53, 53, 53, 10, 14, 10, 55, - 51, 56, 51, 32, 51, 53, 51, 53, 53, 53, - 10, 53, 10, 10, 53, 53, 53, 10, 10, 10, - 0, 51, 51, 51, 51, 51, 51 - } ; - -static yyconst flex_int16_t yy_nxt[125] = - { 0, - 6, 7, 8, 9, 10, 6, 11, 11, 12, 13, - 14, 10, 10, 6, 16, 16, 34, 17, 17, 21, - 35, 18, 18, 50, 50, 18, 22, 18, 18, 22, - 22, 22, 22, 22, 22, 22, 23, 47, 24, 27, - 21, 28, 36, 29, 33, 47, 25, 34, 40, 45, - 44, 35, 38, 41, 24, 29, 39, 42, 43, 44, - 45, 44, 33, 31, 25, 51, 39, 25, 37, 51, - 42, 42, 19, 31, 45, 46, 46, 26, 41, 47, - 48, 46, 49, 25, 19, 50, 15, 15, 15, 15, - 18, 51, 51, 18, 20, 20, 51, 20, 30, 30, - - 30, 32, 32, 32, 32, 21, 21, 51, 21, 5, - 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, - 51, 51, 51, 51 - } ; - -static yyconst flex_int16_t yy_chk[125] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 3, 4, 34, 3, 4, 9, - 34, 9, 10, 50, 49, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 11, 47, 11, 14, - 20, 14, 20, 14, 17, 46, 25, 17, 25, 45, - 44, 17, 24, 27, 24, 27, 24, 29, 29, 43, - 42, 29, 32, 30, 38, 32, 38, 23, 21, 32, - 39, 39, 19, 15, 39, 40, 40, 13, 41, 40, - 41, 48, 48, 12, 7, 48, 52, 52, 52, 52, - 53, 5, 0, 53, 54, 54, 0, 54, 55, 55, - - 55, 56, 56, 56, 56, 57, 57, 0, 57, 51, - 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, - 51, 51, 51, 51 - } ; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -#line 1 "test_flexer.ll" -#line 2 "test_flexer.ll" -/* -#define DEBUG_DEBUG -*/ -#undef YY_DECL -#include -#define YY_DECL int UFlexer::yylex(void* yyval) -#define YY_USER_ACTION ((YYSTYPE*)yyval)->ref.offset = parsed_chars; \ - ((YYSTYPE*)yyval)->ref.length = yyleng; parsed_chars += yyleng; \ - ((YYSTYPE*)yyval)->ref.ptr = yytext; - -int line_num = 1; - -#line 470 "test_flexer.ccc" - -#define INITIAL 0 -#define comment 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -#define ECHO LexerOutput( yytext, yyleng ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ -\ - if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) LexerError( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 -#define YY_DECL int yyFlexLexer::yylex() -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = & std::cin; - - if ( ! yyout ) - yyout = & std::cout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 36 "test_flexer.ll" - - -#line 601 "test_flexer.ccc" - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 52 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_current_state != 51 ); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 38 "test_flexer.ll" -/* skip blanks and tabs */ - YY_BREAK -case 2: -/* rule 2 can match eol */ -YY_RULE_SETUP -#line 40 "test_flexer.ll" -{ - ++line_num; -} - YY_BREAK -case 3: -YY_RULE_SETUP -#line 44 "test_flexer.ll" -{ - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d number <%s>", line_num, yytext); -} - YY_BREAK -case 4: -YY_RULE_SETUP -#line 48 "test_flexer.ll" -{ - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d name <%s>", line_num, yytext); -} - YY_BREAK -case 5: -YY_RULE_SETUP -#line 52 "test_flexer.ll" -{ - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d string <%s>", line_num, yytext); -} - YY_BREAK -case 6: -YY_RULE_SETUP -#line 56 "test_flexer.ll" -{ - BEGIN(comment); -} - YY_BREAK - -case 7: -YY_RULE_SETUP -#line 61 "test_flexer.ll" - - YY_BREAK -case 8: -/* rule 8 can match eol */ -YY_RULE_SETUP -#line 62 "test_flexer.ll" -++line_num; - YY_BREAK -case 9: -YY_RULE_SETUP -#line 63 "test_flexer.ll" - - YY_BREAK -case 10: -/* rule 10 can match eol */ -YY_RULE_SETUP -#line 64 "test_flexer.ll" -++line_num; - YY_BREAK -case 11: -YY_RULE_SETUP -#line 65 "test_flexer.ll" -BEGIN(INITIAL); - YY_BREAK - -case 12: -YY_RULE_SETUP -#line 68 "test_flexer.ll" -{ - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d word <%s>", line_num, yytext); -} - YY_BREAK -case 13: -YY_RULE_SETUP -#line 72 "test_flexer.ll" -ECHO; - YY_BREAK -#line 736 "test_flexer.ccc" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(comment): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* The contents of this function are C++ specific, so the () macro is not used. - */ -yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout ) -{ - yyin = arg_yyin; - yyout = arg_yyout; - yy_c_buf_p = 0; - yy_init = 0; - yy_start = 0; - yy_flex_debug = 0; - yylineno = 1; // this will only get updated if %option yylineno - - yy_did_buffer_switch_on_eof = 0; - - yy_looking_for_trail_begin = 0; - yy_more_flag = 0; - yy_more_len = 0; - yy_more_offset = yy_prev_more_offset = 0; - - yy_start_stack_ptr = yy_start_stack_depth = 0; - yy_start_stack = NULL; - - yy_buffer_stack = 0; - yy_buffer_stack_top = 0; - yy_buffer_stack_max = 0; - - yy_state_buf = 0; - -} - -/* The contents of this function are C++ specific, so the () macro is not used. - */ -yyFlexLexer::~yyFlexLexer() -{ - delete [] yy_state_buf; - yyfree(yy_start_stack ); - yy_delete_buffer( YY_CURRENT_BUFFER ); - yyfree(yy_buffer_stack ); -} - -/* The contents of this function are C++ specific, so the () macro is not used. - */ -void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out ) -{ - if ( new_in ) - { - yy_delete_buffer( YY_CURRENT_BUFFER ); - yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); - } - - if ( new_out ) - yyout = new_out; -} - -#ifdef YY_INTERACTIVE -int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) -#else -int yyFlexLexer::LexerInput( char* buf, int max_size ) -#endif -{ - if ( yyin->eof() || yyin->fail() ) - return 0; - -#ifdef YY_INTERACTIVE - yyin->get( buf[0] ); - - if ( yyin->eof() ) - return 0; - - if ( yyin->bad() ) - return -1; - - return 1; - -#else - (void) yyin->read( buf, max_size ); - - if ( yyin->bad() ) - return -1; - else - return yyin->gcount(); -#endif -} - -void yyFlexLexer::LexerOutput( const char* buf, int size ) -{ - (void) yyout->write( buf, size ); -} - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -int yyFlexLexer::yy_get_next_buffer() -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - yy_size_t new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - yy_state_type yyFlexLexer::yy_get_previous_state() -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 52 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) -{ - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 52 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 51); - - return yy_is_jam ? 0 : yy_current_state; -} - - void yyFlexLexer::yyunput( int c, register char* yy_bp) -{ - register char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register yy_size_t number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - - int yyFlexLexer::yyinput() -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyFlexLexer::yyrestart( std::istream* input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - - void yyFlexLexer::yy_load_buffer_state() -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( std::istream* file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file ) - -{ - int oerrno = errno; - - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yyFlexLexer::yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -void yyFlexLexer::yyensure_buffer_stack(void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - - void yyFlexLexer::yy_push_state( int new_state ) -{ - if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) - { - yy_size_t new_size; - - (yy_start_stack_depth) += YY_START_STACK_INCR; - new_size = (yy_start_stack_depth) * sizeof( int ); - - if ( ! (yy_start_stack) ) - (yy_start_stack) = (int *) yyalloc(new_size ); - - else - (yy_start_stack) = (int *) yyrealloc((void *) (yy_start_stack),new_size ); - - if ( ! (yy_start_stack) ) - YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); - } - - (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; - - BEGIN(new_state); -} - - void yyFlexLexer::yy_pop_state() -{ - if ( --(yy_start_stack_ptr) < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); -} - - int yyFlexLexer::yy_top_state() -{ - return (yy_start_stack)[(yy_start_stack_ptr) - 1]; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -void yyFlexLexer::LexerError( yyconst char msg[] ) -{ - std::cerr << msg << std::endl; - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 72 "test_flexer.ll" - - - -#include - -int main(int argc, char* argv[]) -{ - U_ULIB_INIT(argv); - - U_TRACE(5, "main(%d)", argc) - - UFlexer flexer; - - flexer.setData(UFile::contentOf(argv[1])); - -#ifdef DEBUG - flexer.test(); -#endif -} - diff --git a/tests/ulib/test_flexer.ll b/tests/ulib/test_flexer.ll deleted file mode 100644 index 2d26b73f..00000000 --- a/tests/ulib/test_flexer.ll +++ /dev/null @@ -1,89 +0,0 @@ -%{ -/* -#define DEBUG_DEBUG -*/ -#undef YY_DECL -#include -#define YY_DECL int UFlexer::yylex(void* yyval) -#define YY_USER_ACTION ((YYSTYPE*)yyval)->ref.offset = parsed_chars; \ - ((YYSTYPE*)yyval)->ref.length = yyleng; parsed_chars += yyleng; \ - ((YYSTYPE*)yyval)->ref.ptr = yytext; - -int line_num = 1; -%} - -%option c++ -%option yyclass="UFlexer" caseless -%option nounput -%option nostack -%option noreject -%option never-interactive -%option noyywrap -%option noyymore - -dig [0-9] -alpha [A-Za-z] -name ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$])* -num1 [-+]?{dig}+\.?([eE][-+]?{dig}+)? -num2 [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)? -number {num1}|{num2} -ws [ \t]+ -word [^ \t\n]+ -string \"[^\n"]+\" - -%x comment - -%% - -{ws} /* skip blanks and tabs */ - -\n { - ++line_num; -} - -{number} { - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d number <%s>", line_num, yytext); -} - -{name} { - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d name <%s>", line_num, yytext); -} - -{string} { - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d string <%s>", line_num, yytext); -} - -"/*" { - BEGIN(comment); -} - -{ - [^*\n]* - [^*\n]*\n ++line_num; - "*"+[^*/\n]* - "*"+[^*/\n]*\n ++line_num; - "*"+"/" BEGIN(INITIAL); -} - -{word} { - U_INTERNAL_TRACE("UFlexer::yylex() line_num = %4d word <%s>", line_num, yytext); -} - -%% - -#include - -int main(int argc, char* argv[]) -{ - U_ULIB_INIT(argv); - - U_TRACE(5, "main(%d)", argc) - - UFlexer flexer; - - flexer.setData(UFile::contentOf(argv[1])); - -#ifdef DEBUG - flexer.test(); -#endif -} diff --git a/tests/ulib/test_vector.cpp b/tests/ulib/test_vector.cpp index 52f0d518..c1ac269b 100644 --- a/tests/ulib/test_vector.cpp +++ b/tests/ulib/test_vector.cpp @@ -5,6 +5,9 @@ #include #include #include +/* +#include +*/ #ifdef __MINGW32__ #define _GLIBCXX_USE_C99_DYNAMIC 1 @@ -235,6 +238,99 @@ static void check_equal() U_ASSERT( b.find(U_STRING_FROM_CONSTANT("rilevazione-virus"), true) == true ) } +/** +static void check_bound(uint32_t last_event_id) +{ + U_TRACE(5,"check_bound(%u)", last_event_id) + + UVector vmessage; + uint32_t i, n, pos, start = 0, end = 0; + UString tmp, message(100U), output(U_CAPACITY); + + for (i = 0, n = vmessage.capacity() * 1.5; i < n; ++i) + { + message.snprintf(U_CONSTANT_TO_PARAM("%u"), i); + + tmp = "*="+message; + + if (end < vmessage.capacity()) vmessage.push_back(tmp); + else + { + ++start; + + vmessage.replace(end % vmessage.capacity(), tmp); + } + + ++end; + } + + if (last_event_id < start) last_event_id = start; + + for (i = last_event_id; i < end; ++i) + { + message = vmessage[i % vmessage.capacity()]; + + pos = message.find('='); + + U_INTERNAL_DUMP("vmessage[%u] = %V pos = %u", i % vmessage.capacity(), message.rep, pos) + + (void) output.append(UServer_Base::printSSE(i+1, message.substr(pos+1), U_NULLPTR)); + } + + cout << vmessage << "\n" << output; + +( *=64 *=65 *=66 *=67 *=68 *=69 *=70 *=71 *=72 *=73 *=74 *=75 *=76 *=77 *=78 *=79 *=80 *=81 *=82 *=83 *=84 *=85 *=86 *=87 *=88 *=89 *=90 *=91 *=92 *=93 *=94 *=95 *=32 *=33 *=34 *=35 *=36 *=37 *=38 *=39 *=40 *=41 *=42 *=43 *=44 *=45 *=46 *=47 *=48 *=49 *=50 *=51 *=52 *=53 *=54 *=55 *=56 *=57 *=58 *=59 *=60 *=61 *=62 *=63 ) + +id:81 +data:80 + +id:82 +data:81 + +id:83 +data:82 + +id:84 +data:83 + +id:85 +data:84 + +id:86 +data:85 + +id:87 +data:86 + +id:88 +data:87 + +id:89 +data:88 + +id:90 +data:89 + +id:91 +data:90 + +id:92 +data:91 + +id:93 +data:92 + +id:94 +data:93 + +id:95 +data:94 + +id:96 +data:95 +} +*/ + int U_EXPORT main (int argc, char* argv[]) { @@ -242,6 +338,11 @@ U_EXPORT main (int argc, char* argv[]) U_TRACE(5,"main(%d)",argc) + /* + check_bound(80); + exit(0); + */ + UString tmp; #if defined(U_STDCPP_ENABLE) && defined(HAVE_CXX11) && defined(U_COMPILER_RANGE_FOR) @@ -325,7 +426,7 @@ U_EXPORT main (int argc, char* argv[]) // EXTENSION { - UDirWalk dirwalk(0, U_CONSTANT_TO_PARAM("?db.*test*")); + UDirWalk dirwalk(U_NULLPTR, U_CONSTANT_TO_PARAM("?db.*test*")); n = dirwalk.walk(y); diff --git a/tests/ulib/vector.test b/tests/ulib/vector.test index ed9bdc98..dccf1e5a 100755 --- a/tests/ulib/vector.test +++ b/tests/ulib/vector.test @@ -6,15 +6,15 @@ start_msg vector -#UTRACE="0 50M -1" +#UTRACE="0 50M 0" #UOBJDUMP="0 1M 10" #USIMERR="error.sim" export UTRACE UOBJDUMP USIMERR start_prg vector inp/words.lst < inp/vector.input -tr ' ' '\n' < vector.sort > word.sort -rm -f vector.sort + tr ' ' '\n' < vector.sort > word.sort + rm -f vector.sort # Test against expected output test_output_diff vector word.sort