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

#if @HELP_MACLIST

    MACLIST

    Purpose: Returns a delimited list of the loaded macros.

    Syntax:  MACLIST("separator", all)

               "separator" - Optional. A string, the delimiter used to
                             separate macros names in the list. Defaults
                             to "," the comma delimiter.

                       all - Optional. An integer, the type flag.
                           
                                 0: show normal macros (default)
                                 1: show hidden and normal macros

    Returns: A sorted string of the currently loaded macros.

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

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

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

             Displays the loaded macros in a pop-up box.

    Remarks:
             MACLIST returns an alphabetically sorted list of the loaded
             macros by writing the macros to a temporary file
             and converting the file to a string.

    See Also:
             Objectlist
             Spllist
             Splwrite
             Strsort
             Strfile
             Varlist
#endif


/* get separated list of loaded macros */
maclist(separator, all)
{
        local list;

        if (argc < 2)
        {
                if (argc < 1)
                {
                        separator = ",";
                }

                if (isscalar(separator))
                {
                        all = separator;
                        separator = ",";
                }
                else
                {
                        all = 0;
                }
        }

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

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

        return(list);
}