123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- function testRpl()
- {
- ToolUtilityScripts::appendLineToFunction("data/prototyping/prototyping.tscript", "Prototyping", "onDestroyGameServer", "//AAAAAAAAAAAAAAAAAAAAA");
- }
- function Tools::appendLineToFunction(%file, %nameSpace, %functionName, %appendLine)
- {
- %fileOutput = new ArrayObject(){};
- %fileObj = new FileObject(){};
-
- %insideFunction = false;
- %scopeDepth = 0;
-
- if ( %fileObj.openForRead( %file ) )
- {
- while ( !%fileObj.isEOF() )
- {
- %line = %fileObj.readLine();
-
- if(strIsMatchExpr("*function *(*)*", %line))
- {
- %fileOutput.add(%line);
-
- %start = strpos(%line, "function ");
- %end = strpos(%line, "(", %start);
-
- %scannedFunctionName = "";
- if(%start != -1 && %end != -1)
- {
- %scannedFunctionName = getSubStr(%line, %start + 9, %end-%start-9);
- }
-
- %matchesFunctionSig = false;
- if(%nameSpace !$= "")
- {
- if(%scannedFunctionName $= (%nameSpace @ "::" @ %functionName))
- %matchesFunctionSig = true;
- }
- else
- {
- if(%scannedFunctionName $= %functionName)
- %matchesFunctionSig = true;
- }
-
- if(!%matchesFunctionSig)
- continue;
-
- %insideFunction = true;
-
- if(strIsMatchExpr("*{*", %line))
- {
- %scopeDepth++;
- }
- if(strIsMatchExpr("*}*", %line))
- {
- %scopeDepth--;
- }
- }
- else
- {
- if(%insideFunction && strIsMatchExpr("*{*", %line))
- {
- %scopeDepth++;
- }
- if(%insideFunction && strIsMatchExpr("*}*", %line))
- {
- %scopeDepth--;
-
- if(%scopeDepth == 0) //we've fully backed out of the function scope, so resolve back to the parent
- {
- %insideFunction = false;
- %fileOutput.add(%appendLine);
- }
- }
-
- %fileOutput.add(%line);
- }
- }
- %fileObj.close();
- }
-
- if ( %fileObj.openForWrite( %file ) )
- {
- for(%i=0; %i < %fileOutput.count(); %i++)
- {
- %line = %fileOutput.getKey(%i);
-
- %fileObj.writeLine(%line);
- }
- %fileObj.close();
- }
- }
- function Tools::findInFile(%file, %findText, %startingLineId)
- {
- if(%startingLineId $= "")
- %startingLineId = 0;
-
- %fileObj = new FileObject(){};
-
- if ( %fileObj.openForRead( %file ) )
- {
- %lineId = 0;
- while ( !%fileObj.isEOF() )
- {
- if(%lineId >= %startingLineId)
- {
- %line = %fileObj.readLine();
-
- if(strIsMatchExpr(%findText, %line))
- {
- return %lineId;
- }
- }
-
- %lineId++;
- }
- %fileObj.close();
- }
-
- return -1;
- }
- function Tools::findInFunction(%file, %nameSpace, %functionName, %findText)
- {
- %fileObj = new FileObject(){};
-
- %insideFunction = false;
- %scopeDepth = 0;
-
- if ( %fileObj.openForRead( %file ) )
- {
- %lineId = -1;
- while ( !%fileObj.isEOF() )
- {
- %line = %fileObj.readLine();
- %lineId++;
-
- if(strIsMatchExpr("*function *(*)*", %line))
- {
- %start = strpos(%line, "function ");
- %end = strpos(%line, "(", %start);
-
- %scannedFunctionName = "";
- if(%start != -1 && %end != -1)
- {
- %scannedFunctionName = getSubStr(%line, %start + 9, %end-%start-9);
- }
-
- %matchesFunctionSig = false;
- if(%nameSpace !$= "")
- {
- if(%scannedFunctionName $= (%nameSpace @ "::" @ %functionName))
- %matchesFunctionSig = true;
- }
- else
- {
- if(%scannedFunctionName $= %functionName)
- %matchesFunctionSig = true;
- }
-
- if(!%matchesFunctionSig)
- continue;
-
- %insideFunction = true;
-
- if(strIsMatchExpr("*{*", %line))
- {
- %scopeDepth++;
- }
- if(strIsMatchExpr("*}*", %line))
- {
- %scopeDepth--;
- }
- }
- else
- {
- if(%insideFunction && strIsMatchExpr("*{*", %line))
- {
- %scopeDepth++;
- }
- if(%insideFunction && strIsMatchExpr("*}*", %line))
- {
- %scopeDepth--;
-
- if(%scopeDepth == 0) //we've fully backed out of the function scope, so resolve back to the parent
- {
- %insideFunction = false;
- break;
- }
- }
-
- if(%insideFunction && strIsMatchExpr(%findText, %line))
- {
- break;
- }
- }
- }
- %fileObj.close();
- }
-
- return %lineId;
- }
- function Tools::insertInFile(%file, %insertLineId, %insertText, %insertBefore)
- {
- %fileOutput = new ArrayObject(){};
- %fileObj = new FileObject(){};
- if ( %fileObj.openForRead( %file ) )
- {
- %lineId = 0;
- while ( !%fileObj.isEOF() )
- {
- %line = %fileObj.readLine();
-
- if(%insertLineId == %lineId)
- {
- if(!%insertBefore || %insertBefore $= "")
- {
- %fileOutput.add(%line);
- %fileOutput.add(%insertText);
- }
- else
- {
- %fileOutput.add(%insertText);
- %fileOutput.add(%line);
- }
- }
- else
- {
- %fileOutput.add(%line);
- }
-
- %lineId++;
- }
- %fileObj.close();
- }
-
- if ( %fileObj.openForWrite( %file ) )
- {
- for(%i=0; %i < %fileOutput.count(); %i++)
- {
- %line = %fileOutput.getKey(%i);
-
- %fileObj.writeLine(%line);
- }
- %fileObj.close();
- }
- }
|