void
SaveTab(struct MyGadget *gd)
{
	write_integer(gd->data.tab.sel);
	write_integer(gd->data.tab.tabwidth);
	write_integer(gd->data.tab.tabheight);
}
void
SaveMx(struct MyGadget *gd)
{
	write_integer(gd->data.mx.pixdiv);
	write_integer(gd->data.mx.sel);
	write_integer(gd->data.mx.align);

	write_string(&gd->data.mx.Label[0]);
}
void
SaveColor(struct MyGadget *gd)
{
	write_integer(gd->data.col.cellsize);
	write_integer(gd->data.col.layout);
	write_integer(gd->data.col.redrawbuffer);

	write_color(&gd->data.col.value);
}
Beispiel #4
0
		int bencode_recursive(OutIt& out, const entry& e)
		{
			int ret = 0;
			switch(e.type())
			{
			case entry::int_t:
				write_char(out, 'i');
				ret += write_integer(out, e.integer());
				write_char(out, 'e');
				ret += 2;
				break;
			case entry::string_t:
				ret += write_integer(out, e.string().length());
				write_char(out, ':');
				ret += write_string(e.string(), out);
				ret += 1;
				break;
			case entry::list_t:
				write_char(out, 'l');
				for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i)
					ret += bencode_recursive(out, *i);
				write_char(out, 'e');
				ret += 2;
				break;
			case entry::dictionary_t:
				write_char(out, 'd');
				for (entry::dictionary_type::const_iterator i = e.dict().begin();
					i != e.dict().end(); ++i)
				{
					// write key
					ret += write_integer(out, i->first.length());
					write_char(out, ':');
					ret += write_string(i->first, out);
					// write value
					ret += bencode_recursive(out, i->second);
					ret += 1;
				}
				write_char(out, 'e');
				ret += 2;
				break;
			case entry::preformatted_t:
				std::copy(e.preformatted().begin(), e.preformatted().end(), out);
				ret += int(e.preformatted().size());
				break;
			case entry::undefined_t:

				// empty string
				write_char(out, '0');
				write_char(out, ':');

				ret += 2;
				break;
			}
			return ret;
		}
void
SaveStatus(struct MyGadget *gd)
{
	write_integer(gd->data.sta.barheight);
	write_integer(gd->data.sta.maxvalue);
	write_integer(gd->data.sta.value);

	write_color(&gd->data.sta.barcolor);

	write_string(&gd->data.sta.Label[0]);
	write_string(&gd->data.sta.Trail[0]);
}
Beispiel #6
0
		int bencode_recursive(OutIt& out, const entry& e)
		{
			int ret = 0;
			switch(e.type())
			{
			case entry::int_t:
				write_char(out, 'i');
				ret += write_integer(out, e.integer());
				write_char(out, 'e');
				ret += 2;
				break;
			case entry::string_t:
				ret += write_integer(out, e.string().length());
				write_char(out, ':');
				ret += write_string(e.string(), out);
				ret += 1;
				break;
			case entry::list_t:
				write_char(out, 'l');
				for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i)
					ret += bencode_recursive(out, *i);
				write_char(out, 'e');
				ret += 2;
				break;
			case entry::dictionary_t:
				write_char(out, 'd');
				for (entry::dictionary_type::const_iterator i = e.dict().begin();
					i != e.dict().end(); ++i)
				{
					// write key
					ret += write_integer(out, i->first.length());
					write_char(out, ':');
					ret += write_string(i->first, out);
					// write value
					ret += bencode_recursive(out, i->second);
					ret += 1;
				}
				write_char(out, 'e');
				ret += 2;
				break;
			case entry::undefined_t:
				// trying to encode a structure with uninitialized values!
//				TORRENT_ASSERT_VAL(false, e.type());
				// do nothing
				break;
			}
			return ret;
		}
