sas             Sun Sep 29 12:22:50 2002 EDT

  Added files:                 
    /php4/sapi/cgi      Makefile.frag 
    /php4/sapi/cli      Makefile.frag 
    /php4/sapi/embed    config.m4 php_embed.c php_embed.h 
    /php4/sapi/fastcgi  Makefile.frag 

  Removed files:               
    /php4/main  php_embed.c php_embed.h 

  Modified files:              
    /php4       Makefile.global acinclude.m4 configure.in 
    /php4/sapi/cgi      config.m4 
    /php4/sapi/cli      config.m4 
    /php4/sapi/fastcgi  config.m4 
    /php4/win32 phpembed.dsp 
  Log:
  Follow Yasuo's suggestion and build sapi program's under the sapi-specific
  directory.
  
  Move sapi-specific makefile fragments to their respective directory.
  
  Create an embed sapi module which resides in its own dir now.
  
  
Index: php4/Makefile.global
diff -u php4/Makefile.global:1.25 php4/Makefile.global:1.26
--- php4/Makefile.global:1.25   Sat Sep 28 22:45:24 2002
+++ php4/Makefile.global        Sun Sep 29 12:22:47 2002
@@ -16,25 +16,7 @@
 libs/libphp4.bundle: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
        $(CC) $(MH_BUNDLE_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) 
$(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) 
$(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ libs/libphp4.so
 
-php: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
-       $(BUILD_CGI)
-       
-sapi/cli/php: $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS)
-       $(BUILD_CLI)
-
-libphp.la: $(PHP_LIB_OBJS)
-       $(LIBTOOL) --mode=link $(CC) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) 
$(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) $(PHP_LIB_OBJS) $(EXTRA_LIBS) 
$(ZEND_EXTRA_LIBS) -o $@
-
-libphp.so: $(PHP_LIB_OBJS)
-       $(LIBTOOL) --mode=link $(CC) -shared -export-dynamic $(COMMON_FLAGS) 
$(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS) $(PHP_RPATHS) 
$(PHP_LIB_OBJS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ .libs
-
-libs: libphp.la libphp.so
-
-install: $(install_targets) 
-
-install-cli: sapi/cli/php
-       @echo "Installing PHP CLI binary:        $(INSTALL_ROOT)$(bindir)/"
-       @$(INSTALL_CLI)
+install: $(install_targets)
 
 install-sapi: libphp4.la
        @echo "Installing PHP SAPI module"
@@ -64,14 +46,14 @@
 
 install-su: install-pear install-tester
 
-test: sapi/cli/php
-       @TEST_PHP_EXECUTABLE=$(top_builddir)/sapi/cli/php \
-                       $(top_builddir)/sapi/cli/php -c php.ini-dist 
$(top_srcdir)/run-tests.php $(TESTS)
+test: $(SAPI_CLI_PHP)
+       @TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PHP) \
+                       $(top_builddir)/$(SAPI_CLI_PHP) -c php.ini-dist 
+$(top_srcdir)/run-tests.php $(TESTS)
 
 clean:
        find . -name \*.lo -o -name \*.o -o -name \*.la -o -name \*.a -o -name \*.so| 
xargs rm -f
        find . -name .libs -a -type d|xargs rm -rf
