home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / SampleLib / Lib.c
Encoding:
C/C++ Source or Header  |  1997-03-18  |  3.8 KB  |  173 lines

  1. /*******************************************************************
  2.  $CRT 16 Mar 1996 : hb
  3.  
  4.  $AUT Holger Burkarth
  5.  $DAT >>Lib.c<<   04 Nov 1996    07:59:17 - (C) ProDAD
  6. *******************************************************************/
  7.  
  8. //##private
  9.  
  10. // mcpp:cppc -gs -o pos:pos/libs/my.library p:pLib/LibCode.o p:pCom/_Example/Lib/Lib.c p:pLib/pLinkLib.o
  11.  
  12. /***********************************************************
  13.   pOS programing example - Copyright (C) 1995-97 proDAD
  14.  
  15.   This code was written as an easy to understand example,
  16.   how to program pOS features. It is provided 'as-is',
  17.   without any express or implied warranty.
  18.  
  19.   Permission is hereby granted to use, copy and modify
  20.   this source code for any purpose, without fee, subject
  21.   to the following conditions:
  22.  
  23.     (1) This notice may not be removed or altered from any
  24.         source distribution.
  25.  
  26.     (2) Altered source versions must be plainly marked as
  27.         such, and must not be misrepresented as being
  28.         the original source code.
  29.  
  30.     (3) If only executable code is distributed, then the
  31.         accompanying documentation have to state that
  32.         "this software is based in part on examples of
  33.         the pOS developer packet".
  34.  
  35.     (4) Permission for use of this code is granted only
  36.         if the user accepts full responsibility for any
  37.         undesirable consequences. proDAD accept NO LIABILITY
  38.         for damages of any kind.
  39.  
  40.   ©proDAD
  41. ***********************************************************/
  42.  
  43. #define __COMPUTER_AMIGA 1
  44. #define NOMYDEBUG
  45.  
  46. #include "p:proto/pLibExt.h"
  47. #include "p:proto/pExec2.h"
  48.  
  49. #include "p:pExec/Library.h"
  50. #include "p:pExec/Resident.h"
  51. #include "p:pUtil/TagItem.h"
  52. #include "p:pDOS/Segment.h"
  53. #include "p:pExec/Diagnos.h"
  54. #include "p:pExec/TstTags.h"
  55.  
  56. #ifdef _____ME_____
  57.   #include "grund/inc_string.h"
  58.   #include "grund/inc_limits.h"
  59. #else
  60.  extern "C" {
  61.   #include <string.h>
  62.   #include <limits.h>
  63.  }
  64. #endif
  65.  
  66.  
  67. struct MY_Lib
  68. {
  69.   pOS_Library my_Lib;
  70.  
  71. };
  72.  
  73.  
  74. extern ULONG *FuncTable[];
  75. extern BOOL pLibMain(_R_LB pOS_ExecBase*,_R_A0 MY_Lib*);
  76.  
  77. const CHAR LibraryName[]  ="my.library";
  78. const CHAR LibraryIDName[]="my.library 1.0 ("__DATE2__")";
  79.  
  80. const pOS_TagItem LibraryDescribe[]=
  81. {
  82.   EXTSTTAG_MainOSID, pOS_MAINOSID,
  83.   TAG_END
  84. };
  85.  
  86.  
  87.  
  88.  
  89. pOS_ResidentLibInit InitTable=
  90. {
  91.   sizeof(MY_Lib),
  92.   FuncTable,
  93.   NULL,
  94.   (BOOL(*)(_R_LB pOS_ExecBase*,_R_A0 pOS_Library*))pLibMain
  95. };
  96.  
  97.  
  98. /*----------------------------------
  99. -----------------------------------*/
  100. static BOOL Open_func(MY_Lib* lib)
  101. {
  102. //PRINT("MY_Lib: Open()\n");
  103.   return(1);
  104. }
  105.  
  106. static VOID Close_func(MY_Lib* lib)
  107. {
  108. //PRINT("MY_Lib: Close()\n");
  109. }
  110.  
  111.  
  112. /*----------------------------------
  113. -----------------------------------*/
  114. static pOS_SegmentLst* Expunge_func(MY_Lib* lib)
  115. {
  116.   lib->my_Lib.lib_Flags |= LIBF_DELEXP;
  117.   if(lib->my_Lib.lib_OpenCnt==0) {
  118.     pOS_SegmentLst* Seg=lib->my_Lib.lib_Segm;
  119.  
  120.     pOS_ListRemove(&lib->my_Lib.lib_Node);
  121.     _pOS_FreeLibraryMem2(&lib->my_Lib);
  122. //PRINT("MY_Lib: Expunge+Remove()\n");
  123.     return(Seg);
  124.   }
  125.   return(0);
  126. }
  127.  
  128.  
  129. /*----------------------------------
  130. -----------------------------------*/
  131. static ULONG Reserved_func(MY_Lib* lib)
  132. {
  133. //PRINT("MY_Lib: Reserved()\n");
  134.   return(0);
  135. }
  136.  
  137.  
  138.  
  139. ULONG *FuncTable[]=
  140. {
  141.  (ULONG*)Open_func,
  142.  (ULONG*)Close_func,
  143.  (ULONG*)Expunge_func,
  144. // ------------
  145.  (ULONG*)Reserved_func,
  146.  (ULONG*)Reserved_func,
  147.  (ULONG*)Reserved_func,
  148.  (ULONG*)Reserved_func,
  149.  (ULONG*)Reserved_func,
  150.  (ULONG*)Reserved_func,
  151.  (ULONG*)Reserved_func,
  152.  (ULONG*)Reserved_func,
  153. // ------------
  154.  
  155.  (ULONG*)ULONG_MAX
  156.  
  157. };
  158.  
  159.  
  160.  
  161.  
  162. /*----------------------------------
  163. -----------------------------------*/
  164. BOOL pLibMain(_R_LB pOS_ExecBase* exec,_R_A0 MY_Lib* lib)
  165. {
  166.   gb_ExecBase=(struct pOS_ExecBase*)exec;
  167.   gb_ExecLib=*((struct pOS_ExecLibFunction**)lib->my_Lib.lib_Segm->sel_Seg.seg_Reserved2);
  168. // PRINT("MY_lib: pLibMain( )  exec=%lx lib=%lx seg=%lx %lx\n",gb_ExecBase,lib,lib->my_Lib.lib_Segm,gb_ExecLib);
  169.   return(TRUE);
  170. }
  171.  
  172.  
  173.