View Raw SPL
/*****************************************************************************
*                                                                            *
*   SPLLIST.SPL  Copyright (C) 2015 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Returns a delimited string of the loaded SPL functions      *
*                                                                            *
*   Revisions:   23 Apr 2015  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#if @HELP_SPLLIST

    SPLLIST

    Purpose: Returns a delimited list of the loaded SPL functions.

    Syntax:  SPLLIST("separator", all, path, tabsize, tabchar)

               "separator" - Optional. A string, the delimiter used to
                             separate SPL names in the list. Defaults
                             to "," the comma delimiter.
  
                       all - Optional. An integer, the type flag.
                           
                                 0: show normal SPL functions (default)
                                 1: show hidden and normal SPL functions

                      path  - Optional. An integer, include the full path
                              to the SPL.

                                 0: no path (default)
                                 1: include full path

                    tabsize  - Optional. An integer, the number of TABCHARs
                               used to delimit the SPL path. Defaults to
                               -1, automatic.

                    tabchar  - Optional. A string, the character used to delimit
                               the SPL path. Defaults to " ", the space
                               character.
    
    Returns: A sorted string of the currently loaded SPL routines.

    Example:
             s = spllist();
             t = strget(1, s, ",");

             Variable S contains the comma separated SPL list and T contains
             the first function name in the list.

    Example:
             viewtext(spllist(strescape("\n")));

             Displays the loaded functions in a pop-up box.

    Example:
             viewtext(spllist(strescape("\n"), 0, 1));

             Same as above except the full path to each SPL is included.
             The paths are demlited with spaces.

    Example:
             viewtext(spllist(strescape("\n"), 0, 1, -1, "#"));

             Same as above except the paths are delimited with the #
             character.

    Remarks:
             SPLLIST returns an alphabetically sorted list of the loaded
             SPL functions.

             SPLLIST itself is necessarily included in the list.

    See Also:
             Maclist
             Objectlist
             Splwrite
             Strsort
             Strfile
             Varlist
#endif


/* get separated list of loaded SPL routines */
spllist(separator = ",", all = 0, path = 0, tabsize = -1, tabchar = " ")
{
        local list;

        if (not(isscalar(all)) || not(isscalar(path)) || not(isscalar(tabsize)))
        {
                error(sprintf("%s - integer expected", __FUNC__));
        }

        list = objectlist(9, 0, 1, all);

        if (path)
        {
                /* get paths for SPLs */
                list = spllist_paths(list, tabsize, tabchar);
        }

        if (strescape(separator) != strescape("\n"))
        {
                list = strrep(list, strescape("\n"), strescape(separator));
        }

        return(list);
}


/* gets paths for SPLs */
spllist_paths(list, tabsize, tabchar)
{
        local j = 1, plist = "", str, spl, k, slen;

        tabsize = (tabsize < 0) ? spllist_maxlen(list) + 4 : tabsize;

        do 
        {
                spl = strget(j, list, strescape("\n"));

                if (strlen(spl) == 0)
                {
                        break;
                }

                str = spl;

                slen = tabsize - strlen(str);

                loop (k = 1..slen)
                {
                        str += tabchar;
                }

                plist += str;

                str = which(spl, 0);

                plist += str + strescape("\n");
                
                j++;
        }
        while (1);

        return(plist);
}


/* maximum length of \n delimited list */
spllist_maxlen(list)
{
        local j = 1, maxlen = 0, len, str;

        do
        {
                str = strget(j, list, strescape("\n"));

                if ((len = strlen(str)) == 0)
                {
                        break;
                }

                maxlen = max(maxlen, len);

                j++;

        }
        while(1);

        return(maxlen);
}