home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk403.lzh / RexxHostLib / LibMain.c < prev    next >
C/C++ Source or Header  |  1990-11-17  |  7KB  |  338 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by MXM
  4.  *
  5.  *    Name .....: LibMain.c
  6.  *    Created ..: Saturday 06-Jan-90 23:30
  7.  *    Revision .: 8
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    26-Apr-90       Olsen           Opened dos.library (always forgot it!)
  12.  *    13-Apr-90       Olsen           Added NULL-function
  13.  *    01-Apr-90       Olsen           Moved library calls
  14.  *    27-Mar-90       Olsen           Added alerts/moved flag checks
  15.  *    26-Mar-90       Olsen           Rearranged LibExpunge/LibClose
  16.  *    16-Mar-90       Olsen           Rework for Aztec 5.0 release
  17.  *    07-Jan-90       Olsen           - Empty log message -
  18.  *    07-Jan-90       Olsen           Moved OpenLibrary call
  19.  *    07-Jan-90       Olsen           - Empty log message -
  20.  *    07-Jan-90       Olsen           Created this file!
  21.  *
  22.  * $Revision Header *********************************************************
  23.  *
  24.  *    This file contains the skeleton library functions employed by
  25.  *    rexxhost.library.
  26.  *
  27.  ***************************************************************************/
  28.  
  29.     /* Imported from RexxHostLib.c */
  30.  
  31. extern LONG Revision;
  32.  
  33.     /* ASCII library ID. */
  34.  
  35. char *LibName    = "rexxhost.library";
  36. char *LibId    = "rexxhost.library 36.14 (09 Sep 1990)\r\n";
  37.  
  38.     /* External data, defined in asm startup code. */
  39.  
  40. extern struct Resident     LibRomTag;
  41. extern LONG         LibInit();
  42.  
  43.     /* Main rexx library base. */
  44.  
  45. struct RxsLib        *RexxSysBase;
  46.  
  47.     /* External reference to DOSBase pointer. */
  48.  
  49. struct DosLibrary    *DOSBase;
  50. struct ExecBase        *SysBase;
  51.  
  52.     /* Pointer to library segment list. */
  53.  
  54. BPTR             LibSegList = ZERO;
  55.  
  56.     /* Protos for this module. */
  57.  
  58. struct RexxHostBase *    LibMain(struct RexxHostBase *,BPTR);
  59.  
  60. struct RexxHostBase *    LibOpen(VOID);
  61. BPTR            LibClose(VOID);
  62. BPTR            LibExpunge(VOID);
  63. LONG            LibNull(VOID);
  64.  
  65.     /* And now for the pragmas... */
  66.  
  67. #pragma amicall(RexxHostBase, 0x06, LibOpen())
  68. #pragma amicall(RexxHostBase, 0x0c, LibClose())
  69. #pragma amicall(RexxHostBase, 0x12, LibExpunge())
  70. #pragma amicall(RexxHostBase, 0x18, LibNull())
  71.  
  72.     /* The library initialization. */
  73.  
  74. #pragma regcall(LibMain(d0,a0))
  75.  
  76.     /* The structure expected by the library loader (auto-init). */
  77.  
  78. struct InitTable
  79. {
  80.     ULONG     it_DataSize;    /* Data size to allocate. */
  81.     APTR    *it_FuncTable;    /* Pointer to function table. */
  82.     APTR     it_DataInit;    /* Pointer to data initializers (remember InitStruct?). */
  83.     APTR     it_InitFunc;    /* The real library init function. */
  84. };
  85.  
  86.     /* The list of library functions. */
  87.  
  88. APTR LibFuncTab[] =
  89. {
  90.     LibOpen,        /* Standard library routines. */
  91.     LibClose,
  92.     LibExpunge,
  93.     LibNull,
  94.  
  95.     CreateRexxHost,        /* Now for the real stuff. */
  96.     DeleteRexxHost,
  97.     SendRexxCommand,
  98.     FreeRexxCommand,
  99.     ReplyRexxCommand,
  100.     GetRexxCommand,
  101.     GetRexxArg,
  102.     GetRexxResult1,
  103.     GetRexxResult2,
  104.     GetToken,
  105.     GetStringValue,
  106.     BuildValueString,
  107.     RexxStrCmp,
  108.     GetRexxMsg,
  109.     SendRexxMsg,
  110.     GetRexxString,
  111.     GetRexxClip,
  112.  
  113.     (APTR)-1        /* End marker. */
  114. };
  115.  
  116.     /* The romtag needs this. */
  117.  
  118. struct InitTable LibInitTab =
  119. {
  120.     sizeof(struct RexxHostBase),    /* Lib base. */
  121.     LibFuncTab,            /* Function table. */
  122.     NULL,                /* No data init table (we'll do autoinit). */
  123.     LibInit                /* Lib init routine. */
  124. };
  125.  
  126.     /* LibMain(RexxHostBase,SegList):
  127.      *
  128.      *    Does the main library initialization, expects
  129.      *    all arguments in registers.
  130.      */
  131.  
  132. struct RexxHostBase *
  133. LibMain(struct RexxHostBase *RexxHostBase,BPTR SegList)
  134. {
  135.     struct RexxHostBase *LibBase = NULL;
  136.  
  137.         /* We want to be initialized only once, the empty
  138.          * seglist will (hopefully) guarantee that.
  139.          */
  140.  
  141.     if(!LibSegList)
  142.     {
  143.         if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0))
  144.         {
  145.                 /* Try to open rexxsyslib.library. */
  146.  
  147.             if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  148.             {
  149.                     /* Remember segment list. */
  150.  
  151.                 LibSegList = SegList;
  152.  
  153.                     /* Seems that all initialization went fine. */
  154.  
  155.                 LibBase = RexxHostBase;
  156.  
  157.                     /* Fill in the library node head. */
  158.  
  159.                 RexxHostBase -> LibNode . lib_Node . ln_Type    = NT_LIBRARY;
  160.                 RexxHostBase -> LibNode . lib_Node . ln_Name    = LibName;
  161.  
  162.                     /* Set the remaining flags. */
  163.  
  164.                 RexxHostBase -> LibNode . lib_Flags        = LIBF_SUMUSED | LIBF_CHANGED;
  165.                 RexxHostBase -> LibNode . lib_Version        = LibRomTag . rt_Version;
  166.                 RexxHostBase -> LibNode . lib_Revision        = Revision;
  167.                 RexxHostBase -> LibNode . lib_IdString        = (APTR)LibId;
  168.  
  169.                     /* Fill in the pointer. */
  170.  
  171.                 RexxHostBase -> RexxSysBase = RexxSysBase;
  172.             }
  173.             else
  174.             {
  175.                 /* Help! Can't open the rexx library! */
  176.  
  177.                 Alert(AT_Recovery | AG_OpenLib,&RexxHostBase);
  178.             }
  179.         }
  180.         else
  181.         {
  182.             /* Arrgh! Can't open dos.library! */
  183.  
  184.             Alert(AT_Recovery | AG_OpenLib | AO_DOSLib,&RexxHostBase);
  185.         }
  186.     }
  187.  
  188.         /* Return the result (surprise!). */
  189.  
  190.     return(LibBase);
  191. }
  192.  
  193.     /* LibOpen():
  194.      *
  195.      *    Library open routine.
  196.      */
  197.  
  198. struct RexxHostBase *
  199. LibOpen()
  200. {
  201.     struct RexxHostBase *RexxHostBase;
  202.  
  203.         /* If rexxsyslib.library didn't open we refuse
  204.          * to go any further.
  205.          */
  206.  
  207.     if(RexxSysBase)
  208.     {
  209.             /* Increment open count and prevent delayed
  210.              * expunges.
  211.              */
  212.  
  213.         RexxHostBase -> LibNode . lib_OpenCnt++;
  214.         RexxHostBase -> LibNode . lib_Flags &= ~LIBF_DELEXP;
  215.  
  216.             /* Return base pointer. */
  217.  
  218.         return(RexxHostBase);
  219.     }
  220.  
  221.     return(NULL);
  222. }
  223.  
  224.     /* LibClose():
  225.      *
  226.      *    Closes the library.
  227.      */
  228.  
  229. BPTR
  230. LibClose()
  231. {
  232.     struct RexxHostBase    *RexxHostBase;
  233.     BPTR             SegList = ZERO;
  234.  
  235.         /* Is the library user count ok? */
  236.  
  237.     if(RexxHostBase -> LibNode . lib_OpenCnt > 0)
  238.     {
  239.             /* Decrement user count. */
  240.  
  241.         RexxHostBase -> LibNode . lib_OpenCnt--;
  242.  
  243.             /* Try the expunge. */
  244.  
  245.         SegList = LibExpunge();
  246.     }
  247.     else
  248.     {
  249.         /* One close request after the lib has already
  250.          * shut down? We'll call Mr. Guru.
  251.          */
  252.  
  253.         Alert(AT_Recovery | AG_CloseLib,&RexxHostBase);
  254.     }
  255.  
  256.         /* Return the segment list, ramlib will know
  257.          * what to do with it.
  258.          */
  259.  
  260.     return(SegList);
  261. }
  262.  
  263.     /* LibExpunge(RexxHostBase):
  264.      *
  265.      *    Expunge library, careful: this can be called by
  266.      *    ramlib without the rest of the library knowing
  267.      *    about it.
  268.      */
  269.  
  270. BPTR
  271. LibExpunge()
  272. {
  273.     struct RexxHostBase    *RexxHostBase;
  274.     BPTR             SegList = ZERO;
  275.  
  276.         /* Is the user count zero, the delayed expunge flag
  277.          * set and do we have a valid segment list?
  278.          */
  279.  
  280.     if(RexxHostBase -> LibNode . lib_OpenCnt == 0 && (RexxHostBase -> LibNode . lib_Flags & LIBF_DELEXP) && LibSegList)
  281.     {
  282.             /* Remember segment list. */
  283.  
  284.         SegList = LibSegList;
  285.  
  286.             /* Set real segment list to zero which will
  287.              * hopefully keep us from getting expunged
  288.              * twice.
  289.              */
  290.  
  291.         LibSegList = ZERO;
  292.  
  293.             /* Remove library from lib list. */
  294.  
  295.         Remove(&RexxHostBase -> LibNode . lib_Node);
  296.  
  297.             /* Close the libraries. */
  298.  
  299.         if(RexxSysBase)
  300.             CloseLibrary(RexxSysBase);
  301.  
  302.         if(DOSBase)
  303.             CloseLibrary(DOSBase);
  304.  
  305.             /* Free library/jumptable memory. */
  306.  
  307.         FreeMem((char *)((ULONG)RexxHostBase - RexxHostBase -> LibNode . lib_NegSize),RexxHostBase -> LibNode . lib_NegSize + RexxHostBase -> LibNode . lib_PosSize);
  308.     }
  309.     else
  310.     {
  311.         /* In any other case we'll set the delayed
  312.          * expunge flag (so next expunge call will
  313.          * hopefully wipe us from the lib list).
  314.          */
  315.  
  316.         RexxHostBase -> LibNode . lib_Flags |= LIBF_DELEXP;
  317.     }
  318.  
  319.         /* Return segment list pointer. */
  320.  
  321.     return(SegList);
  322. }
  323.  
  324.     /* LibNull():
  325.      *
  326.      *    Dummy routine, always returns NULL.
  327.      */
  328.  
  329. LONG
  330. LibNull()
  331. {
  332.     struct RexxHostBase *RexxHostBase;
  333.  
  334.         /* Do nothing useful, return NULL. */
  335.  
  336.     return(NULL);
  337. }
  338.