annotate repoint.ps1 @ 641:327177b6bd3a v2.1pre2

Fix recently-introduced bug that made the scale disappear and tracks jump around when toggling off the spectrogram
author Chris Cannam
date Thu, 17 Oct 2019 14:44:55 +0100
parents 12d36dcfbbfb
children
rev   line source
Chris@523 1 <#
Chris@523 2
Chris@523 3 .SYNOPSIS
Chris@523 4 A simple manager for third-party source code dependencies.
Chris@531 5 Run "repoint help" for more documentation.
Chris@523 6
Chris@523 7 #>
Chris@523 8
Chris@529 9 Set-StrictMode -Version 2.0
Chris@529 10 $ErrorActionPreference = "Stop"
Chris@531 11 $env:HGPLAIN = "true"
Chris@529 12
Chris@531 13 $sml = $env:REPOINT_SML
Chris@523 14
Chris@523 15 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
Chris@531 16 $program = "$mydir/repoint.sml"
Chris@523 17
Chris@523 18 # We need either Poly/ML or SML/NJ. No great preference as to which.
Chris@523 19
Chris@531 20 # Typical locations
Chris@531 21 $env:PATH = "$env:PATH;C:\Program Files (x86)\SMLNJ\bin;C:\Program Files\Poly ML;C:\Program Files (x86)\Poly ML"
Chris@531 22
Chris@523 23 if (!$sml) {
Chris@529 24 if (Get-Command "sml" -ErrorAction SilentlyContinue) {
Chris@529 25 $sml = "smlnj"
Chris@529 26 } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) {
Chris@523 27 $sml = "poly"
Chris@523 28 } else {
Chris@523 29 echo @"
Chris@523 30
Chris@523 31 ERROR: No supported SML compiler or interpreter found
Chris@523 32
Chris@531 33 The Repoint external source code manager needs a Standard ML (SML)
Chris@523 34 compiler or interpreter to run.
Chris@523 35
Chris@523 36 Please ensure you have one of the following SML implementations
Chris@523 37 installed and present in your PATH, and try again.
Chris@523 38
Chris@529 39 1. Standard ML of New Jersey
Chris@529 40 - executable name: sml
Chris@529 41
Chris@529 42 2. Poly/ML
Chris@523 43 - executable name: polyml
Chris@523 44
Chris@523 45 "@
Chris@523 46 exit 1
Chris@523 47 }
Chris@523 48 }
Chris@523 49
Chris@529 50 if ($args -match "'""") {
Chris@523 51 $arglist = '["usage"]'
Chris@523 52 } else {
Chris@523 53 $arglist = '["' + ($args -join '","') + '"]'
Chris@523 54 }
Chris@523 55
Chris@523 56 if ($sml -eq "poly") {
Chris@523 57
Chris@523 58 $program = $program -replace "\\","\\\\"
Chris@531 59 echo "use ""$program""; repoint $arglist" | polyml -q --error-exit | Out-Host
Chris@523 60
Chris@529 61 if (-not $?) {
Chris@529 62 exit $LastExitCode
Chris@529 63 }
Chris@529 64
Chris@523 65 } elseif ($sml -eq "smlnj") {
Chris@523 66
Chris@523 67 $lines = @(Get-Content $program)
Chris@523 68 $lines = $lines -notmatch "val _ = main ()"
Chris@523 69
Chris@523 70 $intro = @"
Chris@523 71 val smlrun__cp =
Chris@523 72 let val x = !Control.Print.out in
Chris@523 73 Control.Print.out := { say = fn _ => (), flush = fn () => () };
Chris@523 74 x
Chris@523 75 end;
Chris@523 76 val smlrun__prev = ref "";
Chris@523 77 Control.Print.out := {
Chris@523 78 say = fn s =>
Chris@523 79 (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s
Chris@523 80 then (Control.Print.out := smlrun__cp;
Chris@523 81 (#say smlrun__cp) (!smlrun__prev);
Chris@523 82 (#say smlrun__cp) s)
Chris@523 83 else (smlrun__prev := s; ())),
Chris@523 84 flush = fn s => ()
Chris@523 85 };
Chris@523 86 "@ -split "[\r\n]+"
Chris@523 87
Chris@529 88 $outro = @"
Chris@531 89 val _ = repoint $arglist;
Chris@523 90 val _ = OS.Process.exit (OS.Process.success);
Chris@523 91 "@ -split "[\r\n]+"
Chris@523 92
Chris@529 93 $script = @()
Chris@529 94 $script += $intro
Chris@529 95 $script += $lines
Chris@529 96 $script += $outro
Chris@523 97
Chris@529 98 $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
Chris@523 99
Chris@529 100 $script | Out-File -Encoding "ASCII" $tmpfile
Chris@523 101
Chris@529 102 $env:CM_VERBOSE="false"
Chris@523 103
Chris@529 104 sml $tmpfile
Chris@523 105
Chris@529 106 if (-not $?) {
Chris@529 107 del $tmpfile
Chris@529 108 exit $LastExitCode
Chris@529 109 }
Chris@529 110
Chris@529 111 del $tmpfile
Chris@523 112
Chris@523 113 } else {
Chris@523 114
Chris@529 115 "Unknown SML implementation name: $sml"
Chris@529 116 exit 2
Chris@523 117 }