/*
 *  CopyRight 1995. Nicholas Poljakov all rights reserved.
 */
#include <dos.h>
#include <bios.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <direct.h>
#include <io.h>
#include <fcntl.h>	    /* O_ constant definitions */
#include <sys\types.h>
#include <sys\stat.h>	    /* S_ constant definitions */
#include <state1.h>

#define BORDER 1
#define REV_VID 0x70
#define NORM_VID 0x1E
#define MAX_FRAME 31
#define BKSP 8
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define F9 67
#define F10 68

#define MONO  1 			/* Constant values for adapter */
#define CGA   2                         /*   variable */
#define EGA   3

#define HM  71	 /* Home key	  */
#define UP  72   /* Up Arrow     */
#define PU  73   /* Page Up      */
#define LT  75   /* Left Arrow   */
#define RT  77   /* Right Arrow  */
#define END 79   /* End key      */
#define DN  80   /* Down Arrow   */
#define PD  81   /* Page Down    */
#define ESC '\033'
#define DIR 0x10

#define ROWS1
#define ROWS2 23
#define ROWS  25
#define COLS 78
#define L_W 20
#define M_W 36
#define R_W 20
#define SCRNSIZE ((ROWS)*(COLS+2)*2)
#define LAST (24 * 80)*2

#define M0C  4     /* Files maping col.s */
#define M0L  14    /* Files maping rows  */
#define M0F (((80 * 5) + 9)) * 2
#define INTR 18*2

struct APL_PARM{
       int status;  /* 0-start aplmain,1-start transaction,2-dos shell */
       char p[80];  /* string for system(p) */
       char args[64];/* string of arguments */
       int rc;      /* aplmain return code */
       char dir[60];/* directory name for aplmain */
       int drlen;   /* directory name length */
       void *tpe;   /* entry of exit program */
       char pgm_state;
}*p_aparm;
struct LU_PARM{
       unsigned long conv_id;
       unsigned char lu_id[8];
       unsigned char tp_id[8];
}*p_lparm;

int  fd_ini = -1;
unsigned char cur_off = 0;
int inv_off;
unsigned int attr1b;
void **ptrs;
int size;
unsigned char row, col;
int adapter;
unsigned char far *videomem;
int offset;
int sw = 0;
char pi[40];
char po[40];
char *pa[2];  /* path in & path out pointers */
char path[18];
char file[12];
char tpname[31];
char lu_name[9];
char ps[4][14];
char lu_id[8] = {0,0,0,0,0,0,0,0};
struct crtp *p_crtp;
char InTp[40];
unsigned long conv_id;
char tp_id[8] = {0,0,0,0,0,0,0,0};
char tp_exist = 0; /* Tp_exist eq. 0 if TP not active, and 1 vice versus.*/
char mode_name[9];
char CurFile[14];
char dta[128];
char far *vid_mem;
short cur_ln = 0;
int p_lu_num = 0;   /* number of LU - partners */
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];
struct menu_frame {
    int startx, endx, starty, endy;
    unsigned char *p;
    char **menu;
    char *keys;
    int border;
    int count;
    unsigned char attrib;
    int active;
    int curx, cury;
    char *header;
    unsigned char shd;
    } frame[MAX_FRAME];

char *topline[] = {
    "File",
    "Run",
    "Options",
    "Help"
    };
char *btline[] = {
    "F1 - Help",
    "F3 - View",
    "F5 - Send",
    "F9 - Filter",
    "F10 - Menu",
    "F8 - Command"
    };
char *f_opt[] = {
    "Drive     ",
    "Dos shell ",
    "About     ",
    "Exit      "
    };
char *r_opt[] = {
    "Attach ...",
    "Detach ...",
    "Select ...",
    "Copy   ...",
    "TTY    ..."
    };
char *o_opt[] = {
    "Change LU options",
    "Show partners    ",
    "Remote control   "
    };
char *dr_opt[] = {
    "-- A --",
    "-- B --",
    "-- C --",
    "-- D --",
    "-- E --",
    "-- F --",
    "-- G --"
    };
char *prwin[] = {
    "                            ",
    "  Sample LU 6.2 application ",
    "        program.            ",
    "                            ",
    "     Nicholas Poljakov.     ",
    "         Email:             ",
    "poljakov@vertex.inria.msu.ru"
    };
