Annotation of researchv9/jtools/src/pads/x11/lib.c, revision 1.1

1.1     ! root        1: #include "univ.h"
        !             2: 
        !             3: waitMOUSE() { wait(MOUSE); }
        !             4: 
        !             5: char *itoa(n)
        !             6: register n;
        !             7: {
        !             8:        register char *pic = " [-][0-9]* ";
        !             9:        char cip[10];
        !            10:        register char *p = pic, *c;
        !            11: 
        !            12:        *p++ = ' ';
        !            13:        if( n < 0 ) *p++ = '-', n = -n;
        !            14:        *(c = &cip[0]) = '\0';
        !            15:        do {
        !            16:                *++c = "0123456789"[n%10];
        !            17:        } while( n = n/10 );
        !            18:        while( *c ) *p++ = *c--;
        !            19:        *p++ = ' ';
        !            20:        *p = '\0';
        !            21:        return pic;
        !            22: }
        !            23:        
        !            24: dictorder(a,b)
        !            25: register char *a, *b;
        !            26: {
        !            27:        register disc;
        !            28: 
        !            29:        for( ;; ){
        !            30:                if( !*a ) return 1;
        !            31:                if( !*b ) return 0;
        !            32:                if( disc = (*a++|' ')-(*b++|' ') ) return disc<0;
        !            33:        }
        !            34: }
        !            35: #ifdef ASSERT
        !            36: long assertf(l)
        !            37: long l;
        !            38: {
        !            39:        if( l ) return l;
        !            40:        rectf( &display, display.rect, F_XOR );
        !            41:        for( ;; ) pause();
        !            42: }
        !            43: #endif
        !            44: 
        !            45: outline( b, r )
        !            46: register Bitmap *b;
        !            47: Rectangle r;
        !            48: {
        !            49:        segment( b, r.origin, Pt(r.origin.x,--r.corner.y), F_XOR );
        !            50:        segment( b, Pt(--r.corner.x,r.origin.y), r.origin, F_XOR );
        !            51:        segment( b, Pt(r.origin.x,r.corner.y), r.corner, F_XOR );
        !            52:        segment( b, r.corner, Pt(r.corner.x,r.origin.y), F_XOR );
        !            53: }
        !            54: 
        !            55: Rectangle boundrect( q, r )
        !            56: Rectangle q, r;
        !            57: {
        !            58:        q.origin.x = min( q.origin.x, r.origin.x );
        !            59:        q.origin.y = min( q.origin.y, r.origin.y );
        !            60:        q.corner.x = max( q.corner.x, r.corner.x );
        !            61:        q.corner.y = max( q.corner.y, r.corner.y );
        !            62:        return q;
        !            63: }
        !            64: 
        !            65: Rectangle scrollbar( r, from, to, lo, hi )
        !            66: Rectangle r;
        !            67: {
        !            68:        register short rh = r.corner.y - r.origin.y, h = hi-lo;
        !            69:        
        !            70:        r.corner.y -= muldiv(hi-to,rh,h);
        !            71:        r.origin.y += muldiv(from-lo,rh,h);
        !            72:        return r;
        !            73: }
        !            74: 
        !            75: rectinrect( r, s )
        !            76: Rectangle r, s;
        !            77: {
        !            78:        Rectangle clipped;
        !            79: 
        !            80:        clipped = r;
        !            81:        return rectclip(&clipped,s) && eqrect(r, clipped);
        !            82: }
        !            83: 
        !            84: char *FreeSome = "out of terminal memory";
        !            85: 
        !            86: char *Alloc(n)
        !            87: {
        !            88:        char *a;
        !            89: 
        !            90:        if( !(a = alloc(n)) ){
        !            91:                cursswitch( &NoMemory );
        !            92:                InvertKBDrect( FreeSome, "" );
        !            93:                sleep(30);
        !            94:                exit(1);
        !            95:        }
        !            96:        return a;
        !            97: }
        !            98: 
        !            99: char *GCAlloc(n,p)
        !           100: register char **p;
        !           101: {
        !           102:        register unsigned long nbytes = n;
        !           103:        if( !(gcalloc(nbytes, p)) ){
        !           104:                cursswitch( &NoGCMemory );
        !           105:                InvertKBDrect( FreeSome, "" );
        !           106:                sleep(30);
        !           107:                exit(1);
        !           108:        }
        !           109:        while( nbytes>0 ) (*p)[--nbytes] = 0;
        !           110:        return *p;
        !           111: }
        !           112: 
        !           113: GCString( p, s )
        !           114: char **p, *s;
        !           115: {
        !           116:        *p = GCAlloc( strlen(s)+1, p );
        !           117:        strcpy( *p, s );
        !           118: }
        !           119: 
        !           120: Rectangle moverect(source,bound)
        !           121: Rectangle source, bound;
        !           122: {
        !           123:        Rectangle target;
        !           124:        Point base, track;
        !           125:        int b = butts;
        !           126: 
        !           127:        base = mouse.xy;
        !           128:        bound.origin.x += base.x - source.origin.x;
        !           129:        bound.origin.y += base.y - source.origin.y;
        !           130:        bound.corner.x += base.x - source.corner.x;
        !           131:        bound.corner.y += base.y - source.corner.y;
        !           132:        do {
        !           133:                track = mouse.xy;
        !           134:                if( track.x < bound.origin.x ) track.x = bound.origin.x;
        !           135:                if( track.y < bound.origin.y ) track.y = bound.origin.y;
        !           136:                if( track.x > bound.corner.x ) track.x = bound.corner.x;
        !           137:                if( track.y > bound.corner.y ) track.y = bound.corner.y;
        !           138:                outline( &display, target = raddp( source, sub(track,base) ) ); 
        !           139:                jnap(2);
        !           140:                outline( &display, target );
        !           141:        } while( butts == b );
        !           142:        return butts ? source : target;
        !           143: }

unix.superglobalmegacorp.com

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