@chen: Sorry - your thread took the scenic detour into spaghetti land.
File Manipulation
HELP !
i got a error !
and this is the "output.avs" file
p_1=last.trim(0,63).Lanczos4Resize(-1526461656,1913716392).RemoveGrain(mode=2)
p_2=last.trim(64,0).BicubicResize(-1526461656,1913716392,0.2,0.4).deen("c3d",0,6,8,3)
p_1+p_2
running the program (in debug mode) i got a "Invalid memory access"
Any help ?
thanks !!!
BHH
i got a error !
Code: Select all
Procedure ChangeStrings(Filename.s,oldStr.s,newStr.s)
dif=Len(oldStr)-Len(newStr)
OpenFile(0, Filename)
sz=Lof()*3 ; Cheat #1 - assumes file won't grow 2x
mem=AllocateMemory(sz)
ReadData(mem,sz)
ptr=0
While ptr<=(sz/2)+ctr
If CompareMemory(@oldStr,mem+ptr,Len(oldStr))
If dif<0
CopyMemory(mem+ptr,mem+ptr+(dif * -1),sz-(ptr + (dif * -1)))
CopyMemory(@newStr,mem+ptr,Len(newStr))
ElseIf dif>0
CopyMemory(@newStr,mem+ptr,Len(newStr))
CopyMemory(mem+ptr+Len(oldStr),mem+ptr+Len(newStr),sz-(ptr + (dif * -1)))
Else
CopyMemory(@newStr,mem+ptr,Len(newStr))
EndIf
ctr-dif
ptr+Len(oldStr)+dif
Else
ptr+1
EndIf
Wend
FileSeek(0)
WriteData(mem,Lof()+ctr)
CloseFile(0)
EndProcedure
ChangeStrings("C:\Programmi\PureBasic\Prove\output.avs","-1526461656","out_width")
ChangeStrings("C:\Programmi\PureBasic\Prove\output.avs","1913716392","out_height")
p_1=last.trim(0,63).Lanczos4Resize(-1526461656,1913716392).RemoveGrain(mode=2)
p_2=last.trim(64,0).BicubicResize(-1526461656,1913716392,0.2,0.4).deen("c3d",0,6,8,3)
p_1+p_2
running the program (in debug mode) i got a "Invalid memory access"
Any help ?
thanks !!!
BHH
Ok, auto-resolved !
put a
after
put a
Code: Select all
FreeMemory(mem)after
BHHFileSeek(0)
WriteData(mem,Lof()+ctr)
CloseFile(0)
well not so true...
i try using this routines for changing at least 150 values...
i got memory error
BUT if i use i got less problem...
BHH
i try using this routines for changing at least 150 values...
i got memory error
BUT if i use
Code: Select all
sz=Lof()*100 BHH
Hiya buzzqw,
Yeah, the thing was a bit of a joke and slung together. One of the issues is the size of memory needed.
If the original string is shorter than the replacement string, then divide the source file size by the length of the original string, round up, and then multiply by the length of the replacement string.
So:
Source file: ABABABAB (8 bytes)
Replacing AB with ABC (2 with 3)
.. 8/2=4
.. 4*3=12
ABCABCABCABC (12 bytes)
Don't rely too much on that code though, it was an in fun thing. I think it is better to do a line-by-liner.
Edit:
If it still crashes, blame Trond.
Yeah, the thing was a bit of a joke and slung together. One of the issues is the size of memory needed.
Worst case is that the the source file is filled with a pattern of the string to be replaced.Dare2 wrote:Assumes file won't grow to double size.
If the original string is shorter than the replacement string, then divide the source file size by the length of the original string, round up, and then multiply by the length of the replacement string.
So:
Source file: ABABABAB (8 bytes)
Replacing AB with ABC (2 with 3)
.. 8/2=4
.. 4*3=12
ABCABCABCABC (12 bytes)
Don't rely too much on that code though, it was an in fun thing. I think it is better to do a line-by-liner.
Edit:
If it still crashes, blame Trond.
@}--`--,-- A rose by any other name ..
Replacewith
Code: Select all
sz=Lof()*100 Code: Select all
sz = Lof() + (Len(newStr.s)-Len(oldStr.s))*Lof()Updated to PB4B3 w/ corrections
I updated the code to work with PB4B3 w/ the corrections you guys made, except for Trond's as I couldnt find that sz=Lof()*100 anywhere in the code ..
Hmm, even though it starts, and on a 6K file, locks up the cpu to 100% with no progress
I still updated it to PB4 
Code: Select all
Procedure ChangeStrings(Filename.s,oldStr.s,newStr.s)
OpenFile(0, Filename)
mem=AllocateMemory(Lof(0)*2)
ReadData(0,mem,Lof(0)*2)
While ptr<=((Lof(0)*2)/2)+ctr
If CompareMemory(@oldStr,mem+ptr,Len(oldStr))
If Len(oldStr)-Len(newStr)<0
CopyMemory(mem+ptr,mem+ptr+((Len(oldStr)-Len(newStr)) * -1),(Lof(0)*2)-(ptr + ((Len(oldStr)-Len(newStr)) * -1)))
CopyMemory(@newStr,mem+ptr,Len(newStr))
ElseIf Len(oldStr)-Len(newStr)>0
CopyMemory(@newStr,mem+ptr,Len(newStr))
CopyMemory(mem+ptr+Len(oldStr),mem+ptr+Len(newStr),(Lof(0)*2)-(ptr + ((Len(oldStr)-Len(newStr)) * -1)))
Else
CopyMemory(@newStr,mem+ptr,Len(newStr))
EndIf
ctr-(Len(oldStr)-Len(newStr))
ptr+(Len(oldStr)+(Len(oldStr)-Len(newStr)))-1
EndIf
ptr+1
Wend
FileSeek(0,0)
WriteData(0,mem,Lof(0)+ctr)
CloseFile(0)
FreeMemory(mem)
EndProcedure



