home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / UPLOAD.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  6KB  |  151 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*          This module was originally written by Vince Perriello           */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                BinkleyTerm Terminal/Script Upload Module                 */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50.  
  51. /*
  52.  * Handle uploads from terminal mode.
  53.  * Note: filepath parameter below will be trashed if it's a wildcard!
  54.  */
  55.  
  56. int Upload (char *filepath, int prot, char *extern_ptr)
  57. {
  58.    unsigned save1, save2, save3;
  59.    char *p;
  60.    struct FILEINFO fileinfo;
  61.  
  62.    int err = 1;                      /* Xmodem, Ymodem, Telink
  63.                                       * flag */
  64.  
  65.    if (dfind (&fileinfo, filepath, 0))
  66.       return (0);
  67.  
  68.    save1 = comm_bits;
  69.    save2 = parity;
  70.    save3 = stop_bits;
  71.    comm_bits = BITS_8;
  72.    parity = NO_PARITY;
  73.    stop_bits = STOP_1;
  74.    program_baud ();
  75.    XON_DISABLE ();
  76.  
  77.  
  78.    /* If external protocol requested, call it */
  79.  
  80.    if (extern_ptr != NULL)
  81.       do_extern ("Send", prot, filepath);
  82.    else switch (prot)
  83.       {
  84.       case 'X':
  85.       case 'Y':
  86.       err = Xmodem_Send_File (filepath, NULL);
  87.       break;
  88.  
  89.       default:
  90.  
  91.    /*
  92.     * Find the delimiter on the pathspec for use by the various
  93.     * batch protocols.
  94.     */
  95.  
  96.       p = strrchr (filepath, '\\');
  97.       if (p == NULL)
  98.          p = strrchr (filepath, '/');
  99.       if (p == NULL)
  100.          p = strchr (filepath, ':');
  101.       if (p == NULL)
  102.          p = filepath;
  103.       else
  104.          p++;
  105.  
  106.    /*  At this point *p points to the location in the input
  107.     *  string where the prepended path information ends. All
  108.     *  we need to do, then, is to keep plugging in the stuff
  109.     *  we get from _dos_find(first|next) and transfer files.
  110.     *  We already have the first matching filename from the
  111.     *  _dos_findfirst we did above, so we use a "do" loop.
  112.     */
  113.  
  114.       do
  115.          {
  116.          /* Append the current filename */
  117.          (void) strcpy (p, fileinfo.name);
  118.  
  119.          /* Send the file with the proper protocol */
  120.  
  121.          if (prot == 'Z')
  122.             err = Send_Zmodem (filepath, NULL, 0, 0);
  123.          else
  124.             {
  125.             err = !Batch_Send (filepath);
  126.             }
  127.          } while ((err) && (!dfind (&fileinfo, NULL, 1)));
  128.  
  129.  
  130.       /* Finish the proper protocol if need be */
  131.  
  132.       if (err)
  133.          {
  134.          if (prot == 'Z')
  135.             (void) Send_Zmodem (NULL, NULL, END_BATCH, 0);
  136.          else
  137.             (void) Batch_Send (NULL);
  138.          }
  139.       break;
  140.       }
  141.  
  142.    comm_bits = save1;
  143.    parity = save2;
  144.    stop_bits = save3;
  145.    program_baud ();
  146.    XON_ENABLE ();
  147.    gong ();
  148.  
  149.    return (err);
  150. }
  151.