[BACK]Return to cu.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tip

Annotation of src/usr.bin/tip/cu.c, Revision 1.28

1.28    ! nicm        1: /*     $OpenBSD: cu.c,v 1.27 2010/06/29 17:42:35 nicm Exp $    */
1.3       millert     2: /*     $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $       */
1.1       deraadt     3:
                      4: /*
                      5:  * Copyright (c) 1983, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.14      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
1.21      ray        33: #include <err.h>
                     34: #include <paths.h>
                     35:
1.1       deraadt    36: #include "tip.h"
                     37:
1.18      moritz     38: static void    cuusage(void);
1.1       deraadt    39:
                     40: /*
                     41:  * Botch the interface to look like cu's
                     42:  */
1.4       deraadt    43: void
1.17      deraadt    44: cumain(int argc, char *argv[])
1.1       deraadt    45: {
1.11      miod       46:        int ch, i, parity;
1.20      millert    47:        const char *errstr;
1.1       deraadt    48:        static char sbuf[12];
                     49:
1.6       millert    50:        if (argc < 2)
                     51:                cuusage();
1.26      nicm       52:        DV = NULL;
1.1       deraadt    53:        BR = DEFBR;
1.11      miod       54:        parity = 0;     /* none */
1.20      millert    55:
                     56:        /*
                     57:         * Convert obsolecent -### speed to modern -s### syntax which
                     58:         * getopt() can handle.
                     59:         */
                     60:        for (i = 1; i < argc; i++) {
                     61:                if (argv[i][0] == '-') {
                     62:                        switch (argv[i][1]) {
                     63:                        case '0': case '1': case '2': case '3': case '4':
                     64:                        case '5': case '6': case '7': case '8': case '9':
                     65:                                ch = snprintf(sbuf, sizeof(sbuf), "-s%s",
                     66:                                    &argv[i][1]);
                     67:                                if (ch <= 0 || ch >= sizeof(sbuf)) {
                     68:                                        errx(3, "invalid speed: %s",
                     69:                                            &argv[i][1]);
                     70:                                }
                     71:                                argv[i] = sbuf;
                     72:                                break;
                     73:                        case '-':
                     74:                                /* if we get "--" stop processing args */
                     75:                                if (argv[i][2] == '\0')
                     76:                                        goto getopt;
                     77:                                break;
                     78:                        }
                     79:                }
                     80:        }
                     81:
                     82: getopt:
1.26      nicm       83:        while ((ch = getopt(argc, argv, "l:s:htoe")) != -1) {
1.17      deraadt    84:                switch (ch) {
1.6       millert    85:                case 'l':
1.8       deraadt    86:                        if (DV != NULL) {
                     87:                                fprintf(stderr,
1.23      martynas   88:                                    "%s: cannot specify multiple -l options\n",
1.8       deraadt    89:                                    __progname);
                     90:                                exit(3);
                     91:                        }
                     92:                        if (strchr(optarg, '/'))
                     93:                                DV = optarg;
                     94:                        else
1.21      ray        95:                                if (asprintf(&DV, "%s%s", _PATH_DEV, optarg) == -1)
                     96:                                        err(3, "asprintf");
1.1       deraadt    97:                        break;
                     98:                case 's':
1.20      millert    99:                        BR = (int)strtonum(optarg, 0, INT_MAX, &errstr);
                    100:                        if (errstr)
                    101:                                errx(3, "speed is %s: %s", errstr, optarg);
1.6       millert   102:                        break;
                    103:                case 'h':
1.28    ! nicm      104:                        setboolean(value(LECHO), 1);
        !           105:                        HD = 1;
1.6       millert   106:                        break;
                    107:                case 't':
1.27      nicm      108:                        /* Was for a hardwired dial-up connection. */
1.1       deraadt   109:                        break;
1.6       millert   110:                case 'o':
1.11      miod      111:                        if (parity != 0)
                    112:                                parity = 0;     /* -e -o */
                    113:                        else
                    114:                                parity = 1;     /* odd */
1.6       millert   115:                        break;
                    116:                case 'e':
1.11      miod      117:                        if (parity != 0)
                    118:                                parity = 0;     /* -o -e */
                    119:                        else
                    120:                                parity = -1;    /* even */
1.1       deraadt   121:                        break;
                    122:                default:
1.10      pvalchev  123:                        cuusage();
1.1       deraadt   124:                        break;
                    125:                }
                    126:        }
1.6       millert   127:        argc -= optind;
                    128:        argv += optind;
                    129:
                    130:        switch (argc) {
                    131:        case 1:
                    132:                PN = argv[0];
                    133:                break;
                    134:        case 0:
                    135:                break;
                    136:        default:
                    137:                cuusage();
                    138:                break;
                    139:        }
                    140:
1.1       deraadt   141:        signal(SIGINT, cleanup);
                    142:        signal(SIGQUIT, cleanup);
                    143:        signal(SIGHUP, cleanup);
                    144:        signal(SIGTERM, cleanup);
1.16      otto      145:        signal(SIGCHLD, SIG_DFL);
1.1       deraadt   146:
                    147:        /*
                    148:         * The "cu" host name is used to define the
                    149:         * attributes of the generic dialer.
                    150:         */
1.4       deraadt   151:        (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
1.1       deraadt   152:        if ((i = hunt(sbuf)) == 0) {
                    153:                printf("all ports busy\n");
                    154:                exit(3);
                    155:        }
                    156:        if (i == -1) {
                    157:                printf("link down\n");
                    158:                (void)uu_unlock(uucplock);
                    159:                exit(3);
                    160:        }
                    161:        setbuf(stdout, NULL);
                    162:        loginit();
                    163:        vinit();
1.11      miod      164:        switch (parity) {
                    165:        case -1:
                    166:                setparity("even");
                    167:                break;
                    168:        case 1:
                    169:                setparity("odd");
                    170:                break;
                    171:        default:
                    172:                setparity("none");
                    173:                break;
                    174:        }
1.28    ! nicm      175:        setboolean(value(VERBOSE), 0);
1.27      nicm      176:        if (ttysetup(BR)) {
1.13      millert   177:                fprintf(stderr, "%s: unsupported speed %ld\n",
                    178:                    __progname, BR);
                    179:                (void)uu_unlock(uucplock);
                    180:                exit(3);
                    181:        }
1.26      nicm      182:        con();
1.6       millert   183: }
                    184:
1.18      moritz    185: static void
1.17      deraadt   186: cuusage(void)
1.6       millert   187: {
1.27      nicm      188:        fprintf(stderr, "usage: cu [-eho] [-l line] "
1.19      jmc       189:            "[-s speed | -speed] [phone-number]\n");
1.6       millert   190:        exit(8);
1.1       deraadt   191: }