Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Parser.XML2
Viewing contents of Public_Parser_XML2-1.16/Stylesheet.c

/* Generated from "Stylesheet.cmod" by precompile.pike
 *
 * Do NOT edit this file.
 */

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 2


#line 1 "Stylesheet.cmod"
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: Stylesheet.cmod,v 1.12 2005/05/04 02:10:19 hww3 Exp $
 */

/*
 * File licensing and authorship information block.
 *
 * Version: MPL 1.1/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *
 * Bill Welliver 
 *
 * Portions created by the Initial Developer are Copyright (C) Bill Welliver
 * All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of the LGPL, and not to allow others to use your version
 * of this file under the terms of the MPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL or the LGPL.
 *
 * Significant Contributors to this file are:
 *
 *
 */

#define THIS_IS_XML2_STYLESHEET 1

#include "xml2.h"

/*! @module Public
 */

/*! @module Parser
 */

/*! @module XML2
 */

/*! @class Stylesheet
 */

extern int docloader_num;



#undef class_Stylesheet_defined
#define class_Stylesheet_defined
struct program *Stylesheet_program=NULL;
static int Stylesheet_program_fun_num=-1;

#undef var_object_data_Stylesheet_defined
#define var_object_data_Stylesheet_defined

#undef var_node_Stylesheet_defined
#define var_node_Stylesheet_defined

#undef THIS
#define THIS ((struct Stylesheet_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_STYLESHEET
#define THIS_STYLESHEET ((struct Stylesheet_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_STYLESHEET
#define OBJ2_STYLESHEET(o) ((struct Stylesheet_struct *)(o->storage+Stylesheet_storage_offset))

#undef GET_STYLESHEET_STORAGE
#define GET_STYLESHEET_STORAGE ((struct Stylesheet_struct *)(o->storage+Stylesheet_storage_offset)
static ptrdiff_t Stylesheet_storage_offset;
struct Stylesheet_struct {

#ifdef var_object_data_Stylesheet_defined
#line 83 "Stylesheet.cmod"
STYLESHEET_OBJECT_DATA   *object_data;
#endif /* var_object_data_Stylesheet_defined */

#ifdef var_node_Stylesheet_defined
  struct object * node;

#endif /* var_node_Stylesheet_defined */
};
#line 86 "Stylesheet.cmod"
/* 

   The pike - docloader callback glue
  
 */
xmlDocPtr pike_docloader_conv (const xmlChar * URI, xmlDictPtr dict, 
                               int options, void * ctxt, int type)
{
    struct Node_struct * ns;
    NODE_OBJECT_DATA * od;
    struct object * xnode;

    stack_dup();
    push_text(URI);
    push_int(options);
    push_int(type);
    apply_svalue(&Pike_sp[0-4], 3);

    if(Pike_sp[0-1].type != T_OBJECT)
      return NULL;

    CHECK_NODE_PASSED(Pike_sp[0-1].u.object);
    add_ref(Pike_sp[0-1].u.object);
    ns = OBJ2_NODE(Pike_sp[0-1].u.object);
    od = (NODE_OBJECT_DATA *)(ns->object_data);

    pop_stack();

    if(od->node->doc == NULL)
      return NULL;    
    else return od->node->doc;

    return NULL;
}

#define f_Stylesheet_cq__sprintf_defined
ptrdiff_t f_Stylesheet_cq__sprintf_fun_num = 0;
void f_Stylesheet_cq__sprintf(INT32 args) {
#line 121 "Stylesheet.cmod"
INT_TYPE type;
#line 121 "Stylesheet.cmod"
struct svalue * t;
#line 121 "Stylesheet.cmod"
if(args != 2) wrong_number_of_args_error("_sprintf",args,2);
#line 121 "Stylesheet.cmod"
if(Pike_sp[0-2].type != PIKE_T_INT) SIMPLE_BAD_ARG_ERROR("_sprintf",1,"int");
type=Pike_sp[0-2].u.integer;
#line 121 "Stylesheet.cmod"
t=Pike_sp+1-2; dmalloc_touch_svalue(Pike_sp+1-2);
{
  char * desc;

  check_stylesheet_created();
  
  push_text("Stylesheet()");
}

}
#define f_Stylesheet_create_defined
ptrdiff_t f_Stylesheet_create_fun_num = 0;
void f_Stylesheet_create(INT32 args) {
#line 130 "Stylesheet.cmod"
if(args != 0) wrong_number_of_args_error("create",args,0);
{
}

}
/*! @decl Node apply(Node xml)
 *!
 *! apply the stylesheet object to an xml file.
 *!
 *! @param xml
 *!   a @[Node] object from the parsed XML document to apply.
 *!   Any node from the XML document may be used.
 *!
 *! @returns
 *!    a @[Node] object for the transformed document.
 */
#define f_Stylesheet_apply_defined
ptrdiff_t f_Stylesheet_apply_fun_num = 0;
void f_Stylesheet_apply(INT32 args) {
#line 145 "Stylesheet.cmod"
struct object * xml;
#line 145 "Stylesheet.cmod"
if(args != 1) wrong_number_of_args_error("apply",args,1);
#line 145 "Stylesheet.cmod"
if(Pike_sp[0-1].type != PIKE_T_OBJECT) SIMPLE_BAD_ARG_ERROR("apply",1,"object");
#line 145 "Stylesheet.cmod"
debug_malloc_pass(xml=Pike_sp[0-1].u.object);
{
  xmlDocPtr output;
  struct Node_struct * ns;
  NODE_OBJECT_DATA * od;
  struct object * xnode;
  struct external_variable_context loc;
  int x=0;
  int have_func = 0;

  CHECK_NODE_PASSED(xml);

#ifdef HAVE_XSLTSETLOADERFUNC
    loc.o = Pike_fp->current_object;
    loc.parent_identifier = Pike_fp->fun;
    if (loc.o->prog)
    {
      loc.inherit=INHERIT_FROM_INT(loc.o->prog, loc.parent_identifier);
    }
    find_external_context(&loc, 1);

    printf("docloadeR_num: %d\n", docloader_num);

      /* Then index as usual.
       * You can probably use some casting here to avoid needing
       * outer_variable_num, but the following works even if you
       * want to access some symbol inherited from Pike code.
       */
    low_object_index_no_free(Pike_sp, loc.o,
                               docloader_num +
                               loc.inherit->identifier_level);
    Pike_sp++;

    if(Pike_sp[0-1].type == T_FUNCTION)
    {
      have_func = 1;
      xsltSetLoaderFunc(pike_docloader_conv);
    }
    else
      xsltSetLoaderFunc(NULL);
#endif
 

    /* we should have the docloader function on the stack now. */

  output = xsltApplyStylesheet(THIS->object_data->stylesheet, 
                                 OBJ2_NODE(xml)->object_data->node->doc, 
                                 THIS->object_data->atts);

  /* we pushed the stack, so let's pop it. */
  if(have_func)
  {
    pop_stack();
  }


  if(output == NULL)
  {
    pop_n_elems(args);
    Pike_error("unable to transform document.\n");
  }

  xnode = NEW_NODE();
  ns = OBJ2_NODE((xnode));
  od = (NODE_OBJECT_DATA *)(ns->object_data);

  od->refs = malloc(sizeof(INT32));
  (* od->refs)=1;

  if(output->children == NULL)
  {
    Pike_error("unable to find a node for the document.\n");
  }
  od->node = output->children;

  pop_stack();

  push_object(xnode);
}

}
/*! @decl string output(Node xml, int|void encoding)
 *!
 *!   render the applied stylesheet Node to a string.
 *!
 *! @param xml
 *!   the transformed xml object
 *! 
 *! @param encoding
 *!   an optional encoding for the string. if not supplied, defaults to 
 *!   ISO-8859-1 (ISO Latin 1). Valid options are found in 
 *!   @[Public.XML2.Constants], XML_CHAR_ENCODING*.
 *!
 *! @returns
 *!   the string representation of the transformed XML.
 */
#define f_Stylesheet_output_1_defined
ptrdiff_t f_Stylesheet_output_1_fun_num = 0;
void f_Stylesheet_output_1(INT32 args) {
#line 240 "Stylesheet.cmod"
struct object * xml;
#line 240 "Stylesheet.cmod"
if(args != 1) wrong_number_of_args_error("output",args,1);
#line 240 "Stylesheet.cmod"
if(Pike_sp[0-1].type != PIKE_T_OBJECT) SIMPLE_BAD_ARG_ERROR("output",1,"object");
#line 240 "Stylesheet.cmod"
debug_malloc_pass(xml=Pike_sp[0-1].u.object);
{
  xmlOutputBufferPtr xmlBuf;
  xmlCharEncodingHandlerPtr encoder;

  CHECK_NODE_PASSED(xml);
  encoder = xmlGetCharEncodingHandler((xmlCharEncoding)10);
 
  if(encoder == NULL) 
    Pike_error("unable to obtain encoder.\n");

  xmlBuf = xmlAllocOutputBuffer(encoder);

  xsltSaveResultTo( xmlBuf, OBJ2_NODE(xml)->object_data->node->doc, 
                       THIS->object_data->stylesheet);

  pop_n_elems(args);

  push_text(xmlBuf->conv->content);

  xmlOutputBufferClose(xmlBuf);
}

}
#define f_Stylesheet_output_2_defined
ptrdiff_t f_Stylesheet_output_2_fun_num = 0;
void f_Stylesheet_output_2(INT32 args) {
#line 263 "Stylesheet.cmod"
struct object * xml;
#line 263 "Stylesheet.cmod"
INT_TYPE encoding;
#line 263 "Stylesheet.cmod"
if(args != 2) wrong_number_of_args_error("output",args,2);
#line 263 "Stylesheet.cmod"
if(Pike_sp[0-2].type != PIKE_T_OBJECT) SIMPLE_BAD_ARG_ERROR("output",1,"object");
#line 263 "Stylesheet.cmod"
debug_malloc_pass(xml=Pike_sp[0-2].u.object);
#line 263 "Stylesheet.cmod"
if(Pike_sp[1-2].type != PIKE_T_INT) SIMPLE_BAD_ARG_ERROR("output",2,"int");
encoding=Pike_sp[1-2].u.integer;
#line 264 "Stylesheet.cmod"
{
  xmlOutputBufferPtr xmlBuf;
  xmlCharEncodingHandlerPtr encoder;

  CHECK_NODE_PASSED(xml);
  encoder = xmlGetCharEncodingHandler((xmlCharEncoding)encoding);

  if(encoder == NULL)
    Pike_error("unable to obtain encoder.\n");

  xmlBuf = xmlAllocOutputBuffer(encoder);

  xsltSaveResultTo( xmlBuf, OBJ2_NODE(xml)->object_data->node->doc, 
                       THIS->object_data->stylesheet);

  pop_n_elems(args);

  push_text_len(xmlBuf->conv->content, xmlBuf->conv->use);

  xmlOutputBufferClose(xmlBuf);
}

}

#if defined(f_Stylesheet_output_1_defined) || defined(f_Stylesheet_output_2_defined)
#define f_Stylesheet_output_defined
ptrdiff_t Stylesheet_f_Stylesheet_output_fun_num = 0;
void f_Stylesheet_output(INT32 args) {
  switch(args) {
   case 1:

#ifdef f_Stylesheet_output_1_defined
    f_Stylesheet_output_1(args);
    return;

#endif /* f_Stylesheet_output_1_defined */
    break;
   case 2:

#ifdef f_Stylesheet_output_2_defined
    f_Stylesheet_output_2(args);
    return;

#endif /* f_Stylesheet_output_2_defined */
    break;
   default:
    wrong_number_of_args_error("output",args,1);
  }
}

