View Raw SPL
/* is string a window range, e.g. w3..w7 */
static _getwinlist_iswinrange(str)
{
        local r, s1, s2, status = 0;

        /* check range spec */
        r = strfind("..", str);

        if (strlen(r) > 0)
        {
                /* check if window refs */
                s1 = strget(1, str, "..");
                s2 = strget(2, str, "..");

                status += _getwinlist_str_is_win(s1);
                status += _getwinlist_str_is_win(s2);
        }

        return(status);
}


/* is string a window? */
static _getwinlist_str_is_win(str)
{
        local s, v = 0;

        if (strlen(str) > 0)
        {
                if (strlen(strfind(":", str)) == 0 && strlen(strfind("=", str)) == 0)
                {
                        s = sprintf("iswindow(%s)", str);
                        v = eval(s);
                }
        }

        return(v);
}


static _getwinlist_str_is_win_error()
{
        return(0);
}


static _getwinlist_isdigit(s)
{
        local status;
        static digits = charstrs("0123456789");

        status = length(find(charstr(s) == digits)) > 0;

        return(status);
}


/* extract window names */
_getwinlist(s, wlist, rawstr)
{
        local list, wstr, fstr, i, idx, len;

        list = "";
        i = 1;

        if (argc < 3) rawstr = 0;

        if (strlen(strfind("W", s)) > 0)
        {
                if (strlen(strfind(":", s)) > 0)
                {
                        /* window labels in editbox */
                        fstr = strrev(s);

                        while (1) 
                        {
                                /* formula with window number */
                                if (strlen(fstr) == 0) break;

                                wstr = strfind(" :", fstr);

                                if (strlen(wstr) == 0)
                                {
                                        wstr = strget(i, s, ",");
                                }
                                else
                                {
                                        fstr = strfind(",", wstr);
                                        wstr = strget(1, wstr, ",");
                                }

                                if (strlen(wstr) == 0) break;

                                idx  = castint(wstr);
                                wstr = sprintf("W%d", idx);

                                if (strlen(list) > 0) list += ",";

                                list += wstr;

                                i++;
                        }
                }
                else
                {
                        list = s;
                }
        }
        else 
        {
                /* numeric or no labels */
                while (1) 
                {
                        /* ith window number */
                        wstr = strget(i, s, ",");
                        if (strlen(wstr) == 0) break;

                        if (not(_getwinlist_iswinrange(wstr)))
                        {
                                if (_getwinlist_isdigit(wstr))
                                {
                                        idx = castint(wstr);

                                        /* window number */
                                        wstr = sprintf("w%d", idx);
                                }
                                else if (rawstr)
                                {
                                        list = s;
                                        break;
                                }
                        }

                        if (strlen(wstr) == 0) break;

                        if (strlen(list) > 0) list += ",";

                        list += wstr;
                        i++;
                }
        }

        return(list);
}