Annotation of 42BSD/usr.bin/tip/aculib/v3451.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)v3451.c    4.4 (Berkeley) 6/25/83";
        !             3: #endif
        !             4: 
        !             5: /*
        !             6:  * Routines for calling up on a Vadic 3451 Modem
        !             7:  */
        !             8: #include "tip.h"
        !             9: 
        !            10: static jmp_buf Sjbuf;
        !            11: 
        !            12: v3451_dialer(num, acu)
        !            13:        register char *num;
        !            14:        char *acu;
        !            15: {
        !            16:        int ok, (*func)();
        !            17:        int slow = number(value(BAUDRATE)) < 1200, rw = 2;
        !            18:        char phone[50];
        !            19: #ifdef ACULOG
        !            20:        char line[80];
        !            21: #endif
        !            22: 
        !            23:        /*
        !            24:         * Get in synch
        !            25:         */
        !            26:        vawrite("I\r", 1 + slow);
        !            27:        vawrite("I\r", 1 + slow);
        !            28:        vawrite("I\r", 1 + slow);
        !            29:        vawrite("\005\r", 2 + slow);
        !            30:        if (!expect("READY")) {
        !            31:                printf("can't synchronize with vadic 3451\n");
        !            32: #ifdef ACULOG
        !            33:                logent(value(HOST), num, "vadic", "can't synch up");
        !            34: #endif
        !            35:                return (0);
        !            36:        }
        !            37:        ioctl(FD, TIOCHPCL, 0);
        !            38:        sleep(1);
        !            39:        vawrite("D\r", 2 + slow);
        !            40:        if (!expect("NUMBER?")) {
        !            41:                printf("Vadic will not accept dial command\n");
        !            42: #ifdef ACULOG
        !            43:                logent(value(HOST), num, "vadic", "will not accept dial");
        !            44: #endif
        !            45:                return (0);
        !            46:        }
        !            47:        strcpy(phone, num);
        !            48:        strcat(phone, "\r");
        !            49:        vawrite(phone, 1 + slow);
        !            50:        if (!expect(phone)) {
        !            51:                printf("Vadic will not accept phone number\n");
        !            52: #ifdef ACULOG
        !            53:                logent(value(HOST), num, "vadic", "will not accept number");
        !            54: #endif
        !            55:                return (0);
        !            56:        }
        !            57:        func = signal(SIGINT,SIG_IGN);
        !            58:        /*
        !            59:         * You cannot interrupt the Vadic when its dialing;
        !            60:         * even dropping DTR does not work (definitely a
        !            61:         * brain damaged design).
        !            62:         */
        !            63:        vawrite("\r", 1 + slow);
        !            64:        vawrite("\r", 1 + slow);
        !            65:        if (!expect("DIALING:")) {
        !            66:                printf("Vadic failed to dial\n");
        !            67: #ifdef ACULOG
        !            68:                logent(value(HOST), num, "vadic", "failed to dial");
        !            69: #endif
        !            70:                return (0);
        !            71:        }
        !            72:        if (boolean(value(VERBOSE)))
        !            73:                printf("\ndialing...");
        !            74:        ok = expect("ON LINE");
        !            75:        signal(SIGINT, func);
        !            76:        if (!ok) {
        !            77:                printf("call failed\n");
        !            78: #ifdef ACULOG
        !            79:                logent(value(HOST), num, "vadic", "call failed");
        !            80: #endif
        !            81:                return (0);
        !            82:        }
        !            83:        ioctl(FD, TIOCFLUSH, &rw);
        !            84:        return (1);
        !            85: }
        !            86: 
        !            87: v3451_disconnect()
        !            88: {
        !            89: 
        !            90:        close(FD);
        !            91: }
        !            92: 
        !            93: v3451_abort()
        !            94: {
        !            95: 
        !            96:        close(FD);
        !            97: }
        !            98: 
        !            99: static
        !           100: vawrite(cp, delay)
        !           101:        register char *cp;
        !           102:        int delay;
        !           103: {
        !           104: 
        !           105:        for (; *cp; sleep(delay), cp++)
        !           106:                write(FD, cp, 1);
        !           107: }
        !           108: 
        !           109: static
        !           110: expect(cp)
        !           111:        register char *cp;
        !           112: {
        !           113:        char buf[300];
        !           114:        register char *rp = buf;
        !           115:        int alarmtr(), timeout = 30, online = 0;
        !           116: 
        !           117:        if (strcmp(cp, "\"\"") == 0)
        !           118:                return (1);
        !           119:        *rp = 0;
        !           120:        /*
        !           121:         * If we are waiting for the Vadic to complete
        !           122:         * dialing and get a connection, allow more time
        !           123:         * Unfortunately, the Vadic times out 24 seconds after
        !           124:         * the last digit is dialed
        !           125:         */
        !           126:        online = strcmp(cp, "ON LINE") == 0;
        !           127:        if (online)
        !           128:                timeout = number(value(DIALTIMEOUT));
        !           129:        signal(SIGALRM, alarmtr);
        !           130:        if (setjmp(Sjbuf))
        !           131:                return (0);
        !           132:        alarm(timeout);
        !           133:        while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) {
        !           134:                if (online && notin("FAILED CALL", buf) == 0)
        !           135:                        return (0);
        !           136:                if (read(FD, rp, 1) < 0) {
        !           137:                        alarm(0);
        !           138:                        return (0);
        !           139:                }
        !           140:                if (*rp &= 0177)
        !           141:                        rp++;
        !           142:                *rp = '\0';
        !           143:        }
        !           144:        alarm(0);
        !           145:        return (1);
        !           146: }
        !           147: 
        !           148: static
        !           149: alarmtr()
        !           150: {
        !           151: 
        !           152:        longjmp(Sjbuf, 1);
        !           153: }
        !           154: 
        !           155: static
        !           156: notin(sh, lg)
        !           157:        char *sh, *lg;
        !           158: {
        !           159: 
        !           160:        for (; *lg; lg++)
        !           161:                if (prefix(sh, lg))
        !           162:                        return (0);
        !           163:        return (1);
        !           164: }
        !           165: 
        !           166: static
        !           167: prefix(s1, s2)
        !           168:        register char *s1, *s2;
        !           169: {
        !           170:        register char c;
        !           171: 
        !           172:        while ((c = *s1++) == *s2++)
        !           173:                if (c == '\0')
        !           174:                        return (1);
        !           175:        return (c == '\0');
        !           176: }

unix.superglobalmegacorp.com

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