コード例 #1
0
ファイル: lbaselib.c プロジェクト: AbuShaqra/nodemcu-firmware
static int luaB_tonumber (lua_State *L) {
  int base = luaL_optint(L, 2, 10);
  if (base == 10) {  /* standard conversion */
    luaL_checkany(L, 1);
    if (lua_isnumber(L, 1)) {
      lua_pushnumber(L, lua_tonumber(L, 1));
      return 1;
    }
  }
  else {
    const char *s1 = luaL_checkstring(L, 1);
    char *s2;
    unsigned long n;
    luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
    n = c_strtoul(s1, &s2, base);
    if (s1 != s2) {  /* at least one valid digit? */
      while (isspace((unsigned char)(*s2))) s2++;  /* skip trailing spaces */
      if (*s2 == '\0') {  /* no invalid trailing characters? */
        lua_pushnumber(L, (lua_Number)n);
        return 1;
      }
    }
  }
  lua_pushnil(L);  /* else not a number */
  return 1;
}
コード例 #2
0
ファイル: xsDebug.c プロジェクト: dadongdong/kinomajs
void fxClearBreakpoint(txMachine* the, txString thePath, txString theLine)
{
	txSlot* aSymbol;
	txInteger aLine;
	txSlot** aBreakpointAddress;
	txSlot* aBreakpoint;

	if (!theLine)
		return;
	if (!thePath)
		return;
	aLine = c_strtoul(theLine, NULL, 10);
	if ((aLine <= 0) || (0x00007FFF < aLine))
		return;
	aSymbol = fxFindSymbol(the, thePath);
	if (!aSymbol)
		return;
	aBreakpointAddress = &(mxBreakpoints.value.list.first);
	while ((aBreakpoint = *aBreakpointAddress)) {
		if ((aBreakpoint->value.reference == aSymbol) && (aBreakpoint->ID == (txID)aLine)) {
			*aBreakpointAddress = aBreakpoint->next;
			break;
		}
		aBreakpointAddress = &(aBreakpoint->next);
	}
}
コード例 #3
0
ファイル: lobject.c プロジェクト: 3dot3/nodemcu-firmware
int luaO_str2d (const char *s, lua_Number *result) {
  char *endptr;
  *result = lua_str2number(s, &endptr);
  if (endptr == s) return 0;  /* conversion failed */
  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */
#if defined(LUA_CROSS_COMPILER) 
    {
    long lres = strtoul(s, &endptr, 16);
#if LONG_MAX != 2147483647L
    if (lres & ~0xffffffffL) 
      *result = cast_num(-1);
    else if (lres & 0x80000000L)
      *result = cast_num(lres | ~0x7fffffffL);
    else
#endif
      *result = cast_num(lres);
    }
#else
    *result = cast_num(c_strtoul(s, &endptr, 16));
#endif
  if (*endptr == '\0') return 1;  /* most common case */
  while (isspace(cast(unsigned char, *endptr))) endptr++;
  if (*endptr != '\0') return 0;  /* invalid trailing characters? */
  return 1;
}
コード例 #4
0
ファイル: xsJSON.c プロジェクト: dadongdong/kinomajs
void fxGetNextJSONToken(txScriptParser* theParser)
{
	txMachine* the = theParser->the;
	int c;
	txString p;
	txString q;
	txString r;
	txString s;
	txU4 t = 0;
	txNumber aNumber;

	theParser->line = theParser->line2;

	theParser->crlf = theParser->crlf2;
	theParser->escaped = theParser->escaped2;
	theParser->flags->value.string = theParser->flags2->value.string;
	theParser->integer = theParser->integer2;
	theParser->number = theParser->number2;
	theParser->string->value.string = theParser->string2->value.string;
	theParser->symbol = theParser->symbol2;
	theParser->token = theParser->token2;
	
	theParser->crlf2 = 0;
	theParser->escaped2 = 0;
	theParser->flags2->value.string = mxEmptyString.value.string;
	theParser->integer2 = 0;
	theParser->number2 = 0;
	theParser->string2->value.string = mxEmptyString.value.string;
	theParser->symbol2 = C_NULL;
	theParser->token2 = XS_NO_TOKEN;
	while (theParser->token2 == XS_NO_TOKEN) {
		switch (theParser->character) {
		case C_EOF:
			theParser->token2 = XS_TOKEN_EOF;
			break;
		case 10:	
			theParser->line2++;
			fxGetNextCharacter(theParser);
			theParser->crlf2 = 1;
			break;
		case 13:	
			theParser->line2++;
			fxGetNextCharacter(theParser);
			if (theParser->character == 10)
				fxGetNextCharacter(theParser);
			theParser->crlf2 = 1;
			break;
			
		case '\t':
		case ' ':
			fxGetNextCharacter(theParser);
			break;
			
		case '0':
			fxGetNextCharacter(theParser);
			c = theParser->character;
			if (c == '.') {
				fxGetNextCharacter(theParser);
				c = theParser->character;
				if ((('0' <= c) && (c <= '9')) || (c == 'e') || (c == 'E'))
					fxGetNextNumber(theParser, 0);
				else {
					theParser->number2 = 0;
					theParser->token2 = XS_TOKEN_NUMBER;
				}
			}
			else if ((c == 'e') || (c == 'E')) {
				fxGetNextNumber(theParser, 0);
			}
			else if ((c == 'x') || (c == 'X')) {
				p = theParser->buffer;
				*p++ = '0';
				*p++ = 'x';
				for (;;) {
					fxGetNextCharacter(theParser);
					c = theParser->character;
					if (('0' <= c) && (c <= '9'))
						*p++ = c;
					else if (('A' <= c) && (c <= 'Z'))
						*p++ = c;
					else if (('a' <= c) && (c <= 'z'))
						*p++ = c;
					else
						break;
				}
				*p = 0;
				theParser->number2 = fxStringToNumber(theParser->the, theParser->buffer, 1);
				theParser->integer2 = (txInteger)theParser->number2;
				aNumber = theParser->integer2;
				if (theParser->number2 == aNumber)
					theParser->token2 = XS_TOKEN_INTEGER;
				else
					theParser->token2 = XS_TOKEN_NUMBER;
			}
			else {
				theParser->integer2 = 0;
				theParser->token2 = XS_TOKEN_INTEGER;
			}
			break;
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case '-':	
			fxGetNextNumber(theParser, 1);
			break;
		case ',':
			theParser->token2 = XS_TOKEN_COMMA;
			fxGetNextCharacter(theParser);
			break;	
		case ':':
			theParser->token2 = XS_TOKEN_COLON;
			fxGetNextCharacter(theParser);
			break;	
		case '[':
			theParser->token2 = XS_TOKEN_LEFT_BRACKET;
			fxGetNextCharacter(theParser);
			break;	
		case ']':
			theParser->token2 = XS_TOKEN_RIGHT_BRACKET;
			fxGetNextCharacter(theParser);
			break;	
		case '{':
			theParser->token2 = XS_TOKEN_LEFT_BRACE;
			fxGetNextCharacter(theParser);
			break;	
		case '}':
			theParser->token2 = XS_TOKEN_RIGHT_BRACE;
			fxGetNextCharacter(theParser);
			break;	
		case '"':
			p = theParser->buffer;
			q = p + sizeof(theParser->buffer) - 1;
			r = C_NULL;
			fxGetNextCharacter(theParser);
			for (;;) {
				if (theParser->character == C_EOF) {
					fxReportParserError(theParser, "end of file in string");			
					break;
				}
				else if ((theParser->character == 10) || (theParser->character == 13)) {
					fxReportParserError(theParser, "end of line in string");			
					break;
				}
				else if ((0 <= theParser->character) && (theParser->character < 32)) {
					fxReportParserError(theParser, "invalid character in string");			
					break;
				}
				else if (theParser->character == '"') {
					fxGetNextCharacter(theParser);
					break;
				}
				else if (theParser->character == '"') {
					fxGetNextCharacter(theParser);
					break;
				}
				else if (theParser->character == '\\') {
					theParser->escaped2 = 1;
					r = C_NULL;
					fxGetNextCharacter(theParser);
					switch (theParser->character) {
					case 10:
						theParser->line2++;
						fxGetNextCharacter(theParser);
						break;
					case 13:
						theParser->line2++;
						fxGetNextCharacter(theParser);
						if (theParser->character == 10)
							fxGetNextCharacter(theParser);
						break;
					case '\'':
						if (p < q) *p++ = '\'';
						fxGetNextCharacter(theParser);
						break;
					case '"':
						if (p < q) *p++ = '"';
						fxGetNextCharacter(theParser);
						break;
					case '\\':
						if (p < q) *p++ = '\\';
						fxGetNextCharacter(theParser);
						break;
					case '0':
						if (p < q) *p++ = 0;
						fxGetNextCharacter(theParser);
						break;
					case 'b':
						if (p < q) *p++ = '\b';
						fxGetNextCharacter(theParser);
						break;
					case 'f':
						if (p < q) *p++ = '\f';
						fxGetNextCharacter(theParser);
						break;
					case 'n':
						if (p < q) *p++ = '\n';
						fxGetNextCharacter(theParser);
						break;
					case 'r':
						if (p < q) *p++ = '\r';
						fxGetNextCharacter(theParser);
						break;
					case 't':
						if (p < q) *p++ = '\t';
						fxGetNextCharacter(theParser);
						break;
					case 'u':
						r = p;
						t = 5;
						if (p < q) *p++ = 'u';
						fxGetNextCharacter(theParser);
						break;
					case 'v':
						if (p < q) *p++ = '\v';
						fxGetNextCharacter(theParser);
						break;
					case 'x':
						r = p;
						t = 3;
						if (p < q) *p++ = 'x';
						fxGetNextCharacter(theParser);
						break;
					default:
						p = (txString)fsX2UTF8(theParser, theParser->character, (txU1*)p, q - p);
						fxGetNextCharacter(theParser);
						break;
					}
				}
				else {
					p = (txString)fsX2UTF8(theParser, theParser->character, (txU1*)p, q - p);
					if (r) {
						if ((txU4)(p - r) > t)
							r = C_NULL;
						else if (((txU4)(p - r) == t) && (p < q)) {
							*p = 0;
							t = c_strtoul(r + 1, &s, 16);
							if (!*s)
								p = (txString)fsX2UTF8(theParser, t, (txU1*)r, q - r);
							r = C_NULL;
						}
					}
					fxGetNextCharacter(theParser);
				}
			}
			*p = 0;
			if (p == q)
				fxReportParserError(theParser, "string overflow");			
			fxCopyStringC(theParser->the, theParser->string2, theParser->buffer);
			theParser->token2 = XS_TOKEN_STRING;
			break;
		default:
			if (fxIsIdentifierFirst(theParser->character)) {
				p = theParser->buffer;
				q = p + sizeof(theParser->buffer) - 1;
				for (;;) {
					if (p == q) {
						fxReportParserError(theParser, "identifier overflow");			
						break;
					}
					*p++ = theParser->character;
					fxGetNextCharacter(theParser);
					if (!fxIsIdentifierNext(theParser->character))
						break;
				}
				*p = 0;
				fxGetNextJSONKeyword(theParser);
			}
			else {
				mxDebug1(theParser->the, XS_SYNTAX_ERROR, "invalid character %d", theParser->character);
				fxGetNextCharacter(theParser);
			}
			break;
		}
	}
}