c@219: <# c@219: c@219: .SYNOPSIS c@219: A simple manager for third-party source code dependencies. c@219: Run "repoint help" for more documentation. c@219: c@219: #> c@219: c@219: Set-StrictMode -Version 2.0 c@219: $ErrorActionPreference = "Stop" c@219: $env:HGPLAIN = "true" c@219: c@219: $sml = $env:REPOINT_SML c@219: c@219: $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent c@219: $program = "$mydir/repoint.sml" c@219: c@219: # We need either Poly/ML or SML/NJ. No great preference as to which. c@219: c@219: # Typical locations c@219: $env:PATH = "$env:PATH;C:\Program Files (x86)\SMLNJ\bin;C:\Program Files\Poly ML;C:\Program Files (x86)\Poly ML" c@219: c@219: if (!$sml) { c@219: if (Get-Command "sml" -ErrorAction SilentlyContinue) { c@219: $sml = "smlnj" c@219: } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) { c@219: $sml = "poly" c@219: } else { c@219: echo @" c@219: c@219: ERROR: No supported SML compiler or interpreter found c@219: c@219: The Repoint external source code manager needs a Standard ML (SML) c@219: compiler or interpreter to run. c@219: c@219: Please ensure you have one of the following SML implementations c@219: installed and present in your PATH, and try again. c@219: c@219: 1. Standard ML of New Jersey c@219: - executable name: sml c@219: c@219: 2. Poly/ML c@219: - executable name: polyml c@219: c@219: "@ c@219: exit 1 c@219: } c@219: } c@219: c@219: if ($args -match "'""") { c@219: $arglist = '["usage"]' c@219: } else { c@219: $arglist = '["' + ($args -join '","') + '"]' c@219: } c@219: c@219: if ($sml -eq "poly") { c@219: c@219: $program = $program -replace "\\","\\\\" c@219: echo "use ""$program""; repoint $arglist" | polyml -q --error-exit | Out-Host c@219: c@219: if (-not $?) { c@219: exit $LastExitCode c@219: } c@219: c@219: } elseif ($sml -eq "smlnj") { c@219: c@219: $lines = @(Get-Content $program) c@219: $lines = $lines -notmatch "val _ = main ()" c@219: c@219: $intro = @" c@219: val smlrun__cp = c@219: let val x = !Control.Print.out in c@219: Control.Print.out := { say = fn _ => (), flush = fn () => () }; c@219: x c@219: end; c@219: val smlrun__prev = ref ""; c@219: Control.Print.out := { c@219: say = fn s => c@219: (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s c@219: then (Control.Print.out := smlrun__cp; c@219: (#say smlrun__cp) (!smlrun__prev); c@219: (#say smlrun__cp) s) c@219: else (smlrun__prev := s; ())), c@219: flush = fn s => () c@219: }; c@219: "@ -split "[\r\n]+" c@219: c@219: $outro = @" c@219: val _ = repoint $arglist; c@219: val _ = OS.Process.exit (OS.Process.success); c@219: "@ -split "[\r\n]+" c@219: c@219: $script = @() c@219: $script += $intro c@219: $script += $lines c@219: $script += $outro c@219: c@219: $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml" c@219: c@219: $script | Out-File -Encoding "ASCII" $tmpfile c@219: c@219: $env:CM_VERBOSE="false" c@219: c@219: sml $tmpfile c@219: c@219: if (-not $?) { c@219: del $tmpfile c@219: exit $LastExitCode c@219: } c@219: c@219: del $tmpfile c@219: c@219: } else { c@219: c@219: "Unknown SML implementation name: $sml" c@219: exit 2 c@219: }