------------------------------------------------------------------ -- -- NAME: METAFILE_WS_TABLES - BODY -- DISCREPANCY REPORTS: -- ------------------------------------------------------------------ -- file : METAFILE_WS_TBLS_B.ADA -- level: 0a,1a,2a,0b,1b,2b,0c,1c,2c with GKS_ERRORS; with UNCHECKED_DEALLOCATION; package body METAFILE_WS_TABLES is -- The list of metafile state lists that can be initialized -- from the METAFILE_WS_DT. type LIST_OF_ST_LST; type PTR_TO_LST_OF_MF_ST_LST is access LIST_OF_ST_LST; type LIST_OF_ST_LST is record NEXT_SL : PTR_TO_LST_OF_MF_ST_LST; MF_ST_LST : METAFILE_STATE_LIST_PTR; end record; METAFILE_ST_LSTS : PTR_TO_LST_OF_MF_ST_LST; -- Contains the last state list that was added to the list. function GET_METAFILE_STATE_LIST_PTR (WS_ID : in GKS_TYPES.WS_ID) return METAFILE_STATE_LIST_PTR is -- This procedure returns a pointer to the metafile state list -- specified by a workstation id. -- The following parameter is used in this function: -- WS_ID - The workstation id for the specified metafile state list -- to be returned. TEMP_SL : PTR_TO_LST_OF_MF_ST_LST; -- A temporary state list used for for the loop. begin TEMP_SL := METAFILE_ST_LSTS; while TEMP_SL /= NULL loop -- If the WS_ID is equal to the requested WS_ID return the -- METAFILE_STATE_LIST. If not, get the next -- METAFILE_STATE_LIST. if TEMP_SL.MF_ST_LST.WORKSTATION_ID = WS_ID then return TEMP_SL.MF_ST_LST; else TEMP_SL := TEMP_SL.NEXT_SL; end if; end loop; -- If no state list is found with the requested id, NULL is -- returned. return NULL; end GET_METAFILE_STATE_LIST_PTR; procedure ADD_METAFILE_STATE_LIST (WS_ID : in GKS_TYPES.WS_ID; ERROR_INDICATOR : out ERROR_NUMBER) is -- The following procedure adds a metafile state list to the list -- of workstations of the same type. -- -- The following parameters are used in this procedure: -- WS_ID - The workstation id for the workstation. -- ERROR_INDICATOR - An error indicator used to trap errors. begin declare OLD_METAFILE_ST_LST : PTR_TO_LST_OF_MF_ST_LST; -- Used as a temporary for linking the lists together. begin -- Get a new METAFILE_STATE_LIST. -- Sets the OLD_METAFILE_ST_LST equal to the current state list. -- It gets a new state list and links the new state list to the -- OLD_METAFILE_ST_LST. The first time a state list is allocated -- METAFILE_ST_LSTS is NULL, therefore it sets OLD_METAFILE_ST_ -- LST to NULL. It gets a new state list, and sets the -- NEXT_ST_LST to OLD_METAFILE_ST_LST which is NULL; OLD_METAFILE_ST_LST := METAFILE_ST_LSTS; METAFILE_ST_LSTS := new LIST_OF_ST_LST; METAFILE_ST_LSTS.NEXT_SL := OLD_METAFILE_ST_LST; -- Get a new state list and add it to the list. METAFILE_ST_LSTS.MF_ST_LST:= new METAFILE_STATE_LST; -- Initialize the METAFILE_ST_LSTS.MF_ST_LST. -- The following are parameters passed in to the procedure. METAFILE_ST_LSTS.MF_ST_LST.WORKSTATION_ID := WS_ID; -- If the procedure gets to this point without raising an -- exception, the workstation was opened successfully. ERROR_INDICATOR := GKS_ERRORS.SUCCESSFUL; end; exception when OTHERS => ERROR_INDICATOR := GKS_ERRORS.WS_CANNOT_OPEN; end ADD_METAFILE_STATE_LIST; procedure DELETE_METAFILE_STATE_LIST (WS_ID : in GKS_TYPES.WS_ID) is -- This procedure deletes the metafile state list specified by the -- WS_ID from the list of metafile state lists. -- -- The following parameter is used in this procedure: -- WS_ID - The workstation id for the metafile state list to delete. -- This procedure deallocates the specified metafile state list. procedure FREE_MF_ST_LST is new UNCHECKED_DEALLOCATION (METAFILE_STATE_LST, METAFILE_STATE_LIST_PTR); -- This procedure deallocates a component of the LIST_OF_ST_LST. procedure FREE_LIST_OF_ST_LST is new UNCHECKED_DEALLOCATION (LIST_OF_ST_LST, PTR_TO_LST_OF_MF_ST_LST); PREV_TEMP, TEMP_SL : PTR_TO_LST_OF_MF_ST_LST := METAFILE_ST_LSTS; --Temporary variables for deleting the state list. begin while TEMP_SL /= NULL loop if TEMP_SL.MF_ST_LST.WORKSTATION_ID = WS_ID then -- If the temporary is equal to the first element in the -- list then the list can just be freed. if TEMP_SL = METAFILE_ST_LSTS then METAFILE_ST_LSTS := TEMP_SL.NEXT_SL; FREE_MF_ST_LST(TEMP_SL.MF_ST_LST); FREE_LIST_OF_ST_LST(TEMP_SL); EXIT; else -- Set the previous state list's 'next' pointer equal to -- next state list after the temporary. Then free the -- state list. PREV_TEMP.NEXT_SL := TEMP_SL.NEXT_SL; FREE_MF_ST_LST(TEMP_SL.MF_ST_LST); FREE_LIST_OF_ST_LST(TEMP_SL); EXIT; end if; else -- Set the temporary state list equal to the previous state -- list and get the next state list. PREV_TEMP := TEMP_SL; TEMP_SL := TEMP_SL.NEXT_SL; end if; end loop; end DELETE_METAFILE_STATE_LIST; end METAFILE_WS_TABLES;