! ----- CALCULATE_NEXT_AVAILABLE_UIC.FUN ----- ! ! ----- SUBROUTINE TO CALCULATE THE NEXT AVAILABLE UIC BASED UPON ----- ! ----- THE ASSIGNED UIC GROUP FOR THIS DIVISION ----- ! ! ---------- PASSED: ---------- ! ! ----- DIV_INDEX = Division index into DIVISION_UIC_GROUPS() ! ----- to use ! ! ---------- RETURNED: ---------- ! ! ----- GRP = Next Available decimal UIC Group number ! ----- MBR = Next Available decimal UIC Member number ! ! ----- Last Change 07/09/93 by Brian Lomasky ----- ! SUB CALCULATE_NEXT_AVAILABLE_UIC %INCLUDE "NUSER.INC" DECLARE WORD ERR_FLAG ! TRUE IF DONE SEARCHING FILE DECLARE WORD FOUND_IDENTIFIER ! CODE FOR MATCHING RECORD DECLARE WORD I_O_CHNL ! RIGHTSLIST I/O CHNL TO ACCESS DECLARE LONG LAST_DEC_UIC_MBR ! LAST DECIMAL UIC MEMBER READ DECLARE LONG LAST_UIC_MBR_RETURN! LAST UIC MEMBER TO BE RETURNED DECLARE LONG LAST_UIC_MBR_SEARCH! MEMBER UIC SEARCH VALUE DECLARE WORD SEARCH_FOR_NEXT_UIC! TRUE TO SEARCH FOR NEXT UIC DECLARE LONG UIC_GROUP_SEARCH ! USER-ENTERED UIC GROUP SEARCH EXTERNAL LONG FUNCTION DEC_TO_OCT( & LONG) ! CONVERT DECIMAL TO OCTAL EXTERNAL LONG FUNCTION OCT_TO_DEC( & LONG) ! CONVERT OCTAL TO DECIMAL EXTERNAL WORD FUNCTION SEARCH_RIGHTSLIST(WORD, WORD, & WORD) ! READ MATCHING RIGHTSLIST REC UIC_GROUP_SEARCH = DIVISION_UIC_GROUPS(DIV_INDEX) IF UIC_GROUP_SEARCH < 1% OR UIC_GROUP_SEARCH > 32767% THEN PRINT PRINT "Error: Invalid UIC Group"; UIC_GROUP_SEARCH; BEL CALL SYS$EXIT(ERROR_WITH_NO_PUTMSG BY VALUE) END IF ! ----- CONVERT OCTAL UIC MEMBER NUMBER TO ITS DECIMAL ----- ! ----- VALUE ----- OCT_UIC_GROUP = OCT_TO_DEC(UIC_GROUP_SEARCH) OCT_UIC_MEMBER = 0% ! START SEARCH WITH FIRST MEMBER KGB_UIC_MEMBER = 0% ! START SEARCH WITH FIRST MEMBER KGB_UIC_GROUP = OCT_UIC_GROUP IF DEBUG_MODE THEN PRINT "DEBUG>SEARCH FOR UIC IN GROUP " + & NUM1$(DEC_TO_OCT((KGB_UIC_GROUP))) END IF SEARCH_FOR_NEXT_UIC = TRUE ! SO LOOP WILL EXECUTE ONCE WHILE SEARCH_FOR_NEXT_UIC ! WHILE WE ARE SEARCHING... ! ----- ASSUME THAT WE WILL EXIT AFTER 1 PASS ----- SEARCH_FOR_NEXT_UIC = FALSE ! ----- SEARCH FOR FIRST AVAILABLE UIC-FORMAT ----- ! ----- IDENTIFIER VALUE WHICH IS AVAILABLE FOR ----- ! ----- USE ----- IF DEBUG_MODE THEN PRINT "DEBUG>--------------------------------" PRINT "DEBUG>SEARCH FOR UIC GREATER" + & " THAN [" + & NUM1$(DEC_TO_OCT(( & KGB_UIC_GROUP))) + & "," + NUM1$(DEC_TO_OCT(( & KGB_UIC_MEMBER))) + "]" END IF ! ----- STORE MEMBER UIC SEARCH ----- LAST_UIC_MBR_SEARCH = KGB_UIC_MEMBER LAST_DEC_UIC_MBR = -9% ! INIT FOR NO LAST DECIMAL UIC LAST_UIC_MBR_RETURN = 0%! INIT FOR NO LAST UIC MEMBER ERR_FLAG = FALSE ! SET SO LOOP WILL EXECUTE WHEN ERROR IN FIND #1%, KEY #0% GE KGB_IDENTIFIER, REGARDLESS USE IF ERR = BUCKET_LOCKED THEN SLEEP 1% RETRY END IF ERR_FLAG = TRUE ! SET END-OF-FILE FLAG CONTINUE IF ERR = REC_NOT_FOUND EXIT HANDLER END WHEN WHILE NOT ERR_FLAG ! LOOP TILL WE'RE DONE WHEN ERROR IN ! ----- READ NEXT SEQUENTIAL ----- ! ----- RECORD ----- GET #1%, REGARDLESS USE IF ERR = BUCKET_LOCKED THEN SLEEP 1% RETRY END IF ! ----- SET END-OF-FILE FLAG ----- ERR_FLAG = TRUE CONTINUE IF ERR = REC_NOT_FOUND EXIT HANDLER END WHEN ! ----- DONE IF END-OF-FILE FLAG SET ----- ITERATE IF ERR_FLAG ! ----- CONVERT DECIMAL UIC GROUP NUMBER ----- ! ----- TO ITS OCTAL VALUE (EXPRESSED AS ----- ! ----- A DECIMAL) ----- UIC_GROUP = DEC_TO_OCT((KGB_UIC_GROUP)) IF DEBUG_MODE THEN PRINT "DEBUG>Found Identifier" & + " UIC of " + & NUM1$(UIC_GROUP) + & "," + NUM1$(DEC_TO_OCT((& KGB_UIC_MEMBER))) END IF UNLOCK #1% ! ----- SKIP IF [xxx,0] WAS FOUND ----- ITERATE IF KGB_UIC_MEMBER = 0% SELECT UIC_GROUP_SEARCH CASE > UIC_GROUP! FOUND UIC LESS THAN SEARCH UIC ITERATE ! READ NEXT RECORD CASE < UIC_GROUP! FOUND UIC MORE THAN SEARCH UIC ! ----- SET TO EXIT LOOP ----- ERR_FLAG = TRUE ITERATE ! SKIP TO END OF LOOP CASE ELSE ! UIC GROUPS MATCH ! ----- SEE IF WE READ THE NEXT ----- ! ----- OR SAME SEQUENTIAL (OR THE ----- ! ----- FIRST) UIC MEMBER ----- IF KGB_UIC_MEMBER = & LAST_DEC_UIC_MBR + 1% & OR KGB_UIC_MEMBER = & LAST_DEC_UIC_MBR OR & LAST_DEC_UIC_MBR = -9% THEN ! ----- STORE THE LAST ----- ! ----- DECIMAL UIC MEMBER ----- ! ----- THAT WAS READ ----- LAST_DEC_UIC_MBR = & KGB_UIC_MEMBER ! ----- ENSURE A POSITIVE ----- ! ----- VALUE IS STORED ----- ! ----- AS THE PREVIOUS ----- ! ----- MEMBER UIC TO BE ----- ! ----- RETURNED ----- IF KGB_UIC_MEMBER >= 0% THEN LAST_UIC_MBR_RETURN = & KGB_UIC_MEMBER ELSE LAST_UIC_MBR_RETURN = & KGB_UIC_MEMBER & + 65536% END IF ELSE ! ----- WE FOUND A ----- ! ----- NON-CONSECUTIVE ----- ! ----- UIC MEMBER ----- ! ----- RETURN A UIC THAT ----- ! ----- IS 1 HIGHER THAN ----- ! ----- THE PREVIOUS UIC ----- ! ----- MEMBER THAT WAS ----- ! ----- READ ----- ! ----- SET TO EXIT LOOP ----- ERR_FLAG = TRUE END IF END SELECT NEXT ! ----- THE PROGRAM WILL REACH HERE UPON REACHING ----- ! ----- THE END OF FILE OF THE RIGHTSLIST FILE OR ----- ! ----- IF WE'VE FOUND THE NEXT UIC MEMBER THAT IS ----- ! ----- TO BE RETURNED ----- ! ----- SEE IF INVALID NEXT UIC MEMBER NUMBER ----- IF LAST_UIC_MBR_RETURN >= 65534% THEN PRINT PRINT "Error: Last Identifier UIC is" & + " out of range" + BEL CALL SYS$EXIT(ERROR_WITH_NO_PUTMSG BY VALUE) END IF ! ----- SEE IF ANY LAST UIC MEMBER NUMBER FOUND ----- IF LAST_UIC_MBR_RETURN = 0% THEN ! ----- USE VALUE THAT WE LAST SEARCHED ----- ! ----- FOR ----- KGB_UIC_MEMBER = LAST_UIC_MBR_SEARCH ! ----- FIX IF NO UICS IN DESIRED GROUP ----- ! ----- EXIST ----- KGB_UIC_MEMBER = 1% IF KGB_UIC_MEMBER = 0% ELSE KGB_UIC_MEMBER = LAST_UIC_MBR_RETURN + 1% END IF KGB_UIC_GROUP = OCT_TO_DEC(UIC_GROUP_SEARCH) ! ----- SEE IF THIS UIC EXISTS ON ANY OTHER NODE'S ----- ! ----- RIGHTSLIST.DAT FILE ----- IF DEBUG_MODE THEN PRINT "DEBUG>Check other rightslists" + & " for UIC of " + NUM1$( & DEC_TO_OCT((KGB_UIC_GROUP))) + & "," + NUM1$(DEC_TO_OCT(( & KGB_UIC_MEMBER))) END IF FOUND_IDENTIFIER = 0% ! INIT FILE I/O CHANNEL I_O_CHNL = 1% ! SET TO SKIP FIRST CHANNEL ! ----- FOR EACH OPEN FILE: ----- WHILE I_O_CHNL < RIGHTSLIST_COUNTER I_O_CHNL = I_O_CHNL + 1% ! ----- SKIP IF RIGHTSLIST IS UNAVAILABLE ----- ITERATE IF TRM$(RIGHTSLIST_SPECS(I_O_CHNL)) = "" IF DEBUG_MODE THEN PRINT "DEBUG>Search" + & " Rightslist #" + & NUM1$(I_O_CHNL) END IF IF SEARCH_RIGHTSLIST(I_O_CHNL, 0%, FALSE) THEN IF DEBUG_MODE THEN PRINT "DEBUG>UIC FOUND" & + " ON " + TRM$(& RIGHTSLIST_NODES& (I_O_CHNL)) END IF ! ----- STORE INDEX OF MATCHING ----- ! ----- FILE ----- FOUND_IDENTIFIER = I_O_CHNL ! ----- SET TO EXIT LOOP ----- I_O_CHNL = RIGHTSLIST_COUNTER END IF NEXT IF FOUND_IDENTIFIER <> 0% THEN ! ----- INCREMENT TO TRY NEXT HIGHER UIC ----- ! ----- MEMBER NUMBER ----- IF DEBUG_MODE THEN PRINT "DEBUG>Find next higher" & + " UIC than " + & NUM1$(DEC_TO_OCT(( & KGB_UIC_GROUP))) + & "," + NUM1$(DEC_TO_OCT((& KGB_UIC_MEMBER))) END IF IF KGB_UIC_MEMBER = 32767% THEN KGB_UIC_MEMBER = -32767% - 1% ELSE KGB_UIC_MEMBER = KGB_UIC_MEMBER + 1% END IF ! ----- RESTART UIC SEARCHING FROM ----- ! ----- BEGINNING ----- ! ----- SET TO SEARCH FOR NEXT UIC ----- SEARCH_FOR_NEXT_UIC = TRUE END IF NEXT ! ----- STORE DECIMAL UIC GROUP AND MEMBER ----- GRP = OCT_TO_DEC(UIC_GROUP_SEARCH) MBR = KGB_UIC_MEMBER END SUB