Example #1
0
BLAPI_PROTO
bl_kball(lua_State *L)
{
    // first, sleep by given seconds
    int r = 0, i = 0;

    r = bl_sleep(L);
    if (blrt.abort)
        return r;

    // pop all arguments
    lua_pop(L, lua_gettop(L));


#ifdef _WIN32
    while (i < LUA_MINSTACK && peekch(0))
    {
        bl_k2s(L, vkey());
        i++;
    }
#else
    while (i < LUA_MINSTACK && vkey_is_ready()) {
        bl_k2s(L, vkey());
        i++;
    }
#endif

    return i;
}
Example #2
0
/* Skip whitespace */
static void
space (MNCL_DATA_PARSE_CTX *ctx)
{
    while (1) {
        int c = peekch(ctx);
        if (!c || !isspace(c)) {
            break;
        }
        readch(ctx);
    }
}
Example #3
0
static int
readch (MNCL_DATA_PARSE_CTX *ctx)
{
    int c = peekch(ctx);
    if (c) {
        ++ctx->i;
        ++ctx->col;
        if (c == '\n') {
            ctx->col = 1;
            ++ctx->line;
        }
    }
    return c;
}
Example #4
0
static MNCL_DATA *
number(MNCL_DATA_PARSE_CTX *ctx, int scan)
{
    const char *s = ctx->s + ctx->i;
    int ch;
    MNCL_DATA *result;
    if (peekch(ctx) == '-') {
        readch(ctx);
    }
    if (peekch(ctx) == '0') {
        readch(ctx);
        if (isdigit(peekch(ctx))) {
            snprintf(error_str, 512, "%d:%d: Numbers may not have leading zeros", ctx->line, ctx->col);
            return NULL;
        }
    } else {
        int n = 0;
        while (isdigit(peekch(ctx))) {
            readch(ctx);
            ++n;
        }
        if (n == 0) {
            snprintf(error_str, 512, "%d:%d: Expected number", ctx->line, ctx->col);
            return NULL;
        }
    }
    if (peekch(ctx) == '.') {
        int n = 0;
        readch(ctx);
        while (isdigit(peekch(ctx))) {
            readch(ctx);
            ++n;
        }
        if (n == 0) {
            snprintf(error_str, 512, "%d:%d: Expected number after decimal point", ctx->line, ctx->col);
            return NULL;
        }
    }
    ch = peekch(ctx);
    if (ch == 'e' || ch == 'E') {
        int n = 0;
        readch(ctx);
        ch = peekch(ctx);
        if (ch == '+' || ch == '-') {
            readch(ctx);
        }
        while (isdigit(peekch(ctx))) {
            readch(ctx);
            ++n;
        }
        if (n == 0) {
            snprintf(error_str, 512, "%d:%d: Expected number after exponent", ctx->line, ctx->col);
            return NULL;
        }
    }
    if (scan) {
        return mncl_data_ok;
    }
    result = (MNCL_DATA *)malloc(sizeof(MNCL_DATA));
    if (!result) {
        snprintf(error_str, 512, "%d:%d: Out of memory", ctx->line, ctx->col);
        return NULL;
    }
    result->tag = MNCL_DATA_NUMBER;
    result->value.number = strtod(s, NULL);
    return result;
}
Example #5
0
static int
lex(Lex *l)
{
	Rune r, r2;
	char *t;
	int i;
	char c;

	for(;;){
		r = peekch(l);
		if(r != 0x20 && r != 0x09 && r != 0x0A && r != 0x0D)
			break;
		getch(l);
	}
	r = getch(l);
	if(r == ']' && l->canjmp)
		longjmp(l->jmp, 1);
	l->canjmp = 0;
	if(r == 0 || r == '{' || r == '[' || r == ']' || r == '}' || r == ':' || r == ','){
		l->t = r;
		return 0;
	}
	if(r >= 0x80 || isalpha(r)){
		t = l->buf;
		for(;;){
			t += runetochar(t, &r);
			if(t >= l->buf + l->slen){
				werrstr("json: literal too long");
				return -1;
			}
			r = peekch(l);
			if(r < 0x80 && !isalpha(r))
				break;
			getch(l);
		}
		*t = 0;
		if(strcmp(l->buf, "true") == 0)
			l->t = TTRUE;
		else if(strcmp(l->buf, "false") == 0)
			l->t = TFALSE;
		else if(strcmp(l->buf, "null") == 0)
			l->t = TNULL;
		else{
			werrstr("json: invalid literal");
			return -1;
		}
		return 0;
	}
	if(isdigit(r) || r == '-'){
		l->n = strtod(l->s-1, &l->s);
		l->t = TNUM;
		return 0;
	}
	if(r == '"'){
		r2 = 0;
		t = l->buf;
		for(;;){
			r = getch(l);
			if(r == '"')
				break;
			if(r < ' '){
				werrstr("json: invalid char in string %x", r);
				return -1;
			}
			if(r == '\\'){
				r = getch(l);
				switch(r){
				case 'n':
					r = '\n';
					break;
				case 'r':
					r = '\r';
					break;
				case 'u':
					r = 0;
					for(i = 0; i < 4; i++){
						if(!isxdigit(peekch(l)))
							break;

						c = getch(l);
						r *= 16;
						if(c >= '0' && c <= '9')
							r += c - '0';
						else if(c >= 'a' && c <= 'f')
							r += c - 'a' + 10;
						else if(c >= 'A' && c <= 'F')
							r += c - 'A' + 10;
					}
					if(fixsurrogate(&r, r2)){
						r2 = r;
						continue;
					}
					break;
				case 't':
					r = '\t';
					break;
				case 'f':
					r = '\f';
					break;
				case 'b':
					r = '\b';
					break;
				case '"': case '/': case '\\':
					break;
				default:
					werrstr("json: invalid escape sequence \\%C", r);
					return -1;
				}
			}
			r2 = 0;
			t += runetochar(t, &r);
			if(t >= l->buf + l->slen){
				werrstr("json: string too long");
				return -1;
			}
		}
		*t = 0;
		l->t = TSTRING;
		return 0;
	}
	werrstr("json: invalid char %C", peekch(l));
	return -1;
}
Example #6
0
char CBaseLexer::selectpeek()
{
	if (isMacrosMode)
		return strMacros[idxMacros];
	return peekch();
}
Example #7
0
void main()
{
	UCHAR ch;
	UCHAR tmpch;

	PulseCountDelaysSec = 65 * PULSE_COUNT_DELAY_SEC;  // 1300 aprox 20 sec
	MaxCountPulse = MAXCOUNT_PULSES_BEFORE_DELAY;
	PulseCountHelper = 0;
	IsDelay = 0;
	FlashLed = 0;

	init();

	printf("\r\nStart...\r\nWaiting for Switch To go High state (5v)\r\n ");
	while (!SwitchPort)
	{
		// wait for the switch to be high
	}
	printf("Switch is High\r\n");

	pulseCount = EEReadLong(EEPROMSTARTADDRESS);
	pulseCount = EEReadLong(EEPROMSTARTADDRESS);
	
	printf("\r\nStart: current count from eeprom is: ");
	PrintLong(pulseCount);

	//ClearEEprom();
	//pulseCount = 0;
	LedPort = 0;
	Led2Port = 0;

	int i=0, x;

	SetLedState();
 	while (1)
	{
		
		if (pulseCount < MAXCOUNT2+5)
		{
			CheckSwitch();
		}
		// check if there is data in the usart
		ch = peekch();
		if (ch != 0)
		{ 
			if (ch == 'R') // read count
			{
				printf("\r\ncount: ");
				PrintLong(pulseCount);
			}
			if (ch == 'Z') // zero count
			{
				pulseCount = 0;
				SetLedState();
				EEWriteLong(EEPROMSTARTADDRESS, pulseCount);
				printf("\r\nCount Zeroed");
			}
			if (ch == 'V') // show version 
			{
				printf(VERSIONSTRING);
				//printf("\r\nLow Max count set to: ");
				//PrintLong(MAXCOUNT1);

				//printf("\r\nHigh Max count set to: ");
				//PrintLong(MAXCOUNT2);
			}
			if (ch == 'S')  // read serial number
			{
				EEReadData(EEPROMSERIALSTARTADDRESS, Serial, 5);
				printf("\r\nSerial: %s", Serial);
			}
			if (ch == 'D') // set serial number
			{
				// need to get 5 chars from serial
				printf("\r\nEnter Serial Number (5 char): ");
				for (i=0; i < 5; i++)
				{
					Serial[i] = getch();
					putch(Serial[i]);
				}
				Serial[5] = 0;
				EEWriteData(EEPROMSERIALSTARTADDRESS, Serial, 5);
				printf("\r\nSerial set to: %s", Serial);
			}
			//if (ch == 'Q')
			//{
			//	pulseCount = MAXCOUNT1;
			//	SetLedState();
			//	EEWriteLong(EEPROMSTARTADDRESS, pulseCount);
			//	printf("\r\nCount Set To Max :");
			//	PrintLong(pulseCount);
			//}
			//if ((ch== 'P') && (pulseCount < MAXCOUNT2+5))
			//{
			//	pulseCount++;
			//	// write value to EEPROM address
			//	EEWriteLong((UCHAR)EEPROMSTARTADDRESS, pulseCount);
			//	printf("\r\ncurrent count is: ");
			//	PrintLong(pulseCount);
			//	SetLedState();
			//}
		}
		//printf("qs");	
	
	}
}