summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Köhntopp <kk@php.net>2000-03-12 19:42:29 +0000
committerKristian Köhntopp <kk@php.net>2000-03-12 19:42:29 +0000
commit85940d676f753b550d3abe8756e9e07e2bfba4d5 (patch)
treeed1ed5f45d34e630e6dada7986f5384c8b61085c
parentfa5ab18f2e6464465216f62f3e2da095b39d0493 (diff)
downloadphp-git-85940d676f753b550d3abe8756e9e07e2bfba4d5.tar.gz
Finished porting recode module.
-rw-r--r--ext/recode/recode.c60
-rw-r--r--ext/standard/file.c5
-rw-r--r--ext/standard/file.h1
3 files changed, 63 insertions, 3 deletions
diff --git a/ext/recode/recode.c b/ext/recode/recode.c
index a7acbb67cc..51762ba6fd 100644
--- a/ext/recode/recode.c
+++ b/ext/recode/recode.c
@@ -25,6 +25,7 @@
#if HAVE_LIBRECODE
#include "ext/standard/info.h"
+#include "ext/standard/file.h"
#include "ext/standard/php_string.h"
#include "zend_list.h"
@@ -147,16 +148,69 @@ error_exit:
}
/* }}} */
-/* {{{ proto bool recode_file(string request, int input, int output)
+/* {{{ proto bool recode_file(string request, resource input, resource output)
Recode file input into file output according to request */
PHP_FUNCTION(recode_file)
{
- php_error(E_WARNING, "This has not been ported, yet");
+ RECODE_REQUEST request = NULL;
+ int success;
+ pval **req;
+ pval **input, **output;
+ FILE *in_fp, *out_fp;
+ int in_type, out_type;
+
+ ReSLS_FETCH();
+ if (ARG_COUNT(ht) != 3
+ || zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ in_fp = zend_fetch_resource(input,-1, "File-Handle", &in_type,
+ 2, php_file_le_fopen(), php_file_le_popen());
+ if (!in_fp) {
+ php_error(E_WARNING,"Unable to find input file identifier");
+ RETURN_FALSE;
+ }
+
+ out_fp = zend_fetch_resource(output,-1, "File-Handle", &out_type,
+ 2, php_file_le_fopen(), php_file_le_popen());
+ if (!out_fp) {
+ php_error(E_WARNING,"Unable to find output file identifier");
+ RETURN_FALSE;
+ }
+
+ convert_to_string_ex(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;
+ }
+
+ success = recode_file_to_file(request, in_fp, out_fp);
+ if (!success) {
+ php_error(E_WARNING, "Recoding failed.");
+ goto error_exit;
+ }
+
+ if (request)
+ recode_delete_request(request);
+ RETURN_TRUE;
+
+error_exit:
+ if (request)
+ recode_delete_request(request);
+
RETURN_FALSE;
}
/* }}} */
-
#endif
/*
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 852170e464..3796d5abbe 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -246,6 +246,11 @@ PHPAPI int php_file_le_fopen(void) /* XXX doe we really want this???? */
return le_fopen;
}
+PHPAPI int php_file_le_popen(void) /* XXX you may not like this, but I need it. -- KK */
+{
+ return le_popen;
+}
+
PHPAPI int php_file_le_socket(void) /* XXX doe we really want this???? */
{
diff --git a/ext/standard/file.h b/ext/standard/file.h
index 3d60850035..b2ff0f4f22 100644
--- a/ext/standard/file.h
+++ b/ext/standard/file.h
@@ -76,6 +76,7 @@ PHP_FUNCTION(fstat);
PHPAPI int php_set_sock_blocking(int socketd, int block);
PHPAPI int php_file_le_fopen(void);
+PHPAPI int php_file_le_popen(void);
PHPAPI int php_file_le_socket(void);
PHPAPI int php_file_le_uploads(void);