home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / xseek.prg < prev   
Text File  |  1993-10-14  |  2KB  |  94 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: xseek.prg
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: $Date$
  10.  * Revision..: $Revision$
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*  $DOC$
  23.  *  $FUNCNAME$
  24.  *       GT_XSEEK()
  25.  *  $CATEGORY$
  26.  *       General
  27.  *  $ONELINER$
  28.  *       Special seek function. (x = xtra)
  29.  *  $SYNTAX$
  30.  *       GT_xSeek(xValue, nSeekNum, nOrder, bBlock) --> xRet
  31.  *  $ARGUMENTS$
  32.  *       <xValue>    -  The value to seek for
  33.  *       <nSeekNum>  -  Option (type of seek (see Description))
  34.  *       <nOrder>    -  The index order to seek
  35.  *       <bBlock>    -  A block to eval to get a return value iff
  36.  *                      required
  37.  *  $RETURNS$
  38.  *       <xRet>      -  If nSeekNum == 1, xRet == found()
  39.  *                   -  If nSeekNum == 2, xRet == found()
  40.  *                   -  If nSeekNum == 3, xRet == ""
  41.  *                   -  If nSeekNum == 4, xRet == eval(bBlock)
  42.  *  $DESCRIPTION$
  43.  *       This function does four separate things dependant on nSeekNum
  44.  *
  45.  *       nSeekNum    What Happens
  46.  *       ────────    ────────────────────────────────────────────────────
  47.  *              1    leave record pointer where found and return found()
  48.  *              2    return record pointer to previous, return found()
  49.  *              3    leave record pointer where found and return ''
  50.  *              4    value = eval(bBlock), go previous rec, return value
  51.  *
  52.  *  $EXAMPLES$
  53.  *        .
  54.  *        .
  55.  *     xLookup := DBFILE->(GT_xSeek("KEYS", 4, 1, {|| DESC_40}))
  56.  *        .
  57.  *        .
  58.  *  $SEEALSO$
  59.  *  $END$
  60.  */
  61.  
  62. #include "gt_LIB.ch"
  63.  
  64. function GT_xSeek(xValue, nSeekNum, nOrder, bBlock)
  65.  
  66.    local nOldOrder
  67.    local xRet
  68.    local nRec
  69.  
  70.    if nOrder == NIL
  71.       nOldOrder := -1
  72.    else
  73.       nOldOrder := indexOrd()
  74.       set order to nOrder
  75.    endif
  76.  
  77.    nRec := recno()
  78.    seek xValue
  79.    xRet := found()
  80.  
  81.    if nSeekNum == 2 .or. nSeekNum == 4
  82.       if valtype(bBlock) == "B"
  83.          xValue = eval(bBlock)
  84.       endif
  85.  
  86.       go nRec
  87.    endif
  88.  
  89.    if nOldOrder != -1
  90.       set order to nOldOrder
  91.    endif
  92.  
  93. return if(nSeekNum == 3, '', if(nSeekNum == 4, xValue, xRet))
  94.