-       rm -f libphp4.la php sapi/cli/php modules/* libs/*
+       rm -f libphp4.la $(SAPI_CLI_PHP) $(SAPI_CGI_PHP) modules/* libs/*
 
 distclean: clean
        rm -f config.cache config.log config.status Makefile.objects 
Makefile.fragments libtool main/php_config.h stamp-h php4.spec 
sapi/apache/libphp4.module buildmk.stamp
Index: php4/acinclude.m4
diff -u php4/acinclude.m4:1.205 php4/acinclude.m4:1.206
--- php4/acinclude.m4:1.205     Fri Sep  6 06:27:26 2002
+++ php4/acinclude.m4   Sun Sep 29 12:22:47 2002
@@ -1,4 +1,4 @@
-dnl $Id: acinclude.m4,v 1.205 2002/09/06 10:27:26 sas Exp $
+dnl $Id: acinclude.m4,v 1.206 2002/09/29 16:22:47 sas Exp $
 dnl
 dnl This file contains local autoconf functions.
 
@@ -814,7 +814,7 @@
 dnl PHP_BUILD_PROGRAM
 dnl
 AC_DEFUN(PHP_BUILD_PROGRAM,[
-  OVERALL_TARGET=php
+  OVERALL_TARGET=[]ifelse($1,,php,$1)
   php_c_pre='$(CC)'
   php_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS)'
   php_c_post=' && echo > $[@]'
@@ -1179,7 +1179,7 @@
 ])
 
 dnl
-dnl PHP_SELECT_SAPI(name, type[, sources [, extra-cflags]])
+dnl PHP_SELECT_SAPI(name, type[, sources [, extra-cflags [, build-target]]])
 dnl
 dnl Selects the SAPI name and type (static, shared, programm)
 dnl and optionally also the source-files for the SAPI-specific
@@ -1192,7 +1192,7 @@
   static) PHP_BUILD_STATIC;;
   shared) PHP_BUILD_SHARED;;
   bundle) PHP_BUILD_BUNDLE;;
-  program) PHP_BUILD_PROGRAM;;
+  program) PHP_BUILD_PROGRAM($5);;
   esac
     
   ifelse($3,,,[PHP_ADD_SOURCES([sapi/$1],[$3],[$4],[sapi])])
Index: php4/configure.in
diff -u php4/configure.in:1.373 php4/configure.in:1.374
--- php4/configure.in:1.373     Sat Sep 28 22:45:24 2002
+++ php4/configure.in   Sun Sep 29 12:22:47 2002
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.373 2002/09/29 02:45:24 edink Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.374 2002/09/29 16:22:47 sas Exp $ -*- sh -*-
 dnl ## Process this file with autoconf to produce a configure script.
 
 divert(1)
@@ -215,7 +215,6 @@
 dnl -------------------------------------------------------------------------
 
 dnl paths to the targets are relative to the build directory
-SAPI_PROGRAM=php
 SAPI_SHARED=libs/libphp4.$SHLIB_SUFFIX_NAME
 SAPI_STATIC=libs/libphp4.a
 SAPI_LIBTOOL=libphp4.la
@@ -225,7 +224,7 @@
 esyscmd(./scripts/config-stubs sapi)
 
 if test "$PHP_SAPI" = "default"; then
-  PHP_SELECT_SAPI(cgi, program, cgi_main.c getopt.c)
+  PHP_SELECT_SAPI(cgi, program, cgi_main.c getopt.c,,'$(SAPI_CGI_PATH)')
 fi
 
 AC_MSG_CHECKING([for chosen SAPI module])
@@ -1077,12 +1076,6 @@
 fi
 
 PHP_ADD_SOURCES_X(Zend, zend_execute.c,,PHP_GLOBAL_OBJS,,$flag)
-
-
-PHP_ADD_SOURCES_X(main, php_embed.c,, PHP_LIB_OBJS)
-PHP_LIB_OBJS="$PHP_GLOBAL_OBJS $PHP_LIB_OBJS main/internal_functions_cli.lo"
-PHP_SUBST(PHP_LIB_OBJS)
-
 
 PHP_ADD_BUILD_DIR(main)
 PHP_ADD_BUILD_DIR(regex)
Index: php4/sapi/cgi/config.m4
diff -u php4/sapi/cgi/config.m4:1.18 php4/sapi/cgi/config.m4:1.19
--- php4/sapi/cgi/config.m4:1.18        Wed Sep  4 14:47:26 2002
+++ php4/sapi/cgi/config.m4     Sun Sep 29 12:22:48 2002
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.18 2002/09/04 18:47:26 sniper Exp $
+dnl $Id: config.m4,v 1.19 2002/09/29 16:22:48 sas Exp $
 dnl
 
 AC_DEFUN(PHP_TEST_WRITE_STDOUT,[
@@ -32,6 +32,9 @@
 ])
 
 if test "$PHP_SAPI" = "default"; then
+  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cgi/Makefile.frag)
+  SAPI_CGI_PATH=sapi/cgi/php-cgi
+  PHP_SUBST(SAPI_CGI_PATH)
 
   PHP_TEST_WRITE_STDOUT
 
@@ -61,7 +64,7 @@
   fi
   AC_DEFINE_UNQUOTED(DISCARD_PATH, $DISCARD_PATH, [ ])
 
-  INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_PROGRAM \$(INSTALL_ROOT)\$(bindir)/php-cgi"
+  INSTALL_IT="\$(INSTALL) -m 0755 \$(SAPI_CGI_PATH) 
+\$(INSTALL_ROOT)\$(bindir)/php-cgi"
 fi
 
 AC_MSG_CHECKING(for fhttpd module support)
@@ -100,10 +103,10 @@
 
 case $host_alias in
   *darwin*)
-    BUILD_CGI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) 
\$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_SAPI_OBJS:.lo=.o) 
\$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o php"
+    BUILD_CGI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) 
+\$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_SAPI_OBJS:.lo=.o) 
+\$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
     ;;
   *)
-    BUILD_CGI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) 
\$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) 
\$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o php"
+    BUILD_CGI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) 
+\$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) 
+\$(PHP_SAPI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CGI_PATH)"
     ;;
 esac
 PHP_SUBST(BUILD_CGI)
Index: php4/sapi/cli/config.m4
diff -u php4/sapi/cli/config.m4:1.10 php4/sapi/cli/config.m4:1.11
--- php4/sapi/cli/config.m4:1.10        Tue Aug  6 13:51:24 2002
+++ php4/sapi/cli/config.m4     Sun Sep 29 12:22:48 2002
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.10 2002/08/06 17:51:24 markonen Exp $
+dnl $Id: config.m4,v 1.11 2002/09/29 16:22:48 sas Exp $
 dnl
 
 AC_MSG_CHECKING(for CLI build)
@@ -14,15 +14,19 @@
 ])
 
 if test "$PHP_SAPI_CLI" != "no"; then
+  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/cli/Makefile.frag)
+  SAPI_CLI_PATH=sapi/cli/php
+  PHP_SUBST(SAPI_CLI_PATH)
+
   case $host_alias in
   *darwin*)
-    BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) 
\$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) 
\$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o sapi/cli/php"
+    BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) 
+\$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) 
+\$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
     ;;
   *)
-    BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) 
\$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) 
\$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o sapi/cli/php"
+    BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) 
+\$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) 
+\$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
     ;;
   esac
-  INSTALL_CLI="\$(INSTALL) -m 0755 sapi/cli/php \$(INSTALL_ROOT)\$(bindir)/php"
+  INSTALL_CLI="\$(INSTALL) -m 0755 \$(SAPI_CLI_PATH) \$(INSTALL_ROOT)\$(bindir)/php"
   PHP_SUBST(BUILD_CLI)
   PHP_SUBST(INSTALL_CLI)
 else
Index: php4/sapi/fastcgi/config.m4
diff -u php4/sapi/fastcgi/config.m4:1.6 php4/sapi/fastcgi/config.m4:1.7
--- php4/sapi/fastcgi/config.m4:1.6     Mon May 13 20:07:51 2002
+++ php4/sapi/fastcgi/config.m4 Sun Sep 29 12:22:49 2002
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.6 2002/05/14 00:07:51 jason Exp $
+dnl $Id: config.m4,v 1.7 2002/09/29 16:22:49 sas Exp $
 dnl
 
 AC_MSG_CHECKING(for FastCGI support)
@@ -10,15 +10,19 @@
   else
         FASTCGIPATH=$withval
   fi
+  
+  SAPI_FASTCGI_PATH=sapi/fastcgi/php
+  PHP_SUBST(SAPI_FASTCGI_PATH)
+  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/fastcgi/Makefile.frag)
   test -f "$FASTCGIPATH/lib/libfcgi.a" || AC_MSG_ERROR(Unable to find libfcgi.a in 
$FASTCGIPATH/lib)
   test -f "$FASTCGIPATH/include/fastcgi.h" || AC_MSG_ERROR(Unable to find fastcgi.h 
in $FASTCGIPATH/include)
   
-  PHP_SELECT_SAPI(fastcgi, programm, fastcgi.c) 
+  PHP_SELECT_SAPI(fastcgi, program, fastcgi.c,,'$(SAPI_FASTCGI_PATH)') 
 
   PHP_ADD_INCLUDE($FASTCGIPATH/include)
   PHP_ADD_LIBRARY_WITH_PATH(fcgi, "$FASTCGIPATH/lib",)
 
-  INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_PROGRAM \$(bindir)/$SAPI_FASTCGI"
+  INSTALL_IT="\$(INSTALL) -m 0755 \$(SAPI_FASTCGI_PATH) \$(bindir)/$SAPI_FASTCGI"
   RESULT=yes
   PHP_SUBST(FASTCGI_LIBADD)
   PHP_SUBST(EXT_PROGRAM_LDADD)
Index: php4/win32/phpembed.dsp
diff -u php4/win32/phpembed.dsp:1.1 php4/win32/phpembed.dsp:1.2
--- php4/win32/phpembed.dsp:1.1 Sat Sep 28 22:45:25 2002
+++ php4/win32/phpembed.dsp     Sun Sep 29 12:22:49 2002
@@ -85,7 +85,7 @@
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
 # Begin Source File
 
-SOURCE=..\main\php_embed.c
+SOURCE=..\sapi\embed\php_embed.c
 # End Source File
 # End Group
 # Begin Group "Header Files"
@@ -93,7 +93,7 @@
 # PROP Default_Filter "h;hpp;hxx;hm;inl"
 # Begin Source File
 
-SOURCE=..\main\php_embed.h
+SOURCE=..\sapi\embed\php_embed.h
 # End Source File
 # End Group
 # End Target

Index: php4/sapi/cgi/Makefile.frag
+++ php4/sapi/cgi/Makefile.frag
$(SAPI_CGI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
        $(BUILD_CGI)

Index: php4/sapi/cli/Makefile.frag
+++ php4/sapi/cli/Makefile.frag
$(SAPI_CLI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_CLI_OBJS)
        $(BUILD_CLI)

install-cli: $(SAPI_CLI_PATH)
        @echo "Installing PHP CLI binary:        $(INSTALL_ROOT)$(bindir)/"
        @$(INSTALL_CLI)


Index: php4/sapi/embed/config.m4
+++ php4/sapi/embed/config.m4
PHP_ARG_ENABLE(embed,whether to enable the embedded SAPI module,
[  --enable-embed])

PHP_ARG_ENABLE(embed-shared,whether to build it as shared library,
[  --enable-embed-shared])

if test "$PHP_EMBED" = "yes"; then
  if test "$PHP_EMBED_SHARED" = "yes"; then
    ac_type=shared
  else
    ac_type=static
  fi
  PHP_SELECT_SAPI(embed, $ac_type, php_embed.c)
fi

Index: php4/sapi/embed/php_embed.c
+++ php4/sapi/embed/php_embed.c
/*
   +----------------------------------------------------------------------+
   | PHP Version 4                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2002 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 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_02.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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Edin Kadribasic <[EMAIL PROTECTED]>                              |
   +----------------------------------------------------------------------+
*/
/* $Id: php_embed.c,v 1.1 2002/09/29 16:22:48 sas Exp $ */

