SRL Archive - Lape

Write not writing a new line


rj

2015-04-26 15:40:10

I'm trying to debug something, but writeln isn't writing a new line..


writeln('1');
writeln('2');

This is supposed to be 2 lines right?? Right!

but when I debug my code, this is what the debug looks like

Compiled successfully in 281 ms.
Scanning for files to update..
Path = s=Authors[txt]
result=C:\Simba\Includes\Alotic\
C:\Simba\Includes\Alotic\
FilePath = Authors[txt]
s=Authors[txt]
result=C:\Simba\Includes\Alotic\
s=Authors[txt]
result=C:\Simba\Includes\Alotic\
Path = s=Files[txt]
result=C:\Simba\Includes\Alotic\
C:\Simba\Includes\Alotic\
FilePath = Files[txt]
s=Files[txt]
result=C:\Simba\Includes\Alotic\
s=Files[txt]
result=C:\Simba\Includes\Alotic\
Path = s=lib\Alotic[simba]
result=C:\Simba\Includes\Alotic\lib\ = s=
C:\Simba\Includes\Alotic\lib\ = s=
FilePath = lib\Alotic[simba]
s=lib\Alotic[simba]
result=C:\Simba\Includes\Alotic\lib\b\Alotic[
s=lib\Alotic[simba]
result=C:\Simba\Includes\Alotic\lib\b\Alotic[
s=lib\Alotic[simba]
result=C:\Simba\Includes\Alotic\lib\b\Alotic[
OpenFile - Exception. Could not open file: C:\Simba\Includes\Alotic\lib\Alotic.simba
Creating new File C:\Simba\Includes\Alotic\lib\Alotic.simba
CreateFile - Exception. Could not create file: C:\Simba\Includes\Alotic\lib\Alotic.simba
Path = s=lib\Updater[simba]
result=C:\Simba\Includes\Alotic\lib\ = s=
C:\Simba\Includes\Alotic\lib\ = s=
FilePath = lib\Updater[simba]
s=lib\Updater[simba]
result=C:\Simba\Includes\Alotic\lib\ = s=
s=lib\Updater[simba]
result=C:\Simba\Includes\Alotic\lib\ = s=
s=lib\Updater[simba]
result=C:\Simba\Includes\Alotic\lib\ = s=
OpenFile - Exception. Could not open file: C:\Simba\Includes\Alotic\lib\Updater.simba
Creating new File C:\Simba\Includes\Alotic\lib\Updater.simba
CreateFile - Exception. Could not create file: C:\Simba\Includes\Alotic\lib\Updater.simba
Path = s=lib\core\globals[simba]
result=C:\Simba\Includes\Alotic\lib\core\
C:\Simba\Includes\Alotic\lib\core\
FilePath = lib\core\globals[simba]
s=lib\core\globals[simba]
result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\globals[simba]
result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\globals[simba]
result=C:\Simba\Includes\Alotic\lib\core\
Unable to Free https://raw.githubusercontent.com/officerBarbrady/Alotic/master/lib/core/globals.simba ProSocks Error
OpenFile - Exception. Could not open file: C:\Simba\Includes\Alotic\lib\core\globals.simba
Creating new File C:\Simba\Includes\Alotic\lib\core\globals.simba
CreateFile - Exception. Could not create file: C:\Simba\Includes\Alotic\lib\core\globals.simba
Path = s=lib\core\mainscreen[simba]
result=C:\Simba\Includes\Alotic\lib\core\
C:\Simba\Includes\Alotic\lib\core\
FilePath = lib\core\mainscreen[simba]
s=lib\core\mainscreen[simba]
result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\mainscreen[simba]
result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\mainscreen[simba]
result=C:\Simba\Includes\Alotic\lib\core\

Specifically

Path = s=Authors[txt]
Path = s=lib\Alotic[simba]
result=C:\Simba\Includes\Alotic\lib\ = s=
C:\Simba\Includes\Alotic\lib\ = s=

And other places that you can see (pretty much anywhere there is more than 1 =)

There is no way Path can be equal to ' s=Authors'

even when I create a new line after every write, it still does it

Compiled successfully in 235 ms.
Scanning for files to update..
Path = s=Authors[txt]

result=C:\Simba\Includes\Alotic\

C:\Simba\Includes\Alotic\

FilePath = Authors[txt]

s=Authors[txt]

result=C:\Simba\Includes\Alotic\

s=Authors[txt]

result=C:\Simba\Includes\Alotic\

Path = s=Files[txt]

result=C:\Simba\Includes\Alotic\

C:\Simba\Includes\Alotic\

FilePath = Files[txt]

s=Files[txt]

result=C:\Simba\Includes\Alotic\

s=Files[txt]

result=C:\Simba\Includes\Alotic\

Path = s=lib\Alotic[simba]

result=C:\Simba\Includes\Alotic\lib\ = s=
C:\Simba\Includes\Alotic\lib\ = s=
FilePath = lib\Alotic[simba]

s=lib\Alotic[simba]

result=C:\Simba\Includes\Alotic\lib\b\Alotic[

s=lib\Alotic[simba]

result=C:\Simba\Includes\Alotic\lib\b\Alotic[

s=lib\Alotic[simba]

result=C:\Simba\Includes\Alotic\lib\b\Alotic[

OpenFile - Exception. Could not open file: C:\Simba\Includes\Alotic\lib\Alotic.simba
Creating new File C:\Simba\Includes\Alotic\lib\Alotic.simba
CreateFile - Exception. Could not create file: C:\Simba\Includes\Alotic\lib\Alotic.simba
Path = s=lib\Updater[simba]

result=C:\Simba\Includes\Alotic\lib\ = s=
C:\Simba\Includes\Alotic\lib\ = s=
FilePath = lib\Updater[simba]

s=lib\Updater[simba]

result=C:\Simba\Includes\Alotic\lib\ = s=
s=lib\Updater[simba]

result=C:\Simba\Includes\Alotic\lib\ = s=
s=lib\Updater[simba]

result=C:\Simba\Includes\Alotic\lib\ = s=
OpenFile - Exception. Could not open file: C:\Simba\Includes\Alotic\lib\Updater.simba
Creating new File C:\Simba\Includes\Alotic\lib\Updater.simba
CreateFile - Exception. Could not create file: C:\Simba\Includes\Alotic\lib\Updater.simba
Path = s=lib\core\globals[simba]

result=C:\Simba\Includes\Alotic\lib\core\
C:\Simba\Includes\Alotic\lib\core\
FilePath = lib\core\globals[simba]

s=lib\core\globals[simba]

result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\globals[simba]

result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\globals[simba]

result=C:\Simba\Includes\Alotic\lib\core\
Unable to Free https://raw.githubusercontent.com/officerBarbrady/Alotic/master/lib/core/globals.simba ProSocks Error
OpenFile - Exception. Could not open file: C:\Simba\Includes\Alotic\lib\core\globals.simba
Creating new File C:\Simba\Includes\Alotic\lib\core\globals.simba
CreateFile - Exception. Could not create file: C:\Simba\Includes\Alotic\lib\core\globals.simba
Path = s=lib\core\mainscreen[simba]

result=C:\Simba\Includes\Alotic\lib\core\
C:\Simba\Includes\Alotic\lib\core\
FilePath = lib\core\mainscreen[simba]

s=lib\core\mainscreen[simba]

result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\mainscreen[simba]

result=C:\Simba\Includes\Alotic\lib\core\
s=lib\core\mainscreen[simba]

result=C:\Simba\Includes\Alotic\lib\core\


You can run the script yourself to see:
//{$I Socks.Simba}
{$loadlib prosocks}


(*
Alotic include updater written by rj,
string functions by Janilabo, github page grabber by Brandon
*)

const
BASE_URL = 'https://raw.githubusercontent.com/officerBarbrady/Alotic/master/';
INCLUDE_PATH = 'C:\Simba\Includes\Alotic\';

type
TFileFormat = (FILE_PATH, WEB_PATH, DIRECTORY_PATH);

function mInc(var x: Integer; N: Integer = 1): Integer;
begin
Result := x;
x := (x + N);
end;

function mIncrease(var x: Integer; N: Integer = 1): Integer;
begin
x := (x + N);
Result := x;
end;

function mExplode(str: string; d: Char): TStringArray;
var
a, b, l, p, r, s: Integer;
begin
l := Length(str);
SetLength(Result, 1);
if (l > 0) then
begin
b := 1;
a := 1;
p := 0;
r := 0;
s := 0;
while (mInc(p) < l) do
if (str[p] = d) then
begin
Result[mInc(r)] := Copy(str, a, s);
if (b <= r) then
SetLength(Result, mIncrease(b, b));
a := (p + 1);
s := 0;
end else
s := (s + 1);
SetLength(Result, (r + 1));
Result[r] := Copy(str, a, s);
end else
Result[0] := str;
end;

function mLines(str: string): TStringArray;
begin
if (Length(str) = 0) then
begin
SetLength(Result, 1);
Result[0] := str;
end else
Result := mExplode(str, #10);
end;

function Before(s, str: string): string;
var
p: Integer;
begin
if (Length(s) < Length(str)) then
begin
p := Pos(s, str);
if (p > 1) then
Result := Copy(str, 1, (p - 1))
else
Result := '';
end else
Result := '';
end;

function lastAfter(s, str:string):string;
var
i, l, marker:integer;
begin
l := length(str);
for i := l downto 1 do
if (str[i] = s) then
begin
marker := i;
break;
end;
if (marker <> 0) then
begin
setLength(result, l - marker);
for i := 1 to marker do
result[i] := str[i];
end;
end;

function formatPath(s:string;formatType:TFileFormat):string;
var
base, fileType:string;
begin
case formatType of
FILE_PATH:
begin
fileType := between('[', ']', s);
base := before('[', s);
result := INCLUDE_PATH + base + '.' + fileType;
end;
WEB_PATH:
begin
s := replace(s, '\', '/', [rfReplaceall]);
fileType := between('[', ']', s);
base := before('[', s);
result := base + '.' + fileType;
end;
DIRECTORY_PATH:
begin
writeln('s=',s,#13,#10);
result := INCLUDE_PATH + lastAfter('\', s);
writeln('result=',result,#13,#10);
end;
end;
end;

Function GetPageEx(URL: String): String;
var
S: SSLSocket;
res: ProMemoryStruct;
begin
Pro_InitSocket(S, nil, nil, nil, nil);
Pro_CreateSocket(S, '');
Pro_SetSSL(S, false, false, true);
Pro_SetURL(S, URL);
Pro_DoGetEx(S, res);

{$IFDEF LAPE}
SetLength(Result, res.size);
MemMove(res.memory^, Result[1], res.size);
{$ELSE}
Result := res.memory;
{$ENDIF}
try
Pro_FreeSocket(S);
except
WriteLn('Unable to Free ' + URL + ' ProSocks Error');
end;
end;



procedure updateInclude();
var
i, c, tmpFile:integer;
p:string;
filePaths:TStringArray;
fileContents:string;
begin
writeln('Scanning for files to update..');
p := getPageEx(BASE_URL + 'Files.txt');
//writeln(BASE_URL + 'Files.txt');
filePaths := mLines(p);
//writeln(filePaths);
for i := 0 to high(filePaths) do
begin
writeln('Path = ', formatPath(filePaths[i], DIRECTORY_PATH),#13,#10);
writeln('FilePath = ', filePaths[i],#13,#10);
if (filePaths[i] <> '') then
begin
if (formatPath(filePaths[i], DIRECTORY_PATH) <> '') then
begin
if (not directoryExists(formatPath(filePaths[i], DIRECTORY_PATH))) then
createDirectory(formatPath(filePaths[i], DIRECTORY_PATH));
end;
p := '';
p := getPageEx(BASE_URL + formatPath(filePaths[i], WEB_PATH));
try
tmpFile := openFile(formatPath(filePaths[i], FILE_PATH), false);
readFileString(tmpFile, fileContents, fileSize(tmpFile));
closeFile(tmpFile);
if (length(fileContents) <> length(p)) then
begin
tmpFile := reWriteFile(formatPath(filePaths[i], FILE_PATH), false);
if writeFileString(tmpFile, p) then
begin
c := c + 1;
writeln('Updated ', formatPath(filePaths[i], FILE_PATH));
end;
closeFile(tmpFile);
end;
except
try
writeln('Creating new File ', formatPath(filePaths[i], FILE_PATH));
tmpFile := createFile(formatPath(filePaths[i], FILE_PATH));
if (p <> '') then
begin
c := c + 1;
writeFileString(tmpFile, p);
end;
except
// writeln('Failed to create File ', formatPath(filePaths[i], FILE_PATH));
finally
if (tmpFile <> -1) then
closeFile(tmpFile);
end;
end;
end;
end;
writeln('Updated ' , c , ' Files');
end;

begin
updateInclude();
end.

Enslaved

2015-04-26 20:05:39

this is why simba needs a JIT debugger

slacky

2015-04-26 23:39:24

You're accessing and modifying memory outside side the scripts scope. This can quickly cause some unexpected errors, and weirdness (specially in this case). I ran your script, the second time I ran it, Simba crashed.
- lastAfter: Line 98 will go out of range.
- GetPageEx: Line 142 will go out of range when res.size is 0 (which it can be)
.. might be more

Could you clean up the script, like make sure there is no such errors, then see if the unexpected behavior is still there.