first cut at real Jewish calendar
[unix-history] / usr / src / usr.bin / tip / cu.c
CommitLineData
051b1e55 1/*
c9686c12
KB
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.
051b1e55
DF
16 */
17
05862919 18#ifndef lint
981fd33c 19static char sccsid[] = "@(#)cu.c 5.8 (Berkeley) %G%";
c9686c12 20#endif /* not lint */
24f09632
SL
21
22#include "tip.h"
23
981fd33c 24void cleanup();
24f09632
SL
25
26/*
27 * Botch the interface to look like cu's
28 */
29cumain(argc, argv)
30 char *argv[];
31{
32 register int i;
c731dacc 33 static char sbuf[12];
24f09632 34
24f09632 35 if (argc < 2) {
c731dacc 36 printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
24f09632
SL
37 exit(8);
38 }
c731dacc 39 CU = DV = NOSTR;
b9847ed6 40 BR = DEFBR;
24f09632
SL
41 for (; argc > 1; argv++, argc--) {
42 if (argv[1][0] != '-')
43 PN = argv[1];
3f48242d 44 else switch (argv[1][1]) {
24f09632
SL
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':
b9847ed6 56 if (argc < 3 || speed(atoi(argv[2])) == 0) {
c731dacc
BS
57 fprintf(stderr, "cu: unsupported speed %s\n",
58 argv[2]);
24f09632
SL
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':
c731dacc
BS
70 if (CU)
71 CU[strlen(CU)-1] = argv[1][1];
72 if (DV)
73 DV[strlen(DV)-1] = argv[1][1];
24f09632
SL
74 break;
75
76 default:
77 printf("Bad flag %s", argv[1]);
78 break;
79 }
80 }
c731dacc
BS
81 signal(SIGINT, cleanup);
82 signal(SIGQUIT, cleanup);
83 signal(SIGHUP, cleanup);
84 signal(SIGTERM, cleanup);
85
24f09632
SL
86 /*
87 * The "cu" host name is used to define the
88 * attributes of the generic dialer.
89 */
9a491ec2
KB
90 (void)sprintf(sbuf, "cu%d", BR);
91 if ((i = hunt(sbuf)) == 0) {
24f09632
SL
92 printf("all ports busy\n");
93 exit(3);
94 }
95 if (i == -1) {
96 printf("link down\n");
5d369851 97 (void)uu_unlock(uucplock);
24f09632
SL
98 exit(3);
99 }
c731dacc
BS
100 setbuf(stdout, NULL);
101 loginit();
45d9e9af 102 user_uid();
c731dacc 103 vinit();
dfec50f2 104 setparity("none");
c731dacc 105 boolean(value(VERBOSE)) = 0;
24f09632
SL
106 if (HW)
107 ttysetup(speed(BR));
108 if (connect()) {
109 printf("Connect failed\n");
45d9e9af 110 daemon_uid();
5d369851 111 (void)uu_unlock(uucplock);
24f09632
SL
112 exit(1);
113 }
114 if (!HW)
115 ttysetup(speed(BR));
116}