cleanup
[unix-history] / usr / src / usr.bin / tip / cu.c
CommitLineData
6b46907f 1/* cu.c 4.4 83/06/15 */
24f09632
SL
2
3#include "tip.h"
4
6b46907f 5static char *sccsid = "@(#)cu.c 4.4 %G%";
24f09632
SL
6int cleanup();
7int timeout();
8
9/*
10 * Botch the interface to look like cu's
11 */
12cumain(argc, argv)
13 char *argv[];
14{
15 register int i;
c731dacc 16 static char sbuf[12];
24f09632 17
24f09632 18 if (argc < 2) {
c731dacc 19 printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
24f09632
SL
20 exit(8);
21 }
c731dacc 22 CU = DV = NOSTR;
24f09632
SL
23 for (; argc > 1; argv++, argc--) {
24 if (argv[1][0] != '-')
25 PN = argv[1];
3f48242d 26 else switch (argv[1][1]) {
24f09632
SL
27
28 case 't':
29 HW = 1, DU = -1;
30 --argc;
31 continue;
32
33 case 'a':
34 CU = argv[2]; ++argv; --argc;
35 break;
36
37 case 's':
38 if (speed(atoi(argv[2])) == 0) {
c731dacc
BS
39 fprintf(stderr, "cu: unsupported speed %s\n",
40 argv[2]);
24f09632
SL
41 exit(3);
42 }
43 BR = atoi(argv[2]); ++argv; --argc;
44 break;
45
46 case 'l':
47 DV = argv[2]; ++argv; --argc;
48 break;
49
50 case '0': case '1': case '2': case '3': case '4':
51 case '5': case '6': case '7': case '8': case '9':
c731dacc
BS
52 if (CU)
53 CU[strlen(CU)-1] = argv[1][1];
54 if (DV)
55 DV[strlen(DV)-1] = argv[1][1];
24f09632
SL
56 break;
57
58 default:
59 printf("Bad flag %s", argv[1]);
60 break;
61 }
62 }
c731dacc
BS
63 signal(SIGINT, cleanup);
64 signal(SIGQUIT, cleanup);
65 signal(SIGHUP, cleanup);
66 signal(SIGTERM, cleanup);
67
24f09632
SL
68 /*
69 * The "cu" host name is used to define the
70 * attributes of the generic dialer.
71 */
c731dacc 72 if ((i = hunt(sprintf(sbuf, "cu%d", BR))) == 0) {
24f09632
SL
73 printf("all ports busy\n");
74 exit(3);
75 }
76 if (i == -1) {
77 printf("link down\n");
78 delock(uucplock);
79 exit(3);
80 }
c731dacc
BS
81 setbuf(stdout, NULL);
82 loginit();
83 setuid(getuid());
84 setgid(getgid());
85 vinit();
86 boolean(value(VERBOSE)) = 0;
24f09632
SL
87 if (HW)
88 ttysetup(speed(BR));
89 if (connect()) {
90 printf("Connect failed\n");
91 delock(uucplock);
92 exit(1);
93 }
94 if (!HW)
95 ttysetup(speed(BR));
96}