コード例 #1
0
xmlParserCtxtPtr
RS_XML_xmlCreateConnectionParserCtxt(USER_OBJECT_ con)
{
      xmlParserInputBufferPtr buf;
      xmlParserCtxtPtr ctx = NULL;

#ifdef LIBXML2
      ctx = xmlNewParserCtxt();
#ifndef LIBXML2_NEW_BUFFER  // < 2.9.1
      ctx->_private = (USER_OBJECT_) con;
                                      /* R_chk_calloc */
      buf = (xmlParserInputBufferPtr) calloc(1, sizeof(xmlParserInputBuffer));
      buf->readcallback = RS_XML_readConnectionInput;
      buf->context = (void*) ctx;
      buf->raw = NULL; /* buf->buffer; */
      xmlBufferPtr tmp = xmlBufferCreate();
      buf->buffer = tmp;
#else
    RFunCtxData *userData = (RFunCtxData *) R_alloc(sizeof(RFunCtxData), 1);
    userData->fun = con;
    userData->ctx = ctx;
    buf = xmlParserInputBufferCreateIO(RS_XML_readConnectionInput, NULL, userData, XML_CHAR_ENCODING_NONE);
#endif

      xmlParserInputPtr input = xmlNewIOInputStream(ctx, buf, XML_CHAR_ENCODING_NONE);
      if(!input) {
	  PROBLEM "can't create new IOInputStream"
	      ERROR;
      }
      inputPush(ctx, input);
#endif
      return(ctx);
}
コード例 #2
0
/* call-seq:
 *    XML::Parser::Context.io(io) -> XML::Parser::Context
 *
 * Creates a new parser context based on the specified io object.
 *
 * Parameters:
 *
 *  io - A ruby IO object.
*/
static VALUE rxml_parser_context_io(VALUE klass, VALUE io)
{
  xmlParserCtxtPtr ctxt;
  xmlParserInputBufferPtr input;
  xmlParserInputPtr stream;

  input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
                                       (void*)io, XML_CHAR_ENCODING_NONE);
    
  ctxt = xmlNewParserCtxt();
  if (!ctxt)
  {
    xmlFreeParserInputBuffer(input);
    rxml_raise(&xmlLastError);
  }

  stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);

  if (!stream)
  {
    xmlFreeParserInputBuffer(input);
    xmlFreeParserCtxt(ctxt);
    rxml_raise(&xmlLastError);
  }
  inputPush(ctxt, stream);
  return rxml_parser_context_wrap(ctxt);
}
コード例 #3
0
ファイル: modxslt-libxml.c プロジェクト: ccontavalli/mod-xslt
  /* Taken from libxml2, xmlSAXParseMemoryWithData */
