Author Topic: detecting command...  (Read 2451 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
detecting command...
« on: January 23, 2007, 11:00:31 AM »
Hi all,...

With some client we don't have choice to use some lisp files...
but all file refered each other..

exemple..
if i use (command_name1) or c:command_name
I can't know where this command come from...
I have to many lisp file to check.

So the question is.
how can i retreive the filename LSP for each command ?

need to have something like..

(command_name1) = file1.lsp
c:command_name = file2.lsp
(command_name2) = file1.lsp

any quick suggestion ?

or need to create another lisp to look at each lsp file ?
Keep smile...

Guest

  • Guest
Re: detecting command...
« Reply #1 on: January 23, 2007, 11:05:29 AM »
I have a DVB file that will search a particular folder for LSPs and then search each LSP for a "DEFUN" statement.  It spits the results to an HTML page like the one below.

If you're interested, I can post the code.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: detecting command...
« Reply #2 on: January 23, 2007, 11:48:00 AM »
if i'm interested !!?...

Sure !...
you can send me the file...

thank you.   8-)
Keep smile...

Guest

  • Guest
Re: detecting command...
« Reply #3 on: January 23, 2007, 11:59:58 AM »
Here's the code.
Note the two paths you will need to change.

Quote
Option Explicit

Public colFiles As Collection
Public lCompareMethod As Long        'Compare methode for Instr$
Public strTempFile As String         'Full path to temp file - changes are written to temp file.
Public szLineIn As String            'Line inputed from file we're searching.
Public strLineOut As String          'Line with changes in it, to be written to temp file.
Public iReplacePos As Integer        'Position of found search string.
Public flNumFiles, flNumStrings, flNumTotFiles As Long
Public Const strDefunFileName = "E:\Temp\Defuns.html" '<==Change this to your desired location for the HTML file.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Public Sub Test()
    Dim i As Integer
   
    Set colFiles = New Collection
    FindFile colFiles, "S:\CADDSTDS\MENUS", "LSP" '<==Change the file path location to where you keep your LSPs.

Code: [Select]
Option Explicit

Public colFiles As Collection
Public lCompareMethod As Long        'Compare methode for Instr$
Public strTempFile As String         'Full path to temp file - changes are written to temp file.
Public szLineIn As String            'Line inputed from file we're searching.
Public strLineOut As String          'Line with changes in it, to be written to temp file.
Public iReplacePos As Integer        'Position of found search string.
Public flNumFiles, flNumStrings, flNumTotFiles As Long
Public Const strDefunFileName = "E:\Temp\Defuns.html" '<==Change this to your desired location for the HTML file.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Public Sub Test()
    Dim i As Integer
   
    Set colFiles = New Collection
    FindFile colFiles, "S:\CADDSTDS\MENUS", "LSP" '<==Change the file path location to where you keep your LSPs.
    For i = 1 To colFiles.Count
        SearchAndReplace (colFiles.Item(i))
    Next i
   
    ShellExecute 0, "Open", strDefunFileName, 0, 0, 3
    MsgBox "Done!"
End Sub

Private Sub Backup(ByVal FileName As String)
    Dim FS As New FileSystemObject
    Call FS.CopyFile(FileName, FS.GetTempName)
   
    FS.GetTempName
End Sub

Private Function ReadTextFile(ByVal FileName As String) As String
    Dim FS As New FileSystemObject
    Dim Stream As TextStream

    Call Backup(FileName)
    Set Stream = FS.OpenTextFile(FileName, ForReading, False)
    ReadTextFile = Stream.ReadAll()
    Stream.Close
    Set FS = Nothing
End Function

