示例#1
0
static PyObject *CS_COMMAND_ct_cancel(CS_COMMANDObj *self, PyObject *args)
{
    int type;
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, "i", &type))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_cancel(NULL, self->cmd, type);
    SY_CONN_END_THREADS(self->conn);

    if (self->debug)
	debug_msg("ct_cancel(NULL, cmd%d, %s) -> %s\n",
		  self->serial,
		  value_str(VAL_CANCEL, type), value_str(VAL_STATUS, status));
    if (PyErr_Occurred())
        return NULL;

    return PyInt_FromLong(status);
}
示例#2
0
static PyObject *CS_COMMAND_ct_results(CS_COMMANDObj *self, PyObject *args)
{
    CS_RETCODE status;
    CS_INT result = 0;

    if (!PyArg_ParseTuple(args, ""))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_results(self->cmd, &result);
    SY_CONN_END_THREADS(self->conn);

    if (self->debug)
	debug_msg("ct_results(cmd%d, &result) -> %s, %s\n",
		  self->serial, value_str(VAL_STATUS, status),
		  value_str(VAL_RESULT, result));
    if (PyErr_Occurred())
	return NULL;

    return Py_BuildValue("ii", status, result);
}
      void build_large_row(ObSSTableRow &row)
      {
        ObObj tmp_obj;
        int64_t value_size = 1024 * 64 + 1;
        char value_data[value_size];
        char *ptr;

        //build data
        ptr = value_data;
        for (int i = 0; i < 128 * 64; ++i) {
          memcpy(ptr, "testing ", 8);
          ptr += 8;
        }
        ObString value_str(value_size, value_size, value_data);

        Key tmp_key(10, 10, 1000);
        ObString key(tmp_key.key_len(), tmp_key.key_len(), tmp_key.get_ptr());
        row.set_row_key(key);
        row.set_table_id(1000);
        row.set_column_group_id(2);

        for (int i = 0; i < common::OB_MAX_COLUMN_NUMBER; ++i)
        {
          tmp_obj.set_varchar(value_str);
          row.add_obj(tmp_obj);
        }      
      }
示例#4
0
static PyObject *CS_COMMAND_ct_get_data(CS_COMMANDObj *self, PyObject *args)
{
    DataBufObj *databuf;
    int num;
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, "iO!", &num, &DataBufType, &databuf))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_get_data(self->cmd, (CS_INT)num,
			 databuf->buff, databuf->fmt.maxlength,
			 &databuf->copied[0]);
    databuf->indicator[0] = 0;
    SY_CONN_END_THREADS(self->conn);

    if (self->debug)
	debug_msg("ct_get_data(cmd%d, %d, databuf%d->buff,"
		  " %d, &databuf%d->copied[0]) -> %s, %d\n",
		  self->serial, num, databuf->serial,
		  (int)databuf->fmt.maxlength, databuf->serial,
		  value_str(VAL_STATUS, status), (int)databuf->copied[0]);
    if (PyErr_Occurred())
	return NULL;

    return Py_BuildValue("ii", status, databuf->copied[0]);
}
示例#5
0
static PyObject *CS_COMMAND_ct_cmd_drop(CS_COMMANDObj *self, PyObject *args)
{
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, ""))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_cmd_drop(self->cmd);
    SY_CONN_END_THREADS(self->conn);

    if (self->debug)
	debug_msg("ct_cmd_drop(cmd%d) -> %s\n",
		  self->serial, value_str(VAL_STATUS, status));
    if (status == CS_SUCCEED)
	self->cmd = NULL;
    if (PyErr_Occurred())
        return NULL;

    return PyInt_FromLong(status);
}
示例#6
0
static PyObject *CS_COMMAND_ct_send_data(CS_COMMANDObj *self, PyObject *args)
{
    CS_RETCODE status;
    DataBufObj *databuf;

    if (!PyArg_ParseTuple(args, "O!", &DataBufType, &databuf))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_send_data(self->cmd, databuf->buff, databuf->copied[0]);
    SY_CONN_END_THREADS(self->conn);

    if (self->debug)
	debug_msg("ct_send_data(cmd%d, databuf%d->buff, %d) -> %s\n",
		  self->serial, databuf->serial, (int)databuf->copied[0],
		  value_str(VAL_STATUS, status));
    if (PyErr_Occurred())
	return NULL;

    return PyInt_FromLong(status);
}
示例#7
0
void LH_MonitoringDial::updateNeedles()
{
    bool ok;
    SensorItem si = this->selectedSensor(&ok);
    if(ok)
    {
        QStringList names;
        if(!si.group)
        {
            names.append(setup_value_item_->valueText());
            if(needleCount() != 1)
                updateNeedlesList(&names);

            qreal valFlt = (value_str().toFloat(&ok));
            if(ok)
                setVal( valFlt );
        } else {
            QVector<qreal> currVals = getValuesVector(false, 0, ok, &names);
            if(ok)
            {
                if(needleCount() != currVals.count())
                    updateNeedlesList(&names);
                setVal(currVals);
            }
        }
    }
    else if(needleCount() != 0)
    {
        QStringList names;
        updateNeedlesList(&names);
    }
}
示例#8
0
static PyObject *CS_COMMAND_ct_setparam(CS_COMMANDObj *self, PyObject *args)
{
    DataBufObj *databuf;
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, "O!", &DataBufType, &databuf))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    if(databuf->indicator[0] == CS_NULLDATA) {
	    status = ct_setparam(self->cmd, &databuf->fmt,
				 NULL, NULL, &databuf->indicator[0]);
    } else {
	    status = ct_setparam(self->cmd, &databuf->fmt,
				 databuf->buff, &databuf->copied[0],
				 &databuf->indicator[0]);
    }
    SY_CONN_END_THREADS(self->conn);

    if (self->debug) {
	debug_msg("ct_setparam(cmd%d, &databuf%d->fmt=",
		  self->serial, databuf->serial);
	datafmt_debug(&databuf->fmt);
	if(databuf->indicator[0] == CS_NULLDATA) {
		debug_msg(", NULL, NULL, CS_NULLDATA) -> %s\n",
			  value_str(VAL_STATUS, status));
	} else {
		debug_msg(", databuf%d->buff,"
			  " &databuf%d->copied[0], &databuf%d->indicator[0]) -> %s\n",
			  databuf->serial, databuf->serial, databuf->serial,
			  value_str(VAL_STATUS, status));
	}
    }
    if (PyErr_Occurred())
	return NULL;

    return PyInt_FromLong(status);
}
示例#9
0
 void printParam( const char * name,
                  const std::string & value )
   {
       std::string name_str( name );
       std::string value_str( value );
       XMLEscape( name_str );
       XMLEscape( value_str );
       std::cout << "<Param name=\"" << name_str << "\">" << value_str << "</Param>\n";
   }
示例#10
0
	 /// read attributes and values
	void get_attributes(XMLNode::AttributeMap& attributes) const
	{
		const char* p = _buffer_str.c_str();

		 // find end of tag name
		if (*p == '<')
			++p;

		if (*p == '/')
			++p;
		else if (*p == '?')
			++p;

		p = get_xmlsym_end_utf8(p);

		 // read attributes from buffer
		while(*p && *p!='>' && *p!='/') {
			while(isspace((unsigned char)*p))
				++p;

			const char* attr_name = p;

			p = get_xmlsym_end_utf8(p);

			if (*p != '=')
				break;	//@TODO error handling

			size_t attr_len = p - attr_name;

			if (*++p!='"' && *p!='\'')
				break;	//@TODO error handling

			char delim = *p;
			const char* value = ++p;

			while(*p && *p!=delim)
				++p;

			size_t value_len = p - value;

			if (*p)
				++p;	// '"'

#ifdef XS_STRING_UTF8
			XS_String name_str(attr_name, attr_len);
			XS_String value_str(value, value_len);
#else
			XS_String name_str, value_str;
			assign_utf8(name_str, attr_name, attr_len);
			assign_utf8(value_str, value, value_len);
#endif

			attributes[name_str] = DecodeXMLString(value_str);
		}
	}
