cvs: /php3/functions php3_recode.h recode.c
| From: | Kristian K�hntopp | Date: | Sun, 21 Nov 1999 23:57:31 +0000 |
| Subject: | cvs: /php3/functions php3_recode.h recode.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-12891@lists.php.net to get a copy of this message | ||
kk Sun Nov 21 18:57:31 1999 EDT
Modified files:
/php3/functions php3_recode.h recode.c
Log:
Add function recode_file().
Index: php3/functions/php3_recode.h
diff -u php3/functions/php3_recode.h:1.1 php3/functions/php3_recode.h:1.2
--- php3/functions/php3_recode.h:1.1 Sun Nov 21 18:06:31 1999
+++ php3/functions/php3_recode.h Sun Nov 21 18:57:30 1999
@@ -28,7 +28,7 @@
*/
-/* $Id: php3_recode.h,v 1.1 1999/11/21 23:06:31 kk Exp $ */
+/* $Id: php3_recode.h,v 1.2 1999/11/21 23:57:30 kk Exp $ */
#ifndef _PHP3_RECODE_H
#define _PHP3_RECODE_H
@@ -59,6 +59,7 @@
extern void php3_info_recode(void);
extern void php3_recode_string(INTERNAL_FUNCTION_PARAMETERS);
+extern void php3_recode_file(INTERNAL_FUNCTION_PARAMETERS);
typedef struct {
RECODE_OUTER outer;
Index: php3/functions/recode.c
diff -u php3/functions/recode.c:1.1 php3/functions/recode.c:1.2
--- php3/functions/recode.c:1.1 Sun Nov 21 18:06:31 1999
+++ php3/functions/recode.c Sun Nov 21 18:57:30 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: recode.c,v 1.1 1999/11/21 23:06:31 kk Exp $ */
+/* $Id: recode.c,v 1.2 1999/11/21 23:57:30 kk Exp $ */
#include "php.h"
@@ -40,6 +40,7 @@
#if HAVE_RECODE
#include "php3_recode.h"
+#include "php3_list.h"
#ifdef HAVE_BROKEN_RECODE
extern char *program_name;
@@ -57,10 +58,12 @@
#else
#define RECODE_GLOBAL(a) php3_recode_module.a
recode_module php3_recode_module;
+extern int le_fp,le_pp;
#endif
function_entry recode_functions[] = {
- {"recode_string", php3_recode_string, NULL},
+ {"recode_string", php3_recode_string, NULL},
+ {"recode_file", php3_recode_file, NULL},
{NULL, NULL, NULL}
};
@@ -104,7 +107,7 @@
void php3_info_recode(void)
{
- php3_printf("$Revision: 1.1 $\n");
+ php3_printf("$Revision: 1.2 $\n");
}
/* {{{ proto string recode_string(string request, string str)
@@ -155,6 +158,72 @@
RETURN_FALSE;
}
/* }}} */
+
+/* {{{ proto bool recode_file(string request, int input, int output)
+Recode file input into file output according to request */
+void php3_recode_file(INTERNAL_FUNCTION_PARAMETERS)
+{
+ RECODE_REQUEST request = NULL;
+ int success;
+ pval *req, *input, *output;
+ int in_id, in_type;
+ FILE *in_fp;
+ int out_id, out_type;
+ FILE *out_fp;
+ TLS_VARS;
+
+ if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &req, &input, &output) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(input);
+ convert_to_long(output);
+ in_id = input->value.lval;
+ out_id = output->value.lval;
+
+ in_fp = php3_list_find(in_id,&in_type);
+ if (!in_fp || (in_type!=GLOBAL(le_fp) && in_type!=GLOBAL(le_pp))) {
+ php3_error(E_WARNING,"Unable to find input file identifier %d",in_id);
+ RETURN_FALSE;
+ }
+
+ out_fp = php3_list_find(out_id,&out_type);
+ if (!out_fp || (out_type!=GLOBAL(le_fp) && out_type!=GLOBAL(le_pp))) {
+ php3_error(E_WARNING,"Unable to find output file identifier %d", out_id);
+ RETURN_FALSE;
+ }
+
+ convert_to_string(req);
+
+ request = recode_new_request(RECODE_GLOBAL(outer));
+ if (request == NULL) {
+ php3_error(E_WARNING, "Cannot allocate request structure");
+ RETURN_FALSE;
+ }
+
+ success = recode_scan_request(request, req->value.str.val);
+ if (!success) {
+ php3_error(E_WARNING, "Illegal recode request.");
+ goto error_exit;
+ }
+
+ success = recode_file_to_file(request, in_fp, out_fp);
+ if (!success) {
+ php3_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