Advertisement
Guest User

notepad_test

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