parseSuffix.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // =================================================================================================================
  2. // @parseSuffix
  3. // "Parser-function", parses a SCPI Suffix Program Data (<SUFFIX PROGRAM DATA>)
  4. // References:
  5. // "7.7.3 <SUFFIX PROGRAM DATA>", [1]
  6. // "7.7.3.2 Encoding Syntax", [1]
  7. // Parameters:
  8. // @xObj - parser context, must be prepared by @prepareParserContext
  9. // ... before each call. If it is needed to continue the processing, the
  10. // ... @bKeepContext parameter duing the call @prepareParserContext must
  11. // ... be set to 'true', and otherwise, to restart parsing the parameter
  12. // ... must be set to 'false'.
  13. // Returns:
  14. // eParserStatus_failed - error, can not parse data as a string;
  15. // eParserStatus_success - success, the string has been successfully parsed;
  16. // eParserStatus_need_data - warning, the string can not be parsed due to
  17. // there no enough data to process.
  18. eParserStatus_t parseSuffix( xParseEntry_t * xObj )
  19. {
  20. sParseEntry_t * pObj = (sParseEntry_t*)xObj;
  21. eParserStatus_t status = eParserStatus_invalid;
  22. if( NULL != pObj && NULL != pObj->str && 0 != ((ptrdiff_t)pObj->tail - (ptrdiff_t)pObj->head)
  23. && pObj->str != pObj->tail )
  24. {
  25. status = eParserStatus_need_data; // forward status set: the default 'eParserStatus_invalid' shall
  26. // ... not be returned due to the context will be changed.
  27. // if the context has been cleaned up
  28. if( ! pObj->bContextKept )
  29. {
  30. pObj->parseSuffix.whiteAllowed = true; // enable white-character by default
  31. }
  32. // walk til the end of the buffer
  33. while( pObj->str != pObj->tail )
  34. {
  35. char character = *(pObj->str++);
  36. // Check if the white-character is allowed in current state:
  37. if( pObj->parseDemicalNumber.whiteAllowed )
  38. {
  39. // Check if the character is a white-character:
  40. if( scpi_iswhite( character ) )
  41. {
  42. // skip character
  43. continue;
  44. }
  45. }
  46. }
  47. }
  48. return status;
  49. }