Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Procedure file
Message
From
15/11/2000 13:17:59
 
 
To
15/11/2000 11:01:00
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00441834
Message ID:
00442222
Views:
10
Mike,

Your code for stripping out the tabs and consecutive spaces gave me an idea. The program below will enumerate and display all the PROCEDURES and FUNCTIONS in a program file along with the line number where each occurs. If you pass an array by reference as the second parameter, you'll have the array to work with after the program ends. For what Bob originally wanted, he could then scan the second column of the array for the name he's interested in.
* Program....: GETPROCNAMES.PRG
* Author.....: Rick Borup
* Abstract...: Find and display all the PROCEDURE and FUNCTION names in a file.
* Parameters.: tcFile - the name of the file to scan
*              taArray - the array to hold results (optional)
* Returns....: Nothing
* Notes......: Creates an array of procedure and function names in the
*              specified file, and displays the results on the screen.
LPARAMETERS tcFile, taArray
LOCAL lnFileNbr
lnFileNbr = FOPEN( tcFile)
IF lnFileNbr = -1
   WAIT WINDOW NOWAIT "Can't open file"
   RETURN
ENDIF
IF PCOUNT() = 1
   LOCAL ARRAY taArray[1]  && If no array was passed then use a local one.
ENDIF
LOCAL lnLine, lnCount, lcLine, lnProcNameStart, ;
      lnProcNameEnd, lcLeft4, lnProcNameLen
lnLine = 0
lnCount = 0
DO WHILE !FEOF( lnFileNbr)
   lcLine = FGETS( lnFileNbr)
   lnLine = lnLine + 1
   *   Remove tabs and consecutive spaces (Mike Helland's idea).
   lcLine = STRTRAN( lcLine, CHR(9), SPACE(1))
   DO WHILE SPACE(2) $ lcLine
      lcLine = STRTRAN( lcLine, SPACE(2), SPACE(1))
   ENDDO
   *   If it's a procedure or function name then add it to the array.
   lcLeft4 = UPPER( LEFT( ALLTRIM( lcLine), 4))
   IF lcLeft4 = "PROC" OR lcLeft4 = "FUNC"
      lnProcNameStart = AT( SPACE(1), ALLTRIM( lcLine)) + 1
      lnProcNameEnd = AT( SPACE(1), ALLTRIM( lcLine), 2) - 1
      IF lnProcNameEnd = -1      && no trailing space
         lnProcNameEnd = LEN( ALLTRIM( lcLine))
      ENDIF
      lnProcNameLen = lnProcNameEnd - lnProcNameStart + 1
      lcProcName = SUBSTR( lcLine, lnProcNameStart, lnProcNameLen)
      lnCount = lnCount + 1
      DIMENSION taArray[ lnCount, 3]
      taArray[ lnCount, 1] = IIF( lcLeft4 = "PROC", "PROCEDURE", "FUNCTION")
      taArray[ lnCount, 2] = lcProcName
      taArray[ lnCount, 3] = lnLine
   ENDIF
ENDDO
FCLOSE( lnFileNbr)
CLEAR
FOR lni = 1 TO ALEN( taArray, 1)
   ? taArray[lni, 1] + " " + taArray[lni, 2] + ;
      " occurs at line " + TRANS( taArray[lni, 3])
ENDFOR

RETURN
IF THIS.Useful()
THIS.Enjoy()
ELSE
THIS.Ignore()
ENDIF
Rick Borup, MCSD

recursion (rE-kur'-shun) n.
  see recursion.
Previous
Reply
Map
View

Click here to load this message in the networking platform