View Raw SPL
/*****************************************************************************
*                                                                            *
*   UNPROTECTWIN.SPL Copyright (C) 2009-2010 DSP Development Corporation     *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:         Randy Race                                               *
*                                                                            *
*   Synopsis:       Unprotects a previously protected Window                 *
*                                                                            *
*   Revisions:      23 Jun 2009  RRR  Creation - from MISC.MAC               *
*                   15 Feb 2010  RRR  multiple windows                       *
*                                                                            *
*****************************************************************************/

#include 


#if @HELP_UNPROTECTWIN

    UNPROTECTWIN

    Purpose: Unprotects a previously protected Window.

    Syntax:  UNPROTECTWIN(win)

                win - Optional, one or more Windows. The Windows to unprotect. 
                      Defaults to the current Window.

    Returns: Nothing, the Windows are unprotected and the original Window
             formula and Window dependencies are re-established.

    Example:
             W1: gnorm(1000, 1)
             W2: integ(w1)
             protectwin(W2)

             W1 contains 1000 samples of random noise and W2 performs an
             integration of the noise. W2 is protected such that if W1
             changes, W2 no longer updates. The formula for W2 becomes:

             Protected: integ(w1)

    Example:
             unprotectwin(w2)

             Re-establishes the original formula and allows W2 to update
             when W1 changes.

    Remarks:
             A protected Window is removed from the dependency list so that
             it is no longer dependent on any Window.

             Unlike PROTECT, PROTECTWIN protects a window such that
             UNPROTECTWIN will unprotect the Window with the original
             formula and dependencies.

             Use PROTECTWIN to remove Window dependencies such that
             UNPROTECTWIN can restore them.

    See Also:
             Protect
             Unprotectwin
             Winlock
#endif



/* unprotect previously protected windows */
unprotectwin(argv)
{
        local i, win;

        if (argc < 1)
        {
                unprotectwin_unprotect(refwin(w0));
        }
        else
        {
                loop (i = 1..argc)
                {
                        win = getargv(i);
                        unprotectwin_unprotect(win);
                }
        }
}


/* restore the window formula */
unprotectwin_unprotect(win)
{
        local f, p;

        if (iswindow(win))
        {
                /* formula */
                f = getwform(win);
                
                /* check for "Protected: " string */
                p = strextract(f, 1, 11);
                
                if (p == "Protected: ")
                {
                        /* get original formula and set */
                        f = strextract(f, 12, -1);
                        setwform(win, f);
                }
        }
}