]> granicus.if.org Git - php/commitdiff
- Added additional DEFER macro.
authorKristian Köhntopp <kk@php.net>
Sat, 11 Mar 2000 22:05:41 +0000 (22:05 +0000)
committerKristian Köhntopp <kk@php.net>
Sat, 11 Mar 2000 22:05:41 +0000 (22:05 +0000)
- First stab at porting the recode module. Still having problems
  with the _ex() functions, they core - why?

acinclude.m4
ext/recode/Makefile.in [new file with mode: 0644]
ext/recode/config.m4 [new file with mode: 0644]
ext/recode/php_recode.h [new file with mode: 0644]
ext/recode/recode.c [new file with mode: 0644]
ext/recode/setup.stub [new file with mode: 0644]

index 7b5f4c6c6045394806d75dc4cb32a17580603b8d..7aa50266f28b8e338ad3a12731dcb3e4b38e9206 100644 (file)
@@ -295,7 +295,7 @@ AC_DEFUN(AC_ADD_LIBRARY,[
 dnl
 dnl AC_ADD_LIBRARY_DEFER(library[, append])
 dnl
-dnl add a library to the link line (defferred)
+dnl add a library to the link line (deferred)
 AC_DEFUN(AC_ADD_LIBRARY_DEFER,[
   AC_PHP_ONCE(LIBRARY, $1, [
     ifelse($#, 1, DLIBS="-l$1 $DLIBS", DLIBS="$DLIBS -l$1")
@@ -312,6 +312,16 @@ AC_DEFUN(AC_ADD_LIBRARY_WITH_PATH,[
   AC_ADD_LIBRARY($1)
 ])
 
+dnl
+dnl AC_ADD_LIBRARY_DEFER_WITH_PATH(library, path)
+dnl
+dnl add a library to the link line (deferred)
+dnl and path to linkpath/runpath (not deferred)
+dnl
+AC_DEFUN(AC_ADD_LIBRARY_DEFER_WITH_PATH,[
+  AC_ADD_LIBPATH($2)
+  AC_ADD_LIBRARY_DEFER($1)
+])
 
 AC_DEFUN(AM_SET_LIBTOOL_VARIABLE,[
   LIBTOOL='$(SHELL) $(top_builddir)/libtool $1'
diff --git a/ext/recode/Makefile.in b/ext/recode/Makefile.in
new file mode 100644 (file)
index 0000000..c754c54
--- /dev/null
@@ -0,0 +1,10 @@
+
+DEPTH     = ../..
+topsrcdir = @topsrcdir@
+srcdir    = @srcdir@
+VPATH     = @srcdir@
+
+LTLIBRARY_NAME    = librecode.la
+LTLIBRARY_SOURCES = recode.c
+
+include $(topsrcdir)/build/ltlib.mk
diff --git a/ext/recode/config.m4 b/ext/recode/config.m4
new file mode 100644 (file)
index 0000000..992a79e
--- /dev/null
@@ -0,0 +1,65 @@
+dnl $Id$
+dnl config.m4 for extension recode
+dnl don't forget to call PHP_EXTENSION(recode)
+
+
+AC_MSG_CHECKING(for recode support)
+AC_ARG_WITH(recode,
+[       --with-recode[=DIR]    Include recode support.  DIR is the recode
+                                                                                                       install directory.],
+[
+       if test "$withval" != "no"; then
+               RECODE_LIST="$withval /usr /usr/local /opt"
+
+               for i in $RECODE_LIST; do
+                       if test -f $i/include/recode.h; then
+                               RECODE_DIR=$i
+                               RECODE_INC=include
+                               RECODE_LIB=lib
+                       fi
+                       if test -f $i/include/recode/recode.h; then
+                               RECODE_DIR=$i
+                               RECODE_INC=include/recode
+                               RECODE_LIB=lib/recode
+                       fi
+                       if test -f $i/recode/include/recode.h; then
+                               RECODE_DIR=$i/recode
+                               RECODE_INC=include
+                               RECODE_LIB=lib
+                       fi
+               done
+               if test "$RECODE_DIR" = ""; then
+                       AC_MSG_ERROR(I cannot find recode.h anywhere below $RECODE_LIST. Is it installed?)
+               fi
+
+               old_LDFLAGS="$LDFLAGS"
+               old_LIBS="$LIBS"
+               LDFLAGS="$LDFLAGS -L$RECODE_DIR/$RECODE_LIB"
+               LIBS="$LIBS -lrecode"
+               AC_TRY_LINK([
+char *program_name;
+],[
+recode_format_table();
+],[],[
+                               AC_MSG_ERROR(I cannot link librecode (-L$RECODE_DIR/$RECODE_LIB -lrecode). Is it installed?)
+])
+               LIBS="$old_LIBS"
+               LDFLAGS="$old_LDFLAGS"
+
+               if test "$RECODE_LIB" = ""; then
+                       AC_MSG_ERROR(Please reinstall recode - I cannot find librecode.a)
+               fi
+
+               AC_ADD_INCLUDE($RECODE_DIR/$RECODE_INC)
+               AC_ADD_LIBRARY_DEFER_WITH_PATH(recode, $RECODE_DIR/$RECODE_LIB)
+
+               AC_MSG_RESULT(yes)
+
+               AC_DEFINE(HAVE_LIBRECODE, 1, [Whether we have librecode 3.5 or higher])
+               PHP_EXTENSION(recode)
+       else
+               AC_MSG_RESULT(no)
+       fi
+],[
+       AC_MSG_RESULT(no)
+])
diff --git a/ext/recode/php_recode.h b/ext/recode/php_recode.h
new file mode 100644 (file)
index 0000000..8ff641e
--- /dev/null
@@ -0,0 +1,89 @@
+/* 
+   +----------------------------------------------------------------------+
+   | PHP version 4.0                                                                                                     |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                                          |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 2.01 of the PHP license,     |
+   | that is bundled with this package in the file LICENSE, and is               |
+   | available at through the world-wide-web at                                                          |
+   | http://www.php.net/license/2_01.txt.                                                                |
+   | If you did not receive a copy of the PHP license and are unable to          |
+   | obtain it through the world-wide-web, please send a note to                 |
+   | license@php.net so we can mail you a copy immediately.                              |
+   +----------------------------------------------------------------------+
+   | Authors: Kristian Koehntopp (kris@koehntopp.de)                                     |
+   +----------------------------------------------------------------------+
+ */
+
+
+/* $Id$ */
+
+#ifndef _PHP_RECODE_H
+#define _PHP_RECODE_H
+
+#ifdef COMPILE_DL_RECODE
+#undef HAVE_LIBRECODE
+#define HAVE_LIBRECODE 1
+#endif
+
+#ifdef PHP_WIN32
+#define PHP_MYSQL_API __declspec(dllexport)
+#else
+#define PHP_MYSQL_API
+#endif
+
+#if HAVE_LIBRECODE
+
+/* Checking for thread safety and issue warning if necessary. */
+#ifdef ZTS
+#warning Recode module has not been tested for thread-safety.
+#endif
+
+/* Recode 3.5 is broken in the sense that it requires the definition
+ * of a symbol "program_name" in order to link.
+ */
+#define HAVE_BROKEN_RECODE
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <recode.h>
+#include <unistd.h>
+
+extern zend_module_entry recode_module_entry;
+#define phpext_recode_ptr &recode_module_entry
+
+extern PHP_MINIT_FUNCTION(recode);
+extern PHP_MSHUTDOWN_FUNCTION(recode);
+extern PHP_MINFO_FUNCTION(recode);
+
+extern PHP_FUNCTION(recode_string);
+extern PHP_FUNCTION(recode_file);
+
+typedef struct {
+       RECODE_OUTER   outer;
+} php_recode_globals;
+
+#ifdef ZTS
+# define ReSLS_D       php_recode_globals *recode_globals
+# define ReSLS_DC      , ReSLS_D
+# define ReSLS_C       recode_globals
+# define ReSLS_CC , ReSLS_C
+# define ReSG(v) (recode_globals->v)
+# define ReSLS_FETCH() php_recode_globals *recode_globals = ts_resource(recode_globals_id)
+#else
+# define ReSLS_D
+# define ReSLS_DC
+# define ReSLS_C
+# define ReSLS_CC
+# define ReSG(v) (recode_globals.v)
+# define ReSLS_FETCH()
+extern PHP_MYSQL_API php_recode_globals recode_globals;
+#endif
+
+#else
+#define phpext_recode_ptr NULL
+#endif
+
+#endif /* _PHP_RECODE_H */
diff --git a/ext/recode/recode.c b/ext/recode/recode.c
new file mode 100644 (file)
index 0000000..0756303
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP version 4.0                                                                                                     |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                                          |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 2.01 of the PHP license,     |
+   | that is bundled with this package in the file LICENSE, and is               |
+   | available at through the world-wide-web at                                                          |
+   | http://www.php.net/license/2_01.txt.                                                                |
+   | If you did not receive a copy of the PHP license and are unable to          |
+   | obtain it through the world-wide-web, please send a note to                 |
+   | license@php.net so we can mail you a copy immediately.                              |
+   +----------------------------------------------------------------------+
+   | Authors: Kristian Koehntopp (kris@koehntopp.de)                                     |
+   +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+/* {{{ includes & prototypes */
+
+#include "php.h"
+#include "php_recode.h"
+
+#if HAVE_LIBRECODE
+#include "ext/standard/info.h"
+#include "ext/standard/php_string.h"
+#include "zend_list.h"
+
+#ifdef HAVE_BROKEN_RECODE
+extern char *program_name;
+char *program_name = "php";
+#endif
+
+/* }}} */
+
+#define SAFE_STRING(s) ((s)?(s):"")
+
+php_recode_globals recode_globals;
+extern int le_fp,le_pp;
+
+/* {{{ module stuff */
+static zend_function_entry php_recode_functions[] = {
+       PHP_FE(recode_string, NULL)
+       PHP_FE(recode_file, NULL)
+       PHP_FALIAS(recode, recode_string, NULL)
+       {NULL, NULL, NULL}
+};
+
+zend_module_entry recode_module_entry = {
+       "Recode", 
+       php_recode_functions, 
+       PHP_MINIT(recode), 
+       PHP_MSHUTDOWN(recode), 
+       NULL,
+       NULL, 
+       PHP_MINFO(recode), 
+       STANDARD_MODULE_PROPERTIES
+};
+
+#if APACHE
+extern void timeout(int sig);
+#endif
+
+PHP_MINIT_FUNCTION(recode)
+{
+       ReSLS_FETCH();
+       ReSG(outer)       = recode_new_outer(true);
+       if (ReSG(outer) == NULL)
+               return FAILURE;
+       
+       return SUCCESS;
+}
+
+
+PHP_MSHUTDOWN_FUNCTION(recode)
+{
+       ReSLS_FETCH();
+
+       if (ReSG(outer))
+               recode_delete_outer(ReSG(outer));
+
+       return SUCCESS;
+}
+
+
+PHP_MINFO_FUNCTION(recode)
+{
+       ReSLS_FETCH();
+
+       php_printf("<table border=5 width=\"600\">");
+       php_info_print_table_header(1, "Module Revision");
+       php_info_print_table_row(1, "$Revision$");
+       php_printf("</table>\n");
+}
+
+/* {{{ proto string recode_string(string request, string str)
+   Recode string str according to request string */
+
+PHP_FUNCTION(recode_string)
+{
+/*     All of this cores in zend_get_parameters_ex()...
+
+       RECODE_REQUEST request = NULL;
+       pval **str;
+       pval **req;
+       char  *r;
+       bool   success;
+       
+       ReSLS_FETCH();
+       if (ARG_COUNT(ht) != 2
+        || zend_get_parameters_ex(ht, 2, &req, &str) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+       convert_to_string_ex(str);
+       convert_to_string_ex(req);
+*/
+
+       RECODE_REQUEST request = NULL;
+       char *r = NULL;
+       pval *str;
+       pval *req;
+       bool  success;
+       
+       ReSLS_FETCH();
+       if (ARG_COUNT(ht) != 2
+        || zend_get_parameters(ht, 2, &req, &str) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+       convert_to_string(str);
+       convert_to_string(req);
+
+       request = recode_new_request(ReSG(outer));
+       if (request == NULL) {
+               php_error(E_WARNING, "Cannot allocate request structure");
+               RETURN_FALSE;
+       }
+       
+       success = recode_scan_request(request, req->value.str.val);
+       if (!success) {
+               php_error(E_WARNING, "Illegal recode request '%s'", req->value.str.val);
+               goto error_exit;
+       }
+       
+       r = recode_string(request, str->value.str.val);
+       if (!r) {
+               php_error(E_WARNING, "Recoding failed.");
+               goto error_exit;
+       }
+       
+       RETVAL_STRING(r, 1);
+       free(r);
+       /* FALLTHROUGH */
+
+error_exit:
+       if (request)
+               recode_delete_request(request);
+
+       if (!r) 
+               RETURN_FALSE;
+
+       return;
+}
+/* }}} */
+
+/* {{{ proto bool recode_file(string request, int input, int output)
+   Recode file input into file output according to request */
+PHP_FUNCTION(recode_file)
+{
+       php_error(E_WARNING, "This has not been ported, yet");
+       RETURN_FALSE;
+}
+/* }}} */
+
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ext/recode/setup.stub b/ext/recode/setup.stub
new file mode 100644 (file)
index 0000000..07bf5d9
--- /dev/null
@@ -0,0 +1,3 @@
+define_option with-recode 'GNU-Recode support?' yesnodir no \
+'    Whether to build the recode extension.'
+