示例#11
0
bool binspector_parser_t::is_pp_include()
{
    if (!is_keyword(key_include))
        return false;

    adobe::any_regular_t value;

    require_token(adobe::string_k, value);

    std::string value_str(value.cast<std::string>());

    // std::cerr << "Include file " << value_str << '\n';

    // do the parse; so far we don't support include directories; at this point
    // it'll get complicated when it does.
    //
    // we also need to track which files we include so we do not include them twice.

    boost::filesystem::path parsepath(include_directory_set_m[0] / value_str.c_str());

    // REVISIT (fbrereto) : A std::string to a c-string to a std::string to a... c'mon.
    if (!exists(parsepath))
        throw_exception(adobe::make_string("Could not find requested include file: ",
                                           value_str.c_str()).c_str());

    // check if file has already been parsed and added to the AST.
    if (adobe::find(included_file_set_m, parsepath) != included_file_set_m.end())
        return true;

    included_file_set_m.push_back(parsepath);

    boost::filesystem::ifstream            include_stream(parsepath);
    adobe::line_position_t::getline_proc_t getline(new adobe::line_position_t::getline_proc_impl_t(std::bind(&get_input_line, std::ref(include_stream), std::placeholders::_2)));
    adobe::line_position_t                 position(adobe::name_t(parsepath.string().c_str()), getline);

    try
    {
        binspector_parser_t(include_stream,
                            position,
                            include_directory_set_m,
                            set_structure_proc_m,
                            add_field_proc_m,
                            add_unnamed_field_proc_m,
                            add_typedef_proc_m,
                            included_file_set_m).parse();
    }
    catch (const adobe::stream_error_t& error)
    {
        throw std::runtime_error(adobe::format_stream_error(include_stream, error));
    }

    return true;
}
示例#12
0
static PyObject *CS_COMMAND_ct_describe(CS_COMMANDObj *self, PyObject *args)
{
    CS_INT num;
    CS_DATAFMT datafmt;
    PyObject *fmt;
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, "i", &num))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    memset(&datafmt, 0, sizeof(datafmt));

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_describe(self->cmd, num, &datafmt);
    SY_CONN_END_THREADS(self->conn);

    if (self->debug)
	debug_msg("ct_describe(cmd%d, %d, &fmt) -> %s",
		  self->serial, (int)num, value_str(VAL_STATUS, status));
    if (PyErr_Occurred()) {
	if (self->debug)
	    debug_msg("\n");
	return NULL;
    }

    if (status != CS_SUCCEED) {
	if (self->debug)
	    debug_msg(", None\n");
	return Py_BuildValue("iO", status, Py_None);
    }

    fmt = datafmt_alloc(&datafmt, self->strip);
    if (fmt == NULL) {
	if (self->debug)
	    debug_msg("\n");
	return NULL;
    }

    if (self->debug) {
	debug_msg(", datafmt%d=", ((CS_DATAFMTObj*)fmt)->serial);
	datafmt_debug(&datafmt);
	debug_msg("\n");
    }
    return Py_BuildValue("iN", status, fmt);
}
示例#13
0
static void CS_COMMAND_dealloc(CS_COMMANDObj *self)
{
    SY_LEAK_UNREG(self);
    if (!self->is_eed && self->cmd) {
	/* should check return == CS_SUCCEED, but we can't handle failure
	   here */
	CS_RETCODE status;

	status = ct_cmd_drop(self->cmd);
	if (self->debug)
	    debug_msg("ct_cmd_drop(cmd%d) -> %s\n",
		      self->serial, value_str(VAL_STATUS, status));
    }
    Py_XDECREF(self->conn);
    PyObject_DEL(self);
}
示例#14
0
PyObject *cmd_alloc(CS_CONNECTIONObj *conn)
{
    CS_COMMANDObj *self;
    CS_RETCODE status;
    CS_COMMAND *cmd;

    self = PyObject_NEW(CS_COMMANDObj, &CS_COMMANDType);
    if (self == NULL)
	return NULL;
    SY_LEAK_REG(self);
    self->is_eed = 0;
    self->cmd = NULL;
    self->conn = NULL;
    self->strip = conn->strip;
    self->debug = conn->debug;
    self->serial = cmd_serial++;

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(conn);
    status = ct_cmd_alloc(conn->conn, &cmd);
    SY_CONN_END_THREADS(conn);

    if (self->debug)
	debug_msg("ct_cmd_alloc(conn%d, &cmd) -> %s",
		  conn->serial, value_str(VAL_STATUS, status));
    if (PyErr_Occurred()) {
	if (self->debug)
	    debug_msg("\n");
	Py_DECREF(self);
	return NULL;
    }

    if (status != CS_SUCCEED) {
	Py_DECREF(self);
	if (self->debug)
	    debug_msg(", None\n");
	return Py_BuildValue("iO", status, Py_None);
    }

    self->cmd = cmd;
    self->conn = conn;
    Py_INCREF(self->conn);
    if (self->debug)
	debug_msg(", cmd%d\n", self->serial);
    return Py_BuildValue("iN", CS_SUCCEED, self);
}
示例#15
0
static PyObject *CS_COMMAND_ct_bind(CS_COMMANDObj *self, PyObject *args)
{
    CS_INT item;
    CS_DATAFMTObj *datafmt;
    DataBufObj *databuf;
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, "iO!", &item, &CS_DATAFMTType, &datafmt))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    databuf = (DataBufObj *)databuf_alloc((PyObject*)datafmt);
    if (databuf == NULL)
	return NULL;

    /* PyErr_Clear(); */

    SY_CONN_BEGIN_THREADS(self->conn);
    status = ct_bind(self->cmd, item, &databuf->fmt,
		     databuf->buff, databuf->copied, databuf->indicator);
    SY_CONN_END_THREADS(self->conn);

    if (self->debug) {
	debug_msg("ct_bind(cmd%d, %d, &datafmt%d->fmt=",
		  self->serial, (int)item, datafmt->serial);
	datafmt_debug(&databuf->fmt);
	debug_msg(", databuf%d->buff, databuf%d->copied, databuf%d->indicator)"
		  " -> %s",
		  databuf->serial, databuf->serial, databuf->serial,
		  value_str(VAL_STATUS, status));
    }
    if (PyErr_Occurred()) {
	if (self->debug)
	    debug_msg("\n");
	Py_DECREF(databuf);
        return NULL;
    }

    if (self->debug)
	debug_msg(", databuf%d\n", databuf->serial);
    return Py_BuildValue("iN", status, databuf);
}
示例#16
0
static void j2x_object( store::Item_t const &object_item,
                        store::Item_t *parent_xml_item ) {
  ZORBA_ASSERT( parent_xml_item );
  store::Item_t junk_item, key_item, type_name;

  store::Iterator_t k( object_item->getObjectKeys() );
  k->open();
  while ( k->next( key_item ) ) {
    store::Item_t att_name;
    GENV_ITEMFACTORY->createQName(
      att_name, "", "", key_item->getStringValue()
    );
    store::Item_t value_item( object_item->getObjectValue( key_item ) );
    zstring value_str( value_item->getStringValue() );
    GENV_ITEMFACTORY->createString( value_item, value_str );
    type_name = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
    GENV_ITEMFACTORY->createAttributeNode(
      junk_item, *parent_xml_item, att_name, type_name, value_item
    );
  }
  k->close();
}
示例#17
0
GraphicalValue * GraphicalValue::createFromOption(Option::ConstPtr option,
                                                  QWidget * parent)
{
  GraphicalValue * value = nullptr;

  if(option.get() == nullptr)
    return value;

  std::string tag(option->tag());

  if(tag != "array" )
  {
    if(option->has_restricted_list())
      value = new GraphicalRestrictedList(option, parent);
    else
    {
      std::string type(option->type());

      if(type == Protocol::Tags::type<bool>())               // bool option
        value = new GraphicalBool(option->value<bool>(), parent);
      else if(type == Protocol::Tags::type<Real>())          // Real option
        value = new GraphicalDouble(option->value<Real>(), parent);
      else if(type == Protocol::Tags::type<int>())           // int option
        value = new GraphicalInt(false, option->value<int>(), parent);
      else if(type == Protocol::Tags::type<Uint>())          // Uint option
        value = new GraphicalInt(true, option->value<Uint>(), parent);
      else if(type == Protocol::Tags::type<std::string>())   // string option
        value = new GraphicalString(option->value<std::string>().c_str(), parent);
      else if(type == Protocol::Tags::type<URI>())           // URI option
        value = new GraphicalUri(boost::dynamic_pointer_cast<OptionURI const>(option), parent);
      else
        throw CastingFailed(FromHere(), tag + ": Unknown type");
    }
  }
  else
  {
    if(option->has_restricted_list())
      value = new GraphicalArrayRestrictedList(option, parent);
    else
    {
      OptionArray::ConstPtr array = boost::dynamic_pointer_cast<OptionArray const>(option);
      std::string value_str( array->value_str() );
      std::string type( array->elem_type() );
      QString sep( array->separator().c_str() );

      if(type == Protocol::Tags::type<bool>())                 // bool option
      {
        QRegExp regex("(true)|(false)|(1)|(0)|(on)|(off)");
        value = new GraphicalArray(new QRegExpValidator(regex, parent), sep, parent);
      }
      else if(type == Protocol::Tags::type<Real>())            // Real option
      {
        QDoubleValidator * val = new QDoubleValidator(nullptr);
        val->setNotation(QDoubleValidator::ScientificNotation);
        value = new GraphicalArray(val, sep, parent);
      }
      else if(type == Protocol::Tags::type<int>())              // int option
        value = new GraphicalArray(new QIntValidator(), sep, parent);
      else if(type == Protocol::Tags::type<Uint>())             // Uint option
      {
        QIntValidator * val = new QIntValidator();
        val->setBottom(0);
        value = new GraphicalArray(val, sep, parent);
      }
      else if(type == Protocol::Tags::type<std::string>())      // string option
        value = new GraphicalArray(nullptr,sep,  parent);
      else if(type == Protocol::Tags::type<URI>())              // URI option
        value = new GraphicalUriArray(sep, parent);
      else
        throw CastingFailed(FromHere(), tag + ": Unknown type");

      value->setValue( QString(value_str.c_str()).split(array->separator().c_str()) );
    }
  }
  return value;
}
示例#18
0
static PyObject *CS_COMMAND_ct_res_info(CS_COMMANDObj *self, PyObject *args)
{
    int type;
    CS_RETCODE status;
    CS_INT int_val;
    CS_BOOL bool_val;
    char *type_str = NULL;

    if (!PyArg_ParseTuple(args, "i", &type))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    switch (type) {
    case CS_BROWSE_INFO:
	/* ct_res_info(CS_BROWSE_INFO) -> status, bool */
	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_res_info(self->cmd, type, &bool_val, CS_UNUSED, NULL);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_res_info(cmd%d, CS_BROWSE_INFO, &value, CS_UNUSED,"
		      " NULL) -> %s, %d\n",
		      self->serial,
		      value_str(VAL_STATUS, status), (int)bool_val);
	if (PyErr_Occurred())
	    return NULL;

	return Py_BuildValue("ii", status, bool_val);

#ifdef CS_MSGTYPE
    case CS_MSGTYPE:
	/* ct_res_info(CS_MSGTYPE) -> status, int */
    {
	CS_USHORT ushort_val;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_res_info(self->cmd, type, &ushort_val, CS_UNUSED, NULL);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_res_info(cmd%d, CS_MSGTYPE, &value, CS_UNUSED, NULL)"
		      " -> %s, %d\n",
		      self->serial, value_str(VAL_STATUS, status), ushort_val);
	if (PyErr_Occurred())
	    return NULL;

	return Py_BuildValue("ii", status, ushort_val);
    }
#endif

    case CS_CMD_NUMBER:
	/* ct_res_info(CS_CMD_NUMBER) -> status, int */
	type_str = "CS_CMD_NUMBER";
    case CS_NUM_COMPUTES:
	/* ct_res_info(CS_NUM_COMPUTES) -> status, int */
	if (type_str == NULL)
	    type_str = "CS_NUM_COMPUTES";
    case CS_NUMDATA:
	/* ct_res_info(CS_NUMDATA) -> status, int */
	if (type_str == NULL)
	    type_str = "CS_NUMDATA";
    case CS_NUMORDERCOLS:
	/* ct_res_info(CS_NUMORDER_COLS) -> status, int */
	if (type_str == NULL)
	    type_str = "CS_NUMORDER_COLS";
    case CS_ROW_COUNT:
	/* ct_res_info(CS_ROW_COUNT) -> status, int */
	if (type_str == NULL)
	    type_str = "CS_ROW_COUNT";
    case CS_TRANS_STATE:
	/* ct_res_info(CS_TRANS_STATE) -> status, int */
	if (type_str == NULL)
	    type_str = "CS_TRANS_STATE";
	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_res_info(self->cmd, type, &int_val, CS_UNUSED, NULL);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_res_info(cmd%d, %s, &value, CS_UNUSED, NULL)"
		      " -> %s, %d\n",
		      self->serial, type_str,
		      value_str(VAL_STATUS, status), (int)int_val);
	if (PyErr_Occurred())
	    return NULL;

	return Py_BuildValue("ii", status, int_val);