Beispiel #7
0
static void write_blob(ID3DBlob *blob)
{
    int size = blob ? (int)blob->GetBufferSize() : -1;
    write_integer(size);
    if (size > 0)
        fwrite(blob->GetBufferPointer(), size, 1, stdout);
}
Beispiel #8
0
pfs::error_code ubjson_ostream<OStreamType, JsonType>::write_json (json_type const & j, bool with_prefix)
{
    switch (j.type()) {
    case data_type::null:
        _os << UBJSON_CHAR_NULL;
        break;

    case data_type::boolean:
        _os << (j.boolean_data()
                ? UBJSON_CHAR_TRUE
                : UBJSON_CHAR_FALSE);
        break;

    case data_type::integer:
        return write_integer(j.integer_data(), with_prefix);

    case data_type::real:
        return write_real(j.real_data(), with_prefix);

    case data_type::string:
        return write_string(j.string_data(), with_prefix);

    case data_type::array:
        return write_array(j);

    case data_type::object:
        return write_object(j);
    }

    return pfs::error_code();
}
void
SaveText(struct MyGadget *gd)
{
	write_integer(gd->data.txt.align);
	
	write_string(&gd->data.txt.Label[0]);
}
void
SaveNumber(struct MyGadget *gd)
{
	write_integer(gd->data.num.align);
	
	write_string(&gd->data.num.Label[0]);
}
void
SaveBbox(struct MyGadget *gd)
{
	write_integer(gd->data.bbox.style);
	
	write_string(&gd->data.bbox.Label[0]);
}
Beispiel #12
0
static size_t
write_compact_array(json_t* array, stream_t* stream)
{
    size_t bytes = 0;

    assert(json_is_array(array));
    json_t* header = build_compact_array_header(array);

    uint8_t tag = BSER_TAG_COMPACT_ARRAY;
    if (stream->write(stream, &tag, SIZE_U8) == SIZE_U8) {
        size_t header_bytes = write_array(header, stream);
        if (header_bytes > 0) {
            size_t array_length = json_array_size(array);

            json_t* array_length_node = json_integer(array_length);
            size_t integer_size = write_integer(array_length_node, stream);
            if (integer_size > 0) {
                size_t written = write_compact_objects(array, header, stream);
                if (written > 0) {
                    bytes = SIZE_U8 + header_bytes + integer_size + written;
                }
            }
            json_decref(array_length_node);
        }
    }
    json_decref(header);
    return bytes;
}
Beispiel #13
0
static void write_expression(const expression_t *expression)
{
	/* TODO */
	switch(expression->kind) {
	case EXPR_LITERAL_INTEGER:
		write_integer(&expression->literal);
		break;

	case EXPR_ENUM_CONSTANT: {
		/* UHOH... hacking */
		entity_t *entity = expression->reference.entity;
		write_enum_name(entity->enum_value.enume);
		fprintf(out, ".%s.val", entity->base.symbol->string);
		break;
	}
	case EXPR_UNARY_CASES:
		write_unary_expression(&expression->unary);
		break;
	case EXPR_BINARY_CASES:
		write_binary_expression(&expression->binary);
		break;
	default:
		panic("not implemented expression");
	}
}
Beispiel #14
0
static int
unpack_field(int ctype, int ptype, char * buffer, struct atom * a, void *out) {
	if (ctype == CTYPE_ARRAY) {
		return unpack_array(ptype, buffer, a , out);
	}
	if (ctype == CTYPE_PACKED) {
		pbc_ctx packed;
		struct context * ctx = (struct context *)packed;

		int n = _pbcC_open_packed(packed , ptype, 
			(uint8_t *)buffer + a->v.s.start, a->v.s.end - a->v.s.start);
		if (n<=0)
			return -1;
		int i;
		int r =0;
		for (i=0;i<n;i++) {
			r |= unpack_array(ptype , buffer , &(ctx->a[i]) , out);
		}
		if (r)
			return -1;
		return 0;
	}
	switch(ptype) {
	case PTYPE_DOUBLE:
		return write_real(ctype, read_double(a), out);
	case PTYPE_FLOAT:
		return write_real(ctype, read_float(a), out);
	case PTYPE_INT64:
	case PTYPE_UINT64:
	case PTYPE_INT32:
	case PTYPE_UINT32:
	case PTYPE_FIXED32:
	case PTYPE_FIXED64:
	case PTYPE_SFIXED32:
	case PTYPE_SFIXED64:
	case PTYPE_ENUM:	// enum must be integer type in pattern mode
	case PTYPE_BOOL:
		return write_integer(ctype, a , out);
	case PTYPE_SINT32: {
		struct longlong temp = a->v.i;
		varint_dezigzag32(&temp);
		return write_longlong(ctype, &temp , out);
	}
	case PTYPE_SINT64: {
		struct longlong temp = a->v.i;
		varint_dezigzag64(&temp);
		return write_longlong(ctype, &temp , out);
	}
	case PTYPE_MESSAGE: 
		((union _pbc_var *)out)->m.buffer = buffer + a->v.s.start;
		((union _pbc_var *)out)->m.len = a->v.s.end - a->v.s.start;
		return 0;
	case PTYPE_STRING:
		((union _pbc_var *)out)->s.str = buffer + a->v.s.start;
		((union _pbc_var *)out)->s.len = a->v.s.end - a->v.s.start;
		return 0;
	}
	return -1;
}
Beispiel #15
0
	int bencode_recursive(OutIt& out, const entry& e)
	{
		int ret = 0;
		switch(e.type())
		{
		case entry::int_t:
			write_char(out, 'i');
			ret += write_integer(out, e.integer());
			write_char(out, 'e');
			ret += 2;
			break;
		case entry::string_t:
			ret += write_integer(out, e.string().length());
			write_char(out, ':');
			ret += write_string(out, e.string());
			ret += 1;
			break;
		case entry::list_t:
			write_char(out, 'l');
			for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i)
				ret += bencode_recursive(out, *i);
			write_char(out, 'e');
			ret += 2;
			break;
		case entry::dictionary_t:
			write_char(out, 'd');
			for (entry::dictionary_type::const_iterator i = e.dict().begin();
				i != e.dict().end(); ++i)
			{
				// write key
				ret += write_integer(out, i->first.length());
				write_char(out, ':');
				ret += write_string(out, i->first);
				// write value
				ret += bencode_recursive(out, i->second);
				ret += 1;
			}
			write_char(out, 'e');
			ret += 2;
			break;
		default:
			// do nothing
			break;
		}
		return ret;
	}
