home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 29 Dec 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>SeekTest.c<< 12 Jan 1997 18:44:03 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/ex/SeekTest p:pLib/StartCode.o p:/pOS_RKRM/pDos/SeekTest.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:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:pDOS/Process.h"
- #include "p:pDos/Files.h"
- #include "p:pDOS/DosDev.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=
- "Control Dos-Buffers";
-
- 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;
- ULONG Ops[3]={0,0,(ULONG)"tofile"};
-
- Args=pOS_ReadDosArgs(
- // 0 1 2
- "NAME/A,MODE/N,TO",
- 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) {
- pOS_FileHandle *FH,*FH2;
- UBYTE Buf[32];
- ULONG Mode=Ops[1] ? *((ULONG*)Ops[1]) : 0;
- const dosname_t *Name=(dosname_t*)Ops[0];
- const dosname_t *ToFile=(dosname_t*)Ops[2];
-
- if(Mode==1) {
- if(FH=pOS_OpenFile(NULL,Name,FILEHDMOD_Write)) {
- pOS_WriteFile(FH,"1234567890",10);
- pOS_CloseFile(FH);
- }
- else pOS_PrintDosErr(NULL,Name,0);
- }
- else if(Mode==2) {
- if(FH=pOS_OpenFile(NULL,Name,FILEHDMOD_Read)) {
- ULONG Pos;
- Pos=0;
- pOS_SeekFile(FH,Pos,FILEHDSEK_Begin);
- pOS_ReadFile(FH,Buf,2); Buf[2]=0;
- printf("%ld |%s|\n",Pos,Buf);
-
- Pos=2;
- pOS_SeekFile(FH,Pos,FILEHDSEK_Begin);
- pOS_ReadFile(FH,Buf,2); Buf[2]=0;
- printf("%ld |%s|\n",Pos,Buf);
- pOS_CloseFile(FH);
- }
- else pOS_PrintDosErr(NULL,Name,0);
- }
- else if(Mode==3) {
- if(FH=pOS_OpenFile(NULL,Name,FILEHDMOD_ReadWrite)) {
- ULONG Pos;
- Pos=10;
- pOS_SeekFile(FH,Pos,FILEHDSEK_Begin);
- pOS_WriteFile(FH,"x",1);
-
-
- pOS_SeekFile(FH,0,FILEHDSEK_Begin);
- pOS_ReadFile(FH,Buf,11); Buf[11]=0;
- printf("|%s|\n",Buf);
- pOS_CloseFile(FH);
- }
- else pOS_PrintDosErr(NULL,Name,0);
- }
- else if(Mode==4) {
- if(FH=pOS_OpenFile(NULL,Name,FILEHDMOD_Read)) {
- if(FH2=pOS_OpenFile(NULL,ToFile,FILEHDMOD_Write)) {
- dossize_t Pos,FileSize=FH->fh_Size;
- dospos_t Res;
-
- for(Pos=FileSize; Pos>0; --Pos) {
-
- if(pOS_CheckBreakSignal()) break;
-
- Res=pOS_SeekFile(FH,Pos-1,FILEHDSEK_Begin);
- if(Res==pOS_DOSERR) {
- printf("Position = %ld\n",Pos-1);
- pOS_PrintDosErr(NULL,ToFile,0);
- break;
- }
- else {
- Res=pOS_ReadFile(FH,Buf,1);
- if(Res==pOS_DOSERR) {
- printf("Position = %ld\n",Pos-1);
- pOS_PrintDosErr(NULL,ToFile,0);
- break;
- }
- else if(Res==0) {
- printf("Read-error, Position = %ld\n",Pos-1);
- break;
- }
- else {
- Res=pOS_WriteFile(FH2,Buf,1);
-
- if(Res==pOS_DOSERR) {
- printf("Position = %ld\n",Pos-1);
- pOS_PrintDosErr(NULL,ToFile,0);
- break;
- }
- else if(Res==0) {
- printf("Write-error, Position = %ld\n",Pos-1);
- break;
- }
- }
- }
- }
- pOS_CloseFile(FH2);
- }
- else pOS_PrintDosErr(NULL,ToFile,0);
- pOS_CloseFile(FH);
- }
- else pOS_PrintDosErr(NULL,Name,0);
- }
-
- else if(Mode==5) {
- if(FH=pOS_OpenFile(NULL,Name,FILEHDMOD_Read)) {
- if(FH2=pOS_OpenFile(NULL,ToFile,FILEHDMOD_Read)) {
- dossize_t Pos,FileSize=FH->fh_Size;
- dospos_t Res1,Res2;
-
- for(Pos=0; Pos<FileSize; Pos+=15) {
- UWORD i;
-
- if(pOS_CheckBreakSignal()) break;
-
- Res1=pOS_ReadFile(FH,Buf,15);
- if(Res1==pOS_DOSERR) {
- printf("Position = %ld\n",Pos);
- pOS_PrintDosErr(NULL,Name,0);
- break;
- }
- Res2=pOS_ReadFile(FH2,&Buf[16],15);
- if(Res2==pOS_DOSERR) {
- printf("Position = %ld\n",Pos);
- pOS_PrintDosErr(NULL,ToFile,0);
- break;
- }
-
- if(Res1!=Res2) {
- printf("Res1=%ld, Res2=%ld\n",Res1,Res2);
- break;
- }
-
- for(i=0; i<Res1; ++i) {
- if(Buf[i] != Buf[16+i]) {
- printf("Diffenenze: Pos=%ld\n",Pos+i);
- printf("Buf1 %15.lh\n",&Buf[0]);
- printf("Buf2 %15.lh\n",&Buf[16]);
- }
- }
-
- }
- pOS_CloseFile(FH2);
- }
- else pOS_PrintDosErr(NULL,ToFile,0);
- pOS_CloseFile(FH);
- }
- else pOS_PrintDosErr(NULL,Name,0);
- }
-
- else printf("Unknown mode\n");
-
- pOS_DeleteDosArgs(Args);
- }
- }
-
-
-