#ifdef CS_ORDERBY_COLS
    case CS_ORDERBY_COLS:
	/* ct_res_info(CS_ORDERBY_COLS) -> status, list of int */
    {
	PyObject *list;
	CS_INT *col_nums;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_res_info(self->cmd, CS_NUMORDERCOLS, &int_val, CS_UNUSED, NULL);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_res_info(cmd%d, CS_NUMORDERCOLS, &value, CS_UNUSED,"
		      " NULL) -> %s, %d\n",
		      self->serial,
		      value_str(VAL_STATUS, status), (int)int_val);
	if (PyErr_Occurred())
	    return NULL;

	if (status != CS_SUCCEED)
	    return Py_BuildValue("iO", status, Py_None);

	if (int_val <= 0)
	    return Py_BuildValue("i[]", status);

	col_nums = malloc(sizeof(*col_nums) * int_val);
	if (col_nums == NULL)
	    return PyErr_NoMemory();

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_res_info(self->cmd, CS_ORDERBY_COLS,
			     col_nums, sizeof(*col_nums) * int_val, NULL);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug) {
	    int i;

	    debug_msg("ct_res_info(cmd%d, CS_ORDERBY_COLS, &col_nums, %d,"
		      " NULL) -> %s, [",
		      self->serial, (int)(sizeof(*col_nums) * int_val),
		      value_str(VAL_STATUS, status));
	    for (i = 0; i < int_val; i++) {
		if (i > 0)
		    debug_msg(",");
		debug_msg("%d", (int)col_nums[i]);
	    }
	    debug_msg("]\n");
	}
	if (PyErr_Occurred()) {
	    free(col_nums);
	    return NULL;
	}

	list = build_int_list(col_nums, int_val);
	free(col_nums);
	if (list == NULL)
	    return NULL;
	return Py_BuildValue("iN", status, list);
    }