#include "php_embed.h"

#ifdef PHP_WIN32
#include <io.h>
#include <fcntl.h>
#endif

static char* php_embed_read_cookies(TSRMLS_D)
{
        return NULL;
}

static int php_embed_deactivate(TSRMLS_D)
{
        fflush(stdout);
        return SUCCESS;
}

static inline size_t php_embed_single_write(const char *str, uint str_length)
{
#ifdef PHP_WRITE_STDOUT
        long ret;

        ret = write(STDOUT_FILENO, str, str_length);
        if (ret <= 0) return 0;
        return ret;
#else
        size_t ret;

        ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
        return ret;
#endif
}


static int php_embed_ub_write(const char *str, uint str_length TSRMLS_DC)
{
        const char *ptr = str;
        uint remaining = str_length;
        size_t ret;

        while (remaining > 0) {
                ret = php_embed_single_write(ptr, remaining);
                if (!ret) {
                        php_handle_aborted_connection();
                }
                ptr += ret;
                remaining -= ret;
        }

        return str_length;
}

static void php_embed_flush(void *server_context)
{
        if (fflush(stdout)==EOF) {
                php_handle_aborted_connection();
        }
}

static void php_embed_send_header(sapi_header_struct *sapi_header, void 
*server_context TSRMLS_DC)
{
}

