Commit 93b791da authored by nanahira's avatar nanahira

fix

parent 69f81ea4
' ecvbslib.vbs: VBScript routines for use in
' editorconfig-core-vimscript and editorconfig-vim.
' Copyright (c) 2018--2019 Chris White. All rights reserved.
' Licensed CC-BY-SA, version 3.0 or any later version, at your option.
' Remove CR and LF in a string
function nocrlf(strin)
nocrlf = Replace(Replace(strin, vbCr, ""), vbLf, "")
end function
' === Base64 ================================================================
' from https://stackoverflow.com/a/40118072/2877364 by
' https://stackoverflow.com/users/45375/mklement0
' Base64-encodes the specified string.
' Parameter fAsUtf16LE determines how the input text is encoded at the
' byte level before Base64 encoding is applied.
' * Pass False to use UTF-8 encoding.
' * Pass True to use UTF-16 LE encoding.
Function Base64Encode(ByVal sText, ByVal fAsUtf16LE)
' Use an aux. XML document with a Base64-encoded element.
' Assigning the byte stream (array) returned by StrToBytes() to .NodeTypedValue
' automatically performs Base64-encoding, whose result can then be accessed
' as the element's text.
With CreateObject("Msxml2.DOMDocument").CreateElement("aux")
.DataType = "bin.base64"
if fAsUtf16LE then
.NodeTypedValue = StrToBytes(sText, "utf-16le", 2)
else
.NodeTypedValue = StrToBytes(sText, "utf-8", 3)
end if
Base64Encode = nocrlf(.Text) ' No line breaks; MSXML adds them.
End With
End Function
' Decodes the specified Base64-encoded string.
' If the decoded string's original encoding was:
' * UTF-8, pass False for fIsUtf16LE.
' * UTF-16 LE, pass True for fIsUtf16LE.
Function Base64Decode(ByVal sBase64EncodedText, ByVal fIsUtf16LE)
Dim sTextEncoding
if fIsUtf16LE Then sTextEncoding = "utf-16le" Else sTextEncoding = "utf-8"
' Use an aux. XML document with a Base64-encoded element.
' Assigning the encoded text to .Text makes the decoded byte array
' available via .nodeTypedValue, which we can pass to BytesToStr()
With CreateObject("Msxml2.DOMDocument").CreateElement("aux")
.DataType = "bin.base64"
.Text = sBase64EncodedText
Base64Decode = BytesToStr(.NodeTypedValue, sTextEncoding)
End With
End Function
' Returns a binary representation (byte array) of the specified string in
' the specified text encoding, such as "utf-8" or "utf-16le".
' Pass the number of bytes that the encoding's BOM uses as iBomByteCount;
' pass 0 to include the BOM in the output.
function StrToBytes(ByVal sText, ByVal sTextEncoding, ByVal iBomByteCount)
' Create a text string with the specified encoding and then
' get its binary (byte array) representation.
With CreateObject("ADODB.Stream")
' Create a stream with the specified text encoding...
.Type = 2 ' adTypeText
.Charset = sTextEncoding
.Open
.WriteText sText
' ... and convert it to a binary stream to get a byte-array
' representation.
.Position = 0
.Type = 1 ' adTypeBinary
.Position = iBomByteCount ' skip the BOM
StrToBytes = .Read
.Close
End With
end function
' Returns a string that corresponds to the specified byte array, interpreted
' with the specified text encoding, such as "utf-8" or "utf-16le".
function BytesToStr(ByVal byteArray, ByVal sTextEncoding)
If LCase(sTextEncoding) = "utf-16le" then
' UTF-16 LE happens to be VBScript's internal encoding, so we can
' take a shortcut and use CStr() to directly convert the byte array
' to a string.
BytesToStr = CStr(byteArray)
Else ' Convert the specified text encoding to a VBScript string.
' Create a binary stream and copy the input byte array to it.
With CreateObject("ADODB.Stream")
.Type = 1 ' adTypeBinary
.Open
.Write byteArray
' Now change the type to text, set the encoding, and output the
' result as text.
.Position = 0
.Type = 2 ' adTypeText
.CharSet = sTextEncoding
BytesToStr = .ReadText
.Close
End With
End If
end function
' === Runner ================================================================
' Run a command, copy its stdout/stderr to ours, and return its exit
' status.
' Modified from https://stackoverflow.com/a/32493083/2877364 by
' https://stackoverflow.com/users/3191599/nate-barbettini .
' See also https://www.vbsedit.com/html/4c5b06ac-dc45-4ec2-aca1-f168bab75483.asp
function RunCommandAndEcho(strCommand)
Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2
Set WshShell = CreateObject("WScript.Shell")
'WScript.Echo "Running >>" & strCommand & "<<..."
Set WshShellExec = WshShell.Exec(strCommand)
Do While WshShellExec.Status = WshRunning
'WScript.Echo "Waiting..."
WScript.Sleep 100
Loop
if not WshShellExec.StdOut.AtEndOfStream then
WScript.StdOut.Write(WshShellExec.StdOut.ReadAll())
end if
if not WshShellExec.StdErr.AtEndOfStream then
WScript.StdErr.Write(WshShellExec.StdErr.ReadAll())
end if
RunCommandAndEcho = WshShellExec.ExitCode
end function
' === Argument processing ===================================================
function MakeY64Args(args)
dim b64args(100) ' 100 = arbitrary max
' Make Y64-flavored base64 versions of each arg so we don't have to
' worry about quoting issues while executing PowerShell.
idx=0
For Each arg In args
b64args(idx) = Base64Encode(nocrlf(arg), False)
' Y64 flavor of Base64
b64args(idx) = replace( _
replace( _
replace(b64args(idx), "+", "."), _
"/", "_" ), _
"=", "-")
'Wscript.Echo cstr(idx) & ": >" & arg & "< = >" & b64args(idx) & "<"
'Wscript.Echo b64args(idx)
idx = idx+1
Next
MakeY64Args = b64args
end function
Function QuoteForShell(strIn)
QuoteForShell = """" & _
replace(strIn, """", """""") & """"
End Function
' ecvbslib.vbs: VBScript routines for use in
' editorconfig-core-vimscript and editorconfig-vim.
' Copyright (c) 2018--2019 Chris White. All rights reserved.
' Licensed CC-BY-SA, version 3.0 or any later version, at your option.
' Remove CR and LF in a string
function nocrlf(strin)
nocrlf = Replace(Replace(strin, vbCr, ""), vbLf, "")
end function
' === Base64 ================================================================
' from https://stackoverflow.com/a/40118072/2877364 by
' https://stackoverflow.com/users/45375/mklement0
' Base64-encodes the specified string.
' Parameter fAsUtf16LE determines how the input text is encoded at the
' byte level before Base64 encoding is applied.
' * Pass False to use UTF-8 encoding.
' * Pass True to use UTF-16 LE encoding.
Function Base64Encode(ByVal sText, ByVal fAsUtf16LE)
' Use an aux. XML document with a Base64-encoded element.
' Assigning the byte stream (array) returned by StrToBytes() to .NodeTypedValue
' automatically performs Base64-encoding, whose result can then be accessed
' as the element's text.
With CreateObject("Msxml2.DOMDocument").CreateElement("aux")
.DataType = "bin.base64"
if fAsUtf16LE then
.NodeTypedValue = StrToBytes(sText, "utf-16le", 2)
else
.NodeTypedValue = StrToBytes(sText, "utf-8", 3)
end if
Base64Encode = nocrlf(.Text) ' No line breaks; MSXML adds them.
End With
End Function
' Decodes the specified Base64-encoded string.
' If the decoded string's original encoding was:
' * UTF-8, pass False for fIsUtf16LE.
' * UTF-16 LE, pass True for fIsUtf16LE.
Function Base64Decode(ByVal sBase64EncodedText, ByVal fIsUtf16LE)
Dim sTextEncoding
if fIsUtf16LE Then sTextEncoding = "utf-16le" Else sTextEncoding = "utf-8"
' Use an aux. XML document with a Base64-encoded element.
' Assigning the encoded text to .Text makes the decoded byte array
' available via .nodeTypedValue, which we can pass to BytesToStr()
With CreateObject("Msxml2.DOMDocument").CreateElement("aux")
.DataType = "bin.base64"
.Text = sBase64EncodedText
Base64Decode = BytesToStr(.NodeTypedValue, sTextEncoding)
End With
End Function
' Returns a binary representation (byte array) of the specified string in
' the specified text encoding, such as "utf-8" or "utf-16le".
' Pass the number of bytes that the encoding's BOM uses as iBomByteCount;
' pass 0 to include the BOM in the output.
function StrToBytes(ByVal sText, ByVal sTextEncoding, ByVal iBomByteCount)
' Create a text string with the specified encoding and then
' get its binary (byte array) representation.
With CreateObject("ADODB.Stream")
' Create a stream with the specified text encoding...
.Type = 2 ' adTypeText
.Charset = sTextEncoding
.Open
.WriteText sText
' ... and convert it to a binary stream to get a byte-array
' representation.
.Position = 0
.Type = 1 ' adTypeBinary
.Position = iBomByteCount ' skip the BOM
StrToBytes = .Read
.Close
End With
end function
' Returns a string that corresponds to the specified byte array, interpreted
' with the specified text encoding, such as "utf-8" or "utf-16le".
function BytesToStr(ByVal byteArray, ByVal sTextEncoding)
If LCase(sTextEncoding) = "utf-16le" then
' UTF-16 LE happens to be VBScript's internal encoding, so we can
' take a shortcut and use CStr() to directly convert the byte array
' to a string.
BytesToStr = CStr(byteArray)
Else ' Convert the specified text encoding to a VBScript string.
' Create a binary stream and copy the input byte array to it.
With CreateObject("ADODB.Stream")
.Type = 1 ' adTypeBinary
.Open
.Write byteArray
' Now change the type to text, set the encoding, and output the
' result as text.
.Position = 0
.Type = 2 ' adTypeText
.CharSet = sTextEncoding
BytesToStr = .ReadText
.Close
End With
End If
end function
' === Runner ================================================================
' Run a command, copy its stdout/stderr to ours, and return its exit
' status.
' Modified from https://stackoverflow.com/a/32493083/2877364 by
' https://stackoverflow.com/users/3191599/nate-barbettini .
' See also https://www.vbsedit.com/html/4c5b06ac-dc45-4ec2-aca1-f168bab75483.asp
function RunCommandAndEcho(strCommand)
Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2
Set WshShell = CreateObject("WScript.Shell")
'WScript.Echo "Running >>" & strCommand & "<<..."
Set WshShellExec = WshShell.Exec(strCommand)
Do While WshShellExec.Status = WshRunning
'WScript.Echo "Waiting..."
WScript.Sleep 100
Loop
if not WshShellExec.StdOut.AtEndOfStream then
WScript.StdOut.Write(WshShellExec.StdOut.ReadAll())
end if
if not WshShellExec.StdErr.AtEndOfStream then
WScript.StdErr.Write(WshShellExec.StdErr.ReadAll())
end if
RunCommandAndEcho = WshShellExec.ExitCode
end function
' === Argument processing ===================================================
function MakeY64Args(args)
dim b64args(100) ' 100 = arbitrary max
' Make Y64-flavored base64 versions of each arg so we don't have to
' worry about quoting issues while executing PowerShell.
idx=0
For Each arg In args
b64args(idx) = Base64Encode(nocrlf(arg), False)
' Y64 flavor of Base64
b64args(idx) = replace( _
replace( _
replace(b64args(idx), "+", "."), _
"/", "_" ), _
"=", "-")
'Wscript.Echo cstr(idx) & ": >" & arg & "< = >" & b64args(idx) & "<"
'Wscript.Echo b64args(idx)
idx = idx+1
Next
MakeY64Args = b64args
end function
Function QuoteForShell(strIn)
QuoteForShell = """" & _
replace(strIn, """", """""") & """"
End Function
# ecvimlib.ps1: Editorconfig Vimscript core CLI, PowerShell version,
# library routines.
# Copyright (c) 2018--2019 Chris White. All rights reserved.
# Licensed CC-BY-SA, version 3.0 or any later version, at your option.
#
# N.B.: debug output uses Warning only because those are displayed by default.
#Requires -Version 3
# Get the directory of this script. From
# https://stackoverflow.com/a/5466355/2877364 by
# https://stackoverflow.com/users/23283/jaredpar
$global:DIR = $PSScriptRoot
### Set up debugging output ============================================
$global:debug=$env:EDITORCONFIG_DEBUG # Debug filename
if($global:debug -and ($global:debug -notmatch '^/')) {
# Relative to this script unless it starts with a slash. This is because
# cwd is usually not $DIR when testing.
$global:debug="${DIR}/${global:debug}"
}
### Process args =======================================================
function de64_args($argv) {
$argv | % {
$b64 = $_ -replace '-','=' -replace '_','/' -replace '\.','+'
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($b64))
}
}
### Helpers ============================================================
# Append a string to $debug in UTF-8 rather than the default UTF-16
filter global:D($file = $debug) {
if($debug) {
echo $_ | Out-File -FilePath $file -Encoding utf8 -Append
}
}
# Escape a string for Vim
function global:vesc($str) {
return "'" + ($str -replace "'","''") + "'"
}
# Escape a string for a command-line argument.
# See https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.arguments?view=netframework-4.7.2
function global:argesc($arg) {
return '"' + ($arg -replace '"','"""') + '"'
}
### Find the Vim EXE ===================================================
function global:Find-Vim
{
if($env:VIM_EXE) {
if($debug) { echo "Using env Vim $($env:VIM_EXE)" | D }
return $env:VIM_EXE
}
$vims = @(get-childitem 'c:\program files*\vim\**\vim.exe' | `
sort LastWriteTime -Descending) # @() => always array
# write-host ($vims | format-table | out-string) # DEBUG
# write-host ($vims | get-member | out-string)
if($vims.count -gt 0) {
if($debug) { echo "Using found Vim $($vims[0].FullName)" | D }
return $vims[0].FullName
}
throw "Could not find vim.exe. Please set VIM_EXE to the path to your Vim."
} #Find-Vim
### Runner =============================================================
# Run a process with the given arguments.
function global:run_process
{
param(
[Parameter(Mandatory=$true, Position=0)][string]$run,
[string]$extrapath,
[string]$stdout, # Redirect stdout to this file
[string]$stderr, # Redirect stderr to this file
[string[]]$argv # Arguments to $run
)
$si = new-object Diagnostics.ProcessStartInfo
if($extrapath) {
$si.EnvironmentVariables['path']+=";${extrapath}"
}
$si.FileName=$run
# Stringify the arguments (blech)
$argstr = $argv | % { (argesc $_) + ' ' }
$si.Arguments = $argstr;
if($debug) { echo "Running process $run with arguments >>$argstr<<" | D }
$si.UseShellExecute=$false
# DEBUG $si.RedirectStandardInput=$true
if($stdout) {
if($debug) { echo "Saving stdout to ${stdout}" | D }
$si.RedirectStandardOutput=$true;
}
if($stderr) {
if($debug) { echo "Saving stderr to ${stderr}" | D }
$si.RedirectStandardError=$true;
}
$p = [Diagnostics.Process]::Start($si)
# DEBUG $p.StandardInput.Close() # < /dev/null
$p.WaitForExit()
$retval = $p.ExitCode
if($stdout) {
echo "Standard output:" | D $stdout
$p.StandardOutput.ReadToEnd() | `
Out-File -FilePath $stdout -Encoding utf8 -Append
}
if($stderr) {
echo "Standard error:" | D $stderr
$p.StandardError.ReadToEnd() | `
Out-File -FilePath $stderr -Encoding utf8 -Append
}
$p.Close()
return $retval
}
if($debug) {
echo "======================================================" | D
Get-Date -format F | D
}
$global:VIM = Find-Vim
# ecvimlib.ps1: Editorconfig Vimscript core CLI, PowerShell version,
# library routines.
# Copyright (c) 2018--2019 Chris White. All rights reserved.
# Licensed CC-BY-SA, version 3.0 or any later version, at your option.
#
# N.B.: debug output uses Warning only because those are displayed by default.
#Requires -Version 3
# Get the directory of this script. From
# https://stackoverflow.com/a/5466355/2877364 by
# https://stackoverflow.com/users/23283/jaredpar
$global:DIR = $PSScriptRoot
### Set up debugging output ============================================
$global:debug=$env:EDITORCONFIG_DEBUG # Debug filename
if($global:debug -and ($global:debug -notmatch '^/')) {
# Relative to this script unless it starts with a slash. This is because
# cwd is usually not $DIR when testing.
$global:debug="${DIR}/${global:debug}"
}
### Process args =======================================================
function de64_args($argv) {
$argv | % {
$b64 = $_ -replace '-','=' -replace '_','/' -replace '\.','+'
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($b64))
}
}
### Helpers ============================================================
# Append a string to $debug in UTF-8 rather than the default UTF-16
filter global:D($file = $debug) {
if($debug) {
echo $_ | Out-File -FilePath $file -Encoding utf8 -Append
}
}
# Escape a string for Vim
function global:vesc($str) {
return "'" + ($str -replace "'","''") + "'"
}
# Escape a string for a command-line argument.
# See https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.arguments?view=netframework-4.7.2
function global:argesc($arg) {
return '"' + ($arg -replace '"','"""') + '"'
}
### Find the Vim EXE ===================================================
function global:Find-Vim
{
if($env:VIM_EXE) {
if($debug) { echo "Using env Vim $($env:VIM_EXE)" | D }
return $env:VIM_EXE
}
$vims = @(get-childitem 'c:\program files*\vim\**\vim.exe' | `
sort LastWriteTime -Descending) # @() => always array
# write-host ($vims | format-table | out-string) # DEBUG
# write-host ($vims | get-member | out-string)
if($vims.count -gt 0) {
if($debug) { echo "Using found Vim $($vims[0].FullName)" | D }
return $vims[0].FullName
}
throw "Could not find vim.exe. Please set VIM_EXE to the path to your Vim."
} #Find-Vim
### Runner =============================================================
# Run a process with the given arguments.
function global:run_process
{
param(
[Parameter(Mandatory=$true, Position=0)][string]$run,
[string]$extrapath,
[string]$stdout, # Redirect stdout to this file
[string]$stderr, # Redirect stderr to this file
[string[]]$argv # Arguments to $run
)
$si = new-object Diagnostics.ProcessStartInfo
if($extrapath) {
$si.EnvironmentVariables['path']+=";${extrapath}"
}
$si.FileName=$run
# Stringify the arguments (blech)
$argstr = $argv | % { (argesc $_) + ' ' }
$si.Arguments = $argstr;
if($debug) { echo "Running process $run with arguments >>$argstr<<" | D }
$si.UseShellExecute=$false
# DEBUG $si.RedirectStandardInput=$true
if($stdout) {
if($debug) { echo "Saving stdout to ${stdout}" | D }
$si.RedirectStandardOutput=$true;
}
if($stderr) {
if($debug) { echo "Saving stderr to ${stderr}" | D }
$si.RedirectStandardError=$true;
}
$p = [Diagnostics.Process]::Start($si)
# DEBUG $p.StandardInput.Close() # < /dev/null
$p.WaitForExit()
$retval = $p.ExitCode
if($stdout) {
echo "Standard output:" | D $stdout
$p.StandardOutput.ReadToEnd() | `
Out-File -FilePath $stdout -Encoding utf8 -Append
}
if($stderr) {
echo "Standard error:" | D $stderr
$p.StandardError.ReadToEnd() | `
Out-File -FilePath $stderr -Encoding utf8 -Append
}
$p.Close()
return $retval
}
if($debug) {
echo "======================================================" | D
Get-Date -format F | D
}
$global:VIM = Find-Vim
@echo off
:: editorconfig.bat: First-level invoker for editorconfig-core-vimscript
:: and editorconfig-vim.
:: Just passes the full command line to editorconfig1.vbs, since VBScript
:: applies very simple quoting rules when it parses a command line.
:: Copyright (c) 2018--2019 Chris White. All rights reserved.
:: Licensed CC-BY-SA, version 3.0 or any later version, at your option.
set here=%~dp0
cscript //Nologo "%here%editorconfig1.vbs" %*
:: %* has the whole command line
@echo off
:: editorconfig.bat: First-level invoker for editorconfig-core-vimscript
:: and editorconfig-vim.
:: Just passes the full command line to editorconfig1.vbs, since VBScript
:: applies very simple quoting rules when it parses a command line.
:: Copyright (c) 2018--2019 Chris White. All rights reserved.
:: Licensed CC-BY-SA, version 3.0 or any later version, at your option.
set here=%~dp0
cscript //Nologo "%here%editorconfig1.vbs" %*
:: %* has the whole command line
' editorconfig1.vbs: run by editorconfig.bat
' runs editorconfig2.ps1
' Part of editorconfig-core-vimscript and editorconfig-vim.
'
' Copyright (c) 2018--2019 Chris White. All rights reserved.
' Licensed CC-BY-SA, version 3.0 or any later version, at your option.
'
' Modified from
' https://stackoverflow.com/a/2470557/2877364 by
' https://stackoverflow.com/users/2441/aphoria
' Thanks to https://www.geekshangout.com/vbs-script-to-get-the-location-of-the-current-script/
currentScriptPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
' Load our common library. Thanks to https://stackoverflow.com/a/316169/2877364
With CreateObject("Scripting.FileSystemObject")
executeGlobal .openTextFile(currentScriptPath & "ecvbslib.vbs").readAll()
End With
' === MAIN ==================================================================
' Encode all the arguments as modified base64 so there will be no quoting
' issues when we invoke powershell.
b64args = MakeY64Args(Wscript.Arguments)
' Quote script name just in case
ps1name = QuoteForShell(currentScriptPath & "editorconfig2.ps1")
'Wscript.Echo "Script is in " & ps1name
if True then
retval = RunCommandAndEcho( "powershell.exe" & _
" -executionpolicy bypass -file " & ps1name & " " & join(b64args) _
)
' add -noexit to leave window open so you can see error messages
WScript.Quit retval
end if
' vi: set ts=4 sts=4 sw=4 et ai:
' editorconfig1.vbs: run by editorconfig.bat
' runs editorconfig2.ps1
' Part of editorconfig-core-vimscript and editorconfig-vim.
'
' Copyright (c) 2018--2019 Chris White. All rights reserved.
' Licensed CC-BY-SA, version 3.0 or any later version, at your option.
'
' Modified from
' https://stackoverflow.com/a/2470557/2877364 by
' https://stackoverflow.com/users/2441/aphoria
' Thanks to https://www.geekshangout.com/vbs-script-to-get-the-location-of-the-current-script/
currentScriptPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
' Load our common library. Thanks to https://stackoverflow.com/a/316169/2877364
With CreateObject("Scripting.FileSystemObject")
executeGlobal .openTextFile(currentScriptPath & "ecvbslib.vbs").readAll()
End With
' === MAIN ==================================================================
' Encode all the arguments as modified base64 so there will be no quoting
' issues when we invoke powershell.
b64args = MakeY64Args(Wscript.Arguments)
' Quote script name just in case
ps1name = QuoteForShell(currentScriptPath & "editorconfig2.ps1")
'Wscript.Echo "Script is in " & ps1name
if True then
retval = RunCommandAndEcho( "powershell.exe" & _
" -executionpolicy bypass -file " & ps1name & " " & join(b64args) _
)
' add -noexit to leave window open so you can see error messages
WScript.Quit retval
end if
' vi: set ts=4 sts=4 sw=4 et ai:
# editorconfig2.ps1: Editorconfig Vimscript core CLI, PowerShell version
# Copyright (c) 2018--2019 Chris White. All rights reserved.
# Licensed CC-BY-SA, version 3.0 or any later version, at your option.
# Thanks to https://cecs.wright.edu/~pmateti/Courses/233/Labs/Scripting/bashVsPowerShellTable.html
# by Gallagher and Mateti.
#Requires -Version 3
. "$PSScriptRoot\ecvimlib.ps1"
# Argument parsing =================================================== {{{1
$argv = @(de64_args($args))
# Defaults
$report_version = $false
$set_version = ''
$config_name = '.editorconfig'
$extra_info = ''
$files=@()
# Hand-parse - pretend we're sort of like getopt.
$idx = 0
while($idx -lt $argv.count) {
$a = $argv[$idx]
switch -CaseSensitive -Regex ($a) {
'^(-v|--version)$' { $report_version = $true }
'^--dummy$' {
# A dummy option so that I can test list-valued EDITORCONFIG_CMD
}
'^-f$' {
if($idx -eq ($argv.count-1)) {
throw '-f <filename>: no filename provided'
} else {
++$idx
$config_name = $argv[$idx]
}
} #-f
'^-b$' {
if($idx -eq ($argv.count-1)) {
throw '-b <version>: no version provided'
} else {
++$idx
$set_version = $argv[$idx]
}
} #-b
'^-x$' {
if($idx -eq ($argv.count-1)) {
throw '-x <extra info>: no info provided'
} else {
++$idx
$extra_info = $argv[$idx]
}
} #-x
'^--$' { # End of options, so capture the rest as filenames
++$idx;
while($idx -lt $argv.count) {
$files += $argv[$idx]
}
}
default { $files += $a }
}
++$idx
} # end foreach argument
# }}}1
# Argument processing ================================================ {{{1
if($debug) {
if($extra_info -ne '') {
echo "--- $extra_info --- " | D
}
echo "Running in $DIR" | D
echo "Vim executable: $VIM" | D
echo "report version? $report_version" | D
echo "set version to: $set_version" | D
echo "config filename: $config_name" | D
echo "Filenames: $files" | D
echo "Args: $args" | D
echo "Decoded args: $argv" | D
}
if($report_version) {
echo "EditorConfig VimScript Core Version 0.12.2"
exit
}
if($files.count -lt 1) {
exit
}
if($files[0] -eq '-') {
echo "Reading filenames from stdin not yet supported" # TODO
exit 1
}
$fn=[System.IO.Path]::GetTempFileName();
# Vim will write the settings into here. Sort of like stdout.
$script_output_fn = ''
if($debug) {
$script_output_fn = [System.IO.Path]::GetTempFileName()
}
# Permit throwing in setup commands
$cmd = ''
if($env:EDITORCONFIG_EXTRA) {
$cmd += $env:EDITORCONFIG_EXTRA + ' | '
}
# }}}1
# Build Vim command line ============================================= {{{1
$cmd += 'call editorconfig_core#currbuf_cli({'
# Names
$cmd += "'output':" + (vesc($fn)) + ", "
# filename to put the settings in
if($debug) {
$cmd += " 'dump':" + (vesc($script_output_fn)) + ", "
# where to put debug info
}
# Filenames to get the settings for
$cmd += "'target':["
ForEach ($item in $files) {
$cmd += (vesc($item)) + ", "
}
$cmd += "],"
# Job
$cmd += "}, {"
if($config_name) { $cmd += "'config':" + (vesc($config_name)) + ", " }
# config name (e.g., .editorconfig)
if($set_version) { $cmd += "'version':" + (vesc($set_version)) + ", " }
# version number we should behave as
$cmd += "})"
#$cmd =':q!' # DEBUG
if($debug) { echo "Using Vim command ${cmd}" | D }
$vim_args = @(
'-c', "set runtimepath+=${DIR}\..\..",
'-c', $cmd,
'-c', 'quit!' # TODO write a wrapper that will cquit on exception
)
# Run editorconfig. Thanks for options to
# http://vim.wikia.com/wiki/Vim_as_a_system_interpreter_for_vimscript .
# Add -V1 to the below for debugging output.
# Do not output anything to stdout or stderr,
# since it messes up ctest's interpretation
# of the results.
$basic_args = '-nNes','-i','NONE','-u','NONE','-U','NONE' #, '-V1'
# }}}1
# Run Vim ============================================================ {{{1
if($debug) { echo "Running vim ${VIM}" | D }
$vimstatus = run_process $VIM -stdout $debug -stderr $debug `
-argv ($basic_args+$vim_args)
if($debug) { echo "Done running vim" | D }
if($vimstatus -eq 0) {
cat $fn
}
# }}}1
# Produce debug output =============================================== {{{1
# Debug output cannot be included on stdout or stderr, because
# ctest's regex check looks both of those places. Therefore, dump to a
# separate debugging file.
if($debug) {
echo "Current directory:" | D
(get-item -path '.').FullName | D
echo "Script directory: $DIR" | D
### echo Vim args: "${vim_args[@]}" >> "$debug"
### #od -c <<<"${vim_args[@]}" >> "$debug"
echo "Vim returned $vimstatus" | D
echo "Vim messages were: " | D
cat $script_output_fn | D
echo "Output was:" | D
# Modified from https://www.itprotoday.com/powershell/get-hex-dumps-files-powershell
Get-Content $script_output_fn -Encoding Byte -ReadCount 16 | `
ForEach-Object {
$output = ""
$chars = ''
foreach ( $byte in $_ ) {
$output += "{0:X2} " -f $byte
if( ($byte -ge 32) -and ($byte -le 127) ) {
$chars += [char]$byte
} else {
$chars += '.'
}
}
$output + ' ' + $chars
} | D
del -Force $script_output_fn
} #endif $debug
# }}}1
del -Force $fn
exit $vimstatus
# vi: set fdm=marker:
# editorconfig2.ps1: Editorconfig Vimscript core CLI, PowerShell version
# Copyright (c) 2018--2019 Chris White. All rights reserved.
# Licensed CC-BY-SA, version 3.0 or any later version, at your option.
# Thanks to https://cecs.wright.edu/~pmateti/Courses/233/Labs/Scripting/bashVsPowerShellTable.html
# by Gallagher and Mateti.
#Requires -Version 3
. "$PSScriptRoot\ecvimlib.ps1"
# Argument parsing =================================================== {{{1
$argv = @(de64_args($args))
# Defaults
$report_version = $false
$set_version = ''
$config_name = '.editorconfig'
$extra_info = ''
$files=@()
# Hand-parse - pretend we're sort of like getopt.
$idx = 0
while($idx -lt $argv.count) {
$a = $argv[$idx]
switch -CaseSensitive -Regex ($a) {
'^(-v|--version)$' { $report_version = $true }
'^--dummy$' {
# A dummy option so that I can test list-valued EDITORCONFIG_CMD
}
'^-f$' {
if($idx -eq ($argv.count-1)) {
throw '-f <filename>: no filename provided'
} else {
++$idx
$config_name = $argv[$idx]
}
} #-f
'^-b$' {
if($idx -eq ($argv.count-1)) {
throw '-b <version>: no version provided'
} else {
++$idx
$set_version = $argv[$idx]
}
} #-b
'^-x$' {
if($idx -eq ($argv.count-1)) {
throw '-x <extra info>: no info provided'
} else {
++$idx
$extra_info = $argv[$idx]
}
} #-x
'^--$' { # End of options, so capture the rest as filenames
++$idx;
while($idx -lt $argv.count) {
$files += $argv[$idx]
}
}
default { $files += $a }
}
++$idx
} # end foreach argument
# }}}1
# Argument processing ================================================ {{{1
if($debug) {
if($extra_info -ne '') {
echo "--- $extra_info --- " | D
}
echo "Running in $DIR" | D
echo "Vim executable: $VIM" | D
echo "report version? $report_version" | D
echo "set version to: $set_version" | D
echo "config filename: $config_name" | D
echo "Filenames: $files" | D
echo "Args: $args" | D
echo "Decoded args: $argv" | D
}
if($report_version) {
echo "EditorConfig VimScript Core Version 0.12.2"
exit
}
if($files.count -lt 1) {
exit
}
if($files[0] -eq '-') {
echo "Reading filenames from stdin not yet supported" # TODO
exit 1
}
$fn=[System.IO.Path]::GetTempFileName();
# Vim will write the settings into here. Sort of like stdout.
$script_output_fn = ''
if($debug) {
$script_output_fn = [System.IO.Path]::GetTempFileName()
}
# Permit throwing in setup commands
$cmd = ''
if($env:EDITORCONFIG_EXTRA) {
$cmd += $env:EDITORCONFIG_EXTRA + ' | '
}
# }}}1
# Build Vim command line ============================================= {{{1
$cmd += 'call editorconfig_core#currbuf_cli({'
# Names
$cmd += "'output':" + (vesc($fn)) + ", "
# filename to put the settings in
if($debug) {
$cmd += " 'dump':" + (vesc($script_output_fn)) + ", "
# where to put debug info
}
# Filenames to get the settings for
$cmd += "'target':["
ForEach ($item in $files) {
$cmd += (vesc($item)) + ", "
}
$cmd += "],"
# Job
$cmd += "}, {"
if($config_name) { $cmd += "'config':" + (vesc($config_name)) + ", " }
# config name (e.g., .editorconfig)
if($set_version) { $cmd += "'version':" + (vesc($set_version)) + ", " }
# version number we should behave as
$cmd += "})"
#$cmd =':q!' # DEBUG
if($debug) { echo "Using Vim command ${cmd}" | D }
$vim_args = @(
'-c', "set runtimepath+=${DIR}\..\..",
'-c', $cmd,
'-c', 'quit!' # TODO write a wrapper that will cquit on exception
)
# Run editorconfig. Thanks for options to
# http://vim.wikia.com/wiki/Vim_as_a_system_interpreter_for_vimscript .
# Add -V1 to the below for debugging output.
# Do not output anything to stdout or stderr,
# since it messes up ctest's interpretation
# of the results.
$basic_args = '-nNes','-i','NONE','-u','NONE','-U','NONE' #, '-V1'
# }}}1
# Run Vim ============================================================ {{{1
if($debug) { echo "Running vim ${VIM}" | D }
$vimstatus = run_process $VIM -stdout $debug -stderr $debug `
-argv ($basic_args+$vim_args)
if($debug) { echo "Done running vim" | D }
if($vimstatus -eq 0) {
cat $fn
}
# }}}1
# Produce debug output =============================================== {{{1
# Debug output cannot be included on stdout or stderr, because
# ctest's regex check looks both of those places. Therefore, dump to a
# separate debugging file.
if($debug) {
echo "Current directory:" | D
(get-item -path '.').FullName | D
echo "Script directory: $DIR" | D
### echo Vim args: "${vim_args[@]}" >> "$debug"
### #od -c <<<"${vim_args[@]}" >> "$debug"
echo "Vim returned $vimstatus" | D
echo "Vim messages were: " | D
cat $script_output_fn | D
echo "Output was:" | D
# Modified from https://www.itprotoday.com/powershell/get-hex-dumps-files-powershell
Get-Content $script_output_fn -Encoding Byte -ReadCount 16 | `
ForEach-Object {
$output = ""
$chars = ''
foreach ( $byte in $_ ) {
$output += "{0:X2} " -f $byte
if( ($byte -ge 32) -and ($byte -le 127) ) {
$chars += [char]$byte
} else {
$chars += '.'
}
}
$output + ' ' + $chars
} | D
del -Force $script_output_fn
} #endif $debug
# }}}1
del -Force $fn
exit $vimstatus
# vi: set fdm=marker:
; test EditorConfig files with CRLF line separators
root = true
[*]
key = value
; test EditorConfig files with CRLF line separators
root = true
[*]
key = value
......@@ -21,7 +21,7 @@
become: true
apt:
update_cache: true
name: 'git,nvidia-driver-{{ nvidia_driver_version }},nvidia-cuda-dev,nvidia-cuda-gdb,nvidia-cuda-toolkit,nvidia-cuda-toolkit-gcc,nvidia-container-runtime,libnvidia-encode-{{ nvidia_driver_version }},libnvidia-decode-{{ nvidia_driver_version }},libnvidia-fbc1-{{ nvidia_driver_version }},libnvidia-compute-{{ nvidia_driver_version }},libnvidia-gl-{{ nvidia_driver_version }}'
name: 'git,nvidia-driver-{{ nvidia_driver_version }},nvidia-container-runtime,libnvidia-encode-{{ nvidia_driver_version }},libnvidia-decode-{{ nvidia_driver_version }},libnvidia-fbc1-{{ nvidia_driver_version }},libnvidia-compute-{{ nvidia_driver_version }},libnvidia-gl-{{ nvidia_driver_version }}'
install_recommends: false
- name: check detailed driver version
changed_when: false
......@@ -41,23 +41,6 @@
check_file: libnvidia-fbc-backup/libnvidia-fbc.so
- script: patch.sh
check_file: libnvidia-encode-backup/libnvidia-encode.so
- name: check install of cudnn
find:
paths:
- /usr/lib/x86_64-linux-gnu
patterns: 'libcudnn.so.8.4.0'
register: cudnn_result
- name: purge cudnn7
become: true
apt:
name: libcudnn7,libcudnn7-dev,libcudnn7-doc
state: absent
- name: install cudnn
become: true
apt:
deb: 'https://cdn02.moecube.com:444/init/cudnn/{{item}}'
with_items:
- libcudnn8_8.4.0.27-1+cuda11.6_amd64.deb
- libcudnn8-dev_8.4.0.27-1+cuda11.6_amd64.deb
- libcudnn8-samples_8.4.0.27-1+cuda11.6_amd64.deb
when: not cudnn_result.files[0] is defined and ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int >= 20
- name: cuda
include_tasks: nvidia_cuda.yml
when: nvidia_driver_version <= 510
......@@ -35,7 +35,7 @@
blockinfile:
path: /etc/ssh/sshd_config
block: |
HostKeyAlgorithms=ssh-rsa,ssh-rsa-cert-v01@openssh.com
HostKeyAlgorithms=+ssh-rsa,ssh-rsa-cert-v01@openssh.com
PubkeyAcceptedAlgorithms=+ssh-rsa,ssh-rsa-cert-v01@openssh.com
marker: '# {mark} MyCard Init block'
when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version|int >= 22
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment