📄 encoding_chdl_spec.c
字号:
#include <libxml/encoding.h>
#include <ch.h>
static ChInterp_t interp;
static struct HandlePairsIn{
xmlCharEncodingInputFunc handle_c;
xmlCharEncodingInputFunc handle_ch;
} handlePairsIn;
static struct HandlePairsOut{
xmlCharEncodingOutputFunc handle_c;
xmlCharEncodingOutputFunc handle_ch;
} handlePairsOut;
static int input_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen);
static void * input_chdl_funptr;
static int output_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen);
static void * output_chdl_funptr;
static int callinc_in_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen);
static void* callinc_in_chdl_funptr;
static int callinc_out_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen);
static void * callinc_out_chdl_funptr;
static xmlCharEncodingInputFunc fptr_in;
static xmlCharEncodingOutputFunc fptr_out;
EXPORTCH void xmlRegisterCharEncodingHandler_chdl(void *varg) {
va_list ap;
xmlCharEncodingHandlerPtr handler;
xmlCharEncodingHandler handler_c;
Ch_VaStart(interp, ap, varg);
handler = Ch_VaArg(interp, ap, xmlCharEncodingHandlerPtr);
handler_c = *handler;
if(handler->input == NULL){
handler_c.input = NULL;
}else if(handlePairsIn.handle_ch == handler->input){
handler_c.input = handlePairsIn.handle_c;
}else{
input_chdl_funptr = handler->input;
handler_c.input = (xmlCharEncodingInputFunc)input_chdl_funarg;
handlePairsIn.handle_ch = input_chdl_funptr;
handlePairsIn.handle_c = (xmlCharEncodingInputFunc)input_chdl_funarg;
}
if(handler->output == NULL){
handler_c.output = NULL;
}else if(handlePairsOut.handle_ch == handler->output){
handler_c.output = handlePairsOut.handle_c;
}else{
output_chdl_funptr = handler->output;
handler_c.output = (xmlCharEncodingOutputFunc)output_chdl_funarg;
handlePairsOut.handle_c = (xmlCharEncodingOutputFunc)output_chdl_funarg;
handlePairsOut.handle_ch = output_chdl_funptr;
}
xmlRegisterCharEncodingHandler(&handler_c);
Ch_VaEnd(interp, ap);
}
EXPORTCH xmlCharEncodingHandlerPtr xmlGetCharEncodingHandler_chdl(void *varg) {
va_list ap;
xmlCharEncoding enc;
xmlCharEncodingHandlerPtr retval;
xmlCharEncodingHandlerPtr handler_ch;
/****************************************************************
*
* define the static struct xmlCharEncodingHandler handler_chdl is
* in order to keep the return struct is the original.
* written by ZQ
*
* Junr 15, 2004
*
****************************************************************/
static xmlCharEncodingHandler handler_chdl;
handler_ch = &handler_chdl;
Ch_VaStart(interp, ap, varg);
enc = Ch_VaArg(interp, ap, xmlCharEncoding);
callinc_in_chdl_funptr = Ch_VaArg(interp, ap, void *);
callinc_out_chdl_funptr = Ch_VaArg(interp, ap, void *);
retval = xmlGetCharEncodingHandler(enc);
/*****************************************************************
* The return value of retval is a point to structure.
* In this struct there are member fields is point to funtion.
* The point to function has 3 cases as below:
* 1. NULL.
* 2. Point to function which is defined in ch space. When it return to ch
* space, it is should be the ch funtion which is set in
* register function.
* 3. Point to funtion which is defined in c space (system default funtion)
* return pointer should be set as ch function
* ( callinc_in()/callinc_out() )which will call
* the function (fptr_in or fptr_out)in c space gotten here
*
* written by ZQ
* June, 15th 2004
****************************************************************/
handler_chdl = *retval;
if(retval->input==NULL){
handler_ch->input = NULL;
}else if(handlePairsIn.handle_c == retval->input){
handler_ch->input = handlePairsIn.handle_ch;
}else{
fptr_in = retval->input;
handler_ch->input = (xmlCharEncodingInputFunc)callinc_in_chdl_funptr;
}
if(retval->output==NULL){
handler_ch->output = NULL;
}else if(handlePairsIn.handle_c == retval->output){
handler_ch->output = handlePairsOut.handle_ch;
}else{
fptr_out = retval->output;
handler_ch->output = callinc_out_chdl_funptr;
}
Ch_VaEnd(interp, ap);
return handler_ch;
}
EXPORTCH xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler_chdl(void *varg) {
va_list ap;
char *name;
void *fptr;
xmlCharEncodingHandlerPtr retval;
xmlCharEncodingHandlerPtr handler_ch;
static xmlCharEncodingHandler handler_chdl;
handler_ch = &handler_chdl;
Ch_VaStart(interp, ap, varg);
name = Ch_VaArg(interp, ap, char *);
callinc_in_chdl_funptr = Ch_VaArg(interp, ap, void *);
callinc_out_chdl_funptr = Ch_VaArg(interp, ap, void *);
retval = xmlFindCharEncodingHandler(name);
/*********************************************************************
* The return value of retval is a point to structure.
* In this struct there are member fields is point to funtion.
* The point to function has 3 cases as below:
* 1. NULL.
* 2. Point to function which is defined in ch space. When it return to ch
* space, it is should be the ch funtion which is set in
* register function.
* 3. Point to funtion which is defined in c space (system default funtion)
* return pointer should be set as ch function
* ( callinc_in()/callinc_out() )which will call
* the function (fptr_in or fptr_out)in c space gotten here
*
* written by ZQ
* June, 15th 2004
********************************************************************/
handler_chdl = *retval;
if(retval->input==NULL){
handler_ch->input = NULL;
}else if(handlePairsIn.handle_c == retval->input){
handler_ch->input = handlePairsIn.handle_ch;
}else{
fptr_in = retval->input;
handler_ch->input = (xmlCharEncodingInputFunc)callinc_in_chdl_funptr;
}
if(retval->output==NULL){
handler_ch->output = NULL;
}else if(handlePairsIn.handle_c == retval->output){
handler_ch->output = handlePairsOut.handle_ch;
}else{
fptr_out = retval->output;
handler_ch->output = (xmlCharEncodingOutputFunc)callinc_out_chdl_funptr;
}
Ch_VaEnd(interp, ap);
return handler_ch;
}
EXPORTCH xmlCharEncodingHandlerPtr xmlNewCharEncodingHandler_chdl(void *varg) {
va_list ap;
char *name;
xmlCharEncodingInputFunc input_c, input_ch;
xmlCharEncodingOutputFunc output_c, output_ch;
xmlCharEncodingHandlerPtr retval;
Ch_VaStart(interp, ap, varg);
name = Ch_VaArg(interp, ap, char *);
input_ch = Ch_VaArg(interp, ap, xmlCharEncodingInputFunc);
if(input_ch == NULL){
input_c = NULL;
}else if(handlePairsIn.handle_ch == input_ch){
input_c = handlePairsIn.handle_c;
}else{
input_chdl_funptr = input_ch;
input_c= (xmlCharEncodingInputFunc)input_chdl_funarg;
handlePairsIn.handle_ch = input_ch;
handlePairsIn.handle_c = input_c;
}
output_ch = Ch_VaArg(interp, ap, xmlCharEncodingOutputFunc);
if(output_ch == NULL){
output_c = NULL;
}else if(handlePairsIn.handle_ch == output_ch){
output_c = handlePairsIn.handle_c;
}else{
output_chdl_funptr = output_ch;
output_c= (xmlCharEncodingOutputFunc)output_chdl_funarg;
handlePairsIn.handle_ch = output_ch;
handlePairsIn.handle_c = output_c;
}
retval = xmlNewCharEncodingHandler(name, input_c, output_c);
Ch_VaEnd(interp, ap);
return retval;
}
static int input_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen){
int retval;
Ch_CallFuncByAddr(interp, input_chdl_funptr, &retval, out, outlen, in, inlen);
return retval;
}
static int output_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen){
int retval;
Ch_CallFuncByAddr(interp, output_chdl_funptr, &retval, out, outlen, in, inlen);
return retval;
}
/********************************************************************
* This function is to call the function in c space return by
* xmlFindCharEncodingHandler()
* This function will be run by the callinc_in() defined in ch space
* file: libxml_ch.h
* callin_in() is likes the chf file which calls a function in c space
* callin_in() function is callback funtion used in
* xmlFindCharEncodingHandler()
* the static variable fptr_in is point to function get from
* xmlFindCharEncodingHandler()
*
* Written by ZQ
* 2004, June 14
* *****************************************************************/
EXPORTCH int callinc_in_chdl(void *varg){
va_list ap;
unsigned char *out;
int *outlen;
const unsigned char *in;
int *inlen;
int retval;
Ch_VaStart(interp, ap, varg);
out = Ch_VaArg(interp, ap, unsigned char *);
outlen = Ch_VaArg(interp, ap, int *);
in = Ch_VaArg(interp, ap, unsigned char *);
inlen = Ch_VaArg(interp, ap, int *);
retval = (xmlCharEncodingInputFunc)fptr_in(out, outlen, in, inlen);
return retval;
}
/********************************************************************
* This function is to call the function in c space return by
* xmlFindCharEncodingHandler()
* This function will be run by the callinc_out() defined in ch space
* callin_out() is likes the chf file which calls a function in c space
* callin_out() function is callback funtion used in
* xmlFindCharEncodingHandler()
* the static variable fptr_out is point to function get from
* xmlFindCharEncodingHandler()
*
* Written by ZQ
* 2004, June 14
********************************************************************/
EXPORTCH int callinc_out_chdl(void *varg){
va_list ap;
unsigned char *out;
int *outlen;
const unsigned char *in;
int *inlen;
int retval;
Ch_VaStart(interp, ap, varg);
out = Ch_VaArg(interp, ap, unsigned char *);
outlen = Ch_VaArg(interp, ap, int *);
in = Ch_VaArg(interp, ap, unsigned char *);
inlen = Ch_VaArg(interp, ap, int *);
retval = fptr_out(out, outlen, in, inlen);
return retval;
}
/**********************************************************************
* this two function is used to call the c function in c space but the
* parameters from the ch space
* callinc_in_chdl_funptr is a point to function in ch space get from
* xmlFindCharEncodingHandler()
*
* written by ZQ
* 2004, June 14
*
*********************************************************************/
static int callinc_in_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen){
int retval;
Ch_CallFuncByAddr(interp, callinc_in_chdl_funptr, &retval, out, outlen, in, inlen);
return retval;
}
static int callinc_out_chdl_funarg(unsigned char *out, int *outlen, const unsigned char *in, int *inlen){
int retval;
Ch_CallFuncByAddr(interp, callinc_out_chdl_funptr, &retval, out, outlen, in, inlen);
return retval;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -