Exemple #1
0
void main(void)
 {
   printf("Previous extended Ctrl-Break status %s\n",
    (getcbrk()) ? "On": "Off");

   setcbrk(0);  /* Turn if off*/
    }
Exemple #2
0
void term_reinit(int wait)             /* fixup after running other progs */
{
   struct text_info dat;

   gppconio_init();
   gettextinfo(&dat);

   if (dat.screenheight != screen_h) {
      _set_screen_lines(screen_h);
      gettextinfo(&dat);
      screen_h = dat.screenheight;
      screen_w = dat.screenwidth;
      mouse_init();
   }

   set_bright_backgrounds();

   if (wait) {
      clear_keybuf();
      gch();
   }

   __djgpp_set_ctrl_c(0);
   setcbrk(0);
}
Exemple #3
0
static void sig_install_abort(void)
{
#ifdef __DJGPP__
	setcbrk(1);
#endif

#ifdef __CYGWIN__
/*
 * "If the HandlerRoutine parameter is NULL, [...] a FALSE value restores
 * normal processing of CTRL+C input.  This attribute of ignoring or processing
 * CTRL+C is inherited by child processes."  So restore normal processing here
 * in case our parent (such as Johnny the GUI) had disabled it.
 */
	SetConsoleCtrlHandler(NULL, FALSE);
	SetConsoleCtrlHandler(sig_handle_abort_ctrl, TRUE);
#endif

	signal(SIGINT, sig_handle_abort);
	signal(SIGTERM, sig_handle_abort);
#ifdef SIGXCPU
	signal(SIGXCPU, sig_handle_abort);
#endif
#ifdef SIGXFSZ
	signal(SIGXFSZ, sig_handle_abort);
#endif
}
Exemple #4
0
void
OnExit (void)
{
  ReleaseMemory ();
  ReleaseFatInfo ();
  setcbrk (SavedCBreak);

  SynchronizeLFNs ();

  CROSSCUT_NLS_CLOSE
}
Exemple #5
0
static void hb_gt_dos_CtrlBrkRestore( void )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_CtrlBrkRestore()" ) );

#if defined( __WATCOMC__ )
   signal( SIGINT, SIG_DFL );
   signal( SIGBREAK, SIG_DFL );
#elif defined( _MSC_VER )
   signal( SIGINT, SIG_DFL );
#else
   setcbrk( s_iOldCtrlBreak );
