home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pDos / split.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  4.0 KB  |  160 lines

  1. /*
  2.   $DAT >>split.c<<   12 Oct 1996 - (C) ProDAD Holger Burkarth
  3. */
  4.  
  5. //##ex mcpp:cppc -gs -o pos:pos/c/split p:pLib/StartCode.o p:/pOS_RKRM/pDos/split.c p:pLib/StdIO.o -l pOSStub -l pOS
  6.  
  7. /***********************************************************
  8.   pOS programing example - Copyright (C) 1995-97 proDAD
  9.  
  10.   This code was written as an easy to understand example,
  11.   how to program pOS features. It is provided 'as-is',
  12.   without any express or implied warranty.
  13.  
  14.   Permission is hereby granted to use, copy and modify
  15.   this source code for any purpose, without fee, subject
  16.   to the following conditions:
  17.  
  18.     (1) This notice may not be removed or altered from any
  19.         source distribution.
  20.  
  21.     (2) Altered source versions must be plainly marked as
  22.         such, and must not be misrepresented as being
  23.         the original source code.
  24.  
  25.     (3) If only executable code is distributed, then the
  26.         accompanying documentation have to state that
  27.         "this software is based in part on examples of
  28.         the pOS developer packet".
  29.  
  30.     (4) Permission for use of this code is granted only
  31.         if the user accepts full responsibility for any
  32.         undesirable consequences. proDAD accept NO LIABILITY
  33.         for damages of any kind.
  34.  
  35.   ©proDAD
  36. ***********************************************************/
  37.  
  38.  
  39.  
  40.  
  41.  
  42. #define __COMPUTER_AMIGA 1
  43. #define NOMYDEBUG
  44.  
  45. #include "p:proto/pLibExt.h"
  46. #include "p:proto/pExec2.h"
  47. #include "p:proto/pDOS2.h"
  48. #include "p:pDOS/ArgTags.h"
  49.  
  50. #ifdef _____ME_____
  51.   #include "grund/inc_string.h"
  52.   #include "grund/inc_stdio.h"
  53. #else
  54.  #ifdef __cplusplus
  55.  extern "C" {
  56.  #endif
  57.   #include <string.h>
  58.   #include <stdio.h>
  59.  #ifdef __cplusplus
  60.  }
  61.  #endif
  62. #endif
  63.  
  64.  
  65. VOID Split(const CHAR* InFileName,const CHAR* OutFileName,size_t Size);
  66.  
  67.  
  68. const CHAR *HelpText=
  69. "$H(SPLIT)"
  70. "FILEs in SIZE-Blöck zerlegen und nach AS speichern."
  71. "$H(JOIN)"
  72. "FILEs zu einem neuen File zusammenbauen und nach AS speichern.";
  73.  
  74. const CHAR *PrgHeader=
  75. "Split/Join für Binärdateien";
  76.  
  77. const CHAR *PrgVerText=
  78. "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
  79.  
  80. /*----------------------------------
  81. -----------------------------------*/
  82. #ifdef __cplusplus
  83. extern "C"
  84. #endif
  85.  
  86. VOID main()
  87. {
  88.   struct pOS_DosArgs* Args;
  89.   UWORD Err=0;
  90.   ULONG Area[3]={0,0,0};
  91.  
  92.   Args=pOS_ReadDosArgs(
  93. // 0        1            2
  94. "FILE/A, AS=TO/K/A, S=SIZE/N/A",
  95.     Area,sizeof(Area)/sizeof(ULONG),
  96.  
  97.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,
  98.     ARGTAG_HelpText,      (ULONG)HelpText,
  99.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,
  100.     ARGTAG_VarName,       (ULONG)"shell/split",
  101.     TAG_END);
  102.  
  103.   if(Args) {
  104.     Split((CHAR*)Area[0],(CHAR*)Area[1],*((ULONG*)Area[2]));
  105.     pOS_DeleteDosArgs(Args);
  106.   }
  107.   pOS_SetShellFail(Err);
  108. }
  109.  
  110.  
  111. /*----------------------------------
  112. -----------------------------------*/
  113. VOID Split(const CHAR* InFileName,const CHAR* OutFileName,size_t Size)
  114. {
  115.   UWORD Error=0;
  116.   CHAR FilePuffer[300];
  117.  
  118.  
  119.   if(Size>0) {
  120.     ULONG Nr=0;
  121.     FILE *fileI;
  122.     if(fileI=fopen(InFileName,"r")) {
  123.       UBYTE *const Puf=(UBYTE*)pOS_AllocMem(Size,0);
  124.       if(Puf) {
  125.         while(Error==0) {
  126.           size_t LeseSize=fread(Puf,1,Size,fileI);
  127.           if((SLONG)LeseSize>0) {
  128.             FILE *fileO;
  129.             sprintf(FilePuffer,"%.250s-%03.3ld",OutFileName,++Nr);
  130.             if(fileO=fopen(FilePuffer,"wb")) {
  131.               printf("schreibe %ld Bytes in Datei <%s> ...\n",LeseSize,FilePuffer);
  132.               if(LeseSize!=fwrite(Puf,1,LeseSize,fileO)) {
  133.                 Error=1;
  134.                 printf("... Schreibfehler in <%s>.\n",FilePuffer);
  135.               }
  136.               fclose(fileO);
  137.             }
  138.             else {
  139.               Error=1;
  140.               printf("... konnte Schreibdatei <%s> nicht öffnen.\n",FilePuffer);
  141.             }
  142.           }
  143.           else break;
  144.         }
  145.         pOS_FreeMem(Puf,Size);
  146.       }
  147.       else {
  148.         Error=1;
  149.         printf("... nicht genügen Speichplatz, benötige %ld Bytes\n",Size);
  150.       }
  151.  
  152.       fclose(fileI);
  153.     }
  154.     else {
  155.       Error=1;
  156.       printf("... konnte Lesedatei <%s> nicht öffnen.\n",InFileName);
  157.     }
  158.   }
  159. }
  160.