glue for libpsyc

This commit is contained in:
psyc://psyced.org/~lynX 2011-04-25 22:59:53 +02:00
parent a8fe8e1f3e
commit b97ea34912
7 changed files with 224 additions and 16 deletions

View File

@ -104,7 +104,7 @@ SRC = access_check.c actions.c array.c backend.c bitstrings.c call_out.c \
lex.c main.c mapping.c md5.c mempools.c mregex.c mstrings.c object.c \
otable.c\
parser.c parse.c pkg-alists.c pgk-iksemel.c pkg-idna.c pkg-expat.c \
pkg-mccp.c pkg-mysql.c pkg-pcre.c \
pkg-psyc.c pkg-mccp.c pkg-mysql.c pkg-pcre.c \
pkg-pgsql.c pkg-sqlite.c pkg-tls.c \
ptmalloc.c port.c ptrtable.c \
random.c regexp.c sha1.c simulate.c simul_efun.c stdstrings.c \
@ -116,7 +116,7 @@ OBJ = access_check.o actions.o array.o backend.o bitstrings.o call_out.o \
lex.o main.o mapping.o md5.o mempools.o mregex.o mstrings.o object.o \
otable.o \
parser.o parse.o pkg-alists.o pkg-iksemel.o pkg-idna.o pkg-expat.o \
pkg-mccp.o pkg-mysql.o pkg-pcre.o \
pkg-psyc.o pkg-mccp.o pkg-mysql.o pkg-pcre.o \
pkg-pgsql.o pkg-sqlite.o pkg-tls.o \
ptmalloc.o port.o ptrtable.o \
random.o regexp.o sha1.o simulate.o simul_efun.o stdstrings.o \

View File

