home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 632.lha / ParM_v3.6 / ParM_Src.lzh / ParM_Src / LibSup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-19  |  5.5 KB  |  221 lines

  1. /*
  2.  *    LibSup.c - Copyright © 1990 by S.R. & P.C.
  3.  *
  4.  *    Created:    22 Sep 1990  20:52:16
  5.  *    Modified:    18 Feb 1992  19:42:22
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. #include "ParMBase.h"
  11.  
  12. #define PARMREVISION    7    /* would be nice to auto-increment this */
  13.  
  14. char ParMLibName[] = "parm.library";
  15. char ParMLibId[] = "V4.7 (18 Feb 1992)\r\n";
  16.  
  17. void InstallHandler(void);
  18. void RemoveHandler(void);
  19. BOOL LoadMouseOpt(char *MouseOptFileName, struct MouseOpt *MouseOpt);
  20.  
  21. void ParMLibInit(void);
  22. long ParMLibOpen(void);
  23. long ParMLibClose(void);
  24. long ParMLibExpunge(void);
  25.  
  26. #pragma amicall(ParMBase, 0x06, ParMLibOpen())
  27. #pragma amicall(ParMBase, 0x0c, ParMLibClose())
  28. #pragma amicall(ParMBase, 0x12, ParMLibExpunge())
  29.  
  30. long DosWrite(BPTR file, char *buffer, long length);
  31. #pragma amicall(DOSBase, 0x30, DosWrite(d1,d2,d3))
  32.  
  33.  
  34. extern struct ExecBase *SysBase;
  35. extern struct Library *DOSBase;
  36. extern struct Resident ParMLibRomTag;
  37.  
  38. struct ParMBase *ParMBase;    /* Have a global ParMBase for internal functions */
  39. struct ArpBase *ArpBase;
  40. struct ReqLib *ReqBase;
  41. struct IconBase *IconBase;
  42. struct GfxBase *GfxBase;
  43. struct LayersBase *LayersBase;
  44. struct IntuitionBase *IntuitionBase;
  45. /* default mouse opts values */
  46. struct MouseOpt MouseOpt = {MOUSEOPT_VERSION, 51, 0, 0, 2, 0, -1, 0, 0, IEQUALIFIER_LEFTBUTTON|IEQUALIFIER_RELATIVEMOUSE};
  47.  
  48.  
  49. /* library initialization table, used for AUTOINIT libraries */
  50.  
  51. struct InitTable {
  52.     ULONG it_DataSize;            /* library data space size            */
  53.     void **it_FuncTable;        /* table of entry points            */
  54.     void *it_DataInit;            /* table of data initializers        */
  55.     void (*it_InitFunc)(void);    /* initialization function to run    */
  56. };
  57.  
  58.  
  59. void *libfunctab[] = {    /* my function table */
  60.     ParMLibOpen,        /* standard open    */
  61.     ParMLibClose,        /* standard close    */
  62.     ParMLibExpunge,        /* standard expunge    */
  63.     0,
  64.  
  65. /* real lib functions */
  66.  
  67.     ParseMenus,
  68.     FreeMenus,
  69.     ARun,
  70.     Run,
  71.     WBRun,
  72.     GetTool,
  73.     MakeWBArg,
  74.     MakeWBStartup,
  75.     WBFree,
  76.     Command,
  77.     ParseLine,
  78.     DosError,
  79.     StrIoErr,
  80.     MakeMenuShortCut,
  81.     InitDefaults,
  82.     FreeRepliedWBMessages,
  83.     NewMinList,
  84.     CopyStr,
  85.     FreeStr,
  86.     IsHidden,
  87.     GetWindow,
  88.     CreateExtIO,
  89.     CleanUp,
  90.     NewCleanUp,
  91.     UpdateParMEventsWindow,
  92.     UpdateMouseOpt,
  93.     GetCurrentMouseOpt,
  94.     (void *) -1L        /* end of function vector table */
  95. };
  96.  
  97.  
  98. struct InitTable ParMLibInitTab = {
  99.     sizeof(struct ParMBase),
  100.     libfunctab,
  101.     0,            /* will initialize my data in funkymain()    */
  102.     ParMLibInit
  103. };
  104.  
  105.  
  106. /* Init the global ParMBase */
  107.  
  108. void StoreParMBase(struct ParMBase *pb)
  109. {
  110.     ParMBase = pb;
  111. }
  112.  
  113.  
  114. void _main(struct ParMBase * ParMBase, unsigned long seglist)
  115. {
  116.     ParMBase->pb_SegList = seglist;
  117.  
  118.     /* -----  init. library structure  ----- */
  119.     ParMBase->pb_Lib.lib_Node.ln_Type = NT_LIBRARY;
  120.     ParMBase->pb_Lib.lib_Node.ln_Name = (char *) ParMLibName;
  121.     ParMBase->pb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  122.     ParMBase->pb_Lib.lib_Version = ParMLibRomTag.rt_Version;
  123.     ParMBase->pb_Lib.lib_Revision = PARMREVISION;
  124.     ParMBase->pb_Lib.lib_IdString = (APTR) ParMLibId;
  125.     ParMBase->pb_MsgPort.mp_Flags = PA_IGNORE;
  126.     NewMinList((struct MinList *) & ParMBase->pb_MsgPort.mp_MsgList);
  127.     StoreParMBase(ParMBase);
  128.     LoadMouseOpt(DEFAULT_MOUSEOPT_FILE, &MouseOpt);
  129. }
  130.  
  131.  
  132. long ParMLibOpen(void)
  133. {
  134.     struct ParMBase *ParMBase;
  135.     struct Process *pp;
  136.  
  137.     pp = (struct Process *) SysBase->ThisTask;
  138.     if (!ReqBase && !(ReqBase = (struct ReqLib *) OpenLibrary("req.library", 1))) {
  139.         if (pp->pr_COS)
  140.             DosWrite(pp->pr_COS, "You need req.library\n", 21L);
  141.         return NULL;
  142.     }
  143.     if (!IconBase && !(IconBase = (struct IconBase *) OpenLibrary("icon.library", 0L))) {
  144.         SimpleRequest("parm.library", "You need icon.library!");
  145.         return NULL;
  146.     }
  147.     if (!LayersBase && !(LayersBase = (struct LayersBase *) OpenLibrary("layers.library", 0L)))
  148.         return NULL;
  149.     /* Each user must open arp.library for individual tracked resources */
  150.     if (!(ArpBase = (struct ArpBase *) OpenLibrary("arp.library", 39))) {
  151.         SimpleRequest("parm.library", "You need arp.library V39+\n");
  152.         return NULL;
  153.     }
  154.     ParMBase->ArpBase = ArpBase;
  155.     ParMBase->ReqBase = ReqBase;
  156.     ParMBase->IconBase = IconBase;
  157.     ParMBase->LayersBase = LayersBase;
  158.     IntuitionBase = (struct IntuitionBase *)ArpBase->IntuiBase;
  159.     GfxBase = (struct GfxBase *)ArpBase->GfxBase;
  160.     /* Handler is removed each time OpenCnt becomes zero */
  161.     /* mark us as having another customer */
  162.     if (ParMBase->pb_Lib.lib_OpenCnt++ == 0)
  163.         InstallHandler();
  164.     /* prevent delayed expunges (standard procedure) */
  165.     ParMBase->pb_Lib.lib_Flags &= ~LIBF_DELEXP;
  166.     return (long)ParMBase;
  167. }
  168.  
  169.  
  170. long ParMLibClose(void)
  171. {
  172.     struct ParMBase *ParMBase;
  173.  
  174.     CloseLibrary(ArpBase);
  175.     if (--ParMBase->pb_Lib.lib_OpenCnt == 0) {
  176.         RemoveHandler();
  177.         if (ParMBase->pb_Lib.lib_Flags & LIBF_DELEXP) {
  178.             /* no more people have me open, and I have a delayed expunge pending */
  179.             return ParMLibExpunge();     /* return segment list    */
  180.         }
  181.     }
  182.     return NULL;
  183. }
  184.  
  185.  
  186. long ParMLibExpunge(void)
  187. {
  188.     struct ParMBase *ParMBase;
  189.     ULONG seglist = 0;
  190.     long libsize;
  191.     extern struct Library *DOSBase;
  192.  
  193.     if (ParMBase->pb_Lib.lib_OpenCnt == 0 && ParMBase->pb_MsgCnt == 0) {
  194.         if (ReqBase)
  195.             CloseLibrary(ReqBase);
  196.         if (IconBase)
  197.             CloseLibrary(IconBase);
  198.         if (LayersBase)
  199.             CloseLibrary(LayersBase);
  200.         /* really expunge: remove libbase and freemem */
  201.         seglist = ParMBase->pb_SegList;
  202.         Remove(&ParMBase->pb_Lib.lib_Node);    /* I'm no longer an installed library */
  203.         libsize = ParMBase->pb_Lib.lib_NegSize + ParMBase->pb_Lib.lib_PosSize;
  204.         FreeMem((char *) ParMBase - ParMBase->pb_Lib.lib_NegSize, libsize);
  205.         CloseLibrary(DOSBase);
  206.     }
  207.     else
  208.         ParMBase->pb_Lib.lib_Flags |= LIBF_DELEXP;
  209.  
  210.     /* return NULL or real seglist */
  211.     return (long) seglist;
  212. }
  213.  
  214.  
  215. void GetCurrentMouseOpt(struct MouseOpt *YourMouseOpt)
  216. {
  217.     *YourMouseOpt = MouseOpt;
  218. }
  219.  
  220.  
  221.