* 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 RETURNIF THIS.Useful()