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

  1. /***************************/
  2. /* OS/2 API support        */
  3. /***************************/
  4. #define OS2
  5. #define INCL_DOS
  6. #define INCL_VIO
  7. #define INCL_BASE
  8. #include <os2.h>
  9. #undef COMMENT
  10.  
  11. /***************************/
  12. /* Microsoft C runtime     */
  13. /***************************/
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <process.h>
  18. #include <signal.h>
  19. #include <errno.h>
  20. #include <io.h>
  21. #include <direct.h>
  22. #include <memory.h>
  23. #include <sys/types.h>
  24.  
  25. #ifdef __IBMC__
  26. #define off_t _dummy_off_t  /* avoid warning */
  27. #include <types.h>
  28. #undef off_t
  29. #else
  30. #include <types.h>
  31. #endif
  32. #include <netinet/in.h>
  33. #include <netdb.h>
  34. #include <sys/ioctl.h>
  35. #include <sys/socket.h>
  36.  
  37. void _System addsockettolist(int socket);
  38.  
  39. void
  40. cleanupsocket( int socket )
  41. {
  42.     char * msg = "Unable to start Internet Kermit Service for OS/2\r\nClosing socket.\r\n\n";
  43.  
  44.     sock_init();
  45.     addsockettolist( socket );
  46.     send(socket, msg, strlen(msg), 0);
  47.     soclose( socket );
  48. }
  49.  
  50. int 
  51. main(int argc, char *argv[], char * envp[])
  52. {
  53.     int socket=0;
  54.     int rc=0;
  55.     int i;
  56.     char * script=NULL;
  57.     char * p=NULL;
  58.     char cmdline[1024]="";
  59.     char loadpath[257]="";
  60.     RESULTCODES resultcodes;
  61.     STARTDATA   sdata;
  62.     ULONG       sessionid;
  63.     PID     pid;
  64.     char        achObjBuf[256] = {0};     /* Error data if DosStart fails */
  65.  
  66. #ifdef DEBUG
  67.     for ( i=0;i<argc;i++ )
  68.     printf("arg%d=%s\n",i,argv[i]);
  69. #endif
  70.  
  71.     if (argc < 2) {
  72.         printf("Usage: %s [<IKS command line parameters>] <socket>\n",
  73.         argv[0]);
  74.     if ( argc == 2 ) {
  75.         socket = atoi(argv[1]);        /* required last parameter = socket  */
  76.         cleanupsocket(socket);
  77.     }
  78.         DosExit(1,1);
  79.     } /* endif */
  80.  
  81.     socket = atoi(argv[argc-1]);        /* required last parameter = socket  */
  82.  
  83.     sprintf(cmdline, "-N X -# 132 -A %d", 
  84.          socket, script);
  85.  
  86.     for (i=1;i<argc-1;i++) {         /* append additional parameters */
  87.     strcat(cmdline," ");
  88.     strcat(cmdline,argv[i]);
  89.     }
  90.  
  91.     strcpy(loadpath, argv[0]);
  92.     p = loadpath + strlen(loadpath);
  93.     while ( *p != '\\' && *p != '/' )
  94.     p--;
  95.     *p = '\0';
  96.     printf("changing directory to %s\n",loadpath);
  97.     chdir(loadpath);
  98.  
  99.     strcat(loadpath,"\\k2.exe");
  100.  
  101.     printf("%s %s\n",loadpath,cmdline);
  102.  
  103.     sdata.Length  = sizeof(STARTDATA);
  104.     sdata.Related = SSF_RELATED_INDEPENDENT; /* start a Child for PID */
  105.                                              /* not SSF_RELATED_CHILD */
  106.     sdata.FgBg    = SSF_FGBG_BACK;           /* start session in foreground  */
  107.     sdata.TraceOpt = SSF_TRACEOPT_NONE;      /* No trace                     */
  108.                                              /* Start an OS/2 session using "CMD.EXE /K" */
  109.     sdata.PgmTitle = NULL;
  110.     sdata.PgmName = loadpath;
  111.     sdata.PgmInputs = cmdline;                      /* Keep session up           */
  112.  
  113.     sdata.TermQ = 0;                            /* No termination queue      */
  114.     sdata.Environment = 0;                      /* No environment string     */
  115.     sdata.InheritOpt = SSF_INHERTOPT_PARENT;    /* Inherit parent's environ.  */
  116.     sdata.SessionType = SSF_TYPE_WINDOWABLEVIO; /* Windowed VIO session      */
  117.     sdata.IconFile = 0;                         /* No icon association       */
  118.     sdata.PgmHandle = 0;
  119.     /* Open the session VISIBLE and MAXIMIZED */
  120.     sdata.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MINIMIZE;
  121.     sdata.InitXPos  = 30;     /* Initial window coordinates              */
  122.     sdata.InitYPos  = 40;
  123.     sdata.InitXSize = 200;    /* Initial window size */
  124.     sdata.InitYSize = 140;
  125.     sdata.Reserved = 0;
  126.     sdata.ObjectBuffer  = achObjBuf; /* Contains info if DosExecPgm fails */
  127.     sdata.ObjectBuffLen = (ULONG) sizeof(achObjBuf);
  128.  
  129.     rc = DosStartSession(&sdata,&sessionid,&pid);
  130. #ifdef DEBUG
  131.     printf("rc = %d :: %s\n",rc,achObjBuf);
  132. #endif
  133.     if ( rc && rc != 457 ) {
  134.     printf("ERROR: Unable to start K2.EXE -- closing socket %d\n\n",socket);
  135.     cleanupsocket(socket);
  136.     }
  137.     return(rc);
  138. }
  139.