Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: forum mutilates the code I try to post

  1. #1

    forum mutilates the code I try to post

    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...pic.php?t=4277

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

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: forum mutilates the code I try to post

    [pascal]{$ifdef win32}
    SoYouCantSeeMe;
    {$else}
    OrMeEither;
    {$endif}[/pascal]

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

    [pascal]{$ifdef fpc}
    {$mode delphi}
    {$endif}[/pascal]

    That one too.

    Code:
    {$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?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #3

    forum mutilates the code I try to post

    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>=and(copy(ParamStr(0),1, <> '/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.

    [pascal]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>=and(copy(ParamStr(0),1, <> '/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.
    [/pascal]

  4. #4

    forum mutilates the code I try to post

    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)) >=and(copy(ParamStr(0),1, <> '/tmp/upx')))
    then begin
    Exit(False);
    end;
    end;
    end;
    AssignFile(t, Fn);
    Rewrite(t);
    Writeln(t, fpGetPid());
    CloseFile(t);
    Except
    End;
    Di:=Result;
    end;

  5. #5

    forum mutilates the code I try to post

    [pascal]{$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)) >=and(copy(ParamStr(0),1, <> '/tmp/upx')))
    then begin
    Exit(False);
    end;
    end;
    end;
    AssignFile(t, Fn);
    Rewrite(t);
    Writeln(t, fpGetPid());
    CloseFile(t);
    Except
    End;
    Di:=Result;
    end; [/pascal]

  6. #6

    forum mutilates the code I try to post

    [pascal]{$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)) >=and(copy(ParamStr(0),1, <> '/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} [/pascal]

  7. #7

    forum mutilates the code I try to post

    if posted alone it works... :shock:

    I'm afraid we need an exorcist here

  8. #8

    forum mutilates the code I try to post

    I think I'm getting too old for this , cause I can't see what's wrong here.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  9. #9
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    forum mutilates the code I try to post

    Send in Christina! :rambo:

    She's our resident commando code monkey as of late.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  10. #10

    forum mutilates the code I try to post

    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.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •