Exemplo n.º 1
0
/**
 * \brief write a <stage> node with its members
 * \param writer the writer object to write to
 * \param stage_nr current stage number
 * \param row array of stage members
 * \param row_size number of members in the array
 */
void stageToXml(xmlTextWriterPtr writer, int stage_nr, int* row, int row_size) {

    xmlChar *xStage = itox(stage_nr);

    xmlTextWriterSetIndentString(writer, (xmlChar*)"  ");
    xmlTextWriterSetIndent(writer, 1);

    xmlTextWriterStartElement(writer, (xmlChar*)"stage");

    xmlTextWriterWriteAttribute(writer, (xmlChar*)"value", xStage);

    xmlTextWriterSetIndent(writer, 0);
    int idx;
    xmlChar *xMember;

    for (idx = 0; idx < row_size; idx++) {

        xMember = itox(row[idx]);

        xmlTextWriterStartElement(writer, (xmlChar*)"member");
        xmlTextWriterWriteAttribute(writer, (xmlChar*)"value", xMember);
        xmlTextWriterEndElement(writer);

        free(xMember);
    }

    xmlTextWriterSetIndentString(writer, (xmlChar*)"");
    xmlTextWriterSetIndent(writer, 1);

    xmlTextWriterEndElement(writer);    //stage

    free(xStage);
}
Exemplo n.º 2
0
void bin2string(const byte * data, size_t length, tstring & out)
{
	out.resize(length * 2);
	tchar * p = (tchar *)out.c_str();
	for (; 0 != length; ++data, --length, p += 2)
	{
		if (*data < 0x10)
		{
			*p = '0';
			itox((int)(*data), p + 1, 16);
		}
		else
		{
			itox((int)(*data), p, 16);
		}
	}
}
Exemplo n.º 3
0
/**
 * \brief To start the xml file
 * \param writer the writer object to write to
 * \param a the a variable
 * \param b the b variable
 * \param height dst number of stages
 */
void xmlHeader(xmlTextWriterPtr writer, int a, int b, int height) {

    // conversions
    xmlChar *xa, *xb, *xheight;
    xa = itox(a);
    xb = itox(b);
    xheight = itox(height);

    xmlTextWriterSetIndentString(writer, (xmlChar*)"  ");
    xmlTextWriterSetIndent(writer, 1);

    xmlTextWriterStartElement(writer, (xmlChar*)"dst");
        xmlTextWriterWriteAttribute(writer, (xmlChar*)"a", xa);
        xmlTextWriterWriteAttribute(writer, (xmlChar*)"b", xb);
        xmlTextWriterWriteAttribute(writer, (xmlChar*)"height", xheight);

    free(xa);
    free(xb);
    free(xheight);
}
Exemplo n.º 4
0
Arquivo: util.c Projeto: SICOM/rlib
gchar *str2hex(const gchar *str) {
	guint ch;
	gchar *result = g_malloc(2 * strlen(str) + 1);
	gchar *ptr;
	ptr = result;
	while ((ch = *str++)) {
		*ptr++ = itox((ch >> 4) & 0xF);
		*ptr++ = itox(ch & 0xF);
	}
	*ptr = '\0';
	return result;
}
Exemplo n.º 5
0
char* bmapo(char* src, char* disformat) {
    //二进制与十六进制相互转化
    int i = 0;
    char* start = src;
    if (!strcmp(disformat, "x")) {
        char* dis;
        int offset = 0;
        if ((offset = strlen(src) % 4) != 0) {
            dis = (char*)malloc(strlen(src) / 4 + 2);
            memset(dis,'0', strlen(src) / 4 + 2);
            dis[strlen(src) / 4 + 1] = '\0';
        } else {
            dis = (char*)malloc(strlen(src) / 4 + 1);
            memset(dis,'0', strlen(src) / 4 + 1);
            dis[strlen(src) / 4] = '\0';
        }
        int j = strlen(src) - 1;
        for(i = strlen(dis) - 1; i >= 0; i--) {
            int tmp = 0;
            if (j >= 0) tmp += src[j--] - '0';
            if (j >= 0) tmp += 2 * (src[j--] - '0');
            if (j >= 0) tmp += 4 * (src[j--] - '0');
            if (j >= 0) tmp += 8 * (src[j--] - '0');
            dis[i] = itox(tmp);
        }
        return dis;
    } else if (!strcmp(disformat, "b")) {
        char* dis = (char*)malloc((strlen(src) * 4 + 1)* sizeof(char));
        memset(dis,'0', strlen(src) * 4 + 1);
        dis[strlen(src) * 4] = '\0';
        for (i = 0; i < strlen(src) * 4; i += 4) {
            int tmp = xtoi(*start);
            start++;
            if (tmp / 8 > 0) {
                dis[i] = '1';
                tmp -= 8;
            }
            if (tmp / 4 > 0) {
                dis[i + 1] = '1';
                tmp -= 4;
            }
            if (tmp / 2 > 0) {
                dis[i + 2] = '1';
                tmp -= 2;
            }
            if (tmp / 1 > 0) dis[i + 3] = '1';
        }
        return strchr(dis,'1');
    } else {
        printf("error");
        exit(1);
    }
}
Exemplo n.º 6
0
//---------------------------------------------------------------------------
char HeightMap::add_to(HeightMap *dst)
{
//地図の内容追加
int i2,j2;
double h;
  for(int j=0;j<mesh_j;j++)
  {
  for(int i=0;i<mesh_i;i++)
  {
   if(read(&h,i,j))
   {
    i2=dst->xtoi(itox(i));
    j2=dst->ytoj(jtoy(j));
    dst->write(h,i2,j2);
   }
  }
  }
return 1;
}
Exemplo n.º 7
0
/**
 * \brief write a <node> node with his stage members
 * \param writer the writer object to write to
 * \param node_id the id of the node to write
 * \param table the routing or predecessors table
 * \param row_size array of each row size
 * \param height number of stages
 */
