home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckotel.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  8KB  |  294 lines

  1. /* C K O T E L  --  Kermit stub to fake IBM Telnet and IBM TelnetPM */
  2.  
  3. /*
  4.   Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  5.             Columbia University Academic Information Systems, New York City.
  6.           Jeffrey E Altman <jaltman@secure-endpoints.com>
  7.             Secure Endpoints Inc., New York City
  8.  
  9.   Copyright (C) 1996,2004 Trustees of Columbia University in the City of New
  10.   York.
  11. */
  12.  
  13. /*
  14. telnet.exe -?
  15. Telnet - 08:32:06 on Sep 27 1994.
  16.  
  17. Usage: telnet [-c codepage] [-d filename] [-e envlist]
  18.               [-f config]   [-h height]   [-k keyboard]
  19.               [-l filename] [-o printer]  [-p port]
  20.               [-t termtype] [-u color]    [-w width]    [hostname]
  21.  
  22. Option:
  23.   -?            display this help message
  24.   -c codepage   specify code page translation table
  25.   -d filename   specify debugging filename
  26.   -e envlist    specify environment variables
  27.   -f config     specify configuration filename in <ETC> directory
  28.   -h height     specify screen height
  29.   -k keyboard   specify keyboard type
  30.   -l filename   specify logging filename
  31.   -o printer    specify local printer port name
  32.   -p port       specify remote port number
  33.   -t termtype   specify terminal emulator type
  34.   -u color      specify color for underline
  35.   -w width      specify screen width
  36.  
  37. The goal of this program is to simulate this interface and construct a
  38. proper command line for C-Kermit.  Then call C-Kermit in the place of
  39. telnet.exe or telnetpm.exe and perform the same functionality.
  40.  
  41. According to <sad@utl.edu> IBM changed -c to -cp and added -N to ignore 8th bit
  42. (in other words, apply parity).
  43. */
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49. char* codepage = NULL,
  50.     * debuglog = NULL,
  51.     * envlist  = NULL,
  52.     * config   = NULL,
  53.     * height   = NULL,
  54.     * keyboard = NULL,
  55.     * sessionlog = NULL,
  56.     * printerfile = NULL,
  57.     * tn_port = NULL,
  58.     * termtype = NULL,
  59.     * underline = NULL,
  60.     * width = NULL,
  61.     * hostname = NULL ;
  62. char ckermitcmd[4096] ;
  63.  
  64. void
  65. printhelp( char * progname )
  66. {
  67. printf("%s -? - Version 1.0a\n",progname);
  68. printf("OS/2 C-Kermit Telnet Stub - allows calls to IBM Telnet or IBM TelnetPM\n");
  69. printf("                            to be redirected to OS/2 C-Kermit.\n");
  70. printf("Copyright (C) 1996, Trustees of Columbia University\n\n");
  71. printf("Usage: telnet [-c codepage] [-d filename] [-e envlist]\n");
  72. printf("              [-f config]   [-h height]   [-k keyboard]\n");
  73. printf("              [-l filename] [-n]          [-o printer] [-p port]\n");
  74. printf("              [-t termtype] [-u color]    [-w width]   [hostname]\n");
  75. printf("Option:\n");
  76. printf("  -?            display this help message\n");
  77. printf("  -c codepage   specify code page translation table\n");
  78. printf("  -d filename   specify debugging filename\n");
  79. printf("  -e envlist    specify environment variables\n");
  80. printf("  -f config     specify configuration filename in <ETC> directory\n");
  81. printf("  -h height     specify screen height\n");
  82. printf("  -k keyboard   specify keyboard type\n");
  83. printf("  -l filename   specify logging filename\n");
  84. printf("  -n            ignore 8th bit\n");
  85. printf("  -o printer    specify local printer port name\n");
  86. printf("  -p port       specify remote port number\n");
  87. printf("  -t termtype   specify terminal emulator type\n");
  88. printf("  -u color      specify color for underline\n");
  89. printf("  -w width      specify screen width\n");
  90. }
  91.  
  92. void
  93. constructcmdline( char * exename )
  94. {
  95.     char * s = ckermitcmd ;
  96.     *s = '\0' ;
  97.     strcat( s, exename ) ;
  98.     strcat( s, " -C \"set terminal code-page 850" );
  99.  
  100.     if ( debuglog ) {
  101.         if (*s!='\0')
  102.             strcat( s, ", " );
  103.         strcat( s, "log debug " );
  104.         strcat( s, debuglog );
  105.         }
  106.  
  107.     if ( sessionlog ) {
  108.         if (*s!='\0')
  109.             strcat( s, ", " );
  110.         strcat( s, "log session " );
  111.         strcat( s, sessionlog );
  112.         }
  113.  
  114.     if ( codepage ) {
  115.         if (*s!='\0')
  116.             strcat( s, ", " );
  117.         strcat( s, "set terminal character-set " );
  118.         if ( !strcmp( strlwr(codepage), "tcpdecmu" ) )
  119.             strcat( s, "dec-multinational" ) ;
  120.         else if ( !strcmp( codepage, "tcp8859" ) )
  121.             strcat( s, "latin-1" ) ;
  122.         else
  123.             strcat( s, "cp850" ) ;
  124.         }
  125.  
  126.     if ( height ) {
  127.         if (*s!='\0')
  128.             strcat( s, ", " );
  129.         strcat( s, "set terminal height " );
  130.         strcat( s, height );
  131.         }
  132.  
  133.     if ( width ) {
  134.         if (*s!='\0')
  135.             strcat( s, ", " );
  136.         strcat( s, "set terminal width " );
  137.         strcat( s, width );
  138.         }
  139.  
  140.     if ( printerfile ) {
  141.         if (*s!='\0')
  142.             strcat( s, ", " );
  143.         strcat( s, "set printer " );
  144.         strcat( s, printerfile );
  145.         }
  146.  
  147.     if ( termtype ) {
  148.         if (*s!='\0')
  149.             strcat( s, ", " );
  150.         strcat( s, "set terminal type " );
  151.         strcat( s, termtype );
  152.         }
  153.  
  154.     if (*s!='\0')
  155.         strcat( s, ", " );
  156.     strcat( s, "set exit on-disconnect on" ) ;
  157.  
  158.     if ( hostname ) {
  159.         if (*s!='\0')
  160.             strcat( s, ", " );
  161.         strcat( s, "telnet " );
  162.         strcat( s, hostname );
  163.         if ( tn_port ) {
  164.             strcat( s, " " ) ;
  165.             strcat( s, tn_port ) ;
  166.         }
  167.         strcat( s, ", if failure exit" );
  168.     }
  169.  
  170.     strcat( s, "\"" );
  171. };
  172.  
  173. int
  174. parsecmdline( int argc, char ** argv )
  175. {
  176.     int n = 0 ;
  177.     while ( ++n < argc ) {
  178.         if (argv[n][0] != '-' && argv[n][0] != '/') {
  179.             /* then we have found the host name */
  180.             hostname = argv[n] ;
  181.             continue ;
  182.             }
  183.  
  184.         switch ( argv[n][1] ) {
  185.             case 'S':
  186.             case 's':
  187.                 /* don't know what 's' is, but it is generated
  188.                     by the template, it doesn't have a parameter */
  189.                 break;
  190.  
  191.             case 'C':
  192.             case 'c':
  193.                 codepage = argv[++n] ;
  194.                 break;
  195.  
  196.             case 'D':
  197.             case 'd':
  198.                 debuglog = argv[++n] ;
  199.                 break;
  200.  
  201.             case 'E':
  202.             case 'e':
  203.                 envlist = argv[++n] ;
  204.                 break;
  205.  
  206.             case 'F':
  207.             case 'f':
  208.                 config = argv[++n] ;
  209.                 break;
  210.  
  211.             case 'H':
  212.             case 'h':
  213.                 height = argv[++n] ;
  214.                 break;
  215.  
  216.             case 'K':
  217.             case 'k':
  218.                 keyboard = argv[++n] ;
  219.                 break;
  220.  
  221.             case 'L':
  222.             case 'l':
  223.                 sessionlog = argv[++n] ;
  224.                 break;
  225.  
  226.             case 'O':
  227.             case 'o':
  228.                 printerfile = argv[++n] ;
  229.                 break;
  230.  
  231.             case 'P':
  232.             case 'p':
  233.                 tn_port = argv[++n] ;
  234.                 break;
  235.  
  236.             case 'T':
  237.             case 't':
  238.                 termtype = argv[++n] ;
  239.                 break;
  240.  
  241.             case 'U':
  242.             case 'u':
  243.                 underline = argv[++n] ;
  244.                 break;
  245.  
  246.             case 'W':
  247.             case 'w':
  248.                 width = argv[++n] ;
  249.                 break;
  250.  
  251.             case 'N':
  252.             case 'n':
  253.                 /* ignore */
  254.                 break;
  255.  
  256.             case '?':
  257.                 printhelp( argv[0] ) ;
  258.                 return 1 ;
  259.                 break;
  260.  
  261.             default:
  262.                 printf("ERROR: Illegal flag \"-%c\"\n", argv[n][1] );
  263.                 {
  264.                 int m = 0 ;
  265.                 for ( m = 0 ; m < argc ; m++ )
  266.                     printf( "%s ", argv[m] ) ;
  267.                 printf("\n");
  268.                 }
  269.                 printhelp( argv[0] ) ;
  270. #ifndef NT
  271.                 DosSleep( 10000 ) ;
  272. #endif
  273.                 return 1 ;
  274.             }
  275.         }
  276.     return 0;
  277. };
  278.  
  279. int
  280. main( int argc, char**argv )
  281. {
  282.     int rc = 0;
  283.     if ( parsecmdline( argc, argv ) )
  284.         return 1 ;
  285.  
  286.     constructcmdline("k2.exe") ;
  287.     rc = system( ckermitcmd ) ;
  288.     if ( rc == -1 ) {
  289.         constructcmdline("ckermit.exe");
  290.         rc = system( ckermitcmd ) ;
  291.     }
  292.     return rc;
  293. } ;
  294.