cu.c revision 28365
17527Sjkh/*
27527Sjkh * Copyright (c) 1983, 1993
37527Sjkh *	The Regents of the University of California.  All rights reserved.
47527Sjkh *
57527Sjkh * Redistribution and use in source and binary forms, with or without
67527Sjkh * modification, are permitted provided that the following conditions
77527Sjkh * are met:
87527Sjkh * 1. Redistributions of source code must retain the above copyright
97527Sjkh *    notice, this list of conditions and the following disclaimer.
107527Sjkh * 2. Redistributions in binary form must reproduce the above copyright
117527Sjkh *    notice, this list of conditions and the following disclaimer in the
127527Sjkh *    documentation and/or other materials provided with the distribution.
137527Sjkh * 3. All advertising materials mentioning features or use of this software
147527Sjkh *    must display the following acknowledgement:
157527Sjkh *	This product includes software developed by the University of
167527Sjkh *	California, Berkeley and its contributors.
177527Sjkh * 4. Neither the name of the University nor the names of its contributors
187527Sjkh *    may be used to endorse or promote products derived from this software
197527Sjkh *    without specific prior written permission.
207527Sjkh *
217527Sjkh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
227527Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
237527Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
247527Sjkh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
257527Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
267527Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
277527Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
287527Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
297527Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
307527Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
317527Sjkh * SUCH DAMAGE.
327527Sjkh */
337527Sjkh
347527Sjkh#ifndef lint
3528365Scharnier#if 0
367527Sjkhstatic char sccsid[] = "@(#)cu.c	8.1 (Berkeley) 6/6/93";
3728365Scharnier#endif
3828365Scharnierstatic const char rcsid[] =
3928365Scharnier	"$Id$";
407527Sjkh#endif /* not lint */
417527Sjkh
427527Sjkh#include "tipconf.h"
437527Sjkh#include "tip.h"
447527Sjkh
457527Sjkhvoid	cleanup();
467527Sjkh
477527Sjkh#if INCLUDE_CU_INTERFACE
487527Sjkh
497527Sjkh/*
507527Sjkh * Botch the interface to look like cu's
517527Sjkh */
527527Sjkhcumain(argc, argv)
537527Sjkh	char *argv[];
547527Sjkh{
557527Sjkh	register int i;
567527Sjkh	static char sbuf[12];
577527Sjkh
587527Sjkh	if (argc < 2) {
597527Sjkh		printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
607527Sjkh		exit(8);
617527Sjkh	}
627527Sjkh	CU = DV = NOSTR;
637527Sjkh	BR = DEFBR;
647527Sjkh	for (; argc > 1; argv++, argc--) {
657527Sjkh		if (argv[1][0] != '-')
667527Sjkh			PN = argv[1];
677527Sjkh		else switch (argv[1][1]) {
687527Sjkh
697527Sjkh		case 't':
707527Sjkh			HW = 1, DU = -1;
717527Sjkh			--argc;
727527Sjkh			continue;
737527Sjkh
747527Sjkh		case 'a':
757527Sjkh			CU = argv[2]; ++argv; --argc;
767527Sjkh			break;
777527Sjkh
787527Sjkh		case 's':
797527Sjkh			if (argc < 3 || speed(atoi(argv[2])) == 0) {
807527Sjkh				fprintf(stderr, "cu: unsupported speed %s\n",
817527Sjkh					argv[2]);
827527Sjkh				exit(3);
837527Sjkh			}
847527Sjkh			BR = atoi(argv[2]); ++argv; --argc;
857527Sjkh			break;
867527Sjkh
877527Sjkh		case 'l':
887527Sjkh			DV = argv[2]; ++argv; --argc;
897527Sjkh			break;
907527Sjkh
917527Sjkh		case '0': case '1': case '2': case '3': case '4':
927527Sjkh		case '5': case '6': case '7': case '8': case '9':
937527Sjkh			if (CU)
947527Sjkh				CU[strlen(CU)-1] = argv[1][1];
957527Sjkh			if (DV)
967527Sjkh				DV[strlen(DV)-1] = argv[1][1];
977527Sjkh			break;
987527Sjkh
997527Sjkh		default:
1007527Sjkh			printf("Bad flag %s", argv[1]);
1017527Sjkh			break;
1027527Sjkh		}
1037527Sjkh	}
1047527Sjkh	signal(SIGINT, cleanup);
1057527Sjkh	signal(SIGQUIT, cleanup);
1067527Sjkh	signal(SIGHUP, cleanup);
1077527Sjkh	signal(SIGTERM, cleanup);
1087527Sjkh
1097527Sjkh	/*
1107527Sjkh	 * The "cu" host name is used to define the
1117527Sjkh	 * attributes of the generic dialer.
1127527Sjkh	 */
1137527Sjkh	(void)sprintf(sbuf, "cu%d", BR);
1147527Sjkh	if ((i = hunt(sbuf)) == 0) {
1157527Sjkh		printf("all ports busy\n");
1167527Sjkh		exit(3);
1177527Sjkh	}
1187527Sjkh	if (i == -1) {
1197527Sjkh		printf("link down\n");
1207527Sjkh		(void)uu_unlock(uucplock);
1217527Sjkh		exit(3);
1227527Sjkh	}
1237527Sjkh	setbuf(stdout, NULL);
1247527Sjkh	loginit();
1257527Sjkh	user_uid();
1267527Sjkh	vinit();
1277527Sjkh	setparity("none");
1287527Sjkh	boolean(value(VERBOSE)) = 0;
1297527Sjkh	if (HW)
1307527Sjkh		ttysetup(speed(BR));
1317527Sjkh	if (connect()) {
1327527Sjkh		printf("Connect failed\n");
1337527Sjkh		daemon_uid();
1347527Sjkh		(void)uu_unlock(uucplock);
1357527Sjkh		exit(1);
1367527Sjkh	}
1377527Sjkh	if (!HW)
1387527Sjkh		ttysetup(speed(BR));
1397527Sjkh}
1407527Sjkh#endif /* INCLUDE_CU_INTERFACE */
141