Public Sub FindFile(ByRef files As Collection, doDir$, ext$)
    Dim dirs As Collection
    Set dirs = New Collection
    Dim file$
    If (Right(doDir$, 1) <> "\") Then
        doDir$ = doDir$ & "\"
    End If
    file$ = Dir(doDir$ & "*.*", vbDirectory)
    Do While (file$ <> "")
        If ((file$ <> ".") And (file$ <> "..")) Then
            If ((GetAttr(doDir$ & file$) And vbDirectory) = vbDirectory) Then
'''                dirs.Add doDir$ & file$
            Else
                Dim thisExt$
                If (Len(file$) > 4) Then
                    If (UCase(Right(file$, 3)) = UCase(ext$)) Then
                        files.Add doDir$ & file$
                    End If
                End If
            End If
        End If
        file$ = Dir
    Loop
    If (dirs.Count > 0) Then
        Dim curDir%
        For curDir% = 1 To dirs.Count
            FindFile files, dirs(curDir%), ext$
        Next curDir%
    End If
    Set dirs = Nothing
End Sub

Private Sub SearchAndReplace(szFileName As String)
    Dim x As Integer
    Dim intFile As Integer
    Dim strHeader, strFooter As String
   
    strHeader = "<html>" & vbCrLf & _
                "  <head>" & vbCrLf & _
                "    <title>DEFUN list</title>" & vbCrLf & _
                "  </head>" & vbCrLf
    strFooter = "</html>"
   
    Open szFileName For Input As #1
        intFile = FreeFile
        Open strDefunFileName For Append As #intFile
        Print #intFile, strHeader
        Print #intFile, "<b><a href=""" & szFileName & """>" & szFileName & "</a></b><br>" & vbCrLf
            Do While Not EOF(1)
                Line Input #1, szLineIn
                Do
                    iReplacePos = InStr(iReplacePos + 1, UCase(szLineIn), "DEFUN", vbBinaryCompare)
                    If iReplacePos = 0 Then Exit Do
                    flNumStrings = flNumStrings + 1
                    strLineOut = Left$(szLineIn, Len(szLineIn))
                    strLineOut = LTrim(strLineOut)
                    strLineOut = Mid$(strLineOut, 8)
                    x = InStr(x + 1, strLineOut, "(", lCompareMethod)
                    If x = 0 Then Exit Do
                    strLineOut = Mid$(strLineOut, 1, (x - 1))
                    strLineOut = RTrim$(strLineOut)
                    szLineIn = strLineOut
                    Print #intFile, strLineOut & "<br>" & vbCrLf
                    x = 0
                Loop
            Loop
        Print #intFile, strFooter
        Close #1
    Close #2
End Sub

Andrea

  • Water Moccasin
  • Posts: 2372
Re: detecting command...
« Reply #4 on: January 23, 2007, 12:30:48 PM »
Hey !!  gracias amigo !

 :-)
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: detecting command...
« Reply #5 on: January 23, 2007, 01:34:01 PM »
i've just wrote this..

Code: [Select]
(defun c:checklisp (/ folder lisplist g1 lisplist f1 l1 l1m def com)
  (setq folder (acet-ui-pickdir "Select your Folder" "c:\\" "CheckLISP"))
(if folder
  (progn
  (setq lisplist (vl-directory-files folder "*.lsp"))
  (setq g1 (open "c:\\RESULTLISP.TXT" "w"))
  (write-line folder g1)
 ;; (setq l1 "(defun c: ()")
  (foreach n lisplist
    (write-line (strcat "  " n) g1)
    (setq f1 (open (strcat folder "\\" n) "r"))
    (setq l1 (read-line f1))
    (while l1
      (if (setq def (vl-string-search "defun " l1))
  (progn
    (setq l1m (substr l1 (+ def 7)))
            (setq def (vl-string-search "(" l1m))
            (setq com (substr l1m 1 def))
    (write-line (strcat "     " com) g1)
    ))
      (setq l1 (read-line f1))
     )
    );;foreach
  (close g1)
  );;progn
 );;if
);;defun

not very elegant...but it work.
just sharing with all...
Keep smile...

GDF

  • Water Moccasin
  • Posts: 2081
Re: detecting command...
« Reply #6 on: January 23, 2007, 03:20:56 PM »
Andrea

I like it...thanks for sharing.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Cavediver

  • Guest
Re: detecting command...
« Reply #7 on: January 23, 2007, 04:31:27 PM »
Okay, sorry to interrupt... quick learning moment
What does that last set of code do?  Is it supposed to work with the piece that Matt posted, or does it stand alone?  I tried loading it by itself, but I get a "nil" retun at the command line after I select a directory.

Guest

  • Guest
Re: detecting command...
« Reply #8 on: January 23, 2007, 04:36:42 PM »
It's a stand-alone program.

I get a nil too, but it writes everything to the RESULTLISP.TXT file.  The nil is probably because there isn't a (princ) before the last ).

Cavediver

  • Guest
Re: detecting command...
« Reply #9 on: January 23, 2007, 04:57:08 PM »
Ah ha!  Gotcha.  I was not looking in the right place for the list, and I had no idea that you needed that command at the end.  Thanks!

Adesu

  • Guest
Re: detecting command...
« Reply #10 on: January 23, 2007, 07:15:14 PM »
Hi Andrea,
of course you would got trouble because file name between command code ,very different syntax,but you can look my system
File name                            code lisp
0512-Open Xref Drawing.lsp    oxd
I took code for lisp from capital string of file name
"0512-Open Xref Drawing.lsp" and then I extract it ,only capital string.   


Hi all,...

With some client we don't have choice to use some lisp files...
but all file refered each other..

exemple..
if i use (command_name1) or c:command_name
I can't know where this command come from...
I have to many lisp file to check.

So the question is.
how can i retreive the filename LSP for each command ?

need to have something like..

(command_name1) = file1.lsp
c:command_name = file2.lsp
(command_name2) = file1.lsp

any quick suggestion ?

or need to create another lisp to look at each lsp file ?