Annotation of researchv10no/cmd/daemon/phone.fgd.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Retrieve files from GCOS via dataphone
                      3:  */
                      4: 
                      5: #define        SPIDER  0
                      6: #define        PHONE   1
                      7: #define        LPD     0
                      8: #define        FGET    1
                      9: 
                     10: char   dname[] = "FGETP";
                     11: 
                     12: #include       "gcos.c"
                     13: #include       "fgdemon.c"
                     14: 
                     15: #define        FLUSH   (*output)(inp, lbuf-inp);  lbuf = inp;
                     16: #define        BADCHAR cgset[cp[1] - 040] & 040
                     17: 
                     18: #define        NCONERR 4
                     19: #define        BUSY    -1
                     20: #define        TIMEOUT -2
                     21: #define        BADID   -3
                     22: #define        ERROR   -4
                     23: char   conerr[NCONERR+1][8] = {"BUSY","TIMEOUT","BAD ID","ERROR","UNKNOWN"};
                     24: char   conmes[] = "Can't connect to GCOS: %-13s";
                     25: 
                     26: char   inp[BUFSIZ];
                     27: char   *ebuf;
                     28: char   *lbuf   = inp;
                     29: char   savc;
                     30: int    state;
                     31: int    ioc;
                     32: char   ibuf[BUFSIZ];
                     33: 
                     34: 
                     35: fgd_read()
                     36: {
                     37:        register i, n;
                     38:        register char *cp;
                     39:        extern char cgset[];
                     40: 
                     41:        while((i = connect(fget_id)) < 0) {
                     42:                if(i == TIMEOUT)
                     43:                        trouble(BADTRB, 60,"TIMEOUT");
                     44:                if((i = -i) > NCONERR+1)  i = NCONERR+1;
                     45:                trouble(BADTRB, 60, conmes, conerr[i-1]);
                     46:        }
                     47: 
                     48:        if((ioc = send("$*$out", ibuf)) != 0103) {
                     49: #ifdef DEBUG
                     50:                fprintf(stderr, "ioc = %o; *ibuf = %o\n", ioc, *ibuf);  /*DEBUG*/
                     51:                fprintf(stderr, "out\n");       /*DEBUG*/
                     52: #endif
                     53:                trouble(BADTRB, 60,"out: ioc=%o", ioc);
                     54:        }
                     55: 
                     56:        if((ioc = gerts(0102, 0100, (char *)0, ibuf)) != 0102) {
                     57: #ifdef DEBUG
                     58:                fprintf(stderr, "sack\n");      /*DEBUG*/
                     59: #endif
                     60:                trouble(BADTRB, 60,"sack: ioc=%o", ioc);
                     61:        }
                     62: 
                     63:        if((ioc = gerts(0102, 0100, (char *)0, ibuf)) != 0100) {
                     64: #ifdef DEBUG
                     65:                fprintf(stderr, "data\n");      /*DEBUG*/
                     66: #endif
                     67:                trouble(BADTRB, 60,"data: ioc=%o", ioc);
                     68:        }
                     69: 
                     70:        ebuf = inp + BUFSIZ;
                     71: loop:
                     72:        if(ibuf[1] != 0127)     goto rrec;
                     73:        if(ibuf[2] == '!' && ibuf[3] == '!') {
                     74:                FLUSH
                     75:                endfile();
                     76:                state = 0;
                     77:                goto rrec;
                     78:        }
                     79:        cp = ibuf+1;
                     80:        if(BADCHAR)    goto rrec;
                     81:        state = 0;
                     82:        cp = ibuf+2;
                     83: cloop:
                     84:        if(*cp == 036) {
                     85:                if(*++cp != 0127)       goto rrec;
                     86:                if(cp[1] == '!' && cp[2] == '!') {
                     87:                        FLUSH
                     88:                        endfile();
                     89:                        goto rrec;
                     90:                }
                     91:                if(BADCHAR){
                     92: #ifdef DEBUG
                     93:                        fprintf(stderr, "unexpected high bits\n");
                     94: #endif
                     95:                        trouble(BADTRB, 60, "unexpected high bits");
                     96:                }
                     97:                cp++;
                     98:        }
                     99:        if(cp >= ibuf+BUFSIZ) {
                    100: #ifdef DEBUG
                    101:                fprintf(stderr, "overflow\n");  /*DEBUG*/
                    102: #endif
                    103:                trouble(BADTRB, 60,"overflow");
                    104:        }
                    105:        if(cp[1] == 037) {
                    106:                n = cgset[cp[2]-040]+1;
                    107:                while(n--)
                    108:                        if(putcod(*cp)){
                    109:                                FLUSH
                    110:                        }
                    111:                cp += 3;
                    112:                goto cloop;
                    113:        }
                    114:        if(putcod(*cp++)){
                    115:                FLUSH
                    116:        }
                    117:        goto cloop;
                    118: rrec:
                    119:        if((ioc = gerts(0110, 0100, (char *)0, ibuf)) == 0100) {
                    120: #ifdef DEBUG
                    121:                fprintf(stderr, "%o %o %o %o\n", ibuf[0], ibuf[1],
                    122:                        ibuf[2], ibuf[3]);      /*DEBUG*/
                    123: #endif
                    124:                goto loop;
                    125:        }
                    126:        return;
                    127: }
                    128: 
                    129: 
                    130: dem_dis()
                    131: {
                    132:        FCLOSE(ofd);
                    133:        FCLOSE(tfd);
                    134:        gerts_dis();
                    135: }
                    136: 
                    137: 
                    138: putcod(ch)
                    139: {
                    140:        extern char cgset[];
                    141:        register c, code;
                    142: 
                    143:        if(ch < 040 || ch >= 0140) {
                    144: #ifdef DEBUG
                    145:                fprintf(stderr, "%o: ", ch);            /*DEBUG*/
                    146: #endif
                    147:                fgderr("Bad code: %o, in file %s", ch, fname);
                    148:        }
                    149:        c = cgset[ch-040];
                    150:        switch(state) {
                    151: 
                    152:        case 0:
                    153:                state++;
                    154:                savc = c;
                    155:                return(0);
                    156: 
                    157:        case 1:
                    158:                state++;
                    159:                code = (savc<<3)|(c>>3);
                    160:                savc = c&07;
                    161:                break;
                    162: 
                    163:        case 2:
                    164:                state = 0;
                    165:                code = c | ( savc<<6);
                    166:                break;
                    167:        }
                    168: 
                    169: #ifdef DEBUG
                    170:        putc(code, stderr);     /*DEBUG*/
                    171: #endif
                    172:        *lbuf = code;
                    173:        if(++lbuf >= ebuf || code == '\n')
                    174:                return(1);
                    175:        return(0);
                    176: }
                    177: 
                    178: fgderr(s, ch, f)
                    179: char   *s;
                    180: char   ch;
                    181: char   *f;
                    182: {
                    183: 
                    184:        if(ofd != NULL){
                    185:                fprintf(ofd, s, ch, f);
                    186:                putc('\n', ofd);
                    187:        }
                    188:        trouble(BADTRB, 60,s, ch, f);
                    189: }
                    190: 
                    191: send(card, gbuf)
                    192: char   *card;
                    193: char   *gbuf;
                    194: {
                    195: 
                    196:        char    image[200];
                    197:        register char   *cp;
                    198:        int     fc;
                    199: 
                    200:        if(*card == '$')        fc = 0104;
                    201:        else                    fc = 0110;
                    202: 
                    203:        cp = image;
                    204:        *cp++ = 'H';
                    205:        while(*cp++ = *card++);
                    206: 
                    207:        cp[-1] = '\36';
                    208:        *cp = '\3';
                    209: 
                    210: 
                    211:        return(gerts(fc, 0100, image, gbuf));
                    212: }

unix.superglobalmegacorp.com

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