home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 02 Jun 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>DosSynIO.c<< 19 Nov 1996 11:54:36 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/DosSynIO p:pLib/StartCode.o p:/pOS_RKRM/pDos/DosSynIO.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
- ***********************************************************/
-
- /*\
- *** Example:
- *** struct pOS_FHManage
- *** struct pOS_DosIOReq
- *** struct pOS_DosArgs
- *** struct pOS_FileHandle
- ***
- *** pOS_DoIO
- *** pOS_ReadDosArgs
- *** pOS_OpenFile
- *** pOS_AllocMem
- *** pOS_ReadFile
- *** pOS_CheckBreakSignal
- *** pOS_WriteFile
- *** pOS_PrintDosErr
- *** pOS_CloseFile
- *** pOS_DeleteDosArgs
- ***
- \*/
-
-
- #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/DosErrors.h"
- #include "p:pDOS/DosDev.h"
- #include "p:pDOS/Files.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=
- "Dos-Device - Lister";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
-
-
-
- struct ManData
- {
- pOS_FHManage FMM;
- };
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID Crypt_Read_func(_R_LB struct pOS_DosBase* dos,_R_A0 struct pOS_DosIOReq* io)
- {
- /* ManData *Data=(ManData*)io->dr_U.dr_ReadFH.drrd_FH->fh_Manage; */
- UBYTE *Adr=(UBYTE*)io->dr_U.dr_ReadFH.drrd_Adr; /* Adresse vor DoIO() merken */
-
- pOS_DoIO((struct pOS_IORequest*)io); /* Daten vom Handler lesen */
-
- if(io->dr_Error2==0) {
- dossize_t i;
- for(i=io->dr_U.dr_ReadFH.drrd_ResSize; i>0; --i,++Adr) *Adr += 0xa5;
- }
- }
-
- /*----------------------------------
- -----------------------------------*/
- VOID Crypt_Write_func(_R_LB struct pOS_DosBase* dos,_R_A0 struct pOS_DosIOReq* io)
- {
- // ManData *Data=(ManData*)io->dr_U.dr_ReadFH.drrd_FH->fh_Manage;
- UBYTE *Adr=(UBYTE*)io->dr_U.dr_WriteFH.drwd_Adr; /* ACHTUNG, Daten sind normalerweise 'const' */
-
- {
- dossize_t i;
- for(i=io->dr_U.dr_WriteFH.drwd_Size; i>0; --i,++Adr) *Adr -= 0xa5;
- }
-
- pOS_DoIO((struct pOS_IORequest*)io); /* Daten vom Handler schreiben lassen */
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[5]={0,0,1024,0,0};
-
- Args=pOS_ReadDosArgs(
- // 0 1 2 3 4
- "FROM=SOURCE/A, TO=DESTINATION/A, BUF=BUFFERS/N, ENCODE/S, DECODE",
- Ops,sizeof(Ops)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- struct pOS_FileHandle *SFH,*DFH;
- struct ManData Data;
-
- /*\
- *** Datei öffnen, CurrDir=NULL bedeutet, daß das pr_CurrentDir verwendet wird.
- \*/
- if(SFH=pOS_OpenFile(NULL,(CHAR*)Ops[0],FILEHDMOD_Read)) {
- Data.FMM=*SFH->fh_Manage; /* Standard-Daten kopieren */
-
- printf("ReadFile: Size=%ld\n",SFH->fh_Size); /* nach FILEHDMOD_Read ist fh_Size immer gesetzt */
-
- if(DFH=pOS_OpenFile(NULL,(CHAR*)Ops[1],FILEHDMOD_Write)) {
- UBYTE *Buffer;
- const size_t BufSize=*((ULONG*)Ops[2]);
-
- if(SFH->fh_Count==1 && DFH->fh_Count==1) {
- SFH->fh_Manage=&Data.FMM; DFH->fh_Manage=&Data.FMM;
-
- if(Ops[3]) {
- printf("Encode-Mode\n");
- Data.FMM.fhm_Write_func=Crypt_Write_func; /* unsere Funktion setzen */
- }
- else if(Ops[4]) {
- printf("Decode-Mode\n");
- Data.FMM.fhm_Read_func =Crypt_Read_func; /* unsere Funktion setzen */
- }
-
- if(Buffer=(UBYTE*)pOS_AllocMem(BufSize,MEMF_PUBLIC)) {
- dossize_t RSize,WSize;
-
- while(RSize=pOS_ReadFile(SFH,Buffer,BufSize)) {
- if(pOS_CheckBreakSignal()) break; /* Ctrl-C als Abbruch */
-
- printf("read %ld bytes ...",RSize);
- WSize=pOS_WriteFile(DFH,Buffer,RSize);
- printf(" write %ld bytes\n",WSize);
- if(RSize!=WSize) {
- /** SLONG Error=pOS_GetIoErr(); **/
- pOS_PrintDosErr(NULL,"RSize!=WSize",0);
- break;
- }
- }
- pOS_FreeMem(Buffer,BufSize);
- }
- else printf("Not enougth memory\n");
- }
- else {
- /*\
- *** Steht der 'fh_Count'-Wert nach pOS_FileOpen() nicht auf '1', so wird
- *** das File mehrfach verwendet und ein Verändern der shared-datas (FH)
- *** kann zum Chaos führen.
- \*/
- if(SFH->fh_Count>0) printf("Cannot install read-handler\n");
- if(DFH->fh_Count>0) printf("Cannot install write-handler\n");
- }
- pOS_CloseFile(DFH);
- }
- else printf("Cannot open <%s>\n",Ops[1]);
- pOS_CloseFile(SFH);
- }
- else printf("Cannot open <%s>\n",Ops[0]);
-
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
- }
-
-
-