#endif /* f_Stylesheet_output_1_defined, f_Stylesheet_output_2_defined */
#define f_Stylesheet_set_attributes_defined
ptrdiff_t f_Stylesheet_set_attributes_fun_num = 0;
void f_Stylesheet_set_attributes(INT32 args) {
#line 286 "Stylesheet.cmod"
struct mapping * variables;
#line 286 "Stylesheet.cmod"
if(args != 1) wrong_number_of_args_error("set_attributes",args,1);
#line 286 "Stylesheet.cmod"
if(Pike_sp[0-1].type != PIKE_T_MAPPING) SIMPLE_BAD_ARG_ERROR("set_attributes",1,"mapping(mixed:mixed)");
#line 286 "Stylesheet.cmod"
debug_malloc_pass(variables=Pike_sp[0-1].u.mapping);
{
  const char ** vars = NULL;
  int varcount, i;
  struct keypair * k;
  INT32 e;
  xmlChar* value;
  const xmlChar* str;

  if ( variables != NULL ) 
  {
    struct svalue sind, sval;
    int tmpint=0;

    varcount = 0;

    if(THIS->object_data->atts != NULL)
    {
      free(THIS->object_data->atts);
      THIS->object_data->atts = NULL;
    }
    vars = malloc( sizeof(char *) * 
                  ( 1 + ((m_sizeof(variables)) * 2 )));
    MAPPING_LOOP(variables)  
    {
      sind = k->ind;
      sval = k->val;
      if(!(sind.type == T_STRING && sval.type == T_STRING)) 
      {
        continue;
      }
      /* index */
      str  = (const xmlChar *) sval.u.string->str;
      if ( xmlStrstr(str, (xmlChar*) "\n") == NULL ) 
      {
        if ( xmlStrchr(str, '"') ) 
        {
          if (xmlStrchr(str, '\'')) 
          {
            Pike_error("Param contains quote and double-quotes.");
            return;    
          }
          value = xmlStrdup((const xmlChar *)"'");
          value = xmlStrcat(value, str);
          value = xmlStrcat(value, (const xmlChar *)"'");
        }
        else 
        {
          value = xmlStrdup((const xmlChar *)"\"");
          value = xmlStrcat(value, str);
          value = xmlStrcat(value, (const xmlChar *)"\"");
        }              
      }
      else 
      {
        /* param contains newlines */
        value = xmlStrdup((const xmlChar *)"\"");
        value = xmlStrcat(value, (const xmlChar *)"\"");
      }
            
      str = (const xmlChar*) sind.u.string->str;

      /* namespaces are bad */
      if ( xmlStrchr(str, ':') ) 
        vars[tmpint++] = strdup("supressed");
      else
        vars[tmpint++] = strdup(str);
      vars[tmpint++] = value;
      if ( varcount > MAX_PARAMS )
        Pike_error("Too many params !");
      varcount++;
    }
    vars[tmpint] = NULL;
  }
  else 
  {
    vars = malloc(sizeof(char *));
    vars[0] = NULL;
  }

  THIS->object_data->atts = vars;
  pop_stack();
}

}
#line 370 "Stylesheet.cmod"
int check_stylesheet_created()
{
  if(THIS->object_data->stylesheet != NULL)
    return 1;
  Pike_error("Stylesheet not initialized.\n");
}


#undef internal_init_Stylesheet_defined
#define internal_init_Stylesheet_defined

#undef Stylesheet_event_handler_defined
#define Stylesheet_event_handler_defined
static void init_Stylesheet_struct(void)
#line 378 "Stylesheet.cmod"
{
  STYLESHEET_OBJECT_DATA * dta;

  dta = 
	(STYLESHEET_OBJECT_DATA*)malloc(sizeof(STYLESHEET_OBJECT_DATA));
    if (!dta)
        Pike_error("init_stylesheet: Out of memory!\n");

    dta->stylesheet = NULL;
    dta->atts = NULL;
    THIS->object_data = dta;
}


#undef internal_exit_Stylesheet_defined
#define internal_exit_Stylesheet_defined

#undef Stylesheet_event_handler_defined
#define Stylesheet_event_handler_defined
static void exit_Stylesheet_struct(void)
#line 392 "Stylesheet.cmod"
{ 

  if((* THIS->object_data->refs)==1)
  {
    xsltFreeStylesheet(THIS->object_data->stylesheet);
  }
  else
  {
   (*( THIS->object_data->refs)) --;
  }

  if(THIS->object_data->atts != NULL)
  {
    free(THIS->object_data->atts);
  }

  if(THIS->node != NULL)
  {
/* FIXME: this is a memory leak!!! */
/*    free_object(THIS->node); */
  }

   if(THIS->object_data)
  {
    free(THIS->object_data);
  }
}

#ifdef Stylesheet_event_handler_defined
static void Stylesheet_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_Stylesheet_defined
  case PROG_EVENT_INIT: init_Stylesheet_struct(); break;

