Commit 93b791da authored by nanahira's avatar nanahira

fix

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