xmlDocPtr mxslt_doc_xml_load_entity(mxslt_doc_t * document, char * localfile) {
  xmlParserCtxtPtr ctx;
  xmlParserInputPtr input;
  xmlDocPtr retval;
  xmlChar * filename;

  mxslt_doc_debug_print(document, MXSLT_DBG_LIBXML | MXSLT_DBG_DEBUG | MXSLT_DBG_VERBOSE0,
		"load_entity/xmlCreateMemoryParserCtxt -- replacing entities: %08x\n", xmlSubstituteEntitiesDefaultValue);

    /* SNIPPET: This is a good mix&shake of 
     * xmlCreateMemoryParserCtxt, xmlCreateFileParserCtxt */
  ctx=xmlNewParserCtxt();
  if(ctx == NULL)
    return NULL;

#if LIBXML_VERSION >= 20600
  xmlCtxtUseOptions(ctx, MXSLT_XSLT_OPTIONS);
#endif

    /* Remember which document we are parsing
     * in this context */
  /* ctx->_private=document; */

  filename=xmlCanonicPath((xmlChar *)localfile);
  if(filename == NULL) {
    xmlFreeParserCtxt(ctx);
    return NULL;
  }
  
  input=xmlLoadExternalEntity((char *)filename, NULL, ctx);
  xmlFree(filename);
  if(input == NULL) {
    xmlFreeParserCtxt(ctx);
    return NULL;
  }

  inputPush(ctx, input);

  if(ctx->directory == NULL)
    ctx->directory=xmlParserGetDirectory(localfile);
    /* END SNIPPET */

  /* MXSLT_DUMP_CTX(ctx); */

    /* Parse document */
  xmlParseDocument(ctx);

  if(ctx->wellFormed)
    retval=ctx->myDoc;
  else {
    retval=NULL;
    xmlFreeDoc(ctx->myDoc);
    ctx->myDoc=NULL;
  }
  xmlFreeParserCtxt(ctx);

  return retval;
}
コード例 #4
0
ファイル: testchar.c プロジェクト: GerHobbelt/libxml2
static void testCharRanges(void) {
    char data[5];
    xmlParserCtxtPtr ctxt;
    xmlParserInputBufferPtr buf;
    xmlParserInputPtr input;

    memset(data, 0, 5);

    /*
     * Set up a parsing context using the above data buffer as
     * the current input source.
     */
    ctxt = xmlNewParserCtxt();
    if (ctxt == NULL) {
        fprintf(stderr, "Failed to allocate parser context\n");
	return;
    }
    buf = xmlParserInputBufferCreateStatic(data, sizeof(data),
                                           XML_CHAR_ENCODING_NONE);
    if (buf == NULL) {
        fprintf(stderr, "Failed to allocate input buffer\n");
	goto error;
    }
    input = xmlNewInputStream(ctxt);
    if (input == NULL) {
        xmlFreeParserInputBuffer(buf);
	goto error;
    }
    input->filename = NULL;
    input->buf = buf;
    input->cur =
    input->base = xmlBufContent(input->buf->buffer);
    input->end = input->base + 4;
    inputPush(ctxt, input);

    printf("testing char range: 1");
    fflush(stdout);
    testCharRangeByte1(ctxt, data);
    printf(" 2");
    fflush(stdout);
    testCharRangeByte2(ctxt, data);
    printf(" 3");
    fflush(stdout);
    testCharRangeByte3(ctxt, data);
    printf(" 4");
    fflush(stdout);
    testCharRangeByte4(ctxt, data);
    printf(" done\n");
    fflush(stdout);

error:
    xmlFreeParserCtxt(ctxt);
}
コード例 #5
0
ファイル: jsio.c プロジェクト: atifs/juise
/*
 * Read xmlDocument from server
 */
static xmlDoc *
js_document_read (xmlParserCtxtPtr ctxt, js_session_t *jsp,
			const char *url, const char *encoding, int options)
{
    xmlParserInputBufferPtr input;
    xmlParserInputPtr stream;
    xmlDoc *docp;

    if (jsp == NULL || ctxt == NULL || jsp->js_state == JSS_DEAD)
        return NULL;

    xmlCtxtReset(ctxt);

    input = js_buffer_create(jsp, XML_CHAR_ENCODING_NONE);
    if (input == NULL)
        return NULL;
    input->closecallback = NULL;

    stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
    if (stream == NULL) {
        xmlFreeParserInputBuffer(input);
        return NULL;
    }

    inputPush(ctxt, stream);
    xmlCtxtUseOptions(ctxt, options);

    xmlCharEncodingHandlerPtr hdlr;
    if (encoding && ((hdlr = xmlFindCharEncodingHandler(encoding)) != NULL))
	xmlSwitchToEncoding(ctxt, hdlr);

    if (url != NULL && ctxt->input != NULL && ctxt->input->filename == NULL)
        ctxt->input->filename = (char *) xmlStrdup((const xmlChar *) url);

    /*
     * All right.  The stage is set, time to open the curtain and let
     * the show begin.
     */
    xmlParseDocument(ctxt);

    docp = ctxt->myDoc;
    ctxt->myDoc = NULL;

    if (docp && !ctxt->wellFormed) {
	xmlFreeDoc(docp);
        docp = NULL;
    }

    return docp;
}
コード例 #6
0
ファイル: modxslt-libxml.c プロジェクト: ccontavalli/mod-xslt
  /* Taken from libxml2, xmlSAXParseMemoryWithData */