#endif

    default:
	PyErr_SetString(PyExc_TypeError, "unknown command");
	return NULL;
    }
}
示例#19
0
文件: js.c 项目: shen390s/elvm
static void js_emit_inst(Inst* inst) {
  switch (inst->op) {
  case MOV:
    emit_line("%s = %s;", reg_names[inst->dst.reg], src_str(inst));
    break;

  case ADD:
    emit_line("%s = (%s + %s) & " UINT_MAX_STR ";",
              reg_names[inst->dst.reg],
              reg_names[inst->dst.reg], src_str(inst));
    break;

  case SUB:
    emit_line("%s = (%s - %s) & " UINT_MAX_STR ";",
              reg_names[inst->dst.reg],
              reg_names[inst->dst.reg], src_str(inst));
    break;

  case LOAD:
    emit_line("%s = mem[%s];", reg_names[inst->dst.reg], src_str(inst));
    break;

  case STORE:
    emit_line("mem[%s] = %s;", src_str(inst), reg_names[inst->dst.reg]);
    break;

  case PUTC:
    emit_line("putchar(%s);", src_str(inst));
    break;

  case GETC:
    emit_line("%s = getchar();",
              reg_names[inst->dst.reg]);
    break;

  case EXIT:
    emit_line("running = false; break;");
    break;

  case DUMP:
    break;

  case EQ:
  case NE:
  case LT:
  case GT:
  case LE:
  case GE:
    emit_line("%s = (%s) | 0;",
              reg_names[inst->dst.reg], cmp_str(inst, "true"));
    break;

  case JEQ:
  case JNE:
  case JLT:
  case JGT:
  case JLE:
  case JGE:
  case JMP:
    emit_line("if (%s) pc = %s - 1;",
              cmp_str(inst, "true"), value_str(&inst->jmp));
    break;

  default:
    error("oops");
  }
}
示例#20
0
static PyObject *CS_COMMAND_ct_param(CS_COMMANDObj *self, PyObject *args)
{
    PyObject *obj;
    CS_RETCODE status;

    if (!PyArg_ParseTuple(args, "O", &obj))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    /* FIXME: Need to handle CS_UPDATECOL variant */
    if (DataBuf_Check(obj)) {
	DataBufObj *databuf = (DataBufObj *)obj;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_param(self->cmd, &databuf->fmt,
			  databuf->buff, databuf->copied[0],
			  databuf->indicator[0]);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug) {
	    debug_msg("ct_param(cmd%d, &databuf%d->fmt=",
		      self->serial, databuf->serial);
	    datafmt_debug(&databuf->fmt);
	    debug_msg(", databuf%d->buff, %d, %d) -> %s\n",
		      databuf->serial,
		      (int)databuf->copied[0], databuf->indicator[0],
		      value_str(VAL_STATUS, status));
	}
	if (PyErr_Occurred())
	    return NULL;
    } else if (CS_DATAFMT_Check(obj)) {
	CS_DATAFMTObj *datafmt = (CS_DATAFMTObj *)obj;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_param(self->cmd, &datafmt->fmt,
			  NULL, CS_UNUSED, (CS_SMALLINT)CS_UNUSED);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug) {
	    debug_msg("ct_param(cmd%d, &fmt=", self->serial);
	    datafmt_debug(&datafmt->fmt);
	    debug_msg(", NULL, CS_UNUSED, CS_UNUSED) -> %s\n",
		      value_str(VAL_STATUS, status));
	}
	if (PyErr_Occurred())
	    return NULL;
    } else {
	PyErr_SetString(PyExc_TypeError, "expect CS_DATAFMT or DataBuf");
	return NULL;
	
    }
    return PyInt_FromLong(status);
}
      void test_write_one_file()
      {
        ObSSTableSchemaColumnDef column_def;
        ObSSTableSchema schema;
        ObSSTableRow row;
        char *compressor_name = (char*)COMPRESSOR_NAME;
        ObSSTableWriter writer;
        ObString file_name(static_cast<int32_t>(strlen(sstable_path) + 1),
                      static_cast<int32_t>(strlen(sstable_path) + 1), sstable_path);
        ObString compressor(static_cast<int32_t>(strlen(compressor_name) + 1),
                            static_cast<int32_t>(strlen(compressor_name) + 1), compressor_name);
        int64_t disk_usage = 0;
        int64_t trailer_offset = 0;
        ObObj obj;
        ObObj key_obj;
        uint64_t table_id = 0;
        uint64_t column_group_id = 0;
        char value_data[1024 + 1];
        char rowkey_str[32];
        ObString row_key;
        ObRowkey key;
        char *ptr;
        int ret;
      
        // init schema
        for (int64_t i = 0; i < 5; ++i)
        {
          column_def.table_id_ = static_cast<uint32_t>(1025 + i);

          // add rowkey column
          column_def.column_group_id_ = 0;
          column_def.column_name_id_ = 1;
          column_def.column_value_type_ = ObVarcharType;
          column_def.rowkey_seq_ = 1;
          schema.add_column_def(column_def);

          for ( int j = 0; j < 10 ; ++j)
          {
            column_def.column_group_id_ = static_cast<uint16_t>(j);
            column_def.column_name_id_ = 2;
            column_def.column_value_type_ = ObDoubleType;
            column_def.rowkey_seq_ = 0;
            schema.add_column_def(column_def);
      
            column_def.column_name_id_ = 3;
            column_def.column_value_type_ = ObIntType;
            column_def.rowkey_seq_ = 0;
            schema.add_column_def(column_def);
      
            column_def.column_name_id_ = 4;
            column_def.column_value_type_ = ObVarcharType;
            column_def.rowkey_seq_ = 0;
            schema.add_column_def(column_def);
          }
        }
      
        //build data
        ptr = value_data;
        for (int64_t i = 0; i < 128; ++i) {
          memcpy(ptr, "testing ", 8);
          ptr += 8;
        }
        ObString value_str(1025, 1025, value_data);
        writer.set_dio(true);
      
        int64_t start_time = tbsys::CTimeUtil::getTime();
        // create sstable file
        if (OB_ERROR == (ret = writer.create_sstable(schema, file_name,
                                  compressor, 2)))
        {
          TBSYS_LOG(ERROR, "Failed to create sstable file: %s", sstable_path);
        }
      
        for (int64_t i = 0; i < 5000000; ++i) 
        {
          row.clear();
          table_id = i / 1000000 + 1025;
          column_group_id = i % 1000000 / 100000;
          row.set_table_id(table_id);
          row.set_column_group_id(column_group_id);
          sprintf(rowkey_str, "row_key_%08ld", i);
          row_key.assign(rowkey_str, 16);
          key_obj.set_varchar(row_key);
          key.assign(&key_obj, 1);
          row.set_rowkey(key);
      
          obj.set_double((double)i);
          row.add_obj(obj);
          obj.set_int(i);
          row.add_obj(obj);
          obj.set_varchar(value_str);
          row.add_obj(obj);
      
          if (OB_ERROR == (ret = writer.append_row(row, disk_usage)))
          {
            TBSYS_LOG(ERROR, "add row failed, i=%ld", i);
            return;
          }
        }
      
        if (OB_ERROR == (ret = writer.close_sstable(trailer_offset)))
        {
          TBSYS_LOG(ERROR, "close sstable failed ------------------");
        }
      
        printf("test_write_one_file, run_time=%ld\n", 
          tbsys::CTimeUtil::getTime() - start_time);
        //remove(sstable_path);
      }