Beispiel #16
0
// write one stroke to file system
unsigned char write_stroke (FILE * file, PtrStroke stroke)
{
    if (file == NULL || stroke == NULL || stroke->nPoints == 0)
    {
        return 0;
    }
  //write pen size
    if ( !write_integer(stroke->iPenSize,file,WRITEINT_LINEEND) )
    {
        SB_INKERRPRINTF("write failed, iPenSize= %d \n",stroke->iPenSize);
        return 0;
    }
  //write rgb
    if ( !write_rgb(&stroke->gdkColor,file) )
    {
        SB_INKERRPRINTF("failed write rgb\n");
        return 0;
    }

    if ( !write_integer(stroke->nPoints,file,WRITEINT_LINEEND) )
    {
        SB_INKERRPRINTF("write failed, nPoints= %d \n",stroke->nPoints);
        return 0;
    }

    SB_INKPRINTF("stroke->nPoints=%d \n", stroke->nPoints);
    PtrInkPoint point = stroke->firstPoint;
    while (point)
    {
        if ( !write_integer(point->x, file, WRITEINT_2SPACES) )
        {
            SB_INKERRPRINTF("fwrite failed, point->x= %d \n", point->x);
            return 0;
        }
        if ( !write_integer(point->y, file, WRITEINT_LINEEND) )
        {
            SB_INKERRPRINTF("fwrite failed, point->y= %d \n", point->y);
            return 0;
        }
        SB_INKPRINTF("point(%d,%d) \n", point->x, point->y);
        point = point->nextPoint;
    }
    return 1;
}
void
SaveEdit(struct MyGadget *gd)
{
	write_integer(gd->data.edi.tabwidth);
	write_integer(gd->data.edi.align);
	write_integer(gd->data.edi.maxchars);
	write_integer(gd->data.edi.editable);
	write_integer(gd->data.edi.stylable);
	write_integer(gd->data.edi.selectable);
	write_integer(gd->data.edi.autoident);
	write_integer(gd->data.edi.wordwrap);
}
void
SaveScroller(struct MyGadget *gd)
{
	write_integer(gd->data.bscroller.min);
	write_integer(gd->data.bscroller.max);
	write_integer(gd->data.bscroller.minrange);
	write_integer(gd->data.bscroller.maxrange);
	write_integer(gd->data.bscroller.setprop);
	write_integer(gd->data.bscroller.pos);
	write_integer(gd->data.bscroller.minstep);
	write_integer(gd->data.bscroller.maxstep);
}
Beispiel #19
0
pfs::error_code ubjson_ostream<OStreamType, JsonType>::write_string (string_type const & s, bool with_prefix)
{
    if (with_prefix) {
        // Using size is safe here (no matter the string encoding)
        if (s.size() == 1 && *s.cbegin() <= numeric_limits<int8_t>::max()) {
            _os << static_cast<int8_t>('C');
            _os << static_cast<int8_t>(*s.cbegin());
        } else {
            _os << static_cast<int8_t>('S');
            write_integer(static_cast<typename json_type::integer_type>(s.size()), true);
            _os << s.utf8();
        }
    } else {
        write_integer(static_cast<typename json_type::integer_type>(s.size()), true);
        _os << s;
    }

    return pfs::error_code();
}
Beispiel #20
0
pfs::error_code ubjson_ostream<OStreamType, JsonType>::write_array (json_type const & j)
{
    _os << UBJSON_CHAR_ARRAY_BEGIN;

    bool use_count_optimization = ((_flags & count_optimized) && !j.empty());
    bool is_special_case = false;

    // If a type is specified, a count must also be specified.
    // A type cannot be specified by itself.
    bool use_type_optimization  = ((_flags & type_optimized) && use_count_optimization);

    // Additional checks for type optimization
    if (use_type_optimization) {

        // This call is safe. Array is not empty as checked before
        int8_t first_prefix = prefix(*j.cbegin());
        use_type_optimization = pfs::all_of(j.cbegin()
                , j.cend()
                , compare_prefix(first_prefix));

        if (use_type_optimization) {
            _os << UBJSON_CHAR_TYPE;
            _os << first_prefix;

            // Check special cases
            if (first_prefix == UBJSON_CHAR_NOOP
                    || first_prefix == UBJSON_CHAR_NULL
                    || first_prefix == UBJSON_CHAR_TRUE
                    || first_prefix == UBJSON_CHAR_FALSE) {
                is_special_case = true;
            }
        }
    }

    if (use_count_optimization) {
        _os << UBJSON_CHAR_SIZE;
        write_integer(static_cast<typename json_type::integer_type>(j.size()), true);
    }

    // Ignore special cases: strongly-typed arrays of null, no-op and boolean values
    if (! is_special_case) {
        typename json_type::const_iterator first = j.cbegin();
        typename json_type::const_iterator last  = j.cend();

        for (; first != last; ++first)
            write_json(*first, !use_type_optimization);
    }

    // If a count is specified the container must not specify an end-marker.
    if (!use_count_optimization)
        _os << UBJSON_CHAR_ARRAY_END;

    return pfs::error_code();
}
Beispiel #21
0
//write the rgb value in gdkcolor
unsigned char write_rgb(GdkColor *pGdkColor, FILE * file)
{
    if ( !write_integer(pGdkColor->red, file, WRITEINT_2SPACES) )
    {
        SB_INKERRPRINTF("failed, pGdkColor->red= %d \n", pGdkColor->red);
        return 0;
    }
    if ( !write_integer(pGdkColor->green, file, WRITEINT_2SPACES) )
    {
        SB_INKERRPRINTF("failed, pGdkColor->green= %d \n", 
                        pGdkColor->green);
        return 0;
    }
    if ( !write_integer(pGdkColor->blue, file, WRITEINT_LINEEND) )
    {
        SB_INKERRPRINTF("failed, pGdkColor->blue= %d \n", pGdkColor->blue);
        return 0;
    }
    SB_INKPRINTF("rgb(%d,%d,%d) \n", pGdkColor->red, 
                    pGdkColor->green,pGdkColor->blue);
    return 1;
}
Beispiel #22
0
		void bencode_recursive(OutIt& out, const entry& e)
		{
			switch(e.type())
			{
			case entry::int_t:
				write_char(out, 'i');
				write_integer(out, e.integer());
				write_char(out, 'e');
				break;
			case entry::string_t:
				write_integer(out, e.string().length());
				write_char(out, ':');
				write_string(out, e.string());
				break;
			case entry::list_t:
				write_char(out, 'l');
				for (entry::list_type::const_iterator i = e.list().begin(); i != e.list().end(); ++i)
					bencode_recursive(out, *i);
				write_char(out, 'e');
				break;
			case entry::dictionary_t:
				write_char(out, 'd');
				for (entry::dictionary_type::const_iterator i = e.dict().begin();
					i != e.dict().end(); ++i)
				{
					// write key
					write_integer(out, i->first.length());
					write_char(out, ':');
					write_string(out, i->first);
					// write value
					bencode_recursive(out, i->second);
				}
				write_char(out, 'e');
				break;
			default:
				throw invalid_encoding();
			}
		}
