main.c revision 1.2 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1988, 1990 Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.1 cgd char copyright[] =
36 1.1 cgd "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n\
37 1.1 cgd All rights reserved.\n";
38 1.1 cgd #endif /* not lint */
39 1.1 cgd
40 1.1 cgd #ifndef lint
41 1.2 mycroft /*static char sccsid[] = "from: @(#)main.c 5.4 (Berkeley) 3/22/91";*/
42 1.2 mycroft static char rcsid[] = "$Id: main.c,v 1.2 1993/08/01 18:07:24 mycroft Exp $";
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.1 cgd #include <sys/types.h>
46 1.1 cgd
47 1.1 cgd #include "ring.h"
48 1.1 cgd #include "externs.h"
49 1.1 cgd #include "defines.h"
50 1.1 cgd
51 1.1 cgd /*
52 1.1 cgd * Initialize variables.
53 1.1 cgd */
54 1.1 cgd void
55 1.1 cgd tninit()
56 1.1 cgd {
57 1.1 cgd init_terminal();
58 1.1 cgd
59 1.1 cgd init_network();
60 1.1 cgd
61 1.1 cgd init_telnet();
62 1.1 cgd
63 1.1 cgd init_sys();
64 1.1 cgd
65 1.1 cgd #if defined(TN3270)
66 1.1 cgd init_3270();
67 1.1 cgd #endif
68 1.1 cgd }
69 1.1 cgd
70 1.1 cgd void
71 1.1 cgd usage()
72 1.1 cgd {
73 1.1 cgd fprintf(stderr, "Usage: %s %s%s%s%s\n",
74 1.1 cgd prompt,
75 1.1 cgd #ifdef AUTHENTICATE
76 1.1 cgd " [-8] [-E] [-K] [-L] [-X atype] [-a] [-d] [-e char] [-k realm]",
77 1.1 cgd "\n\t[-l user] [-n tracefile] ",
78 1.1 cgd #else
79 1.1 cgd " [-8] [-E] [-L] [-a] [-d] [-e char] [-l user] [-n tracefile]",
80 1.1 cgd "\n\t",
81 1.1 cgd #endif
82 1.1 cgd #if defined(TN3270) && defined(unix)
83 1.1 cgd # ifdef AUTHENTICATE
84 1.1 cgd "[-noasynch] [-noasynctty] [-noasyncnet]\n\t[-r] [-t transcom] ",
85 1.1 cgd # else
86 1.1 cgd "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
87 1.1 cgd # endif
88 1.1 cgd #else
89 1.1 cgd "[-r] ",
90 1.1 cgd #endif
91 1.1 cgd #ifdef ENCRYPT
92 1.1 cgd "[-x] [host-name [port]]"
93 1.1 cgd #else
94 1.1 cgd "[host-name [port]]"
95 1.1 cgd #endif
96 1.1 cgd );
97 1.1 cgd exit(1);
98 1.1 cgd }
99 1.1 cgd
100 1.1 cgd /*
101 1.1 cgd * main. Parse arguments, invoke the protocol or command parser.
102 1.1 cgd */
103 1.1 cgd
104 1.1 cgd
105 1.1 cgd main(argc, argv)
106 1.1 cgd int argc;
107 1.1 cgd char *argv[];
108 1.1 cgd {
109 1.1 cgd extern char *optarg;
110 1.1 cgd extern int optind;
111 1.1 cgd int ch;
112 1.1 cgd char *user, *strrchr();
113 1.1 cgd
114 1.1 cgd tninit(); /* Clear out things */
115 1.1 cgd #if defined(CRAY) && !defined(__STDC__)
116 1.1 cgd _setlist_init(); /* Work around compiler bug */
117 1.1 cgd #endif
118 1.1 cgd
119 1.1 cgd TerminalSaveState();
120 1.1 cgd
121 1.1 cgd if (prompt = strrchr(argv[0], '/'))
122 1.1 cgd ++prompt;
123 1.1 cgd else
124 1.1 cgd prompt = argv[0];
125 1.1 cgd
126 1.1 cgd user = NULL;
127 1.1 cgd
128 1.1 cgd rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
129 1.1 cgd autologin = -1;
130 1.1 cgd
131 1.1 cgd while ((ch = getopt(argc, argv, "8EKLS:X:ade:k:l:n:rt:x")) != EOF) {
132 1.1 cgd switch(ch) {
133 1.1 cgd case '8':
134 1.1 cgd eight = 3; /* binary output and input */
135 1.1 cgd break;
136 1.1 cgd case 'E':
137 1.1 cgd rlogin = escape = _POSIX_VDISABLE;
138 1.1 cgd break;
139 1.1 cgd case 'K':
140 1.1 cgd #ifdef AUTHENTICATE
141 1.1 cgd autologin = 0;
142 1.1 cgd #endif
143 1.1 cgd break;
144 1.1 cgd case 'L':
145 1.1 cgd eight |= 2; /* binary output only */
146 1.1 cgd break;
147 1.1 cgd case 'S':
148 1.1 cgd {
149 1.1 cgd #ifdef HAS_GETTOS
150 1.1 cgd extern int tos;
151 1.1 cgd
152 1.1 cgd if ((tos = parsetos(optarg, "tcp")) < 0)
153 1.1 cgd fprintf(stderr, "%s%s%s%s\n",
154 1.1 cgd prompt, ": Bad TOS argument '",
155 1.1 cgd optarg,
156 1.1 cgd "; will try to use default TOS");
157 1.1 cgd #else
158 1.1 cgd fprintf(stderr,
159 1.1 cgd "%s: Warning: -S ignored, no parsetos() support.\n",
160 1.1 cgd prompt);
161 1.1 cgd #endif
162 1.1 cgd }
163 1.1 cgd break;
164 1.1 cgd case 'X':
165 1.1 cgd #ifdef AUTHENTICATE
166 1.1 cgd auth_disable_name(optarg);
167 1.1 cgd #endif
168 1.1 cgd break;
169 1.1 cgd case 'a':
170 1.1 cgd autologin = 1;
171 1.1 cgd break;
172 1.1 cgd case 'c':
173 1.1 cgd skiprc = 1;
174 1.1 cgd break;
175 1.1 cgd case 'd':
176 1.1 cgd debug = 1;
177 1.1 cgd break;
178 1.1 cgd case 'e':
179 1.1 cgd set_escape_char(optarg);
180 1.1 cgd break;
181 1.1 cgd case 'k':
182 1.1 cgd #if defined(AUTHENTICATE) && defined(KRB4)
183 1.1 cgd {
184 1.1 cgd extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
185 1.1 cgd dest_realm = dst_realm_buf;
186 1.1 cgd (void)strncpy(dest_realm, optarg, dst_realm_sz);
187 1.1 cgd }
188 1.1 cgd #else
189 1.1 cgd fprintf(stderr,
190 1.1 cgd "%s: Warning: -k ignored, no Kerberos V4 support.\n",
191 1.1 cgd prompt);
192 1.1 cgd #endif
193 1.1 cgd break;
194 1.1 cgd case 'l':
195 1.1 cgd autologin = 1;
196 1.1 cgd user = optarg;
197 1.1 cgd break;
198 1.1 cgd case 'n':
199 1.1 cgd #if defined(TN3270) && defined(unix)
200 1.1 cgd /* distinguish between "-n oasynch" and "-noasynch" */
201 1.1 cgd if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
202 1.1 cgd == 'n' && argv[optind - 1][2] == 'o') {
203 1.1 cgd if (!strcmp(optarg, "oasynch")) {
204 1.1 cgd noasynchtty = 1;
205 1.1 cgd noasynchnet = 1;
206 1.1 cgd } else if (!strcmp(optarg, "oasynchtty"))
207 1.1 cgd noasynchtty = 1;
208 1.1 cgd else if (!strcmp(optarg, "oasynchnet"))
209 1.1 cgd noasynchnet = 1;
210 1.1 cgd } else
211 1.1 cgd #endif /* defined(TN3270) && defined(unix) */
212 1.1 cgd SetNetTrace(optarg);
213 1.1 cgd break;
214 1.1 cgd case 'r':
215 1.1 cgd rlogin = '~';
216 1.1 cgd break;
217 1.1 cgd case 't':
218 1.1 cgd #if defined(TN3270) && defined(unix)
219 1.1 cgd transcom = tline;
220 1.1 cgd (void)strcpy(transcom, optarg);
221 1.1 cgd #else
222 1.1 cgd fprintf(stderr,
223 1.1 cgd "%s: Warning: -t ignored, no TN3270 support.\n",
224 1.1 cgd prompt);
225 1.1 cgd #endif
226 1.1 cgd break;
227 1.1 cgd case 'x':
228 1.1 cgd #ifdef ENCRYPT
229 1.1 cgd encrypt_auto(1);
230 1.1 cgd decrypt_auto(1);
231 1.1 cgd #else
232 1.1 cgd fprintf(stderr,
233 1.1 cgd "%s: Warning: -x ignored, no ENCRYPT support.\n",
234 1.1 cgd prompt);
235 1.1 cgd #endif
236 1.1 cgd break;
237 1.1 cgd case '?':
238 1.1 cgd default:
239 1.1 cgd usage();
240 1.1 cgd /* NOTREACHED */
241 1.1 cgd }
242 1.1 cgd }
243 1.1 cgd if (autologin == -1)
244 1.1 cgd autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
245 1.1 cgd
246 1.1 cgd argc -= optind;
247 1.1 cgd argv += optind;
248 1.1 cgd
249 1.1 cgd if (argc) {
250 1.1 cgd char *args[7], **argp = args;
251 1.1 cgd
252 1.1 cgd if (argc > 2)
253 1.1 cgd usage();
254 1.1 cgd *argp++ = prompt;
255 1.1 cgd if (user) {
256 1.1 cgd *argp++ = "-l";
257 1.1 cgd *argp++ = user;
258 1.1 cgd }
259 1.1 cgd *argp++ = argv[0]; /* host */
260 1.1 cgd if (argc > 1)
261 1.1 cgd *argp++ = argv[1]; /* port */
262 1.1 cgd *argp = 0;
263 1.1 cgd
264 1.1 cgd if (setjmp(toplevel) != 0)
265 1.1 cgd Exit(0);
266 1.1 cgd if (tn(argp - args, args) == 1)
267 1.1 cgd return (0);
268 1.1 cgd else
269 1.1 cgd return (1);
270 1.1 cgd }
271 1.1 cgd (void)setjmp(toplevel);
272 1.1 cgd for (;;) {
273 1.1 cgd #ifdef TN3270
274 1.1 cgd if (shell_active)
275 1.1 cgd shell_continue();
276 1.1 cgd else
277 1.1 cgd #endif
278 1.1 cgd command(1, 0, 0);
279 1.1 cgd }
280 1.1 cgd }
281