Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Manipulate screen or file data
;*************************************************************************************** ; Program Title: ScreenFileUtility * ; * ; Author Steffen Fraas, sfraas@zoo.co.uk * ; * ; Date: 30/12/2001 * ; * ; Synopsis: Manipulate screen or file data * ; * ; Functions: See panel. * ; * ; CALLed routines/modules Screenfileutility.wbt * ; * ; Input/Output files: * ; * ; Documentation File: * ; * ; Notes: Incorporates FileMath functions * ; * ; Installation Save this file in WinBatch.exe's directory * ; * ; For screen data manipulation add next two lines into wspopup.mnu * ; * ; ScreenFileUtilities \ {F7} ; must start in column 1 * ; Call(StrCat(Dirhome(),"Screenfileutility.wbt"),"") ; must start in column 5 * ; * ; To process a range of lines in WinBatch Studio, first highlight lines before * ; invoking utility. Default is all lines. * ; * ; * ; For file data manipulation add a shortcut to desktop pointing at this file * ; * ; * ;*************************************************************************************** ;New Utility vers="Utility v1.0" gosub initudfs gosub saveinput gosub request gosub processrequest exit ;-------------------------------------------------------------------------------------------------- :request ;{{{:request}}} Intcontrol(28,1,0,0,0) ; Fixed font. Intcontrol(63,100,10,890,990) ; Stretch panel. if batchu then x=AskItemList(StrCat(vers," - ","Batch Utility - UDF loaded count=",Intcontrol(77,90,0,0,0)),batch,@Tab,@Unsorted,@Single) ; Get function name selected. else x=AskItemList(StrCat(vers," - ","Screen Utility - UDF loaded count=",Intcontrol(77,90,0,0,0)),screen,@Tab,@Unsorted,@Single) ; Get function name selected. sf=StrTrim(StrLower(StrSub(x,1,2))) ; Get function code. if sf=="x" || x=="" || cancel then return ; Exit/cancel - same thing here. if StrSub(sf,1,1)==";" then goto request function=ItemExtract(sf,functs,@Tab) if StrTrim(function)=="" then Message("Unimplemented function",x) then return if !ItemLocate(function,Intcontrol(77,103,0,0,0),@Tab) then gosub %function% file3=%function%(batchu,file1) return ;-------------------------------------------------------------------------------------------------- :processrequest ;{{{:processrequest}}} if file3<>"" if FileSize(file3)<>0 if !batchu buf=BinaryAlloc(FileSize(file3)) BinaryRead(buf,file3) if !crlf && BinaryPeekStr(buf,FileSize(file3)-2,2)==@CrLf then BinaryEodSet(buf,BinaryEodGet(buf)-2) ClipPut("") BinaryClipPut(buf,1) wPaste() BinaryFree(buf) else Run(StrCat(DirHome(),"Browser.exe"),FileNameShort(file3)) endif else Run(StrCat(DirHome(),"Browser.exe"),FileNameShort(file3)) endif endif if !batchu then wClearSel() drop(batch,batchu,buf,cancel,crlf,file1,file2,file3,function,functs,logudf,screen,sf,size) drop(udflist,udfs,vers,x,xx) return ;-------------------------------------------------------------------------------------------------- :saveinput ;{{{:saveinput}}} if batchu file1=AskFileName("Select File",FilePath(Intcontrol(1004,0,0,0,0)),"All Files|*.*","*.*",1) else file1=FileNameLong(FileCreateTemp("UF1")) batchu=0 if !wGetSelState() then wSelectAll() wCopy() size=BinaryClipGet(0,1) buf=BinaryAlloc(size) BinaryClipGet(buf,1) if size<3 then crlf=0 if size>2 then if BinaryPeekStr(buf,size-2,2)<>@CrLf then crlf=0 BinaryWrite(buf,file1) BinaryFree(buf) endif return ;-------------------------------------------------------------------------------------------------- :initudfs ;{{{:initudfs}}} ;@fmADD=1 ;@fmSUBTRACT=2 ;@fmOR=3 ;@fmXOR=4 ;@fmAND=5 file1="" file2="" file3="" Intcontrol(72,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. crlf=1 batchu=0 if RtStatus()==1 || RtStatus()==0 then batchu=1 ; Interpreter or .exe. xx=0 functs="" if batchu xx=xx+1 functs=StrCat(functs,"Datainformation",@Tab) batch=StrCat(StrFix(xx," ",4),"File - data information",@Tab) xx=xx+1 functs=StrCat(functs,"Charactercount",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Character Count",@Tab) batch=StrCat(batch,";****************************** FileMath functions ******************************",@Tab) xx=xx+1 functs=StrCat(functs,"Sortascending",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Sort (Ascending)",@Tab) xx=xx+1 functs=StrCat(functs,"Sortdescending",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Sort (Descending)",@Tab) xx=xx+1 functs=StrCat(functs,"ColumnSort",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Column Sort ",@Tab) xx=xx+1 functs=StrCat(functs,"Removeduplicatelines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Remove Duplicate lines",@Tab) xx=xx+1 functs=StrCat(functs,"Getduplicatelines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Get Duplicate lines",@Tab) xx=xx+1 functs=StrCat(functs,"Addlines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - ADD (Makes a combination of both input files. Not sorted. Dups may exist)",@Tab) xx=xx+1 functs=StrCat(functs,"Subtractlines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - SUBTRACT (Subtracts line in second file from the first file. Sorted. Dups may exist)",@Tab) xx=xx+1 functs=StrCat(functs,"Orlines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - OR (Returns lines found in both files. Sorted. No dups)",@Tab) xx=xx+1 functs=StrCat(functs,"Xorlines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - XOR (Returns lines not found in both file)",@Tab) xx=xx+1 functs=StrCat(functs,"Andlines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - AND (Returns lines only found in both files)",@Tab) batch=StrCat(batch,";****************************** Column manipulation functions ******************************",@Tab) xx=xx+1 functs=StrCat(functs,"ShiftColumns",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Shift columns",@Tab) xx=xx+1 functs=StrCat(functs,"DeleteColumns",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Delete columns",@Tab) xx=xx+1 functs=StrCat(functs,"SaveColumns",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Save columns",@Tab) xx=xx+1 functs=StrCat(functs,"InsertColumns",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Insert columns",@Tab) xx=xx+1 functs=StrCat(functs,"InsertData",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Insert data",@Tab) batch=StrCat(batch,";****************************** Line manipulation functions ******************************",@Tab) xx=xx+1 functs=StrCat(functs,"Dropblanklines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Drop blank lines",@Tab) xx=xx+1 functs=StrCat(functs,"WrapLines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Wrap lines",@Tab) xx=xx+1 functs=StrCat(functs,"CentreLines",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Centre/Align lines",@Tab) xx=xx+1 functs=StrCat(functs,"Appenddata",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Append data to lines",@Tab) xx=xx+1 functs=StrCat(functs,"Prependdata",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Prepend data to lines",@Tab) batch=StrCat(batch,";****************************** Hex manipulation functions *******************************",@Tab) xx=xx+1 functs=StrCat(functs,"HextoHex",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Hex for Hex replacement",@Tab) xx=xx+1 functs=StrCat(functs,"HextoString",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Hex for String replacement",@Tab) xx=xx+1 functs=StrCat(functs,"StringtoHex",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - String for Hex replacement",@Tab) xx=xx+1 functs=StrCat(functs,"MultipleHex",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Multiple Hex deletions",@Tab) xx=xx+1 functs=StrCat(functs,"DisplayHex",@Tab) batch=StrCat(batch,StrFix(xx," ",4),"File - Display Hex",@Tab) batch=StrCat(batch,";****************************** End of function list ******************************",@Tab) batch=StrCat(batch,@Tab,@Tab,"X Exit") else xx=xx+1 functs=StrCat(functs,"Datainformation",@Tab) screen=StrCat(StrFix(xx," ",4),"Screen - data information",@Tab) xx=xx+1 functs=StrCat(functs,"Charactercount",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Character Count",@Tab) screen=StrCat(screen,";****************************** FileMath functions ******************************",@Tab) xx=xx+1 functs=StrCat(functs,"Sortascending",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Sort (Ascending)",@Tab) xx=xx+1 functs=StrCat(functs,"Sortdescending",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Sort (Descending)",@Tab) xx=xx+1 functs=StrCat(functs,"ColumnSort",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Column Sort ",@Tab) xx=xx+1 functs=StrCat(functs,"Removeduplicatelines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Remove Duplicate lines",@Tab) xx=xx+1 functs=StrCat(functs,"Getduplicatelines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Get Duplicate lines",@Tab) xx=xx+1 functs=StrCat(functs,"Addlines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - ADD (Makes a combination of both input files. Not sorted. Dups may exist)",@Tab) xx=xx+1 functs=StrCat(functs,"Subtractlines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - SUBTRACT (Subtracts line in second file from the first file. Sorted. Dups may exist)",@Tab) xx=xx+1 functs=StrCat(functs,"Orlines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - OR (Returns lines found in both files. Sorted. No dups)",@Tab) xx=xx+1 functs=StrCat(functs,"Xorlines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - XOR (Returns lines not found in both file)",@Tab) xx=xx+1 functs=StrCat(functs,"Andlines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - AND (Returns lines only found in both files)",@Tab) screen=StrCat(screen,";****************************** Column manipulation functions ******************************",@Tab) xx=xx+1 functs=StrCat(functs,"ShiftColumns",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Shift columns",@Tab) xx=xx+1 functs=StrCat(functs,"DeleteColumns",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Delete columns",@Tab) xx=xx+1 functs=StrCat(functs,"SaveColumns",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Save columns",@Tab) xx=xx+1 functs=StrCat(functs,"InsertColumns",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Insert columns",@Tab) xx=xx+1 functs=StrCat(functs,"InsertData",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Insert Data",@Tab) screen=StrCat(screen,";****************************** Line manipulation functions ******************************",@Tab) xx=xx+1 functs=StrCat(functs,"DropBlankLines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Drop blank lines",@Tab) xx=xx+1 functs=StrCat(functs,"WrapLines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Wrap lines",@Tab) xx=xx+1 functs=StrCat(functs,"CentreLines",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Centre/Align lines",@Tab) xx=xx+1 functs=StrCat(functs,"Appenddata",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Append data to lines",@Tab) xx=xx+1 functs=StrCat(functs,"Prependdata",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Prepend data to lines",@Tab) screen=StrCat(screen,";****************************** Hex manipulation functions *******************************",@Tab) xx=xx+1 functs=StrCat(functs,"HextoHex",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Hex for Hex replacement",@Tab) xx=xx+1 functs=StrCat(functs,"HextoString",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Hex for String replacement",@Tab) xx=xx+1 functs=StrCat(functs,"StringtoHex",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - String for Hex replacement",@Tab) xx=xx+1 functs=StrCat(functs,"MultipleHex",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Mulitple Hex deletions",@Tab) xx=xx+1 functs=StrCat(functs,"DisplayHex",@Tab) screen=StrCat(screen,StrFix(xx," ",4),"Screen - Display Hex",@Tab) screen=StrCat(screen,";****************************** End of function list ******************************",@Tab) screen=StrCat(screen,@Tab,@Tab,"X Exit") endif functs=StrLower(functs) udfs=StrCat(" ",StrReplace(Intcontrol(77,103,0,0,0),@Tab," ")," ") udflist="fmfilemath fmgetdups fmgetfileobject fmremovedups fmsortfile fmsortfilereverse fmverifyfileobject fmcolumnsort" for x=1 to ItemCount(udflist," ") if ItemLocate(ItemExtract(x,udflist," "),udfs," ") then continue logudf=ItemExtract(x,udflist," ") gosub %logudf% next return ;------------------------------------------------------------------------------------------------------------ :datainformation ;{{{:datainformation}}} #definefunction Datainformation(batchu,file1) ;{{{#definefunction Datainformation}}} if !batchu then wClearSel() sub1max1=0 ; Length of longest line. sub1max1l=0 ; Line # of longest line. sub1tbar=0 ; No of lines in file. sub1bx1=0 ; No of blanks. sub1tsf=0 ; Current line no. sub1f=FileOpen(file1,"Read") while @True sub1line=FileRead(sub1f) if sub1line=="*EOF*" then break sub1tsf=sub1tsf+1 if sub1max1maxsize || ec<1 || ec>maxsize || ec 5), "fmFileMath Error","param4 is not 1 2 3 4 or 5") ;Hack to optimize ADD(1) if optype==1 FileCopy(filea[0],fileout[0],0) FileAppend(fileb[0], fileout[0]) fileout[1]=FileSize(fileout[0]) fileout[2]=filea[2]+fileb[2] ; Recordcount. fileout[3]=Max(filea[3],fileb[3]) ; Maxsize. fileout[5]=0 ; Sorted=false. fileout[6]=0 ; 'deduped=false. return endif ;Hack to optimize "OR" if optype==3 ; OR. tempout=fmGetFileObject(FileNameLong(FileCreateTemp("~fm")),0) fmFileMath(filea,fileb,tempout,1) fmRemoveDups(tempout,fileout) FileDelete(tempout[0]) ;sorted and deduped status set by fmRemoveDups routine return endif switch optype ; case 1 ; add ; ADD optimized above case 2 ; Subtract. tempa=fmGetFileObject(FileNameLong(FileCreateTemp("~fm")),0) tempb=fmGetFileObject(FileNameLong(FileCreateTemp("~fm")),0) fmSortFile(filea,tempa) fmSortFile(fileb,tempb) fileout[5]=1 ; Sorted. fileout[6]=0 ; Deduped. break ; case 3 ; OR ; OR optimized above case 4 ; XOR. case 5 ; AND. tempa=fmGetFileObject(FileNameLong(FileCreateTemp("~fm")),0) tempb=fmGetFileObject(FileNameLong(FileCreateTemp("~fm")),0) fmRemoveDups(filea,tempa) fmRemoveDups(fileb,tempb) fileout[5]=1 ; Sorted. fileout[6]=1 ; Deduped. endswitch handlea=FileOpen(tempa[0],"READ") handleb=FileOpen(tempb[0],"READ") out=FileOpen(fileout[0],"WRITE") ;state machine 0 need both lines ; 1 compare 2 lines reccount=0 maxsize=0 state=optype while 1 switch state ; case 1 ;ADD ; ADD replaced by optimization above ; case 2 ; SUBTRACT. linea=StrTrim(FileRead(handlea)) lineb=StrTrim(FileRead(handleb)) :xsubtract ;{{{:xsubtract}}} if linea=="*EOF*" state = 99 ; All done. continue endif if lineb=="*EOF*" FileWrite(out, linea) reccount=reccount+1 maxsize=Max(maxsize,StrLen(linea)) state=98 ; No more minus lines. continue endif test=StrCmp(linea,lineb) if test==0 ; Lines match. toast both of them. linea=StrTrim(FileRead(handlea)) lineb=StrTrim(FileRead(handleb)) else if test > 0 ; LineA > lineB Need new lineB. lineb=FileRead(handleb) else ; LineA < lineB. FileWrite(out,linea) reccount=reccount+1 maxsize=Max(maxsize,StrLen(linea)) linea=FileRead(handlea) state=optype endif endif goto xsubtract ; NB No structure levels being crossed. DON'T USE GOTOs!!!!!! break ; case 3 ; OR ; OR replace by optimization aboce case 4 ; XOR. linea=StrTrim(FileRead(handlea)) lineb=StrTrim(FileRead(handleb)) :xxor ;{{{:xxor}}} if linea=="*EOF*" if lineb!="*EOF*" FileWrite(out,lineb) reccount=reccount+1 maxsize=Max(maxsize,StrLen(lineb)) state = 97 ; Dump rest of B. continue endif state=99 continue endif if lineb=="*EOF*" FileWrite(out,linea) reccount=reccount+1 maxsize=Max(maxsize,StrLen(linea)) state=98 ; Dump rest of A. continue endif test=StrCmp(linea,lineb) if test==0 ; Lines match. toast both of them. linea=StrTrim(FileRead(handlea)) lineb=StrTrim(FileRead(handleb)) else if test > 0 ; LineA > lineB Need new lineB. FileWrite(out,lineb) reccount=reccount+1 maxsize=Max(maxsize,StrLen(lineb)) lineb=FileRead(handleb) else ; LineA < lineB. FileWrite(out,linea) reccount=reccount+1 maxsize=Max(maxsize,StrLen(linea)) linea=FileRead(handlea) endif endif goto xxor ; NB No structure levels being crossed. DON'T USE GOTOs!!!!!! break case 5 ; AND. linea=StrTrim(FileRead(handlea)) lineb=StrTrim(FileRead(handleb)) :xand ;{{{:xand}}} if linea=="*EOF*" state = 99 continue endif if lineb=="*EOF*" state = 99 continue endif test=StrCmp(linea,lineb) if test==0 ; Lines match. the only case where we write a line. FileWrite(out,linea) reccount=reccount+1 maxsize=Max(maxsize,StrLen(linea)) linea=StrTrim(FileRead(handlea)) lineb=StrTrim(FileRead(handleb)) else if test > 0 ; LineA > lineB Need new lineB. lineb=FileRead(handleb) else ; LineA < lineB. linea=FileRead(handlea) endif endif goto xand ; NB No structure levels being crossed. DON'T USE GOTOs!!!!!! break case 97 ; Dump rest of B to the outfile. while 1 lineb=FileRead(handleb) if lineb=="*EOF*" then break FileWrite(out,lineb) reccount=reccount+1 maxsize=Max(maxsize,StrLen(lineb)) endwhile state=99 break case 98 ; Dump rest of A to the outfile. while 1 linea=FileRead(handlea) if linea=="*EOF*" then break FileWrite(out,linea) reccount=reccount+1 maxsize=Max(maxsize,StrLen(linea)) endwhile state=99 break endswitch if state==99 then break endwhile FileClose(handlea) FileClose(handleb) FileClose(out) if optype!=1 ; Not for adds. FileDelete(tempa[0]) FileDelete(tempb[0]) endif fileout[1]=FileSize(fileout[0]) fileout[2]=reccount fileout[3]=maxsize return #endfunction return ;--------------------------------------------------------------------------------------------------- :shiftcolumns ;{{{:shiftcolumns}}} #definefunction Shiftcolumns(batchu,file1) ;{{{#definefunction Shiftcolumns}}} sc9=1 cm9=5 Intcontrol(72,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. while @True shiftcformat=`WWWDLGED,5.0` shiftccaption=`Shift Columns` shiftcx=450 shiftcy=10 shiftcwidth=100 shiftcheight=78 shiftcnumcontrols=8 shiftc01=`2,4,160,DEFAULT,STATICTEXT,DEFAULT,"Shift column x +/- y positions"` shiftc02=`2,16,64,DEFAULT,STATICTEXT,DEFAULT,""` shiftc03=`4,33,30,DEFAULT,STATICTEXT,DEFAULT,"Column"` shiftc04=`32,30,15,DEFAULT,EDITBOX,sc9,""` shiftc05=`50,30,15,DEFAULT,EDITBOX,cm9,""` shiftc06=`070,32,36,DEFAULT,STATICTEXT,DEFAULT,"positions"` shiftc07=`08,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Move",1` shiftc08=`53,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Exit",2` shcbp=Dialog("Shiftc") if cancel || shcbp==2 then break ; Cancel requested. if !IsNumber(sc9) || !IsNumber(cm9) || sc9<1 then continue break endwhile if cancel || shcbp==2 then return "" ; Cancel requested. f1=FileOpen(file1,"Read") file3=FileNameLong(FileCreateTemp("UF3")) f3=FileOpen(file3,"Write") while @True line=FileRead(f1) if line=="*EOF*" then break dl9=StrLen(line) ; Handy constant. if cm9<0 then goto left9 ; Left cm5. if sc9==0 then line=StrCat(StrFill(" ",cm9),line) ; Shift all rightwards. else line=StrCat(StrSub(line,1,sc9-1),StrFill(" ",cm9),StrSub(line,sc9,-1)) ; Part old line, filler, rest. goto writeout ; Write out line. :left9 ;{{{:left9}}} if dl9 < sc9 then line="" ; Line long enough, no, column disappears. then goto writeout if sc9==0 then line=StrSub(line,Abs(cm9)+1,-1) ; Simple left move ? Start at 'cm5' rightwards. then goto writeout nc9=sc9-Abs(cm9) ; Work out old col 1 to 'cm9'. if nc9>0 then line=StrCat(StrSub(line,1,nc9-1),StrSub(line,sc9,-1)) ; Old part, chop, remainder. else line=StrSub(line,Abs(cm9)+1,-1) ; From 'cm9' rightwards. :writeout ;{{{:writeout}}} FileWrite(f3,line) endwhile FileClose(f1) FileClose(f3) return file3 :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;--------------------------------------------------------------------------------------------------- :deletecolumns ;{{{:deletecolumns}}} #definefunction Deletecolumns(batchu,file1) ;{{{#definefunction Deletecolumns}}} Intcontrol(72,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. sc13=1 ec13=5 while @True deleteformat=`WWWDLGED,5.0` deletecaption=`Delete Columns` deletex=300 deletey=50 deletewidth=85 deleteheight=78 deletenumcontrols=8 delete01=`2,4,100,DEFAULT,STATICTEXT,DEFAULT,"Delete columns:"` delete02=`2,16,100,DEFAULT,STATICTEXT,DEFAULT,"Enter start and end column"` delete03=`4,33,30,DEFAULT,STATICTEXT,DEFAULT,"Column x,y"` delete04=`32,30,15,DEFAULT,EDITBOX,Sc13,""` delete05=`50,30,15,DEFAULT,EDITBOX,Ec13,""` delete06=`01,58,20,DEFAULT,PUSHBUTTON,DEFAULT,"&Delete",1` delete07=`25,58,30,DEFAULT,PUSHBUTTON,DEFAULT,"&Save&&Del",3` delete08=`60,58,20,DEFAULT,PUSHBUTTON,DEFAULT,"&Exit",2` dbp=Dialog("Delete") if cancel || dbp==2 then break ; Cancel requested. if !IsNumber(sc13) || !IsNumber(ec13) || sc13<1 || ec13 "" then FileClose(f4) then Display(2,"Listing of DELETED columns",file4) return file3 :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;--------------------------------------------------------------------------------------------------- :savecolumns ;{{{:savecolumns}}} #definefunction Savecolumns(batchu,file1) ;{{{#definefunction Savecolumns}}} Intcontrol(72,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. sc13=1 ec13=5 while @True saveformat=`WWWDLGED,5.0` savecaption=`Save Columns` savex=300 savey=50 savewidth=85 saveheight=78 savenumcontrols=7 save01=`2,4,100,DEFAULT,STATICTEXT,DEFAULT,"Save columns:"` save02=`2,16,100,DEFAULT,STATICTEXT,DEFAULT,"Enter start and end column"` save03=`4,33,30,DEFAULT,STATICTEXT,DEFAULT,"Column x,y"` save04=`32,30,15,DEFAULT,EDITBOX,Sc13,""` save05=`50,30,15,DEFAULT,EDITBOX,Ec13,""` save06=`01,58,20,DEFAULT,PUSHBUTTON,DEFAULT,"&Save",1` save07=`60,58,20,DEFAULT,PUSHBUTTON,DEFAULT,"&Exit",2` dbp=Dialog("Save") if cancel || dbp==2 then break ; Cancel requested. if !IsNumber(sc13) || !IsNumber(ec13) || sc13<1 || ec13 "*EOF*" then gosub write else line4eof=1 else line4="" endif FileWrite(f3,line) endwhile FileClose(f1) FileClose(f4) FileClose(f3) return file3 :write ;{{{:write}}} line1=StrLen(line) ; Length of line receiving insert data. if line1 "" then line=StrCat(line,StrFill(" ",sc17-line1)) ; Line short, pad it out first. if !sc17 then line=StrCat(line4,line) ; Just join them if column is zero. else line=StrCat(StrSub(line,1,sc17),line4,StrSub(line,sc17+1,-1)) ; Insert Line4 in between columns. return :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;------------------------------------------------------------------------------------------------------------ :insertdata ;{{{:insertdata}}} #definefunction Insertdata(batchu,file1) ;{{{#definefunction Insertdata}}} Intcontrol(72,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. sc17=1 while @True insertformat=`WWWDLGED,5.0` insertcaption=`Insert Data` insertx=300 inserty=50 insertwidth=100 insertheight=78 insertnumcontrols=6 insert01=`2,4,100,DEFAULT,STATICTEXT,DEFAULT,"Insert Data at column x "` insert02=`4,25,30,DEFAULT,STATICTEXT,DEFAULT,"Column x"` insert03=`40,22,15,DEFAULT,EDITBOX,Sc17,""` insert04=`10,40,70,DEFAULT,EDITBOX,Data,""` insert05=`08,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Insert",1` insert06=`53,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Exit",2` ibp=Dialog("Insert") if cancel || ibp==2 then break ; Cancel requested. if !IsNumber(sc17) then continue if sc17<1 then continue sc17=sc17-1 break endwhile if cancel || ibp==2 || data=="" then return "" ; Cancel requested. f1=FileOpen(file1,"Read") file3=FileNameLong(FileCreateTemp("UF3")) f3=FileOpen(file3,"Write") while @True line=FileRead(f1) if line=="*EOF*" then break line1=StrLen(line) ; Length of line receiving insert data. if line1 2 || StrLen(hexb)<>2 || hexa=="00" || hexb=="00" then continue if !StrScan(StrSub(hexa,1,1),hexs,1,@Fwdscan) || !StrScan(StrSub(hexa,2,1),hexs,1,@Fwdscan) then continue if !StrScan(StrSub(hexb,1,1),hexs,1,@Fwdscan) || !StrScan(StrSub(hexb,2,1),hexs,1,@Fwdscan) then continue a=xBaseConvert(hexa,16,10) b=xBaseConvert(hexb,16,10) break endwhile if cancel || hexc==2 then return "" ; Cancel requested. f1=FileOpen(file1,"Read") file3=FileNameLong(FileCreateTemp("UF3")) f3=FileOpen(file3,"Write") while @True line=FileRead(f1) if line=="*EOF*" then break FileWrite(f3,StrReplace(line,Num2Char(a),Num2Char(b))) endwhile FileClose(f1) FileClose(f3) return file3 :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;--------------------------------------------------------------------------------------------------- :hextostring ;{{{:hextostring}}} #definefunction Hextostring(batchu,file1) ;{{{#definefunction Hextostring}}} if !StrIndexNc(Intcontrol(77,42,0,0,0),"wilx34i.dll",1,@Fwdscan) then AddExtender("wilx34i.dll") Intcontrol(73,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. hexa="00" hexs="0123456789abcdef" hexb="" while @True hexcformat=`WWWDLGED,5.0` hexccaption=`Hex String replacement` hexcx=450 hexcy=10 hexcwidth=100 hexcheight=78 hexcnumcontrols=7 hexc01=`2,4,160,DEFAULT,STATICTEXT,DEFAULT,"Replace Hex byte with string"` hexc02=`2,16,64,DEFAULT,STATICTEXT,DEFAULT,""` hexc03=`4,33,30,DEFAULT,STATICTEXT,DEFAULT,"Byte "` hexc04=`32,30,15,DEFAULT,EDITBOX,Hexa,""` hexc05=`50,30,40,DEFAULT,EDITBOX,Hexb,""` hexc06=`08,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Swap",1` hexc07=`53,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Exit",2` hexc=Dialog("Hexc") if cancel || hexc==2 then break ; Cancel requested. hexa=StrLower(hexa) if StrLen(hexa)<>2 || hexa=="00" then continue if !StrScan(StrSub(hexa,1,1),hexs,1,@Fwdscan) || !StrScan(StrSub(hexa,2,1),hexs,1,@Fwdscan) then continue a=xBaseConvert(hexa,16,10) break endwhile if cancel || hexc==2 then return "" ; Cancel requested. f1=FileOpen(file1,"Read") file3=FileNameLong(FileCreateTemp("UF3")) f3=FileOpen(file3,"Write") while @True line=FileRead(f1) if line=="*EOF*" then break FileWrite(f3,StrReplace(line,Num2Char(a),hexb)) ; Swap byte with string. endwhile FileClose(f1) FileClose(f3) return file3 :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;--------------------------------------------------------------------------------------------------- :stringtohex ;{{{:stringtohex}}} #definefunction Stringtohex(batchu,file1) ;{{{#definefunction Stringtohex}}} if !StrIndexNc(Intcontrol(77,42,0,0,0),"wilx34i.dll",1,@Fwdscan) then AddExtender("wilx34i.dll") Intcontrol(73,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. hexa="" hexs="0123456789abcdef" while @True hexcformat=`WWWDLGED,5.0` hexccaption=`String with hex replacement` hexcx=450 hexcy=10 hexcwidth=100 hexcheight=78 hexcnumcontrols=7 hexc01=`2,4,160,DEFAULT,STATICTEXT,DEFAULT,"Replace string with hex byte"` hexc02=`2,16,64,DEFAULT,STATICTEXT,DEFAULT,""` hexc03=`4,33,30,DEFAULT,STATICTEXT,DEFAULT,"String "` hexc04=`32,30,40,DEFAULT,EDITBOX,Hexa,""` hexc05=`75,30,20,DEFAULT,EDITBOX,Hexb,""` hexc06=`08,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Swap",1` hexc07=`53,58,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Exit",2` hexc=Dialog("Hexc") if cancel || hexc==2 then break ; Cancel requested. if hexa=="" then continue hexb=StrLower(hexb) if hexb=="" then break if StrLen(hexb)<>2 || hexb=="00" then continue if !StrScan(StrSub(hexb,1,1),hexs,1,@Fwdscan) || !StrScan(StrSub(hexb,2,1),hexs,1,@Fwdscan) then continue b=xBaseConvert(hexb,16,10) break endwhile if cancel || hexc==2 then return "" ; Cancel requested. f1=FileOpen(file1,"Read") file3=FileNameLong(FileCreateTemp("UF3")) f3=FileOpen(file3,"Write") while @True line=FileRead(f1) if line=="*EOF*" then break if hexb<>"" then FileWrite(f3,StrReplace(StrLower(line),StrLower(hexa),Num2Char(b))) ; Replace string with hex byte. else FileWrite(f3,StrReplace(StrLower(line),StrLower(hexa),"")) ; Delete string. endwhile FileClose(f1) FileClose(f3) return file3 :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;--------------------------------------------------------------------------------------------------- :multiplehex ;{{{:multiplehex}}} #definefunction Multiplehex(batchu,file1) ;{{{#definefunction Multiplehex}}} if !StrIndexNc(Intcontrol(77,42,0,0,0),"wilx34i.dll",1,@Fwdscan) then AddExtender("wilx34i.dll") Intcontrol(73,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. Intcontrol(28,2,0,0,0) ; Fixed font. Intcontrol(63,200,10,690,990) ; Stretch panel. Intcontrol(72,2,0,0,0) ; Cancel and return. x="" ; Init. output=0 ; In case of problems. hexdel=StrCat("01",@Tab,"02",@Tab,"03",@Tab,"04",@Tab,"05",@Tab,"06",@Tab,"07",@Tab,"08",@Tab,"09",@Tab,"0a",@Tab,"0b",@Tab,"0c",@Tab,"0d",@Tab,"0e",@Tab,"0f",@Tab,"10",@Tab) hexdel=StrCat(hexdel,"10",@Tab,"11",@Tab,"12",@Tab,"13",@Tab,"14",@Tab,"15",@Tab,"16",@Tab,"17",@Tab,"18",@Tab,"19",@Tab,"1a",@Tab,"1b",@Tab,"1c",@Tab,"1d",@Tab,"1e",@Tab,"1f",@Tab) hexdel=StrCat(hexdel,"20",@Tab,"21",@Tab,"22",@Tab,"23",@Tab,"24",@Tab,"25",@Tab,"26",@Tab,"27",@Tab,"28",@Tab,"29",@Tab,"2a",@Tab,"2b",@Tab,"2c",@Tab,"2d",@Tab,"2e",@Tab,"2f",@Tab) hexdel=StrCat(hexdel,"30",@Tab,"31",@Tab,"32",@Tab,"33",@Tab,"34",@Tab,"35",@Tab,"36",@Tab,"37",@Tab,"38",@Tab,"39",@Tab,"3a",@Tab,"3b",@Tab,"3c",@Tab,"3d",@Tab,"3e",@Tab,"3f",@Tab) hexdel=StrCat(hexdel,"40",@Tab,"41",@Tab,"42",@Tab,"43",@Tab,"44",@Tab,"45",@Tab,"46",@Tab,"47",@Tab,"48",@Tab,"49",@Tab,"4a",@Tab,"4b",@Tab,"4c",@Tab,"4d",@Tab,"4e",@Tab,"4f",@Tab) hexdel=StrCat(hexdel,"50",@Tab,"51",@Tab,"52",@Tab,"53",@Tab,"54",@Tab,"55",@Tab,"56",@Tab,"57",@Tab,"58",@Tab,"59",@Tab,"5a",@Tab,"5b",@Tab,"5c",@Tab,"5d",@Tab,"5e",@Tab,"5f",@Tab) hexdel=StrCat(hexdel,"60",@Tab,"61",@Tab,"62",@Tab,"63",@Tab,"64",@Tab,"65",@Tab,"66",@Tab,"67",@Tab,"68",@Tab,"69",@Tab,"6a",@Tab,"6b",@Tab,"6c",@Tab,"6d",@Tab,"6e",@Tab,"6f",@Tab) hexdel=StrCat(hexdel,"70",@Tab,"71",@Tab,"72",@Tab,"73",@Tab,"74",@Tab,"75",@Tab,"76",@Tab,"77",@Tab,"78",@Tab,"79",@Tab,"7a",@Tab,"7b",@Tab,"7c",@Tab,"7d",@Tab,"7e",@Tab,"7f",@Tab) hexdel=StrCat(hexdel,"80",@Tab,"81",@Tab,"82",@Tab,"83",@Tab,"84",@Tab,"85",@Tab,"86",@Tab,"87",@Tab,"88",@Tab,"89",@Tab,"8a",@Tab,"8b",@Tab,"8c",@Tab,"8d",@Tab,"8e",@Tab,"8f",@Tab) hexdel=StrCat(hexdel,"90",@Tab,"91",@Tab,"92",@Tab,"93",@Tab,"94",@Tab,"95",@Tab,"96",@Tab,"97",@Tab,"98",@Tab,"99",@Tab,"9a",@Tab,"9b",@Tab,"9c",@Tab,"9d",@Tab,"9e",@Tab,"9f",@Tab) hexdel=StrCat(hexdel,"a0",@Tab,"a1",@Tab,"a2",@Tab,"a3",@Tab,"a4",@Tab,"a5",@Tab,"a6",@Tab,"a7",@Tab,"a8",@Tab,"a9",@Tab,"aa",@Tab,"ab",@Tab,"ac",@Tab,"ad",@Tab,"ae",@Tab,"af",@Tab) hexdel=StrCat(hexdel,"b0",@Tab,"b1",@Tab,"b2",@Tab,"b3",@Tab,"b4",@Tab,"b5",@Tab,"b6",@Tab,"b7",@Tab,"b8",@Tab,"b9",@Tab,"ba",@Tab,"bb",@Tab,"bc",@Tab,"bd",@Tab,"be",@Tab,"bf",@Tab) hexdel=StrCat(hexdel,"c0",@Tab,"c1",@Tab,"c2",@Tab,"c3",@Tab,"c4",@Tab,"c5",@Tab,"c6",@Tab,"c7",@Tab,"c8",@Tab,"c9",@Tab,"ca",@Tab,"cb",@Tab,"cc",@Tab,"cd",@Tab,"ce",@Tab,"cf",@Tab) hexdel=StrCat(hexdel,"d0",@Tab,"d1",@Tab,"d2",@Tab,"d3",@Tab,"d4",@Tab,"d5",@Tab,"d6",@Tab,"d7",@Tab,"d8",@Tab,"d9",@Tab,"da",@Tab,"db",@Tab,"dc",@Tab,"dd",@Tab,"de",@Tab,"df",@Tab) hexdel=StrCat(hexdel,"e0",@Tab,"e1",@Tab,"e2",@Tab,"e3",@Tab,"e4",@Tab,"e5",@Tab,"e6",@Tab,"e7",@Tab,"e8",@Tab,"e9",@Tab,"ea",@Tab,"eb",@Tab,"ec",@Tab,"ed",@Tab,"ee",@Tab,"ef",@Tab) hexdel=StrCat(hexdel,"f0",@Tab,"f1",@Tab,"f2",@Tab,"f3",@Tab,"f4",@Tab,"f5",@Tab,"f6",@Tab,"f7",@Tab,"f8",@Tab,"f9",@Tab,"fa",@Tab,"fb",@Tab,"fc",@Tab,"fd",@Tab,"fe",@Tab,"ff",@Tab) x=AskItemList("Select hex byte/s to be deleted ",hexdel,@Tab,@Unsorted,@Multiple) ; Get hex bytes for deletion. if x==0 || cancel then return "" ; Exit/cancel - same thing here. f1=FileOpen(file1,"Read") file3=FileNameLong(FileCreateTemp("UF3")) f3=FileOpen(file3,"Write") while @True line=FileRead(f1) if line=="*EOF*" then break for y=1 to ItemCount(x,@Tab) z=xBaseConvert(ItemExtract(y,x,@Tab),16,10) line=StrReplace(line,Num2Char(z),"") ; Delete hex byte. next FileWrite(f3,line) ; Line with deleted hex. endwhile FileClose(f1) FileClose(f3) return file3 :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;--------------------------------------------------------------------------------------------------- :displayhex ;{{{:displayhex}}} #definefunction Displayhex(batchu,file1) ;{{{#definefunction Displayhex}}} Intcontrol(73,2,0,0,0) ; Cancel and return. cancel=0 ; Reset. browser=StrCat(DirHome(),"Browser.exe") if FileExist(browser)<>1 then browser=StrLower(AskFileName("Browser not found - Select a Browser for hex viewing", DirHome(),"Program|*.exe|All Files|*.*|", "*.exe", 1)) ; Get a hex browser. if cancel then return "" Run(`%Browser%`,FileNameShort(file1)) ; Call Browser for 'work' file. if StrLower(browser)==StrLower(StrCat(DirHome(),"browser.exe")) then WinWaitExist("~Browser - ",5) ; Wait for it... then SendMenusTo("~Browser - ", "View Hex") ; Select Hex view option. return "" :cancel ;{{{:cancel}}} cancel=1 return #endfunction return ;---------------------------------------------------------------------------------------------------
Article ID: W15520
File Created: 2003:05:13:11:28:28
Last Updated: 2003:05:13:11:28:28