mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
hide old rewrite
This commit is contained in:
parent
4cf112c2f0
commit
13162b1665
1 changed files with 16 additions and 17 deletions
|
@ -1,5 +1,4 @@
|
||||||
// vim:foldmethod=marker:syntax=lpc:noexpandtab
|
// vim:foldmethod=marker:syntax=lpc:noexpandtab
|
||||||
// $Id: parse.c,v 1.30 2008/12/18 18:16:14 lynx Exp $
|
|
||||||
|
|
||||||
#include "psyc.h"
|
#include "psyc.h"
|
||||||
#ifdef LIBPSYC // net/spyc currently doesn't work without libpsyc
|
#ifdef LIBPSYC // net/spyc currently doesn't work without libpsyc
|
||||||
|
@ -12,7 +11,7 @@ private string buffer;
|
||||||
int state;
|
int state;
|
||||||
int may_parse_more;
|
int may_parse_more;
|
||||||
|
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC // {{{
|
||||||
private string body_buffer;
|
private string body_buffer;
|
||||||
int body_len;
|
int body_len;
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ mapping hvars;
|
||||||
// prototypes
|
// prototypes
|
||||||
parse_header();
|
parse_header();
|
||||||
buffer_content();
|
buffer_content();
|
||||||
#endif // LIBPSYC
|
#endif // }}} LIBPSYC
|
||||||
|
|
||||||
// being faded out in favor of regular croak()
|
// being faded out in favor of regular croak()
|
||||||
#define PARSEERROR(reason) { \
|
#define PARSEERROR(reason) { \
|
||||||
|
@ -46,7 +45,7 @@ step(); // prototype
|
||||||
// overload this as needed
|
// overload this as needed
|
||||||
varargs mixed croak(string mc, string data, vamapping vars) { return 0; }
|
varargs mixed croak(string mc, string data, vamapping vars) { return 0; }
|
||||||
|
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC //{{{
|
||||||
// reset parser state
|
// reset parser state
|
||||||
void parser_reset() {
|
void parser_reset() {
|
||||||
if (state != PSYCPARSE_STATE_BLOCKED)
|
if (state != PSYCPARSE_STATE_BLOCKED)
|
||||||
|
@ -57,13 +56,13 @@ void parser_reset() {
|
||||||
tvars = ({ });
|
tvars = ({ });
|
||||||
hvars = ([ ]);
|
hvars = ([ ]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif //}}}
|
||||||
|
|
||||||
// initialize the parser
|
// initialize the parser
|
||||||
void parser_init() {
|
void parser_init() {
|
||||||
# ifndef LIBPSYC
|
# ifndef LIBPSYC //{{{
|
||||||
parser_reset();
|
parser_reset();
|
||||||
# endif
|
# endif //}}}
|
||||||
buffer = "";
|
buffer = "";
|
||||||
state = PSYCPARSE_STATE_GREET; // AFTER reset
|
state = PSYCPARSE_STATE_GREET; // AFTER reset
|
||||||
}
|
}
|
||||||
|
@ -80,9 +79,9 @@ void resume_parse() {
|
||||||
|
|
||||||
// called when a complete packet has arrived
|
// called when a complete packet has arrived
|
||||||
void dispatch(mapping rvars, mapping evars, mixed method, mixed body) {
|
void dispatch(mapping rvars, mapping evars, mixed method, mixed body) {
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC //{{{
|
||||||
parser_reset();
|
parser_reset();
|
||||||
#endif
|
#endif //}}}
|
||||||
}
|
}
|
||||||
|
|
||||||
void psyc_dispatch(mixed p) {
|
void psyc_dispatch(mixed p) {
|
||||||
|
@ -109,13 +108,13 @@ void feed(string data) {
|
||||||
|
|
||||||
buffer += data;
|
buffer += data;
|
||||||
|
|
||||||
# ifndef LIBPSYC
|
# ifndef LIBPSYC //{{{
|
||||||
do {
|
do {
|
||||||
may_parse_more = 0;
|
may_parse_more = 0;
|
||||||
step();
|
step();
|
||||||
} while (may_parse_more);
|
} while (may_parse_more);
|
||||||
|
|
||||||
# else
|
# else //}}}
|
||||||
if (state != PSYCPARSE_STATE_HEADER)
|
if (state != PSYCPARSE_STATE_HEADER)
|
||||||
step();
|
step();
|
||||||
|
|
||||||
|
@ -158,14 +157,14 @@ void step() {
|
||||||
if (!strlen(buffer))
|
if (!strlen(buffer))
|
||||||
return;
|
return;
|
||||||
switch(state) {
|
switch(state) {
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC //{{{
|
||||||
case PSYCPARSE_STATE_HEADER:
|
case PSYCPARSE_STATE_HEADER:
|
||||||
parse_header();
|
parse_header();
|
||||||
break;
|
break;
|
||||||
case PSYCPARSE_STATE_CONTENT:
|
case PSYCPARSE_STATE_CONTENT:
|
||||||
buffer_content();
|
buffer_content();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif //}}}
|
||||||
case PSYCPARSE_STATE_BLOCKED:
|
case PSYCPARSE_STATE_BLOCKED:
|
||||||
// someone requested to stop parsing - e.g. _request_features circuit
|
// someone requested to stop parsing - e.g. _request_features circuit
|
||||||
// message
|
// message
|
||||||
|
@ -177,9 +176,9 @@ void step() {
|
||||||
state = PSYCPARSE_STATE_HEADER;
|
state = PSYCPARSE_STATE_HEADER;
|
||||||
buffer = buffer[2 ..];
|
buffer = buffer[2 ..];
|
||||||
first_response();
|
first_response();
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC //{{{
|
||||||
step();
|
step();
|
||||||
#endif
|
#endif //}}}
|
||||||
} else {
|
} else {
|
||||||
croak("_error_syntax_initialization");
|
croak("_error_syntax_initialization");
|
||||||
// "The new protocol begins with a pipe and a line feed.");
|
// "The new protocol begins with a pipe and a line feed.");
|
||||||
|
@ -192,7 +191,7 @@ void step() {
|
||||||
|
|
||||||
// EOF for LIBPSYC
|
// EOF for LIBPSYC
|
||||||
|
|
||||||
#ifndef LIBPSYC
|
#ifndef LIBPSYC //{{{
|
||||||
// processes routing header variable assignments
|
// processes routing header variable assignments
|
||||||
// basic version does no state
|
// basic version does no state
|
||||||
mapping process_header(mixed varops) {
|
mapping process_header(mixed varops) {
|
||||||
|
@ -478,6 +477,6 @@ test() {
|
||||||
list_parse("5\tabcde|4\tabcd");
|
list_parse("5\tabcde|4\tabcd");
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
#endif // !LIBPSYC
|
#endif // !LIBPSYC //}}}
|
||||||
|
|
||||||
#endif // LIBPSYC
|
#endif // LIBPSYC
|
||||||
|
|
Loading…
Reference in a new issue