static void php_embed_log_message(char *message)
{
        fprintf (stderr, "%s\n", message);
}

static void php_embed_register_variables(zval *track_vars_array TSRMLS_DC)
{
        php_import_environment_variables(track_vars_array TSRMLS_CC);
}

static int php_embed_startup(sapi_module_struct *sapi_module)
{
        if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
                return FAILURE;
        }
        return SUCCESS;
}

static sapi_module_struct php_embed_module = {
        "embedded",                    /* name */
        "PHP Embedded Library",        /* pretty name */
        
        php_embed_startup,              /* startup */
        php_module_shutdown_wrapper,   /* shutdown */
  
        NULL,                          /* activate */
        php_embed_deactivate,           /* deactivate */
  
        php_embed_ub_write,             /* unbuffered write */
        php_embed_flush,                /* flush */
        NULL,                          /* get uid */
        NULL,                          /* getenv */
  
        php_error,                     /* error handler */
  
        NULL,                          /* header handler */
        NULL,                          /* send headers handler */
        php_embed_send_header,          /* send header handler */
        
        NULL,                          /* read POST data */
        php_embed_read_cookies,         /* read Cookies */
  
        php_embed_register_variables,   /* register server variables */
        php_embed_log_message,          /* Log message */
  
        NULL,                          /* Block interruptions */
        NULL,                          /* Unblock interruptions */

        STANDARD_SAPI_MODULE_PROPERTIES
};
/* }}} */