unsigned char *tlx[5];

char far *sv;
char *tpx1 = "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍ»";
char *tpx2 = "º Partner LU name ³ MODE name  ³ LU Type º";
char *tpx3 = "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍ¹";
char *tpx4 = "º                 ³            ³         º";
char *tpx5 = "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍ¼";
char p_dcl[21] = "Current path is : ";
unsigned char dr_ind[80];
char c_pt[60];
int drive_ind[10];
char *window_getche();
int vmode;
#define TPG    50
struct index
    {  long reset;
       char ind_str[4];
       short lentxt;
    } index[TPG];
int fp_help;

main(argc, argv)
int argc;
char *argv[];
{
	    int i;
       int drivecnt;
       unsigned char j;
       void _near *tp1;
       void _near *tp2;
       char _far *ttp;

	    union
    {					/* Access equiment either as:	 */
	unsigned u;			/*   unsigned or		 */
	struct				/*   bit fields 		 */
	{
	    unsigned diskflag : 1;	/* Diskette drive installed?	 */
	    unsigned coprocessor : 1;	/* Coprocessor? (except on PC)	 */
	    unsigned sysram : 2;	/* RAM on system board		 */
	    unsigned video : 2; 	/* Startup video mode		 */
	    unsigned disks : 2; 	/* Drives 00=1, 01=2, 10=3, 11=4 */
	    unsigned dma : 1;		/* 0=Yes, 1=No (1 for PC Jr.)	 */
	    unsigned comports : 3;	/* Serial ports 		 */
	    unsigned game : 1;		/* Game adapter installed?	 */
	    unsigned modem : 1; 	/* Internal modem?		 */
	    unsigned printers : 2;	/* Number of printers		 */
	} bits;
    } equip;
    char **pt;
    char *pt1;


    FP_SEG(pt) = 0x10;
    FP_OFF(pt) = 0xa0;
    pt1 = *pt;
    pt1 += 5;
    pt = pt1 + 12;
    p_aparm = *pt;
    pt = pt1 + 16;
    p_lparm = *pt;

    conv_id = p_lparm -> conv_id;
    memcpy(lu_id,p_lparm -> lu_id,8);
    memcpy(tp_id,p_lparm -> tp_id,8);
    if (tp_id[0] != 0) {
        tp_exist = 1;
    }

    strcpy(path, "*.*");
    pa[0] = pi;
    pa[1] = po;
/*
    if (argc == 1) {
        inv_off = 1;
    }
    if ((strcmp(argv[1], "/i") == 0)||(strcmp(argv[1], "/I") == 0)) {
        inv_off = 0;
    }
    if ((strcmp(argv[1], "/o") == 0)||(strcmp(argv[1], "/O") == 0)) {
        inv_off = 1;
    }
*/
    tlx[0] = &tpx1;
    tlx[1] = &tpx2;
    tlx[2] = &tpx3;
    tlx[3] = &tpx4;
    tlx[4] = &tpx5;

    ttp = dta;
    tp1 = FP_OFF ( ttp );
    tp2 = FP_SEG ( ttp );
  /*
    _asm
        {
          mov   ax, word ptr tp2[0]
          push  ds
          mov   ds, ax
          mov   dx, word ptr tp1[0]
          mov   ah, 1ah
          int   21h
          pop   ds
        }
   */
    _asm
        {
          push  es
          mov   ax, 0f000h
          mov   es, ax
          mov   al, es:[0fffeh]
          mov   byte ptr j[0], al
          pop   es
	}
    if ((j == 0xff)) {   /* IBM PC */
        drivecnt = 2;
        goto Set_vm;
    }
    if ((j == 0xfe)) {   /* IBM PC/XT */
        drivecnt = 3;
        goto Set_vm;
    }
    if ((j == 0xfb)) {   /* Robotron 1834 */
        drivecnt = 3;
        goto Set_vm;
    }
	equip.u = _bios_equiplist();
    _asm
       {
        mov  ah, 08h
        mov  dl, 05h
        int  13h
        mov  byte ptr j[0], dl
       }
    drivecnt = j;
       if (j == 0) {
            dr_opt[0] = NULL;
            dr_opt[1] = NULL;
       }
       if (j == 1) {
            dr_opt[1] = NULL;
       }
       _asm
           {
               mov  cx, 7
               mov  dl, 80h
	    Look:
	       push cx
	       push dx
               mov  ah, 08h
               int  13h
	       pop  dx
               jc   Eexit
	       inc  dl
	       pop  cx
               loop Look
           Eexit:
               and  dl, 7fh
               mov  byte ptr j[0], dl
	   }
       drivecnt += j;
       for (i = j + 2; i < 7; i++) {
            dr_opt[i] = NULL;
       }
       j = 0;
       for (i = 0; i < 7; i++) {
            if (dr_opt[i] != NULL) {
                drive_ind[j] = i;
                j++;
            }
       }
Set_vm:
        init_adapter();
        switch (vmode) {
        case MONO:  vid_mem = (char far *) 0xb0000000;
                break;
        case CGA:   vid_mem = (char far *) 0xb8000000;
                break;
        case EGA:   vid_mem = (char far *) 0xb8000000;
                break;
        }


       sv = malloc(4000);
       cls(1);
       sfs(sv, vid_mem);
       goto_xy(0,0);
       for (i = 0; i < MAX_FRAME; i++) {
           frame[i].p = NULL;
       }

       /* Make frame 0 and 1 */

       frame[0].startx = 0;
       frame[0].endx = 0;
       frame[0].starty = 0;
       frame[0].endy = 78;
       frame[0].menu = (char **)topline;
       frame[0].border = 0;
       frame[0].keys = NULL;
       frame[0].count = 4;
       frame[0].attrib = 0x7f; /* 0x1f; */
       frame[0].active = 0;
       frame[0].p = malloc(80*2);
       frame[0].shd = 0;

	    frame[1].startx = 24;
	    frame[1].endx = 24;
	    frame[1].starty = 0;
	    frame[1].endy = 78;
	    frame[1].menu = (char **)btline;
	    frame[1].border = 0;
	    frame[1].keys = NULL;
            frame[1].count = 5;
	    frame[1].attrib = 0x70; /* 0x50; */
	    frame[1].active = 0;
	    frame[1].p = malloc(80*2);
	    frame[1].shd = 0;

       frame[8].startx = 6;
       frame[8].endx = 21;
       frame[8].starty = 8;
       frame[8].endy = 72;
       frame[8].menu = (char **)btline;
       frame[8].border = 0;
       frame[8].keys = NULL;
       frame[8].count = 4;
       frame[8].attrib = 0x1e;
       frame[8].active = 0;
       frame[8].p = malloc((80*23)*2);
       frame[8].shd = 1;

       attr1b = frame[8].attrib;

       make_menu(2, f_opt, "cdae", 4, 1, 0, BORDER, 0x1a,1);
       make_menu(3, r_opt, "adsct", 5, 1, 8, BORDER, 0x1a,1);
       make_menu(4, o_opt, "swr", 3, 1, 16, BORDER, 0x1a,1);
       make_window(5,"Local LU",4,10,8,40,BORDER, 0x30, 1);
       make_menu(6, dr_opt, "", drivecnt, 4, 6, BORDER, 0x1e, 1);
       make_menu(7, prwin, "", 7, 7, 22, BORDER, 0x1e, 1);
       make_window(10,"TTY information screen",0,0,5,79,BORDER, 0x30, 0);
       make_window(11,"TTY emulating screen",6,0,24,79,BORDER, 0x71, 0);
       make_window(14,"Errors",12,30,18,60,BORDER, 0x51, 1);
       make_window(15,"OK",12,30,18,60,BORDER, 0x51, 1);
       make_window(16,"LU Partner",8,30,13,60,BORDER, 0x71, 1);
       make_window(17,"LU Partner",11,32,16,62,BORDER, 0x71, 1);
       make_window(18,"LU Partner",14,34,19,64,BORDER, 0x71, 1);
       make_window(19,"LU Partner",17,36,22,66,BORDER, 0x71, 1);
       make_window(20,"Send",10,11,18,70,BORDER, 0x71, 1);
       make_window(21,"Remote Control",8,21,18,60,BORDER, 0x70, 1);
       make_window(22,"List of LU",4,10,18,70,BORDER, 0x70, 1);
       make_window(23,"",19,10,21,70,BORDER, 0x70, 1);
       make_window(25,"Help",0,0,24,79,BORDER, 0x27, 0);
       make_window(26,"Receive File",10,10,18,59, BORDER, 0x17, 1);
       make_window(27,"File Filter",15,20,19,50, BORDER, 0x70, 1);
       make_window(28,"Copy Shell",5,10,20,70, BORDER, 0x27, 1);
       make_window(29,"",4,6,19,70, 0, 0x27, 1);
       make_window(30,"Enter arguments",19,10,21,70,BORDER, 0x70, 1);
       /* 24 - reserved */

       fp_help = open("help.txt", O_RDONLY | O_TEXT);
       if (fp_help != NULL) {
            if (read(fp_help, &index, TPG * sizeof(struct index)) < 0) {
                close(fp_help);
                fp_help = 0;
            }
       }
       pd_driver();
       for (i = 0; i < MAX_FRAME; i++) {
           if (frame[i].p != NULL) {
               free(frame[i].p);
           }
       }
       free(sv);
       save_ini();
       close(fp_help);
       cls(0);
       p_aparm -> status = 0;
       p_aparm -> rc = 0;
       exit (0);
}
 pd_driver()
        {
            int choice1, choice2, selection;
            unsigned int ch;
            int i, cnt;

            /* Put on screen menu 0 */

            cnt = 1;
            save_video(0);
            save_video(1);
   Retry:
            write_string(0, 0, topline[0], frame[0].attrib);
            write_string(0, 8, topline[1], frame[0].attrib);
            write_string(0, 16, topline[2], frame[0].attrib);
            write_string(0, 74, topline[3], frame[0].attrib);

            write_string(24, 0, btline[0], frame[1].attrib);
/*          write_string(24, 10, btline[1], frame[1].attrib);
            write_string(24, 20, btline[2], frame[1].attrib);  */
            write_string(24, 10, btline[4], frame[1].attrib);

	    sfs(sv, vid_mem);
            if( p_aparm -> rc != 0){ /* recall aplmain */
                cnt = 0;
                if( p_aparm -> rc == 2)
                    write_string(0, 0, topline[0], REV_VID);
                else
                    write_string(0, 16, topline[2], REV_VID);
                goto ReCall;
            }
	    if (cnt == 1) {
                save_video(7);
                draw_border(7);
                display_menu(7);
                frame[7].active = 1;
            }
            if ((ch = getch()) == ESC) {
                return 0;
            }
            restore_video(7);
            if (ch == 0) {
                switch (ch = getch()) {
                    case F1 :
                              help("0   ");
                              break;
                    case F3 :
                              break;
                    case F10 :
                              if (cnt == 1) {
                                cnt = 0;
                              }
                              write_string(0, 0, topline[0], REV_VID);
                              ReCall:
                              set_ini();
                              i = pr_m0();
                              restore_video(0);
                              if (i == -1) {
                                return 0;
                              }
                              break;
                 }
            }
            goto Retry;
}
 pr_m0()
{
	    int choice1, choice2, choice3, selection;
        int ind, swi;
        unsigned int ch;
        unsigned long rc;
        char far *sv1;
	    char c_buf[80];
	    char c_pt[30];

         choice1 = 0;
         if( p_aparm -> rc == 2) /* DOS shell */
                goto Ag;
         if(( p_aparm -> rc == 1) || ( p_aparm -> rc == 3)){ /* transaction  or command */
                Fmh5Handler();
         }


         for (;;) {
             if ((ch = getch()) == ESC) {
                return -1;
             }
         if (ch == '\r') {
         Ag:
	   sfs(sv, vid_mem);
	   while ((selection = pulldown(choice1 + 2)) != -1) {
            if ((selection == -2)||(selection == -3)) {
		restore_video(choice1 + 2);
                choice2 = choice1;
		if ((selection == -2))
		    if (choice1 == 0)
			choice1 = 2;
		    else
			choice1--;
		else
		    if (choice1 == 2)
			choice1 = 0;
		    else
			choice1++;
                switch (choice2) {
		    case 0 :
			      write_string(0, 0, topline[0], frame[0].attrib);
                              break;
                    case 1 :
			      write_string(0, 8, topline[1], frame[0].attrib);
			      break;
		    case 2 :
			      write_string(0, 16, topline[2], frame[0].attrib);
			      break;
                }
                switch (choice1) {
		    case 0 :
			      write_string(0, 0, topline[0], REV_VID);
			      break;
		    case 1 :
			      write_string(0, 8, topline[1], REV_VID);
			      break;
		    case 2 :
			      write_string(0, 16, topline[2], REV_VID);
			      break;
                }
                sfs(sv, vid_mem);
                continue;
            }
            switch (choice1) {
                case 0 : /* File menu */
                         switch (selection) {
                            case 0 : /* Change dir. */
                                     if ((choice2 = pulldown(6)) != -1) {
                                          ch_drive(drive_ind[choice2]);
				     }
				     restore_video(6);
                                     break;
                            case 1 : /* Dos shell */
                                     cls(0);
                                     save_ini();
                                     p_lparm -> conv_id = conv_id;
                                     memcpy( p_lparm -> lu_id, lu_id,8);
                                     memcpy( p_lparm -> tp_id, tp_id,8);
                                     p_aparm -> status = 2;
                                     p_aparm -> rc = 2;
                                     exit(2);
                            case 2 : /* About */
                                     help("0   ");
                                     break;
                            case 3 : /* Exit */
                                     return -1;
                          }
                          break;
                case 1 : /* Run menu */
                         switch (selection) {
                            case 0 : /* Attach local LU */
                                     SetLu();
                                     break;
                            case 1 : /* Detach local LU */
                                     detach_lu (lu_id, &rc);
                                     memset(lu_id, 0, 8);
                                     break;
                            case 2 : /* Select active partner */
                                     SelPtLu();
                                     break;
                            case 3 : /* Select file and send */
                                     CpFl(choice1 + 2);
                                     break;
                            case 4 : /* TTY */
                                     em_tty();
                          }
                          break;
                case 2 : /* Options menu */
                         switch (selection) {
                            case 0 : /* Change LU options */
                                     break;
                            case 1 : /* Show partners */
                                     showp(1); /* show and pause */
                                     break;
			    case 2 : /* Remote control */
                                     Fmh5Handler();
				     break;
                          }
                          break;
             }
           }
            restore_video(choice1 + 2);
		 }
                 choice2 = choice1;
		 if (ch == 0) {
                    switch (ch = getch()) {
                         case LT :
				   if (choice1 == 0) {
					choice1 = 2;
					break;
				   }
				   choice1--;
				   break;
			 case RT :
				   if (choice1 == 2) {
					choice1 = 0;
					break;
				   }
				   choice1++;
				   break;
                         case F1 :
                                   switch (choice1) {
                                        case  0:  help("2   ");
                                                  break;
                                        case  1:  help("3   ");
                                                  break;
                                        case  2:  help("4   ");
                                                  break;
                                    }
                                   break;
                    }
		 switch (choice2) {
		    case 0 :
			      write_string(0, 0, topline[0], frame[0].attrib);
                              break;
                    case 1 :
			      write_string(0, 8, topline[1], frame[0].attrib);
			      break;
		    case 2 :
			      write_string(0, 16, topline[2], frame[0].attrib);
			      break;
		  }
		 switch (choice1) {
		    case 0 :
			      write_string(0, 0, topline[0], REV_VID);
			      break;
		    case 1 :
			      write_string(0, 8, topline[1], REV_VID);
			      break;
		    case 2 :
			      write_string(0, 16, topline[2], REV_VID);
			      break;
		  }
		 }
    }
    return 0;
}
CpFl(nw)
int nw;
{
      char *s_dir;
      char msg[20];
      char *p_nm[4];
      char dr_ind[40];
      register unsigned	i;
      unsigned char attr1;
      unsigned char attr2;
      unsigned char attr;
      unsigned ch;
      int k;
      char *tmp;
      int to;
      int from;

      restore_video(nw);
      if ((s_dir = malloc(_MAX_PATH)) == NULL) {
	  return -1;
      }
      window(28);
      strcpy(msg, "Source LU ----> ");
      write_string(7, 14, msg, 0x2f);
      strcpy(ps[0], "1. ");
      strcat(ps[0], lu_name);
      p_nm[0] = ps[0];
      for (i = 1; i < p_lu_num+ 1; i++) {
          ps[i][0] = (i + 1) | 0x30;
          ps[i][1] = 0x00;
          strcat(ps[i], ". ");
	  strcat(ps[i], pstr[i-1].plu);
	  p_nm[i] = ps[i];
      }
      make_menu(24, p_nm, "12345", p_lu_num + 1, 7, 30, BORDER, 0x72, 1);
      sfs(sv, vid_mem);
      i = pulldown(24);
      from = i;
      strcpy(msg, "Copy From ");
      strcat(msg, &ps[i][3]);
      write_string(18, 14, msg, 0x2f);

      strcpy(msg, "Target LU ----> ");
      write_string(7, 14, msg, 0x2f);
      sfs(sv, vid_mem);
      i = pulldown(24);
      to = i;
      strcpy(msg, " To  ");
      strcat(msg, &ps[i][3]);
      write_string(18, 32, msg, 0x2f);
    _asm
       {
        mov ah, 0
        int 1ah
	add dx, 9 // 1/2 sec.
        mov bx, dx
    repeat:
        int 1ah
        cmp dx, bx
        jne repeat
       }

      restore_video( 24 );
      deactivate(28);
      attr1 = frame[29].attrib;
      attr2 = frame[8].attrib;
      _getdcwd(0, s_dir, _MAX_PATH);
      if (to == 0) {
	 strcpy(pa[1], s_dir);
      }
      else {
        if (rem_path(po, to-1) < 0) {
           window(14);
           window_xy(14, 1, 4);
           window_puts(14, "Get path failure");
           window_xy(14, 2, 3);
           window_puts(14, "Press ESC to exit");
           while ((ch = getch()) != ESC) ;
           deactivate(14);
           return 0;
        }
      }

      if (from == 0) {
         strcpy(pi, s_dir);
         cur_ln = to - 1;
      }
      else {
        if (rem_path(pi, from-1) < 0) {
           window(14);
           window_xy(14, 1, 4);
           window_puts(14, "Get path failure");
           window_xy(14, 2, 3);
           window_puts(14, "Press ESC to exit");
           while ((ch = getch()) != ESC) ;
           deactivate(14);
           return 0;
        }
      }
   ReCopy:
      window(29);
      write_string(5, 11, "        ", attr1b);
      strcpy(dr_ind, "Target : ");
      if (to == 0) {
         strcat(dr_ind, lu_name);
      }
      else
	 strcat(dr_ind, pstr[to-1].plu);

      write_string(5, 11, dr_ind, frame[29].attrib | 0x0f);
      strcpy(dr_ind, p_dcl);
      strcat(dr_ind, pa[1]);
      write_string(5, 26, "                                        ", frame[29].attrib);
      attr = frame[29].attrib;
      if (attr == 0x1e) {
         attr &= 0xf0;
	 attr |= 0x0c;
      }
      else
         attr &= 0xf0;

      write_string(5, 26, dr_ind, attr);
      sfs(sv, vid_mem);
      save_video(8);
      frame[8].active = 1;
      i = 0;
      if ((k = menu0(vid_mem, to, from)) == 2) {
          i = from;
          from = to;
	  to = i;
          tmp = pa[0];
          pa[0] = pa[1];
          pa[1] = tmp;
          if ((from == to)) {
              if (from == 0) {
                 chdir(pa[0]);
              }
              else
                 rem_cd(pa[0], from);
          }
	  i = frame[29].attrib;
	  frame[29].attrib = frame[8].attrib;
	  frame[8].attrib = i;
          i = -1;
      }
      else
            if ( k == 3 ) {
               i = -1;
            }
      restore_video(8);
      deactivate(29);
      if (i == -1) {
          goto ReCopy;
      }
      chdir(s_dir);
      frame[29].attrib = attr1;
      frame[8].attrib = attr2;
      free(s_dir);
      return 0;
}
