Annotation of 43BSD/contrib/icon/functions/move.c, revision 1.1.1.1

1.1       root        1: #include "../h/rt.h"
                      2: 
                      3: /*
                      4:  * move(i) - move &pos by i, return substring of &subject spanned.
                      5:  *  Reverses effects if resumed.
                      6:  */
                      7: Xmove(nargs, oldsubj, arg1, arg0)
                      8: int nargs;
                      9: struct descrip oldsubj, arg1, arg0;
                     10:    {
                     11:    register int i, j;
                     12:    long l;
                     13:    int oldpos;
                     14: 
                     15:    /*
                     16:     * i must be a (non-long) integer.
                     17:     */
                     18:    switch (cvint(&arg1, &l)) {
                     19:       case T_INTEGER:  j = (int)l; break;
                     20: #ifdef LONGS
                     21:       case T_LONGINT:  fail();
                     22: #endif LONGS
                     23:       default:         runerr(101, &arg1);
                     24:       }
                     25: 
                     26:    /*
                     27:     * Save old &subject and &pos.  Local variable i holds &pos
                     28:     *  before the move.
                     29:     */
                     30:    oldsubj = k_subject;
                     31:    oldpos = i = k_pos;
                     32: 
                     33:    /*
                     34:     * If attempted move is past either end of the string, fail.
                     35:     */
                     36:    if (i + j <= 0 || i + j > STRLEN(k_subject) + 1)
                     37:       fail();
                     38: 
                     39:    /*
                     40:     * Set new &pos.
                     41:     */
                     42:    k_pos += j;
                     43: 
                     44:    /*
                     45:     * Make sure j >= 0.
                     46:     */
                     47:    if (j < 0) {
                     48:       i += j;
                     49:       j = -j;
                     50:       }
                     51: 
                     52:    /*
                     53:     * Suspend substring of &subject that was moved over.
                     54:     */
                     55:    STRLEN(arg0) = j;
                     56:    STRLOC(arg0) = STRLOC(k_subject) + i - 1;
                     57:    suspend();
                     58: 
                     59:    /*
                     60:     * If move is resumed, restore the old subject and position
                     61:     *  and fail.
                     62:     */
                     63:    k_subject = oldsubj;
                     64:    k_pos = oldpos;
                     65:    fail();
                     66:    }
                     67: 
                     68: Procblock(move,2)

unix.superglobalmegacorp.com

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