1 /* 2 * Copyright (c) 1988, 1990 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)main.c 5.3 (Berkeley) 03/01/91"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 20 #include "ring.h" 21 #include "externs.h" 22 #include "defines.h" 23 24 /* 25 * Initialize variables. 26 */ 27 void 28 tninit() 29 { 30 init_terminal(); 31 32 init_network(); 33 34 init_telnet(); 35 36 init_sys(); 37 38 #if defined(TN3270) 39 init_3270(); 40 #endif 41 } 42 43 void 44 usage() 45 { 46 fprintf(stderr, "Usage: %s %s%s%s%s\n", 47 prompt, 48 #ifdef AUTHENTICATE 49 " [-8] [-E] [-K] [-L] [-X atype] [-a] [-d] [-e char] [-k realm]", 50 "\n\t[-l user] [-n tracefile] ", 51 #else 52 " [-8] [-E] [-L] [-a] [-d] [-e char] [-l user] [-n tracefile]", 53 "\n\t", 54 #endif 55 #if defined(TN3270) && defined(unix) 56 # ifdef AUTHENTICATE 57 "[-noasynch] [-noasynctty] [-noasyncnet]\n\t[-r] [-t transcom] ", 58 # else 59 "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t", 60 # endif 61 #else 62 "[-r] ", 63 #endif 64 #ifdef ENCRYPT 65 "[-x] [host-name [port]]" 66 #else 67 "[host-name [port]]" 68 #endif 69 ); 70 exit(1); 71 } 72 73 /* 74 * main. Parse arguments, invoke the protocol or command parser. 75 */ 76 77 78 main(argc, argv) 79 int argc; 80 char *argv[]; 81 { 82 extern char *optarg; 83 extern int optind; 84 int ch; 85 char *user, *strrchr(); 86 87 tninit(); /* Clear out things */ 88 #if defined(CRAY) && !defined(__STDC__) 89 _setlist_init(); /* Work around compiler bug */ 90 #endif 91 92 TerminalSaveState(); 93 94 if (prompt = strrchr(argv[0], '/')) 95 ++prompt; 96 else 97 prompt = argv[0]; 98 99 user = NULL; 100 101 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE; 102 autologin = -1; 103 104 while ((ch = getopt(argc, argv, "8EKLS:X:ade:k:l:n:rt:x")) != EOF) { 105 switch(ch) { 106 case '8': 107 eight = 3; /* binary output and input */ 108 break; 109 case 'E': 110 rlogin = escape = _POSIX_VDISABLE; 111 break; 112 case 'K': 113 #ifdef AUTHENTICATE 114 autologin = 0; 115 #endif 116 break; 117 case 'L': 118 eight |= 2; /* binary output only */ 119 break; 120 case 'S': 121 { 122 #ifdef HAS_GETTOS 123 extern int tos; 124 125 if ((tos = parsetos(optarg, "tcp")) < 0) 126 fprintf(stderr, "%s%s%s%s\n", 127 prompt, ": Bad TOS argument '", 128 optarg, 129 "; will try to use default TOS"); 130 #else 131 fprintf(stderr, 132 "%s: Warning: -S ignored, no parsetos() support.\n", 133 prompt); 134 #endif 135 } 136 break; 137 case 'X': 138 #ifdef AUTHENTICATE 139 auth_disable_name(optarg); 140 #endif 141 break; 142 case 'a': 143 autologin = 1; 144 break; 145 case 'd': 146 debug = 1; 147 break; 148 case 'e': 149 set_escape_char(optarg); 150 break; 151 case 'k': 152 #if defined(AUTHENTICATE) && defined(KRB4) 153 { 154 extern char *dest_realm, dst_realm_buf[], dst_realm_sz; 155 dest_realm = dst_realm_buf; 156 (void)strncpy(dest_realm, optarg, dst_realm_sz); 157 } 158 #else 159 fprintf(stderr, 160 "%s: Warning: -k ignored, no Kerberos V4 support.\n", 161 prompt); 162 #endif 163 break; 164 case 'l': 165 autologin = 1; 166 user = optarg; 167 break; 168 case 'n': 169 #if defined(TN3270) && defined(unix) 170 /* distinguish between "-n oasynch" and "-noasynch" */ 171 if (argv[optind - 1][0] == '-' && argv[optind - 1][1] 172 == 'n' && argv[optind - 1][2] == 'o') { 173 if (!strcmp(optarg, "oasynch")) { 174 noasynchtty = 1; 175 noasynchnet = 1; 176 } else if (!strcmp(optarg, "oasynchtty")) 177 noasynchtty = 1; 178 else if (!strcmp(optarg, "oasynchnet")) 179 noasynchnet = 1; 180 } else 181 #endif /* defined(TN3270) && defined(unix) */ 182 SetNetTrace(optarg); 183 break; 184 case 'r': 185 rlogin = '~'; 186 break; 187 case 't': 188 #if defined(TN3270) && defined(unix) 189 transcom = tline; 190 (void)strcpy(transcom, optarg); 191 #else 192 fprintf(stderr, 193 "%s: Warning: -t ignored, no TN3270 support.\n", 194 prompt); 195 #endif 196 break; 197 case 'x': 198 #ifdef ENCRYPT 199 encrypt_auto(); 200 #else 201 fprintf(stderr, 202 "%s: Warning: -x ignored, no ENCRYPT support.\n", 203 prompt); 204 #endif 205 break; 206 case '?': 207 default: 208 usage(); 209 /* NOTREACHED */ 210 } 211 } 212 if (autologin == -1) 213 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1; 214 215 argc -= optind; 216 argv += optind; 217 218 if (argc) { 219 char *args[7], **argp = args; 220 221 if (argc > 2) 222 usage(); 223 *argp++ = prompt; 224 if (user) { 225 *argp++ = "-l"; 226 *argp++ = user; 227 } 228 *argp++ = argv[0]; /* host */ 229 if (argc > 1) 230 *argp++ = argv[1]; /* port */ 231 *argp = 0; 232 233 if (setjmp(toplevel) != 0) 234 Exit(0); 235 if (tn(argp - args, args) == 1) 236 return (0); 237 else 238 return (1); 239 } 240 (void)setjmp(toplevel); 241 for (;;) { 242 #ifdef TN3270 243 if (shell_active) 244 shell_continue(); 245 else 246 #endif 247 command(1, 0, 0); 248 } 249 } 250