home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pDos / SegmInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  4.8 KB  |  187 lines

  1. /*******************************************************************
  2.  $CRT 11 Mar 1997 : hb
  3.  
  4.  $AUT Holger Burkarth
  5.  $DAT >>SegmInfo.c<<   11 Mar 1997    11:01:24 - (C) ProDAD
  6. *******************************************************************/
  7.  
  8. //##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
  9.  
  10. /***********************************************************
  11.   pOS programing example - Copyright (C) 1995-97 proDAD
  12.  
  13.   This code was written as an easy to understand example,
  14.   how to program pOS features. It is provided 'as-is',
  15.   without any express or implied warranty.
  16.  
  17.   Permission is hereby granted to use, copy and modify
  18.   this source code for any purpose, without fee, subject
  19.   to the following conditions:
  20.  
  21.     (1) This notice may not be removed or altered from any
  22.         source distribution.
  23.  
  24.     (2) Altered source versions must be plainly marked as
  25.         such, and must not be misrepresented as being
  26.         the original source code.
  27.  
  28.     (3) If only executable code is distributed, then the
  29.         accompanying documentation have to state that
  30.         "this software is based in part on examples of
  31.         the pOS developer packet".
  32.  
  33.     (4) Permission for use of this code is granted only
  34.         if the user accepts full responsibility for any
  35.         undesirable consequences. proDAD accept NO LIABILITY
  36.         for damages of any kind.
  37.  
  38.   ©proDAD
  39. ***********************************************************/
  40.  
  41. #define __COMPUTER_AMIGA 1
  42. #define NOMYDEBUG
  43.  
  44. #include "p:pExec/Types.h"
  45. #include "p:pExec/Memory.h"
  46. #include "p:pDOS/ArgTags.h"
  47. #include "p:pDOS/DosSig.h"
  48. #include "p:pDos/Segment.h"
  49. #include "p:pDos/SegmInfo.h"
  50. #include "p:pDos/Hunk.h"
  51. #include "p:pDOS/DosErrors.h"
  52. #include "p:proto/pLibExt.h"
  53. #include "p:proto/pExec2.h"
  54. #include "p:proto/pDOS2.h"
  55.  
  56. #ifdef _____ME_____
  57.   #include "grund/inc_string.h"
  58.   #include "grund/inc_stdio.h"
  59. #else
  60.  #ifdef __cplusplus
  61.  extern "C" {
  62.  #endif
  63.   #include <string.h>
  64.   #include <stdio.h>
  65.  #ifdef __cplusplus
  66.  }
  67.  #endif
  68. #endif
  69.  
  70.  
  71. const CHAR *HelpText=
  72. ""
  73. ;
  74.  
  75. const CHAR *PrgHeader=
  76. "";
  77.  
  78. const CHAR *PrgVerText=
  79. "$VER: SegmInfo 1.0 ("__DATE2__") (Copyright 1997 by proDAD) (Created by Holger Burkarth)";
  80.  
  81.  
  82. VOID PrintDatas(const struct pOS_SegmentInfo* si);
  83. const CHAR* GetHunkName(ULONG id);
  84.  
  85. /*----------------------------------
  86. -----------------------------------*/
  87. #ifdef __cplusplus
  88. extern "C"
  89. #endif
  90.  
  91. VOID main()
  92. {
  93.   struct pOS_DosArgs* RDA;
  94.   ULONG  Ops[1]={0};
  95.  
  96.   RDA=pOS_ReadDosArgs(
  97. //  0
  98. "FILE/A",
  99.  
  100.     Ops,sizeof(Ops)/sizeof(ULONG),
  101.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  102.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  103.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  104.     ARGTAG_VarName,       (ULONG)"shell/join",
  105.     TAG_END);
  106.  
  107.   if(RDA) {
  108.     struct pOS_SegmentLst *SegmLst;
  109.     ULONG i,k;
  110.  
  111.     SegmLst=pOS_LoadSegmentA((dosname_t*)Ops[0],NULL);
  112.     if(SegmLst) {
  113.       struct pOS_SegmentInfo SI={sizeof(struct pOS_SegmentInfo)};
  114.       const struct pOS_Segment* Seg;
  115.       const VOID *PtrArray[8];
  116.  
  117.       printf("Print of Segmentlist:\n");
  118.       for(Seg=&SegmLst->sel_Seg,i=0; Seg!=NULL; Seg=Seg->seg_Next,++i) {
  119.         if(pOS_GetSegmentPtrInfo(SegmLst,Seg,NULL,&SI)) {
  120.           if(i<8) PtrArray[i]=SI.segi_StartAddress;
  121.           printf("\nSegment %ld:\n",i);
  122.           PrintDatas(&SI);
  123.         }
  124.         else {printf("error\n"); break;}
  125.       }
  126.  
  127.  
  128.       printf("\nTesting:\n");
  129.       if(i>8) i=8;
  130.       for(k=0; k<i; ++k) {
  131.         printf("\nTest 0x%lx + 16 ...",PtrArray[k]);
  132.         if(pOS_GetSegmentPtrInfo(SegmLst,NULL,
  133.                    (VOID*)( (ULONG)PtrArray[k] +16 ),&SI))
  134.         {
  135.           printf("Ok\n");
  136.           PrintDatas(&SI);
  137.         }
  138.         else printf("address not in segment\n");
  139.  
  140.         printf("\nTest 0x%lx + 1024 ...",PtrArray[k]);
  141.         if(pOS_GetSegmentPtrInfo(SegmLst,NULL,
  142.                    (VOID*)( (ULONG)PtrArray[k] +1024 ),&SI))
  143.         {
  144.           printf("Ok\n");
  145.           PrintDatas(&SI);
  146.         }
  147.         else printf("address not in segment\n");
  148.       }
  149.  
  150.       pOS_UnloadSegment(SegmLst);
  151.     }
  152.     else pOS_PrintDosErr(NULL,(CHAR*)Ops[0],0);
  153.     pOS_DeleteDosArgs(RDA);
  154.   }
  155. }
  156.  
  157.  
  158.  
  159. const CHAR* GetHunkName(ULONG id)
  160. {
  161.   const CHAR* Str;
  162.  
  163.   switch(id) {
  164.     case HUNKTYP_Code: Str="Code"; break;
  165.     case HUNKTYP_Data: Str="Data"; break;
  166.     case HUNKTYP_Bss:  Str="Bss";  break;
  167.     default:           Str="---";
  168.   }
  169.   return(Str);
  170. }
  171.  
  172.  
  173. VOID PrintDatas(const struct pOS_SegmentInfo* si)
  174. {
  175.   printf(
  176. "segi_SegmLst      = 0x%lx\n"
  177. "segi_Segm         = 0x%lx\n"
  178. "segi_StartAddress = 0x%lx\n"
  179. "segi_SegmSize     = %ld\n"
  180. "segi_SegmOffset   = %ld\n"
  181. "segi_HunkType     = %ld  [%s]\n"
  182. "segi_MemFlags     = 0x%lx\n"
  183.  ,si->segi_SegmLst,si->segi_Segm,si->segi_StartAddress,
  184.   si->segi_SegmSize,si->segi_SegmOffset,si->segi_HunkType,
  185.   GetHunkName(si->segi_HunkType),si->segi_MemFlags);
  186. }
  187.