PDA

View Full Version : forum mutilates the code I try to post



Chebmaster
17-04-2007, 12:10 PM
Namely, in the construct

{$ifdef win32}
...
{$else}
...
{$endif}

it removes all lines from {$else} (including it) up to {$endif}.
No matter in which form I post (as code or as plain text).

The probleam thread here:
http://www.pascalgamedevelopment.com/viewtopic.php?t=4277

The code could be seen here:
http://freepascal.ru/forum/viewtopic.php?t=2159

WILL
17-04-2007, 01:49 PM
{$ifdef win32}
SoYouCantSeeMe;
{$else}
OrMeEither;
{$endif}

Hmm.... seems like I can see it. :?

{$ifdef fpc}
{$mode delphi}
{$endif}

That one too.


{$ifdef fpc}
{$mode delphi}
{$endif}

And that one.

Was there something a bit more specific that you were having trouble with in terms of different characters between the { and } brackets?

Chebmaster
17-04-2007, 02:45 PM
The only specific I can think of is that I was trying to edit a very old post. Other than that I have no idea.

The code itself, I assume, you saw (the second link is the Russian forum page I posted it on).


----------------------------
unit cl_pms;

{$ifdef fpc}
{$mode delphi}
{$endif}

interface

uses
SysUtils {$ifdef win32}, Windows{$else}, baseunix {$endif};

function ThisIsAnOnlyInstance: boolean;

implementation

{$ifdef win32}

var
M: THandle;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var N: string;
begin
Result:=True;
N:=ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
M:=OpenMutex(MUTEX_MODIFY_STATE, False, PChar(N));
if M = 0 then M:=CreateMutex(nil, True, PChar(N))
else begin
if WaitForSingleObject(M, 0) <WAIT_ABANDONED>=8)and(copy(ParamStr(0),1, 8) <> '/tmp/upx')))
then begin
Exit(False);
end;
end;
end;
AssignFile(t, Fn);
Rewrite(t);
Writeln(t, fpGetPid());
CloseFile(t);
Except
End;
Di:=Result;
end;
{$endif}

initialization
finalization
Try
{$ifdef win32}
if Di then ReleaseMutex(M);
{$else}
if Di and FileExists(Fn) then DeleteFile(Fn);
{$endif}
Except End;
end.

unit cl_pms;

{$ifdef fpc}
{$mode delphi}
{$endif}

interface

uses
SysUtils {$ifdef win32}, Windows{$else}, baseunix {$endif};

function ThisIsAnOnlyInstance: boolean;

implementation

{$ifdef win32}

var
M: THandle;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var N: string;
begin
Result:=True;
N:=ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
M:=OpenMutex(MUTEX_MODIFY_STATE, False, PChar(N));
if M = 0 then M:=CreateMutex(nil, True, PChar(N))
else begin
if WaitForSingleObject(M, 0) <WAIT_ABANDONED>=8)and(copy(ParamStr(0),1, 8) <> '/tmp/upx')))
then begin
Exit(False);
end;
end;
end;
AssignFile(t, Fn);
Rewrite(t);
Writeln(t, fpGetPid());
CloseFile(t);
Except
End;
Di:=Result;
end;
{$endif}

initialization
finalization
Try
{$ifdef win32}
if Di then ReleaseMutex(M);
{$else}
if Di and FileExists(Fn) then DeleteFile(Fn);
{$endif}
Except End;
end.

Chebmaster
17-04-2007, 02:48 PM
There is it again. I try to post it, the chunk between lines end; and {$endif} is just not there :evil:

---------------------------- try the said chunk only:
{$else}

var
Fn: string;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var
i: integer;
t: Text;
s: stat;
begin
Result:=True;
Fn:= '/tmp/.' + ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
Try
if FileExists(Fn) then begin
i:=0;
AssignFile(t, Fn);
Reset(t);
Readln(t, i);
CloseFile(t);
if i = fpGetPid() then Exit
else
if DirectoryExists('/proc/' + IntToStr(i)) then begin
if not FileExists('/proc/' + IntToStr(i) + '/exe') //I'm unsure if
// any *nix creates one or it's just my distribution
or ((ExtractFileName(fpReadLink ('/proc/' + IntToStr(i) + '/exe')) = ExtractFileName(ParamStr(0)))
and not ((Length(ParamStr(0)) >=8)and(copy(ParamStr(0),1, 8) <> '/tmp/upx')))
then begin
Exit(False);
end;
end;
end;
AssignFile(t, Fn);
Rewrite(t);
Writeln(t, fpGetPid());
CloseFile(t);
Except
End;
Di:=Result;
end;

Chebmaster
17-04-2007, 02:48 PM
{$else}

