xref: /original-bsd/usr.bin/tip/cu.c (revision b485b642)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)cu.c	5.8 (Berkeley) 10/03/89";
20 #endif /* not lint */
21 
22 #include "tip.h"
23 
24 void	cleanup();
25 
26 /*
27  * Botch the interface to look like cu's
28  */
29 cumain(argc, argv)
30 	char *argv[];
31 {
32 	register int i;
33 	static char sbuf[12];
34 
35 	if (argc < 2) {
36 		printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
37 		exit(8);
38 	}
39 	CU = DV = NOSTR;
40 	BR = DEFBR;
41 	for (; argc > 1; argv++, argc--) {
42 		if (argv[1][0] != '-')
43 			PN = argv[1];
44 		else switch (argv[1][1]) {
45 
46 		case 't':
47 			HW = 1, DU = -1;
48 			--argc;
49 			continue;
50 
51 		case 'a':
52 			CU = argv[2]; ++argv; --argc;
53 			break;
54 
55 		case 's':
56 			if (argc < 3 || speed(atoi(argv[2])) == 0) {
57 				fprintf(stderr, "cu: unsupported speed %s\n",
58 					argv[2]);
59 				exit(3);
60 			}
61 			BR = atoi(argv[2]); ++argv; --argc;
62 			break;
63 
64 		case 'l':
65 			DV = argv[2]; ++argv; --argc;
66 			break;
67 
68 		case '0': case '1': case '2': case '3': case '4':
69 		case '5': case '6': case '7': case '8': case '9':
70 			if (CU)
71 				CU[strlen(CU)-1] = argv[1][1];
72 			if (DV)
73 				DV[strlen(DV)-1] = argv[1][1];
74 			break;
75 
76 		default:
77 			printf("Bad flag %s", argv[1]);
78 			break;
79 		}
80 	}
81 	signal(SIGINT, cleanup);
82 	signal(SIGQUIT, cleanup);
83 	signal(SIGHUP, cleanup);
84 	signal(SIGTERM, cleanup);
85 
86 	/*
87 	 * The "cu" host name is used to define the
88 	 * attributes of the generic dialer.
89 	 */
90 	(void)sprintf(sbuf, "cu%d", BR);
91 	if ((i = hunt(sbuf)) == 0) {
92 		printf("all ports busy\n");
93 		exit(3);
94 	}
95 	if (i == -1) {
96 		printf("link down\n");
97 		(void)uu_unlock(uucplock);
98 		exit(3);
99 	}
100 	setbuf(stdout, NULL);
101 	loginit();
102 	user_uid();
103 	vinit();
104 	setparity("none");
105 	boolean(value(VERBOSE)) = 0;
106 	if (HW)
107 		ttysetup(speed(BR));
108 	if (connect()) {
109 		printf("Connect failed\n");
110 		daemon_uid();
111 		(void)uu_unlock(uucplock);
112 		exit(1);
113 	}
114 	if (!HW)
115 		ttysetup(speed(BR));
116 }
117