Flush out the last dregs in the terminal before quitting when
[unix-history] / usr / src / usr.bin / telnet / main.c
CommitLineData
897ce52e
KB
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
b36fc510
KB
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.
897ce52e
KB
16 */
17
18#ifndef lint
19char 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
4ad36dea 25static char sccsid[] = "@(#)main.c 1.10 (Berkeley) %G%";
897ce52e
KB
26#endif /* not lint */
27
115a5494
GM
28#include <sys/types.h>
29
30#include "ring.h"
31
6f6e51bd
GM
32#include "externs.h"
33#include "defines.h"
34
35/*
36 * Initialize variables.
37 */
38
39void
40tninit()
41{
6f6e51bd
GM
42 init_terminal();
43
44 init_network();
45
46 init_telnet();
b307f09e
GM
47
48 init_sys();
ee2a19ae
GM
49
50 init_3270();
6f6e51bd
GM
51}
52
53
54/*
55 * main. Parse arguments, invoke the protocol or command parser.
56 */
57
58
80a47e22 59int
6f6e51bd
GM
60main(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;
7673a54e 86 (void) strcpy(transcom, argv[2]);
6f6e51bd
GM
87 argv++;
88 argc--;
89 }
90 } else if (!strcmp(argv[1], "-noasynch")) {
4ad36dea
GM
91 noasynchtty = 1;
92 noasynchnet = 1;
93 } else if (!strcmp(argv[1], "-noasynchtty")) {
94 noasynchtty = 1;
95 } else if (!strcmp(argv[1], "-noasynchnet")) {
96 noasynchnet = 1;
6f6e51bd
GM
97 } else
98#endif /* defined(TN3270) && defined(unix) */
99 if (argv[1][1] != '\0') {
100 fprintf(stderr, "Unknown option *%s*.\n", argv[1]);
101 }
102 }
103 argc--;
104 argv++;
105 }
106 if (argc != 1) {
107 if (setjmp(toplevel) != 0)
108 Exit(0);
80a47e22
GM
109 if (tn(argc, argv) == 1) {
110 return 0;
111 } else {
112 return 1;
113 }
6f6e51bd 114 }
80a47e22 115 (void) setjmp(toplevel);
6f6e51bd
GM
116 for (;;) {
117#if !defined(TN3270)
118 command(1);
119#else /* !defined(TN3270) */
120 if (!shell_active) {
121 command(1);
122 } else {
123#if defined(TN3270)
124 shell_continue();
125#endif /* defined(TN3270) */
126 }
127#endif /* !defined(TN3270) */
128 }
129}