Annotation of researchv9/jtools/src/pads/host/pad.c, revision 1.1.1.1

1.1       root        1: #include <pads.pri>
                      2: SRCFILE("pad.c")
                      3: #include <ctype.h>
                      4: 
                      5: void Pad::makecurrent()        { termop(P_MAKECURRENT); }
                      6: void Pad::clear()      { termop(P_CLEAR); }
                      7: 
                      8: void Pad::alarm(short n)
                      9: {
                     10:        R->pktstart(P_ALARM);
                     11:        R->sendobj( _object );
                     12:        R->sendshort( n );
                     13:        R->pktend();
                     14: }
                     15: 
                     16: Pad::~Pad()            { trace("%d.~Pad()", this); VOK; termop(P_DELETE); }
                     17: int Pad::ok()          { return this!=0; }
                     18: int Line::ok()         { return this!=0; }
                     19: 
                     20: Attrib Implicits(PadRcv *obj)          /* can't inline - C++ bug */
                     21: {
                     22:        Attrib accum = 0;
                     23:        PadRcv padrcv;
                     24: 
                     25:        if( !obj ) return 0;
                     26:        if( &obj->kbd       != &padrcv.kbd       ) accum |= ACCEPT_KBD; // warning
                     27:        if( &obj->userclose != &padrcv.userclose ) accum |= USERCLOSE;  // warning
                     28:        trace( "Implicits(%d,0x%X)", obj, accum );
                     29:        return accum;
                     30: }
                     31: 
                     32: Pad::Pad(PadRcv *o)
                     33: {
                     34:        trace( "%d.Pad(%d)", this, o );         VOK;
                     35:        if( o && !o->isvalid() )
                     36:                PadsWarn( "Pad::Pad: object is not a PadRcv" );
                     37:        _name = "<name>";
                     38:        _banner = "<banner>";
                     39:        _object = o;
                     40:        _attributes = 0;
                     41:        R->pktstart( P_PADDEF );
                     42:        R->sendobj( _object );
                     43:        R->pktend();
                     44:        options( Implicits(_object) );
                     45: }
                     46: 
                     47: void Pad::nameorbanner(Protocol p, PRINTF_ARGS)
                     48: {
                     49:        char *t, **_born = (p==P_BANNER ? &_banner : &_name);
                     50:        trace( "%d.nameorbanner(0x%X,%s) %s", this, p, fmt, *_born );   VOK;
                     51:        t = sf( PRINTF_COPY );
                     52:        if( strcmp( t, *_born ) ){
                     53:                R->pktstart( p );
                     54:                R->sendobj( _object );
                     55:                R->sendstring( *_born = t );
                     56:                R->pktend();
                     57:        }
                     58: }
                     59:        
                     60: void Pad::banner(PRINTF_ARGS)  { nameorbanner(P_BANNER, PRINTF_COPY); }
                     61:        
                     62: void Pad::name(PRINTF_ARGS)    { nameorbanner(P_NAME, PRINTF_COPY); }
                     63: 
                     64: void Pad::tabs(short n)
                     65: {
                     66:        short lo = 1, hi = 127;
                     67: 
                     68:        trace( "%d.tabs(%d)", this, n );        VOK;
                     69:        if( n<lo || n>hi )
                     70:                PadsWarn( "tabs(%d) should be >=%d and <=%d", n, lo, hi );
                     71:        else {
                     72:                R->pktstart( P_TABS );
                     73:                R->sendobj( _object );
                     74:                R->sendshort( n );
                     75:                R->pktend();
                     76:        }
                     77: }
                     78: 
                     79: void Pad::removeline(long k)
                     80: {
                     81:        trace( "%d.removeline(%d)", this, n );          VOK;
                     82:        R->pktstart( P_REMOVELINE );
                     83:        R->sendobj( _object );
                     84:        R->sendlong( k );
                     85:        R->pktend();
                     86: }
                     87:        
                     88: void Pad::createline(long lo, long hi)
                     89: {
                     90:        trace( "%d.createline(%d,%d)", this, lo, hi );          VOK;
                     91:        if( lo>hi ) return;
                     92:        R->pktstart( P_CREATELINE );
                     93:        R->sendobj( _object );
                     94:        R->sendlong( lo );
                     95:        R->sendlong( hi );
                     96:        R->pktend();
                     97: }
                     98:        
                     99: void Pad::createline(long k)
                    100: {
                    101:        createline(k, k);
                    102: }
                    103:        
                    104: void Pad::menu(Index ix)
                    105: {
                    106:        trace( "%d.menu(0x%X)", this, ix.sht() );       VOK;
                    107:        IF_LIVE( !_object ) return;
                    108:        R->pktstart( P_CARTE );
                    109:        R->sendobj( _object );
                    110:        R->sendshort( ix.sht() );
                    111:        R->pktend();
                    112: }
                    113: 
                    114: void Pad::menu(Menu &m)
                    115: {
                    116:        trace( "%d.menu(%d)", this, &m );       VOK;
                    117:        IF_LIVE( !&m ) return;
                    118:        menu(m.index());
                    119: }
                    120: 
                    121: void Pad::options(Attrib on, Attrib off)
                    122: {
                    123:        trace( "%d.options(0x%X,0x%X)", this, on, off );        VOK;
                    124:        _attributes |= on;
                    125:        _attributes &= ~off;
                    126:        R->pktstart( P_ATTRIBUTE );
                    127:        R->sendobj( _object );
                    128:        R->sendshort( _attributes );
                    129:        R->pktend();
                    130: }
                    131: 
                    132: void Pad::lines(long l)
                    133: {
                    134:        trace( "%d.lines(%d)", this, l );               VOK;
                    135:        IF_LIVE( l<0 ) return;
                    136:        R->pktstart( P_LINES );
                    137:        R->sendobj( _object );
                    138:        R->sendlong( _lines = l );
                    139:        R->pktend();
                    140: }      
                    141: 
                    142: void Pad::termop(Protocol p)
                    143: {
                    144:        trace( "%d.termop(%d)", this, p ); VOK;
                    145:        R->pktstart( p );
                    146:        R->sendobj( _object );
                    147:        R->pktend();
                    148: }
                    149: 
                    150: void Pad::insert(long k, PRINTF_ARGS)
                    151:        { insert(k, (Attrib)0, (PadRcv*)0, *(Menu*)0, PRINTF_COPY); }
                    152: 
                    153: void Pad::insert(long k, Attrib a, PRINTF_ARGS)
                    154:        { insert(k, a, (PadRcv*)0, *(Menu*)0, PRINTF_COPY); }
                    155: 
                    156: void Pad::insert(long k, Attrib a, PadRcv *o, Menu &m, PRINTF_ARGS)
                    157:        { insert(k, a, o, &m ? m.index() : ZIndex, PRINTF_COPY); }
                    158: 
                    159: void Pad::insert(long k, Attrib a, PadRcv *o, Index ix, PRINTF_ARGS)
                    160: {
                    161:        Line l;
                    162:        char t[1024];
                    163: 
                    164:        trace( "%d.insert(%d,0x%X,%d,0x%X,%s)", this, k, a, o, ix.sht(), fmt ); VOK;
                    165:        sprintf( l.text = t, PRINTF_COPY );
                    166:        l.key = k ? k : UniqueKey();
                    167:        if( !o ) a &= ~ACCEPT_KBD;
                    168:        l.attributes = a;
                    169:        l.object = o;
                    170:        l.carte = o ? ix : ZIndex;
                    171:        insert(l);
                    172: }
                    173: 
                    174: static Line prev; /* = { 0, 0, 0, 0, {0,0} } - cfront bug */
                    175: void Pad::insert(Line &l)
                    176: {
                    177:        char buf[256];
                    178:        register char *from;
                    179:        register int to;
                    180:        static Pad *prevpad;
                    181: 
                    182:        trace("%d.insert(%d,%s,%d,%X)",this,l.key,l.text,l.object,l.attributes);VOK;
                    183:        if( l.object && !l.object->isvalid() )
                    184:                PadsWarn("Pad::insert: object is not a PadRcv");
                    185:        if( _lines>0 && (l.key<1 || l.key>_lines) ){
                    186:                PadsWarn("Pad::insert: key out of range: %d %s", l.key, l.text);
                    187:                return;
                    188:        }
                    189:        if( l.attributes&FLUSHLINE || l.key==prev.key )
                    190:                R->writesize = 0;
                    191:        for( from = l.text, to = 0; *from && to<250; ++from )
                    192:                buf[to++] = isprint(*from) || *from=='\t'  ? *from : ' ';
                    193:        buf[to] = '\0';
                    194:        if(         this == prevpad
                    195:        &&         l.key == prev.key+1
                    196:        && l.carte.sht() == prev.carte.sht()
                    197:        &&  l.attributes == prev.attributes ){
                    198:                trace( "P_NEXTLINE %d", l.key );
                    199:                R->pktstart( P_NEXTLINE );
                    200:                R->sendobj( l.object );
                    201:        } else {
                    202:                R->pktstart( P_LINE );
                    203:                R->sendobj( _object );
                    204:                R->sendobj( l.object );
                    205:                R->sendlong( l.key );
                    206:                R->sendshort( l.carte.sht() );
                    207:                R->sendshort( l.attributes );
                    208:        }
                    209:        R->sendstring( buf );
                    210:        R->pktend();
                    211:        prev = l;
                    212:        prevpad = this;
                    213: }
                    214: 
                    215: Line::Line()
                    216: {
                    217:        trace( "%d.Line()", this ); VOK;
                    218:        object = 0;
                    219:        text = "";
                    220:        key = 0;
                    221:        attributes = 0;
                    222:        carte = 0;
                    223: }
                    224: 
                    225: long UniqueKey() { static long u; return u += 1024; }
                    226: 
                    227: void Pad::error( PRINTF_ARGS )
                    228: {
                    229:        trace( "%d.error(%s)", this, fmt );     VOK;
                    230:        if( errorkey ) removeline( errorkey );
                    231:        errorkey = 0;
                    232:        if( !fmt || !*fmt ) return;
                    233:        insert(errorkey = UniqueKey(), SELECTLINE, PRINTF_COPY);
                    234: }
                    235: 
                    236: void Pad::makegap(long k, long gap)
                    237: {
                    238:        trace( "%d.makegap(%d,%d)", this, k, gap ); VOK;
                    239:        R->pktstart( P_MAKEGAP );
                    240:        R->sendobj( _object );
                    241:        R->sendlong( k );
                    242:        R->sendlong( gap );
                    243:        R->pktend();
                    244: }

unix.superglobalmegacorp.com

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