-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathfuncs.ps1
More file actions
111 lines (100 loc) · 4.04 KB
/
funcs.ps1
File metadata and controls
111 lines (100 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# useful functions
# capture the repo root at dot-source time - $PSScriptRoot is unreliable inside functions
$NHROOT = $PSScriptRoot
if (Test-Path os) { $NHOS = (Get-Content os -Raw).Trim() } else { $NHOS = "Windows" }
if (Test-Path cpu) { $NHCPU = (Get-Content cpu -Raw).Trim() } else { $NHCPU = "x86_64" }
if (Test-Path abi) { $NHABI = (Get-Content abi -Raw).Trim() } else { $NHABI = "WIN64" }
$HOS = $NHOS
$HCPU = $NHCPU
$HABI = $NHABI
function zero_pad {
param ($c)
if ($c -lt 100) { $zp = "0$c" } else { $zp = $c }
if ($zp -lt 10) { $zp = "0$zp" }
$zp
}
function add_link {
param ($src, $dst, $links)
$src_pad = zero_pad ($src + $bcpu)
$dst_pad = zero_pad ($dst + $bcpu)
if ($src_pad -ne $dst_pad) {
if ($src_pad -lt $dst_pad) { $nl = "$src_pad-$dst_pad" } else { $nl = "$dst_pad-$src_pad" }
if ($links.IndexOf($nl) -eq -1) { return "-l $nl " }
}
return ""
}
function wrap {
param ($cpu, $num_cpu)
$wp = $cpu % $num_cpu
if ($wp -lt 0) { $wp += $num_cpu }
$wp
}
function boot_cpu_gui {
param ($front, $cpu, $link)
$cmd = "$NHROOT\obj\$NHCPU\$NHABI\$NHOS\main_gui.exe"
$boot = if ($global:emu -eq '-e') { "obj/vp64/VP64/sys/boot_image" } else { "obj/$HCPU/$HABI/sys/boot_image" }
$argstring = "$boot " + $link.Trim()
if ($global:emu -ne '') { $argstring += " $global:emu" }
if ($cpu -lt 1) {
if ($front -eq $FALSE) {
Start-Process -FilePath $cmd -WorkingDirectory $NHROOT -NoNewWindow -ArgumentList "$argstring -run service/gui/app.lisp"
} else {
$process = Start-Process -FilePath $cmd -WorkingDirectory $NHROOT -NoNewWindow -ArgumentList "$argstring -run service/gui/app.lisp" -PassThru -Wait
if ($process.ExitCode -eq 0) {
. "$NHROOT\stop.ps1"
Clear-Host
}
}
} else {
Start-Process -FilePath $cmd -WorkingDirectory $NHROOT -NoNewWindow -ArgumentList $argstring
}
}
function boot_cpu_tui {
param ($front, $cpu, $link)
$cmd = "$NHROOT\obj\$NHCPU\$NHABI\$NHOS\main_tui.exe"
$boot = if ($global:emu -eq '-e') { "obj/vp64/VP64/sys/boot_image" } else { "obj/$HCPU/$HABI/sys/boot_image" }
$argstring = "$boot " + $link.Trim()
if ($global:emu -ne '') { $argstring += " $global:emu" }
if ($cpu -lt 1) {
if ($front -eq $FALSE) {
Start-Process -FilePath $cmd -WorkingDirectory $NHROOT -NoNewWindow -ArgumentList "$argstring -run $global:script" -Wait
} else {
$process = Start-Process -FilePath $cmd -WorkingDirectory $NHROOT -NoNewWindow -ArgumentList "$argstring -run $global:script" -PassThru -Wait
if ($process.ExitCode -eq 0) {
. "$NHROOT\stop.ps1"
Clear-Host
}
}
} else {
Start-Process -FilePath $cmd -WorkingDirectory $NHROOT -NoNewWindow -ArgumentList $argstring
}
}
function main {
# no param() block - keeps ALL args in $args with no named-parameter binding
# $args[0] = default node count, $args[1] = max node count, rest = flags
$global:ncpu = [int]$args[0]
$maxn = [int]$args[1]
$global:bcpu = 0
$global:emu = ""
$global:front = $FALSE
$global:script = "apps/tui/tui.lisp"
$global:showhelp = $FALSE
for ($i = 2; $i -lt $args.Count; $i++) {
$arg = $args[$i]
switch ($arg) {
"-i" { $global:script = "apps/tui/install.lisp" }
"-s" { $global:script = $args[++$i] }
"-e" { $global:emu = "-e" }
"-f" { $global:front = $TRUE }
"-n" { $global:ncpu = [int]$args[++$i] }
"-b" { $global:bcpu = [int]$args[++$i] }
"-h" { $global:showhelp = $TRUE }
"--help" { $global:showhelp = $TRUE }
default { $global:showhelp = $TRUE }
}
}
if ($global:ncpu -gt $maxn) { $global:ncpu = $maxn }
if ($global:bcpu -eq 0 -and $global:showhelp -eq $FALSE) {
. "$NHROOT\stop.ps1"
}
}