! Dictionary manipulation for new filestores

%externalstring(47) copyright %alias "GDMR_(C)_FSDICT" = %c
   "Copyright (C) 1987 George D.M. Ross"

%option "-nonstandard-nocheck-nodiag-noline-nostack"
!%option "-nonstandard"

%include "MOOSE:MOUSE.INC"

%systemroutinespec phex(%integer i)

%conststring(15) FS dictionary name = "FS_DICTIONARY"

%record(dict fm)%map master master
   %ownrecord(dict fm) FS dictionary = 0
   %record(dict fm)%name m
   %integer i
      m == poa_master dict
      m == m_alt %while m_alt ## nil
      !! printstring("Master master: top alt at ")
      !! phex(addr(m));  newline
      i = find entry(FS dictionary name, m)
      %if i = 0 %start
         !! printstring("Master master: creating...");  newline
         i = make entry(FS dictionary name, m)
         %signal 10, 0, 0, "Can't add FS dictionary?" %if i = 0
         integer(i) = addr(FS dictionary)
      %finish
      !! printstring("Master master: found dictionary at ")
      !! phex(integer(i));  newline
      %result == record(integer(i))
%end

%externalroutine FS insert(%string(31) name, %integer value)
   %record(dict fm)%name master
   %integer i
      !! printstring("Insert ");  printstring(name)
      !! printstring(" with value ");  write(value, 0)
      !! printstring(" (");  phex(value);  print symbol(')')
      !! newline
      master == master master
      %signal 10, 0, 0, "Can't find FS dictionary?" %if master == nil
      i = make entry(name, master)
      %signal 10, 0, 0, "FS insert" %if i = 0
      integer(i) = value
%end

%externalpredicate FS lookup(%string(31) name, %integername value)
   %record(dict fm)%name master
   %integer i
      !! printstring("Look up ");  printstring(name)
      !! newline
      master == master master
      %signal 10, 0, 0, "Can't find FS dictionary?" %if master == nil
      i = find entry(name, master)
      %false %if i = 0
      value = integer(i)
      %true
%end

%end %of %file
