' Copyright (c) 1989, Julie M. Covington
'                     STARWEST-bbs co-sysop
'                     (509)758-6248 (300-1200-2400-bps 8-N-1 First-time access)
'                     (509)758-6245 (Voice)
'                     525 15th Street
'                     Clarkston, Washington, 99403.

'    I the author, place this source-code program and comments in the
' public-domain, to be freely used, copied, modified, compiled, or distributed
' via electronic computer bulletin-boards or computer user groups for no extra
' charge with the exception of a nominal media/duplication fee. It cannot be
' sold outright, or combined with other items in a package for sale without the
' expressed permission of above specified author. Monetary donations to the
' above address will go towards work on future upgrades, support and new items.

'    I the author, take no responsibility for the effects or side-effects of
' using, copying, modifying, compiling, or distributing this source-code
' program and comments.

'    In short, use it, pass it around, customize it, have fun. Good luck.

'    BIPATCH.EXE is a program which allows Bimodem, the simultaneous upload/
' download/chat file-transfer protocol, to interface into the RBBS-PC bulletin-
' board-system environment. RBBS-PC and other bulletin-board-systems adhere
' to the modern standard of signaling the external file-transfer protocol
' driver that a batch transfer is to take place by prefixing an @ symbol onto
' the beginning of the filename to transfer. Example: @C:\RBBS\NODE1WRK. This
' would indicate to the protocol driver that  file NODE1WRK, located in the
' \RBBS subdirectory on drive C:, is not a file to send but a file containing
' a list of files to send.
'    Bimodem, set up as its authors intend, does not recoginize this switch.
' It usually requires a whole door environment to work, and then circumvents
' RBBS-PC's extensive security system for time-remaining, security-level, and
' other built in checking. This is due to non-standard batch-mode operation.
' Bimodem does accept filenames to be strung-out on its command-line luckily.
' This program, BIPATCH.BAS, and its compiled form BIPATCH.EXE, convert
' the file sent by RBBS-PC containing a list of files to be sent in batch mode
' into a Bimodem command-line listing of files to be sent.
'    BIPATCH.EXE will allow Bimodem to behave in the RBBS-PC environment just
' exactly as Zmodem or other modern protocol drivers. Stack-up a bunch of files
' to download in RBBS-PC and away it goes. The available length of the command
' line is the only limitation.
'    This program was written in Turbo-basic 1.1. Co-processor switch off, DOS
' break switch off for compiling. Modifications needed to run on a multi-node
' RBBS-PC system. The source-code for compilation follows:





    cline$=command$                            ' BIUP.BAT the bimodem send
                                               ' batch-file specified in rbbs
                                               ' PROTO.DEF executes this
                                               ' basic program whose source
                                               ' code you are now reading.
                                               ' Cline$ takes on dos command-
                                               ' line passed to BIUP.BAT from
                                               ' rbbs PROTO.DEF.

    bflag%=instr(cline$,"@")                   ' Bflag% takes on position of @
                                               ' symbol within cline$. Rbbs
	                                       ' appends @ as first character
                                               ' of filename for protocol to
                                               ' to send if batch-mode. Bflag%
                                               ' returns 0 if @ not found.

    if bflag%<1 then outfl$=cline$:goto 100    ' If bflag%=0 then non-batch
                                               ' mode indicated and cline$ is
                                               ' passed unchanged to the new
                                               ' bimodem command line this
                                               ' program will create.

    lstfl$=right$(cline$,len(cline$)-bflag%)   ' Lstfl$ takes on the filename
                                               ' rbbs sent to the protocol.
                                               ' Usually C:\RBBS\NODE1WRK which
                                               ' isn't a file to send but
                                               ' contains a list of files to
                                               ' send as a batch transfer.

    tem$=left$(cline$,bflag%-1)                ' Tem$ takes the portion of
                                               ' cline$ up to the @ symbol in
                                               ' the filename @C:\RBBS\NODE1WRK

    temfl$=""                                  ' Clear temfl$ which will hold
                                               ' the filnames to transfer on
                                               ' bimodem's command-line.

    open lstfl$ for input as #1                ' Open the file rbbs sent as
                                               ' the file containing the list
                                               ' of files to batch transfer.
                                               ' Usually C:\RBBS\NODE1WRK.

    do until eof(1)                            ' Begin a loop to pull filename
                                               ' records from NODE1WRK and
                                               ' line them up separated by
                                               ' spaces on a dos command line.

    line input#1,dtemp$                        ' Dtemp$ takes on filename
                                               ' from a record in NODE1WRK.

    temfl$=temfl$+dtemp$+" "                   ' Temfl$ adds the contents of
                                               ' of dtemp$ which is another
                                               ' filename plus a space to its
                                               ' current contents.

    loop                                       ' Keep pulling filename records
                                               ' from NODE1WRK and adding them
                                               ' up on one long line separated
                                               ' by spaces.

    close #1                                   ' Close the filename contained
                                               ' in lstfl$ usually NODE1WRK
                                               ' which was passed by rbbs
                                               ' in the PROTO.DEF command-line.

    outfl$=tem$+temfl$                         ' Outfl$ takes on tem$ which
                                               ' contains most of the original
                                               ' protocol command-line plus
                                               ' temfl$ which contains all the
                                               ' filenames separated by a space
                                               ' to transfer in the batch.

100 open "bifix.bat" for output as #1          ' Open BIFIX.BAT which is going
                                               ' to be the new batch-file that
                                               ' will invoke BIMODEM.COM with
                                               ' all the files in the batch
                                               ' transfer on its command-line.

    print #1,outfl$                            ' Write out one single line in
                                               ' the new batch-file BIFIX.BAT
                                               ' which will execute BIMODEM.COM
                                               ' with all needed switches and
                                               ' parameters from the original
                                               ' command-line passed from rbbs
                                               ' PROTO.DEF plus the newly
                                               ' broken-down filenames from
                                               ' NODE1WRK.

    close #1                                   ' Close BIFIX.BAT the newly
                                               ' created batch-file in
                                               ' preparation to exit.

    end                                        ' Exit this program and return
                                               ' execution control back to
                                               ' the bimodem send batchfile
                                               ' BIUP.BAT which originally
                                               ' called this program.