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

1.1       root        1: #include <pads.pub>
                      2: 
                      3: class Creator : public PadRcv {
                      4:        void    linereq(long,Attrib=0);
                      5: public:
                      6:        Pad     *pad;
                      7:                Creator();
                      8:        char    *kbd(char*);
                      9: };
                     10: 
                     11: class Journal : public PadRcv {
                     12:        void    linereq(long,Attrib=0);
                     13:        void    create(long);
                     14: public:
                     15:        Pad     *pad;
                     16:        void    cycle();
                     17:                Journal();
                     18: };
                     19: 
                     20: class Test : public PadRcv {
                     21:        void    linereq(long,Attrib=0);
                     22: public:
                     23:        Pad     *pad;
                     24:                Test();
                     25:        void    err(long);
                     26:        void    lines(long);
                     27:        void    exit();
                     28:        void    cycle();
                     29:        void    tabs(long t)    { pad->tabs(t); }
                     30:        void    remove(long k)  { pad->removeline(k); }
                     31:        char    *kbd(char*);
                     32:        char    *help();
                     33:        void    usercut();
                     34: };
                     35: 
                     36: void Test::usercut() {}
                     37: 
                     38: int sscanf(char*,char* ...);
                     39: 
                     40: char *Test::kbd(char *s)
                     41: {
                     42:        int i;
                     43:        if( !sscanf(s,"%d",&i) || i<=0 || i>=1000 )
                     44:                return "out of range";
                     45:        linereq(i,SELECTLINE);
                     46:        return 0;
                     47: }
                     48: 
                     49: char *Creator::kbd(char *s)
                     50: {
                     51:        int lo, hi;
                     52:        if( 2 == sscanf(s, "%d %d", &lo, &hi) )
                     53:                pad->createline(lo, hi );
                     54:        return 0;
                     55: }
                     56: 
                     57: char *Test::help()
                     58: {
                     59:        static int i;
                     60:        switch( i++%3 ){
                     61:                case 0: return 0;
                     62:                case 1: return "";
                     63:                case 2: return "Test::help";
                     64:        }
                     65: }
                     66: 
                     67: void Test::exit() { ::exit(); }
                     68: 
                     69: void Test::cycle()
                     70: {
                     71:        static i;
                     72:        char *ctime(long*);
                     73:        long time(long*), t;
                     74: 
                     75:        pad->alarm(i++/10);
                     76:        time(&t);
                     77:        pad->insert( 1, "%s", ctime(&t) );
                     78: }
                     79: 
                     80: Test::Test()
                     81: {
                     82:        Menu m( "first 1", (Action) &Test::linereq, 1 );
                     83:        Menu sub;
                     84:        Menu subsub;
                     85:        pad = new Pad( (PadRcv*) this );
                     86:        pad->lines(1000);
                     87:        pad->insert(1001, "one thouseand and one");
                     88:        pad->banner( "%s=%s", "Banner", "Test" );
                     89:        pad->name( "%s=%s", "name", "test" );
                     90:        pad->options(DONT_CLOSE|NO_TILDE);
                     91:        pad->makecurrent();
                     92:        subsub.sort( "B", (Action) &Test::linereq, 101 );
                     93:        subsub.sort( "A", (Action) &Test::linereq, 102 );
                     94:        subsub.sort( "D", (Action) &Test::linereq, 103 );
                     95:        subsub.sort( "C", (Action) &Test::linereq, 104 );
                     96:        sub.first( subsub.index("subsub") );
                     97:        sub.last( "b", (Action) &Test::linereq, 110 );
                     98:        sub.last( "a", (Action) &Test::linereq, 120 );
                     99:        sub.last( "d", (Action) &Test::linereq, 130 );
                    100:        sub.last( "c", (Action) &Test::linereq, 140 );
                    101:        m.first( sub.index("sub") );
                    102:        m.first( "cycle", (Action) &Test::cycle );
                    103:        m.first( "tabs=1", (Action) &Test::tabs, 1 );
                    104:        m.first( "tabs=3", (Action) &Test::tabs, 3 );
                    105:        m.last( "tabs=5", (Action) &Test::tabs, 5 );
                    106:        m.last( "tabs=7", (Action) &Test::tabs, 7 );
                    107:        m.last( "tabs=0", (Action) &Test::tabs, 0 );
                    108:        m.last( "tabs=128", (Action) &Test::tabs, 128 );
                    109:        m.last( "remove 100", (Action) &Test::remove, 100 );
                    110:        m.last( NumericRange(1,10) );
                    111:        pad->menu(m.index());
                    112:        pad->alarm();
                    113: }
                    114: 
                    115: Creator::Creator()
                    116: {
                    117:        pad = new Pad( (PadRcv*) this );
                    118:        pad->banner( "%s=%s", "Banner", "Creator" );
                    119:        pad->name( "%s=%s", "name", "creator" );
                    120:        pad->makecurrent();
                    121:        for( long i = 1; i <= 100; i += 10 ){
                    122:                pad->createline(i);
                    123:                pad->createline(i+3, i+7);
                    124:        }
                    125: }
                    126: 
                    127: void Creator::linereq(long i, Attrib a)
                    128: {
                    129:        pad->insert(i, a, "line\t%d\t[]", i);
                    130: }
                    131: 
                    132: Journal::Journal()
                    133: {
                    134:        pad = new Pad( (PadRcv*) this );
                    135:        pad->banner( "%s", "Journal" );
                    136:        pad->name( "%s", "Journal" );
                    137:        pad->makecurrent();
                    138:        pad->alarm();
                    139:        Menu m;
                    140:        m.last("create one", (Action)&Journal::create, 1);
                    141:        m.last("create two", (Action)&Journal::create, 2);
                    142:        pad->menu(m);
                    143: }
                    144: 
                    145: void Journal::create(long i)
                    146: {
                    147:        while(i--)
                    148:                pad->createline(10);
                    149: }
                    150: 
                    151: void Journal::linereq(long i, Attrib a)
                    152: {
                    153:        pad->insert(i, a, "journal %d", i);
                    154: }
                    155: 
                    156: void Journal::cycle()
                    157: {
                    158:        static k;
                    159: 
                    160:        pad->createline(++k);
                    161:        if( k-20 >= 1 ) pad->removeline(k-20);
                    162:        pad->alarm();
                    163: }
                    164: 
                    165: void Test::linereq(long i, Attrib a)
                    166: {
                    167:        Menu m;
                    168: 
                    169:        switch( i%5 ){
                    170:        case 0:
                    171:                pad->insert( i, a, "line\t%d\t[]", i  );
                    172:                pad->banner( "banner=%d", i );
                    173:                break;
                    174:        case 1:
                    175:                m.last( "150", (Action)&Test::linereq, 150 );
                    176:                pad->insert( i, a|USERCUT, (PadRcv*) this, m, "line\t%d", i );
                    177:                pad->name( "name=%d", i );
                    178:                break;
                    179:        case 2:
                    180:                m.last("250", (Action)&Test::linereq, 250 );
                    181:                pad->insert( i, a|USERCUT, (PadRcv*) this, m, "line\t%d", i );
                    182:                break;
                    183:        case 3:
                    184:                m.last("exit?", (Action)&Test::exit, 0 );
                    185:                pad->insert( i, a|USERCUT, (PadRcv*) this, m, "line\t%d", i );
                    186:                break;
                    187:        case 4:
                    188:                pad->insert( i, a|USERCUT, "" );
                    189:                break;
                    190:        }
                    191:        
                    192: }
                    193: 
                    194: void main(int, char **argv)
                    195: {
                    196:        new long;
                    197:        if( argv[1] )
                    198:                PadsInit( argv[1] );
                    199:        else
                    200:                PadsInit();
                    201:        extern char *TapTo;
                    202:        TapTo = ".tapto";
                    203:        new Test;
                    204:        new Creator;
                    205:        new Journal;
                    206:        NewPadStats();
                    207:        NewHelp();
                    208:        PadsServe();
                    209: }

unix.superglobalmegacorp.com

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