Пример #1
0
Файл: lexer.cpp Проект: aep/clay
static bool hexEscapeChar(char &x) {
    int digit1, digit2;
    if (!hexDigit(digit1)) return false;
    if (!hexDigit(digit2)) return false;
    x = (char)(digit1*16 + digit2);
    return true;
}
Пример #2
0
	vector<uint8_t> Configure::getBinary(const wstring &name) const
	{
		wstring str = get(name);
		vector<uint8_t> ve;
		uint8_t v = 0;
		bool next = false;

		ve.reserve(str.size() / 2);

		for(auto it = str.begin(); it != str.end(); ++ it)
		{
			if(next)
			{
				v <<= 4;
				v |= hexDigit(*it);
				ve.push_back(v);
				next = false;
			}
			else
			{
				v = hexDigit(*it);
				next = true;
			}
		}

		return ve;
	}
Пример #3
0
void decodeHex(const char *p, const char *end, unsigned char *target)
{
    for ( ; p < end; ++p) {
        unsigned c = 16 * hexDigit(*p);
        c += hexDigit(*++p);
        *target++ = c;
    }
}
Пример #4
0
bool parse_color_value( const char * & str, css_length_t & value )
{
    value.type = css_val_unspecified;
    skip_spaces( str );
    if ( substr_compare( "inherited", str ) )
    {
        value.type = css_val_inherited;
        value.value = 0;
        return true;
    }
    if ( substr_compare( "none", str ) )
    {
        value.type = css_val_unspecified;
        value.value = 0;
        return true;
    }
    if (*str=='#') {
        // #rgb or #rrggbb colors
        str++;
        int nDigits = 0;
        for ( ; hexDigit(str[nDigits])>=0; nDigits++ )
            ;
        if ( nDigits==3 ) {
            int r = hexDigit( *str++ );
            int g = hexDigit( *str++ );
            int b = hexDigit( *str++ );
            value.type = css_val_color;
            value.value = (((r + r*16) * 256) | (g + g*16)) * 256 | (b + b*16);
            return true;
        } else if ( nDigits==6 ) {
            int r = hexDigit( *str++ ) * 16;
            r += hexDigit( *str++ );
            int g = hexDigit( *str++ ) * 16;
            g += hexDigit( *str++ );
            int b = hexDigit( *str++ ) * 16;
            b += hexDigit( *str++ );
            value.type = css_val_color;
            value.value = ((r * 256) | g) * 256 | b;
            return true;
        } else
            return false;
    }
    for ( int i=0; standard_color_table[i].name != NULL; i++ ) {
        if ( substr_icompare( standard_color_table[i].name, str ) ) {
            value.type = css_val_color;
            value.value = standard_color_table[i].color;
            return true;
        }
    }
    return false;
}
Пример #5
0
// String from hex "414A" -> "AJ".
std::string stringFromHex(const char *p, const char *end)
{
    if (p == end)
        return std::string();

    std::string rc;
    rc.reserve((end - p) / 2);
    for ( ; p < end; ++p) {
        unsigned c = 16 * hexDigit(*p);
        c += hexDigit(*++p);
        rc.push_back(char(c));
    }
    return rc;
}
Пример #6
0
int htoi(char* s){
	int i = 0, c, t = 0;

	if(!strncmp("0x", s, 2) || !strncmp("0X", s, 2))
		i = 2;
	while(c = hexDigit(s[i])){
		switch(c){
		case 1:
			t = 16 * t + s[i] - '0';
			break;
		case 2:
			t = 16 * t + s[i] - 'A' + 10;
			break;
		case 3:
			t = 16 * t + s[i] - 'a' + 10;
			break;
		default:
			printf("Error when convert\n");
		}
		i++;
#if D_S
		/*printf("%d\t", i);     */
#endif
	}
	return t;
}
Пример #7
0
static unsigned strToHex(
	const char *str)
{
	unsigned rtn = 0;
	while(*str) {
		rtn <<= 4;
		rtn |= hexDigit(*str++);
	}
	return rtn;
}
Пример #8
0
Файл: lexer.cpp Проект: aep/clay
static bool hexDigits() {
    int x;
    while (true) {
        optNumericSeparator();
        const char *p = save();
        if (!hexDigit(x)) {
            restore(p);
            break;
        }
    }
    return true;
}
Пример #9
0
char *makeuuid(void) {
	char uuid[UUID_LEN] = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx", *p=uuid;
	short r;
	
	srand((unsigned)time(NULL));
	
	while (*p) {
		r = rand()%16|0;
		
		switch (*p) {
			case 'x':
				*p = hexDigit(r);
				break;
			case 'y':
				*p = hexDigit((r &0x3) |0x8);
				break;
		}
		
		p++;
	}
	
	return dup_str(uuid);
}
/* convert ASCII string in hex to unsigned */
unsigned hexToBin(const char *hex)
{
	unsigned rtn = 0;
	const char *cp = hex;
	if((cp[0] == '0') && (cp[1] == 'x')) {
		cp += 2;
	}
	if(strlen(cp) > 8) {
		printf("***BAD HEX STRING (%s)\n", cp);
		return 0;
	}
	while(*cp) {
		rtn <<= 4;
		rtn += hexDigit(*cp);
		cp++;
	}
	return rtn;
}
Пример #11
0
/**
 * Pretty-print 0-terminated byte values.
 * Helper function for test output.
 *
 * @param bytes 0-terminated byte array to print
 */
