Technical information
RMS NetLinx Virtual Device API
125
RMS Enterprise - NetLinx Programmer’s Guide
RMS Command Escaping Functions (Cont.)
RmsParseCmdParam
Ex
Description: Use this function to parse out parameters from module SEND_COMMAND or
SEND_STRING. Parses the strings sent to or from modules extracting the parameters.
• A single param is picked of the cmd string and removed, through the separator.
• The separator is NOT returned from the function.
• If the first character of the param is a double quote, the function will remove up to (and including) the
next double-quote and the separator without spaces.
• The double quotes will then be stripped from the parameter before it is returned.
• If the double-quote/separator sequence is not found, the function will remove up to (and including) the
separator character and the leading double quote will NOT be removed.
• If the separator is not found, the entire remained of the command is removed.
Parameters:
• (1) IN/OUT - sndcmd/str data
• (2) SEPARATOR - delimiting character
Returns: Parse parameter from the front of the string not including the separator.
Syntax:
DEFINE_FUNCTION CHAR[RMS_MAX_PARAM_LEN] RmsParseCmdParamEx(CHAR cCmd[], CHAR separator)
{
STACK_VAR CHAR cTemp[RMS_MAX_PARAM_LEN]
STACK_VAR CHAR cSep[1]
STACK_VAR CHAR chC
STACK_VAR INTEGER nLoop
STACK_VAR INTEGER nState
STACK_VAR CHAR bInquotes
STACK_VAR CHAR bDone
cSep[1] = separator;
// Reset state
nState = 1; //ST_START
bInquotes = FALSE;
bDone = FALSE;
// Loop the command and escape it
FOR (nLoop = 1; nLoop <= LENGTH_ARRAY(cCmd); nLoop++)
{
// Grab characters and process it based on state machine
chC = cCmd[nLoop];
Switch (nState)
{
// Start or string: end of string bails us out
CASE 1: //ST_START
{
// Starts with a quote?
// If so, skip it, set flag and move to collect.
IF (chC == '"')
{
nState = 2; //ST_COLLECT
bInquotes = TRUE;
}
// Starts with a separator? Empty param
ELSE IF (chC == cSep)
{
// I am done
bDone = TRUE;
}
// Not a quote or a comma? Add it to the string and move to collection
Else
{
cTemp = "cTemp, chC"
nState = 2; //ST_COLLECT
}
BREAK;
}
// Collect string.