Loading ...
Sorry, an error occurred while loading the content.
 

diddle the middle clip

Expand Messages
  • Bucky
    I wrote this to help remove banner ads from saved web pages. I also used this to extract filenames from inside javascript. Most useful When editing a large
    Message 1 of 1 , Feb 27, 2001
      I wrote this to help remove banner ads from saved
      web pages. I also used this to extract filenames from
      inside javascript. Most useful When editing a large
      number of pages at once. If you can pick a unique
      starting and ending point for a search then this will
      grab everything in the middle. Works great when
      when pages contain unique javascript comments
      before and after the text you want.

      This is only my second clip in 3 years so bugs are
      possible.

      2 lines are really long and need to be rejoined.

      There's lots of comments; should be helpful for
      beginners. If you make enhancements please share
      them with the list.



      H="Diddle The Middle"

      ; This Clip will select all the text between
      ; the "StartText" and the "EndText".
      ; Selected text can be deleted or pasted
      ; into a new document.
      ;
      ^!If ^$GetValue(diddleintro)$ = 1 SKIPINTRO
      ; show intro only once
      ^!SaveValue diddleintro=1
      ; next line is 143 chars wide
      ^!Info This Clip Finds the Unknown Text located between
      a know start and end point. Middle data can be deleted or
      extracted to a new document.

      :SKIPINTRO
      ^!FocusDoc
      ^!ClearVariable %NewDocIndex%
      ^!Set %BeforePostion%=^$GetRow$:^$GetCol$
      ^!Set %BeforeDocIndex%=^$GetDocIndex$

      :Prompt
      ; prompt for needed items
      ^!SetWizardTitle "Diddle The Middle v0.9"
      ; next line is 276 chars long
      ^!Set %StartText%=^?{Enter Text that Prefixes Wanted
      Selection=^%StartText%}; %EndText%=^?{Enter Text
      that Suffixes Wanted Selection=^%EndText%}; %Action
      %=^?{What to do with Found Selection(s)=Delete
      Selection|_Append To New Document}; %ALL
      DOCS%=^?{(T=A)Scope=All Documents|}
      ^!IfCancel TheEnd
      ^!SetWizardTitle ""
      ; if start or end text is empty then prompt again
      ^!IfTrue ^$IsEmpty(^%StartText%)$ ^!Goto Prompt
      ^!IfTrue ^$IsEmpty(^%EndText%)$ ^!Goto Prompt
      ; make it search top down
      ^!SetCursor 1:1
      ; if ALLDOCS is All Documents then start at doc 1
      ^!IF ^%ALLDOCS% = "All Documents" SetDocument ELSE FindPrefix

      :SetDocument
      ^!SetDocIndex 1
      ^!Set %VARINDEX%=1
      ^!SetCursor 1:1
      ^!Goto FindPrefix

      :NextDocument
      ; if not doing ALLDOCS then end
      ^!IfFalse ^%ALLDOCS% TheEnd
      ; when we get to the New Document end
      ^!If ^$GetDocIndex$ = ^%NewDocIndex% TheEnd ELSE IncDoc

      :IncDoc
      ^!Inc VARINDEX
      ^!SetDocIndex ^%VARINDEX%
      ^!SetCursor 1:1
      ^!Goto FindPrefix

      :FindPrefix
      ; [T: Substrings | C: Whole words ]
      ; I: Ignores character case.
      ; R: Regular expression.
      ; S: Silent search.
      ^!Find ^%StartText% TIS
      ; check for next document if nothing found
      ^!IfError NextDocument
      ; rem next. find leaves cursor at start of selection
      ;^!Info found prefix=^$GetRow$:^$GetCol$
      ; move to the end of found text
      ^!Jump SELECT_END
      ; save this as starting position
      ^!Set %StartPostion%=^$GetRow$:^$GetCol$
      ; rem next.
      ;^!Info StartPostion=^%StartPostion%
      ; now look for Suffix
      ^!Goto FindSuffix

      :FindSuffix
      ^!Find ^%EndText% TIS
      ; if nothing found then look for another Prefix
      ^!IfError FindPrefix
      ; rem next. find leaves cursor at start of selection
      ;^!Info found suffix=^$GetRow$:^$GetCol$
      ; save this position to restart find
      ^!Set %SavePostion%=^$GetRow$:^$GetCol$
      ; move to the beginning of found text
      ^!Jump Select_Start
      ; save this as Ending position
      ^!Set %EndPostion%=^$GetRow$:^$GetCol$
      ; rem next.
      ;^!Info Selection ^%StartPostion% to ^%EndPostion%
      ; now make selection
      ; Move the cursor back to the start position
      ^!SetCursor ^%StartPostion%
      ; Extend the selection to the end position
      ^!SelectTo ^%EndPostion%
      ; rem next.
      ;^!Info ^$GetSelection$
      ; Save document index
      ^!Set %SaveDocIndex%=^$GetDocIndex$
      ; branch to DeleteSelection or AppendSelection
      ^!IF ^%Action% = "Delete Selection" DeleteSelection ELSE AppendSelection


      :DeleteSelection
      ^!TOOLBAR Cut
      ; put cursor back - test this
      ^!SetCursor ^%SavePostion%
      ^!Goto FindPrefix

      :AppendSelection
      ; open only one new document
      ^!IfFalse ^%NewDocIndex% OpenNewDoc
      ; copy selection
      ^!TOOLBAR Copy
      ; switch to new doc
      ^!SetDocIndex ^%NewDocIndex%
      ; paste selection
      ^!TOOLBAR Paste
      ; hard coded separater.
      ^%NL%
      ; return to document
      ^!SetDocIndex ^%SaveDocIndex%
      ; put cursor back
      ^!SetCursor ^%SavePostion%
      ; rem next. break out of a run away loop
      ;^!Continue [Find Next]
      ; go look for more
      ^!Goto FindPrefix

      :OpenNewDoc
      ; ren next.
      ;^!Info Opening NewDoc
      ^!TOOLBAR New Document
      ; Save NEW document index
      ^!Set %NewDocIndex%=^$GetDocIndex$
      ; too bad i couldn't open the new
      ; document without it coming into
      ; focus
      ^!SetDocIndex ^%SaveDocIndex%
      ^!Goto AppendSelection


      :TheEnd
      ; restore document and cursor
      ^!SetDocIndex ^%BeforeDocIndex%
      ^!SetCursor ^%BeforePostion%
      ^!Goto End
    Your message has been successfully submitted and would be delivered to recipients shortly.