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

1.1       root        1: #include <pads.pri>
                      2: SRCFILE("menu.c")
                      3: 
                      4: Index ZIndex; /* = {0,0}; */
                      5: int Index::null() { return !(major|minor); }
                      6: 
                      7: Menu::Menu() { list = 0; size = 0; }
                      8: 
                      9: Menu::Menu(char *t, Action a, long o)
                     10: {
                     11:        trace( "%d.Menu(%s,%d,%d)", this, t, a, o );
                     12:        list = 0;
                     13:        size = 0;
                     14:        first(t, a, o);
                     15: }
                     16: 
                     17: Menu::~Menu()
                     18: {
                     19:        IList *l, *lnext;
                     20: 
                     21:        for( l = list; l; l = lnext ){
                     22:                lnext = l->next;                // new malloc()
                     23:                delete l;
                     24:        }
                     25: }
                     26: 
                     27: void Menu::first(char *t, Action a, long o)
                     28: {
                     29:        trace( "%d.first(%s,%d,%d)", this, t, a, o );
                     30:        first( ICache->place( Item(t,a,o) ) );
                     31: }
                     32: 
                     33: void Menu::last(char *t, Action a, long o)
                     34: {
                     35:        trace( "%d.last(%s,%d,%d)", this, t, a, o );
                     36:        last( ICache->place( Item(t,a,o) ) );
                     37: }
                     38: 
                     39: void Menu::first(Index i)
                     40: {
                     41:        trace( "%d.first(%u:%u)", this, i.major, i.minor );
                     42:        if( i.null() ) return;
                     43:        list = new IList(i,list);
                     44:        ++size;
                     45: }
                     46: 
                     47: void Menu::last(Index i)
                     48: {
                     49:        IList *l;
                     50: 
                     51:        trace( "%d.last(%u:%u)", this, i.major, i.minor );
                     52:        if( i.null() ) return;
                     53:        ++size;
                     54:        if( !list ){
                     55:                list = new IList(i,0);
                     56:                return;
                     57:        }
                     58:        for( l = list; l->next; l = l->next ) {}
                     59:        l->next = new IList(i,0);
                     60: }
                     61: 
                     62: int IndexTextCmp( Index a, Index b )
                     63: {
                     64:        trace( "IndexTextCmp(%u:%u,%u:%u)", a.major, a.minor, b.major, b.minor );
                     65:        return strcmp( ICache->take(a)->text, ICache->take(b)->text );
                     66: }
                     67: 
                     68: void Menu::sort(char *t, Action a, long o )
                     69: {
                     70:        int cmp;
                     71:        IList **p;
                     72: 
                     73:        trace( "%d.sort(%s,%d,%d)", this, t, a, o );
                     74:        Index i = ICache->place( Item(t,a,o) );
                     75:        if( !list ){
                     76:                first(i);
                     77:                return;
                     78:        }
                     79:        for( p = &list; *p; p = &((*p)->next) ){
                     80:                trace( "%u:%u", (*p)->index.major, (*p)->index.minor );
                     81:                cmp = IndexTextCmp( i, (*p)->index );
                     82:                if( cmp == 0 ) return;
                     83:                if( cmp < 0 ) break;
                     84:        }
                     85:        ++size;
                     86:        *p = new IList(i,*p);
                     87: }
                     88: 
                     89: Index Menu::index(char *t, Action a, long o)
                     90: {
                     91:        IList *l;
                     92:        int i;
                     93:        Carte *c;
                     94:        
                     95:        trace( "%d.index() %d", this, size );
                     96:        if( size==0 ) return 0;
                     97:        c = (Carte *) new char [CARTESIZE(size)];
                     98:        c->attrib = 0;
                     99:        if (size > 255)
                    100:                size = 255;
                    101:        c->size = size;
                    102:        for( l = list, i = 1; l; l = l->next, ++i )
                    103:                c->bin[i] = l->index;
                    104:        if( t )
                    105:                c->bin[0] = ICache->place(Item(t,a,o));
                    106:        Index ix = CCache->place(c);
                    107:        delete c;
                    108:        return ix;
                    109: }
                    110: 
                    111: void Menu::dump()
                    112: {
                    113:        IList *l;
                    114: 
                    115:        trace( "%d.dump()", this );
                    116:        for( l = list; l; l = l->next ){
                    117:                trace( "%u:%u", l->index.major, l->index.minor );
                    118:        }
                    119: }

unix.superglobalmegacorp.com

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