evilpuncker
vai se tratar garota
- Messages
- 2,178
- Points
- 0
- Age
- 109
- Location
- bronzil
- Github
- EPuncker
- Emulator
- Client Version
- 2019-05-30a MAIN
helloHere you go, see if it works alright (did only basic testing). Requires PHP-CLI:
php collapsemes.php /path/to/npc/folderOld files are backed up as *.bak, files that need no change are not touched. You might want to use this in a separate working copy in case it screws up.
collapsemes.php:
#!/usr/bin/php<?php// =================================================================// Collapse consecutive *mes into one, v1.0.1// (c) 2015 Ai4rei/AN//// This work is licensed under a// Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )// =================================================================// Down-level (PHP 4)if(!function_exists('file_put_contents')){ function file_put_contents($sFileName,$sData) { if(($hFile = fopen($sFileName,'wb'))!==false) { return fwrite($hFile,$sData) && fclose($hFile); } return false; }}// Down-level Endfunction ProcessFile($sFile){ $bSuccess = false; echo "File: {$sFile}... load"; if(($sData =@file_get_contents($sFile))!==false) { echo ' conv'; // mes ( ( var | string ) [,+] )* string; mes " $sPattern = '/((?<![a-z0-9_])mess+((????:[$.]?@?|#{1,2}|')(?:[a-zA-Z0-9_]+)$?)|(??<!)"(?:.(?!(?<!)"))*.?"))s*[,+]s*)*(??<!)"(?:.(?!(?<!)"))*.?))"s*;s*mess+")/sS'; if(preg_match($sPattern,$sData)) { do { $sData = preg_replace($sPattern,'mes $2n',$sData); } while(preg_match($sPattern,$sData)); echo ' save'; if(rename($sFile,substr($sFile,0,-3).'bak') && file_put_contents($sFile,$sData)) { echo " successn"; $bSuccess = true; } else { echo " failuren"; } } else { echo " skipn"; $bSuccess = true; } } else { echo " failuren"; } return $bSuccess;}function ProcessPath($sPath){ $bSuccess = true; echo "Enter: {$sPath}n"; if(($hDir =@opendir($sPath))!==false) { while(($sFile = readdir($hDir))!==false) { if(substr($sFile,0,1)=='.') {// unix world: skip self- and parent-references and so-called hidden files continue; } $sFullPath = $sPath.'/'.$sFile; if(is_dir($sFullPath)) { if(!ProcessPath($sFullPath)) { $bSuccess = false; break; } } elseif(is_file($sFullPath) && substr(strtolower($sFile),-4)==='.txt') { if(!ProcessFile($sFullPath)) { $bSuccess = false; break; } } } closedir($hDir); } else { echo "Failed to read directory: {$sPath}n"; } echo "Leave: {$sPath}n"; return $bSuccess;}function Main($nArgc,$aArgv){ if($nArgc<2) { echo "Usage: php collapsemes.php <script path>n"; return true; } return ProcessPath($aArgv[1]);}if(isset($_SERVER['argc']) && isset($_SERVER['argv'])){ return Main($_SERVER['argc'],$_SERVER['argv']) ? 0 : 1;}die("This script must be run on command line.n");?>
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Edit:
v1.0.1: Removed a flag, added regexp overview.
mes "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
better wait for @Haru input, by the way since you pointed it out, the early code you provided can work now I guess, can you re-paste it and I'll try to make it work again (I don't really remember how I managed to do so lol)Just to make sure, to make it support the following?
mes "Lorem ipsum dolor sit amet,\r"
"consectetur adipiscing elit."↓↓↓Code:mes "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
We use essential cookies to make this site work, and optional cookies to enhance your experience.