var
Fn: string;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var
i: integer;
t: Text;
s: stat;
begin
Result:=True;
Fn:= '/tmp/.' + ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
Try
if FileExists(Fn) then begin
i:=0;
AssignFile(t, Fn);
Reset(t);
Readln(t, i);
CloseFile(t);
if i = fpGetPid() then Exit
else
if DirectoryExists('/proc/' + IntToStr(i)) then begin
if not FileExists('/proc/' + IntToStr(i) + '/exe') //I'm unsure if
// any *nix creates one or it's just my distribution
or ((ExtractFileName(fpReadLink ('/proc/' + IntToStr(i) + '/exe')) = ExtractFileName(ParamStr(0)))
and not ((Length(ParamStr(0)) >=8)and(copy(ParamStr(0),1, 8) <> '/tmp/upx')))
then begin
Exit(False);
end;
end;
end;
AssignFile(t, Fn);
Rewrite(t);
Writeln(t, fpGetPid());
CloseFile(t);
Except
End;
Di:=Result;
end;

Chebmaster
17-04-2007, 02:49 PM
{$ifdef win32}

....

{$else}

var
Fn: string;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var
i: integer;
t: Text;
s: stat;
begin
Result:=True;
Fn:= '/tmp/.' + ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
Try
if FileExists(Fn) then begin
i:=0;
AssignFile(t, Fn);
Reset(t);
Readln(t, i);
CloseFile(t);
if i = fpGetPid() then Exit
else
if DirectoryExists('/proc/' + IntToStr(i)) then begin
if not FileExists('/proc/' + IntToStr(i) + '/exe') //I'm unsure if
// any *nix creates one or it's just my distribution
or ((ExtractFileName(fpReadLink ('/proc/' + IntToStr(i) + '/exe')) = ExtractFileName(ParamStr(0)))
and not ((Length(ParamStr(0)) >=8)and(copy(ParamStr(0),1, 8) <> '/tmp/upx')))
then begin
Exit(False);
end;
end;
end;
AssignFile(t, Fn);
Rewrite(t);
Writeln(t, fpGetPid());
CloseFile(t);
Except
End;
Di:=Result;
end;
{$endif}

Chebmaster
17-04-2007, 02:50 PM
if posted alone it works... :shock:

I'm afraid we need an exorcist here :(

savage
17-04-2007, 05:51 PM
I think I'm getting too old for this ;), cause I can't see what's wrong here.

WILL
17-04-2007, 08:28 PM
Send in Christina! :rambo:

She's our resident commando code monkey as of late. :D

Chebmaster
17-04-2007, 08:45 PM
cause I can't see what's wrong here.
basically, I post
A
B
C,

it appears on the forum page as
A
C.

I then post
B

It looks pretty B.

I cannot post the whole Pascal code chunk here because of this, but you can find it at this page: http://freepascal.ru/forum/viewtopic.php?t=2159

Try to copy-paste the first Pascal code chunk from there to here, and you'll see that the middle of it is mysteriously missing in your post. namely, the Unix version of ThisIsAnOnlyInstance function, the accompanying variable declarations and the {$else} directive. They are just not there.

Nitrogen
18-04-2007, 09:04 AM
Did you try disabling HTML in your post? I know I had some issues when trying to post code with angle brackets <like this> and it thought it was HTML...

savage
18-04-2007, 11:14 AM
Disabling HTML seems to work...

unit cl_pms;

{$ifdef fpc}
{$mode delphi}
{$endif}

interface

uses
SysUtils {$ifdef win32}, Windows{$else}, baseunix {$endif};

function ThisIsAnOnlyInstance: boolean;

implementation

{$ifdef win32}

var
M: THandle;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var N: string;
begin
Result:=True;
N:=ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
M:=OpenMutex(MUTEX_MODIFY_STATE, False, PChar(N));
if M = 0 then M:=CreateMutex(nil, True, PChar(N))
else begin
if WaitForSingleObject(M, 0) <> WAIT_ABANDONED
then Result:=False;
end;
Di:=Result;
end;

{$else}

var
Fn: string;
Di: boolean = false;

function ThisIsAnOnlyInstance: boolean;
var
i: integer;
t: Text;
s: stat;
begin
Result:=True;
Fn:= '/tmp/.' + ChangeFileExt(ExtractFileName(ParamStr(0)),'') + 'SingleInstanceMutex';
Try
if FileExists(Fn) then begin
i:=0;
AssignFile(t, Fn);
Reset(t);
Readln(t, i);
CloseFile(t);
if i = fpGetPid() then Exit
else
if DirectoryExists('/proc/' + IntToStr(i)) then begin
if not FileExists('/proc/' + IntToStr(i) + '/exe') //I'm unsure if
// any *nix creates one or it's just my distribution
or ((ExtractFileName(fpReadLink ('/proc/' + IntToStr(i) + '/exe')) = ExtractFileName(ParamStr(0)))
and not ((Length(ParamStr(0)) >=8)and(copy(ParamStr(0),1, 8) <> '/tmp/upx')))
then begin
Exit(False);
end;
end;
end;
AssignFile(t, Fn);
Rewrite(t);
Writeln(t, fpGetPid());
CloseFile(t);
Except
End;
Di:=Result;
end;
{$endif}

initialization
finalization
Try
{$ifdef win32}
if Di then ReleaseMutex(M);
{$else}
if Di and FileExists(Fn) then DeleteFile(Fn);
{$endif}
Except End;
end.

Chebmaster
18-04-2007, 06:04 PM
Oh. :idea: Thank you! :D
I either forgot to disable it from the start, or my profile settings got reset somehow.