<commit_before>@set args=%*
@powershell "iex((@('')*3+(cat '%~f0'|select -skip 3))-join[char]10)"
@exit /b %ERRORLEVEL%

$args = @( ([regex]'"([^"]*)"').Replace($env:args,{
        $args[0].Groups[1] -replace " ",[char]1
    }) -split " " | ForEach-Object{ $_ -replace [char]1," " })

# set GO "go" -option constant
set GO "go.exe" -option constant

set CMD "Cmd" -option constant

$LUAURL = @{
    "amd64"="https://sourceforge.net/projects/luabinaries/files/5.3.4/Windows%20Libraries/Dynamic/lua-5.3.4_Win64_dllw4_lib.zip/download";
    "386"="https://sourceforge.net/projects/luabinaries/files/5.3.4/Windows%20Libraries/Dynamic/lua-5.3.4_Win32_dllw4_lib.zip/download";
}

Set-PSDebug -strict
$VerbosePreference = "Continue"

function Do-Copy($src,$dst){
    Write-Verbose "$ copy '$src' '$dst'"
    Copy-Item $src $dst
}

function Do-Remove($file){
    if( Test-Path $file ){
        Write-Verbose "$ del '$file'"
        Remove-Item $file
    }
}

function Make-Dir($folder){
    if( -not (Test-Path $folder) ){
        Write-Verbose "$ mkdir '$folder'"
        New-Item $folder -type directory | Out-Null
    }
}

Add-Type -Assembly System.Windows.Forms
function Ask-Copy($src,$dst){
    $fname = (Join-Path $dst (Split-Path $src -Leaf))
    if( Test-Path $fname ){
        if( "Yes" -ne [System.Windows.Forms.MessageBox]::Show(
            'Override "{0}" by default ?' -f $fname,
            "NYAGOS Install", "YesNo","Question","button2") ){
            return
        }
    }
    Do-Copy $src $dst
}

function Get-GoArch{
    if( Test-Path "goarch.txt" ){
        $arch = (Get-Content "goarch.txt")
    }elseif( (Test-Path env:GOARCH) -and $env:GOARCH ){
        $arch = $env:GOARCH
    }else{
        $arch = (& $GO version | %{ $_.Split()[-1].Split("/")[-1] } )
    }
    Write-Verbose ("Found GOARCH="+$arch)
    return $arch
}

function ForEach-GoDir{
    Get-ChildItem . -Recurse |
    Where-Object{ $_.Extension -eq '.go' } |
    ForEach-Object{ Split-Path $_.FullName -Parent } |
    Sort-Object |
    Get-Unique
}

