home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / term232.lha / Source_Code / termSource / termTransfer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-18  |  15.6 KB  |  803 lines

  1. /*
  2. **    $Id: termTransfer.c,v 1.7 92/08/18 16:13:17 olsen Sta Locker: olsen $
  3. **    $Revision: 1.7 $
  4. **    $Date: 92/08/18 16:13:17 $
  5. **
  6. **    File transfer routines
  7. **
  8. **    Copyright ⌐ 1990-1992 by Olaf `Olsen' Barthel & MXM
  9. **        All Rights Reserved
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* The action strings to display. */
  15.  
  16. STATIC UBYTE *SendQuery[3] =
  17. {
  18.     NULL,
  19.     NULL,
  20.     NULL
  21. };
  22.  
  23. STATIC UBYTE *ReceiveQuery[3] =
  24. {
  25.     NULL,
  26.     NULL,
  27.     NULL
  28. };
  29.  
  30.     /* The transfer types to display. */
  31.  
  32. STATIC UBYTE *TransferTypes[3] =
  33. {
  34.     NULL,
  35.     NULL,
  36.     NULL
  37. };
  38.  
  39.     /* SendTextFile(UBYTE *TheFile):
  40.      *
  41.      *    Send a single text file via xpr.
  42.      */
  43.  
  44. VOID
  45. SendTextFile(UBYTE *TheFile)
  46. {
  47.     BYTE OldStatus = Status;
  48.  
  49.     Uploading    = TRUE;
  50.     MultipleFiles    = FALSE;
  51.  
  52.     LocalizeString(SendQuery,MSG_TERMTRANSFER_UPLOAD_FILE_TXT,MSG_TERMTRANSFER_UPLOAD_ASCII_TXT);
  53.     LocalizeString(TransferTypes,MSG_TERMTRANSFER_BINARY_TXT,MSG_TERMTRANSFER_ASCII_TXT);
  54.  
  55.         /* If not initialized, try to set up a new
  56.          * external transfer protocol.
  57.          */
  58.  
  59.     if(!XProtocolBase)
  60.     {
  61.         NewLibrary = FALSE;
  62.  
  63.         xpr_options(0,NULL);
  64.  
  65.         if(NewLibrary)
  66.         {
  67.             if(ProtocolSetup())
  68.             {
  69.                 SaveProtocolOpts();
  70.  
  71.                 strcpy(Config . Protocol,LastXprLibrary);
  72.             }
  73.         }
  74.     }
  75.  
  76.     if(XProtocolBase)
  77.     {
  78.         XprIO -> xpr_filename = TheFile;
  79.  
  80.         if(TransferPanel(SendQuery[TRANSFER_TEXT]))
  81.         {
  82.             BYTE Aborted;
  83.  
  84.             Status = STATUS_UPLOAD;
  85.  
  86.             ClearSerial();
  87.  
  88.             LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[TRANSFER_TEXT]);
  89.  
  90.             if(!XProtocolSend(XprIO))
  91.                 Aborted = TRUE;
  92.             else
  93.                 Aborted = FALSE;
  94.  
  95.             if(TransferWindow)
  96.             {
  97.                 WakeUp(TransferWindow);
  98.  
  99.                 WaitTime(2,0);
  100.             }
  101.  
  102.             if(Aborted)
  103.                 Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  104.             else
  105.                 Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  106.  
  107.             Status = OldStatus;
  108.  
  109.             DeleteTransferPanel();
  110.  
  111.             if(ReadRequest)
  112.             {
  113.                 ReadRequest -> IOSer . io_Command    = CMD_READ;
  114.                 ReadRequest -> IOSer . io_Data        = ReadBuffer;
  115.                 ReadRequest -> IOSer . io_Length    = 1;
  116.  
  117.                 SetSignal(0,SIG_SERIAL);
  118.  
  119.                 SendIO(ReadRequest);
  120.             }
  121.         }
  122.     }
  123.  
  124.     if(SendAbort && UsesZModem)
  125.         SerWrite(ZModemCancel,20);
  126.  
  127.     SendAbort = FALSE;
  128.  
  129.     Uploading = FALSE;
  130.  
  131.     if(Config . UploadMacro[0])
  132.         SerialCommand(Config . UploadMacro);
  133.  
  134.     DidTransfer = FALSE;
  135. }
  136.  
  137.     /* StartXprReceive():
  138.      *
  139.      *    Receive files via xpr.
  140.      */
  141.  
  142. VOID
  143. StartXprReceive(BYTE Type)
  144. {
  145.     struct FileRequester    *FileRequest;
  146.     UBYTE             DummyBuffer[256];
  147.     BYTE             OldStatus = Status;
  148.  
  149.     LocalizeString(ReceiveQuery,MSG_TERMTRANSFER_DOWNLOAD_FILE_TXT,MSG_TERMTRANSFER_DOWNLOAD_ASCII_TXT);
  150.     LocalizeString(TransferTypes,MSG_TERMTRANSFER_BINARY_TXT,MSG_TERMTRANSFER_ASCII_TXT);
  151.  
  152.         /* Select the download path. */
  153.  
  154.     switch(Type)
  155.     {
  156.         case TRANSFER_BINARY:    DownloadPath = &Config . BinaryDownloadPath[0];
  157.                     break;
  158.  
  159.         case TRANSFER_TEXT:    DownloadPath = &Config . TextDownloadPath[0];
  160.                     break;
  161.  
  162.         case TRANSFER_ASCII:    DownloadPath = &Config . ASCIIDownloadPath[0];
  163.                     break;
  164.     }
  165.  
  166.     BlockWindows();
  167.  
  168.         /* Set up the library if necessary. */
  169.  
  170.     if(!XProtocolBase)
  171.     {
  172.         NewLibrary = FALSE;
  173.  
  174.         xpr_options(0,NULL);
  175.  
  176.         if(NewLibrary)
  177.         {
  178.             if(ProtocolSetup())
  179.             {
  180.                 SaveProtocolOpts();
  181.  
  182.                 strcpy(Config . Protocol,LastXprLibrary);
  183.             }
  184.         }
  185.     }
  186.  
  187.     if(XProtocolBase)
  188.     {
  189.             /* Do we need to ask the user for
  190.              * the destination file name?
  191.              */
  192.  
  193.         if(TransferBits & XPRS_NORECREQ)
  194.         {
  195.                 /* Obviously not, let's open
  196.                  * the transfer info window as
  197.                  * usual and download the file(s).
  198.                  */
  199.  
  200.             if(TransferPanel(ReceiveQuery[Type]))
  201.             {
  202.                 Status = STATUS_DOWNLOAD;
  203.  
  204.                 ClearSerial();
  205.  
  206.                 LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_DOWNLOAD_TXT),TransferTypes[Type]);
  207.  
  208.                     /* Receive the data. */
  209.  
  210.                 if(!XProtocolReceive(XprIO))
  211.                     TransferAborted = TRUE;
  212.  
  213.                     /* In case the transfer has been aborted,
  214.                      * flush the input buffer of dirty data.
  215.                      */
  216.  
  217.                 if(TransferAborted)
  218.                     xpr_sflush();
  219.  
  220.                     /* Wake the user up. */
  221.  
  222.                 if(TransferWindow)
  223.                 {
  224.                     WakeUp(TransferWindow);
  225.  
  226.                     WaitTime(2,0);
  227.                 }
  228.  
  229.                 if(TransferAborted)
  230.                 {
  231.                     TransferAborted = FALSE;
  232.  
  233.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  234.                 }
  235.                 else
  236.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  237.  
  238.                 Status = OldStatus;
  239.  
  240.                     /* Queue another read request. */
  241.  
  242.                 if(ReadRequest)
  243.                 {
  244.                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  245.                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  246.                     ReadRequest -> IOSer . io_Length    = 1;
  247.  
  248.                     SetSignal(0,SIG_SERIAL);
  249.  
  250.                     SendIO(ReadRequest);
  251.                 }
  252.  
  253.                 DeleteTransferPanel();
  254.             }
  255.         }
  256.         else
  257.         {
  258.                 /* Download the file(s). */
  259.  
  260.             if(FileRequest = GetFile(ReceiveQuery[Type],DownloadPath,"",DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_TERMTRANSFER_RECEIVE_TXT)))
  261.             {
  262.                     /* Save the download path. */
  263.  
  264.                 strcpy(DownloadPath,FileRequest -> rf_Dir);
  265.  
  266.                     /* Install the name of the file to receive. */
  267.  
  268.                 XprIO -> xpr_filename = DummyBuffer;
  269.  
  270.                     /* Open the transfer panel. */
  271.  
  272.                 if(TransferPanel(ReceiveQuery[Type]))
  273.                 {
  274.                     Status = STATUS_DOWNLOAD;
  275.  
  276.                     ClearSerial();
  277.  
  278.                     LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_DOWNLOAD_TXT),TransferTypes[Type]);
  279.  
  280.                         /* Receive the file. */
  281.  
  282.                     if(!XProtocolReceive(XprIO))
  283.                         TransferAborted = TRUE;
  284.  
  285.                         /* In case the transfer has been aborted,
  286.                          * flush the input buffer of dirty data.
  287.                          */
  288.  
  289.                     if(TransferAborted)
  290.                         xpr_sflush();
  291.  
  292.                         /* Wake the user up. */
  293.  
  294.                     if(TransferWindow)
  295.                     {
  296.                         WakeUp(TransferWindow);
  297.  
  298.                         WaitTime(2,0);
  299.                     }
  300.  
  301.                     if(TransferAborted)
  302.                     {
  303.                         TransferAborted = FALSE;
  304.  
  305.                         Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  306.                     }
  307.                     else
  308.                         Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  309.  
  310.                     Status = OldStatus;
  311.  
  312.                         /* Close the transfer panel. */
  313.  
  314.                     DeleteTransferPanel();
  315.  
  316.                         /* Queue another read
  317.                          * request.
  318.                          */
  319.  
  320.                     if(ReadRequest)
  321.                     {
  322.                         ReadRequest -> IOSer . io_Command    = CMD_READ;
  323.                         ReadRequest -> IOSer . io_Data        = ReadBuffer;
  324.                         ReadRequest -> IOSer . io_Length    = 1;
  325.  
  326.                         SetSignal(0,SIG_SERIAL);
  327.  
  328.                         SendIO(ReadRequest);
  329.                     }
  330.                 }
  331.  
  332.                 FreeAslRequest(FileRequest);
  333.             }
  334.         }
  335.     }
  336.  
  337.     if(SendAbort && UsesZModem)
  338.         SerWrite(ZModemCancel,20);
  339.  
  340.     SendAbort = FALSE;
  341.  
  342.     ReleaseWindows();
  343.  
  344.     DownloadPath = NULL;
  345.  
  346.     DidTransfer = FALSE;
  347.  
  348.     if(Config . DownloadMacro[0])
  349.         SerialCommand(Config . DownloadMacro);
  350. }
  351.  
  352.     /* StartXprSend():
  353.      *
  354.      *    Send files via xpr.
  355.      */
  356.  
  357. BYTE
  358. StartXprSend(BYTE Type)
  359. {
  360.     struct FileRequester    *FileRequest;
  361.     UBYTE             DummyBuffer[256];
  362.     BYTE             OldStatus = Status;
  363.     UBYTE            *UploadPath;
  364.     BYTE             DidSend = TRUE;
  365.  
  366.     LocalizeString(SendQuery,MSG_TERMTRANSFER_UPLOAD_FILE_TXT,MSG_TERMTRANSFER_UPLOAD_ASCII_TXT);
  367.     LocalizeString(TransferTypes,MSG_TERMTRANSFER_BINARY_TXT,MSG_TERMTRANSFER_ASCII_TXT);
  368.  
  369.         /* We are uploading data. */
  370.  
  371.     Uploading = TRUE;
  372.  
  373.         /* Select the upload path. */
  374.  
  375.     switch(Type)
  376.     {
  377.         case TRANSFER_BINARY:    UploadPath = &Config . BinaryUploadPath[0];
  378.                     break;
  379.  
  380.         case TRANSFER_TEXT:    UploadPath = &Config . TextUploadPath[0];
  381.                     break;
  382.  
  383.         case TRANSFER_ASCII:    UploadPath = &Config . ASCIIUploadPath[0];
  384.                     break;
  385.     }
  386.  
  387.     BlockWindows();
  388.  
  389.         /* If not initialized, try to set up a new
  390.          * external transfer protocol.
  391.          */
  392.  
  393.     if(!XProtocolBase)
  394.     {
  395.         NewLibrary = FALSE;
  396.  
  397.         xpr_options(0,NULL);
  398.  
  399.         if(NewLibrary)
  400.         {
  401.             if(ProtocolSetup())
  402.             {
  403.                 SaveProtocolOpts();
  404.  
  405.                 strcpy(Config . Protocol,LastXprLibrary);
  406.             }
  407.         }
  408.     }
  409.  
  410.     if(XProtocolBase)
  411.     {
  412.             /* Clear the pattern match anchor structure. */
  413.  
  414.         memset(FileAnchor,0,sizeof(struct AnchorPath));
  415.  
  416.         FileMatch = FALSE;
  417.  
  418.             /* Do we need to use our own file requester or
  419.              * will xpr handle this job for us?
  420.              */
  421.  
  422.         if(TransferBits & XPRS_NOSNDREQ)
  423.         {
  424.                 /* Open the transfer info window. */
  425.  
  426.             if(TransferPanel(SendQuery[Type]))
  427.             {
  428.                 BYTE Aborted;
  429.  
  430.                 Status = STATUS_UPLOAD;
  431.  
  432.                     /* Shut up the serial line. */
  433.  
  434.                 ClearSerial();
  435.  
  436.                 LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[Type]);
  437.  
  438.                     /* Perform upload. */
  439.  
  440.                 if(!XProtocolSend(XprIO))
  441.                     Aborted = TRUE;
  442.                 else
  443.                     Aborted = FALSE;
  444.  
  445.                 if(TransferWindow)
  446.                 {
  447.                     WakeUp(TransferWindow);
  448.  
  449.                     WaitTime(2,0);
  450.                 }
  451.  
  452.                 if(Aborted)
  453.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  454.                 else
  455.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  456.  
  457.                 Status = OldStatus;
  458.  
  459.                     /* Close the info window. */
  460.  
  461.                 DeleteTransferPanel();
  462.  
  463.                     /* And request another character. */
  464.  
  465.                 if(ReadRequest)
  466.                 {
  467.                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  468.                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  469.                     ReadRequest -> IOSer . io_Length    = 1;
  470.  
  471.                     SetSignal(0,SIG_SERIAL);
  472.  
  473.                     SendIO(ReadRequest);
  474.                 }
  475.             }
  476.         }
  477.         else
  478.         {
  479.                 /* We will need the file requester to find
  480.                  * out which file(s) are to be transferred.
  481.                  * Multiple files and wildcards are
  482.                  * supported as well as plain file names.
  483.                  */
  484.  
  485.             if(FileRequest = GetFile(SendQuery[Type],UploadPath,"",DummyBuffer,"",FALSE,TRUE,FALSE,LocaleString(MSG_TERMTRANSFER_SEND_TXT)))
  486.             {
  487.                 strcpy(UploadPath,FileRequest -> rf_Dir);
  488.  
  489.                 if(FileRequest -> rf_NumArgs <= 1)
  490.                 {
  491.                     BPTR OldLock,NewLock;
  492.  
  493.                     MultipleFiles = FALSE;
  494.  
  495.                         /* Put the name of the first selected
  496.                          * file into the buffer.
  497.                          */
  498.  
  499.                     if(FileRequest -> rf_NumArgs == 1)
  500.                         strcpy(DummyBuffer,FileRequest -> rf_ArgList[0] . wa_Name);
  501.  
  502.                     XprIO -> xpr_filename = DummyBuffer;
  503.  
  504.                         /* To have a valid directory to
  505.                          * read the files from we'll jump
  506.                          * to the directory given in the file
  507.                          * requester. This is due to the fact
  508.                          * that all xpr protocols have referenced
  509.                          * files by their file names (sans path)
  510.                          * yet.
  511.                          */
  512.  
  513.                     if(NewLock = Lock(FileRequest -> rf_Dir,ACCESS_READ))
  514.                     {
  515.                         OldLock = CurrentDir(NewLock);
  516.  
  517.                         if(TransferPanel(SendQuery[Type]))
  518.                         {
  519.                             BYTE Aborted;
  520.  
  521.                             Status = STATUS_UPLOAD;
  522.  
  523.                             ClearSerial();
  524.  
  525.                             LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[Type]);
  526.  
  527.                             if(!XProtocolSend(XprIO))
  528.                                 Aborted = TRUE;
  529.                             else
  530.                                 Aborted = FALSE;
  531.  
  532.                             if(TransferWindow)
  533.                             {
  534.                                 WakeUp(TransferWindow);
  535.  
  536.                                 WaitTime(2,0);
  537.                             }
  538.  
  539.                             if(Aborted)
  540.                                 Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  541.                             else
  542.                                 Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  543.  
  544.                             Status = OldStatus;
  545.  
  546.                             DeleteTransferPanel();
  547.  
  548.                             if(ReadRequest)
  549.                             {
  550.                                 ReadRequest -> IOSer . io_Command    = CMD_READ;
  551.                                 ReadRequest -> IOSer . io_Data        = ReadBuffer;
  552.                                 ReadRequest -> IOSer . io_Length    = 1;
  553.  
  554.                                 SetSignal(0,SIG_SERIAL);
  555.  
  556.                                 SendIO(ReadRequest);
  557.                             }
  558.                         }
  559.                         else
  560.                             MyEasyRequest(Window,LocaleString(MSG_TERMTRANSFER_FAILED_TO_LOCATE_DIRECTORY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),FileRequest -> rf_Dir);
  561.  
  562.                         CurrentDir(OldLock);
  563.  
  564.                         UnLock(NewLock);
  565.                     }
  566.                 }
  567.                 else
  568.                 {
  569.                         /* This looks like a batch file request. */
  570.  
  571.                     if(FileRequest -> rf_NumArgs > 1)
  572.                     {
  573.                         BPTR OldLock,NewLock;
  574.  
  575.                             /* Set up the array of file names. */
  576.  
  577.                         FileCountMax    = FileRequest -> rf_NumArgs;
  578.                         FileArg        = FileRequest -> rf_ArgList;
  579.  
  580.                         MultipleFiles    = TRUE;
  581.  
  582.                             /* If this protocol doesn't support
  583.                              * batch file upload, make sure that
  584.                              * at least the first selected file
  585.                              * is transferred.
  586.                              */
  587.  
  588.                         XprIO -> xpr_filename = FileRequest -> rf_ArgList[0] . wa_Name;
  589.  
  590.                         if(NewLock = Lock(FileRequest -> rf_Dir,ACCESS_READ))
  591.                         {
  592.                             OldLock = CurrentDir(NewLock);
  593.  
  594.                             if(TransferPanel(SendQuery[Type]))
  595.                             {
  596.                                 BYTE Aborted;
  597.  
  598.                                 Status = STATUS_UPLOAD;
  599.  
  600.                                 ClearSerial();
  601.  
  602.                                 LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[Type]);
  603.  
  604.                                 if(!XProtocolSend(XprIO))
  605.                                     Aborted = TRUE;
  606.                                 else
  607.                                     Aborted = FALSE;
  608.  
  609.                                 if(TransferWindow)
  610.                                 {
  611.                                     WakeUp(TransferWindow);
  612.  
  613.                                     WaitTime(2,0);
  614.                                 }
  615.  
  616.                                 if(Aborted)
  617.                                     Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  618.                                 else
  619.                                     Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  620.  
  621.                                 Status = OldStatus;
  622.  
  623.                                 DeleteTransferPanel();
  624.  
  625.                                 if(ReadRequest)
  626.                                 {
  627.                                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  628.                                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  629.                                     ReadRequest -> IOSer . io_Length    = 1;
  630.  
  631.                                     SetSignal(0,SIG_SERIAL);
  632.  
  633.                                     SendIO(ReadRequest);
  634.                                 }
  635.                             }
  636.                             else
  637.                                 MyEasyRequest(Window,LocaleString(MSG_TERMTRANSFER_FAILED_TO_LOCATE_DIRECTORY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),FileRequest -> rf_Dir);
  638.  
  639.                             CurrentDir(OldLock);
  640.  
  641.                             UnLock(NewLock);
  642.                         }
  643.                     }
  644.                 }
  645.  
  646.                 FreeAslRequest(FileRequest);
  647.             }
  648.             else
  649.                 DidSend = FALSE;
  650.         }
  651.  
  652.         if(FileMatch)
  653.             MatchEnd(FileAnchor);
  654.     }
  655.  
  656.     if(SendAbort && UsesZModem)
  657.         SerWrite(ZModemCancel,20);
  658.  
  659.     SendAbort = FALSE;
  660.  
  661.     ReleaseWindows();
  662.  
  663.     Uploading = FALSE;
  664.  
  665.     if(Config . UploadMacro[0])
  666.         SerialCommand(Config . UploadMacro);
  667.  
  668.     DidTransfer = FALSE;
  669.  
  670.     return(DidSend);
  671. }
  672.  
  673.     /* ASCIISetup():
  674.      *
  675.      *    Set up xprascii.library for plain ASCII file
  676.      *    transfer. This routine temporarily selects a
  677.      *    different protocol than currently set.
  678.      */
  679.  
  680. BYTE
  681. ASCIISetup()
  682. {
  683.     UBYTE    Options[256];
  684.     STRPTR    Index;
  685.  
  686.         /* Close the currently opened xpr.library. */
  687.  
  688.     if(XProtocolBase)
  689.     {
  690.         XProtocolCleanup(XprIO);
  691.  
  692.         CloseLibrary(XProtocolBase);
  693.     }
  694.  
  695.         /* Use the same path name as the
  696.          * default protocol.
  697.          */
  698.  
  699.     strcpy(Options,Config . Protocol);
  700.  
  701.     if(Index = PathPart(Options))
  702.     {
  703.         *Index = 0;
  704.  
  705.         if(!AddPart(Options,"xprascii.library",256))
  706.             strcpy(Options,"xprascii.library");
  707.     }
  708.     else
  709.         strcpy(Options,"xprascii.library");
  710.  
  711.         /* Open xprascii.library... */
  712.  
  713.     if(!(XProtocolBase = (struct Library *)OpenLibrary(Options,0)))
  714.         XProtocolBase = (struct Library *)OpenLibrary("xprascii.library",0);
  715.  
  716.     if(XProtocolBase)
  717.     {
  718.             /* Clear the interface buffer. */
  719.  
  720.         memset(XprIO,0,sizeof(struct XPR_IO));
  721.  
  722.             /* Try to obtain the ASCII settings. */
  723.  
  724.         if(!GetEnvDOS("xprascii",Options))
  725.             Options[0] = 0;
  726.  
  727.             /* Initialize the interface buffer. */
  728.  
  729.         XprIO -> xpr_filename    = Options;
  730.         XprIO -> xpr_fopen    = (APTR)xpr_fopen;
  731.         XprIO -> xpr_fclose    = (APTR)xpr_fclose;
  732.         XprIO -> xpr_fread    = (APTR)xpr_fread;
  733.         XprIO -> xpr_fwrite    = (APTR)xpr_fwrite;
  734.         XprIO -> xpr_sread    = (APTR)xpr_sread;
  735.         XprIO -> xpr_swrite    = (APTR)xpr_swrite;
  736.         XprIO -> xpr_sflush    = (APTR)xpr_sflush;
  737.         XprIO -> xpr_update    = (APTR)xpr_update;
  738.         XprIO -> xpr_chkabort    = (APTR)xpr_chkabort;
  739.         XprIO -> xpr_gets    = (APTR)xpr_gets;
  740.         XprIO -> xpr_setserial    = (APTR)xpr_setserial;
  741.         XprIO -> xpr_ffirst    = (APTR)xpr_ffirst;
  742.         XprIO -> xpr_fnext    = (APTR)xpr_fnext;
  743.         XprIO -> xpr_finfo    = (APTR)xpr_finfo;
  744.         XprIO -> xpr_fseek    = (APTR)xpr_fseek;
  745.         XprIO -> xpr_extension    = 4;
  746.         XprIO -> xpr_options    = (APTR)xpr_options;
  747.         XprIO -> xpr_unlink    = (APTR)xpr_unlink;
  748.         XprIO -> xpr_squery    = (APTR)xpr_squery;
  749.         XprIO -> xpr_getptr    = (APTR)xpr_getptr;
  750.  
  751.             /* Initialize it. */
  752.  
  753.         TransferBits = XProtocolSetup(XprIO);
  754.  
  755.             /* Successful initialization? */
  756.  
  757.         if(!(TransferBits & XPRS_SUCCESS))
  758.         {
  759.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_SET_UP_PROTOCOL_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),"xprascii.library");
  760.  
  761.             CloseLibrary(XProtocolBase);
  762.  
  763.             XProtocolBase = NULL;
  764.  
  765.             ProtocolSetup();
  766.  
  767.             return(FALSE);
  768.         }
  769.     }
  770.     else
  771.     {
  772.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_OPEN_PROTOCOL_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),"xprascii.library");
  773.  
  774.         ProtocolSetup();
  775.  
  776.         return(FALSE);
  777.     }
  778.  
  779.     BinaryTransfer = FALSE;
  780.  
  781.     return(TRUE);
  782. }
  783.  
  784.     /* ASCIIShutdown():
  785.      *
  786.      *    Close down xprascii.library and reopen the library
  787.      *    set in the current configuration.
  788.      */
  789.  
  790. VOID
  791. ASCIIShutdown()
  792. {
  793.     XProtocolCleanup(XprIO);
  794.  
  795.     CloseLibrary(XProtocolBase);
  796.  
  797.     XProtocolBase = NULL;
  798.  
  799.     BinaryTransfer = TRUE;
  800.  
  801.     ProtocolSetup();
  802. }
  803.