home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / FILES.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-31  |  4.8 KB  |  130 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // FILES.CPP - Declarations for creating UW clients for file transfers.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    06/05/91  RW  Original Version of FILES.CPP
  28. //
  29. // You may contact the author by:
  30. // =============================
  31. //
  32. //  e-mail: rhys@cs.uq.oz.au
  33. //    mail: Rhys Weatherley
  34. //          5 Horizon Drive
  35. //          Jamboree Heights
  36. //          Queensland 4074
  37. //        Australia
  38. //
  39. //-------------------------------------------------------------------------
  40.  
  41. #include <stdio.h>        // Standard I/O routines.
  42. #include "extern.h"        // DOS/Windows 3.0 declarations.
  43. #include "files.h"        // Declarations for this module.
  44. #include "keys.h"        // Keyboard handling declarations.
  45. #include "uw.h"            // Declarations for the protocol master.
  46. #include <dos.h>        // "delay" is defined here.
  47.  
  48. UWAsciiFileTransfer::UWAsciiFileTransfer (UWDisplay *wind,int type,char *name)
  49.         : UWFileTransfer (wind)
  50. {
  51.   kind = type;
  52.   capture = (kind == ASCII_CAPTURE);
  53.   if (type == ASCII_UPLOAD)
  54.     file = fopen (name,"rt");    // Open the Ascii file for text mode reading.
  55.    else if (type == ASCII_DOWNLOAD)
  56.     file = fopen (name,"wb");    // Open the Ascii file for binary mode writing.
  57.    else
  58.     file = fopen (name,"ab");    // Open the Ascii file for binary mode append.
  59.   UWMaster.install (this);    // Install the file transfer object.
  60.   if (file == NULL)
  61.     UWMaster.remove ();        // Remove object if initialisation failed.
  62.    else
  63.     setvbuf (file,NULL,_IOFBF,BUFSIZ); // Set a file buffer if possible.
  64. } // UWAsciiFileTransfer::UWAsciiFileTransfer //
  65.  
  66. // The destructor closes the transfer file if necessary so that
  67. // ASCII file transfers are correctly cleaned up if windows are
  68. // destroyed when protocol 1 exits.
  69. UWAsciiFileTransfer::~UWAsciiFileTransfer (void)
  70. {
  71.   if (file != NULL)
  72.     fclose (file);
  73. } // UWAsciiFileTransfer::~UWAsciiFileTransfer //
  74.  
  75. void    UWAsciiFileTransfer::key (int keypress)
  76. {
  77.   if ((kind == ASCII_CAPTURE && keypress == CAPTURE_KEY) ||
  78.       (kind != ASCII_CAPTURE && keypress == 033))
  79.     {
  80.       // termination key has been pressed - close off the transfer file //
  81.       fclose (file);
  82.       file = NULL;        // Indicator for the destructor.
  83.       UWMaster.remove ();    // Remove this client from the client stack.
  84.     }
  85.    else if (underneath)
  86.     underneath -> key (keypress); // Do the normal terminal key processing.
  87. } // UWAsciiFileTransfer //
  88.  
  89. void    UWAsciiFileTransfer::remote (int ch)
  90. {
  91.   if (kind != ASCII_UPLOAD)
  92.     fputc (ch,file);        // Save the character in the transfer file.
  93.   if (underneath)
  94.     underneath -> remote (ch);    // Do the normal terminal remote processing.
  95. } // UWAsciiFileTransfer //
  96.  
  97. void    UWAsciiFileTransfer::tick (void)
  98. {
  99.   if (kind == ASCII_UPLOAD)
  100.     {
  101.       int ch;
  102.       ch = fgetc (file);    // Get the next character to be transfered.
  103.       if (ch == '\n')        // Check for the end of the line.
  104.         {
  105.       send ('\r');        // Send a CR character at the end of lines.
  106.       DELAY_FUNC (10);    // Delay 10ms between lines to allow catch-up.
  107.     }
  108.        else if (ch != EOF)
  109.         send (ch);        // Send the transfer character directly.
  110.        else
  111.         {
  112.       // Upload is finished - clean up the transfer information //
  113.           fclose (file);
  114.           file = NULL;        // Indicator for the destructor.
  115.           UWMaster.remove ();    // Remove this client from the client stack.
  116.     }
  117.     }
  118.   if (underneath)
  119.     underneath -> tick ();    // Pass the tick on to the client underneath.
  120. } // UWAsciiFileTransfer::tick //
  121.  
  122. char    *UWAsciiFileTransfer::getstatus (void)
  123. {
  124.   static char *names[] =
  125.         {"ASCII upload in progress - ESC to abort",
  126.        "ASCII download in progress - ESC to abort/end",
  127.        "ASCII capture in progress - ALT-L to abort/end"};
  128.   return (names[kind]);
  129. } // UWAsciiFileTransfer::getstatus //
  130.