static void
printBytes(uint8_t *bytes, char *out) {
    int i;
    uint8_t b;

    i=0;
    while((b=*bytes++)!=0) {
        *out++=' ';
        *out++=hexDigit((uint8_t)(b>>4));
        *out++=hexDigit((uint8_t)(b&0xf));
        ++i;
    }
    i=3*(5-i);
    while(i>0) {
        *out++=' ';
        --i;
    }
    *out=0;
}
Пример #12
0
 bool setManglingKey(lString16 key) {
     if (key.startsWith(lString16(L"urn:uuid:")))
         key = key.substr(9);
     _fontManglingKey.clear();
     _fontManglingKey.reserve(16);
     lUInt8 b = 0;
     int n = 0;
     for (int i=0; i<key.length(); i++) {
         int d = hexDigit(key[i]);
         if (d>=0) {
             b = (b << 4) | d;
             if (++n > 1) {
                 _fontManglingKey.add(b);
                 n = 0;
                 b = 0;
             }
         }
     }
     return _fontManglingKey.length() == 16;
 }
Пример #13
0
 virtual void OnText( const lChar16 * text, int len, lUInt32 flags)
 {
     int fmt = m_stack.getInt(pi_imgfmt);
     if (!fmt)
         return;
     _fmt = fmt;
     for (int i=0; i<len;) {
         int d = -1;
         do {
             d = i<len ? hexDigit(text[i]) : -1;
             i++;
         } while (d<0 && i<len);
         if (_lastDigit>=0 && d>=0) {
             _buf.add((lUInt8)((_lastDigit<<4) | d));
             _lastDigit = -1;
         } else {
             if (d>=0)
                 _lastDigit = d;
         }
     }
 }
Пример #14
0
// Process incoming characters
void gaitDesignerProcess(GAIT_DESIGNER* gait){
	int b = __uartGetByte(gait->uart);
	if(b==-1) return;	// No characters at all
	
	uint8_t inx = gait->msgInx;
	uint8_t* buffer = gait->buffer;

	Writer old = rprintfInit(gait->uart->writer);

	// Process all received characters
	while(b!=-1){
		uint8_t servo;
		int8_t percent;

		uint8_t c = b & 0xff;;
//		_uartSendByte(gait->uart,c);
		if(c == '\r'){
			// ignore it
		}else if(c=='\n'){
			buffer[inx] = '\0';
			// now process msg
			if(buffer[0]=='G' && inx>=3 && inx%2 ==1){
				// A group message,
				inx=0;
				for(servo=0; servo < gait->num_actuators && buffer[inx+1];servo++){
					inx++;
					int8_t percent = (hexDigit(buffer,inx) << 4);
					inx++;
					percent |= hexDigit(buffer,inx);
					setSpeed(gait,servo,percent);
				}
			}else if(buffer[0]=='N' && inx==1){
				// Reply with number of servos
				rprintf("#n%d\r\n",gait->num_actuators);
			}else if(buffer[0]=='C'){
				// Get config ie: C0
				// Reply with: c0,center,range
				servo=0;
				inx=1;
				while(buffer[inx]>='0' && buffer[inx]<='9'){
					servo*=10;
					servo+= (buffer[inx++] & 15);
				}
				SERVO* theServo = (SERVO*)getEntry(gait, servo);

				rprintf("#c%d,%d,%d\r\n",servo,theServo->center_us,theServo->range_us);
			}else if(buffer[0]=='S'){
				// Single servo cmd  <inx>,<speed>
				boolean neg = FALSE;
				servo=0;
				percent=0;
				inx=1;
				while(buffer[inx]>='0' && buffer[inx]<='9'){
					servo*=10;
					servo+= (buffer[inx++] & 15);
				}
				if(buffer[inx++]==','){
					if(buffer[inx]=='-'){
						inx++;
						neg=TRUE;
					}
					while(buffer[inx]){
						percent*=10;
						percent += (buffer[inx++] & 15);
					}
					if(neg){
						percent *= -1;
					}
					setSpeed(gait,servo,percent);
				}
			}
			inx=0;
		}else if (c=='#'){
			inx = 0;
		}else{
			buffer[inx++] = b;
		}
		b = __uartGetByte(gait->uart);
	}
	gait->msgInx = inx;
	rprintfInit(old);
}
Пример #15
0
Файл: lexer.cpp Проект: aep/clay
static bool hexInt() {
    if (!str("0x")) return false;
    int x;
    if (!hexDigit(x)) return false;
    return hexDigits();
}