/*
 *  CopyRight 1995. Nicholas Poljakov all rights reserved.
 */
/*************************  REM_CD.C  ***************************/
/*                 cd for remote disk                           */
/****************************************************************/

#include <dos.h>
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <state1.h>


extern char lu_id[8];
extern char tp_id[8];
extern char tp_exist;
extern char *pa[2];
extern struct  part {            /* partner structure */
		  char	 plu[8] ;	     /* str plu_name	    */
                  int psl;                    /* str plu_s_limit     */
		  char	 mode_name[8] ;	     /* str mode_name	    */
                  int max_ru_size;            /* str ru_h_size       */
                  int pacing;                 /* str =               */
                  unsigned char lu_type;
               }  pstr[4];
ExeFl(char *,int);
RemCom(int);

rem_cd(e_ptr, from)
int from;
struct f_name {
                struct f_name *next;
                struct f_name *prev;
                char   ind;
                unsigned int time;
                unsigned int date;
                unsigned long int size;
                char   name[12];
               } *e_ptr;
{
    unsigned  long conv_id;
    unsigned char rts;
    unsigned char wr;
    unsigned int max_length ;
    unsigned  char tpn[64];
    char *p;
    struct rc {
                unsigned int prim;
                unsigned long sec;
              } v_rc;
    unsigned long rc;
    char p_lu[9];
    char p_mode[9];
    int length;
    char gds[2];

              p = e_ptr -> name;
              if (!tp_exist) {
                                tp_started
                                            (lu_id,
                                             tp_id,
                                             &rc);
                                if (rc != 0) {
                                                return (-1);
                                              }
                                tp_exist = 1; /* TP_started O.K! */
                             }

              strcpy (tpn,"DIR "); /* name of work */
              strcat (tpn, "cd ");      /* name of sub-funct */
              strcat (tpn, p );      /* name of new directory */
              /*conv_id - return param -id work link */
              strcpy(p_lu, pstr[from].plu);
              strcpy(p_mode, pstr[from].mode_name);
                   allocate  (p_lu,
                              p_mode,
                              tpn,
                              WHEN_SESSION_ALLOCATED,
                              NONE,
                              NONE,
                              NULL,
                              NULL,
                              tp_id,
                              &conv_id,
                              NULL,
                              &v_rc) ;


                  if (v_rc.prim != 0) {
                                          return (-1);
                                       }
              max_length = 2017;
              recwait (tp_id,
                    conv_id,
                    ll,
                    &v_rc,
                    &length,
                    max_length,
                    &rts,
                    &gds,
                    &wr);
                  rem_path(pa[0], from);
       return 0;
}
ExeFl(char *CurFile,int to){
    unsigned  long conv_id;
    unsigned char rts;
    unsigned char wr;
    unsigned int max_length ;
    unsigned  char tpn[64];
    char *p;
    struct rc {
                unsigned int prim;
                unsigned long sec;
              } v_rc;
    unsigned long rc;
    char p_lu[9];
    char p_mode[9];
    int length;
    char gds[2];
    char lst[50];

    p = &CurFile[strlen(CurFile) - 3];
    if (memcmp(p, "exe", 3) != 0)
         if (memcmp(p , "com", 3) != 0)
              if (memcmp(p , "bat", 3) != 0)
                      return 0;

     window(30);
     window_xy(30, 0, 0);
     window_gets(30,lst);
     deactivate(30);


     if (!tp_exist) {
                       tp_started
                                   (lu_id,
                                    tp_id,
                                    &rc);
                       if (rc != 0) {
                                       return (-1);
                                     }
                       tp_exist = 1; /* TP_started OK! */
                    }

     strcpy (tpn,"EXE "); /* name of work */
     strcat (tpn, CurFile); /* name of file */
     strcat (tpn," ");
     strcat (tpn, lst); /* parameter list */

     /*conv_id - return param -id work link */
     strcpy(p_lu, pstr[to-1].plu);
     strcpy(p_mode, pstr[to-1].mode_name);
          allocate  (p_lu,
                     p_mode,
                     tpn,
                     WHEN_SESSION_ALLOCATED,
                     NONE,
                     NONE,
                     NULL,
                     NULL,
                     tp_id,
                     &conv_id,
                     NULL,
                     &v_rc) ;


         if (v_rc.prim != 0) {
                                 return (-1);
                              }
     max_length = 2017;
     recwait (tp_id,
           conv_id,
           ll,
           &v_rc,
           &length,
           max_length,
           &rts,
           &gds,
           &wr);
      return 0;
}

RemCom( int to )
{
    unsigned  long conv_id;
    unsigned char rts;
    unsigned char wr;
    unsigned int max_length ;
    unsigned  char tpn[64];
    char *p;
    struct rc {
                unsigned int prim;
                unsigned long sec;
              } v_rc;
    unsigned long rc;
    char p_lu[9];
    char p_mode[9];
    int length;
    char gds[2];
    char lst[50];


     window(30);
     window_xy(30, 0, 0);
     window_gets(30,lst);
     deactivate(30);


     if (!tp_exist) {
                       tp_started
                                   (lu_id,
                                    tp_id,
                                    &rc);
                       if (rc != 0) {
                                       return (-1);
                                     }
                       tp_exist = 1; /* TP_started OK! */
                    }

     strcpy (tpn,"COM "); /* name of work */
     strcat (tpn, lst); /* command */

     /*conv_id - return param -id work link */
     strcpy(p_lu, pstr[to-1].plu);
     strcpy(p_mode, pstr[to-1].mode_name);
          allocate  (p_lu,
                     p_mode,
                     tpn,
                     WHEN_SESSION_ALLOCATED,
                     NONE,
                     NONE,
                     NULL,
                     NULL,
                     tp_id,
                     &conv_id,
                     NULL,
                     &v_rc) ;


         if (v_rc.prim != 0) {
                                 return (-1);
                              }
     max_length = 2017;
     recwait (tp_id,
           conv_id,
           ll,
           &v_rc,
           &length,
           max_length,
           &rts,
           &gds,
           &wr);
      return 0;
 }
