home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- $CRT 03 Oct 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>Join.c<< 11 Jan 1997 13:08:10 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/c/Join p:pLib/StartCode.o p:/pOS_RKRM/pDos/Join.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:pExec/Types.h"
- #include "p:pExec/Memory.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/Files.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.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
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: Join 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* RDA;
- ULONG Ops[4]={0,0,0,0};
- UWORD Err=DOSFAIL_FAIL;
-
- RDA=pOS_ReadDosArgs(
- // 0 1 2 3
- "FROM/A/M,TO/K/A,BUF=BUFFERS/K/N,VERBOSE/S",
-
- Ops,sizeof(Ops)/sizeof(ULONG),
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- ARGTAG_VarName, (ULONG)"shell/join",
- TAG_END);
-
- if(RDA) {
- size_t BufSize;
- UBYTE *Buffer;
- struct pOS_FileHandle *IFH,*OFH;
- UBYTE AutoDel=0,Ende=0;
- UBYTE Verbose=Ops[3];
- size_t FileSize=0;
-
- if(Ops[2]) { BufSize=((ULONG*)Ops[2])[0] * 512; }
- else BufSize=8*512;
- if(BufSize<512) BufSize=512;
- else if(BufSize>256000) BufSize=256000;
-
- if(Verbose) printf("Join BufSize=%ld\n",BufSize);
-
- if(Buffer=(UBYTE*)pOS_AllocMem(BufSize,MEMF_PUBLIC)) {
- if(OFH=pOS_OpenFile(NULL,(UBYTE*)Ops[1],FILEHDMOD_Write)) {
- UBYTE **Names=(UBYTE**)Ops[0];
-
- Err=DOSFAIL_OK;
- for(; Ende==0 && AutoDel==0 && *Names; ++Names) {
- if(IFH=pOS_OpenFile(NULL,*Names,FILEHDMOD_Read)) {
- size_t Size;
- if(Verbose) printf("read file <%s> ...",*Names);
- while(Size=pOS_ReadFile(IFH,Buffer,BufSize)) {
- if(pOS_CheckBreakSignal()) {
- Ende=1; break;
- }
- if(Size!=~0) {
- if(Size!=pOS_WriteFile(OFH,Buffer,Size)) {
- AutoDel=1;
- printf("write-error <%s> DosErr=%ld\n",(UBYTE*)Ops[1],pOS_GetIoErr());
- break;
- }
- else FileSize+=Size;
- }
- else {
- AutoDel=1;
- printf("read-error <%s> DosErr=%ld\n",*Names,pOS_GetIoErr());
- break;
- }
- }
- if(AutoDel==0 && Ende==0 && Verbose) printf(" add %ld, sumsize %ld bytes\n",IFH->fh_Size,FileSize);
- pOS_CloseFile(IFH);
- }
- else {
- AutoDel=1;
- printf("Cannot open read-file <%s> DosErr=%ld\n",*Names,pOS_GetIoErr());
- break;
- }
- }
- pOS_CloseFile(OFH);
- if(AutoDel) {
- if(!Err) Err=DOSFAIL_FAIL;
- if(pOS_DeleteObjectName(NULL,(UBYTE*)Ops[1])) {
- printf("File <%s> is removed\n",(UBYTE*)Ops[1]);
- }
- }
- else {
- if(Verbose) printf("Ok, new file <%s> length=%ld bytes\n",Ops[1],FileSize);
- }
- }
- else printf("Cannot open write-file <%s> DosErr=%ld\n",Ops[1],pOS_GetIoErr());
- pOS_FreeMem(Buffer,BufSize);
- }
- else printf("Cannot allocate memory, bytes=%ld\n",BufSize);
- pOS_DeleteDosArgs(RDA);
- }
- pOS_SetShellFail(Err);
- }
-
-
-