xmlDocPtr mxslt_doc_xml_parse(mxslt_doc_t * document, xmlParserInputBufferPtr buf, char * localfile) {
  xmlParserCtxtPtr ctx;
  xmlParserInputPtr input;
  xmlDocPtr retval;

  mxslt_doc_debug_print(document, MXSLT_DBG_LIBXML | MXSLT_DBG_DEBUG | MXSLT_DBG_VERBOSE0,
		"xml_parse/xmlCreateMemoryParserCtxt -- replacing entities: %08x\n", xmlSubstituteEntitiesDefaultValue);

  if(buf == NULL)
    return NULL;

    /* SNIPPET: This is a good mix&shake of 
     * xmlCreateMemoryParserCtxt, xmlCreateFileParserCtxt */
  ctx=xmlNewParserCtxt();
  if(ctx == NULL) {
    xmlFreeParserInputBuffer(buf);
    return NULL;
  }

#if LIBXML_VERSION >= 20600
  xmlCtxtUseOptions(ctx, MXSLT_XSLT_OPTIONS);
#endif

    /* Default are no longer changed... since 2.6.0 they
     * are completely ignored, leading to broken modxslt :|| */
  if(ctx->sax) {
    ctx->sax->resolveEntity=mxslt_sax_resolve_entity;
    ctx->sax->processingInstruction=mxslt_sax_processing_instruction;
  }

    /* Remember which document we are parsing
     * in this context */
/*  ctx->_private=document; */

  input=xmlNewInputStream(ctx);
  if(input == NULL) {
    xmlFreeParserInputBuffer(buf);
    xmlFreeParserCtxt(ctx);

    return NULL;
  }

  input->filename=(char *)xmlCanonicPath((xmlChar *)localfile);
  if(input->filename == NULL) {
    xmlFreeParserCtxt(ctx);
    xmlFreeParserInputBuffer(buf);
    xmlFreeInputStream(input);

    return NULL;
  }

  input->buf=buf;
#if LIBXML_VERSION < 20900
  input->base=input->buf->buffer->content;
  input->cur=input->buf->buffer->content;
  input->end=&input->buf->buffer->content[input->buf->buffer->use];
#else
    /* With libxml2 2.9.0, the buffer struct can only be accessed through
     * methods. */
  input->base=xmlBufContent(input->buf->buffer);
  input->cur=xmlBufContent(input->buf->buffer);
  input->end=xmlBufEnd(input->buf->buffer);
#endif

  inputPush(ctx, input);

  if(ctx->directory == NULL)
    ctx->directory=xmlParserGetDirectory(localfile);
    /* END SNIPPET */

  if(mxslt_doc_debug_level(document, MXSLT_DBG_LIBXML | MXSLT_DBG_DEBUG | MXSLT_DBG_VERBOSE2)) 
    mxslt_doc_dump_ctx(ctx, document);

    /* Parse document */
  xmlParseDocument(ctx);

  if(ctx->wellFormed)
    retval=ctx->myDoc;
  else {
    retval=NULL;
    xmlFreeDoc(ctx->myDoc);
    ctx->myDoc=NULL;
  }
  xmlFreeParserCtxt(ctx);
  /* xmlFreeParserInputBuffer(buf); */

  return retval;
}
コード例 #7
0
void evalOpcode(unsigned char opcode) {

    int i;
    int16 opr1, opr2, opr3;
    unsigned int16 genPurpose = 0;

    if (opcode & 0b10000000) {
        genPurpose = gblMemPtr + 2;
        gblMemPtr = ((((unsigned int16)opcode & 0b00111111) << 8) + 2*fetchNextOpcode());
        opr1 = fetchNextOpcode();
        if (opcode & 0b01000000) {
            for (i = 0; i < (opr1 + 3); i++) {
                inputPop();
            }
        }
        for (i = 0; i < opr1; i++) {
            inputPush (stkPop());
        }
        inputPush (gblStkPtr);
        inputPush (genPurpose);
        inputPush(gblInputStkPtr - (opr1 + 2));
        return;
    }
    switch (opcode) {
    case CODE_END:
        gblLogoIsRunning = 0;
        output_low (RUN_LED);
        // clear thes variables just in case.
        gblLoopAddress = 0;
        gblRepeatCount = 0;
        break;
    case NUM8:
        int8 Hi3 = fetchNextOpcode();
        stkPush(Hi3);
        break;
    case NUM16:
        int8 Hi2 = fetchNextOpcode();
        int8 Lo2 = fetchNextOpcode();
        unsigned int16 teste4 = Hi2 << 8;
        teste4 += Lo2;
        stkPush (teste4);
        break;
    case LIST:
        stkPush(gblMemPtr + 2); //incremento de 2 em 2
        gblMemPtr += (2 * fetchNextOpcode());
        break;
    case EOL:
        genPurpose = stkPop();
        if (genPurpose > gblMemPtr) {
            //printf(usb_cdc_putc,"genPurpose >>>> gblMemPtr");
            gblMemPtr = genPurpose;
        } else {
            //printf(usb_cdc_putc,"genPurpose <<<< gblMemPtr");
            gblMemPtr = genPurpose;
            gblRepeatCount = stkPop();   // repeat count
            //printf(usb_cdc_putc," gblRepeatCount %Lu \n",genPurpose);
            if (gblRepeatCount > 1)
                gblRepeatCount--;
            if (gblRepeatCount != 1) {
                stkPush (gblRepeatCount);
                stkPush (gblMemPtr);
            }
        }
        break;
    case EOLR:
        if (stkPop()) {   // if condition is true
            stkPop();        // throw away the loop address
            gblMemPtr = stkPop(); // fetch the next command address
        } else { // if condition if false -> keep on looping.
            gblMemPtr = stkPop();
            stkPush (gblMemPtr);
            delay_ms(5); // this prevents the waituntil loop to execute too rapidly
            // which has proven to cause some problems when reading sensor values.
        }
        break;
    case LTHING:
        genPurpose = 2 * fetchNextOpcode();  // index of the input variable
        opr1 = inputPop();  // base address in the input stack
        inputPush(opr1);    // push the base address back to the stack.
        stkPush (gblInputStack[opr1 + genPurpose]);
        break;
    case STOP:
    case OUTPUT:
        if (opcode == OUTPUT){
            genPurpose = stkPop(); // this is the output value
        }
        opr1 = inputPop();  // this is the proc-input stack base address
        gblMemPtr = inputPop(); // this is the return address
        opr2 = inputPop();  // this is the data stack index;
        // remove any remaining data that belongs to the current procedure from the data stack
        // Usually this is important for the STOP opcode.
        while (gblStkPtr > opr2){
            stkPop();
        }
        // remove the procedure inputs from the input stack
        while (gblInputStkPtr > opr1){
            inputPop();
        }
        // Output will push the output to the stack
        if (opcode == OUTPUT){
            stkPush (genPurpose);
        }
        break;
    case REPEAT:
        gblLoopAddress = stkPop();
        gblRepeatCount = stkPop();
        // these will be poped by EOL
        stkPush (gblMemPtr);  // address after repeat is complete

        if (gblRepeatCount > 1) {
            stkPush (gblRepeatCount);
            stkPush (gblLoopAddress); // address while still repeating
            gblMemPtr = gblLoopAddress;
        } else if (gblRepeatCount == 1) {
            gblMemPtr = gblLoopAddress;
        } else {  // if loop count = 0
            gblMemPtr = stkPop();
        }
        break;
    case COND_IF:
        opr1 = stkPop();  // if true pointer address
        opr2 = stkPop();  // condition
        if (opr2) {
            stkPush(gblMemPtr);
            gblMemPtr = opr1;
        }
        break;
    case COND_IFELSE:
        opr1 = stkPop(); // if false pointer address
        opr2 = stkPop(); // if true pointer address
        opr3 = stkPop(); // condition
        stkPush(gblMemPtr);
        if (opr3) {
            gblMemPtr = opr2;
        } else {
            gblMemPtr = opr1;
        }
        break;
    case BEEP:
        beep();
        break;
    case WAITUNTIL:
        gblLoopAddress = stkPop();
        // these will be poped by EOLR
        stkPush(gblMemPtr);  // address after repeat is complete
        stkPush (gblLoopAddress); // address while still repeating
        gblMemPtr = gblLoopAddress;
        break;
    case LOOP:
        gblLoopAddress = stkPop(); // the begining of loop
        gblRepeatCount = 0; // disable this counter (loop forever)
        stkPush(0);   // this distinguishes LOOP from Repeat. (see EOL)
        stkPush(gblLoopAddress); // push loop address back into the stack
        // so that EOL will loop
        gblMemPtr = gblLoopAddress;
        break;
    case WAIT:
        gblWaitCounter = stkPop() * 4;
        break;
    case TIMER:
        stkPush(gblTimer); // gblTimer increases every 1ms. See in RTCC interrupt
        break;
    case RESETT:
        gblTimer = 0;
        break;
    case SEND:
        genPurpose = stkPop();
        break;
    case IR:
        stkPush (gblMostRecentlyReceivedByte);
        gblNewByteHasArrivedFlag = 0;
        break;
    case NEWIR:
        stkPush (gblNewByteHasArrivedFlag);
        break;
    case RANDOM:
        stkPush (rand());
        break;
    case OP_PLUS:
    case OP_MINUS:
    case OP_MULTIPLY:
    case OP_DIVISION:
    case OP_REMAINDER:
    case OP_EQUAL:
    case OP_GREATER:
    case OP_LESS:
    case OP_AND:
    case OP_OR:
    case OP_XOR:
        opr2=stkPop();  // second operand
        opr1=stkPop();// first operand
        switch (opcode) {
            case OP_PLUS:
                opr1+=opr2;
                break;
            case OP_MINUS:
                opr1-=opr2;
                break;
            case OP_MULTIPLY:
                opr1*=opr2;
                break;
            case OP_DIVISION:
                opr1/=opr2;
                break;
            case OP_REMAINDER:
                opr1%=opr2;
                break;
            case OP_EQUAL:
                opr1=(opr1==opr2);
                break;
            case OP_GREATER:
                opr1=(opr1>opr2);
                break;
            case OP_LESS:
                opr1=(opr1<opr2);
                break;
            case OP_AND:
                opr1=(opr1&&opr2);
                break;
            case OP_OR:
                opr1=(opr1||opr2);
                break;
            case OP_XOR:
                opr1=(opr1^opr2);
                break;
        };
        stkPush(opr1);
        break;
    case OP_NOT:
        stkPush(!stkPop());
        break;
    case SETGLOBAL:
        genPurpose = stkPop();// this is the value
        globalVariables[stkPop()] = genPurpose;
        break;
    case GETGLOBAL:
        stkPush(globalVariables[stkPop()]);
        break;
    case ASET:
        opr2 = stkPop();// this is the value to be stored
        opr1 = stkPop() * 2;// this is the array index. Each entry is two bytes wide.
        genPurpose = ARRAY_BASE_ADDRESS + stkPop();// this is the base address of the array.
        flashSetWordAddress(genPurpose + opr1);
        flashWrite(opr2);
        break;
    case AGET:
        opr1 = stkPop() * 2;// this is the array index. Each entry is two bytes wide.
        genPurpose = ARRAY_BASE_ADDRESS + stkPop();// this is the base address of the array.
        opr2 = read_program_eeprom(genPurpose + opr1);
        stkPush(opr2);
        break;
    case RECORD:
        genPurpose = stkPop();
        // PCM parts (14 bit PICs like the 16F877) uses an external EEPROM for data Logging storage
        flashSetWordAddress(RECORD_BASE_ADDRESS + gblRecordPtr++);
        flashWrite(genPurpose);
        // save current record pointer location
        flashSetWordAddress(MEM_PTR_LOG_BASE_ADDRESS);
        flashWrite(gblRecordPtr);
        break;
    case RECALL:
        genPurpose = read_program_eeprom(RECORD_BASE_ADDRESS + gblRecordPtr++);
        stkPush(genPurpose);
        break;
    case RESETDP:
        gblRecordPtr = 0;
        break;
    case SETDP:
        gblRecordPtr = stkPop() * 2;
        break;
    case ERASE:
        opr1 = stkPop() * 2;
        for (genPurpose=0; genPurpose<opr1; genPurpose++) {
            flashSetWordAddress(RECORD_BASE_ADDRESS + genPurpose);
            flashWrite(0);
        }
        gblRecordPtr = 0;
        break;
    case OPC_MOTORS_OFF:
        motors_off();
        break;
    case OPC_MOTORS_THATWAY:
        motors_that_way();
        break;
    case OPC_MOTORS_THISWAY:
        motors_this_way();
        break;
    case OPC_MOTORS_REVERT:
        motors_reverse();
        break;
    case OPC_MOTORS_ON_FOR:
    case OPC_MOTORS_ON:
        motors_on();
        if (opcode == OPC_MOTORS_ON_FOR) {
            set_on_for(stkPop()*4);
        }
        break;
    case OPC_MOTORS_POWER:
        motors_power(stkPop());
        break;
    case OPC_MOTORS_ANGLE:
        motors_angle(stkPop());
        break;
    case OPC_ACTIVATE_MOTORS:
        mtrsActive = stkPop();
        break;
    case REALLY_STOP:
        start_stop_logo_machine = 1;
        break;
    case EB:
        stkPush(read_program_eeprom(stkPop()));
        break;
    case DB:
        opr1 = stkPop();
        opr2 = stkPop();
        flashSetWordAddress(opr2);
        flashWrite(opr1);
        break;
    case LOW_BYTE:
        stkPush(stkPop() & 0xff);
        break;
    case HIGH_BYTE:
        stkPush(stkPop() >> 8);
        break;
    case SENSOR1:
    case SENSOR2:
    case SENSOR3:
    case SENSOR4:
    case SENSOR5:
    case SENSOR6:
    case SENSOR7:
    case SENSOR8:
        if (opcode < SENSOR3) {
            i = opcode - SENSOR1;
        } else {
            i = opcode - SENSOR3 + 2;
        }
        stkPush(readSensor(i));
        break;
    case SWITCH1:
    case SWITCH2:
    case SWITCH3:
    case SWITCH4:
    case SWITCH5:
    case SWITCH6:
    case SWITCH7:
    case SWITCH8:
        if (opcode < SWITCH3) {
            i = opcode - SWITCH1;
        } else {
            i = opcode - SWITCH3 + 2;
        }
        stkPush(readSensor(i)>>9);
        break;
    case ULED_ON:
        output_high(USER_LED);
        break;
    case ULED_OFF:
        output_low(USER_LED);
        break;

    case CL_I2C_START:
        i2c_start();
        break;
    case CL_I2C_STOP:
        i2c_stop();
        break;
    case CL_I2C_WRITE:
        i2c_write(stkPop());
        break;
    case CL_I2C_READ:
        stkPush(i2c_read(stkPop()));
        break;
    default:
        start_stop_logo_machine = 1;
        break;
    };
}