sps.c
State selectCoords_cmd(Context ctx) {
    if (ctx.argStr[0] != '[')
        return ERR_BAD_SYNTAX;

    const unsigned MAX_NUM = 4;
    unsigned numValues = 0;
    unsigned values[MAX_NUM];

    // shift for '[' at the beginning
    unsigned strIndex = 1;
    while (numValues < MAX_NUM) {
        if (ctx.argStr[strIndex] == '_') {
            values[numValues] = 0;
            strIndex += 1;
        } else {
            char *endPtr;
            values[numValues] = (unsigned)strtol(&ctx.argStr[strIndex], &endPtr, 10);
            int shift = endPtr - &ctx.argStr[strIndex];

            if (shift == 0)
                return ERR_BAD_SYNTAX;

            strIndex += shift;
        }
        numValues++;

        if (ctx.argStr[strIndex] == ',') {
            strIndex++;
            continue;
        }

        if (ctx.argStr[strIndex] == ']')
            break;

        return ERR_BAD_SYNTAX;
    }

    if (numValues == 2)
        return selectCell(ctx.table, values[0], values[1]);

    if (numValues == 4)
        return selectRectangle(ctx.table, values[0], values[1], values[2], values[3]);

    return ERR_BAD_SYNTAX;
}
// Command to select cells from coordinates
Command to select cells from coordinates
Command to select cells from coordinates
State selectCoords_cmd(Context ctx) {
    if (ctx.argStr[0] != '[')
        return ERR_BAD_SYNTAX;
    const unsigned MAX_NUM = 4;
    unsigned numValues = 0;
    unsigned values[MAX_NUM];
    unsigned strIndex = 1;
    while (numValues < MAX_NUM) {
        if (ctx.argStr[strIndex] == '_') {
            values[numValues] = 0;
            strIndex += 1;
        } else {
            char *endPtr;
            values[numValues] = (unsigned)strtol(&ctx.argStr[strIndex], &endPtr, 10);
            int shift = endPtr - &ctx.argStr[strIndex];
            if (shift == 0)
                return ERR_BAD_SYNTAX;
            strIndex += shift;
        }
        numValues++;
        if (ctx.argStr[strIndex] == ',') {
            strIndex++;
            continue;
        }
        if (ctx.argStr[strIndex] == ']')
            break;
        return ERR_BAD_SYNTAX;
    }
    if (numValues == 2)
        return selectCell(ctx.table, values[0], values[1]);
    if (numValues == 4)
        return selectRectangle(ctx.table, values[0], values[1], values[2], values[3]);
    return ERR_BAD_SYNTAX;
}
State selectCoords_cmd ( Context ctx ) { if ( ctx . argStr [ 0 ] != ' ' ) return ERR_BAD_SYNTAX ; const unsigned MAX_NUM = 4 ; unsigned numValues = 0 ; unsigned values [ MAX_NUM ] ; unsigned strIndex = 1 ; while ( numValues < MAX_NUM ) { if ( ctx . argStr [ strIndex ] == ' ' ) { values [ numValues ] = 0 ; strIndex += 1 ; } else { char * endPtr ; values [ numValues ] = ( unsigned ) strtol ( & ctx . argStr [ strIndex ] , & endPtr , 10 ) ; int shift = endPtr - & ctx . argStr [ strIndex ] ; if ( shift == 0 ) return ERR_BAD_SYNTAX ; strIndex += shift ; } numValues ++ ; if ( ctx . argStr [ strIndex ] == ' ' ) { strIndex ++ ; continue ; } if ( ctx . argStr [ strIndex ] == ' ' ) break ; return ERR_BAD_SYNTAX ; } if ( numValues == 2 ) return selectCell ( ctx . table , values [ 0 ] , values [ 1 ] ) ; if ( numValues == 4 ) return selectRectangle ( ctx . table , values [ 0 ] , values [ 1 ] , values [ 2 ] , values [ 3 ] ) ; return ERR_BAD_SYNTAX ; }
Command to select cells from coordinates
Command to select cells from coordinates
// shift for '[' at the beginning