/*!

*/
bool
RCSSParamParser::init( const char * msg )
{
    char buf[32];
    int n_read = 0;
    if ( std::sscanf( msg, " ( %31s %n", buf, &n_read ) != 1 )
    {
        std::cerr << "***ERROR*** RCSSParamParser. "
                  << "Failed to parse parameter type name. "
                  << msg
                  << std::endl;
        return false;
    }

    M_param_name = buf;

    const std::string msg_str( msg );

    for ( std::string::size_type pos = msg_str.find_first_of( '(', n_read );
          pos != std::string::npos;
          pos = msg_str.find_first_of( '(', pos ) )
    {
        std::string::size_type end_pos = msg_str.find_first_of( ' ', pos );
        if ( end_pos == std::string::npos )
        {
            std::cerr << "***ERROR*** RCSSParamParser. "
                      << "Failed to parse parameter name. "
                      << msg
                      << std::endl;
            return false;
        }

        pos += 1;
        const std::string name_str( msg_str, pos, end_pos - pos );

        pos = end_pos;
        // search end paren or double quatation
        end_pos = msg_str.find_first_of( ")\"", end_pos ); //"
        if ( end_pos == std::string::npos )
        {
            std::cerr << "***ERROR*** RCSSParamParser. "
                      << "Failed to parse parameter value for ["
                      << name_str << "] in "
                      << msg
                      << std::endl;
            return false;
        }

        // found string type value
        if ( msg_str[end_pos] == '\"' ) // "
        {
            pos = end_pos;
            end_pos = msg_str.find_first_of( '\"', end_pos + 1 ); //"
            if ( end_pos == std::string::npos )
            {
                std::cerr << "***ERROR*** RCSSParamParser. "
                          << "Failed to parse string parameter value for ["
                          << name_str << "] in "
                          << msg
                          << std::endl;
                return false;
            }
            end_pos += 1; // skip double quatation
        }
        else
        {
            pos += 1; // skip white space
        }

        std::string value_str( msg_str, pos, end_pos - pos );
        value_str = cleanString( value_str );

        M_str_pairs.push_back( std::make_pair( name_str, value_str ) );

        pos = end_pos;
    }

    return true;
}
示例#23
0
static PyObject *CS_COMMAND_ct_data_info(CS_COMMANDObj *self, PyObject *args)
{
    int action;
    CS_INT num;
    CS_IODESC iodesc;
    CS_IODESCObj *desc;
    CS_RETCODE status;

    if (!first_tuple_int(args, &action))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    switch (action) {
    case CS_SET:
	/* ct_data_info(CS_SET, int, iodesc) -> status */
	if (!PyArg_ParseTuple(args, "iO!",
			      &action, &CS_IODESCType, &desc))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_data_info(self->cmd, CS_SET, CS_UNUSED, &desc->iodesc);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_data_info(cmd%d, CS_SET, CS_UNUSED, iodesc%d)"
		      " -> %s\n",
		      self->serial, desc->serial,
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_GET:
	/* ct_data_info(CS_GET, int) -> status, iodesc */
	if (!PyArg_ParseTuple(args, "ii", &action, &num))
	    return NULL;
	memset(&iodesc, 0, sizeof(iodesc));

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_data_info(self->cmd, CS_GET, num, &iodesc);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_data_info(cmd%d, CS_GET, %d, &iodesc) -> %s",
		      self->serial, (int)num, value_str(VAL_STATUS, status));
	if (PyErr_Occurred()) {
	    if (self->debug)
		debug_msg("\n");
	    return NULL;
	}

	if (status != CS_SUCCEED) {
	    if (self->debug)
		debug_msg(", None\n");
	    return Py_BuildValue("iO", status, Py_None);
	}
	desc = (CS_IODESCObj*)iodesc_alloc(&iodesc);
	if (desc == NULL) {
	    if (self->debug)
		debug_msg("\n");
	    return NULL;
	}

	if (self->debug)
	    debug_msg(", iodesc%d\n", desc->serial);
	return Py_BuildValue("iN", status, desc);

    default:
	PyErr_SetString(PyExc_TypeError, "unknown action");
	return NULL;
    }
}
示例#24
0
static PyObject *CS_COMMAND_ct_cursor(CS_COMMANDObj *self, PyObject *args)
{
    int type;
    char *name, *text;
    CS_INT option = CS_UNUSED;
    CS_RETCODE status;
    char *type_str = NULL;

    if (!first_tuple_int(args, &type))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    switch (type) {
    case CS_CURSOR_DECLARE:
	/* ct_cursor(CS_CURSOR_DECLARE, cursor_id, sql [,options]) -> status */
	type_str = "CS_CURSOR_DECLARE";
    case CS_CURSOR_UPDATE:
	/* ct_cursor(CS_CURSOR_UPDATE, table, sql [,options]) -> status */
	if (type_str == NULL)
	    type_str = "CS_CURSOR_UPDATE";
	if (!PyArg_ParseTuple(args, "iss|i", &type, &name, &text, &option))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_cursor(self->cmd, type,
			   name, CS_NULLTERM, text, CS_NULLTERM, option);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_cursor(cmd%d, %s, \"%s\", CS_NULLTERM, \"%s\","
		      " CS_NULLTERM, %s) -> %s\n",
		      self->serial, type_str, name, text,
		      value_str(VAL_CURSOROPT, option),
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_CURSOR_OPTION:
	/* ct_cursor(CS_CURSOR_OPTION [,options]) -> status */
	type_str = "CS_CURSOR_OPTION";
    case CS_CURSOR_OPEN:
	/* ct_cursor(CS_CURSOR_OPEN [,options]) -> status */
	if (type_str == NULL)
	    type_str = "CS_CURSOR_OPEN";
    case CS_CURSOR_CLOSE:
	/* ct_cursor(CS_CURSOR_CLOSE [,options]) -> status */
	if (type_str == NULL)
	    type_str = "CS_CURSOR_CLOSE";
	if (!PyArg_ParseTuple(args, "i|i", &type, &option))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_cursor(self->cmd, type,
			   NULL, CS_UNUSED, NULL, CS_UNUSED, option);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_cursor(cmd%d, %s, NULL, CS_UNUSED, NULL, CS_UNUSED,"
		      " %s) -> %s\n",
		      self->serial, type_str,
		      value_str(VAL_CURSOROPT, option),
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_CURSOR_ROWS:
	/* ct_cursor(CS_CURSOR_ROWS, int) -> status */
	if (!PyArg_ParseTuple(args, "ii", &type, &option))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_cursor(self->cmd, type,
			   NULL, CS_UNUSED, NULL, CS_UNUSED, option);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_cursor(cmd%d, CS_CURSOR_ROWS, NULL, CS_UNUSED,"
		      " NULL, CS_UNUSED, %s) -> %s\n",
		      self->serial,
		      value_str(VAL_CURSOROPT, option),
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_CURSOR_DELETE:
	/* ct_cursor(CS_CURSOR_DELETE, table) -> status */
	if (!PyArg_ParseTuple(args, "is", &type, &name))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_cursor(self->cmd, type,
			   name, CS_NULLTERM, NULL, CS_UNUSED, CS_UNUSED);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_cursor(cmd%d, CS_CURSOR_DELETE, \"%s\", CS_NULLTERM,"
		      " NULL, CS_UNUSED, CS_UNUSED) -> %s\n",
		      self->serial, name, value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_CURSOR_DEALLOC:
	/* ct_cursor(CS_CURSOR_DEALLOC) -> status */
	if (!PyArg_ParseTuple(args, "i", &type))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_cursor(self->cmd, type,
			   NULL, CS_UNUSED, NULL, CS_UNUSED, CS_UNUSED);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_cursor(cmd%d, CS_CURSOR_DEALLOC, NULL, CS_UNUSED,"
		      " NULL, CS_UNUSED, CS_UNUSED) -> %s\n",
		      self->serial, value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    default:
	PyErr_SetString(PyExc_TypeError, "unknown type");
	return NULL;
    }
}
示例#25
0
static PyObject *CS_COMMAND_ct_command(CS_COMMANDObj *self, PyObject *args)
{
    int type;
    char *databuf;
    CS_INT option = CS_UNUSED;
    CS_RETCODE status;
    char *type_str = NULL;

    if (!first_tuple_int(args, &type))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    switch (type) {
    case CS_LANG_CMD:
	/* ct_command(CS_LANG_CMD, sql [,option]) -> status */
	type_str = "CS_LANG_CMD";
    case CS_RPC_CMD:
	/* ct_command(CS_RPC_CMD, name [,option]) -> status */
	if (type_str == NULL)
	    type_str = "CS_RPC_CMD";
	if (!PyArg_ParseTuple(args, "is|i", &type, &databuf, &option))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_command(self->cmd, type, databuf, CS_NULLTERM, option);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_command(cmd%d, %s, \"%s\", CS_NULLTERM, %s) -> %s\n",
		      self->serial, type_str, databuf,
		      value_str(VAL_OPTION, option),
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

#ifdef CS_MSG_CMD
    case CS_MSG_CMD:
	/* ct_command(CS_MSG_CMD, int) -> status */
    {
	CS_INT num;

	if (!PyArg_ParseTuple(args, "ii", &type, &num))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_command(self->cmd, type, (CS_VOID*)&num, CS_UNUSED, CS_UNUSED);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_command(cmd%d, CS_MSG_CMD, %d, CS_UNUSED, CS_UNUSED)"
		      " -> %s\n",
		      self->serial, (int)num, value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);
    }
#endif

#ifdef CS_PACKAGE_CMD
    case CS_PACKAGE_CMD:
	/* ct_command(CS_PACKAGE_CMD, name) -> status */
	if (!PyArg_ParseTuple(args, "is", &type, &databuf))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_command(self->cmd, type, databuf, CS_NULLTERM, CS_UNUSED);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_command(cmd%d, CS_PACKAGE_CMD, \"%s\", CS_NULLTERM,"
		      " CS_UNUSED) -> %s\n",
		      self->serial,
		      databuf, value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);
#endif

    case CS_SEND_DATA_CMD:
	/* ct_command(CS_SEND_DATA_CMD) -> status */
	if (!PyArg_ParseTuple(args, "i", &type))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_command(self->cmd, type, NULL, CS_UNUSED, CS_COLUMN_DATA);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_command(cmd%d, CS_SEND_DATA_CMD, NULL, CS_UNUSED,"
		      " CS_COLUMN_DATA) -> %s\n",
		      self->serial,
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    default:
	PyErr_SetString(PyExc_TypeError, "unknown type");
	return NULL;
    }
}
示例#26
0
文件: scala.c 项目: shen390s/elvm
static void scala_emit_inst(Inst* inst) {
  switch (inst->op) {
  case MOV:
    emit_line("%s = %s;", reg_names[inst->dst.reg], src_str(inst));
    break;

  case ADD:
    emit_line("%s = (%s + %s) & " UINT_MAX_STR,
              reg_names[inst->dst.reg],
              reg_names[inst->dst.reg], src_str(inst));
    break;

  case SUB:
    emit_line("%s = (%s - %s) & " UINT_MAX_STR,
              reg_names[inst->dst.reg],
              reg_names[inst->dst.reg], src_str(inst));
    break;

  case LOAD:
    emit_line("%s = mem(%s)", reg_names[inst->dst.reg], src_str(inst));
    break;

  case STORE:
    emit_line("mem(%s) = %s", src_str(inst), reg_names[inst->dst.reg]);
    break;

  case PUTC:
    emit_line("print(%s.toChar)", src_str(inst));
    break;

  case GETC:
    emit_line("try { val __ = System.in.read(); "
              "  %s = if (__ == -1)  0 else __; }"
              "catch {case _: Exception => ()}",
              reg_names[inst->dst.reg]);
    break;

  case EXIT:
    emit_line("sys.exit(0)");
    break;

  case DUMP:
    break;

  case EQ:
  case NE:
  case LT:
  case GT:
  case LE:
  case GE:
    emit_line("%s = if (%s) 1 else 0;",
              reg_names[inst->dst.reg], cmp_str(inst, "true"));
    break;

  case JEQ:
  case JNE:
  case JLT:
  case JGT:
  case JLE:
  case JGE:
  case JMP:
    emit_line("if (%s) pc = %s - 1;",
              cmp_str(inst, "true"), value_str(&inst->jmp));
    break;

  default:
    error("oops");
  }
}
示例#27
0
static store::Item_t j2x_array( store::Item_t const &array_item,
                                store::Item *parent_xml_item ) {
  zstring base_uri;
  store::NsBindings ns_bindings;
  store::Item_t array_elt_item, element_name, junk_item, type_name, xml_item;

  store::Iterator_t i( array_item->getArrayValues() );
  i->open();

  if ( !i->next( array_elt_item ) )
    throw XQUERY_EXCEPTION(
      zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
      ERROR_PARAMS( ZED( ZJ2X0001_EmptyArray ) )
    );
  if ( !array_elt_item->isAtomic() ||
       !TypeOps::is_subtype( array_elt_item->getTypeCode(), store::XS_STRING ) )
    throw XQUERY_EXCEPTION(
      zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
      ERROR_PARAMS( ZED( ZJ2X0001_Bad1stElement ) )
    );

  GENV_ITEMFACTORY->createQName(
    element_name, "", "", array_elt_item->getStringValue()
  );
  type_name = GENV_TYPESYSTEM.XS_UNTYPED_QNAME;
  GENV_ITEMFACTORY->createElementNode(
    xml_item, parent_xml_item,
    element_name, type_name, false, false, ns_bindings, base_uri
  );

  bool did_attributes = false;
  while ( i->next( array_elt_item ) ) {
    switch ( array_elt_item->getKind() ) {
      case store::Item::ARRAY:
        j2x_array( array_elt_item, xml_item.getp() );
        break;
      case store::Item::ATOMIC: {
        zstring value_str( array_elt_item->getStringValue() );
        GENV_ITEMFACTORY->createTextNode( junk_item, xml_item, value_str );
        break;
      }
      case store::Item::OBJECT:
        if ( did_attributes )
          throw XQUERY_EXCEPTION(
            zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
            ERROR_PARAMS( ZED( ZJ2X0001_UnexpectedObject ) )
          );
        j2x_object( array_elt_item, &xml_item );
        did_attributes = true;
        break;
      default:
        throw XQUERY_EXCEPTION(
          zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
          ERROR_PARAMS( ZED( ZJ2X0001_BadElement ), array_elt_item->getKind() )
        );
    } // switch
  } // while

  i->close();
  return xml_item;
}
示例#28
0
static PyObject *CS_COMMAND_ct_dynamic(CS_COMMANDObj *self, PyObject *args)
{
    int type;
    char *id, *buff;
    char *cmd_str = NULL;
    CS_RETCODE status;

    if (!first_tuple_int(args, &type))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    switch (type) {
    case CS_CURSOR_DECLARE:
	/* ct_dynamic(CS_CURSOR_DECLARE, dyn_id, cursor_id) -> status */
	cmd_str = "CS_CURSOR_DECLARE";
    case CS_PREPARE:
	/* ct_dynamic(CS_PREPARE, dyn_id, sql) -> status */
	if (cmd_str == NULL)
	    cmd_str = "CS_PREPARE";
	if (!PyArg_ParseTuple(args, "iss", &type, &id, &buff))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_dynamic(self->cmd, type,
			    id, CS_NULLTERM, buff, CS_NULLTERM);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_dynamic(cmd%d, %s, \"%s\", CS_NULLTERM, \"%s\","
		      " CS_NULLTERM) -> %s\n",
		      self->serial, cmd_str, id, buff,
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_DEALLOC:
	/* ct_dynamic(CS_DEALLOC, dyn_id) -> status */
	cmd_str = "CS_DEALLOC";
    case CS_DESCRIBE_INPUT:
	/* ct_dynamic(CS_DESCRIBE_INPUT, dyn_id) -> status */
	if (cmd_str == NULL)
	    cmd_str = "CS_DESCRIBE_INPUT";
    case CS_DESCRIBE_OUTPUT:
	/* ct_dynamic(CS_DESCRIBE_OUTPUT, dyn_id) -> status */
	if (cmd_str == NULL)
	    cmd_str = "CS_DESCRIBE_OUTPUT";
    case CS_EXECUTE:
	/* ct_dynamic(CS_EXECUTE, dyn_id) -> status */
	if (cmd_str == NULL)
	    cmd_str = "CS_EXECUTE";
	if (!PyArg_ParseTuple(args, "is", &type, &id))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_dynamic(self->cmd, type,
			    id, CS_NULLTERM, NULL, CS_UNUSED);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_dynamic(cmd%d, %s, \"%s\", CS_NULLTERM, NULL,"
		      " CS_UNUSED) -> %s\n",
		      self->serial, cmd_str, id,
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    case CS_EXEC_IMMEDIATE:
	/* ct_dynamic(CS_EXEC_IMMEDIATE, sql) -> status */
	if (!PyArg_ParseTuple(args, "is", &type, &buff))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_dynamic(self->cmd, type,
			    NULL, CS_UNUSED, buff, CS_NULLTERM);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_dynamic(cmd%d, CS_EXEC_IMMEDIATE, NULL, CS_UNUSED,"
		      " \"%s\", CS_NULLTERM) -> %s\n",
		      self->serial, buff, value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);

    default:
	PyErr_SetString(PyExc_TypeError, "unknown dynamic command");
	return NULL;
    }
}
示例#29
0
static PyObject *CS_COMMAND_ct_cmd_props(CS_COMMANDObj *self, PyObject *args)
{
    int action, property;
    PyObject *obj = NULL;
    CS_RETCODE status;
    CS_BOOL bool_value;

    if (!first_tuple_int(args, &action))
	return NULL;

    if (self->cmd == NULL) {
	PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped");
	return NULL;
    }

    switch (action) {
    case CS_SET:
	/* ct_cmd_props(CS_SET, property, value) -> status */
	if (!PyArg_ParseTuple(args, "iiO", &action, &property, &obj))
	    return NULL;

	switch (property_type(property)) {
	case OPTION_BOOL:
	    bool_value = PyInt_AsLong(obj);
	    if (PyErr_Occurred())
		return NULL;

	    /* PyErr_Clear(); */

	    SY_CONN_BEGIN_THREADS(self->conn);
	    status = ct_cmd_props(self->cmd, CS_SET, property,
				  &bool_value, CS_UNUSED, NULL);
	    SY_CONN_END_THREADS(self->conn);

	    if (self->debug)
		debug_msg("ct_cmd_props(cmd%d, CS_SET, %s, %d, CS_UNUSED,"
			  " NULL) -> %s\n",
			  self->serial,
			  value_str(VAL_PROPS, property), (int)bool_value,
			  value_str(VAL_STATUS, status));
	    if (PyErr_Occurred())
		return NULL;

	    return PyInt_FromLong(status);


	default:
	    PyErr_SetString(PyExc_TypeError, "unhandled property value");
	    return NULL;
	}
	break;

    case CS_GET:
	/* ct_cmd_props(CS_GET, property) -> status, value */
	if (!PyArg_ParseTuple(args, "ii", &action, &property))
	    return NULL;

	switch (property_type(property)) {
	case OPTION_BOOL:
	    /* PyErr_Clear(); */

	    SY_CONN_BEGIN_THREADS(self->conn);
	    status = ct_cmd_props(self->cmd, CS_GET, property,
				  &bool_value, CS_UNUSED, NULL);
	    SY_CONN_END_THREADS(self->conn);

	    if (self->debug)
		debug_msg("ct_cmd_props(cmd%d, CS_GET, %s, &value, CS_UNUSED,"
			  " NULL) -> %s, %d\n",
			  self->serial,
			  value_str(VAL_PROPS, property),
			  value_str(VAL_STATUS, status), (int)bool_value);
	    if (PyErr_Occurred())
		return NULL;

	    return Py_BuildValue("ii", status, bool_value);


	default:
	    PyErr_SetString(PyExc_TypeError, "unhandled property value");
	    return NULL;
	}
	break;

#ifdef CS_CLEAR
    case CS_CLEAR:
	/* ct_cmd_props(CS_CLEAR, property) -> status */
	if (!PyArg_ParseTuple(args, "ii", &action, &property))
	    return NULL;

	/* PyErr_Clear(); */

	SY_CONN_BEGIN_THREADS(self->conn);
	status = ct_cmd_props(self->cmd, CS_CLEAR, property,
			      NULL, CS_UNUSED, NULL);
	SY_CONN_END_THREADS(self->conn);

	if (self->debug)
	    debug_msg("ct_cmd_props(cmd%d, CS_CLEAR, %s, NULL, CS_UNUSED,"
		      " NULL) -> %s\n",
		      self->serial,
		      value_str(VAL_PROPS, property),
		      value_str(VAL_STATUS, status));
	if (PyErr_Occurred())
	    return NULL;

	return PyInt_FromLong(status);
#endif

    default:
	PyErr_SetString(PyExc_TypeError, "unknown action");
	return NULL;
    }
}
示例#30
0
文件: context.c 项目: yaraki/forsh
static void print_value(Value *value)
{
	char buf[1024];
	value_str(value, buf, sizeof(buf));
	printf(" %s", buf);
}