function Get-Imports {
    Get-ChildItem . -Recurse |
    Where-Object{ $_.Extension -eq '.go' } |
    ForEach-Object{ Get-Content $_.FullName  } |
    ForEach-Object{ ($_ -replace '\s*//.*$','').Split()[-1] <# remove comment #>} |
    ?{ ($_ -match 'github.com/' -and $_ -notmatch '/nyagos/') `
        -or $_ -match 'golang.org/' } |
    %{ $_ -replace '"','' } |
    Sort-Object |
    Get-Unique
}

function Go-Generate{
    Get-ChildItem "." -Recurse |
    Where-Object{ $_.Name -eq "make.xml" } |
    ForEach-Object{
        $dir = (Split-Path $_.FullName -Parent)
        pushd $dir
        $xml = [xml](Get-Content $_.FullName)
        :allloop foreach( $li in $xml.make.generate.li ){
            foreach( $target in $li.target ){
                if( -not $target ){ continue }
                foreach( $source in $li.source ){
                    if( -not $source ){ continue }
                    if( (Newer-Than $source $target) ){
                        Write-Verbose ("$ $GO generate for {0}" -f
                            (Join-Path $dir $target) )
                        & $GO generate
                        break allloop
                    }
                }
            }
        }
        popd
    }
}

function Go-Fmt{
    $status = $true
    git status -s | %{
        $fname = $_.Substring(3)
        if( $fname -like "*.go" -and (Test-Path($fname)) ){
            $prop = Get-ItemProperty($fname)<commit_msg>Fix: make.cmd errors when git mv filenames.<commit_after>@set args=%*
@powershell "iex((@('')*3+(cat '%~f0'|select -skip 3))-join[char]10)"
@exit /b %ERRORLEVEL%

$args = @( ([regex]'"([^"]*)"').Replace($env:args,{
        $args[0].Groups[1] -replace " ",[char]1
    }) -split " " | ForEach-Object{ $_ -replace [char]1," " })

# set GO "go" -option constant
set GO "go.exe" -option constant

set CMD "Cmd" -option constant

$LUAURL = @{
    "amd64"="https://sourceforge.net/projects/luabinaries/files/5.3.4/Windows%20Libraries/Dynamic/lua-5.3.4_Win64_dllw4_lib.zip/download";
    "386"="https://sourceforge.net/projects/luabinaries/files/5.3.4/Windows%20Libraries/Dynamic/lua-5.3.4_Win32_dllw4_lib.zip/download";
}

Set-PSDebug -strict
$VerbosePreference = "Continue"

function Do-Copy($src,$dst){
    Write-Verbose "$ copy '$src' '$dst'"
    Copy-Item $src $dst
}

function Do-Remove($file){
    if( Test-Path $file ){
        Write-Verbose "$ del '$file'"
        Remove-Item $file
    }
}

function Make-Dir($folder){
    if( -not (Test-Path $folder) ){
        Write-Verbose "$ mkdir '$folder'"
        New-Item $folder -type directory | Out-Null
    }
}

Add-Type -Assembly System.Windows.Forms
function Ask-Copy($src,$dst){
    $fname = (Join-Path $dst (Split-Path $src -Leaf))
    if( Test-Path $fname ){
        if( "Yes" -ne [System.Windows.Forms.MessageBox]::Show(
            'Override "{0}" by default ?' -f $fname,
            "NYAGOS Install", "YesNo","Question","button2") ){
            return
        }
    }
    Do-Copy $src $dst
}

function Get-GoArch{
    if( Test-Path "goarch.txt" ){
        $arch = (Get-Content "goarch.txt")
    }elseif( (Test-Path env:GOARCH) -and $env:GOARCH ){
        $arch = $env:GOARCH
    }else{
        $arch = (& $GO version | %{ $_.Split()[-1].Split("/")[-1] } )
    }
    Write-Verbose ("Found GOARCH="+$arch)
    return $arch
}

function ForEach-GoDir{
    Get-ChildItem . -Recurse |
    Where-Object{ $_.Extension -eq '.go' } |
    ForEach-Object{ Split-Path $_.FullName -Parent } |
    Sort-Object |
    Get-Unique
}

function Get-Imports {
    Get-ChildItem . -Recurse |
    Where-Object{ $_.Extension -eq '.go' } |
    ForEach-Object{ Get-Content $_.FullName  } |
    ForEach-Object{ ($_ -replace '\s*//.*$','').Split()[-1] <# remove comment #>} |
    ?{ ($_ -match 'github.com/' -and $_ -notmatch '/nyagos/') `
        -or $_ -match 'golang.org/' } |
    %{ $_ -replace '"','' } |
    Sort-Object |
    Get-Unique
}

function Go-Generate{
    Get-ChildItem "." -Recurse |
    Where-Object{ $_.Name -eq "make.xml" } |
    ForEach-Object{
        $dir = (Split-Path $_.FullName -Parent)
        pushd $dir
        $xml = [xml](Get-Content $_.FullName)
        :allloop foreach( $li in $xml.make.generate.li ){
            foreach( $target in $li.target ){
                if( -not $target ){ continue }
                foreach( $source in $li.source ){
                    if( -not $source ){ continue }
                    if( (Newer-Than $source $target) ){
                        Write-Verbose ("$ $GO generate for {0}" -f
                            (Join-Path $dir $target) )
                        & $GO generate
                        break allloop
                    }
                }
            }
        }
        popd
    }
}

function Go-Fmt{
    $status = $true
    git status -s | %{
        $fname = $_.Substring(3)
        $arrow = $fname.IndexOf(" -> ")
        if( $arrow -ge 0 ){
            $fname = $fname.Substring($arrow+4)
        }
        if( $fname -like "*.go" -and (Test-Path($fname)) ){
            $prop = Get-ItemProperty($fname)
{'fraction_non_alphanumeric': 0.1826001128031585, 'fraction_numerical': 0.012408347433728144, 'mean_word_length': 2.0772234273318873, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2687612', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2459, 'n_words': 503}