mbed2 zad 5b
Dependencies: LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI
Diff: Dekodowanie/Tokeny/Tokeny.cpp
- Revision:
- 5:cafab5a4d1c9
- Parent:
- 4:7855d3ab4c15
diff -r 7855d3ab4c15 -r cafab5a4d1c9 Dekodowanie/Tokeny/Tokeny.cpp --- a/Dekodowanie/Tokeny/Tokeny.cpp Mon Jun 08 21:49:36 2020 +0000 +++ b/Dekodowanie/Tokeny/Tokeny.cpp Tue Jun 09 12:30:01 2020 +0000 @@ -6,7 +6,7 @@ extern struct Token asToken[MAX_TOKEN_NR]; extern struct Keyword asKeywordList[MAX_KEYWORD_NR]; - +/* void ReplaceCharactersInString(char pcString[], char cOldChar, char cNewChar) { char *pcStringCharacters = pcString; @@ -18,26 +18,26 @@ } } + enum Result eHexStringToUInt(char pcStr[], unsigned int *puiValue) { - char *pcEnd; unsigned char ucCharCounter; - if((strncmp(pcStr, "0x", 2) != 0) ||(strlen(pcStr)) != 6) + if((strncmp(pcStr, "0x", 2) != 0) || (strlen(pcStr)) != 6) { return ERROR; } - for(ucCharCounter = 2; pcStr[ucCharCounter] != NULL; ucCharCounter++) + for(ucCharCounter = 2; ucCharCounter < 6; ucCharCounter++) { if((strncmp(pcStr+ucCharCounter, "0", 1) < 0) || (strncmp(pcStr+ucCharCounter, "F", 1) > 0) || ((strncmp(pcStr+ucCharCounter, "9", 1) > 0) && (strncmp(pcStr+ucCharCounter, "A", 1) < 0))) { return ERROR; } } - *puiValue = strtol(pcStr, &pcEnd, 0); + *puiValue = strtol(pcStr, NULL, 0); return OK; } - +*/ unsigned char ucFindTokensInString (char *pcString) { char *pcTokenStart = pcString; @@ -71,6 +71,7 @@ void DecodeTokens(void) { + unsigned int uiTokenNumber; unsigned char ucTokenListCounter; struct Token *TokenValue; @@ -81,9 +82,11 @@ { TokenValue->eType = KEYWORD; } - else if( eHexStringToUInt(TokenValue->uValue.pcString, &TokenValue->uValue.uiNumber) == OK ) + else if (sscanf(asToken[ucTokenListCounter].uValue.pcString, "%4x", &uiTokenNumber) == 1) + //else if( eHexStringToUInt(TokenValue->uValue.pcString, &TokenValue->uValue.uiNumber) == OK ) { TokenValue->eType = NUMBER; + TokenValue->uValue.uiNumber = uiTokenNumber; } else {