#endif
}
Exemple #6
0
static void sig_install_abort(void)
{
#ifdef __DJGPP__
	setcbrk(1);
#endif

#ifdef __CYGWIN32__
	SetConsoleCtrlHandler(sig_handle_abort_ctrl, TRUE);
#endif

	signal(SIGINT, sig_handle_abort);
	signal(SIGTERM, sig_handle_abort);
#ifdef SIGXCPU
	signal(SIGXCPU, sig_handle_abort);
#endif
#ifdef SIGXFSZ
	signal(SIGXFSZ, sig_handle_abort);
#endif
}
Exemple #7
0
void remove_link(messagerec *m1, char *aux)
/* deletes a message */
{
  messagerec m;
  char s[81],s1[81];
  int f;
  long csec,nsec;

  m=*m1;
  strcpy(s,syscfg.msgsdir);
  switch(m.storage_type) {
    case 0:
    case 1:
      ltoa(m.stored_as,s1,16);
      if (m.storage_type==1) {
        strcat(s,aux);
	strcat(s,"\\");
      }
      strcat(s,s1);
      unlink(s);
      break;
    case 2:
      f=open_file(aux);
      csec=m.stored_as;
      while ((csec>0) && (csec<2048)) {
	nsec=(long) gat[csec];
	gat[csec]=0;
	csec=nsec;
      }
      sh_lseek(f,0L,SEEK_SET);
      sh_write(f,(void *)gat,4096);
      sh_close(f);
      break;
    default:
      /* illegal storage type */
      break;
  }
  setcbrk(1);
}
int main(void)
{
	if (setjmp(abortBuffer))
		return 3;
	ctrlbrk(exit_program); // Set up to handle CTRL-Break from user
	setcbrk(1);
	// Attempt to remove the trace file, so that it doesn't grow out of control
	remove ("TRACEQP.TXT");

	try
{
BrewerCMDINI    ini(10);            // Initialization file
Display         display(&ini);      // All window functions are here
Brewer          brewer(&ini, &display); // All Brewer functions are here
char*           userCommand;        // Command typed by user
char*           parameter;          // Parameter to command typed by user
char*           result;             // Response to command from Brewer
char            temp[200];          // Buffer
ostrstream*     s;                  // Stream to fill buffer
int             index;              // Command index (-1 if not a built-in command)
int             loop, loop2;        // Loop indeces

	do
    {
        // Clear Brewer status.  VERY IMPORTANT!!
        brewer.status();
        display.updateStatusWindow(R_OK);
        userCommand = display.getUserInput();
        display.updateStatusWindow(R_ACK);
        parameter = userCommand;
		if((index = findCommand(userCommand)) != -1)
        {
            parameter += strlen(cmdList[index]);
            while(isspace(*parameter))
				parameter++;
        }
//        s = new ostrstream(temp, 200);
//        *s << "Decoded message as " << index;
//        if(index == -1)
//            *s << ": Unknown command " << userCommand;
//        else
//            *s << ": " << cmdList[index] << " with parameter " << parameter;
//        *s << ends;
//        delete s;
//        display.bossMessage(temp);
        switch(index)
        {
        case 0:     // COSMACMODE
            if(*parameter)
                brewer.switchTo(cosmacMode, SerialPort::BaudRate(atoi(parameter)));
            else
                brewer.switchTo(cosmacMode, SerialPort::baud1200);
            break;
        case 1:     // GETCFG: Write Brewer configuration
            if(brewer.mode() == loadMode)
				brewer.wrongMode();
            else if(!*parameter)
                display.bossMessage(missingParam);
            else if(brewer.isAllowed())
            {
                ifstream ifile(parameter);
				ofstream ofile("brewcmd.tmp");
                while(kbhit())   // ensure that kbhit is cleared
                    getch();
                while(ifile.good() && !kbhit())
                {
                    temp[0] = '?';  // We want to read values from the Brewer
                    do { temp[1] = ifile.get(); ofile.put(temp[1]); } while(isspace(temp[1]));
                    if(temp[1] == ';')
                    {
                        ifile.getline(temp, 200, '\n');
                        ofile << temp << endl;
                    }
					else if(ifile.good())
                    {
                        // Save the second character, which we read already
                        ifile.getline(&temp[2], 198, '=');
                        // Convert to uppercase
                        for(loop = 0; loop < strlen(temp); loop++)
							temp[loop] = toupper(temp[loop]);
                        ofile << (&temp[2]) << '=';
                        result = brewer.commandWithReply(temp);
                        ofile << result << endl;
                        ifile.getline(temp, 200, '\n');
                    }
                }
                ifile.close();
                ofile.close();
                remove("brewcmd.bak");
                rename(parameter, "brewcmd.bak");
                rename("brewcmd.tmp", parameter);
			}
            break;
        case 2:     // HELP
            if(*parameter)
            {
                if((index = findCommand(parameter)) == -1)
					display.write("  Unknown command\n");
                else
                {
                    display.write("  ");
                    display.write(cmdHelp[index]);
                    display.write("\n");
                }
            }
            else
            {
                display.write("Valid commands are:\n");
                for(loop = 0; *cmdList[loop]; loop++)
				{
                    s = new ostrstream(temp, 200);
                    *s << "  " << cmdList[loop];
                    for(loop2 = strlen(cmdList[loop]); loop2 < 12; loop2++)
                        *s << " ";
                    if((loop + 1) % 5 == 0 || !*cmdList[loop + 1])
						*s << endl;
                    *s << ends;
                    delete s;
                    display.write(temp);
                }
            }
            break;
        case 3:     // INIT: Redetect communications
            brewer.reset();
            break;
        case 4:     // LOAD: Load top code
            if(!*parameter)
                display.bossMessage(missingParam);
            else
                brewer.loadTopCode(parameter);
			break;
        case 5:     // LOADMODE
            if(*parameter)
                brewer.switchTo(loadMode, SerialPort::BaudRate(atoi(parameter)));
            else
                brewer.switchTo(loadMode, SerialPort::baud9600);
			break;
        case 6:     // OPMODE
            if(*parameter)
                brewer.switchTo(operatingMode, SerialPort::BaudRate(atoi(parameter)));
            else
                brewer.switchTo(operatingMode, SerialPort::baud9600);
            break;
        case 7:     // PUTCFG: Read Brewer configuration
            if(brewer.mode() == loadMode)
                brewer.wrongMode();
            else if(!*parameter)
                display.bossMessage(missingParam);
			else if(brewer.isAllowed())
            {
                ifstream ifile(parameter);
                while(kbhit())   // ensure that kbhit is cleared
                    getch();
                while(ifile.good() && !kbhit())
				{
                    temp[0] = '!';  // We want to write values to the Brewer
                    do { temp[1] = ifile.get(); } while(isspace(temp[1]));
                    if(temp[1] == ';')
                        ifile.getline(temp, 200, '\n');
                    else if(ifile.good())
                    {
                        // Save the second character, which we read already
                        ifile.getline(&temp[2], 198, '=');
                        strcat(temp, " ");  // Separator
                        ifile.getline(&temp[strlen(temp)], 200 - strlen(temp), '\n');
                        // Convert to uppercase
						for(loop = 0; loop < strlen(temp); loop++)
                            temp[loop] = toupper(temp[loop]);
                        brewer.command(temp);
                    }
                }
                ifile.close();
                brewer.testSerialNumber();
			}
            break;
        case 8:     // QUIT
            break;
        case 9:     // READLOG
            if(brewer.mode() == loadMode)
                brewer.wrongMode();
            else if(brewer.isAllowed())
            {
                do
                {
                    result = brewer.commandWithReply("LOGENTRY");
					display.brewerMessage(result);
                } while(strcmp(result, " All log items reported.") != 0 && !kbhit());
            }
            break;
        case 10:    // REPEAT
            if(brewer.mode() == loadMode)
				brewer.wrongMode();
            else if(!*parameter)
                display.bossMessage(missingParam);
            else do
            {
                result = brewer.commandWithReply(parameter);
                display.brewerMessage(result);
            } while(!kbhit());
            break;
        case 11:    // RESET
            brewer.warmReset();
            break;
		case 12:    // RUN
            if(brewer.mode() == loadMode)
                brewer.wrongMode();
            else if(!*parameter)
                display.bossMessage(missingParam);
            else
			{
                ifstream ifile(parameter);
                while(kbhit())   // ensure that kbhit is cleared
                    getch();
                while(ifile.good() && !kbhit())
                {
                    do { temp[0] = ifile.get(); } while(isspace(temp[0]));
                    // Save the first character, which we read already
                    ifile.getline(&temp[1], 199, '\n');
                    // Convert to uppercase
                    for(loop = 0; loop < strlen(temp); loop++)
                        temp[loop] = toupper(temp[loop]);
                    if(temp[0] == ';')
                        display.brewerMessage(temp);
					else if(strlen(temp) > 0)
                    {
                        result = brewer.commandWithReply(temp);
                        if(strlen(result) > 0)
                            display.brewerMessage(result);
                    }
                }
				ifile.close();
            }
            break;
        case 13:    // SAVE
            brewer.save();
            break;
        case 14:    // SEND
            if(!*parameter)
                display.bossMessage(missingParam);
            else
            {
                s = new ostrstream(temp, 200);
				*s << brewer.lowLevelCommandWithReply(parameter) << ends;
                display.brewerMessage(temp);
                delete s;
            }
            break;
        case 15:    // STATUS
			brewer.status();
            brewer.showSetup();
            break;
        case 16:    // SYN
            if(brewer.mode() == cosmacMode)
                brewer.wrongMode();
            else
            {
                s = new ostrstream(temp, 200);
                *s << brewer.lowLevelCommandWithReply("\x16") << ends;
                display.brewerMessage(temp);
                delete s;
			}
            break;
        case 17:    // ZERO
            if(brewer.mode() == cosmacMode)
                brewer.wrongMode();
            else
				brewer.lowLevelCommand("\x1e"); // RS (^^): zero reset counter
            break;
        default:
            if(strcmp(userCommand, "") == 0)
                brewer.status();
            else if(brewer.mode() == loadMode)
                brewer.wrongMode();
            else if(userCommand[strlen(userCommand) - 1] == 'A' &&
                    !isalpha(userCommand[strlen(userCommand) - 2]))
                display.bossMessage("Do not use the A command, use the REPEAT command instead");
            else
            {
				result = brewer.commandWithReply(userCommand);
                display.brewerMessage(result);
			}
            break;
        }
        while(kbhit())
			getch();
    } while(index != 8); // QUIT
    return 0;
}
    catch(BaseException& err)
    {
		cout << "An exception occurred" << endl;
		err.display();
		cout << "Hit a key to terminate program" << endl;
		while (!kbhit())
			continue;
		return 3;
	}
}
Exemple #9
0
/*------------------------------------------------------------------------------

 FUNCTION NAME: Main_Init

 DESCRIPTION: Main init function

 PARAMETERS:
   - INPUT:
   - OUTPUT:

 RETURN:

 NOTES: Don't try to change the order of the function calls!

------------------------------------------------------------------------------*/
void Main_Init (void)
{
t_uchar    Lines[2] = {9,END_OF_LINES};
char    Msg[40];
#ifdef PC_TERMINAL
int     RetVal;
t_uchar    PrinterIndex, NumPrinters, Type, Port, Model;
t_boolean InvertScreen;
int     LCDContrastOffset;
#endif

  /* MAEL Version */
  #if defined (FEDORA_VERSION)
    srand48((long) time(NULL));
  #else

    #if !defined (NT_VERSION)
      /* Standart Random generation init */
      randomize ();
    #else
      /* Seed the random-number generator with current time so that
      * the numbers will be different every time we run.
      */
      srand( (unsigned)time( NULL ) );  
    #endif

  #endif /* MAEL Version */

  /*---------------------------------------------------*/
  /* Set dos verify option to on and other DOS options */
  /*---------------------------------------------------*/
  #if !defined (NT_VERSION)
    #if !defined (FEDORA_VERSION)
    /* In Linux Verify is always on */
    /* And cbreak does nothing */
    setverify (1);
    setcbrk (0);
    #endif /* FEDORA_VERSION */
    /* Set new Ctrl-Break handler */
    #if defined (DOSX286)
      DosSetPassToProtVec (0x1B, (PIHANDLER) Main_HandlerCtrlBreak,
                           &OldCtrlBrkProt, &OldCtrlBrkReal);
      DosSetPassToProtVec (0x23, (PIHANDLER) Main_HandlerCtrlBreak,
                           &OldCtrlCProt, &OldCtrlCReal);
    #else
      #if defined (FEDORA_VERSION)
        signal(SIGINT,SIG_IGN); 
      #else
        ctrlbrk (Main_HandlerCtrlBreak);
      #endif /* MAEL VERSION */
    #endif
  #endif


  /*-------------*/
  /* Nosdos Init */
  /*-------------*/

  /*----------*/
  /* Init. Kb */
  /*----------*/

  #if defined (FEDORA_VERSION)
      Kb_Init (KEYBOARD_STANDART);
  #else
  #if defined (TERMINAL_WT9602)
    Kb_Init (KEYBOARD_WT9602);
  #else
    #if defined (TERMINAL_WT9603)
      Kb_Init (KEYBOARD_WT9603);
    #else
      Kb_Init (KEYBOARD_STANDART);
    #endif
  #endif

  #endif /* MAEL Version */

  /*-----------------------*/
  /* Init. display modules */
  /*-----------------------*/

  #if defined(FEDORA_VERSION)
    #if defined(SVGALIB_MODE) || defined(XLIB_MODE)
      GrphDisp_Init (240, 128, 8);
    #else
      GrphDisp_Init (40, 14, 8);
    #endif
  #else

  #if defined(NT_VERSION)
    GrphDisp_Init (40, 14, 8);
  #else
    GrphDisp_Init (240, 128, 8);
  #endif

  #endif /* MAEL Version */

  GrphText_Init (240, 128, 8);

  #if defined (TERMINAL_WT9602) || defined (TERMINAL_WT9603)
    #if defined (LNSE)
      GrphDisp_SetInvertScreen (FALSE);
    #else
      GrphDisp_SetInvertScreen (TRUE);
    #endif
    Util_SetLCDContrast (INITIAL_LCD_CONTRAST);
  #endif

  /* Init message */
  GrphText_PopUp (54, 0, 240, Lines, TRUE);
  strcpy (Msg, S0252);
  GrphText_Cls (TRUE);
  GrphText_Write (1, (t_uchar) ((40-strlen (Msg))/2*6), Msg, FONT_7X5, (t_uchar) strlen (Msg),
                  TRUE, FALSE);


  /*-------------------------------------------------------*/
  /* Ramdisk init (includes error handler for disk access) */
  /*-------------------------------------------------------*/
  
  RamDisk_Init ();

  /* Init. Error logger */
  Errlog_Init ();

  /*------------*/
  /* Init. UART */
  /*------------*/
  
  Uart_Init ();

  /*----------------------*/
  /* Init. Parallel ports */
  /*----------------------*/

  Parallel_Init ();

  /*-----------------*/
  /* End nosdos Init */
  /*-----------------*/

  /*-----------*/
  /* App. Init */
  /*-----------*/

  /* Database Init */
  DB_InitStaticData ();

  RetVal = DB_LoadDBGlobal ();
  if (RetVal != DB_OK)
  { /* ??? Disk error: ends application ??? */
  } /* endif */
  DB_InitDynamicData ();

  /* Communication Init */
  Comm_Init ();

#if defined (FEDORA_VERSION)
  /* Ping IP address to initialize vpn */
  TCPIP_Init_Tunnel();
  /* Get and Apply last contrast value configured */
  Display_GetAndApplyContrast();
#endif

  /* Comm_Init for backup line if it is configured */
  {
    t_uchar CurrentLineType, OperationMode;

    DB_OperationMode (&OperationMode);
    if (OperationMode == OPERATIONMODE_REALONLINEBACKUP)
    {
      DB_CurrentLineType (&CurrentLineType);
      /* Change current line type to backup line */
      DB_GLOBAL_DYNAMIC.DB_CURRENT_LINETYPE = LINETYPE_BACKUP;
      /* Init backup line */
      Comm_PhysInitComm ();
      /* Restore main line type */
      DB_GLOBAL_DYNAMIC.DB_CURRENT_LINETYPE = CurrentLineType;
    } /* endif */
  }

  /* Comm_Init for main line */
  Comm_PhysInitComm ();

  Comm_CommDeviceInit ();

  /* App. protocol */
  Prot_Init ();

#if defined(ENABLE_HOTLINE)
  /* Init. Answer logger of hotline */
  Hotline_Init ();
#endif

  /* Devices init */
  Devices_Init ();
  /* Enable OMR device */
  Devices_SetState (DEVCODE_OMR, DEVSTATE_ENABLED);

  /*----------------------*/
  /* Init. printer module */
  /*----------------------*/

  DB_NumPrinters (&NumPrinters);

  for (PrinterIndex = 0; PrinterIndex < NumPrinters; PrinterIndex++)
  {
    DB_PrinterInfo (PrinterIndex, &Type, &Port, &Model);
    Printer_Init (PrinterIndex, Type, Port, Model, TRUE);
  } /* endfor */

  /* Invert screen option */
  DB_GetInvertScreen (&InvertScreen);
  GrphDisp_SetInvertScreen (InvertScreen);

  /* LCD Contrast */
  DB_GetLCDContrastOffset (&LCDContrastOffset);
  Util_SetLCDContrast (LCDContrastOffset);

  /*----------------------*/
  /* App. crc error check */
  /*----------------------*/

  DB_ChkAppCrcError ();

  /*---------------*/
  /* End App. Init */
  /*---------------*/

  /* Clear message from virtual display */
  GrphText_Cls (FALSE);
  GrphText_PopDown (FALSE);

} /* Main_Init */
Exemple #10
0
char *readfile(messagerec *m1, char *aux, long *l)
/* reads a message from disk into memory */
{
  int f,csec;
  long l1,l2;
  char *b,s[81],s1[81];
  messagerec m;

  setcbrk(0);
  *l=0L;
  m=*m1;
  switch(m.storage_type) {
    case 0:
    case 1:
      strcpy(s,syscfg.msgsdir);
      ltoa(m.stored_as,s1,16);
      if (m.storage_type==1) {
        strcat(s,aux);
	strcat(s,"\\");
      }
      strcat(s,s1);
      f=sh_open1(s,O_RDONLY | O_BINARY);
      if (f==-1) {
        *l=0L;
        return(NULL);
      }
      l1=filelength(f);
      if ((b=(char *)farmalloc(l1))==NULL) {
        sh_close(f);
        return(NULL);
      }
      sh_read(f,(void *)b,l1);
      sh_close(f);
      *l=l1;
      break;
    case 2:
      f=open_file(aux);
      csec=m.stored_as;
      l1=0;
      while ((csec>0) && (csec<2048)) {
        l1+=512L;
        csec=gat[csec];
      }
      if (!l1) {
        sh_close(f);
        return(NULL);
      }
      if ((b=(char *)farmalloc(l1))==NULL) {
        sh_close(f);
        return(NULL);
      }
      csec=m.stored_as;
      l1=0;
      while ((csec>0) && (csec<2048)) {
        sh_lseek(f,4096L + 512L*csec,SEEK_SET);
        l1+=(long)read(f,(void *)(&(b[l1])),512);
        csec=gat[csec];
      }
      sh_close(f);
      l2=l1-512;
      while ((l2<l1) && (b[l2]!=26))
	++l2;
      *l=l2;
      break;
    case 255:
      f=sh_open1(aux,O_RDONLY | O_BINARY);
      if (f==-1) {
        *l=0L;
        return(NULL);
      }
      l1=filelength(f);
      if ((b=(char *)farmalloc(l1+256L))==NULL) {
        sh_close(f);
        return(NULL);
      }
      sh_read(f,(void *)b,l1);
      sh_close(f);
      *l=l1;
      break;
    default:
      /* illegal storage type */
      *l=0L;
      b=NULL;
      break;
  }
  return(b);
}
Exemple #11
0
void savefile(char *b, long l1, messagerec *m1, char *aux)
/* saves a message in memory to disk */
{
  int f,gatp,i5,i4,gati[128];
  messagerec m;
  char s[81],s1[81];
  int section;
  long l2;

  setcbrk(0);
  m=*m1;
  switch(m.storage_type) {
    case 0:
    case 1:
      lock_status();
      m.stored_as=status.qscanptr++;
      save_status();
      ltoa(m.stored_as,s1,16);
      strcpy(s,syscfg.msgsdir);
      if (m.storage_type==1) {
        strcat(s,aux);
        strcat(s,"\\");
      }
      strcat(s,s1);
      f=sh_open(s,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
      sh_write(f, (void *)b,l1);
      sh_close(f);
      break;
    case 2:
      f=open_file(aux);
      if (f>0) {
        for (section=0; section<1024; section++) {
          set_gat_section(f,section);
          gatp=0;
          i5=(int) ((l1 + 511L)/512L);
          i4=1;
          while ((gatp<i5) && (i4<2048)) {
            if (gat[i4]==0)
              gati[gatp++]=i4;
            ++i4;
          }
          if (gatp>=i5) {
            l2=MSG_STARTING;
            gati[gatp]=-1;
            for (i4=0; i4<i5; i4++) {
              sh_lseek(f,l2 + 512L * (long)(gati[i4]),SEEK_SET);
              sh_write(f,(void *)(&b[i4*512]),512);
              gat[gati[i4]]=gati[i4+1];
            }
            save_gat(f);
            break;
          }
        }
        sh_close(f);
      }
      m.stored_as=((long) gati[0]) + ((long)gat_section)*2048L;
      break;
    case 255:
      f=sh_open(aux,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
      sh_write(f, (void *)b,l1);
      sh_close(f);
      break;
    default:
      break;
  }
  farfree((void *)b);
  *m1=m;
}
Exemple #12
0
CROSSCUT_NLS_DATA

int
main (int argc, char *argv[])
{
  int memkind, handle;
  char loop1, loop2;
  struct dfree free;
  char buf[BUFFERSIZE];
  char cmpbuf[BUFFERSIZE];
  unsigned long sector, total, disksize, allocated, beginsector, endsector;
  unsigned long FilledDiskSize, FilledTotal, FileSize = 0;
  int Arg1IsFile, Arg2IsFile;
  int UseImageFile, ImageModus, Overwrite;
  int i, enable;
  int audible, verify, fallthrough, askdisk, asktdisk;
  char sdrive, tdrive;
  int HardDiskOk;
  int informative, copyfast;
  char switchchar;
  int tocopysectors;
  unsigned tobuffer;
#ifndef ALL_RECOVERY_MODE
  int recoverymode;
#endif
  int bytespersector;
  int CopyingToSameDisk = FALSE;
  int action, success;
  struct LFNAttribute attr;

  struct IniParserStruct *ParsedData;
  struct TwoDriveCopyData tdrvdata;

  attr.output = TRUE;

  memkind = UNALLOCATED;
  UseImageFile = FALSE;

  SetExePath (argv[0]);		/* Remember executable's path.     */
  CriticalHandlerOn ();		/* Install critical handler.       */
  InitLFNAPI ();		/* Initialise LFN API.             */

  CROSSCUT_NLS_OPEN

    switchchar = SwitchChar ();

  /* Check arguments */
  if ((argc == 2) && ((argv[1][0] == '/') || (argv[1][0] == switchchar)) &&
      (argv[1][1] == '?') && (argv[1][2] == '\0'))
    {
      ShowHelp (switchchar);
      return COPYSUCCESS;
    }

  if (argc > 2)
    {
      Arg1IsFile = IsFile (argv[1]);
      Arg2IsFile = IsFile (argv[2]);
    }

#ifdef DEF_HELP
  if (argc < 3)
    {
      /* The way we do it.                */
      ShowHelp (switchchar);
      return INITERROR;
    }
  else if ((!HasFloppyForm (argv[1]) && !Arg1IsFile) ||
	   (!HasFloppyForm (argv[2]) && !Arg2IsFile))
#else
  if ((argc < 3) || (!HasFloppyForm (argv[1]) && !Arg1IsFile)
      || (!HasFloppyForm (argv[2]) && !Arg2IsFile))
#endif
    {
      /* The way (DR and MS) DOS does it. */
      NLS_PUTSTRING (1, 0, "Invalid drive specification or non removable media.");
      return INITERROR;
    }

  if (ParseIniFile (NULL) < 0)	/* Parse .ini file. */
    {
      NLS_PUTSTRING (1, 1, "Error reading configuration file.");
      return INITERROR;
    }

  ParsedData = GetParsedData ();

  audible = ParsedData->audible;
  verify = ParsedData->verify;
  HardDiskOk = ParsedData->UseSWAP;
  informative = ParsedData->informative;
  Overwrite = ParsedData->overwrite;
  fallthrough = ParsedData->autoexit;
  askdisk = ParsedData->askdisk;
  asktdisk = ParsedData->asktdisk;
  copyfast = (ParsedData->speed == FAST);
#ifndef ALL_RECOVERY_MODE
  recoverymode = ParsedData->mode;
#endif

  /* Check arguments. */
  for (i = 3; i < argc; i++)
    {
      if (strlen (argv[i]) > 3)
	{
	  NLS_PRINTSTRING (1, 2, "Invalid switch:");
	  printf (" %s\n", argv[i]);
	  return INITERROR;
	}

      enable = TRUE;
      if (strlen (argv[i]) == 3)
	{
	  if (argv[i][2] == '-')
	    {
	      enable = FALSE;
	    }
	  else
	    {
	      NLS_PRINTSTRING (1, 2, "Invalid switch");
	      printf (" %s\n", argv[i]);
	      return INITERROR;
	    }
	}

      if ((argv[i][0] == switchchar) || (argv[i][0] == '/'))
	switch (argv[i][1])
	  {
	  case 'a':		/* DOS is case insensitive. */
	  case 'A':
	    audible = enable;
	    break;
	  case 'v':
	  case 'V':
	    verify = enable;
	    break;
	  case 'm':
	  case 'M':
	    HardDiskOk = !enable;
	    break;
	  case 'i':
	  case 'I':
	    informative = enable;
	    break;
	  case 'o':
	  case 'O':
	    Overwrite = enable;
	    break;
	  case 'x':
	  case 'X':
	    fallthrough = enable;
	    break;
	  case 'd':
	  case 'D':
	    askdisk = !enable;
	    break;

	  case 'f':
	  case 'F':
	    copyfast = enable;
	    break;

#ifndef ALL_RECOVERY_MODE
	  case 'r':
	  case 'R':
	    recoverymode = enable;
	    break;
#else
	  case 'r':
	  case 'R':
#endif
	  case 't':
	  case 'T':
	    asktdisk = !enable;
	    break;

	  case '1':
	    NLS_PRINTSTRING (2, 0, "Warning: option");
	    printf (" %s ", argv[i]);
	    NLS_PUTSTRING (2, 1, "doesn't do anything!");
	    break;

	  default:
	    NLS_PRINTSTRING (1, 2, "Invalid switch");
	    printf (" %s\n", argv[i]);
	    return INITERROR;
	  }
      else
	{
	  NLS_PRINTSTRING (1, 3, "Too many parameters:");
	  printf (" %s\n", argv[i]);
	  return INITERROR;
	}
    }

  if (Arg1IsFile && Arg2IsFile)
    {
      ConvertToSFN (argv[1], INFILE_ID);
      ConvertToSFN (argv[2], OUTFILE_ID);

      SetLFNAttribute (&attr, OUTFILE_ID);

      if ((access (GetSFN (OUTFILE_ID), EXISTS) == 0) &&
	  Overwrite &&
	  (remove (GetSFN (OUTFILE_ID)) == -1))
	{
	  NLS_PUTSTRING (1, 4, "File is write protected!");
	  return INITERROR;
	}

      if (CopyFile (GetSFN (INFILE_ID), GetSFN (OUTFILE_ID)))
	{
	  printf ("%s ", argv[1]);
	  NLS_PRINTSTRING (1, 5, "copied to");
	  printf (" %s", argv[2]);
	  if (audible)
	    Beep ();

	  SynchronizeLFNs ();
	  return COPYSUCCESS;
	}
      else
	{
	  NLS_PRINTSTRING (3, 0, "Problem copying");
	  printf (" %s ", argv[1]);
	  NLS_PRINTSTRING (3, 1, "to");
	  printf (" %s.\n", argv[2]);
	  return CRITICAL;
	}
    }
  else if (Arg1IsFile)
    {
      ConvertToSFN (argv[1], INFILE_ID);

      if (access (GetSFN (INFILE_ID), READPERMISSION) != 0)
	{
	  NLS_PRINTSTRING (1, 6, "File not found:");
	  printf (" %s\n", argv[1]);
	  return INITERROR;
	}

      CopyingToSameDisk = IsCopyToSameDisk (argv[1], argv[2]);
      UseImageFile = TRUE;
      ImageModus = READIMAGE;
    }
  else if (Arg2IsFile)
    {
      CopyingToSameDisk = IsCopyToSameDisk (argv[2], argv[1]);

      ConvertToSFN (argv[2], OUTFILE_ID);

      SetLFNAttribute (&attr, OUTFILE_ID);

      if (!CopyingToSameDisk)
	{
	  if (access (GetSFN (OUTFILE_ID), EXISTS) == 0)
	    {
	      if (Overwrite)
		{
		  if (remove (GetSFN (OUTFILE_ID)) != 0)
		    {
		      NLS_PRINTSTRING (1, 4, "File is write protected!");
		      return INITERROR;
		    }
		}
	      else
		{
		  NLS_PRINTSTRING (1, 7, "File already exists!");
		  return INITERROR;
		}
	    }
	}

      if (CopyingToSameDisk)
	copyfast = TRUE;
      UseImageFile = TRUE;
      ImageModus = WRITEIMAGE;
    }

  sdrive = (char) toupper (argv[1][0]) - 65;
  tdrive = (char) toupper (argv[2][0]) - 65;

  loop1 = CatYES;		/* initialize loop1         */
  loop2 = CatYES;		/* initialize loop2         */

  ctrlbrk (OnCBreak);
  SavedCBreak = getcbrk ();
  setcbrk (1);			/* set control-break to ON  */
  atexit (OnExit);		/* make sure that all allocated memory is released when
				   program stops. */

  if ((sdrive != tdrive) && (!UseImageFile) && BiosReportsTwoDrives ())
    {
      tdrvdata.sourcedrv = sdrive;
      tdrvdata.destdrv = tdrive;
      tdrvdata.cpybuf = buf;
      tdrvdata.cmpbuf = cmpbuf;
      tdrvdata.bufsize = BUFFERSIZE;
      tdrvdata.bel = audible;
      tdrvdata.fallthrough = fallthrough;
      tdrvdata.askdisk = askdisk;
      tdrvdata.copyfast = copyfast;
      tdrvdata.verify = verify;
#ifndef ALL_RECOVERY_MODE
      tdrvdata.recoverymode = recoverymode;
#endif
#ifdef UPDATE_SERIALNUM
      tdrvdata.updateserial = ParsedData->serialnumber;
#endif

      TwoDriveCopy (&tdrvdata);

      return COPYSUCCESS;
    }

  endsector = 0;
  while (!NLS_TEST_NO (loop1))	/* loop1 */
    {
      if (!UseImageFile || (ImageModus == WRITEIMAGE))
	{
	  if (askdisk)
	    {
	      puts ("");
	      NLS_PRINTSTRING (1, 8, "Insert SOURCE diskette into drive");
	      printf (" %s\n\n", argv[1]);
	      NLS_PRINTSTRING (1, 9, "Press any key to continue . . .");
	      WaitForInput ();
	      puts ("");
	    }
	  else
	    askdisk = TRUE;	/* Always ask after the first run. */
	}

      if (endsector == 0)
	{
	  if (!UseImageFile || (ImageModus == WRITEIMAGE))
	    {
	      if (!DiskReadBootInfo (sdrive, &free) ||
                  (DetermineFATType() != FAT12))
		{
		  puts ("");
		  NLS_PUTSTRING (1, 10, "Disk not ready!");
		  return CRITICAL;
		}
	    }
	  else
	    {
	      /* Remember file size */
	      handle = open (GetSFN (INFILE_ID), O_RDONLY | O_BINARY);
	      if (handle < 0)
		{
		  puts ("");
		  NLS_PUTSTRING (1, 11, "Unable to open image file.");
		  return INITERROR;
		}
	      FileSize = filelength (handle);
	      close (handle);

	      if (!FileReadBootInfo (GetSFN (INFILE_ID), &free))
		{
		  puts ("");
		  NLS_PUTSTRING (1, 11, "Unable to open image file.");
		  return INITERROR;
		}
	    }

	  total = free.df_total * free.df_sclus;
	  bytespersector = free.df_bsec;
	  disksize = total * bytespersector;

	  if (disksize == 0)
	    {
	      puts ("");
	      NLS_PUTSTRING (1, 0, "Invalid drive specification or non removable media.");
	      return INITERROR;
	    }

	  /* Initialize fast copy:
	     - After checking if disk in drive is ok, BUT
	     - before initializing memory                  */
	  /*
	     In case of writing an image file to disk. We'd like the
	     program to succeed regardless of wether we used the
	     /f switch or corresponding .ini file entry             */
	  if (((copyfast) ||
	       ((UseImageFile && (ImageModus == READIMAGE)) &&
		disksize != FileSize)) &&
	      (disksize != FileSize))
	    {
	      SetCopySpeed (FAST);

	      if (!UseImageFile || (ImageModus == WRITEIMAGE))
		{
		  if (!DiskReadFatInfo (sdrive))
		    SetCopySpeed (FULL);
		}
	      else if (!FileReadFatInfo (GetSFN (INFILE_ID)))
		{
		  NLS_PUTSTRING (1, 32, "Can not copy image file");
		  return INITERROR;
		}
	    }
	  else
	    SetCopySpeed (FULL);
	}

      puts ("");

      /* Get the size of the meaningfull data on the disk */
      FilledDiskSize = GetDiskFilledSize (BUFFERSIZE);
      FilledTotal = (FilledDiskSize / free.df_bsec) / free.df_sclus;

      if ((UseImageFile) && (!CopyingToSameDisk))
	switch (SetImageFile (GetSFN (ImageModus - 1), ImageModus, FilledDiskSize))
	  {
	  case EZERO:
	    allocated = disksize;
	    break;

	  case DISKTOSMALL:
	    puts ("");
	    NLS_PUTSTRING (1, 12, "Not enough disk space on target drive!");
	    return INITERROR;

	  default:
	    NLS_PRINTSTRING (1, 13, "Error accessing image file:");
	    printf (" %s\n", argv[ImageModus]);
	    return INITERROR;
	  }
      else
	{
	  if (CopyingToSameDisk)
	    switch (ImageModus)
	      {
	      case READIMAGE:
		memkind = InitializeFittingMemory (FilledDiskSize, HardDiskOk, &allocated,
						   '\0', argv[2][0]);
		break;
	      case WRITEIMAGE:
		memkind = InitializeFittingMemory (FilledDiskSize, HardDiskOk, &allocated,
						   argv[1][0], '\0');
		break;
	      }
	  else
	    memkind = InitializeFittingMemory (FilledDiskSize, HardDiskOk, &allocated,
					       argv[1][0], argv[2][0]);

	  if (memkind == 0)
	    {
	      NLS_PUTSTRING (1, 14, "Insufficient memory for disk copy.\n");
	      return INITERROR;
	    }
	}

      if (CopyingToSameDisk)
	{
	  if (allocated != FilledDiskSize)
	    {
	      NLS_PUTSTRING (1, 14, "Insufficient memory for disk copy.\n");
	      return INITERROR;
	    }

	  if (ImageModus == READIMAGE)
	    {
	      PrepareForWriting ();
	      if (!ReadFileIntoMemory (GetSFN (INFILE_ID), buf, BUFFERSIZE))
		{
		  NLS_PUTSTRING (1, 33, "Problem reading image file.");
		  return CRITICAL;
		}
	    }
	  else
	    /* ImageModus == WRITEIMAGE */ if (!asktdisk)
	    {
	      if (!DiskLargeEnough (GetSFN (OUTFILE_ID), FilledDiskSize))
		{
		  puts ("");
		  NLS_PUTSTRING (1, 12, "Not enough disk space on target drive!");
		  return INITERROR;
		}
	    }
	}

      if (!UseImageFile || (ImageModus == WRITEIMAGE))
	{
	  beginsector = endsector;
	  endsector += allocated / BYTESPERSECTOR;
	  if ((endsector > total) || (allocated == FilledDiskSize))
	    endsector = total;
	}

      if (!UseImageFile || (ImageModus == WRITEIMAGE))
	{
	  NLS_PRINTSTRING (4, 0, "Copying");
	  printf (" %d ", (int) FilledTotal);
	  NLS_PRINTSTRING (4, 1, "clusters");
	  printf (", %d ", free.df_sclus);
	  NLS_PRINTSTRING (4, 2, "sectors per cluster");
	  printf (", %d ", free.df_bsec);
	  NLS_PRINTSTRING (4, 3, "bytes per sector");
	  puts (".");
	  NLS_PRINTSTRING (4, 4, "Relevant drive size is");
	  printf (" %lu ", FilledDiskSize);
	  NLS_PRINTSTRING (4, 5, "bytes");
	  printf (".");
	}

      if (informative && (!UseImageFile))
	{
	  printf (" ");
	  NLS_PRINTSTRING (1, 15, "Using");
	  printf (" ");

	  switch (memkind)
	    {
	    case EMS:
	      puts ("EMS.\n");
	      break;
	    case XMS:
	      puts ("XMS.\n");
	      break;
	    case HARDDISK:
	      NLS_PUTSTRING (1, 16, "temporary file");
	      puts ("");
	      break;
	    case BUFFERS:
	      NLS_PRINTSTRING (5, 0, "buffer of");
	      printf (" %ld ", allocated);
	      NLS_PUTSTRING (5, 1, "bytes.");
	      puts ("");
	      break;
	    }
	}
      else if (!UseImageFile || (ImageModus == WRITEIMAGE))
	puts ("\n");

      if (!UseImageFile || (ImageModus == WRITEIMAGE))
	{

	  for (action = DISKREADING;
	       (verify) ? (action <= VERIFICATION) : (action < VERIFICATION);
	       action++)
	    {
	      if (action == DISKREADING)
		{
		  if (!UseImageFile)
		    {
		      NLS_PRINTSTRING (1, 17, "Reading SOURCE diskette . . .");
		    }
		  else
		    NLS_PRINTSTRING (1, 34, "Creating image file . . .");

		  PrepareForWriting ();
		}
	      else
		{
		  puts ("");
		  NLS_PRINTSTRING (1, 38, "Verifying . . .");

		  PrepareForReading ();
		}

	      for (sector = beginsector; sector < endsector;
		   sector = sector + TOCOPYSECTORS)
		{
		  if (sector < endsector - TOCOPYSECTORS)
		    tocopysectors = TOCOPYSECTORS;
		  else
		    tocopysectors = (int) (endsector - sector);
		  tobuffer = (unsigned) (tocopysectors * BYTESPERSECTOR);

		  if (IsDiskReadRequired (sector, tocopysectors))	/* Fast copy */
		    {
#ifndef ALL_RECOVERY_MODE
		      if (recoverymode)
#endif

			ReadSectors (sdrive, tocopysectors, (int) sector, buf,
				     bytespersector);
#ifndef ALL_RECOVERY_MODE
		      else if (absread (sdrive, tocopysectors, (int) sector, buf) != 0)
			{
			  puts ("");
			  NLS_PRINTSTRING (1, 18, "Media error reading from sector");
			  printf (" %ld.\n", sector);
			}
#endif
		      if (action == DISKREADING)
			success = WriteMemoryBlock (buf, tobuffer);
		      else
			success = ReadMemoryBlock (cmpbuf, tobuffer);

		      if (!success)
			{
			  puts ("");
			  NLS_PUTSTRING (1, 20, "Unsuspected memory error.");
			  SetErrorStopped ();
			  return CRITICAL;
			}

		      if (action == VERIFICATION)
			{
			  if (memcmp (buf, cmpbuf, 5 /*tobuffer */ ) != 0)
			    {
			      puts ("");
			      NLS_PRINTSTRING (1, 37, "Compare error on sector");
			      printf (" %ld.\n", sector);
			    }
			}
		    }
		}
	    }
	}

      if (audible && (!UseImageFile))
	Beep ();

      if (!UseImageFile || (ImageModus == READIMAGE))
	{
	  while (!NLS_TEST_NO (loop2))	/* loop2 */
	    {
	      if (askdisk)
		{
		  if (!UseImageFile)
		    puts ("\n");
		  NLS_PRINTSTRING (1, 21, "Insert TARGET diskette into drive");
		  printf (" %s\n\n", argv[2]);
		  NLS_PRINTSTRING (1, 9, "Press any key to continue . . .");
		  WaitForInput ();
		}
	      else
		askdisk = TRUE;

	      /* Check disk capacity is the same as that of the original
	         diskette. */
	      for (;;)
		{
		  if (!DiskReadBootInfo (tdrive, &free))
		    {
		      puts ("");
		      NLS_PUTSTRING (1, 10, "Disk not ready!");
		      total = 0;
		    }
		  else
		    total = free.df_total * free.df_sclus;

		  if (((UseImageFile) && (FileSize != FilledDiskSize)) ||
		      (disksize != total * free.df_bsec))
		    {
		      puts ("");
		      NLS_PUTSTRING (1, 22, "Diskette does not have the same capacity as the original.");

		      if (fallthrough)
			return NONFATAL;

		      puts ("");
		      NLS_PRINTSTRING (1, 23, "Put a diskette with the right capacity in drive");
		      printf (" %s, \n", argv[2]);
		      NLS_PUTSTRING (1, 24, "or press CTRL-C to cancel.");
		      WaitForInput ();	/* When the user presses CTRL-C this function does not return */
		    }
		  else
		    break;
		}

	      if (UseImageFile)
		{
		  puts ("\n");
		  NLS_PRINTSTRING (4, 0, "Copying");
		  printf (" %d ", (int) FilledTotal);
		  NLS_PRINTSTRING (4, 1, "clusters");
		  printf (", %d ", free.df_sclus);
		  NLS_PRINTSTRING (4, 2, "sectors per cluster");
		  printf (", %d ", free.df_bsec);
		  NLS_PRINTSTRING (4, 3, "bytes per sector");
		  puts (".");
		  NLS_PRINTSTRING (4, 4, "Relevant drive size is");
		  printf (" %lu ", FilledDiskSize);
		  NLS_PRINTSTRING (4, 5, "bytes");
		  puts (".");

		  beginsector = endsector;
		  endsector += allocated / BYTESPERSECTOR;
		  if (endsector > total)
		    endsector = total;
		}

	      for (action = DISKWRITING;
	      (verify) ? (action <= VERIFICATION) : (action < VERIFICATION);
		   action++)
		{
		  if (action == DISKWRITING)
		    {
		      if (UseImageFile)
			{
			  puts ("");
			  NLS_PRINTSTRING (1, 35, "Writing image file . . .");
			}
		      else	

			{
			  puts ("\n");
			  NLS_PRINTSTRING (1, 25, "Writing to TARGET diskette in drive . . .");
			}
		      PrepareForReading ();
		    }
		  else	/* VERIFICATION */
		    {
		      puts ("");
		      NLS_PRINTSTRING (1, 38, "Verifying . . .");
		      PrepareForReading ();	/* Rewind */

		    }


		  for (sector = beginsector; sector < endsector;
		       sector = sector + TOCOPYSECTORS)
		    {
		      if (sector < endsector - TOCOPYSECTORS)
			tocopysectors = TOCOPYSECTORS;
		      else
			tocopysectors = (int) (endsector - sector);
		      tobuffer = (unsigned) (tocopysectors * BYTESPERSECTOR);

		      if (IsDiskReadRequired (sector, tocopysectors))
			{
			  if (!ReadMemoryBlock (buf, tobuffer))
			    {
			      puts ("");
			      NLS_PUTSTRING (1, 20, "Unsuspected memory error.");
			      SetErrorStopped ();
			      return CRITICAL;
			    }

			  if (action == DISKWRITING)
			    {
#ifdef UPDATE_SERIALNUM
			      if (sector == 0)
				{
				  if (ParsedData->serialnumber == UPDATE)
				    UpdateDiskSerialNumber (buf);
				}
#endif
			      if (abswrite (tdrive, tocopysectors, (int) sector, buf) != 0)
				{
				    if (sector == 0)
				    {
					if (abswrite(tdrive, 1, 0, buf) != 0)
					{
					    puts("\n");
					    NLS_PRINTSTRING(1, 41, "Sector 0 unwritable! Write protected?");
					    
					    if (FilledDiskSize == allocated) 
					 	break; 
					    else 
						return CRITICAL;	
					}
				     }				    				   
				    
				  puts ("");
				  NLS_PRINTSTRING (1, 27, "Media error writing to sector");
				  printf (" %ld.\n", sector);
				}
			    }
			  else
			    {

			      if (absread (tdrive, tocopysectors, (int) sector, cmpbuf) != 0)
				{
				  puts ("");
				  NLS_PRINTSTRING (1, 18, "Media error reading from sector");
				  printf (" %ld.\n", sector);
				}

			      if (sector == 0)
				{
				  if (ParsedData->serialnumber == UPDATE)
				    {
				      ClearDiskSerialNumber (buf);
				      ClearDiskSerialNumber (cmpbuf);
				    }
				}

			      if (memcmp (buf, cmpbuf, tobuffer) != 0)
				{
				  puts ("");
				  NLS_PRINTSTRING (1, 37, "Compare error on sector");
				  printf (" %ld.\n", sector);
				}
			    }
			}
		    }
		}
	      if (!UseImageFile)
		puts ("");

	      if (UseImageFile || (FilledDiskSize == allocated))	/* If everything fitted in memory */
		{
		  loop2 = (fallthrough) ? CatNO : CatNO + 1;
		  if (loop2 == CatYES)
		    loop2++;
		  while (!NLS_TEST_YES_NO (loop2))
		    {
		      ClrKbd ();
		      if (audible)
			Beep ();
		      puts ("");
		      if (UseImageFile)
			puts ("");
		      NLS_PRINTSTRING (1, 28, "Do you want another copy of this ");
		      if (UseImageFile)
			{
			  endsector = 0;
			  NLS_PRINTSTRING (1, 29, "image file (Y/N)?");
			}
		      else
			NLS_PRINTSTRING (1, 30, "disk (Y/N)?");

		      loop2 = toupper (getch ());
		      puts ("");
		    }
		  if (UseImageFile && (NLS_TEST_YES (loop2)))
		    puts ("");
		}
	      else
		{
		  puts ("");
		  loop2 = CatNO;
		}

	      /* Change the serial number of the target disk. */
#ifdef UPDATE_SERIALNUM
	      if (ParsedData->serialnumber == UPDATE)
		{
		  puts ("");
		  PrintDiskSerialNumber ();
		  puts ("");
		}
#endif
	    }			/*  loop2 */

	  loop2 = CatYES;
	  if (loop2 == CatNO)
	    loop2++;
	  ReleaseMemory ();
	}
      else
	{
	  if (CopyingToSameDisk)
	    {
	      PrepareForReading ();
	      if (!WriteFileFromMemory (GetSFN (OUTFILE_ID), buf, BUFFERSIZE,
					FilledDiskSize, asktdisk,
					fallthrough, Overwrite))
		{
		  NLS_PUTSTRING (1, 36, "Problem writing image file.");
		  return CRITICAL;
		}
	    }
	}

      loop1 = CatYES + 1;
      if (loop1 == CatNO)
	loop1++;
      if (!UseImageFile && !fallthrough && (endsector == total))
	{
	  while (!NLS_TEST_YES_NO (loop1))
	    {
	      ClrKbd ();
	      puts ("");
	      NLS_PRINTSTRING (1, 31, "Copy another disk (Y/N)?");
	      loop1 = toupper (getch ());
	      puts ("");
	      endsector = 0;
	    }
	}
      else if (UseImageFile || (fallthrough && (endsector == total)))
	{
	  loop1 = CatNO;
	  if (fallthrough)
	    puts ("");
	  else if (audible && (ImageModus == WRITEIMAGE))
	    Beep ();
	}

    }				/* end loop1 */

  if ((UseImageFile) && (ImageModus == WRITEIMAGE))
    puts ("");

  return COPYSUCCESS;
}