View Raw SPL
/*****************************************************************************
*                                                                            *
*   CURLOCSET.SPL  Copyright (C) 2013 DSP Development Corporation            *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Sets cursor locations based on a source window              *
*                                                                            *
*   Revisions:   17 Oct 2013  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#if @HELP_CURLOCSET

    CURLOCSET

    Purpose: Sets cursor locations of one or more windows based on a source window.

    Syntax:  CURLOCSET(srcwin, deswin1, deswin2, ..., deswinN)

               srcwin  - A window. The source window to obtain the X indices
                         of the first and second cursors.

               deswinN - Optional, zero or more Windows. The target windows.
                         If not specified, defaults to the current window.

    Returns: Nothing, the X locations of cursor 1 and cursor 2 of each
             destination window is set to the locations of the source window.
             
    Example:
             W1: integ(gnorm(1000, 1/1000));curput(0.4);curput(0.6, 2)
             W2: integ(gnorm(1000, 1/1000));curlocset(w1)

             W1 contains 1000 point random series. The first cursor
             location of W1 is set to 0.4 and the second cursor
             location is set to 0.6. W2 contains a 1000 point random
             series where the location of cursor 1 is set to 0.4 and
             the location of cursor 2 is set to 0.6.

    Example:
             W1: integ(gnorm(1000, 1/1000));curput(0.1);curput(0.9, 2)
             W2: integ(gnorm(1000, 1/1000))
             W3: integ(gnorm(1000, 1/1000))
        
             curlocset(w1, w2, w3)

             W1 through W3 contain 1000 point random series.  The first
             cursor location of W1 is set to 0.1 and the second cursor
             location is set to 0.9.  The cursor locations of W2 and W3
             are set to 0.1 and 0.9.

    Remarks:
             If no target window is specified, the cursor locations of the
             current window are set to the source window.

             See CURPOSSET to set the index positions of cursors based on a
             source window.

             See CURXEXTRACT to extract multiple windows based on the
             X locations of the source window cursor position.

    See Also:
             Curposset
             Curput
             Curloc
             Curxextract
#endif


/* set cursor location based on a source window */
curlocset(srcwin, argv)
{
        local loc1, loc2, cnt, i, deswin;

        if (argc < 1)
        {
                error("curlocset - source window required");
        }

        if (not(iswindow(srcwin)))
        {
                error("curlocset - source window required");
        }

        /* source cursor location */
        loc1 = curloc(srcwin, 1, 1);
        loc2 = curloc(srcwin, 1, 2);

        /* variable arg count */
        cnt = argc - 1;

        /* set target window cursor locations */
        if (cnt > 0)
        {
                loop (i = 1..cnt)
                {
                        deswin = getargv(i);

                        if (iswindow(deswin))
                        {
                                /* set destination cursor positions */
                                curput(deswin, loc1, 1, 1);
                                curput(deswin, loc2, 2, 1);
                        }
                }
        }
        else
        {
                /* set current window cursor positions */
                curput(w0, loc1, 1, 1);
                curput(w0, loc2, 2, 1);
        }
}