WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

LineHider


Hide/restore all or a range of lines in a script in WinBatch Studio. Useful when working on long scripts.

v2.1 Easy selection for line hiding/restoring.

;*****************************************************************************************
; Program Title:          LineHider v2.1                                                 *
;                                                                                        *
; Author:                 Steffen Fraas, sfraas@zoo.co.uk                                *
;                                                                                        *
; Date:                   April 5 2005                                                   *
;                                                                                        *
; Synopsis:               Hide/restore all or a range of lines in a script in WinBatch   *
;                         Studio. Useful when working on long scripts.                   *
;                                                                                        *
;                                                                                        *
; CALLed routines/modules: LineHider.wbt                                                 *
;                                                                                        *
; Input/Output files:                                                                    *
;                                                                                        *
; Documentation File:                                                                    *
;                                                                                        *
; Requirements:           Minimum: Winbatch v2001a                                       *
;                                                                                        *
; Installation:           Save this file in ...\WinBatch\system\ directory               *
;                                                                                        *
;                         Add next two lines into wsp-user.mnu                           *
;                                                                                        *
;            LineHider                   \ {F6}               ; must start in column 1   *
;                Call(StrCat(Dirhome(),"Linehider.wbt"),"")   ; must start in column 5   *
;                                                                                        *
; Restrictions:                                                                          *
;                                                                                        *
;     A tag, representing hidden lines, must not be altered or moved from start column 1.*
;                                                                                        *
;     Current version of LineHider assumes the default Winbatch Studio line terminator   *
;     is in use - CrLf.                                                                  *
;                                                                                        *
;     The number of lines that can be `hidden` in one operation is restricted to         *
;     5,000,000 bytes at any one time. Change variable 'currlimit' if required.          *
;     The clipboard of older version of Windows only supports a maximum of 64K.          *
;                                                                                        *
; Operation:                                                                             *
;                                                                                        *
;                         After initiating a hide or restore operation,                  *
;                         always wait for the lines saved/restored or other              *
;                         message before touching the keyboard again.                    *
;                                                                                        *
;                                                                                        *
;                                                                                        *
;       It is assumed, in the following examples, that the function key F6 has           *
;       been assigned to the LineHider utility.                                          *
;                                                                                        *
;*NEW*  To hide line/s:                                                                  *
;         Partially or fully select one or more consecutive lines                        *
;         and press F6. The partially/selected lines will be replaced                    *
;         by a LineHider tag.                                                            *
;                                                                                        *
;         Example of quickly removing a few lines from middle of screen:                 *
;             With the cursor somewhere in the middle of the screen just                 *
;             drag it down in a straight line for a few lines and press                  *
;             F6. All the fully highlighted as well as the partially                     *
;             highlighted lines will be removed.                                         *                       *
;                                                                                        *
;*NEW*  To return hidden lines represented by one tag:                                   *
;         Highlight or partially highlight the LineHider tag - just                      *
;         highlighting a single character is enough - press F6 and                       *
;         accept prompt.                                                                 *
;                                                                                        *
;       To display all hidden lines:                                                     *
;         Press F6 and select the 'List all hidden lines' option.                        *
;                                                                                        *
;       To restore all hidden lines:                                                     *
;         Press F6 and select the 'Restore all hidden lines' option.                     *
;                                                                                        *
;       To remove all tags:                                                              *
;         Press F6 and select the 'Remove all tags' option. After the selection has been *
;         confirmed, all tags will be removed and the checkpoint file will be deleted.   *
;                                                                                        *
;       Re-display:                                                                      *
;                                                                                        *
;         The re-display of a display message can be initiated by pressing and holding   *
;         down the shift or control key during the display.                              *
;                                                                                        *
;       Quick 'all lines restored?' check:                                               *
;         Press F6, and hit ENTER or select 'List hidden lines'. A message will display  *
;         the number of tags found.                                                      *
;                                                                                        *
;                                                                                        *
;    Operational considerations:                                                         *
;                                                                                        *
;       Whenever LineHider is invoked, it will allocate a checkpoint file if none is     *
;       found. The checkpoint file will always be in the same directory as the current   *
;       open file. LineHider also uses a backup checkpoint file.                         *
;                                                                                        *
;    Example:                                                                            *
;                                                                                        *
;        current file name           - test.wbt                                          *
;        checkpoint file name        - test.wbt.ext.lhf                                  *
;        backup checkpoint file name - test.wbt.ext.lhf.backup                           *
;                                                                                        *
;                                                                                        *
;    When hiding/restoring lines the following actions are taken:                        *
;                                                                                        *
;                                                                                        *
;      hiding:                                                                           *
;                                                                                        *
;          copy line/lines                                                               *
;          replace line/lines with tag                                                   *
;          delete backup checkpoint file                                                 *
;          rename checkpoint file as backup checkpoint file                              *
;          update checkpoint file by adding tag and hidden lines                         *
;          save current file                                                             *
;                                                                                        *
;                                                                                        *
;      restoring:                                                                        *
;                                                                                        *
;          replace tag with hidden lines                                                 *
;          save current file                                                             *
;          delete backup checkpoint file                                                 *
;          rename checkpoint file as backup checkpoint file                              *
;          update checkpoint file by deleting tag and hidden lines                       *
;                                                                                        *
;                                                                                        *
;      recovery procedure:                                                               *
;                                                                                        *
;          rename checkpoint file as fred.txt (keep for investigatory purposes)          *
;          rename backup checkpoint file as checkpoint file                              *
;          open affected file in Winbatch Studio                                         *
;          press F6 and select 'Restore all lines'                                       *
;                                                                                        *
;                                                                                        *
;    Note:                                                                               *
;                                                                                        *
;          A zero-length checkpoint file indicates that all hidden lines have been       *
;          restored.                                                                     *
;                                                                                        *
;                                                                                        *
;    Additional notes:                                                                   *
;                                                                                        *
;         When highlighting more than one line, and this includes a LineHider tag, a new *
;         tag will be generated.                                                         *
;                                                                                        *
;         Always ensure there is enough disk space for both checkpoint files. 2 x the    *
;         size of the current open file, plus one k, should ensure trouble-free          *
;         operation.                                                                     *
;                                                                                        *
;         Adopt the habit of pressing F6 and select 'Restore all hidden lines'  just     *
;         before leaving Winbatch Studio.                                                *
;                                                                                        *
;         During lengthy 'Restore all lines' operations, it is advisable to refrain from *
;         using the keyboard!                                                            *
;                                                                                        *
;         Exited Winbatch Studio without restoring hidden lines? No problem.             *
;         Provided the checkpoint file and the tags in the edited file are still         *
;         available then do the following:                                               *
;                                                                                        *
;         a) open the file in Winbatch Studio                                            *
;         b) press F6                                                                    *
;         c) select 'Restore all hidden liness'                                          *
;                                                                                        *
;         The result of deleting or overlaying a file which contains tags, - all         *
;         intentionally of course - is an out-of-step checkpoint file. If the data it    *
;         contains is no longer required, even for a manual recovery, then it is best    *
;         to delete it. The next LineHider request will then start with a newly-allocated*
;         checkpoint file.                                                               *
;                                                                                        *
;         Why the `flashing` screen when restoring all lines?                            *
;           In order to find a tag, LineHider has first to select all lines via the      *
;           wSelectAll() command. Once a tag is found it is replaced with the hidden     *
;           lines represented by this tag. This process is repeated until no more tags   *
;           are found.                                                                   *
;                                                                                        *
;                                                                                        *
;                                                                                        *
;                                                                                        *
;*****************************************************************************************
;*****************************************************************************************
;                                                                                        *
;  This script has been formatted and syntaxchecked by SyntaxChecker v2005Ca             *
;                                                                                        *
;  For more information, please contact the author via e-mail, subject 'SyntaxChecker'.  *
;                                                                                        *
;*****************************************************************************************
;*****************************************************************************************

         vers="LineHider v2.1  "
         If (!RtStatus()==10 || RtStatus()) && wGetFileName()=="" Then Exit
         If wGetFileName()=="" Then Exit
         If !ItemLocate("lhf_tag_found",Intcontrol(77,103,0,0,0),@Tab) Then GoSub PRELOAD ; Pre-load UDFs once only per session. ; Line 348
         Intcontrol(72,2,0,0,0)
         cancel=0
         currlimit=5000000                                 ; Maximum number of bytes to be processed for a 'hide lines' operation.
         fill="******************"
         saveclip=""
         savedclip=0
         z=3
         If ClipHasFormat(1) Then saveclip=ClipGet()
           Then savedclip=1
         time=StrReplace(StrCat(StrSub(TimeYMDHMS(),1,11),GetExactTime()),":","-")
         file=StrCat(FilePath(wGetFileName()), StrSub(wGetFileName(),StrScan(wGetFileName(),"\",StrLen(wGetFileName()),@Backscan)+1,-1),".ext.lhf")
         If FileExist(file)==2
            Message(StrCat(vers," - ",file),StrCat(file,@CrLf,"is currently used by another application.",@CrLf,"Aborting"))
          Else
            curwin=StrSub(WinGetActive(),1,StrLen(WinGetActive())-3)
            If FileExist(file)==0 Then FileClose(FileOpen(file,"Write"))
            If wGetSelState()
               list = wSelInfo()                           ; Returns a tab-delimited list of the block bounds.
               b1 = ItemExtract( 1, list, @Tab)
               b3 = ItemExtract( 3, list, @Tab)
               b4 = ItemExtract( 4, list, @Tab)
               wClearSel()
               wGotoLine(b1)
               wGotoCol(1)
               wStartSel()
               If b3>b1&&b4==1 Then b3=b3-1
               wGotoLine(b3)
               wGotoCol(1)
               wEnd()
               wEndSel()
               wCopy()
               nl=ClipGet()
               If StrLen(nl)>currlimit
                  wClearSel()
                  Message(vers,StrCat("Data selected, (",StrLen(nl),") bytes, is greater than user-selected limit of ",currlimit))
                Else
                  If StrSub(nl,1,4)==StrCat(";$","$£") && StrSub(nl,27,44)==StrCat("$","£€    ****************** Line/s suppressed ") && ItemCount(nl,"-")==7 && StrSub(nl,92,24)=="bytes ******************" && StrLen(StrReplace(nl,@CrLf,""))==115
                     nl2=lhf_Tag_Found(file,nl,1)          ; Line 349
                     If nl2==""
                        Message(StrCat(vers," - ",file),StrCat("Lines for tag ",nl," not found"))
                      Else
                        If !StrScan(nl2,@Cr,1,@Fwdscan) Then nl2x=1
                         Else nl2x=ItemCount(nl2,@Cr)-1
                        Intcontrol(28,1,0,0,0)
                        Intcontrol(63,50,10,950,700)
                        AskItemList(StrCat(vers," - Restore ",nl2x," lines from ",file,"?"),StrReplace(nl2,@CrLf,@Cr),@Cr,@Unsorted,@Single)
                        If cancel
                         Else
                           If StrSub(nl,StrLen(nl)-1,2)<>@CrLf Then If StrSub(nl2,StrLen(nl2)-1,2)==@CrLf Then nl2=StrSub(nl2,1,StrLen(nl2)-2)
                           ClipPut("")
                           ClipAppend(nl2)
                           WinActivate(curwin)
                           wPaste()
                           wFileSave()
                           lhf_Tag_Found(file,nl,3)        ; Line 349
                           z=4
                        EndIf
                     EndIf
                   Else
                     If !StrScan(nl,@Cr,1,@Fwdscan) Then nl2x=1
                      Else nl2x=ItemCount(nl,@Cr)-1
                     If StrScan(nl,@Cr,1,@Fwdscan) && StrSub(nl,StrLen(nl)-1,2)<>@CrLf Then nl2x=nl2x+1
                     If StrSub(nl,StrLen(nl)-1,2)==@CrLf Then ClipPut(StrCat(";$","$£",time,"$","£€","    ****************** Line/s suppressed ",StrFix(nl2x," ",9),", ",StrFix(StrLen(nl)," ",9)," bytes ******************",@CrLf))
                       Then tag=StrCat(";£$","€£",time,"$€","£$",StrFixLeft(StrLen(nl),"0",8),@CrLf,nl)
                      Else ClipPut(StrCat(";$","$£",time,"$","£€","    ****************** Line/s suppressed ",StrFix(nl2x," ",9),", ",StrFix(StrLen(nl)," ",9)," bytes ******************"))
                      Else tag=StrCat(";£$","€£",time,"$€","£$",StrFixLeft(StrLen(nl)+2,"0",8),@CrLf,nl,@CrLf)
                     WinActivate(curwin)
                     wPaste()
                     lhf_Tag_Found(file,tag,2)             ; Line 349
                     wFileSave()
                     z=4
                  EndIf
               EndIf
             Else
               rlinesformat=`WWWDLGED,5.0`
               rlinescaption=`%vers%`
               rlinesx=9999
               rlinesy=9999
               rlineswidth=70
               rlinesheight=70
               rlinesnumcontrols=4
               rlines01=`3,04,62,DEFAULT,PUSHBUTTON,DEFAULT,"&List all hidden lines",1`
               rlines02=`3,20,62,DEFAULT,PUSHBUTTON,DEFAULT,"&Restore all hidden lines",2`
               rlines04=`3,36,62,DEFAULT,PUSHBUTTON,DEFAULT,"R&emove all tags",4`
               rlines03=`3,52,62,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",3`
               rlines=Dialog("rlines")
               If rlines==4 Then If !AskYesNo("Confirmation","OK to remove all tags and delete checkpoint file?") Then cancel=1
               If cancel || rlines==3
                Else
                  If rlines==1
                     z=-1
                   Else
                     WinActivate(curwin)
                     x=wGetLineNo()
                     z=0
                     While @True
                        WinActivate(curwin)
                        wSelectAll()
                        wCopy()
                        wClearSel()
                        rbuf=BinaryAlloc(BinaryClipGet(0,1))
                        BinaryClipGet(rbuf,1)
                        s=BinaryTagInit(rbuf,StrCat(";$","$£"),StrCat("$","£€"))
:NEXTTAG                                                   ; From 294 295 299 302
                        s=BinaryTagFind(s)
                        If s=="" Then Break
                        bti1=BinaryTagIndex(s,1)
                        bte=BinaryTagExtr(s,0)
                        If !(StrLen(bte)==22 && ItemCount(bte,"-")==7) || bti1==1 Then GoTo NEXTTAG ; Line 289
                        If bti1<>0 Then If BinaryPeekStr(rbuf,bti1-2,2)<>@CrLf Then GoTo NEXTTAG ; Line 289
                        If BinaryIndex(rbuf,bti1,@CrLf,@Fwdscan) Then ct=BinaryPeekStr(rbuf,bti1,BinaryIndex(rbuf,bti1,@CrLf,@Fwdscan)-bti1)
                         Else ct=BinaryPeekStr(rbuf,bti1,BinaryEodGet(rbuf)-bti1)
                        If !(StrSub(ct,1,4)==StrCat(";$","$£") && StrSub(ct,27,44)==StrCat("$","£€    ",fill," Line/s suppressed ") && ItemCount(ct,"-")==7 && StrSub(ct,92,24)==StrCat("bytes ",fill) && StrLen(StrReplace(ct,@CrLf,""))==115) Then Message("Invalid Tag",ct)
                          Then GoTo NEXTTAG                ; Line 289
                        nl=lhf_Tag_Found(file,StrCat(";$","$£",bte,"$","£€"),1) ; Line 349
                        If nl=="" && rlines==3 Then Message(vers,StrCat("Line/s for tag ;$","$£",bte,"$","£€ not found.",@CrLf,"Continuing with rest of restore."))
                          Then GoTo NEXTTAG                ; Line 289
                        If rlines==4 Then nl=""
                        If bti1+116<(BinaryEodGet(rbuf)-bti1) || BinaryPeekStr(rbuf,bti1+114,2)<>@CrLf Then If StrSub(nl,StrLen(nl)-1,2)==@CrLf Then nl=StrSub(nl,1,StrLen(nl)-2)
                        x=BinaryStrCnt(rbuf,0,BinaryTagIndex(s,0),@CrLf)+1
                        WinActivate(curwin)
                        wGotoLine(x)
                        wGotoCol(116)
                        wSelHome()
                        wCut()
                        ClipPut(nl)
                        WinActivate(curwin)
                        wPaste()
                        wFileSave()
                        lhf_Tag_Found(file,StrCat(";$","$£",bte,"$","£€"),3) ; Line 349
                        BinaryFree(rbuf)
                        z=1
                     EndWhile
                     If rlines==4 && z==1 Then z=5
                     If rlines==4 && z==0 Then z=6
                     wGotoLine(x)
                     wGotoCol(1)
                  EndIf
               EndIf
            EndIf
         EndIf
         wClearSel()
         If savedclip Then ClipPut(saveclip)
           Then wStatusMsg("Original Clipboard contents restored")
         If IsDefined(rbuf) Then If rbuf Then BinaryFree(rbuf)
         WinActivate(curwin)
:CLOSE                                                     ; From 340
         If z==-1 Then z=lhf_Display_Lines(vers,file,lhf_Tag_Found(file,"",4)) ; Line 385 349
         If z==1 Then Display(0.5,vers,"Line/s restored")
         If z==0 Then Display(2,StrCat(vers," - ",file),StrCat("********** No line/s restored **********",@CrLf,@CrLf,"Checkpoint file=",file,@CrLf,"Size=",FileSize(file),@CrLf,"Tags found=",ItemCount(lhf_Tag_Found(file,"",4),@Tab))) ; Line 349
         If z==4 Then wStatusMsg("Line/s saved")
         If z==5 Then Display(0.5,vers,"All tags removed")
         If z==6 Then Display(0.5,vers,"No tags found to remove")
           Then If FileExist(file) Then FileDelete(file)
         If z<>3 Then If IsKeydown(@Shift || @Ctrl) Then GoTo CLOSE ; Line 332
         Drop(bte,bti1,cancel,ct,currlimit,curwin,file,fill,nl,nl2,nl2x,rbuf,s,saveclip,savedclip,tag,time,vers,x,z)
         DropWild("rline*")
         Exit
:CANCEL                                                    ; Error handler. ; From ?
         cancel=1
         Intcontrol(72,2,0,0,0)
         Return
:PRELOAD                                                   ; From 185
         #DefineFunction lhf_Tag_Found(file,nl,code)       ; From 223 240 254 300 315 333 335
            a=BinaryAlloc(FileSize(file))
            BinaryRead(a,file)
            tag=""
            If code==1 || code==3 || code==4
               s=BinaryTagInit(a,StrCat(";£$","€£"),StrCat("$€","£$"))
               While @True
                  s=BinaryTagFind(s)
                  If s=="" Then Break
                  offset=BinaryTagIndex(s,0)
                  If code==4 Then tag=ItemInsert(StrCat(";£$","€£",BinaryPeekStr(a,offset,34)),-1,tag,@Tab)
                  If BinaryTagExtr(s,0)<>StrSub(nl,5,22) Then Continue
                  size=BinaryPeekStr(a,offset+26,8)
                  tag=BinaryPeekStr(a,offset+36,size)
                  Break
               EndWhile
               If code==3
                  b=BinaryAlloc(FileSize(file)-(size+41))
                  If FileSize(file)-(size+41)
                     If offset==5 Then BinaryCopy(b,0,a,BinaryIndex(a,offset,@CrLf,@Fwdscan)+size+2,BinaryEodGet(a)-(BinaryIndex(a,offset,@CrLf,@Fwdscan)+size+2))
                      Else BinaryCopy(b,0,a,0,offset-5)
                      Else If BinaryEodGet(a)<>(offset+36+size) Then BinaryCopy(b,offset-5,a,BinaryIndex(a,offset,@CrLf,@Fwdscan)+size+2,BinaryEodGet(a)-(BinaryIndex(a,offset,@CrLf,@Fwdscan)+size+2))
                  EndIf
               EndIf
             Else
               b=BinaryAlloc(FileSize(file)+StrLen(nl))
               If FileSize(file) Then BinaryCopy(b,0,a,0,BinaryEodGet(a))
               BinaryPokeStr(b,BinaryEodGet(a),nl)
            EndIf
            BinaryFree(a)
            If IsDefined(b) Then FileDelete(StrCat(FilePath(file),FileRoot(file),".lhf.backup"))
              Then FileRename(file,StrCat(FilePath(file),FileRoot(file),".lhf.backup"))
              Then BinaryWrite(b,file)
              Then BinaryFree(b)
            Return tag
         #EndFunction
         #DefineFunction lhf_Display_Lines(vers,file,taglist) ; From 333
            If !ItemCount(taglist,@Tab) Then Display(0.1,vers,StrCat("Checkpoint file=",file,@CrLf,"Size=",FileSize(file),@CrLf,"no tags found"))
              Then Return -1
            taglist=ItemSort(taglist,@Tab)
            a=BinaryAlloc(FileSize(file))
            BinaryRead(a,file)
            lhf=FileCreateTemp("LHF")
            lhfh=FileOpen(lhf,"Write")
            taglist2=""
            tags=ItemCount(taglist,@Tab)
            For x=1 To tags
               taglist2=ItemInsert(StrCat(StrFix(x," ",4),StrSub(ItemExtract(x,taglist,@Tab),1,31)),-1,taglist2,@Tab)
            Next
            listing=" -   Listing of tags & hidden lines"
            FileWrite(lhfh,StrCat(TimeYMDHMS(),"   -   ",vers,listing,@CrLf,@CrLf,"Open file:       ",wGetFileName(),@CrLf,"C/P file:        ",file,@CrLf,"Backup C/P file: ",file,".backup",@CrLf))
            FileWrite(lhfh,StrCat("List of tags (",tags,") in chronological order",@CrLf,@CrLf,StrReplace(taglist2,@Tab,@CrLf),@CrLf,@CrLf,StrFill("-",100)))
            FileClose(lhfh)
            For x=1 To ItemCount(taglist,@Tab)
               y=BinaryIndexEx(a,0,ItemExtract(x,taglist,@Tab),@Fwdscan,0)
               If y==-1 Then Message(vers,StrCat(@CrLf,"tag ***",ItemExtract(x,taglist,@Tab),"*** not found"))
                 Then Continue
               lhfh=FileOpen(lhf,"Append")
               FileWrite(lhfh,StrCat(@CrLf,StrFix(x," ",4),StrFill("*",33),BinaryPeekStr(a,y,31),StrFill("*",32),@CrLf))
               FileClose(lhfh)
               count=BinaryPeekStr(a,y+31,8)
               start=y+41
               BinaryWriteEx(a,start,lhf,FileSize(lhf),count)
            Next
            BinaryFree(a)
            Run("Notepad.exe",lhf)
            FileDelete(lhf)
            Return 3
         #EndFunction
         Return

Article ID:   W17308
File Created: 2007:07:03:14:29:26
Last Updated: 2007:07:03:14:29:26