int php_embed_init(int argc, char **argv PTSRMLS_DC)
{
        zend_llist global_vars;
#ifdef ZTS
        zend_compiler_globals *compiler_globals;
        zend_executor_globals *executor_globals;
        php_core_globals *core_globals;
        sapi_globals_struct *sapi_globals;
        void ***tsrm_ls;
#endif

#ifdef HAVE_SIGNAL_H
#if defined(SIGPIPE) && defined(SIG_IGN)
        signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so
                                                                 that sockets created 
via fsockopen()
                                                                 don't kill PHP if the 
remote site
                                                                 closes it.  in 
apache|apxs mode apache
                                                                 does that for us!  
[EMAIL PROTECTED]
                                                                 20000419 */
#endif
#endif

#ifdef PHP_WIN32
  _fmode = _O_BINARY;                   /*sets default for file streams to binary */
  setmode(_fileno(stdin), O_BINARY);            /* make the stdio mode be binary */
  setmode(_fileno(stdout), O_BINARY);           /* make the stdio mode be binary */
  setmode(_fileno(stderr), O_BINARY);           /* make the stdio mode be binary */
#endif

#ifdef ZTS
  tsrm_startup(1, 1, 0, NULL);
#endif

#ifdef ZTS
  compiler_globals = ts_resource(compiler_globals_id);
  executor_globals = ts_resource(executor_globals_id);
  core_globals = ts_resource(core_globals_id);
  sapi_globals = ts_resource(sapi_globals_id);
  tsrm_ls = ts_resource(0);
  *ptsrm_ls = tsrm_ls;
#endif

  sapi_startup(&php_embed_module);

  if (php_module_startup(&php_embed_module, NULL, 0)==FAILURE) {
          return FAILURE;
  }
 
  if (argv) {
        php_embed_module.executable_location = argv[0];
  }

  zend_llist_init(&global_vars, sizeof(char *), NULL, 0);  

  /* Set some Embedded PHP defaults */
  SG(options) |= SAPI_OPTION_NO_CHDIR;
  zend_alter_ini_entry("register_argc_argv", 19, "1", 1, PHP_INI_SYSTEM, 
PHP_INI_STAGE_ACTIVATE);
  zend_alter_ini_entry("html_errors", 12, "0", 1, PHP_INI_SYSTEM, 
PHP_INI_STAGE_ACTIVATE);
  zend_alter_ini_entry("implicit_flush", 15, "1", 1, PHP_INI_SYSTEM, 
PHP_INI_STAGE_ACTIVATE);
  zend_alter_ini_entry("max_execution_time", 19, "0", 1, PHP_INI_SYSTEM, 
PHP_INI_STAGE_ACTIVATE);

  SG(request_info).argc=argc;
  SG(request_info).argv=argv;

  if (php_request_startup(TSRMLS_C)==FAILURE) {
          php_module_shutdown(TSRMLS_C);
          return FAILURE;
  }
  
  SG(headers_sent) = 1;
  SG(request_info).no_headers = 1;
  php_register_variable("PHP_SELF", "-", NULL TSRMLS_CC);

  return SUCCESS;
}

