home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / LINKED.PRG < prev    next >
Text File  |  1991-08-16  |  5KB  |  144 lines

  1. /*
  2.  * File......: Linked.PRG
  3.  * Author....: Brian Loesgen
  4.  * CIS ID....: 74326,1174
  5.  * Date......: $Date:   15 Aug 1991 23:05:52  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/linked.prv  $
  8.  * 
  9.  * This is an original work by Brian Loesgen and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/linked.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:05:52   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 19:52:08   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.0   13 Jun 1991 15:21:26   GLENN
  24.  * Initial revision.
  25.  *
  26.  */
  27.  
  28.  
  29. /*  $DOC$
  30.  *  $FUNCNAME$
  31.  *     FT_LINKED()
  32.  *  $CATEGORY$
  33.  *     Environment
  34.  *  $ONELINER$
  35.  *     Determine if a function was linked in
  36.  *  $SYNTAX$
  37.  *     FT_LINKED( <cString> ) -> lResult
  38.  *  $ARGUMENTS$
  39.  *     <cString> is a character string containing one or more function
  40.  *               calls
  41.  *  $RETURNS$
  42.  *     .T. if all functions within the string are currently linked into
  43.  *     the application, .F. if one or more aren't.  See below for a 
  44.  *     definition of "function."
  45.  *  $DESCRIPTION$
  46.  *
  47.  *     This function would be used in data driven application to determine
  48.  *     whether or not a macro compiled function was linked in.
  49.  *
  50.  *     Several functions can be passed, and nested, in <cString>.
  51.  *
  52.  *     Caveat: Some function calls are converted by the preprocessor
  53.  *     into other function calls. You cannot have these types of
  54.  *     functions in a macro compiled string as they never exist at
  55.  *     runtime. FT_LINKED will correctly tell you that they are invalid.
  56.  *
  57.  *     For instance: there is no function called SORT() in any of the
  58.  *     Nantucket LIBraries, but it is a valid CLIPPER command because the
  59.  *     preprocessor will convert it to other function calls.
  60.  *
  61.  *
  62.  *  $EXAMPLES$
  63.  *
  64.  *     cString := "FT_GoodFunc(BadFunc(3,2))"
  65.  *     IF FT_LINKED(cString)
  66.  *        EVAL( &("{||"+cString+"}") )
  67.  *     ELSE
  68.  *        ALERT("Error: "+cString+" was not linked in. Called by FT_LINKED()")
  69.  *     ENDIF
  70.  *
  71.  *
  72.  *  $END$
  73.  */
  74.  
  75.  
  76. #ifdef FT_TEST
  77.  
  78.   FUNCTION Main
  79.   LOCAL cString
  80.   LOCAL aString := { "TRIM('abc ')",                                     ;
  81.                      "NotARealFunc()",                                   ;
  82.                      "FT_DispMsg()",                                     ;
  83.                      'TRIM(cVar+"abc"+LEFT(cString)), FOUND()',          ;
  84.                      "IsItLinked()",                                     ;
  85.                      "lRetVal := FOUND()",                               ;
  86.                      "!EOF() .AND. MONTH(DATE())=12 .AND. YeeHa()",      ;
  87.                      "!EOF() .AND. MONTH(DATE())=12",                    ;
  88.                      "!EOF() .AND. MONTH(DATE(YeeHa()))=12",             ;
  89.                      "LEFT(SUBSTR(nNum,4,VAL(cChar+ASC(c))))",           ;
  90.                      "EOF(>> Note: Syntax IS NOT checked! <<)"           ;
  91.                    }
  92.   CLS
  93.   @1,0 SAY "String Tested                               Result"
  94.   @2,0 TO 2,MAXCOL()
  95.   AEVAL(aString, {|ele,num| QOUT(ele, SPACE(45-LEN(ele)), FT_Linked(ele)) } )
  96.   @MAXROW()-2,0
  97.   RETURN NIL
  98.  
  99. #endif
  100.  
  101. *------------------------------------------------
  102.  
  103.  
  104. FUNCTION FT_Linked( cFuncs )
  105.  
  106. // A function is detected by the left parenthesis, "(", and it begins
  107. // at the space, comma or start-of-string preceeding the "("
  108.  
  109. // Returns: .T. if all functions are available,
  110. //          .F. if not
  111.  
  112. LOCAL aFuncArray := {}, nSpace, nComma, nFEnd, lRetVal := .F.
  113.  
  114. IF AT("(",cFuncs) = 0
  115.    // No functions in string
  116.    ALERT("Warning: Expected function(s) in FT_Linked(), but none were found")
  117. ELSE
  118.    DO WHILE (nFEnd := AT("(",cFuncs)) > 0
  119.       // Add the current function to the array of functions
  120.       AADD( aFuncArray,LEFT(cFuncs,nFEnd)+")" )
  121.       // Remove the current function from the string
  122.       cFuncs := SUBSTR(cFuncs, nFEnd+1)
  123.       nSpace := AT(" ",cFuncs) ; nComma := AT(",",cFuncs)
  124.       DO WHILE  (nComma > 0 .and. nComma < nFEnd) .or. ;
  125.             (nSpace > 0 .and. nSpace < nFEnd)
  126.          // We have extra parameters or spaces prior to the start
  127.          // of the function. Strip them out.
  128.          if nComma > 0
  129.             cFuncs := SUBSTR(cFuncs, nComma+1)
  130.          elseif nSpace > 0
  131.             cFuncs := SUBSTR(cFuncs, nSpace+1)
  132.          endif
  133.          nSpace := AT(" ", cFuncs) ; nComma := AT(",", cFuncs)
  134.       ENDDO
  135.    ENDDO
  136.    // Scan through the array of functions, stop after the first occurence
  137.    // of a function which returns a TYPE() of "U" (hence is not linked in)
  138.    lRetVal := ASCAN(aFuncArray,{|element| TYPE(element)=="U"})=0
  139. ENDIF
  140. RETURN( lRetVal )
  141.  
  142.  
  143.  
  144.