#endif /* internal_init_Stylesheet_defined */

#ifdef internal_exit_Stylesheet_defined
  case PROG_EVENT_EXIT: exit_Stylesheet_struct(); break;

#endif /* internal_exit_Stylesheet_defined */
  default: break; 
  }
}

#endif /* Stylesheet_event_handler_defined */
/*! @endclass
 */


/*! @endmodule
 */

/*! @endmodule
 */

/*! @endmodule
 */


#line 434 "Stylesheet.cmod"
void pike_init_xml2_stylesheet()
{
  
#ifdef class_Stylesheet_defined

#ifdef PROG_STYLESHEET_ID
#line 78 "Stylesheet.cmod"
  START_NEW_PROGRAM_ID(STYLESHEET);
#else
#line 78 "Stylesheet.cmod"
  start_new_program();

#endif /* PROG_STYLESHEET_ID */

#ifndef tObjImpl_STYLESHEET

#undef tObjImpl_STYLESHEET
#define tObjImpl_STYLESHEET tObj

#endif /* tObjImpl_STYLESHEET */

#ifdef THIS_STYLESHEET
  Stylesheet_storage_offset = ADD_STORAGE(struct Stylesheet_struct);
#endif /* THIS_STYLESHEET */

#ifdef var_node_Stylesheet_defined
  PIKE_MAP_VARIABLE("node", Stylesheet_storage_offset + OFFSETOF(Stylesheet_struct, node),
                    tObj, PIKE_T_OBJECT, 0);
#endif /* var_node_Stylesheet_defined */

#ifdef Stylesheet_event_handler_defined
  pike_set_prog_event_callback(Stylesheet_event_handler);

#endif /* Stylesheet_event_handler_defined */

#ifdef f_Stylesheet_cq__sprintf_defined
  f_Stylesheet_cq__sprintf_fun_num =
#line 121 "Stylesheet.cmod"
    ADD_FUNCTION2("_sprintf", f_Stylesheet_cq__sprintf, tFunc("\10\200\0\0\0\177\377\377\377" tMix,tString), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Stylesheet_cq__sprintf_defined */

#ifdef f_Stylesheet_create_defined
  f_Stylesheet_create_fun_num =
#line 130 "Stylesheet.cmod"
    ADD_FUNCTION2("create", f_Stylesheet_create, tFunc(tNone,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Stylesheet_create_defined */

#ifdef f_Stylesheet_apply_defined
  f_Stylesheet_apply_fun_num =
#line 145 "Stylesheet.cmod"
    ADD_FUNCTION2("apply", f_Stylesheet_apply, tFunc(tObj,tObj), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Stylesheet_apply_defined */

#ifdef f_Stylesheet_output_defined
  Stylesheet_f_Stylesheet_output_fun_num =
#line 263 "Stylesheet.cmod"
    ADD_FUNCTION2("output", f_Stylesheet_output, tOr(tFunc(tObj,tString),tFunc(tObj "\10\200\0\0\0\177\377\377\377",tString)), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Stylesheet_output_defined */

#ifdef f_Stylesheet_set_attributes_defined
  f_Stylesheet_set_attributes_fun_num =
#line 286 "Stylesheet.cmod"
    ADD_FUNCTION2("set_attributes", f_Stylesheet_set_attributes, tFunc(tMapping,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Stylesheet_set_attributes_defined */
#line 79 "Stylesheet.cmod"
  Pike_compiler->new_program->flags |= PROGRAM_USES_PARENT;
#line 78 "Stylesheet.cmod"
  Stylesheet_program=end_program();
#line 78 "Stylesheet.cmod"
  Stylesheet_program_fun_num=add_program_constant("Stylesheet",Stylesheet_program,0);

#endif /* class_Stylesheet_defined */
#line 437 "Stylesheet.cmod"
}

void pike_exit_xml2_stylesheet()
{
  
#ifdef class_Stylesheet_defined
  if(Stylesheet_program) {
#line 78 "Stylesheet.cmod"
    free_program(Stylesheet_program);
    Stylesheet_program=0;
  }

#endif /* class_Stylesheet_defined */
#line 442 "Stylesheet.cmod"
}



gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University