void php_embed_shutdown(TSRMLS_D)
{
        php_request_shutdown((void *) 0);
        php_module_shutdown(TSRMLS_C);
#ifdef ZTS
    tsrm_shutdown();
#endif
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: sw=4 ts=4 fdm=marker
 * vim<600: sw=4 ts=4
 */

Index: php4/sapi/embed/php_embed.h
+++ php4/sapi/embed/php_embed.h
/*
   +----------------------------------------------------------------------+
   | PHP Version 4                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2002 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 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_02.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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Edin Kadribasic <[EMAIL PROTECTED]>                              |
   +----------------------------------------------------------------------+
*/
/* $Id: php_embed.h,v 1.1 2002/09/29 16:22:48 sas Exp $ */

#ifndef _PHP_EMBED_H_
#define _PHP_EMBED_H_

#include <main/php.h>
#include <main/SAPI.h>
#include <main/php_main.h>
#include <main/php_variables.h>
#include <main/php_ini.h>
#include <zend_ini.h>

#ifdef ZTS
#define PTSRMLS_D        void ****ptsrm_ls
#define PTSRMLS_DC       , PTSRMLS_D
#define PTSRMLS_C        &tsrm_ls
#define PTSRMLS_CC       , PTSRMLS_C
#else
#define PTSRMLS_D
#define PTSRMLS_DC
#define PTSRMLS_C
#define PTSRMLS_CC
#endif

#define PHP_EMBED_START_BLOCK(x,y) { \
    void ***tsrm_ls; \
    php_embed_init(x, y PTSRMLS_CC); \
    zend_first_try {

#define PHP_EMBED_END_BLOCK() \
  } zend_catch { \
    /* int exit_status = EG(exit_status); */ \
  } zend_end_try(); \
  php_embed_shutdown(TSRMLS_C); \
}

BEGIN_EXTERN_C() 
int php_embed_init(int argc, char **argv PTSRMLS_DC);
void php_embed_shutdown(TSRMLS_D);
END_EXTERN_C()


#endif /* _PHP_EMBED_H_ */

Index: php4/sapi/fastcgi/Makefile.frag
+++ php4/sapi/fastcgi/Makefile.frag
$(SAPI_FASTCGI_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
        $(BUILD_CGI)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to