xref: /csrg-svn/usr.bin/telnet/main.c (revision 35717)
133685Sbostic /*
233685Sbostic  * Copyright (c) 1988 Regents of the University of California.
333685Sbostic  * All rights reserved.
433685Sbostic  *
533685Sbostic  * Redistribution and use in source and binary forms are permitted
634898Sbostic  * provided that the above copyright notice and this paragraph are
734898Sbostic  * duplicated in all such forms and that any documentation,
834898Sbostic  * advertising materials, and other materials related to such
934898Sbostic  * distribution and use acknowledge that the software was developed
1034898Sbostic  * by the University of California, Berkeley.  The name of the
1134898Sbostic  * University may not be used to endorse or promote products derived
1234898Sbostic  * from this software without specific prior written permission.
1334898Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434898Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534898Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633685Sbostic  */
1733685Sbostic 
1833685Sbostic #ifndef lint
1933685Sbostic char copyright[] =
2033685Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\
2133685Sbostic  All rights reserved.\n";
2233685Sbostic #endif /* not lint */
2333685Sbostic 
2433685Sbostic #ifndef lint
25*35717Smckusick static char sccsid[] = "@(#)main.c	1.9 (Berkeley) 09/26/88";
2633685Sbostic #endif /* not lint */
2733685Sbostic 
2832381Sminshall #include <sys/types.h>
2932381Sminshall 
3032381Sminshall #include "ring.h"
3132381Sminshall 
3232145Sminshall #include "externs.h"
3332145Sminshall #include "defines.h"
3432145Sminshall 
3532145Sminshall /*
3632145Sminshall  * Initialize variables.
3732145Sminshall  */
3832145Sminshall 
3932145Sminshall void
4032145Sminshall tninit()
4132145Sminshall {
4232145Sminshall     init_terminal();
4332145Sminshall 
4432145Sminshall     init_network();
4532145Sminshall 
4632145Sminshall     init_telnet();
4732531Sminshall 
4832531Sminshall     init_sys();
4934302Sminshall 
5034302Sminshall     init_3270();
5132145Sminshall }
5232145Sminshall 
5332145Sminshall 
5432145Sminshall /*
5532145Sminshall  * main.  Parse arguments, invoke the protocol or command parser.
5632145Sminshall  */
5732145Sminshall 
5832145Sminshall 
5934849Sminshall int
6032145Sminshall main(argc, argv)
6132145Sminshall 	int argc;
6232145Sminshall 	char *argv[];
6332145Sminshall {
6432145Sminshall     tninit();		/* Clear out things */
6532145Sminshall 
6632145Sminshall     TerminalSaveState();
6732145Sminshall 
6832145Sminshall     prompt = argv[0];
6932145Sminshall     while ((argc > 1) && (argv[1][0] == '-')) {
7032145Sminshall 	if (!strcmp(argv[1], "-d")) {
7132145Sminshall 	    debug = 1;
7232145Sminshall 	} else if (!strcmp(argv[1], "-n")) {
7332145Sminshall 	    if ((argc > 1) && (argv[2][0] != '-')) {	/* get file name */
7432145Sminshall 		NetTrace = fopen(argv[2], "w");
7532145Sminshall 		argv++;
7632145Sminshall 		argc--;
7732145Sminshall 		if (NetTrace == NULL) {
7832145Sminshall 		    NetTrace = stdout;
7932145Sminshall 		}
8032145Sminshall 	    }
8132145Sminshall 	} else {
8232145Sminshall #if	defined(TN3270) && defined(unix)
8332145Sminshall 	    if (!strcmp(argv[1], "-t")) {
8432145Sminshall 		if ((argc > 1) && (argv[2][0] != '-')) { /* get file name */
8532145Sminshall 		    transcom = tline;
86*35717Smckusick 		    (void) strcpy(transcom, argv[2]);
8732145Sminshall 		    argv++;
8832145Sminshall 		    argc--;
8932145Sminshall 		}
9032145Sminshall 	    } else if (!strcmp(argv[1], "-noasynch")) {
9132145Sminshall 		noasynch = 1;
9232145Sminshall 	    } else
9332145Sminshall #endif	/* defined(TN3270) && defined(unix) */
9432145Sminshall 	    if (argv[1][1] != '\0') {
9532145Sminshall 		fprintf(stderr, "Unknown option *%s*.\n", argv[1]);
9632145Sminshall 	    }
9732145Sminshall 	}
9832145Sminshall 	argc--;
9932145Sminshall 	argv++;
10032145Sminshall     }
10132145Sminshall     if (argc != 1) {
10232145Sminshall 	if (setjmp(toplevel) != 0)
10332145Sminshall 	    Exit(0);
10434849Sminshall 	if (tn(argc, argv) == 1) {
10534849Sminshall 	    return 0;
10634849Sminshall 	} else {
10734849Sminshall 	    return 1;
10834849Sminshall 	}
10932145Sminshall     }
11034849Sminshall     (void) setjmp(toplevel);
11132145Sminshall     for (;;) {
11232145Sminshall #if	!defined(TN3270)
11332145Sminshall 	command(1);
11432145Sminshall #else	/* !defined(TN3270) */
11532145Sminshall 	if (!shell_active) {
11632145Sminshall 	    command(1);
11732145Sminshall 	} else {
11832145Sminshall #if	defined(TN3270)
11932145Sminshall 	    shell_continue();
12032145Sminshall #endif	/* defined(TN3270) */
12132145Sminshall 	}
12232145Sminshall #endif	/* !defined(TN3270) */
12332145Sminshall     }
12432145Sminshall }
125