xref: /original-bsd/usr.bin/telnet/main.c (revision a141c157)
1 /*
2  * Copyright (c) 1988 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.
16  */
17 
18 #ifndef lint
19 char copyright[] =
20 "@(#) Copyright (c) 1988 Regents of the University of California.\n\
21  All rights reserved.\n";
22 #endif /* not lint */
23 
24 #ifndef lint
25 static char sccsid[] = "@(#)main.c	1.9 (Berkeley) 09/26/88";
26 #endif /* not lint */
27 
28 #include <sys/types.h>
29 
30 #include "ring.h"
31 
32 #include "externs.h"
33 #include "defines.h"
34 
35 /*
36  * Initialize variables.
37  */
38 
39 void
40 tninit()
41 {
42     init_terminal();
43 
44     init_network();
45 
46     init_telnet();
47 
48     init_sys();
49 
50     init_3270();
51 }
52 
53 
54 /*
55  * main.  Parse arguments, invoke the protocol or command parser.
56  */
57 
58 
59 int
60 main(argc, argv)
61 	int argc;
62 	char *argv[];
63 {
64     tninit();		/* Clear out things */
65 
66     TerminalSaveState();
67 
68     prompt = argv[0];
69     while ((argc > 1) && (argv[1][0] == '-')) {
70 	if (!strcmp(argv[1], "-d")) {
71 	    debug = 1;
72 	} else if (!strcmp(argv[1], "-n")) {
73 	    if ((argc > 1) && (argv[2][0] != '-')) {	/* get file name */
74 		NetTrace = fopen(argv[2], "w");
75 		argv++;
76 		argc--;
77 		if (NetTrace == NULL) {
78 		    NetTrace = stdout;
79 		}
80 	    }
81 	} else {
82 #if	defined(TN3270) && defined(unix)
83 	    if (!strcmp(argv[1], "-t")) {
84 		if ((argc > 1) && (argv[2][0] != '-')) { /* get file name */
85 		    transcom = tline;
86 		    (void) strcpy(transcom, argv[2]);
87 		    argv++;
88 		    argc--;
89 		}
90 	    } else if (!strcmp(argv[1], "-noasynch")) {
91 		noasynch = 1;
92 	    } else
93 #endif	/* defined(TN3270) && defined(unix) */
94 	    if (argv[1][1] != '\0') {
95 		fprintf(stderr, "Unknown option *%s*.\n", argv[1]);
96 	    }
97 	}
98 	argc--;
99 	argv++;
100     }
101     if (argc != 1) {
102 	if (setjmp(toplevel) != 0)
103 	    Exit(0);
104 	if (tn(argc, argv) == 1) {
105 	    return 0;
106 	} else {
107 	    return 1;
108 	}
109     }
110     (void) setjmp(toplevel);
111     for (;;) {
112 #if	!defined(TN3270)
113 	command(1);
114 #else	/* !defined(TN3270) */
115 	if (!shell_active) {
116 	    command(1);
117 	} else {
118 #if	defined(TN3270)
119 	    shell_continue();
120 #endif	/* defined(TN3270) */
121 	}
122 #endif	/* !defined(TN3270) */
123     }
124 }
125