Search for Text String in a file

Discussion in 'AutoCAD' started by Don Butler, Jun 16, 2004.

  1. Don Butler

    Don Butler Guest

    I have written a Lisp Reactor that keeps track of what Lisp Commands have
    been utilized by our users over a month or two.

    Each Lisp Event command description is written to a TXT file as it is being
    called.

    Upon exiting AutoCAD, another Reactor formats, sorts and removes
    redundancies in the TXT file.

    The resultant TXT file is in the following syntax...

    C:ABVPLATE
    C:ABVPLY
    C:AR
    C:BC
    C:BCC
    C:BI
    C:BLOCKLIST
    C:BREAK24
    C:C2
    C:CAN5
    C:CC
    C:CFC
    C:CHAM
    C:CN
    ....

    What I want to do now is to write a routine to search a folder of LSP Files
    for the function definitions and then write another TXT file with the
    function name followed by the source file name.

    Can I search for a text string using a search or find function (VLISP of
    DOSLIB) or do I need to open and read each file line by line?

    I'm hoping a search or find function will be not be case sensitive.

    If this can be done, I will streamline the available routines to just what
    is being utilized.

    Don
     
    Don Butler, Jun 16, 2004
    #1
  2. Don Butler

    Don Butler Guest

    Matt:

    Thanks, not very good with Basic but I'll give it a go.

    I have many routines that are not being used.

    Others programs have either taken their place or they are outmoded.

    Just doing some house cleaning...

    Don
     
    Don Butler, Jun 16, 2004
    #2
  3. Don Butler

    Matt W Guest

    If you need any help, let me know.


    --
    Matt W

    There are 3 kinds of people:
    Those who can count, and those who can't.

    | Matt:
    |
    | Thanks, not very good with Basic but I'll give it a go.
    |
    | I have many routines that are not being used.
    |
    | Others programs have either taken their place or they are outmoded.
    |
    | Just doing some house cleaning...
    |
    | Don
    |
    |
    | | > The question I have is, "Why are you tracking what commands are being
    | used?"
    | > Why not just scour any custom menus and/or tool palettes to find out
    | what's
    | > being used?
    | >
    | >
    | > Anywho... you're in luck (sort of).
    | > I have a VBA app that will search a directory of LSPs and create an HTML
    | > file with the name of the program as a hyperlink and then underneath
    that,
    | > it lists every defun in the program.
    | >
    | > Just take the contents of the TXT file and paste it into a new VBA app
    and
    | > run the Test sub, but BEFORE YOU DO THAT... check out the lines that I
    | have
    | > added comments to about file directories and a name for the HTML file.
    | >
    | > Enjoy!
    | >
    | >
    | > --
    | > Matt W
    | >
    | > There are 3 kinds of people:
    | > Those who can count, and those who can't.
    | >
    | > | > | I have written a Lisp Reactor that keeps track of what Lisp Commands
    | have
    | > | been utilized by our users over a month or two.
    | > |
    | > | Each Lisp Event command description is written to a TXT file as it is
    | > being
    | > | called.
    | > |
    | > | Upon exiting AutoCAD, another Reactor formats, sorts and removes
    | > | redundancies in the TXT file.
    | > |
    | > | The resultant TXT file is in the following syntax...
    | > |
    | > | C:ABVPLATE
    | > | C:ABVPLY
    | > | C:AR
    | > | C:BC
    | > | C:BCC
    | > | C:BI
    | > | C:BLOCKLIST
    | > | C:BREAK24
    | > | C:C2
    | > | C:CAN5
    | > | C:CC
    | > | C:CFC
    | > | C:CHAM
    | > | C:CN
    | > | ...
    | > |
    | > | What I want to do now is to write a routine to search a folder of LSP
    | > Files
    | > | for the function definitions and then write another TXT file with the
    | > | function name followed by the source file name.
    | > |
    | > | Can I search for a text string using a search or find function (VLISP
    of
    | > | DOSLIB) or do I need to open and read each file line by line?
    | > |
    | > | I'm hoping a search or find function will be not be case sensitive.
    | > |
    | > | If this can be done, I will streamline the available routines to just
    | what
    | > | is being utilized.
    | > |
    | > | Don
    | > |
    | > |
    | >
    | >
    | >
    |
    |
     
    Matt W, Jun 16, 2004
    #3
  4. Don Butler

    coachball8 Guest

    Don, is there any chance I could get a look at that lisp reactor code? I'd like to do a little cleanup of our files, but the company is so large that it's impossible to check every user. TIA
     
    coachball8, Jun 16, 2004
    #4
  5. Don Butler

    Don Butler Guest

    Sure...

    ;;;Set Reactor
    ;******************************************************
    (vlr-set-notification (vlr-lisp-reactor nil '(:)vlr-lispwillstart .
    lispwillstart))) 'active-document-only)
    ;******************************************************

    ;;;Track LISP usage
    (defun lispWillStart (a b / file)
    (setq file (open "F:\\_BPCTools\\Programs\\Programs.txt" "a"))
    (write-line (car b) file)
    (close file)
    )

    Don



    like to do a little cleanup of our files, but the company is so large that
    it's impossible to check every user. TIA
     
    Don Butler, Jun 16, 2004
    #5
  6. Don Butler

    coachball8 Guest

    Thanks Don. That should help out a bunch.
     
    coachball8, Jun 16, 2004
    #6
  7. Don Butler

    RichardG Guest

    Don
    what is the correct usage for this reactor. I have been looking to do some
    cleanup here as well as well as track lisp useage. Is there more to your
    function that what is shown? What are "a" and "b" and how are they set.
    Thanks for any info
    Richard
     
    RichardG, Jun 16, 2004
    #7
  8. Don Butler

    Don Butler Guest

    There are guys here that are very well versed in Reactors. I'm just a
    newbie.

    Check this out...
    http://www.afralisp.com/vl/reactors1.htm
    And...
    http://www.dsxcad.com/book/The Visual LISP Developers Bible.pdf


    When the Reactor fires (a Lisp command has been called), it calls my Lisp
    routine first.
    My Lisp routine MUST have 2 arguments, [i.e. (defun lispWillStart (a b /
    file)]
    Say you have a Lisp rountine that is called by entering ZZZ at the command
    line.
    If you examine a and b after calling the ZZZ command you would find...

    a = #<VLR-Lisp-Reactor>
    b = ("(C:ZZZ)")

    You can put the stuff I posted in your Acad.doc file. Substitute a path to
    an EXISTING text file.
    ===============================================================
    (vlr-set-notification (vlr-lisp-reactor nil '(:)vlr-lispwillstart .
    lispwillstart))) 'active-document-only)
    (defun lispWillStart (a b / file)
    (setq file (open "F:\\_BPCTools\\Programs\\Programs.txt" "a")) ;PATH and
    File must exist
    (write-line (car b) file)
    (close file)
    )
    ===============================================================
    I use this to format the file...

    [;;;For Info Only, missing some functions]
    (defun C:FormatPrograms (/ fil file lis)
    (setq fil (remove-dups (bpc:read-file
    "C:\\_BPCTools\\Programs\\Programs.txt")))
    (setq fil (mapcar '(lambda (x) (vl-list->string (vl-remove 40 (vl-remove 41
    (vl-string->list x))))) fil)) ;Remove parantheses
    (setq lis '())
    (foreach n fil
    (if (= (cadr (vl-string->list n)) 58)(setq lis (cons n lis))) ;;Only C:
    functions
    )
    (setq lis (acad_strlsort lis))
    (setq file (open "C:\\_BPCTools\\Programs\\Programs.txt" "w"))
    (foreach n lis (write-line n file))
    (close file)
    (princ)
    )

    Don
     
    Don Butler, Jun 17, 2004
    #8
  9. Don Butler

    RichardG Guest

    thanks for the pointers to the other two sites. I browse to Afralisp alot
    and have seen some of the reactor pages. And i appreciate the newbie status
    as i am too. But the line below quotes from the example:

    ......" If you examine a and b after calling the ZZZ command you would
    find..."
    a = #<VLR-Lisp-Reactor>
    b = ("(C:ZZZ)")

    and this is my question how are "a" and "b" set. Does the ZZZ function set
    the value for ..... b=("(C:ZZZ)") as well as "a"
    if so it cant just be a simple setq or can it. Sorry for all the questions
    and thanks for your help
    Richard




     
    RichardG, Jun 17, 2004
    #9
  10. Don Butler

    zeha Guest

    That's what happening insite the function lispWillStart
    the arguments a and b where called from (defun lispWillStart (a b / file)

    Thus a = #<VLR-Lisp-Reactor>
    b = ("(C:ZZZ)") function called

    b (LISP function) is written to the file

    be sure that the name and directory is correct

    I use for the directory most (getvar "dwgperfix") the current directory

    This is modified to write only LISP functions if they not exist

    ;;;Set Reactor
    ;******************************************************
    (vlr-set-notification (vlr-lisp-reactor nil '(:)vlr-lispwillstart .
    lispwillstart))) 'active-document-only)
    ;**************************************************** **

    ;;;Track LISP usage
    (defun lispWillStart (a b / linexist filename file)
    (setq linexist nil filename (strcat (getvar"dwgprefix")"Programs.txt"))
    (if (setq file (open filename "r"))
    (progn
    (while (setq rl (read-line file))
    (if (= rl (car b))(setq linexist T))
    )
    (close file)
    (if (not linexist)
    (progn
    (setq file (open filename "a"))
    (write-line (car b) file)
    (close file)
    )
    )
    )
    )
    )
     
    zeha, Jun 17, 2004
    #10
  11. Don Butler

    Don Butler Guest

    Actually, I want the location of Programs.txt file to be static.

    The modification [(getvar"dwgprefix")] will point to whatever folder the
    drawing is in, so is inconsistent.

    To answer Richard, the VisualLisp Reactor automatically reports two items so
    functions must have 2 arguments...

    Search AutoLisp help for "vlr-lisp-reactor".

    Don
     
    Don Butler, Jun 17, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.