Annotation of 43BSD/contrib/icon/lib/escan.c, revision 1.1

1.1     ! root        1: #include "../h/rt.h"
        !             2: 
        !             3: /*
        !             4:  * escan - restore &subject and &pos at the end of a scanning expression.
        !             5:  *
        !             6:  *  Arguments:
        !             7:  *    arg1 - value being scanned
        !             8:  *    arg2 - old value of &subject
        !             9:  *    arg3 - old value of &pos
        !            10:  *    arg4 - result of the scanning expression
        !            11:  *
        !            12:  * The result of the scanning expression is dereferenced if it refers to &subject
        !            13:  *  or &pos, then copied to the first argument (the last three will
        !            14:  *  be popped when escan returns).  Then the previous values of &subject
        !            15:  *  and &pos are restored.
        !            16:  *
        !            17:  * Escan suspends once it has restored the old &subject; on failure
        !            18:  *  the new &subject and &pos are "unrestored", and the failure is
        !            19:  *  propagated into the using clause.
        !            20:  */
        !            21: 
        !            22: escan(nargs, arg4, arg3, arg2, arg1)
        !            23: int nargs;
        !            24: struct descrip arg4, arg3, arg2, arg1;
        !            25:    {
        !            26:    DclSave
        !            27:    struct descrip tmp;
        !            28: 
        !            29:    SetBound;
        !            30: 
        !            31:    /*
        !            32:     * If the result of the scanning expression is &subject or &pos,
        !            33:     *  it is dereferenced.
        !            34:     */
        !            35:    if (arg4.type == D_VAR && (int)BLKLOC(arg1) == (int)&k_subject)
        !            36:       DeRef(arg4)
        !            37:    if (arg4.type == D_TVPOS)
        !            38:       DeRef(arg4)
        !            39: 
        !            40:    /*
        !            41:     * Copy the result of the scanning expression into arg1, which will
        !            42:     *  be the result of the scan.
        !            43:     */
        !            44:    arg1 = arg4;
        !            45: 
        !            46:    /*
        !            47:     * Swap new and old values of &subject, leaving the new value in arg2.
        !            48:     */
        !            49:    tmp = k_subject;
        !            50:    k_subject = arg2;
        !            51:    arg2 = tmp;
        !            52: 
        !            53:    /*
        !            54:     * Swap new and old values of &pos, leaving the new value in arg3.
        !            55:     */
        !            56:    tmp = arg3;
        !            57:    INTVAL(arg3) = k_pos;
        !            58:    k_pos = INTVAL(tmp);
        !            59: 
        !            60:    /*
        !            61:     * Suspend the value of the scanning expression.
        !            62:     */
        !            63:    suspend();
        !            64: 
        !            65:    /*
        !            66:     * Upon resumption, restore the new values for &subject and &pos
        !            67:     *  and fail.
        !            68:     */
        !            69:    k_subject = arg2;
        !            70:    k_pos = INTVAL(arg3);
        !            71: 
        !            72:    fail();
        !            73:    }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.