From 15671f57ea852bc1df5c0d2a358b714eeb097074 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周一, 17 10月 2016 14:27:19 +0800 Subject: [PATCH] Merge pull request #83 from ardovm/master --- libscpi/src/lexer.c | 42 ++++++++++++++++++++++-------------------- 1 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libscpi/src/lexer.c b/libscpi/src/lexer.c index 98c6f74..5d5582d 100644 --- a/libscpi/src/lexer.c +++ b/libscpi/src/lexer.c @@ -160,7 +160,7 @@ /* skip characters */ /* 7.4.1 <PROGRAM MESSAGE UNIT SEPARATOR>*/ -// TODO: static int skipProgramMessageUnitSeparator(lex_state_t * state) +/* TODO: static int skipProgramMessageUnitSeparator(lex_state_t * state) */ /** * Skip all whitespaces @@ -178,10 +178,10 @@ } /* 7.4.2 <PROGRAM DATA SEPARATOR> */ -// static int skipProgramDataSeparator(lex_state_t * state) +/* static int skipProgramDataSeparator(lex_state_t * state) */ /* 7.5.2 <PROGRAM MESSAGE TERMINATOR> */ -// static int skipProgramMessageTerminator(lex_state_t * state) +/* static int skipProgramMessageTerminator(lex_state_t * state) */ /** * Skip decimal digit @@ -189,7 +189,7 @@ * @return */ static int skipDigit(lex_state_t * state) { - if (!iseos(state) && isdigit(state->pos[0])) { + if (!iseos(state) && isdigit((uint8_t)(state->pos[0]))) { state->pos++; return SKIP_OK; } else { @@ -204,7 +204,7 @@ */ static int skipNumbers(lex_state_t * state) { int someNumbers = 0; - while (!iseos(state) && isdigit(state->pos[0])) { + while (!iseos(state) && isdigit((uint8_t)(state->pos[0]))) { state->pos++; someNumbers++; } @@ -232,7 +232,7 @@ */ static int skipAlpha(lex_state_t * state) { int someLetters = 0; - while (!iseos(state) && isalpha(state->pos[0])) { + while (!iseos(state) && isalpha((uint8_t)(state->pos[0]))) { state->pos++; someLetters++; } @@ -305,9 +305,9 @@ */ static int skipProgramMnemonic(lex_state_t * state) { const char * startPos = state->pos; - if (!iseos(state) && isalpha(state->pos[0])) { + if (!iseos(state) && isalpha((uint8_t)(state->pos[0]))) { state->pos++; - while (!iseos(state) && (isalnum(state->pos[0]) || ischr(state, '_'))) { + while (!iseos(state) && (isalnum((uint8_t)(state->pos[0])) || ischr(state, '_'))) { state->pos++; } } @@ -451,9 +451,9 @@ int scpiLex_CharacterProgramData(lex_state_t * state, scpi_token_t * token) { token->ptr = state->pos; - if (!iseos(state) && isalpha(state->pos[0])) { + if (!iseos(state) && isalpha((uint8_t)(state->pos[0]))) { state->pos++; - while (!iseos(state) && (isalnum(state->pos[0]) || ischr(state, '_'))) { + while (!iseos(state) && (isalnum((uint8_t)(state->pos[0])) || ischr(state, '_'))) { state->pos++; } } @@ -535,7 +535,7 @@ skipChr(state, '/'); - // TODO: strict parsing : SLASH? (ALPHA+ (MINUS? DIGIT)?) ((SLASH | DOT) (ALPHA+ (MINUS? DIGIT)?))* + /* TODO: strict parsing : SLASH? (ALPHA+ (MINUS? DIGIT)?) ((SLASH | DOT) (ALPHA+ (MINUS? DIGIT)?))* */ if (skipAlpha(state)) { skipChr(state, '-'); skipDigit(state); @@ -562,7 +562,7 @@ /* 7.7.4 <NONDECIMAL NUMERIC PROGRAM DATA> */ static int skipHexNum(lex_state_t * state) { int someNumbers = 0; - while (!iseos(state) && isxdigit(state->pos[0])) { + while (!iseos(state) && isxdigit((uint8_t)(state->pos[0]))) { state->pos++; someNumbers++; } @@ -615,7 +615,7 @@ } if (someNumbers) { - token->ptr += 2; // ignore number prefix + token->ptr += 2; /* ignore number prefix */ token->len = state->pos - token->ptr; } else { token->type = SCPI_TOKEN_UNKNOWN; @@ -692,8 +692,8 @@ token->len = state->pos - token->ptr; if ((token->len > 0)) { - //token->ptr++; - //token->len -= 2; + /* token->ptr++; + * token->len -= 2; */ } else { token->type = SCPI_TOKEN_UNKNOWN; state->pos = token->ptr; @@ -728,7 +728,7 @@ state->pos++; for (; i > 0; i--) { - if (!iseos(state) && isdigit(state->pos[0])) { + if (!iseos(state) && isdigit((uint8_t)(state->pos[0]))) { arbitraryBlockLength *= 10; arbitraryBlockLength += (state->pos[0] - '0'); state->pos++; @@ -743,6 +743,8 @@ token->ptr = state->pos - arbitraryBlockLength; token->len = arbitraryBlockLength; validData = 1; + } else { + validData = 0; } } else if (iseos(state)) { validData = 0; @@ -753,15 +755,15 @@ } if (validData == 1) { - // valid + /* valid */ token->type = SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA; } else if (validData == 0) { - // incomplete + /* incomplete */ token->type = SCPI_TOKEN_UNKNOWN; token->len = 0; state->pos = state->buffer + state->len; } else { - // invalid + /* invalid */ token->type = SCPI_TOKEN_UNKNOWN; state->pos = token->ptr; token->len = 0; @@ -792,7 +794,7 @@ } } -// TODO: 7.7.7.2-2 recursive - any program data +/* TODO: 7.7.7.2-2 recursive - any program data */ /** * Detect token Expression -- Gitblit v1.9.1