9804 hal-set-property should support --direct option
[unleashed.git] / usr / src / cmd / tip / cu.c
blobfb911d64bd19ef119fbf1ca2f9c4aaad504dfa13
1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
12 #pragma ident "%Z%%M% %I% %E% SMI"
14 #include "tip.h"
16 void cleanup(void);
17 void timeout(void);
20 * Botch the interface to look like cu's
22 void
23 cumain(int argc, char *argv[])
25 int i;
26 static char sbuf[14];
28 if (argc < 2) {
29 usage:
30 (void) fprintf(stderr,
31 "usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
32 exit(8);
34 CU = DV = NOSTR;
35 for (; argc > 1; argv++, argc--) {
36 if (argv[1][0] != '-')
37 PN = argv[1];
38 else if (argv[1][1] != '\0' && argv[1][2] != '\0') {
39 (void) fprintf(stderr,
40 "cu: extra characters after flag: %s\n",
41 argv[1]);
42 goto usage;
43 } else switch (argv[1][1]) {
45 case 't':
46 HW = 1, DU = -1;
47 --argc;
48 continue;
50 case 'a':
51 CU = argv[2]; ++argv; --argc;
52 break;
54 case 's':
55 if (argc < 3)
56 goto usage;
57 if (speed(atoi(argv[2])) == 0) {
58 (void) fprintf(stderr,
59 "cu: unsupported speed %s\n",
60 argv[2]);
61 exit(3);
63 BR = atoi(argv[2]); ++argv; --argc;
64 break;
66 case 'l':
67 DV = argv[2]; ++argv; --argc;
68 break;
70 case '0': case '1': case '2': case '3': case '4':
71 case '5': case '6': case '7': case '8': case '9':
72 if (CU)
73 CU[strlen(CU)-1] = argv[1][1];
74 if (DV)
75 DV[strlen(DV)-1] = argv[1][1];
76 break;
78 default:
79 (void) fprintf(stderr, "cu: bad flag %s\n", argv[1]);
80 goto usage;
83 (void) signal(SIGINT, (sig_handler_t)cleanup);
84 (void) signal(SIGQUIT, (sig_handler_t)cleanup);
85 (void) signal(SIGHUP, (sig_handler_t)cleanup);
86 (void) signal(SIGTERM, (sig_handler_t)cleanup);
89 * The "cu" host name is used to define the
90 * attributes of the generic dialer.
92 (void) snprintf(sbuf, sizeof (sbuf), "cu%d", BR);
93 if ((i = hunt(sbuf)) == 0) {
94 (void) printf("all ports busy\n");
95 exit(3);
97 if (i == -1) {
98 (void) printf("link down\n");
99 delock(uucplock);
100 exit(3);
102 setbuf(stdout, NULL);
103 loginit();
104 gid = getgid();
105 egid = getegid();
106 uid = getuid();
107 euid = geteuid();
108 userperm();
109 vinit();
110 setparity("none");
111 boolean(value(VERBOSE)) = 0;
112 if (HW)
113 ttysetup(speed(BR));
114 if (connect()) {
115 (void) printf("Connect failed\n");
116 myperm();
117 delock(uucplock);
118 exit(1);
120 if (!HW)
121 ttysetup(speed(BR));