- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
- $mapTable = @(
- @("move-l_format.c", "m_reg_tab", "amp_move.h", "m_reg_tab_move_l"),
- @("move-r_format.c", "m_reg_tab", "amp_move.h", "m_reg_tab_move_r"),
- @("move-c_format.c", "m_reg_tab", "amp_move.h", "m_reg_tab_move_cen"),
-
- @("music-l_format.c", "m_reg_tab", "amp_music.h", "m_reg_tab_music_l"),
- @("music-r_format.c", "m_reg_tab", "amp_music.h", "m_reg_tab_music_r"),
- @("music-c_format.c", "m_reg_tab", "amp_music.h", "m_reg_tab_music_cen"),
-
- @("news-l_format.c", "m_reg_tab", "amp_news.h", "m_reg_tab_news_l"),
- @("news-r_format.c", "m_reg_tab", "amp_news.h", "m_reg_tab_news_r"),
- @("news-c_format.c", "m_reg_tab", "amp_news.h", "m_reg_tab_news_cen"),
-
- @("move-l_format.c", "m_ram1_tab", "amp_move.h", "eq_tables_ram1_left_move"),
- @("move-r_format.c", "m_ram1_tab", "amp_move.h", "eq_tables_ram1_right_move"),
- @("move-c_format.c", "m_ram1_tab", "amp_move.h", "eq_tables_ram1_cen_move"),
-
- @("music-l_format.c", "m_ram1_tab", "amp_music.h", "eq_tables_ram1_left_music"),
- @("music-r_format.c", "m_ram1_tab", "amp_music.h", "eq_tables_ram1_right_music"),
- @("music-c_format.c", "m_ram1_tab", "amp_music.h", "eq_tables_ram1_cen_music"),
-
- @("news-l_format.c", "m_ram1_tab", "amp_news.h", "eq_tables_ram1_left_news"),
- @("news-r_format.c", "m_ram1_tab", "amp_news.h", "eq_tables_ram1_right_news"),
- @("news-c_format.c", "m_ram1_tab", "amp_news.h", "eq_tables_ram1_cen_news")
-
- )
- $format = '(?si)(?<var>{0}\[\]\s*=\s*)(?<block>(?>/\*.*?\*/|//[^\n]*|(?<open>\{{)|(?<-open>\}})|.)+?(?(open)(?!)))'
- $encoding = New-Object System.Text.UTF8Encoding -ArgumentList $false
- $files = Get-ChildItem -Recurse | Where-Object { -not $_.PSIsContainer }
- foreach ($arr in $mapTable) {
- $srcfile = $files | Where-Object { $_.Name -eq $arr[0] } | Select-Object -First 1
- $dstfile = $files | Where-Object { $_.Name -eq $arr[2] } | Select-Object -First 1
- if ($null -ne $srcfile -and $null -ne $dstfile) {
- $resrc = [regex]($format -f $arr[1])
- $redst = [regex]($format -f $arr[3])
- $txtsrc = [System.IO.File]::ReadAllText($srcfile.FullName, $encoding)
- $txtdst = [System.IO.File]::ReadAllText($dstfile.FullName, $encoding)
- [System.IO.File]::WriteAllText($dstfile.FullName, $redst.Replace($txtdst, {
- param([System.Text.RegularExpressions.Match]$mdst)
- $msrc = $resrc.Match($txtsrc)
- if ($msrc.Success) {
- $mdst.Groups['var'].Value + $msrc.Groups['block'].Value
- } else {
- $mdst.Value
- }
- }), $encoding)
- }
- }
复制代码
|