home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- $CRT 11 Mar 1997 : hb
-
- $AUT Holger Burkarth
- $DAT >>SegmInfo.c<< 11 Mar 1997 11:01:24 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/ex/SegmInfo p:pLib/StartCode.o p:/pOS_RKRM/pDos/SegmInfo.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/Segment.h"
- #include "p:pDos/SegmInfo.h"
- #include "p:pDos/Hunk.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: SegmInfo 1.0 ("__DATE2__") (Copyright 1997 by proDAD) (Created by Holger Burkarth)";
-
-
- VOID PrintDatas(const struct pOS_SegmentInfo* si);
- const CHAR* GetHunkName(ULONG id);
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* RDA;
- ULONG Ops[1]={0};
-
- RDA=pOS_ReadDosArgs(
- // 0
- "FILE/A",
-
- 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) {
- struct pOS_SegmentLst *SegmLst;
- ULONG i,k;
-
- SegmLst=pOS_LoadSegmentA((dosname_t*)Ops[0],NULL);
- if(SegmLst) {
- struct pOS_SegmentInfo SI={sizeof(struct pOS_SegmentInfo)};
- const struct pOS_Segment* Seg;
- const VOID *PtrArray[8];
-
- printf("Print of Segmentlist:\n");
- for(Seg=&SegmLst->sel_Seg,i=0; Seg!=NULL; Seg=Seg->seg_Next,++i) {
- if(pOS_GetSegmentPtrInfo(SegmLst,Seg,NULL,&SI)) {
- if(i<8) PtrArray[i]=SI.segi_StartAddress;
- printf("\nSegment %ld:\n",i);
- PrintDatas(&SI);
- }
- else {printf("error\n"); break;}
- }
-
-
- printf("\nTesting:\n");
- if(i>8) i=8;
- for(k=0; k<i; ++k) {
- printf("\nTest 0x%lx + 16 ...",PtrArray[k]);
- if(pOS_GetSegmentPtrInfo(SegmLst,NULL,
- (VOID*)( (ULONG)PtrArray[k] +16 ),&SI))
- {
- printf("Ok\n");
- PrintDatas(&SI);
- }
- else printf("address not in segment\n");
-
- printf("\nTest 0x%lx + 1024 ...",PtrArray[k]);
- if(pOS_GetSegmentPtrInfo(SegmLst,NULL,
- (VOID*)( (ULONG)PtrArray[k] +1024 ),&SI))
- {
- printf("Ok\n");
- PrintDatas(&SI);
- }
- else printf("address not in segment\n");
- }
-
- pOS_UnloadSegment(SegmLst);
- }
- else pOS_PrintDosErr(NULL,(CHAR*)Ops[0],0);
- pOS_DeleteDosArgs(RDA);
- }
- }
-
-
-
- const CHAR* GetHunkName(ULONG id)
- {
- const CHAR* Str;
-
- switch(id) {
- case HUNKTYP_Code: Str="Code"; break;
- case HUNKTYP_Data: Str="Data"; break;
- case HUNKTYP_Bss: Str="Bss"; break;
- default: Str="---";
- }
- return(Str);
- }
-
-
- VOID PrintDatas(const struct pOS_SegmentInfo* si)
- {
- printf(
- "segi_SegmLst = 0x%lx\n"
- "segi_Segm = 0x%lx\n"
- "segi_StartAddress = 0x%lx\n"
- "segi_SegmSize = %ld\n"
- "segi_SegmOffset = %ld\n"
- "segi_HunkType = %ld [%s]\n"
- "segi_MemFlags = 0x%lx\n"
- ,si->segi_SegmLst,si->segi_Segm,si->segi_StartAddress,
- si->segi_SegmSize,si->segi_SegmOffset,si->segi_HunkType,
- GetHunkName(si->segi_HunkType),si->segi_MemFlags);
- }
-