home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / ASCIIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  4.5 KB  |  119 lines

  1. /*
  2.  * ASCIIR.C
  3.  *
  4.  * Contains:          AsciiReceive()
  5.  *
  6.  * The Greenleaf Comm Library
  7.  *
  8.  * Copyright (C) 1989-90 Greenleaf Software Inc.  All Rights Reserved.
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include "gf.h"
  14. #include "asiports.h"
  15. #include "xfer.h"
  16. #include "_xfer.h"
  17.  
  18. /*
  19.  * int AsciiReceive( int port,
  20.  *                   char *file_name,
  21.  *                   void ( *message_routine )( char *message ),
  22.  *                   void ( *idle_routine )( XFER *status_block ),
  23.  *                   void ( *echo_routine )( int c ),
  24.  *                   char strip_lf,
  25.  *                   unsigned int abort_key )
  26.  *
  27.  * ARGUMENTS
  28.  *
  29.  *  int port:                          This is the com port where the transfer
  30.  *                                     will be performed.  It should be open.
  31.  *
  32.  *  char *file_name:                   The file to be opened which will receive
  33.  *                                     all the downloaded characters..
  34.  *
  35.  *  void ( *message_routine )( char * ):A routine to print character messages
  36.  *                                      sent out by the driver.  NULL for no
  37.  *                                      routine present.
  38.  *
  39.  *  void ( *idle_routine )( XFER * ):  An idle routine.  It gets a parameter
  40.  *                                     block pointer, enabling it to print
  41.  *                                     out statistics.  NULL for no routine.
  42.  *
  43.  *  void ( *echo_routine )( int c ):   During ASCII transfers, it is often
  44.  *                                     useful to be able to see what the
  45.  *                                     remote end is sending.  This function
  46.  *                                     allows the program to print the
  47.  *                                     characters, one at a time, as
  48.  *                                     they are received.
  49.  *
  50.  *  char strip_lf:                     This flag indicates whether line feed
  51.  *                                     characters should be stripped from
  52.  *                                     the incoming data.  A lot of times
  53.  *                                     each line should just be terminated
  54.  *                                     with a CR, not an LF also.
  55.  *
  56.  *  unsigned int abort_key:            A user defined abort key.  Control X
  57.  *                                     conventionally, but ESC is good too.
  58.  *                                     Note that in this case, hitting
  59.  *                                     the abort key will not return an
  60.  *                                     error code, as this is really one of
  61.  *                                     only two legitimate ways to stop an
  62.  *                                     ASCII file transfer.
  63.  *
  64.  * DESCRIPTION
  65.  *
  66.  * This routine calls the driver routine to perform an ASCII file
  67.  * download.  Note that ASCII downloads have no handshaking.
  68.  * This means the receiver has to be able to suck in the data as fast
  69.  * as possible.  If RTS/CTS or XON/XOFF flow control are turned on,
  70.  * they will work properly, and provide a usable means of flow control.
  71.  * The download terminates normally when either the user hits the
  72.  * abort key, or a timeout occurs.  The timeout constant is defined in
  73.  * XFER.H.
  74.  *
  75.  * SIDE EFFECTS
  76.  *
  77.  * File may have been transfered.
  78.  *
  79.  * RETURNS
  80.  *
  81.  * This routine returns the xfer status word that was set up
  82.  * by the driver routine.  The interpretation of the return values
  83.  * is described in the include file, "XFER.H", which also contains
  84.  * their definitions.
  85.  *
  86.  * AUTHOR
  87.  *  Mark Nelson          26-Sep-1989  20:57:40.92
  88.  *
  89.  * MODIFICATIONS
  90.  *
  91.  */
  92. int GF_CONV AsciiReceive( int port,
  93.                   char *file_name,
  94.                   void (GF_CDECL *message_routine )( char *message ),
  95.                   void (GF_CDECL *idle_routine )( XFER *status_block ),
  96.                   void (GF_CDECL *echo_routine )( int c ),
  97.                   char strip_lf,
  98.                   unsigned int abort_key )
  99. {
  100.     XFER ascii;
  101.  
  102.     ascii.port = port;
  103.     ascii.return_file_name = NULL;
  104.     ascii.filename = file_name;
  105.     ascii.file_length = 0L;
  106.     ascii.message_routine = message_routine;
  107.     ascii.idle_routine = idle_routine;
  108.     ascii.abort_key = abort_key;
  109.     ascii.transfer_type = XFER_TYPE_ASCII;
  110.     ascii.x.ascii.received_character_printer = echo_routine;
  111.     ascii.x.ascii.strip_lf = strip_lf;
  112.     _AsciiReceive( &ascii );
  113.     if ( ascii.return_status == XFER_RETURN_KEYBOARD_ABORT )
  114.         return( XFER_RETURN_SUCCESS );
  115.     else
  116.         return( ascii.return_status );
  117. }
  118.  
  119.