void nodeToXml(xmlTextWriterPtr writer, int node_id, int **table, int *row_size, int height) {

    int stage;
    xmlChar *xNode_id = itox(node_id);

    xmlTextWriterSetIndentString(writer, (xmlChar*)"  ");
    xmlTextWriterSetIndent(writer, 1);

    xmlTextWriterStartElement(writer, (xmlChar*)"node");
        xmlTextWriterWriteAttribute(writer, (xmlChar*)"id", xNode_id);

        for (stage = 0; stage < height; stage++) {

            stageToXml(writer, stage, table[stage], row_size[stage]);
        }

        xmlTextWriterSetIndentString(writer, (xmlChar*)"  ");
    xmlTextWriterEndElement(writer);        //node

    free(xNode_id);
}
Exemplo n.º 8
0
void snprintf_1(char* buffer, int buffer_size, const char* format, int input) {
    int index;
    const char* format_iter;
    const char* subformat_iter;

    index = 0;
    format_iter = format;
    while (*format_iter) {
        
        //
        // Look for format string combinations
        //
        
        if (*format_iter == '%') {
            format_iter++;

            if (*format_iter == 'i') {
                format_iter++;                

                //
                // Format the input as integer
                //

                itoa(input, format_int_buffer);
                subformat_iter = format_int_buffer;
                while (*subformat_iter) {
                    buffer[index] = *subformat_iter;
                    subformat_iter++;

                    index++;
                    if (index == buffer_size) {
                        goto format_done;
                    }
                }
            } else if (*format_iter == 'x') {
                format_iter++;                

                buffer[index] = '0';
                index++;                
                if (index == buffer_size) {
                    goto format_done;
                }

                buffer[index] = 'x';
                index++;
                if (index == buffer_size) {
                    goto format_done;
                }                                

                //
                // Format the input as hex
                //

                itox(input, format_int_buffer);
                subformat_iter = format_int_buffer;
                while (*subformat_iter) {
                    buffer[index] = *subformat_iter;
                    subformat_iter++;

                    index++;
                    if (index == buffer_size) {
                        goto format_done;
                    }
                }
            } else if (*format_iter == '%') {

                //
                // Literal %
                //
                
                buffer[index] = '%';

                index++;
                if (index == buffer_size) {
                    goto format_done;
                }
            }
        } else {

            //
            // Copy the format string character to the buffer
            //
            
            buffer[index] = *format_iter;
            format_iter++;

            index++;
            if (index == buffer_size) {
                goto format_done;
            }
        }
    }

    buffer[index] = '\0';

format_done:
    return;
}
Exemplo n.º 9
0
const wchar * ftox(wchar * out, size_t buf_size, double val, unsigned precision, bool b_sign)
{
	wchar temp[64];
	size_t outptr;
	size_t temp_len;

	if (buf_size == 0) return out;
	buf_size--; //for null terminator

	outptr = 0;

	if (outptr == buf_size) {out[outptr] = 0; return out;}

	if (val < 0) {out[outptr++] = '-'; val = -val;}
	else if (b_sign) {out[outptr++] = '+';}

	if (outptr == buf_size) {out[outptr] = 0; return out;}


	{
		double powval = pow((double)10.0, (double)precision);
		int64 blargh = (int64)floor(val * powval + 0.5);
		itox(blargh, temp, 10);
	}

	temp_len = _tcslen(temp);
	if (temp_len <= precision)
	{
		out[outptr++] = '0';
		if (outptr == buf_size) {out[outptr] = 0; return out;}
		out[outptr++] = '.';
		if (outptr == buf_size) {out[outptr] = 0; return out;}
		size_t d;
		for (d = precision - temp_len;d;d--)
		{
			out[outptr++] = '0';
			if (outptr == buf_size) {out[outptr] = 0; return out;}
		}
		for (d = 0;d < temp_len;d++)
		{
			out[outptr++] = temp[d];
			if (outptr == buf_size) {out[outptr] = 0; return out;}
		}
	}
	else
	{
		size_t d = temp_len;
		const wchar * src = temp;
		while (*src)
		{
			if (d-- == precision)
			{
				out[outptr++] = '.';
				if (outptr == buf_size) {out[outptr] = 0; return out;}
			}
			out[outptr++] = *(src++);
			if (outptr == buf_size) {out[outptr] = 0; return out;}
		}
	}
	out[outptr] = 0;
	return out;
}