void
SaveSlider(struct MyGadget *gd)
{
	write_integer(gd->data.bslider.min);
	write_integer(gd->data.bslider.max);
	write_integer(gd->data.bslider.pos);
	write_integer(gd->data.bslider.style);
	write_integer(gd->data.bslider.hashtype);
	write_integer(gd->data.bslider.hashcount);
	write_integer(gd->data.bslider.thickness);
	write_integer(gd->data.bslider.keyinc);
	write_integer(gd->data.bslider.fillall);

	write_color(&gd->data.bslider.fillcolor);
	write_color(&gd->data.bslider.barcolor);

	write_string(&gd->data.bslider.Label[0]);
	write_string(&gd->data.bslider.MinLabel[0]);
	write_string(&gd->data.bslider.MaxLabel[0]);
}
Beispiel #24
0
static size_t
write_json(json_t* json, stream_t* stream)
{
    switch (json_typeof(json)) {
        case JSON_OBJECT:  return write_object(json, stream);
        case JSON_ARRAY:   return write_array(json, stream);
        case JSON_STRING:  return write_string(json, stream);
        case JSON_INTEGER: return write_integer(json, stream);
        case JSON_REAL:    return write_real(json, stream);
        case JSON_TRUE:    return write_true(json, stream);
        case JSON_FALSE:   return write_false(json, stream);
        case JSON_NULL:    return write_null(json, stream);
        default:           return 0;
    }
}
Beispiel #25
0
static size_t
write_object(json_t* json, stream_t* stream)
{
    uint8_t tag = BSER_TAG_OBJECT;
    size_t bytes = 0;

    assert(json_is_object(json));

    if (stream->write(stream, &tag, SIZE_U8) == SIZE_U8) {
        size_t total_bytes = SIZE_U8;

        json_t* length_node = json_integer(json_object_size(json));
        size_t integer_length = write_integer(length_node, stream);
        total_bytes += integer_length;
        json_decref(length_node);

        if (integer_length > 0) {
            size_t val_bytes = 1;
            void *iter = json_object_iter(json);

            while (iter != NULL && val_bytes > 0) {
                val_bytes = 0;

                json_t* key_node = json_string(json_object_iter_key(iter));
                size_t key_bytes = write_string(key_node, stream);
                total_bytes += key_bytes;
                json_decref(key_node);

                if (key_bytes > 0) {
                    json_t* value = json_object_iter_value(iter);
                    val_bytes = write_json(value, stream);
                    total_bytes += val_bytes;
                }
                iter = json_object_iter_next(json, iter);
            }
            if (iter == NULL) {
                bytes = total_bytes;
            }
        }
    }
    return bytes;
}
Beispiel #26
0
static void
list_formatted_write_scalar (st_parameter_dt *dtp, bt type, void *p, int kind,
			     size_t size)
{
  if (dtp->u.p.current_unit == NULL)
    return;

  if (dtp->u.p.first_item)
    {
      dtp->u.p.first_item = 0;
      write_char (dtp, ' ');
    }
  else
    {
      if (type != BT_CHARACTER || !dtp->u.p.char_flag ||
	dtp->u.p.current_unit->delim_status != DELIM_NONE)
      write_separator (dtp);
    }

  switch (type)
    {
    case BT_INTEGER:
      write_integer (dtp, p, kind);
      break;
    case BT_LOGICAL:
      write_logical (dtp, p, kind);
      break;
    case BT_CHARACTER:
      write_character (dtp, p, kind, size);
      break;
    case BT_REAL:
      write_real (dtp, p, kind);
      break;
    case BT_COMPLEX:
      write_complex (dtp, p, kind, size);
      break;
    default:
      internal_error (&dtp->common, "list_formatted_write(): Bad type");
    }

  dtp->u.p.char_flag = (type == BT_CHARACTER);
}
Beispiel #27
0
static size_t
write_string(json_t* json, stream_t* stream)
{
    size_t bytes = 0;
    assert(json_is_string(json));
    const char* chars = json_string_value(json);
    size_t len = strlen(chars);
    uint8_t tag = BSER_TAG_STRING;

    if (stream->write(stream, &tag, SIZE_U8) == SIZE_U8) {
        json_t* length_node = json_integer(len);
        size_t len_bytes = write_integer(length_node, stream);
        json_decref(length_node);
        if (len_bytes > 0 &&
            stream->write(stream, chars, len) == len) {
            bytes = SIZE_U8 + len_bytes + len;
        }
    }
    return bytes;
}
Beispiel #28
0
// write ink object to file stream
unsigned char write_ink (PtrInk ink, FILE * file)
{
    PtrStroke stroke;

    if (ink == NULL || file == NULL )
    {
        SB_INKPRINTF("failed:incorrect arguments\n");
        return 0;
    }
    if (ink->nStrokes == 0)
    {
        SB_INKPRINTF("return:ink->nStrokes=0 \n");
        return 0;
    }
    if ( 0!= fseek (file, 0, SEEK_SET) )
    {
        SB_INKERRPRINTF("fseek failed \n");
        return 0;
    }
    if ( !write_integer (ink->nStrokes, file,WRITEINT_LINEEND) )
    {
        SB_INKERRPRINTF("failed writing ink->nStrokes=%d \n",
                        ink->nStrokes);
        return 0;
    }

    SB_INKPRINTF("ink=%p, ink->nStrokes=%d \n", ink, ink->nStrokes);
    stroke = ink->firstStroke;
    while (stroke)
    {
        if (0 ==write_stroke (file, stroke) )
        {
            SB_INKERRPRINTF("write_stroke failed \n");
            return 0;
        }
        stroke = stroke->nextStroke;
    }
    SB_INKPRINTF("succeeded \n");
    return 1;
}
Beispiel #29
0
static size_t
write_array(json_t* json, stream_t* stream)
{
    size_t bytes = 0;

    if (can_be_compact_array(json)) {
        bytes = write_compact_array(json, stream);
    } else {
        uint8_t tag = BSER_TAG_ARRAY;
        if (stream->write(stream, &tag, SIZE_U8) == SIZE_U8) {
            size_t int_bytes;

            size_t length = json_array_size(json);
            json_t* length_node = json_integer(length);

            int_bytes = write_integer(length_node, stream);
            json_decref(length_node);

            if (int_bytes > 0) {
                int i;
                size_t elem_bytes = 1;
                size_t elems_bytes = 0;

                for (i = 0; i < length && elem_bytes > 0; ++i) {
                    elem_bytes = write_json(json_array_get(json, i), stream);
                    elems_bytes += elem_bytes;
                }

                if (i == length) {
                    bytes = SIZE_U8 + int_bytes + elems_bytes;
                }
            }
        }
    }
    return bytes;
}
void
SaveString(struct MyGadget *gd)
{
	write_integer(gd->data.string.editable);
	write_integer(gd->data.string.selectable);
	write_integer(gd->data.string.maxchars);
	write_integer(gd->data.string.pixdeb);
	write_integer(gd->data.string.pixdiv);
	write_integer(gd->data.string.value);
	write_integer(gd->data.string.aligntxt);
	write_integer(gd->data.string.alignlab);
	write_integer(gd->data.string.acceptvir);
	write_integer(gd->data.string.negvalue);
	write_integer(gd->data.string.car);

	write_string(&gd->data.string.Text[0]);
}