PROGRAM MenuFilter
LastUpdated... = "Rev: 15:17 02Nov1993 u2443 8 /users/u2443/BP/MENU.FILTER"
$INCLUDE UPCASE.EQUATES
$INCLUDE FDEF MENU.MASTER.FDEF
$INCLUDE FDEF MENU.SECURITY.FDEF
open "MENU.MASTER" to MenuMasterFile else
   stop "Unable to open MENU.MASTER file.  (MenuFilter)"
end
open "MENU.SECURITY" to MenuSecurityFile else
   stop "Unable to open MENU.SECURITY file.  (MenuFilter)"
end
Xref = ""
gosub LoadSecurityData
select MenuMasterFile
Count = 0
Countb = 0
crt "Processing all items of MENU.MASTER file:"
crt "Item...  Menu..."
loop
   readnext MenuMasterKey else exit
   Count += 1
   if mod(Count,10) eq 0 then crt @(0):fmt(Count,"R#7"):@(0):
   begin case
      case MenuMasterKey matches "'FN*'..."
         continue
      case MenuMasterKey matches "'ORIG*'..."
         continue
      case MenuMasterKey matches "'ANSI*'..."
         continue
   end CASE
   read MenuMasterRec from MenuMasterFile, MenuMasterKey else continue
   if MenuMasterRec<2,2> ne "Y" then continue ;* Skip non custom menus
   Countb += 1
   if mod(Countb,10) eq 0 then crt @(9):fmt(Countb,"R#7"):@(0):
   FirstLine = MenuMasterRec<MENU$NBR.OF.ATTS>
   LastLine  = dcount(MenuMasterRec,@FM)
   for i = FirstLine to LastLine
      if MenuMasterRec<i,3> ne "M" then continue
      ItemName = MenuMasterRec<i,2>
      gosub BuildXref
   next i
   if MenuMasterKey matches "U...MASTER" then continue
   if MenuMasterKey matches "D...MASTER" then continue
   locate MenuMasterKey in Xref<1,1> setting Idx else
      ins MenuMasterKey before Xref<1,Idx>
      ins ""            before Xref<2,Idx>
   end
repeat
crt fmt(Count,"R#7"):"  ":fmt(Countb,"R#7")
gosub PrintXref
stop
 
LoadSecurityData:
select MenuSecurityFile
crt "Loading MENU.SECURITY data..."
Count = 0
crt "Item..."
loop
   readnext MenuSecurityKey else exit
   Count += 1
   if mod(Count,10) eq 0 then crt fmt(Count,"R#7"):@(0):
   readv InitialMenu from MenuSecurityFile, MenuSecurityKey, MNUS$INITIAL.MENU else continue
   readv AllowedMenus from MenuSecurityFile, MenuSecurityKey, MNUS$ALLOWED.MENUS else continue
   locate InitialMenu in Xref<1,1> setting Idx else
      ins InitialMenu     before Xref<1,Idx>
      ins MenuSecurityKey before Xref<2,Idx>
   end
   MoreAllowedMenus = AllowedMenus ne ""
   loop while MoreAllowedMenus
      remove AllowedMenu from AllowedMenus setting MoreAllowedMenus
      locate AllowedMenu in Xref<1,1> setting Idx else
         ins AllowedMenu     before Xref<1,Idx>
         ins MenuSecurityKey before Xref<2,Idx>
      end
   repeat
repeat
crt fmt(Count,"R#7")
return
 
BuildXref:
locate ItemName in Xref<1,1> setting Idx then
   if Xref<2,Idx> eq "" then
      Xref<2,Idx> = MenuMasterKey
   end
end else
   ins ItemName      before Xref<1,Idx>
   ins MenuMasterKey before Xref<2,Idx>
end
return
 
PrintXref:
Items = dcount(Xref<1>,@VM)
crt "Total number of child/parent relationships identified: ":Items
Work = ""
for i = 1 to Items
   if Xref<2,i> eq "" then
      Work<-1> = Xref<1,i>
   end
next i
crt "Total number of custom menus with no parents: ":dcount(Work,@FM)
formlist Work
crt "Default select list activated..."
return
end
