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

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)acu.c      4.10 (Berkeley) 7/16/83";
        !             3: #endif
        !             4: 
        !             5: #include "tip.h"
        !             6: 
        !             7: static acu_t *acu = NOACU;
        !             8: static int conflag;
        !             9: static int acuabort();
        !            10: static acu_t *acutype();
        !            11: static jmp_buf jmpbuf;
        !            12: /*
        !            13:  * Establish connection for tip
        !            14:  *
        !            15:  * If DU is true, we should dial an ACU whose type is AT.
        !            16:  * The phone numbers are in PN, and the call unit is in CU.
        !            17:  *
        !            18:  * If the PN is an '@', then we consult the PHONES file for
        !            19:  *   the phone numbers.  This file is /etc/phones, unless overriden
        !            20:  *   by an exported shell variable.
        !            21:  *
        !            22:  * The data base files must be in the format:
        !            23:  *     host-name[ \t]*phone-number
        !            24:  *   with the possibility of multiple phone numbers
        !            25:  *   for a single host acting as a rotary (in the order
        !            26:  *   found in the file).
        !            27:  */
        !            28: char *
        !            29: connect()
        !            30: {
        !            31:        register char *cp = PN;
        !            32:        char *phnum, string[256];
        !            33:        FILE *fd;
        !            34:        int tried = 0;
        !            35: 
        !            36:        if (!DU) {              /* regular connect message */
        !            37:                if (CM != NOSTR)
        !            38:                        pwrite(FD, cp, size(CM));
        !            39:                return (NOSTR);
        !            40:        }
        !            41:        /*
        !            42:         * @ =>'s use data base in PHONES environment variable
        !            43:         *        otherwise, use /etc/phones
        !            44:         */
        !            45:        signal(SIGINT, acuabort);
        !            46:        signal(SIGQUIT, acuabort);
        !            47:        if (setjmp(jmpbuf)) {
        !            48:                signal(SIGINT, SIG_IGN);
        !            49:                signal(SIGQUIT, SIG_IGN);
        !            50:                printf("\ncall aborted\n");
        !            51:                logent(value(HOST), "", "", "call aborted");
        !            52:                if (acu != NOACU) {
        !            53:                        boolean(value(VERBOSE)) = FALSE;
        !            54:                        if (conflag)
        !            55:                                disconnect();
        !            56:                        else
        !            57:                                (*acu->acu_abort)();
        !            58:                }
        !            59:                delock(uucplock);
        !            60:                exit(1);
        !            61:        }
        !            62:        if ((acu = acutype(AT)) == NOACU)
        !            63:                return ("unknown ACU type");
        !            64:        if (*cp != '@') {
        !            65:                while (*cp) {
        !            66:                        for (phnum = cp; any(*cp, "0123456789-*=K"); cp++)
        !            67:                                ;
        !            68:                        if (*cp)
        !            69:                                *cp++ = '\0';
        !            70:                        
        !            71:                        if (conflag = (*acu->acu_dialer)(phnum, CU)) {
        !            72:                                logent(value(HOST), phnum, acu->acu_name,
        !            73:                                        "call completed");
        !            74:                                return (NOSTR);
        !            75:                        } else
        !            76:                                logent(value(HOST), phnum, acu->acu_name,
        !            77:                                        "call failed");
        !            78:                        tried++;
        !            79:                }
        !            80:        } else {
        !            81:                if ((fd = fopen(PH, "r")) == NOFILE) {
        !            82:                        printf("%s: ", PH);
        !            83:                        return ("can't open phone number file");
        !            84:                }
        !            85:                while (fgets(string, sizeof(string), fd) != NOSTR) {
        !            86:                        for (cp = string; !any(*cp, " \t\n"); cp++)
        !            87:                                ;
        !            88:                        if (*cp == '\n') {
        !            89:                                fclose(fd);
        !            90:                                return ("unrecognizable host name");
        !            91:                        }
        !            92:                        *cp++ = '\0';
        !            93:                        if (strcmp(string, value(HOST)))
        !            94:                                continue;
        !            95:                        while (any(*cp, " \t"))
        !            96:                                cp++;
        !            97:                        if (*cp == '\n') {
        !            98:                                fclose(fd);
        !            99:                                return ("missing phone number");
        !           100:                        }
        !           101:                        for (phnum = cp; any(*cp, "0123456789-*="); cp++)
        !           102:                                ;
        !           103:                        *cp = '\0';
        !           104:                        
        !           105:                        if (conflag = (*acu->acu_dialer)(phnum, CU)) {
        !           106:                                fclose(fd);
        !           107:                                logent(value(HOST), phnum, acu->acu_name,
        !           108:                                        "call completed");
        !           109:                                return (NOSTR);
        !           110:                        } else
        !           111:                                logent(value(HOST), phnum, acu->acu_name,
        !           112:                                        "call failed");
        !           113:                        tried++;
        !           114:                }
        !           115:                fclose(fd);
        !           116:        }
        !           117:        if (!tried)
        !           118:                logent(value(HOST), "", acu->acu_name, "missing phone number");
        !           119:        else
        !           120:                (*acu->acu_abort)();
        !           121:        return (tried ? "call failed" : "missing phone number");
        !           122: }
        !           123: 
        !           124: disconnect()
        !           125: {
        !           126:        if (!conflag)
        !           127:                return;
        !           128:        logent(value(HOST), "", acu->acu_name, "call terminated");
        !           129:        if (boolean(value(VERBOSE)))
        !           130:                printf("\r\ndisconnecting...");
        !           131:        (*acu->acu_disconnect)();
        !           132: }
        !           133: 
        !           134: static int
        !           135: acuabort(s)
        !           136: {
        !           137:        signal(s, SIG_IGN);
        !           138:        longjmp(jmpbuf, 1);
        !           139: }
        !           140: 
        !           141: static acu_t *
        !           142: acutype(s)
        !           143:        register char *s;
        !           144: {
        !           145:        register acu_t *p;
        !           146:        extern acu_t acutable[];
        !           147: 
        !           148:        for (p = acutable; p->acu_name != '\0'; p++)
        !           149:                if (!strcmp(s, p->acu_name))
        !           150:                        return (p);
        !           151:        return (NOACU);
        !           152: }

unix.superglobalmegacorp.com

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