Annotation of researchv9/jtools/src/pi/journal.c, revision 1.1.1.1

1.1       root        1: #include "journal.pri"
                      2: #include "core.pub"
                      3: #include "format.h"
                      4: SRCFILE("journal.c")
                      5: 
                      6: Journal::Journal(char *p)
                      7: {
                      8:        proc = p;
                      9:        key = 0;
                     10:        length = 50;
                     11:        lastreq = 0;
                     12: }
                     13: 
                     14: void Journal::open()
                     15: {
                     16:        trace("%d.open()", this);               VOK;
                     17:        if( !pad ){
                     18:                pad = new Pad((PadRcv*) this);
                     19:                banner();
                     20:        }
                     21:        pad->makecurrent();
                     22: }
                     23: 
                     24: void Journal::hostclose()
                     25: {
                     26:        trace( "%d.hostclose()", this );        VOK;
                     27:        if( pad ){
                     28:                delete pad;
                     29:                pad = 0;
                     30:        }
                     31:        if( bls ){
                     32:                delete bls;
                     33:                delete ct;
                     34:                bls = 0;
                     35:                ct = 0;
                     36:        }
                     37:        invalidate();
                     38: }
                     39: 
                     40: void Journal::banner()
                     41: {
                     42:        trace("%d.banner()", this);     VOK;
                     43:        if( pad ){
                     44:                pad->banner("Journal: %s", proc);
                     45:                pad->name("Journal %s", proc);
                     46:                pad->tabs(2);
                     47:                pad->options(TRUNCATE|NO_TILDE);
                     48:                if( !bls ){
                     49:                        bls = new Bls[length];
                     50:                        ct = new int[length];
                     51:                }
                     52:        }
                     53: }
                     54: 
                     55: void Journal::insert(PRINTF_ARGS)
                     56: {
                     57:        trace("%.insert(%s)", this, fmt);
                     58:        if( !this ) return;     VOK;
                     59:        if( !this->pad || !bls ) return;                        // can that be?
                     60:        Bls t(PRINTF_COPY);
                     61:        if( !t.text[0] ) return;
                     62:        long i = key%length;
                     63:        if( key==0 || strcmp(bls[i].text, t.text) ){
                     64:                i = (++key)%length;
                     65:                ct[i] = 0;
                     66:                bls[i].clear();
                     67:                bls[i].af("%s", t.text);
                     68:        }
                     69:        if( lastreq == key )
                     70:                linereq(key);
                     71:        else
                     72:                pad->createline(key);
                     73:        ++ct[i];
                     74:        if( key-length > 0 ) pad->removeline(key-length);
                     75: }
                     76: 
                     77: void Journal::linereq(long i, Attrib a)
                     78: {
                     79:        trace("%.linereq(%d,%x)", this, i, a); VOK;
                     80:        if( i <= key-length || !bls ) return;                   // too late!
                     81:        int mod = i%length;
                     82:        if( ct[mod] > 1 )
                     83:                pad->insert(i, a, "%s (%d)", bls[mod].text, ct[mod]);
                     84:        else
                     85:                pad->insert(i, a, "%s", bls[mod].text);
                     86:        lastreq = i;
                     87: }

unix.superglobalmegacorp.com

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