
   [32m----------------------------------------------------------------------[0m
                                  [42mCombine[0m
                          [3m[33mby David M. Balean, 1994[0m
   [32m----------------------------------------------------------------------[0m


          [32m-  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -
[0m

      There is a very real problem with the AmigaDOS "JOIN" command.  What
  happens if you wish to join 100 files?  Quite frankly it is a pain in the
  unmentionable.  Not only are you unable to join that many files at one go,
  but a mistake could land you in some more unmentionable.  Here is my
  answer to that difficulty.

      "Combine" takes the name of a file containing a list of the files you
  wish to join together and sends them in same order as in that list to the
  designated destination file.  There are QUIET and DELETE options and the
  standard output can be redirected.  The name of the list file can't be the
  same as the destination but it can be placed in list file as one of the
  source files.


[33mSHELL or CLI usage[0m
[32m------------------[0m
    When used from the SHELL or CLI the format is:-

[1mCOMBINE [FROM] {list file} [AS/TO] {destination file} [Q/QUIET] [D/DELETE][0m

    Redirection in this case is managed by AmigaDOS in the normal manner
  with the following:
  ">filename" to create a new output file, deleting any pre-existing file
  ">>filename" to append to an already existing file
  "<filename" to redirect the input (unused by this program)

      The only required arguments are the listfile and the destination file
  names which are accepted in that order.  If "AS" (or "TO") is specified
  with the first filename or "FROM" with the second then this order can be
  reversed.  If a filename has the same name as a one of these keywords then
  it MUST be preceded by the appropriate "FROM" or "AS".

[33mWorkbench usage[0m
[32m---------------[0m

[3m  User Input:[0m
      When used from Workbench the user is presented with requests for the
  "FROM list filename", the "AS Destination filename", the desired options
  and redirection of output.  This is a little primitive but it seems to
  work reasonably well.  The user's input is shown with white background
  under Version 2 and above of the operating system unless something clever
  has been done.  This is to make it obvious when a space has been input by
  the user.  Filenames here should not be surrounded by quotes as the names
  are treated literally.  As with the CLI/SHELL command line the options may
  be written in full but they can to be shortened to "Q" and "D" in upper or
  lower case but separated by at least one space.  If a redirected standard
  output is requested, don't prepend it with ">" because that will be taken
  to be part of the filename!  If designated, any existing file will have
  the output appended to it so that it's original contents won't be lost,
  otherwise a new file will be created.  In general it is probably better to
  let the output go to the window as normal and simply press the return key
  unless you want a log of what happened.

      Remember that all user input is treated literally!  The input routine
  accepts characters $20 to $7e and $a1 to $ff as literals.  This is the
  normal and alternate character sets more or less complete.  The Del key
  generates character $7f and this causes the character under the cursor to
  be deleted and the rest of the line is moved left one place.  If there is
  no character under the cursor, a screen "DisplayBeep" is generated.  The
  Backspace key has "<-" on it (as does the cursor left key) and this
  generates character $0b.  This is similar to the Del key except that it
  causes the key to the left of the cursor to be deleted.  The right and
  left cursor keys operate as normal but if an attempt is made to move out
  of the existing input string a screen "DisplayBeep" is generated.  The
  left and right cursor keys can also be operated in shifted mode in which
  case the cursor is moved to the beginning or end of the string.  The
  "RETURN" or"ENTER" key generates character $0D which terminates the entry
  of that patricular input.  All the other keys are ignored and may or may
  not generate a screen "DisplayBeep".

[3m  Icons - Tool and Project:[0m
      Combine can be started under Workbench in either of two ways.  Firstly
  it can be started from it's own icon in the normal way.  If you do this
  then all path names either have to be complete or worked out from position
  in the file structure of the "Combine " program.  The other way is to use
  it's "Do_Combine" project icon.  As this occupies very little disk space,
  copies can be made for wherever it is needed.  Put the "Combine" program's
  full pathname in the default tool of the icon using "Information" in the
  Workbench menu.  If you have made "Combine" resident with the AmigaDOS
  "Resident" command, just insert "Combine" into the default tool name
  without any path.  In this case "Combine" picks up the current directory
  to use from the icon's position in the file structure.  It's actually a
  lot simpler than it sounds.  The way I use "Combine" is to place the
  program in a directory called "bin".  I prefer to keep the C directory for
  standard commands only.  In my startup sequence "bin" is placed in the
  search path using the "PATH" command so that it is only necessary to place
  "Combine" in the default tool of the project icon.

[33mThe File List[0m
[32m-------------[0m
[3m  Filenames:[0m
      The filenames in the list must be separated by white space or on
  separate lines.  If a filename contains any spaces it must be surrounded
  by double quotes which are treated as invalid characters as far as
  filenames are concerned.  Combine will accept the output file of the "DIR"
  AmigaDOS command assuming that the output is all files and no directories.
  However if any files do contain spaces in their names it will be necessary
  to surround these names with double quotes first.

[3m  Comments:[0m
      It is also possible to include comments in the list.  A comment starts
  with a semicolon.  The rest of the line is treated as a comment.  If it
  starts after a filename, make sure there is a space after the filename.

  Example of a list:

;list file - this is a comment ,,,¨¦Þµ,,;;.®;;i Anything you like!
Filename1
Filename2  Filename3       "Filename 4" ;Another comment

"Filename 5"
;END OF FILE - another comment!


[33mOptions[0m
[32m-------[0m
[3m  QUIET or Q[0m
      If the QUIET option is chosen there are no progress reports sent to
  the user's window or designated output file if output has been redirected.
  The only exception to this is if there was a Workbench start in which case
  the user is requested to press a key to quit the program at completion.
  If the operating system is Version 2 or higher there is the option of
  clicking the mouse on the CLOSEWINDOW gadget to quit at termination.

[3m  DELETE or D[0m
      It may be that the chosen destination file already exists or that the
  destination file is mentioned once or more within the source file list.
  For the AmigaDOS "JOIN" command it is illegal for a source file to be the
  same as the destination...  Combine allows this however.  The list file is
  scanned before any attempts to create the destination file.  What happens
  is that the original destination file is saved to a temporary file in the
  "T:" directory which MUST exist if this happens.  If it doesn't, the
  program will quit with an error message provided the QUIET option hasn't
  been specified.  No harm will be done.  If the "T:" directory exists, the
  normal state of affairs, and the file was successfully copied, then all
  future references to that file as a source are treated as being the saved
  file, and not the original.  This prevents the file from being overwitten
  and then being unavailable for future appending if in the list.

      What the "DELETE" option does is to automatically delete such a
  temporary if it has been created.  If there has been an error, however,
  the file is automatically retained.  As long as the "QUIET" option hasn't
  been selected the user will be kept informed as to what happened.


[33mABORT[0m
[32m-----[0m
      To abort the program simply press [Ctrl C] or [Ctrl D] in the normal
  way.  All memory allocation, unclosed files and locks get cleaned up in
  the normal way by the program's exit routine.  Also the current directory
  is returned to the original as I have found the SHELL sometimes misbehaves
  (not disastrously) if this happens.


[33mResident[0m
[32m--------[0m
      Combine can be made resident with the AmigaDOS "RESIDENT" command.  As
  it would probably only be used at infrequent intervals this is a little
  bit of overkill but I wanted to test it out.


[33mVersion[0m
[32m-------[0m
    To display the version use the AmigaDOS command
                 VERSION Combine full


[33mGeneral Information & What I Learned[0m
[32m------------------------------------[0m
      I started this program partly because I wanted to check out the SAS/C
  library function "getch()" which returns an immediate character much as
  "getchar()" does on other systems.  I had earlier discovered that it
  recognized the WINDOWCLOSE gadget but it didn't seem to do so every time.
  For a long time I couldn't work out what was going on.  The AmigaDOS
  Reference Guide makes it plain that in RAW:  mode [as per "getch()] the
  input event itself gets transmitted and in the Amiga ROM Kernal reference
  it is stated that it is terminated with '|'.  I thought at first that
  there was a fixed length to this but I was wrong.  After about a week of
  getting nowhere I realized that the real problem was that "stdout" must be
  flushed every time otherwise things went totally up the spout.

      I also managed to freeze Workbench on numerous occasions, something
  I've never done before.  I traced this to my use of the SAS/C library
  function "chdir()".  It appears that it is safe under most circumstances
  but not every time.  I can't see why.  I found that the AmigaDOS function
  "CurrentDir()" to be bulletproof so I have stuck with that.

      One other thing that has annoyed me for some time with the later
  versions of SAS/C which I didn't encounter previously is that "feof()" is
  supposed to set the EOF flag when the end of file is reached.  In fact it
  doesn't do so; the next non-existent byte has to be read first.  This
  gives no input byte of course so an error condition has to be checked in
  any case.  You can't use something like "while (!(feof(fp))".  It doesn't
  really matter except that the "feof()" function is rendered useless.  Endo
  of file shouldn't have to be treated as an error state.


      Lastly, I haven't had any problems with this version but I have to
  suggest that you use it at your own risk!  I hope it makes someone's life
  easier.  I haven't tested it on OS1.3 but it should be OK.


                    [1mCombine v1.5 © David M. Balean 1994[0m
Machine used was Amiga 2000HD with Derringer 68030 and total 7MB ram, OS2.04
               Compiled with the C language using SAS/C 6.50
                    Text editor used was Cygnus Ed v2.11
                          Program size 15744 bytes


                              [3m[1mDavid M. Balean[0m
                               44, Wyong Road
                               Killarney Vale
                                N.S.W. 2261

                               5th March 1994


          [32m-  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -  =  -
[0m

