How to implement a 2D lookup table?
I suggest you turn this into a simple 1D table by using two different
separators, for example ‘:’ between joint and direction, and ‘,’ between
consecutive movements. Then, instead of “B,CCW,S,CW” you would type
“B:CCW,S:CW”. For parsing the string, you split at the commas, and
consider the pieces between the commas as single items. In other words,
“B:CCW” would be the name for relay 2, and you do not try to split it
further.

Here is a simple method to map the strings to the relays:

const char * const relay_names[] = {"", "B:CW", "B:CCW", "S:UP",
    "S:DN", "W:CW", "W:CCW", "E:UP", "E:DN", "G:OP", "G:CL"};

// Return the relay number.
int get_relay(const char * name)
{
    for (int i = 1; i &lt;= 10; i++)
        if (strcmp(name, relay_names[i]) == 0)
            return i;
    return -1;  // meaning invalid
}