Annotation of researchv9/jtools/src/blitblt/kbdstring.c, revision 1.1.1.1

1.1       root        1: #include <jerq.h>
                      2: 
                      3: #define kbdcurs(p)     rectf(&display,Rect(p.x,p.y,p.x+1,p.y+fontheight(&defont) ),F_XOR)
                      4: 
                      5: static echo(c,p)
                      6: Point p;
                      7: {
                      8:        static char buf[2];
                      9: 
                     10:        buf[0] = c;
                     11:        string(&defont, buf, &display, p, F_XOR);
                     12: }
                     13: 
                     14: 
                     15: kbdstring(str,nchmax,p)        /* read string from keyboard with echo at p */
                     16: register char *str; int nchmax; Point p;
                     17: {
                     18:        register int kbd, nchars = 0;
                     19: 
                     20:        *str = 0; kbdcurs(p);
                     21:        for (;;) {
                     22:                wait(KBD);
                     23:                kbdcurs(p);
                     24:                switch (kbd = kbdchar()) {
                     25:                case 0:
                     26:                        break;
                     27:                case '\r':
                     28:                case '\n':
                     29:                        return nchars;
                     30:                case '\b':
                     31:                        if (nchars <= 0) break;
                     32:                        kbd = *--str; *str = 0; nchars--;
                     33:                        p.x -= fontwidth(&defont);
                     34:                        echo(kbd, p);
                     35:                        break;
                     36:                default:
                     37:                        if (nchars >= nchmax) break;
                     38:                        *str++ = kbd; *str = 0; nchars++;
                     39:                        echo(kbd, p);
                     40:                        p.x += fontwidth(&defont);
                     41:                }
                     42:                kbdcurs(p);
                     43:        }
                     44: }

unix.superglobalmegacorp.com

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