home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / split.zip / JOIN.C next >
Text File  |  1994-08-03  |  4KB  |  89 lines

  1. /*******************************************************************
  2. * Join 2 pieces of a file together
  3. *
  4. * Syntax: join AppendedFile FileToAppend
  5. *
  6. *******************************************************************/
  7. #define INCL_DOS
  8. #include <os2.h>
  9.  
  10. #include <stdio.h>            // printf & sprintf
  11.  
  12. #define BUFFER_SIZE 8192      // Size of read buffer
  13.  
  14. int main (int argc, char **argv)
  15. {
  16. APIRET      rc;                 // Return code
  17. HFILE       hAppendedFile;      // File handle for merged file
  18. HFILE       hFileToAppend;      // File handle for file to append
  19. char        *AppendedFile;      // Point to Appended File string
  20. char        *FileToAppend;      // Point to File To Append string
  21. FILESTATUS3 FileStatus;         // File information for FileToAppend
  22. ULONG       ulFileSize;         // File size for FileToAppend
  23. ULONG       action;             // Action taken for a DosOpen call
  24. ULONG       ulNewPointer;       // New pointer location for DosSetFilePtr
  25. ULONG       ulPosition;         // Location in FileToAppend
  26. ULONG       ulBytesRead;        // How many bytes were read on DosRead
  27. ULONG       ulBytesWritten;     // How many bytes were written on DosWrite
  28. BYTE        buffer[BUFFER_SIZE];// Read/Write buffer
  29.  
  30.    /**********************************************************************
  31.    * Check the number of command line arguments. We are supposed to have
  32.    * 2 arguements: The file to append to and the file we are appending
  33.    **********************************************************************/
  34.    rc=0;
  35.    if (argc==3)
  36.       {
  37.       ulPosition=0;
  38.       AppendedFile=argv[1];
  39.       FileToAppend=argv[2];
  40.       rc=DosOpen(AppendedFile, &hAppendedFile, &action, 0L, 0L,
  41.               OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
  42.               OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_WRITEONLY,
  43.               0L);
  44.       if (rc==0)
  45.          {
  46.          rc=DosSetFilePtr(hAppendedFile, 0, FILE_END, &ulNewPointer);
  47.          } /* end IF */
  48.       if (rc==0)
  49.          {
  50.          rc=DosOpen(FileToAppend, &hFileToAppend, &action, ulBytesRead, 0L,
  51.                  OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
  52.                  OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
  53.                  0L);
  54.          } /* end IF */
  55.       if (rc==0)
  56.          {
  57.          rc=DosQueryFileInfo(hFileToAppend, 1, &FileStatus, sizeof(FileStatus));
  58.          ulFileSize=FileStatus.cbFile;
  59.          } /* end IF */
  60.       if (rc==0)
  61.          {
  62.          printf("Appending %s to the end of %s\n",FileToAppend, AppendedFile);
  63.          while (ulPosition<ulFileSize && rc==0)
  64.             {
  65.             rc=DosRead(hFileToAppend, buffer, BUFFER_SIZE, &ulBytesRead);
  66.             if (rc==0)
  67.                {
  68.                ulPosition+=ulBytesRead;
  69.                rc=DosWrite(hAppendedFile, buffer, ulBytesRead, &ulBytesWritten);
  70.                } /* end IF */
  71.             } /* end while */
  72.          } /* end IF */
  73.       DosClose(hFileToAppend);
  74.       DosClose(hAppendedFile);
  75.       } /* end if */
  76.    else /* */
  77.       {
  78.       printf("  Syntax is: join AppendedFile FileToAppend\n\n");
  79.       printf("  For example: 'join oem.wav oem.1' results in\n");
  80.       printf("    oem.1 being appended to the end of oem.wav.\n");
  81.       } /* end ELSE */
  82.    /*****************************************************
  83.    * If we had an error condition, print out a message
  84.    *****************************************************/
  85.    if (rc)
  86.       printf("We encountered an error code on a Dos call: %d\n", rc);
  87.    return(rc);
  88. }
  89.