Example #1
0
void asciicat(
  char *pcBuffer,
  char *pcString)
/* The one and only function that violates all coding standards.            */
{
  char      x[2];
  char      cHighNibble, cLowNibble;

  x[0] = 0;
  x[1] = 0;

  pcString += 2;                /* skip the 0x prefix */

  strcat(pcBuffer, "\"");

  while (*pcString != 0)
  {
    cHighNibble = *pcString++;
    cLowNibble = *pcString++;

    *x = TO_HEX(cHighNibble) << 4 | TO_HEX(cLowNibble);

    if (((*x) >= ' ') && ((*x) <= '~'))
      strcat(pcBuffer, x);
    else
      strcat(pcBuffer, ".");
  }

  strcat(pcBuffer, "\"");
}
Example #2
0
char Lua::_urlDecode(std::string::const_iterator& it, std::string::const_iterator& itEnd)
{
    if (*it != '%')
        return *it;
    if (++it != itEnd)
    {
#define TO_HEX(x) (                                     \
x >= '0' && x <= '9' ?                                  \
    x - '0' : (                                         \
        x >= 'A' && x <= 'F' ?                          \
            x - 'A' + 10 : (                            \
                x >= 'a' && x <= 'f' ? x - 'a' + 10 : x \
            )                                           \
        )                                               \
)
        char digit = (TO_HEX(*it)) * 16;
        if (++it != itEnd)
        {
            digit += TO_HEX(*it);
            return digit;
        }
#undef TO_HEX
    }
    --it;
    return '%';
}
Example #3
0
/*
** Add a number in hexadecimal format to (buf).
*/
ret_t
cherokee_buffer_add_ullong16 (cherokee_buffer_t *buf, cullong_t ulNum)
{
	size_t  i                     = (IOS_NUMBUF - 1);
	int     ival                  = 0;
	int     newlen                = 0;
	char    szOutBuf[IOS_NUMBUF];

	szOutBuf[i] = '\0';

	/* Convert number to string
	 */
	do {
		ival = (int) (ulNum & 0xF);
		szOutBuf[--i] = (char) TO_HEX(ival);
	}
	while ((ulNum >>= 4) != 0);

	/* Verify free space in buffer and if needed then enlarge it.
	*/
	newlen = buf->len + (int) ((IOS_NUMBUF - 1) - i);
	if (unlikely ((cuint_t)newlen >= buf->size)) {
		if (unlikely (realloc_new_bufsize(buf, newlen) != ret_ok)) {
			return ret_nomem;
		}
	}

	/* Copy	including '\0'
	 */
	strcpy (buf->buf + buf->len, &szOutBuf[i]);

	buf->len = newlen;

	return ret_ok;
}
static void
xhairs_color_opacity_changed (GtkColorButton *button, ZoomOptionsPrivate *priv)
{
    GdkRGBA rgba;
    gchar *color_string;

    gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &rgba);
    color_string = g_strdup_printf ("#%02x%02x%02x",
                                    TO_HEX(rgba.red),
                                    TO_HEX(rgba.green),
                                    TO_HEX(rgba.blue));

    g_settings_set_string (priv->settings, "cross-hairs-color", color_string);
    g_free (color_string);

    g_settings_set_double (priv->settings, "cross-hairs-opacity", rgba.alpha);
}
Example #5
0
void RDMSubDeviceBwLcd::DataHex(const uint8_t* pData, uint16_t nLength) {
	unsigned j;

	for (j = 0; j < nLength ; j++) {
		unsigned nOffset = j * 4;
		const uint8_t nData = pData[j];
		m_aText[nOffset    ] = ' ';
		m_aText[nOffset + 1] = TO_HEX((nData & 0xF0) >> 4);
		m_aText[nOffset + 2] = TO_HEX(nData & 0x0F);
	}

	for (; j < DMX_FOOTPRINT; j++) {
		unsigned nOffset = j * 4;
		m_aText[nOffset] = ' ';
		m_aText[nOffset + 1] = ' ';
		m_aText[nOffset + 2] = ' ';
	}
}
Example #6
0
char *createPattern_TM(char *pattern, int len) {
	char buff[MAX_PATTERN_LENGTH];
	char *res;
	int i, j;

	for (i = 0, j = 0; i < len; i++) {
		if (pattern[i] >= 32 && pattern[i] < 127) {
			buff[j++] = pattern[i];
		} else {
			buff[j++] = '|';
			buff[j++] = TO_HEX((pattern[i] & 0x0F0) >> 4);
			buff[j++] = TO_HEX(pattern[i] & 0x00F);
			buff[j++] = '|';
		}
	}
	buff[j++] = '\0';
	res = (char*)malloc(sizeof(char) * j);
	strcpy(res, buff);
	return res;
}
Example #7
0
EXPORT void str_encode_percent (const char * str, int len, char * out)
{
    if (len < 0)
        len = INT_MAX;

    while (len --)
    {
        char c = * str ++;
        if (! c)
            break;

        if (IS_LEGAL (c))
            * out ++ = c;
        else
        {
            * out ++ = '%';
            * out ++ = TO_HEX ((unsigned char) c >> 4);
            * out ++ = TO_HEX (c & 0xF);
        }
    }

    * out = 0;
}