@ -117,6 +117,7 @@ AC_MY_ARG_ENABLE(use-system-crypt,yes,,)
AC_MY_ARG_ENABLE(udp-send,yes,,)
AC_MY_ARG_ENABLE(use-ipv6,no,,[Enables support for IPv6])
AC_MY_ARG_ENABLE(use-alists,no,,[Enables alist support])
AC_MY_ARG_ENABLE(use-psyc,no,,[Enables libpsyc support])
AC_MY_ARG_ENABLE(use-mccp,no,,[Enables MCCP support])
AC_MY_ARG_ENABLE(use-mysql,no,,[Enables mySQL support])
AC_MY_ARG_ENABLE(use-pgsql,no,,[Enables PostgreSQL support])
@ -346,18 +347,18 @@ else
enable_use_sqlite="yes"
fi
AC_UPDATE_VAR(enable_use_iksemel)
if test "x$enable_use_iksemel" = "x" || test "x$enable_use_iksemel" = "xyes"; then
cdef_use_iksemel="#define"
iksemel_path=
enable_use_iksemel="yes"
elif test "x$enable_use_iksemel" = "xno"; then
cdef_use_iksemel="#undef"
iksemel_path=
AC_UPDATE_VAR(enable_use_psyc)
if test "x$enable_use_psyc" = "x" || test "x$enable_use_psyc" = "xyes"; then
cdef_use_psyc="#define"
psyc_path=
enable_use_psyc="yes"
elif test "x$enable_use_psyc" = "xno"; then
cdef_use_psyc="#undef"
psyc_path=
else
cdef_use_iksemel="#define"
iksemel_path="$enable_use_iksemel"
enable_use_iksemel="yes"
cdef_use_psyc="#define"
psyc_path="$enable_use_psyc"
enable_use_psyc="yes"
fi
AC_UPDATE_VAR(enable_use_json)
@ -388,6 +389,20 @@ else
enable_use_expat="yes"
fi
AC_UPDATE_VAR(enable_use_psyc)
if test "x$enable_use_psyc" = "x" || test "x$enable_use_psyc" = "xyes"; then
cdef_use_psyc="#define"
psyc_path=
enable_use_psyc="yes"
elif test "x$enable_use_psyc" = "xno"; then
cdef_use_psyc="#undef"
psyc_path=
else
cdef_use_psyc="#define"
psyc_path="$enable_use_psyc"
enable_use_psyc="yes"
fi
AC_UPDATE_VAR(enable_use_iksemel)
if test "x$enable_use_iksemel" = "x" || test "x$enable_use_iksemel" = "xyes"; then
cdef_use_iksemel="#define"
@ -1199,14 +1214,45 @@ else
enable_use_pthreads=no
fi
# --- libpsyc ---
lp_cv_has_psyc_lib="no"
AC_CHECK_LIB(psyc,main, lp_cv_has_psyc_lib="yes")
if test $lp_cv_has_psyc_lib = yes; then
LIBS="-lpsyc"
AC_CACHE_CHECK(for libpsyc usability,lp_cv_has_psyc,
AC_TRY_RUN([
#include <psyc.h>
int main(void) {
(void) PSYC_version();
return 0;
}
],
lp_cv_has_psyc=yes,
lp_cv_has_psyc=no
))
CFLAGS="$saveflags"
if test $lp_cv_has_psyc = yes; then
AC_DEFINE(HAS_PSYC, 1, [Does the machine offer libpsyc?])
PKGLIBS="$PKGLIBS -lpsyc"
echo "Congrats! libpsyc is available on this system."
else
echo "libpsyc not available on this system yet."
fi
fi
# --- PCRE ---
lp_cv_has_pcre_lib="no"
AC_CHECK_LIB(pcre,main, lp_cv_has_pcre_lib="yes")
if test $lp_cv_has_pcre_lib = yes; then
saveflags="$CFLAGS"
CFLAGS="$CFLAGS -lpcre"
# saveflags="$CFLAGS"
# CFLAGS="$CFLAGS -lpcre"
LIBS="-lpcre"
AC_CACHE_CHECK(for PCRE usability,lp_cv_has_pcre,
AC_TRY_RUN([
#include <pcre.h>
@ -2871,6 +2917,7 @@ AC_SUBST(cdef_use_sqlite)
AC_SUBST(cdef_use_iksemel)
AC_SUBST(cdef_use_pthreads)
AC_SUBST(cdef_use_alists)
AC_SUBST(cdef_use_psyc)
AC_SUBST(cdef_use_mccp)
AC_SUBST(cdef_use_pcre)
AC_SUBST(cdef_use_builtin_pcre)

View File

@ -338,6 +338,10 @@
*/
@cdef_use_system_crypt@ USE_SYSTEM_CRYPT
/* Define this if you want enhanced PSYC support (libpsyc)
*/
@cdef_use_psyc@ USE_PSYC
/* Define this if you want MCCP (Mud Control Compression Protocol).
*/
@cdef_use_mccp@ USE_MCCP

View File

@ -605,6 +605,11 @@ int attach_erq_demon(object|string, int default: F_CONST0);
int send_erq(int, int*|string, null|closure default: F_CONST0);
#endif
#ifdef USE_PSYC
mixed psyc_parse(int* | string);
string psyc_render(mapping, mapping, string, int* | string);
#endif /* USE_PSYC */
/* Files */

149
src/pkg-psyc.c Normal file
View File

@ -0,0 +1,149 @@
/*------------------------------------------------------------------
* Glue for libpsyc.
*------------------------------------------------------------------
* func_spec for this:
*
mixed psyc_parse(int* | string);
string psyc_render(mapping, mapping, string, int* | string);
*
*------------------------------------------------------------------
* test LPC code:
// doesn't work with (int *) yet
mixed x = psyc_parse(":_context\ttest\n\n:_topic\ttesting\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n");
mixed y = psyc_render(([ "_context": "test" ]), ([ "_topic": "testing" ]), "_notice_test_libpsyc", "Just [_topic] libpsyc.");
debug_message(sprintf("libpsyc returned %O and %O\n", x, y));
*/
#include "array.h"
#include "interpret.h"
#include "mstrings.h"
#include "simulate.h"
#include <psyc.h>
#include <psyc/parser.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef USE_PSYC
/*-------------------------------------------------------------------------*/
// string psyc_render(mapping, mapping, string, int* | string);
svalue_t *
f_psyc_render(svalue_t *sp) {
free_svalue(sp--);
free_svalue(sp--);
free_svalue(sp--);
free_svalue(sp--);
/*
printf("rendering... not yet\n");
string_t *out;
memsafe(
// out = alloc_mstring(5), 5,
out = new_mstring("PSYC"), 5,
"f_psyc_render test");
put_string(sp, out);
*/
put_c_string(++sp, "PSYC");
return sp;
} /* f_psyc_render */
/*-------------------------------------------------------------------------*/
// mixed psyc_parse(int* | string);
svalue_t *
f_psyc_parse (svalue_t *sp) {
mp_int i;
PSYC_String name, value, elem;
PSYC_ParseState state;
PSYC_ParseListState listState;
char oper;
int ret;
PSYC_initParseState(&state);
i = 0;
if (sp->type == T_POINTER) {
if ((i = (mp_int)VEC_SIZE(sp->u.vec)) > 32) {
errorf("Bad arg 1 to psyc_parse(): int[] too long (%"PRIdMPINT")\n"
, i);
/* NOTREACHED */
return sp;
}
printf("\nparsing %ld bytes... not yet\n", i);
}
else if (sp->type == T_STRING) {
printf("\nparsing '%s'...\n", get_txt(sp->u.str));
PSYC_nextParseBuffer(&state, PSYC_newString(get_txt(sp->u.str),
mstrsize(sp->u.str)));
}
do {
ret = PSYC_parse(&state, &oper, &name, &value);
switch (ret) {
case PSYC_PARSE_ROUTING:
case PSYC_PARSE_ENTITY:
write(1, "\t", 1);
write(1, &oper, 1);
case PSYC_PARSE_BODY:
// printf("the string is '%.*s'\n", name);
write(1, name.ptr, name.length);
write(1, " = ", 3);
write(1, value.ptr, value.length);
write(1, "\n", 1);
if (memcmp(name.ptr, "_list", 5) == 0)
{
write(1, ">>> LIST START\n", 15);
PSYC_initParseListState(&listState);
PSYC_nextParseListBuffer(&listState, value);
while ((ret = PSYC_parseList(&listState, &name, &value, &elem)))
{
switch (ret)
{
case PSYC_PARSE_LIST_END:
case PSYC_PARSE_LIST_ELEM:
write(1, "|", 1);
write(1, elem.ptr, elem.length);
write(1, "\n", 1);
break;
default:
errorf("Error while parsing PSYC list: %i\n", ret);
/* NOTREACHED */
return sp;
}
if (ret == PSYC_PARSE_LIST_END)
{
write(1, ">>> LIST END\n", 13);
break;
}
}
}
break;
case PSYC_PARSE_COMPLETE:
printf("Done parsing.\n");
ret = 0;
break;
case PSYC_PARSE_INSUFFICIENT:
errorf("Insufficient PSYC data.\n");
/* NOTREACHED */
return sp;
default:
errorf("Error while parsing PSYC: %i\n", ret);
/* NOTREACHED */
return sp;
}
} while (ret);
free_svalue(sp);
put_number(sp, 4404); // push a test rc
return sp;
} /* f_psyc_parse */
#endif /* USE_PSYC */

View File

@ -121,6 +121,9 @@ enable_use_mysql=no
enable_use_pgsql=no
enable_use_sqlite=no
# NEW: libpsyc support
enable_use_psyc=yes
# maximum permitted tcp connections
with_max_players=900

View File

@ -17,7 +17,7 @@ version_longtype="stable"
# A timestamp, to be used by bumpversion and other scripts.
# It can be used, for example, to 'touch' this file on every build, thus
# forcing revision control systems to add it on every checkin automatically.
version_stamp="Mon Jun 21 13:52:21 CEST 2010"
version_stamp="Mon Apr 25 22:51:12 CEST 2011"
# Okay, LDMUD is using 3.x.x so to avoid conflicts let's just use 4.x.x
version_major=4