Archive: Problem with a long string


Problem with a long string
Hello all.

I have a strange problem. A co-worker asked me if I could make an exe that would simply copy the first line of a current text file into a new text file. I said, no problem, and quickly put together an nsi file using Instructor's LineRead function. (I also tried Afrow's Read from text file line number function too, and got the same problem). My problem is this, this text file i'm reading from has very long lines, over 3400 characters. I am using the long string build of NSIS 2.10, but am getting truncated output for both line read functions after character 1023.

I can however just StrCpy my variable with a string (same string that's in Doc1.txt) that is over 3400 characters (see below), and that works just fine. So I know my Long String build is working, but it seems that both line read functions I have tried still have the 1024 character limitation.

Any thoughts would be appreciated. I have attached the "Doc1.txt" file, so you can compile the below code and recreate the problem. Thanks all.


Name LineMove
OutFile LineMove.exe
AutoCloseWindow True
SilentInstall Silent

Var Source
Var String

Section ""

StrCpy $Source Doc1.txt

Push $Source
Push "1"
Call LineRead
Pop $String
MessageBox MB_OK "$String"

StrCpy $String "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg\
hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd\
efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza\
bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx\
yzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu\
vwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr\
stuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno\
pqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl\
mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi\
jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef\
ghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabc\
defghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw\
xyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst\
uvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopq\
rstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn\
opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk\
lmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh\
ijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde\
fghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab\
cdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy\
zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv\
wxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs\
tuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop\
qrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm\
nopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij\
klmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg\
hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd\
efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza\
bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx\
yzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu\
vwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr\
stuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno\
pqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl\
mnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi\
jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef\
ghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabc\
defghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw\
xyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst\
uvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopq\
rstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn\
opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk\
lmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh\
ijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde\
fghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"

MessageBox MB_OK "$String"

SectionEnd


Function LineRead
Exch $1
Exch
Exch $0
Exch
Push $2
Push $3
Push $4
ClearErrors

IfFileExists $0 0 error
IntOp $1 $1 + 0
IntCmp $1 0 error 0 plus
StrCpy $4 0
FileOpen $2 $0 r
IfErrors error
FileRead $2 $3
IfErrors +3
IntOp $4 $4 + 1
Goto -3
FileClose $2
IntOp $1 $4 + $1
IntOp $1 $1 + 1
IntCmp $1 0 error error

plus:
FileOpen $2 $0 r
IfErrors error
StrCpy $3 0
IntOp $3 $3 + 1
FileRead $2 $0
IfErrors +4
StrCmp $3 $1 0 -3
FileClose $2
goto end
FileClose $2

error:
SetErrors
StrCpy $0 ''

end:
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd

NSIS docs states that "strings are limited to 1024 characters" and thus this doesn't depend on the special build string limitation. This could be a feature request though.


1023 was actually hard-coded in the source code. I've fixed it and attached a patch. Version 2.13 will contain this fix, as well as the next nightly build. Thanks.


And updated the documentation. Thanks deguix.


Thank you so much for your help kichik. I'm a little unsure how to implement this patch though, I'm guessing I would need to use it to re-compile the makensis.exe file correct? I have not done that before, do you know when 2.13 will be released? Sorry for the bother, thanks again for your help.


Yes, you'd have to recompile. 2.13 will be released in about a month. The next nightly build will be built, well, this night. You can also write your own function to keep reading until it reaches a new line marker, the maximum string length or the end of the file.


Good to know, thanks again for your help kichik.