* This is for UniVerse, has been used in versions 7.3 and later.

FUNCTION ReadHashedFile(HashedFile,KeyValue,FieldToReturn)
$COPYRIGHT "Copyright (c) 2002-2006, Ray Wurlod.  All rights reserved.  May be 
freely used with this copyright notice intact."

* Hashed file may be given as a VOC name or pathname.  If both exist, the VOC 
name takes precedence.  
* The record whose key value is supplied is read, and the field requested is 
returned.  
* The field may be requested by name or by number.  If there is a field whose 
name is a number, 
* irrespective of the actual storage location, that takes precedence.

$INCLUDE UNIVERSE.INCLUDE FILEINFO.H
$INCLUDE UNIVERSE.INCLUDE INFO_KEYS.H

* Determine whether HashedFile entry occurs in VOC file.
      CALL !VOC.PATHNAME(IK$DATA, (HashedFile), Pathname, TempVocNeeded)

      Ans = @NULL
      HashedFileName = HashedFile

      If TempVocNeeded
      Then
         DirPath = ""
         FilePath = ""
         CALL !GET.PATHNAME(HashedFile, DirPath, FilePath, Status)
         CALL !MAKE.PATHNAME(DirPath, "D_":FilePath, DictPath, Status)
         VocName = FilePath : ".$$TMP$$. " : @USERNO
         VocEntry = "F" : @FM : HashedFile : @FM : DictPath
         Open "VOC" To Voc.fvar
         Then
            RecordLockU Voc.fvar,VocName
            Write VocEntry To Voc.fvar, VocName
            Then
               HashedFileName = VocName
            End
         End
      End

* Open hashed file and its dictionary (to retrieve field name definition)
      Open HashedFileName To File.fvar
         Else File.fvar = 0
      Open "DICT",HashedFileName To File.dfvar
         Else File.dfvar = 0

      If FileInfo(File.fvar, FINFO$IS.FILEVAR) And FileInfo(File.dfvar, 
FINFO$IS.FILEVAR)
      Then

         Read DictEntry From File.dfvar, FieldToReturn
         Then

            * Dict entry was found.

            Ans = ""  ; * in case of PH or X entry (A and S not handled either)

            Begin Case

               Case FieldToReturn = -1  ; * special override
                  Read Ans From File.fvar,KeyValue Else Ans = ""

               Case Left(DictEntry,1) = "D"
                  ReadV Ans From File.fvar,KeyValue,DictEntry<2> Else Ans = ""

               Case Left(DictEntry,1) = "I"
                  Ans = ""
                  Read @RECORD From File.fvar,KeyValue
                  Then
                     @ID = KeyValue
                     Ans = 
Fmt(Oconv(Itype(DictEntry),DictEntry<3>),DictEntry<5>)
                  End

            End Case

         End
         Else

            * Dict entry not found
            Ans = ""
            If Num(FieldToReturn)
            Then
               If FieldToReturn < 0
                  Then Read Ans From File.fvar,KeyValue Else Ans = ""
                  Else ReadV Ans From File.fvar,KeyValue,FieldToReturn Else Ans 
= ""
            End

         End

      End


      If TempVocNeeded
      Then
         Delete Voc.fvar, VocName
         Close Voc.fvar
      End

RETURN(Ans)

END
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to