home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / MISC / FNPFEVAL.PRG < prev    next >
Text File  |  1993-02-23  |  3KB  |  103 lines

  1. /*
  2.  * File......: FNPFEVAL.PRG
  3.  * Author....: Glenn Scott
  4.  * CIS ID....: 71620,1521
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  * 
  9.  * This is an original work by Glenn Scott and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19. #include "netto.ch"
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *     FN_PFEVAL()
  24.  *  $CATEGORY$
  25.  *     Miscellaneous
  26.  *  $ONELINER$
  27.  *     Set preferred server and eval block
  28.  *  $SYNTAX$
  29.  *
  30.  *     fn_pfEval( xID, bBlock ) -> xRet
  31.  *
  32.  *  $ARGUMENTS$
  33.  *
  34.  *     <xID> can be numeric, or a character.
  35.  *
  36.  *     If it's numeric, it is the connection ID of the server you want
  37.  *     to set to before evaluating <bBlock>.  This is is position of
  38.  *     the server in the server name table. You can use FN_FSNAME()
  39.  *     to find a connection ID, given a server name.  If the 
  40.  *     connection ID is invalid, the current connection ID is used.
  41.  *
  42.  *     If it's a character, it is the _name_ of the server you want
  43.  *     to set to before evaluating <bBlock>.  If the server name is
  44.  *     invalid or not found, the current server is used.
  45.  *
  46.  *     <bBlock> is a code block to evaluate.
  47.  *
  48.  *  $RETURNS$
  49.  *
  50.  *     <xVal>, whatever is returned from the block when it is 
  51.  *     evaluated.
  52.  *
  53.  *  $DESCRIPTION$
  54.  *     
  55.  *     Some APIs require you to set to a preferred connection ID first
  56.  *     before they can be executed.  This call just simplifies the
  57.  *     process of getting the old ID, setting the new one, doing 
  58.  *     something, then resetting the old ID.
  59.  *
  60.  *     This function records the state of fn_error() after evaluating
  61.  *     the block and makes sure it stays that way before returning.
  62.  *     Therefore, you can't really know whether or not the calls to
  63.  *     change the preferred server back and forth are working or not,
  64.  *     as there is no way to access their return values.
  65.  *     
  66.  *  $EXAMPLES$
  67.  *
  68.  *  $INCLUDE$
  69.  *
  70.  *  $SEEALSO$
  71.  *    
  72.  *  $END$
  73.  */
  74.  
  75. function fn_pfEval( xID, bBlk )
  76.    local nOld, xVal, nErr, nID
  77.  
  78.    default xID to fn_pfconid(), bBlk to { || nil }
  79.  
  80.    do case
  81.      case valtype( xID ) == "C"                      // It's a server name
  82.         nID := ascan( fn_fsname(), upper( xID ) )    // Look it up
  83.         nID := iif( nID == 0, fn_pfconid(), nID )    // Use current if not found
  84.      case valtype( xID ) == "N"
  85.         if xID < 1 .or. xID > 8                      
  86.            nID := fn_pfconid()                       // Use current if invalid
  87.         else
  88.            nID := xID
  89.         endif
  90.   otherwise
  91.      nID := fn_pfconid()
  92.   endcase
  93.  
  94.    nOld := fn_pfconid()         // Save old connection ID
  95.    fn_spfcid( nID )             // Set to new connection ID
  96.    xVal := eval( bBlk )         // Evaluate the block
  97.    nErr := fn_error()           // Store the error code; we'll lose it
  98.    fn_spfcid( nOld )            // Reset the connection ID (and lose error)
  99.    _fnSetErr( nErr )            // Reset the error the way we want it
  100.  
  101.    return xVal                  // Return the result of eval'ing the block
  102.    
  103.