home *** CD-ROM | disk | FTP | other *** search
- /*
- $DAT >>split.c<< 12 Oct 1996 - (C) ProDAD Holger Burkarth
- */
-
- //##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
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
-
-
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:pDOS/ArgTags.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- VOID Split(const CHAR* InFileName,const CHAR* OutFileName,size_t Size);
-
-
- const CHAR *HelpText=
- "$H(SPLIT)"
- "FILEs in SIZE-Blöck zerlegen und nach AS speichern."
- "$H(JOIN)"
- "FILEs zu einem neuen File zusammenbauen und nach AS speichern.";
-
- const CHAR *PrgHeader=
- "Split/Join für Binärdateien";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Area[3]={0,0,0};
-
- Args=pOS_ReadDosArgs(
- // 0 1 2
- "FILE/A, AS=TO/K/A, S=SIZE/N/A",
- Area,sizeof(Area)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader,
- ARGTAG_HelpText, (ULONG)HelpText,
- ARGTAG_PrgVerText, (ULONG)PrgVerText,
- ARGTAG_VarName, (ULONG)"shell/split",
- TAG_END);
-
- if(Args) {
- Split((CHAR*)Area[0],(CHAR*)Area[1],*((ULONG*)Area[2]));
- pOS_DeleteDosArgs(Args);
- }
- pOS_SetShellFail(Err);
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID Split(const CHAR* InFileName,const CHAR* OutFileName,size_t Size)
- {
- UWORD Error=0;
- CHAR FilePuffer[300];
-
-
- if(Size>0) {
- ULONG Nr=0;
- FILE *fileI;
- if(fileI=fopen(InFileName,"r")) {
- UBYTE *const Puf=(UBYTE*)pOS_AllocMem(Size,0);
- if(Puf) {
- while(Error==0) {
- size_t LeseSize=fread(Puf,1,Size,fileI);
- if((SLONG)LeseSize>0) {
- FILE *fileO;
- sprintf(FilePuffer,"%.250s-%03.3ld",OutFileName,++Nr);
- if(fileO=fopen(FilePuffer,"wb")) {
- printf("schreibe %ld Bytes in Datei <%s> ...\n",LeseSize,FilePuffer);
- if(LeseSize!=fwrite(Puf,1,LeseSize,fileO)) {
- Error=1;
- printf("... Schreibfehler in <%s>.\n",FilePuffer);
- }
- fclose(fileO);
- }
- else {
- Error=1;
- printf("... konnte Schreibdatei <%s> nicht öffnen.\n",FilePuffer);
- }
- }
- else break;
- }
- pOS_FreeMem(Puf,Size);
- }
- else {
- Error=1;
- printf("... nicht genügen Speichplatz, benötige %ld Bytes\n",Size);
- }
-
- fclose(fileI);
- }
- else {
- Error=1;
- printf("... konnte Lesedatei <%s> nicht öffnen.\n",InFileName);
- }
- }
- }
-