Advertisement
dragony

SA:MP Missing Bracket Finder PWN v1.1

May 16th, 2013
1,280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.74 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. //Author: DraGoN FiRe
  4. //Version 1.1
  5.  
  6. public OnFilterScriptInit()
  7. {
  8.     print("\n\n\n|----------------------------------|\n");//Credits :P
  9.     print("      Missing Bracket Finder");
  10.     print("                by");
  11.     print("           DraGoN FiRe\n");
  12.     print("|----------------------------------|\n\n\n");
  13.     if(!fexist("mbFile.lst"))
  14.     {//Checking if file exist.
  15.         print("Missing file \"mbFile.lst\", you must put preprocessed script file which \nyou want to check in scriptfiles folder and to name it \"mbFile.lst\".");//Checking if file exists in certain folder
  16.         print("To get .lst file you need to compile your script with following params in \npawn.cfg \"-l -;+ -(+ -\\\", without quotes.");
  17.         return 1;
  18.     }
  19.     new time = GetTickCount();//Getting current server time so we can calculate execution time
  20.     print("Working...\n\n\n");
  21.     new File:mbFile = fopen("mbFile.lst", io_read);//Opening File...
  22.     new OpenedBrackets, ClosedBrackets, LastGoodLine, line, string[512], CountChecks, bool:Delete = false;//Vars
  23.     while(fread(mbFile, string))
  24.     {//Reading File
  25.         line++;
  26.         if(strfind(string, "\\", false) != -1)
  27.         {//Removing Special simbols
  28.             for(new i = 0; string[i] != '\0'; i++)
  29.             {
  30.                 if(string[i] == '\\')
  31.                 {
  32.                     strdel(string, i, i+2);
  33.                     i--;
  34.                 }
  35.             }
  36.         }
  37.         if(Delete && strfind(string, "\"", false) == -1)
  38.         {//If there is
  39.             continue;
  40.         }
  41.         else if(strfind(string, "\"", false) != -1)
  42.         {//Removing Text Areas
  43.             new posX, posY;
  44.             for(new i = 0; string[i] != '\0'; i++)
  45.             {
  46.                 if(string[i] == '"')
  47.                 {
  48.                     if(Delete)
  49.                     {
  50.                         strdel(string, 0, i+1);
  51.                         Delete = false;
  52.                         i = 0;
  53.                         continue;
  54.                     }
  55.                     if(!posX) posX = i;
  56.                     else if(!posY) posY = i;
  57.                 }
  58.                 if(posX && posY)
  59.                 {
  60.                     posY++;
  61.                     strdel(string, posX, posY);
  62.                     i -= (posY-posX);
  63.                     posX = posY = 0;
  64.                 }
  65.             }
  66.             if(posX && !posY)
  67.             {//If there is opened quote (text area with break line)
  68.                 strdel(string, posX, strlen(string));
  69.                 Delete = true;
  70.             }
  71.         }
  72.         if(strfind(string, "public ", false) != -1 || strfind(string, "forward ", false) != -1 || strfind(string, "stock ", false) != -1)
  73.         {//Searching for valid checkpoints, where brackets must match
  74.             if(OpenedBrackets != ClosedBrackets)
  75.             {
  76.                 break;
  77.             }
  78.             else
  79.             {//If number of brackets match we can save this as last good line...
  80.                 LastGoodLine = line;
  81.                 CountChecks++;
  82.             }
  83.         }
  84.         if(strfind(string, "{", true) != -1)
  85.         {//Searching for open brackets and counting them
  86.             for(new i = 0; string[i] != '\0'; i++)
  87.             {
  88.                 if(string[i] == '{')
  89.                 {
  90.                     OpenedBrackets++;
  91.                 }
  92.             }
  93.         }
  94.         if(strfind(string, "}", true) != -1)
  95.         {//Searching for closed brackets and counting them
  96.             for(new i = 0; string[i] != '\0'; i++)
  97.             {
  98.                 if(string[i] == '}')
  99.                 {
  100.                     ClosedBrackets++;
  101.                 }
  102.             }
  103.         }
  104.     }
  105.     if(OpenedBrackets == ClosedBrackets) print("Everything is fine! ;) Enjoy!\n\n\n");
  106.     if(OpenedBrackets != ClosedBrackets)
  107.     {
  108.         if(OpenedBrackets > ClosedBrackets) printf("Some bracket isn't closed on lines between %d and %d.\n\n\n", LastGoodLine, line);
  109.         if(OpenedBrackets < ClosedBrackets) printf("Some bracket isn't opened on lines between %d and %d.\n\n\n", LastGoodLine, line);
  110.     }
  111.     print("|---------------Stats---------------|");
  112.     printf("Opened Brackets: %d\nClosed Brackets: %d\nTotal lines: %d\nTime to execute: %.2fsek\nTotal CheckPoints: %d", OpenedBrackets, ClosedBrackets, line, float(GetTickCount() - time)/1000, CountChecks);
  113.     print("|-----------------------------------|");
  114.     return 1;
  115. }
  116.  
  117. public OnFilterScriptExit()
  118. {
  119.     return 1;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement