Annotation of researchv10no/cmd/telno.c, revision 1.1

1.1     ! root        1: #include <ipc.h>
        !             2: #include <fio.h>
        !             3: /*
        !             4: name<tab>company<tab>dialcode<tab>phone<tab>location<tab>room<tab>org<tab>mail<\n>
        !             5: */
        !             6: int    fd;
        !             7: 
        !             8: timeout(){
        !             9:        fprint(2, "telno: timeout\n");
        !            10:        exit(1);
        !            11: }
        !            12: main(argc, argv)
        !            13:        char *argv[];
        !            14: {
        !            15:        register i;
        !            16: 
        !            17:        if(argc==1){
        !            18:                fprint(2, "usage: telno datum...\n");
        !            19:                return 1;
        !            20:        }
        !            21:        fd=ipcopen(ipcpath("nj/homer/dq", "dk", "dq1"), "light");
        !            22:        if(fd==-1){
        !            23:                fprint(2, "telno: call failed: %s\n", errstr);
        !            24:                return 1;
        !            25:        }
        !            26:        copy("-\n", 0);
        !            27:        nap(20);
        !            28:        for(i=1; i<argc; i++)
        !            29:                lookup(argv[i]);
        !            30:        return 0;
        !            31: }
        !            32: char   peekbuf[20];
        !            33: int    npeek=0;
        !            34: #define        unget(c)        (peekbuf[npeek++]=(c))
        !            35: lookup(s)
        !            36:        char *s;
        !            37: {
        !            38:        char buf[256];
        !            39:        sprint(buf, "%s\n", s);
        !            40:        write(fd, buf, strlen(buf));
        !            41:        copy("\n", 0);
        !            42:        unget('\n');
        !            43:        copy("\n.\n", 1);
        !            44:        return 0;
        !            45: }
        !            46: get(){
        !            47:        register n, c;
        !            48:        char buf[sizeof peekbuf];
        !            49:        if(npeek==0){
        !            50:                n=read(fd, buf, sizeof peekbuf);
        !            51:                if(n<=0){
        !            52:                        fprint(2, "telno: read error\n");
        !            53:                        exit(1);
        !            54:                }
        !            55:                while(--n>=0)
        !            56:                        unget(buf[n]);
        !            57:        }
        !            58:        c=peekbuf[--npeek];
        !            59:        c&=0x7F;
        !            60:        if(c<' ' && c!='\n')
        !            61:                return get();
        !            62:        return c;
        !            63: }
        !            64: copy(end, output)
        !            65:        register char *end;
        !            66: {
        !            67:        register n=0;
        !            68:        register char *e;
        !            69:        char c;
        !            70:        for(;;){
        !            71:                c=get();
        !            72:                if(output)
        !            73:                        Fputc(1, c);
        !            74:                e=end;
        !            75:                while(c==*e && *++e)
        !            76:                        c=get();
        !            77:                if(*e==0)
        !            78:                        break;
        !            79:                if(e>end){
        !            80:                        unget(c);
        !            81:                        while(e>end+1)
        !            82:                                unget(*--e);
        !            83:                }
        !            84:        }
        !            85: }

unix.superglobalmegacorp.com

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