SA-MP Forums Archive
[Tool/Web/Other] [PHP] PAWN Indentation - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Tools and Files (https://sampforum.blast.hk/forumdisplay.php?fid=82)
+---- Thread: [Tool/Web/Other] [PHP] PAWN Indentation (/showthread.php?tid=480613)



[PHP] PAWN Indentation - Emmet_ - 11.12.2013

Script Indentation

Introduction
This is just a VERY simple PHP script that indents any text that's inputted into the text box. I'm slightly inexperienced with PHP since I'm a beginner, so that's why it looks like shit.

How it works
It works by automatically inserting 4 spaces in front of each unindentated piece of code - or tries to fix it. Also works well with opening braces.

I can't get this to work for some reason:

pawn Код:
new
    a,
    b,
    c;
But I'm trying to make it work. It shouldn't be hard, since it works with other code, right?

Images
Since my web host is down, I only have images, sorry.



Which then outputs the following code after pressing the 'Indent' button:

pawn Код:
public OnPlayerConnect(playerid)
{
    if (IsPlayerNPC(playerid))
    {
        return 1;
    }
    else
    {
        SendClientMessageToAll(-1, "Wow, a player connected!");
    }    
    return 1;
}
It also works tough on multiple opening braces!



Output:

pawn Код:
public OnPlayerConnect(playerid)
{
    if (TestIndentation())
    {
        if(TestIndentation())
        {
            if(TestIndentation())
            {
                if(TestIndentation())
                {
                }
            }
        }
    }
    return 1;
}
Download
indent.zip

If I did anything wrong, please point it out! I'm planning on learning more about PHP and I want to know what's right - thank you!


Re: [PHP] PAWN Indentation - tyler12 - 11.12.2013

Useful.

You might want to fix the 'output':



Re: [PHP] PAWN Indentation - Emmet_ - 11.12.2013

Quote:
Originally Posted by tyler12
Посмотреть сообщение
Useful.

You might want to fix the 'output':
I don't get what you mean about "fixing the output", sorry.

And thanks by the way!


Re: [PHP] PAWN Indentation - tyler12 - 11.12.2013

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
I don't get what you mean about "fixing the output", sorry.

And thanks by the way!
The output is different from the code in the image; it should be:

pawn Код:
public OnPlayerConnect(playerid)
{
    if( IsPlayerNPC(playerid))
    {
        return 1;
    }
    else SendClientMessageToAll(0xFFFFFF,"A player connected!");
    return 1;
}
edit;


Re: [PHP] PAWN Indentation - Emmet_ - 11.12.2013

Oh, woops. I was testing it multiple times and I guess I inserted the wrong code. Thanks!


Re: [PHP] PAWN Indentation - Akira297 - 11.12.2013

Haven't tested it. However, how much of lining could it take before an overload of heap? Seems useful however.


Re: [PHP] PAWN Indentation - Emmet_ - 11.12.2013

Quote:
Originally Posted by Akira297
Посмотреть сообщение
Haven't tested it. However, how much of lining could it take before an overload of heap? Seems useful however.
It seems to work good on a 25,000 line script. However, it completely broke on one of the other scripts I had, so I'll have to fix that up right away.

I wouldn't recommend using this for over 5,000 lines. This was just a tool I made for personal use to indent some of the small scripts I had.


Re: [PHP] PAWN Indentation - Memoryz - 11.12.2013

PHP код:
if (!isset($_POST['IndentText']))

    echo 
"Oh shit, an error occurred.";
    return 
0;

If you are trying to prevent the rest of the PHP from continuing on, I'd suggest doing this rather than returning 0. (I don't even think 'return 0' will stop the script from executing)

PHP код:
if (!isset($_POST['IndentText']))

   die(
"Oh shit, an error occurred.");

Also, indent.php can be a .html file since it doesn't execute any PHP within the file.

I like it though, very useful.


Re: [PHP] PAWN Indentation - Emmet_ - 11.12.2013

Alright, version 2 is now released. This script no longer breaks on multidimensional arrays!

Quote:
Originally Posted by Memoryz
Посмотреть сообщение
PHP код:
if (!isset($_POST['IndentText']))

    echo 
"Oh shit, an error occurred.";
    return 
0;

If you are trying to prevent the rest of the PHP from continuing on, I'd suggest doing this rather than returning 0. (I don't even think 'return 0' will stop the script from executing)

PHP код:
if (!isset($_POST['IndentText']))

   die(
"Oh shit, an error occurred.");

Also, indent.php can be a .html file since it doesn't execute any PHP within the file.

I like it though, very useful.
Thanks for the info! I've just updated the script. I was also thinking of implementing both of them in one, so when someone presses "Indent", the code will automatically be indented without redirecting to a new page.


Re: [PHP] PAWN Indentation - Djole1337 - 11.12.2013

lel php...

Javascript plz.


Re: [PHP] PAWN Indentation - Memoryz - 11.12.2013

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
lel php...

Javascript plz.
You don't need to enter a thread labelled "PHP" and throw around your stubborn mentality, comparing a server-side language to a client-side language, not to mention you wrote "LOL" incorrectly.