Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: 2042488d202f85ffd6b2c6c9a9bbe84e6099c85e
Timestamp: Wed, 31 Jan 2018 02:23:53 +0000 (7 years ago)

+12892 -16680 +/-199 browse
fix out of date dependencies
1diff --git a/Gopkg.lock b/Gopkg.lock
2index 54d0aa0..66b3b15 100644
3--- a/Gopkg.lock
4+++ b/Gopkg.lock
5 @@ -8,10 +8,10 @@
6 version = "v1.5.0"
7
8 [[projects]]
9- branch = "master"
10- name = "github.com/gosuri/uilive"
11+ name = "github.com/gizak/termui"
12 packages = ["."]
13- revision = "ac356e6e42cd31fcef8e6aec13ae9ed6fe87713e"
14+ revision = "24acd523c756fd9728824cdfac66aad9d8982fb7"
15+ version = "v2.2.0"
16
17 [[projects]]
18 name = "github.com/jawher/mow.cli"
19 @@ -20,6 +20,12 @@
20 version = "v1.0.3"
21
22 [[projects]]
23+ name = "github.com/maruel/panicparse"
24+ packages = ["stack"]
25+ revision = "766956aceb8ff49664065ae50bef0ae8a0a83ec4"
26+ version = "v1.0.2"
27+
28+ [[projects]]
29 name = "github.com/mattn/go-colorable"
30 packages = ["."]
31 revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
32 @@ -32,6 +38,12 @@
33 version = "v0.0.3"
34
35 [[projects]]
36+ name = "github.com/mattn/go-runewidth"
37+ packages = ["."]
38+ revision = "9e777a8366cce605130a531d2cd6363d07ad7317"
39+ version = "v0.0.2"
40+
41+ [[projects]]
42 name = "github.com/mattn/go-sqlite3"
43 packages = ["."]
44 revision = "6c771bb9887719704b210e87e934f08be014bdb1"
45 @@ -39,6 +51,18 @@
46
47 [[projects]]
48 branch = "master"
49+ name = "github.com/mitchellh/go-wordwrap"
50+ packages = ["."]
51+ revision = "ad45545899c7b13c020ea92b2072220eefad42b8"
52+
53+ [[projects]]
54+ branch = "master"
55+ name = "github.com/nsf/termbox-go"
56+ packages = ["."]
57+ revision = "88b7b944be8bc8d8ec6195fca97c5869ba20f99d"
58+
59+ [[projects]]
60+ branch = "master"
61 name = "golang.org/x/sys"
62 packages = ["unix"]
63 revision = "2c42eef0765b9837fbdab12011af7830f55f88f0"
64 @@ -46,6 +70,6 @@
65 [solve-meta]
66 analyzer-name = "dep"
67 analyzer-version = 1
68- inputs-digest = "1a1f721ab61fd1976d54ba03bad816beaefd926604a77b24c318305d4082f779"
69+ inputs-digest = "59a956a9d4768c1668abfcf5af67434d0f8251797d381c64b9dcf013a3dfcb34"
70 solver-name = "gps-cdcl"
71 solver-version = 1
72 diff --git a/Gopkg.toml b/Gopkg.toml
73index e70ac58..329330b 100644
74--- a/Gopkg.toml
75+++ b/Gopkg.toml
76 @@ -25,10 +25,6 @@
77 version = "1.5.0"
78
79 [[constraint]]
80- branch = "master"
81- name = "github.com/gosuri/uilive"
82-
83- [[constraint]]
84 name = "github.com/jawher/mow.cli"
85 version = "1.0.3"
86
87 diff --git a/vendor/github.com/gizak/termui/.gitignore b/vendor/github.com/gizak/termui/.gitignore
88new file mode 100644
89index 0000000..8b156b0
90--- /dev/null
91+++ b/vendor/github.com/gizak/termui/.gitignore
92 @@ -0,0 +1,26 @@
93+ # Compiled Object files, Static and Dynamic libs (Shared Objects)
94+ *.o
95+ *.a
96+ *.so
97+
98+ # Folders
99+ _obj
100+ _test
101+
102+ # Architecture specific extensions/prefixes
103+ *.[568vq]
104+ [568vq].out
105+
106+ *.cgo1.go
107+ *.cgo2.c
108+ _cgo_defun.c
109+ _cgo_gotypes.go
110+ _cgo_export.*
111+
112+ _testmain.go
113+
114+ *.exe
115+ *.test
116+ *.prof
117+ .DS_Store
118+ /vendor
119 diff --git a/vendor/github.com/gizak/termui/.travis.yml b/vendor/github.com/gizak/termui/.travis.yml
120new file mode 100644
121index 0000000..206e887
122--- /dev/null
123+++ b/vendor/github.com/gizak/termui/.travis.yml
124 @@ -0,0 +1,6 @@
125+ language: go
126+
127+ go:
128+ - tip
129+
130+ script: go test -v ./
131\ No newline at end of file
132 diff --git a/vendor/github.com/gizak/termui/LICENSE b/vendor/github.com/gizak/termui/LICENSE
133new file mode 100644
134index 0000000..311ccc7
135--- /dev/null
136+++ b/vendor/github.com/gizak/termui/LICENSE
137 @@ -0,0 +1,22 @@
138+ The MIT License (MIT)
139+
140+ Copyright (c) 2015 Zack Guo
141+
142+ Permission is hereby granted, free of charge, to any person obtaining a copy
143+ of this software and associated documentation files (the "Software"), to deal
144+ in the Software without restriction, including without limitation the rights
145+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
146+ copies of the Software, and to permit persons to whom the Software is
147+ furnished to do so, subject to the following conditions:
148+
149+ The above copyright notice and this permission notice shall be included in all
150+ copies or substantial portions of the Software.
151+
152+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
153+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
154+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
155+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
156+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
157+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158+ SOFTWARE.
159+
160 diff --git a/vendor/github.com/gizak/termui/README.md b/vendor/github.com/gizak/termui/README.md
161new file mode 100644
162index 0000000..d5f3d9a
163--- /dev/null
164+++ b/vendor/github.com/gizak/termui/README.md
165 @@ -0,0 +1,151 @@
166+ # termui [![Build Status](https://travis-ci.org/gizak/termui.svg?branch=master)](https://travis-ci.org/gizak/termui) [![Doc Status](https://godoc.org/github.com/gizak/termui?status.png)](https://godoc.org/github.com/gizak/termui)
167+
168+ <img src="./_example/dashboard.gif" alt="demo cast under osx 10.10; Terminal.app; Menlo Regular 12pt.)" width="80%">
169+
170+ `termui` is a cross-platform, easy-to-compile, and fully-customizable terminal dashboard. It is inspired by [blessed-contrib](https://github.com/yaronn/blessed-contrib), but purely in Go.
171+
172+ Now version v2 has arrived! It brings new event system, new theme system, new `Buffer` interface and specific colour text rendering. (some docs are missing, but it will be completed soon!)
173+
174+ ## Installation
175+
176+ `master` mirrors v2 branch, to install:
177+
178+ go get -u github.com/gizak/termui
179+
180+ It is recommanded to use locked deps by using [glide](https://glide.sh): move to `termui` src directory then run `glide up`.
181+
182+ For the compatible reason, you can choose to install the legacy version of `termui`:
183+
184+ go get gopkg.in/gizak/termui.v1
185+
186+ ## Usage
187+
188+ ### Layout
189+
190+ To use `termui`, the very first thing you may want to know is how to manage layout. `termui` offers two ways of doing this, known as absolute layout and grid layout.
191+
192+ __Absolute layout__
193+
194+ Each widget has an underlying block structure which basically is a box model. It has border, label and padding properties. A border of a widget can be chosen to hide or display (with its border label), you can pick a different front/back colour for the border as well. To display such a widget at a specific location in terminal window, you need to assign `.X`, `.Y`, `.Height`, `.Width` values for each widget before sending it to `.Render`. Let's demonstrate these by a code snippet:
195+
196+ `````go
197+ import ui "github.com/gizak/termui" // <- ui shortcut, optional
198+
199+ func main() {
200+ err := ui.Init()
201+ if err != nil {
202+ panic(err)
203+ }
204+ defer ui.Close()
205+
206+ p := ui.NewPar(":PRESS q TO QUIT DEMO")
207+ p.Height = 3
208+ p.Width = 50
209+ p.TextFgColor = ui.ColorWhite
210+ p.BorderLabel = "Text Box"
211+ p.BorderFg = ui.ColorCyan
212+
213+ g := ui.NewGauge()
214+ g.Percent = 50
215+ g.Width = 50
216+ g.Height = 3
217+ g.Y = 11
218+ g.BorderLabel = "Gauge"
219+ g.BarColor = ui.ColorRed
220+ g.BorderFg = ui.ColorWhite
221+ g.BorderLabelFg = ui.ColorCyan
222+
223+ ui.Render(p, g) // feel free to call Render, it's async and non-block
224+
225+ // event handler...
226+ }
227+ `````
228+
229+ Note that components can be overlapped (I'd rather call this a feature...), `Render(rs ...Renderer)` renders its args from left to right (i.e. each component's weight is arising from left to right).
230+
231+ __Grid layout:__
232+
233+ <img src="./_example/grid.gif" alt="grid" width="60%">
234+
235+ Grid layout uses [12 columns grid system](http://www.w3schools.com/bootstrap/bootstrap_grid_system.asp) with expressive syntax. To use `Grid`, all we need to do is build a widget tree consisting of `Row`s and `Col`s (Actually a `Col` is also a `Row` but with a widget endpoint attached).
236+
237+ ```go
238+ import ui "github.com/gizak/termui"
239+ // init and create widgets...
240+
241+ // build
242+ ui.Body.AddRows(
243+ ui.NewRow(
244+ ui.NewCol(6, 0, widget0),
245+ ui.NewCol(6, 0, widget1)),
246+ ui.NewRow(
247+ ui.NewCol(3, 0, widget2),
248+ ui.NewCol(3, 0, widget30, widget31, widget32),
249+ ui.NewCol(6, 0, widget4)))
250+
251+ // calculate layout
252+ ui.Body.Align()
253+
254+ ui.Render(ui.Body)
255+ ```
256+
257+ ### Events
258+
259+ `termui` ships with a http-like event mux handling system. All events are channeled up from different sources (typing, click, windows resize, custom event) and then encoded as universal `Event` object. `Event.Path` indicates the event type and `Event.Data` stores the event data struct. Add a handler to a certain event is easy as below:
260+
261+ ```go
262+ // handle key q pressing
263+ ui.Handle("/sys/kbd/q", func(ui.Event) {
264+ // press q to quit
265+ ui.StopLoop()
266+ })
267+
268+ ui.Handle("/sys/kbd/C-x", func(ui.Event) {
269+ // handle Ctrl + x combination
270+ })
271+
272+ ui.Handle("/sys/kbd", func(ui.Event) {
273+ // handle all other key pressing
274+ })
275+
276+ // handle a 1s timer
277+ ui.Handle("/timer/1s", func(e ui.Event) {
278+ t := e.Data.(ui.EvtTimer)
279+ // t is a EvtTimer
280+ if t.Count%2 ==0 {
281+ // do something
282+ }
283+ })
284+
285+ ui.Loop() // block until StopLoop is called
286+ ```
287+
288+ ### Widgets
289+
290+ Click image to see the corresponding demo codes.
291+
292+ [<img src="./_example/par.png" alt="par" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/par.go)
293+ [<img src="./_example/list.png" alt="list" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/list.go)
294+ [<img src="./_example/gauge.png" alt="gauge" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/gauge.go)
295+ [<img src="./_example/linechart.png" alt="linechart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/linechart.go)
296+ [<img src="./_example/barchart.png" alt="barchart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/barchart.go)
297+ [<img src="./_example/mbarchart.png" alt="barchart" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/mbarchart.go)
298+ [<img src="./_example/sparklines.png" alt="sparklines" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/sparklines.go)
299+ [<img src="./_example/table.png" alt="table" type="image/png" width="45%">](https://github.com/gizak/termui/blob/master/_example/table.go)
300+
301+ ## GoDoc
302+
303+ [godoc](https://godoc.org/github.com/gizak/termui)
304+
305+ ## TODO
306+
307+ - [x] Grid layout
308+ - [x] Event system
309+ - [x] Canvas widget
310+ - [x] Refine APIs
311+ - [ ] Focusable widgets
312+
313+ ## Changelog
314+
315+ ## License
316+ This library is under the [MIT License](http://opensource.org/licenses/MIT)
317 diff --git a/vendor/github.com/gizak/termui/barchart.go b/vendor/github.com/gizak/termui/barchart.go
318new file mode 100644
319index 0000000..6560c8b
320--- /dev/null
321+++ b/vendor/github.com/gizak/termui/barchart.go
322 @@ -0,0 +1,149 @@
323+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
324+ // Use of this source code is governed by a MIT license that can
325+ // be found in the LICENSE file.
326+
327+ package termui
328+
329+ import "fmt"
330+
331+ // BarChart creates multiple bars in a widget:
332+ /*
333+ bc := termui.NewBarChart()
334+ data := []int{3, 2, 5, 3, 9, 5}
335+ bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
336+ bc.BorderLabel = "Bar Chart"
337+ bc.Data = data
338+ bc.Width = 26
339+ bc.Height = 10
340+ bc.DataLabels = bclabels
341+ bc.TextColor = termui.ColorGreen
342+ bc.BarColor = termui.ColorRed
343+ bc.NumColor = termui.ColorYellow
344+ */
345+ type BarChart struct {
346+ Block
347+ BarColor Attribute
348+ TextColor Attribute
349+ NumColor Attribute
350+ Data []int
351+ DataLabels []string
352+ BarWidth int
353+ BarGap int
354+ CellChar rune
355+ labels [][]rune
356+ dataNum [][]rune
357+ numBar int
358+ scale float64
359+ max int
360+ }
361+
362+ // NewBarChart returns a new *BarChart with current theme.
363+ func NewBarChart() *BarChart {
364+ bc := &BarChart{Block: *NewBlock()}
365+ bc.BarColor = ThemeAttr("barchart.bar.bg")
366+ bc.NumColor = ThemeAttr("barchart.num.fg")
367+ bc.TextColor = ThemeAttr("barchart.text.fg")
368+ bc.BarGap = 1
369+ bc.BarWidth = 3
370+ bc.CellChar = ' '
371+ return bc
372+ }
373+
374+ func (bc *BarChart) layout() {
375+ bc.numBar = bc.innerArea.Dx() / (bc.BarGap + bc.BarWidth)
376+ bc.labels = make([][]rune, bc.numBar)
377+ bc.dataNum = make([][]rune, len(bc.Data))
378+
379+ for i := 0; i < bc.numBar && i < len(bc.DataLabels) && i < len(bc.Data); i++ {
380+ bc.labels[i] = trimStr2Runes(bc.DataLabels[i], bc.BarWidth)
381+ n := bc.Data[i]
382+ s := fmt.Sprint(n)
383+ bc.dataNum[i] = trimStr2Runes(s, bc.BarWidth)
384+ }
385+
386+ //bc.max = bc.Data[0] // what if Data is nil? Sometimes when bar graph is nill it produces panic with panic: runtime error: index out of range
387+ // Asign a negative value to get maxvalue auto-populates
388+ if bc.max == 0 {
389+ bc.max = -1
390+ }
391+ for i := 0; i < len(bc.Data); i++ {
392+ if bc.max < bc.Data[i] {
393+ bc.max = bc.Data[i]
394+ }
395+ }
396+ bc.scale = float64(bc.max) / float64(bc.innerArea.Dy()-1)
397+ }
398+
399+ func (bc *BarChart) SetMax(max int) {
400+
401+ if max > 0 {
402+ bc.max = max
403+ }
404+ }
405+
406+ // Buffer implements Bufferer interface.
407+ func (bc *BarChart) Buffer() Buffer {
408+ buf := bc.Block.Buffer()
409+ bc.layout()
410+
411+ for i := 0; i < bc.numBar && i < len(bc.Data) && i < len(bc.DataLabels); i++ {
412+ h := int(float64(bc.Data[i]) / bc.scale)
413+ oftX := i * (bc.BarWidth + bc.BarGap)
414+
415+ barBg := bc.Bg
416+ barFg := bc.BarColor
417+
418+ if bc.CellChar == ' ' {
419+ barBg = bc.BarColor
420+ barFg = ColorDefault
421+ if bc.BarColor == ColorDefault { // the same as above
422+ barBg |= AttrReverse
423+ }
424+ }
425+
426+ // plot bar
427+ for j := 0; j < bc.BarWidth; j++ {
428+ for k := 0; k < h; k++ {
429+ c := Cell{
430+ Ch: bc.CellChar,
431+ Bg: barBg,
432+ Fg: barFg,
433+ }
434+
435+ x := bc.innerArea.Min.X + i*(bc.BarWidth+bc.BarGap) + j
436+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2 - k
437+ buf.Set(x, y, c)
438+ }
439+ }
440+ // plot text
441+ for j, k := 0, 0; j < len(bc.labels[i]); j++ {
442+ w := charWidth(bc.labels[i][j])
443+ c := Cell{
444+ Ch: bc.labels[i][j],
445+ Bg: bc.Bg,
446+ Fg: bc.TextColor,
447+ }
448+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 1
449+ x := bc.innerArea.Min.X + oftX + k
450+ buf.Set(x, y, c)
451+ k += w
452+ }
453+ // plot num
454+ for j := 0; j < len(bc.dataNum[i]); j++ {
455+ c := Cell{
456+ Ch: bc.dataNum[i][j],
457+ Fg: bc.NumColor,
458+ Bg: barBg,
459+ }
460+
461+ if h == 0 {
462+ c.Bg = bc.Bg
463+ }
464+ x := bc.innerArea.Min.X + oftX + (bc.BarWidth-len(bc.dataNum[i]))/2 + j
465+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2
466+ buf.Set(x, y, c)
467+ }
468+ }
469+
470+ return buf
471+ }
472 diff --git a/vendor/github.com/gizak/termui/block.go b/vendor/github.com/gizak/termui/block.go
473new file mode 100644
474index 0000000..3e8571b
475--- /dev/null
476+++ b/vendor/github.com/gizak/termui/block.go
477 @@ -0,0 +1,240 @@
478+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
479+ // Use of this source code is governed by a MIT license that can
480+ // be found in the LICENSE file.
481+
482+ package termui
483+
484+ import "image"
485+
486+ // Hline is a horizontal line.
487+ type Hline struct {
488+ X int
489+ Y int
490+ Len int
491+ Fg Attribute
492+ Bg Attribute
493+ }
494+
495+ // Vline is a vertical line.
496+ type Vline struct {
497+ X int
498+ Y int
499+ Len int
500+ Fg Attribute
501+ Bg Attribute
502+ }
503+
504+ // Buffer draws a horizontal line.
505+ func (l Hline) Buffer() Buffer {
506+ if l.Len <= 0 {
507+ return NewBuffer()
508+ }
509+ return NewFilledBuffer(l.X, l.Y, l.X+l.Len, l.Y+1, HORIZONTAL_LINE, l.Fg, l.Bg)
510+ }
511+
512+ // Buffer draws a vertical line.
513+ func (l Vline) Buffer() Buffer {
514+ if l.Len <= 0 {
515+ return NewBuffer()
516+ }
517+ return NewFilledBuffer(l.X, l.Y, l.X+1, l.Y+l.Len, VERTICAL_LINE, l.Fg, l.Bg)
518+ }
519+
520+ // Buffer draws a box border.
521+ func (b Block) drawBorder(buf Buffer) {
522+ if !b.Border {
523+ return
524+ }
525+
526+ min := b.area.Min
527+ max := b.area.Max
528+
529+ x0 := min.X
530+ y0 := min.Y
531+ x1 := max.X - 1
532+ y1 := max.Y - 1
533+
534+ // draw lines
535+ if b.BorderTop {
536+ buf.Merge(Hline{x0, y0, x1 - x0, b.BorderFg, b.BorderBg}.Buffer())
537+ }
538+ if b.BorderBottom {
539+ buf.Merge(Hline{x0, y1, x1 - x0, b.BorderFg, b.BorderBg}.Buffer())
540+ }
541+ if b.BorderLeft {
542+ buf.Merge(Vline{x0, y0, y1 - y0, b.BorderFg, b.BorderBg}.Buffer())
543+ }
544+ if b.BorderRight {
545+ buf.Merge(Vline{x1, y0, y1 - y0, b.BorderFg, b.BorderBg}.Buffer())
546+ }
547+
548+ // draw corners
549+ if b.BorderTop && b.BorderLeft && b.area.Dx() > 0 && b.area.Dy() > 0 {
550+ buf.Set(x0, y0, Cell{TOP_LEFT, b.BorderFg, b.BorderBg})
551+ }
552+ if b.BorderTop && b.BorderRight && b.area.Dx() > 1 && b.area.Dy() > 0 {
553+ buf.Set(x1, y0, Cell{TOP_RIGHT, b.BorderFg, b.BorderBg})
554+ }
555+ if b.BorderBottom && b.BorderLeft && b.area.Dx() > 0 && b.area.Dy() > 1 {
556+ buf.Set(x0, y1, Cell{BOTTOM_LEFT, b.BorderFg, b.BorderBg})
557+ }
558+ if b.BorderBottom && b.BorderRight && b.area.Dx() > 1 && b.area.Dy() > 1 {
559+ buf.Set(x1, y1, Cell{BOTTOM_RIGHT, b.BorderFg, b.BorderBg})
560+ }
561+ }
562+
563+ func (b Block) drawBorderLabel(buf Buffer) {
564+ maxTxtW := b.area.Dx() - 2
565+ tx := DTrimTxCls(DefaultTxBuilder.Build(b.BorderLabel, b.BorderLabelFg, b.BorderLabelBg), maxTxtW)
566+
567+ for i, w := 0, 0; i < len(tx); i++ {
568+ buf.Set(b.area.Min.X+1+w, b.area.Min.Y, tx[i])
569+ w += tx[i].Width()
570+ }
571+ }
572+
573+ // Block is a base struct for all other upper level widgets,
574+ // consider it as css: display:block.
575+ // Normally you do not need to create it manually.
576+ type Block struct {
577+ area image.Rectangle
578+ innerArea image.Rectangle
579+ X int
580+ Y int
581+ Border bool
582+ BorderFg Attribute
583+ BorderBg Attribute
584+ BorderLeft bool
585+ BorderRight bool
586+ BorderTop bool
587+ BorderBottom bool
588+ BorderLabel string
589+ BorderLabelFg Attribute
590+ BorderLabelBg Attribute
591+ Display bool
592+ Bg Attribute
593+ Width int
594+ Height int
595+ PaddingTop int
596+ PaddingBottom int
597+ PaddingLeft int
598+ PaddingRight int
599+ id string
600+ Float Align
601+ }
602+
603+ // NewBlock returns a *Block which inherits styles from current theme.
604+ func NewBlock() *Block {
605+ b := Block{}
606+ b.Display = true
607+ b.Border = true
608+ b.BorderLeft = true
609+ b.BorderRight = true
610+ b.BorderTop = true
611+ b.BorderBottom = true
612+ b.BorderBg = ThemeAttr("border.bg")
613+ b.BorderFg = ThemeAttr("border.fg")
614+ b.BorderLabelBg = ThemeAttr("label.bg")
615+ b.BorderLabelFg = ThemeAttr("label.fg")
616+ b.Bg = ThemeAttr("block.bg")
617+ b.Width = 2
618+ b.Height = 2
619+ b.id = GenId()
620+ b.Float = AlignNone
621+ return &b
622+ }
623+
624+ func (b Block) Id() string {
625+ return b.id
626+ }
627+
628+ // Align computes box model
629+ func (b *Block) Align() {
630+ // outer
631+ b.area.Min.X = 0
632+ b.area.Min.Y = 0
633+ b.area.Max.X = b.Width
634+ b.area.Max.Y = b.Height
635+
636+ // float
637+ b.area = AlignArea(TermRect(), b.area, b.Float)
638+ b.area = MoveArea(b.area, b.X, b.Y)
639+
640+ // inner
641+ b.innerArea.Min.X = b.area.Min.X + b.PaddingLeft
642+ b.innerArea.Min.Y = b.area.Min.Y + b.PaddingTop
643+ b.innerArea.Max.X = b.area.Max.X - b.PaddingRight
644+ b.innerArea.Max.Y = b.area.Max.Y - b.PaddingBottom
645+
646+ if b.Border {
647+ if b.BorderLeft {
648+ b.innerArea.Min.X++
649+ }
650+ if b.BorderRight {
651+ b.innerArea.Max.X--
652+ }
653+ if b.BorderTop {
654+ b.innerArea.Min.Y++
655+ }
656+ if b.BorderBottom {
657+ b.innerArea.Max.Y--
658+ }
659+ }
660+ }
661+
662+ // InnerBounds returns the internal bounds of the block after aligning and
663+ // calculating the padding and border, if any.
664+ func (b *Block) InnerBounds() image.Rectangle {
665+ b.Align()
666+ return b.innerArea
667+ }
668+
669+ // Buffer implements Bufferer interface.
670+ // Draw background and border (if any).
671+ func (b *Block) Buffer() Buffer {
672+ b.Align()
673+
674+ buf := NewBuffer()
675+ buf.SetArea(b.area)
676+ buf.Fill(' ', ColorDefault, b.Bg)
677+
678+ b.drawBorder(buf)
679+ b.drawBorderLabel(buf)
680+
681+ return buf
682+ }
683+
684+ // GetHeight implements GridBufferer.
685+ // It returns current height of the block.
686+ func (b Block) GetHeight() int {
687+ return b.Height
688+ }
689+
690+ // SetX implements GridBufferer interface, which sets block's x position.
691+ func (b *Block) SetX(x int) {
692+ b.X = x
693+ }
694+
695+ // SetY implements GridBufferer interface, it sets y position for block.
696+ func (b *Block) SetY(y int) {
697+ b.Y = y
698+ }
699+
700+ // SetWidth implements GridBuffer interface, it sets block's width.
701+ func (b *Block) SetWidth(w int) {
702+ b.Width = w
703+ }
704+
705+ func (b Block) InnerWidth() int {
706+ return b.innerArea.Dx()
707+ }
708+
709+ func (b Block) InnerHeight() int {
710+ return b.innerArea.Dy()
711+ }
712+
713+ func (b Block) InnerX() int {
714+ return b.innerArea.Min.X
715+ }
716+
717+ func (b Block) InnerY() int { return b.innerArea.Min.Y }
718 diff --git a/vendor/github.com/gizak/termui/block_common.go b/vendor/github.com/gizak/termui/block_common.go
719new file mode 100644
720index 0000000..6438bf2
721--- /dev/null
722+++ b/vendor/github.com/gizak/termui/block_common.go
723 @@ -0,0 +1,20 @@
724+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
725+ // Use of this source code is governed by a MIT license that can
726+ // be found in the LICENSE file.
727+
728+ // +build !windows
729+
730+ package termui
731+
732+ const TOP_RIGHT = '┐'
733+ const VERTICAL_LINE = '│'
734+ const HORIZONTAL_LINE = '─'
735+ const TOP_LEFT = '┌'
736+ const BOTTOM_RIGHT = '┘'
737+ const BOTTOM_LEFT = '└'
738+ const VERTICAL_LEFT = '┤'
739+ const VERTICAL_RIGHT = '├'
740+ const HORIZONTAL_DOWN = '┬'
741+ const HORIZONTAL_UP = '┴'
742+ const QUOTA_LEFT = '«'
743+ const QUOTA_RIGHT = '»'
744 diff --git a/vendor/github.com/gizak/termui/block_test.go b/vendor/github.com/gizak/termui/block_test.go
745new file mode 100644
746index 0000000..8194179
747--- /dev/null
748+++ b/vendor/github.com/gizak/termui/block_test.go
749 @@ -0,0 +1,72 @@
750+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
751+ // Use of this source code is governed by a MIT license that can
752+ // be found in the LICENSE file.
753+
754+ package termui
755+
756+ import (
757+ "testing"
758+ )
759+
760+ func TestBlockFloat(t *testing.T) {
761+ Init()
762+ defer Close()
763+
764+ b := NewBlock()
765+ b.X = 10
766+ b.Y = 20
767+
768+ b.Float = AlignCenter
769+ b.Align()
770+ }
771+
772+ func TestBlockInnerBounds(t *testing.T) {
773+ Init()
774+ defer Close()
775+
776+ b := NewBlock()
777+ b.X = 10
778+ b.Y = 11
779+ b.Width = 12
780+ b.Height = 13
781+
782+ assert := func(name string, x, y, w, h int) {
783+ t.Log(name)
784+ area := b.InnerBounds()
785+ cx := area.Min.X
786+ cy := area.Min.Y
787+ cw := area.Dx()
788+ ch := area.Dy()
789+
790+ if cx != x {
791+ t.Errorf("expected x to be %d but got %d", x, cx)
792+ }
793+ if cy != y {
794+ t.Errorf("expected y to be %d but got %d\n%+v", y, cy, area)
795+ }
796+ if cw != w {
797+ t.Errorf("expected width to be %d but got %d", w, cw)
798+ }
799+ if ch != h {
800+ t.Errorf("expected height to be %d but got %d", h, ch)
801+ }
802+ }
803+
804+ b.Border = false
805+ assert("no border, no padding", 10, 11, 12, 13)
806+
807+ b.Border = true
808+ assert("border, no padding", 11, 12, 10, 11)
809+
810+ b.PaddingBottom = 2
811+ assert("border, 2b padding", 11, 12, 10, 9)
812+
813+ b.PaddingTop = 3
814+ assert("border, 2b 3t padding", 11, 15, 10, 6)
815+
816+ b.PaddingLeft = 4
817+ assert("border, 2b 3t 4l padding", 15, 15, 6, 6)
818+
819+ b.PaddingRight = 5
820+ assert("border, 2b 3t 4l 5r padding", 15, 15, 1, 6)
821+ }
822 diff --git a/vendor/github.com/gizak/termui/block_windows.go b/vendor/github.com/gizak/termui/block_windows.go
823new file mode 100644
824index 0000000..a4fba77
825--- /dev/null
826+++ b/vendor/github.com/gizak/termui/block_windows.go
827 @@ -0,0 +1,14 @@
828+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
829+ // Use of this source code is governed by a MIT license that can
830+ // be found in the LICENSE file.
831+
832+ // +build windows
833+
834+ package termui
835+
836+ const TOP_RIGHT = '+'
837+ const VERTICAL_LINE = '|'
838+ const HORIZONTAL_LINE = '-'
839+ const TOP_LEFT = '+'
840+ const BOTTOM_RIGHT = '+'
841+ const BOTTOM_LEFT = '+'
842 diff --git a/vendor/github.com/gizak/termui/buffer.go b/vendor/github.com/gizak/termui/buffer.go
843new file mode 100644
844index 0000000..9e3a973
845--- /dev/null
846+++ b/vendor/github.com/gizak/termui/buffer.go
847 @@ -0,0 +1,106 @@
848+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
849+ // Use of this source code is governed by a MIT license that can
850+ // be found in the LICENSE file.
851+
852+ package termui
853+
854+ import "image"
855+
856+ // Cell is a rune with assigned Fg and Bg
857+ type Cell struct {
858+ Ch rune
859+ Fg Attribute
860+ Bg Attribute
861+ }
862+
863+ // Buffer is a renderable rectangle cell data container.
864+ type Buffer struct {
865+ Area image.Rectangle // selected drawing area
866+ CellMap map[image.Point]Cell
867+ }
868+
869+ // At returns the cell at (x,y).
870+ func (b Buffer) At(x, y int) Cell {
871+ return b.CellMap[image.Pt(x, y)]
872+ }
873+
874+ // Set assigns a char to (x,y)
875+ func (b Buffer) Set(x, y int, c Cell) {
876+ b.CellMap[image.Pt(x, y)] = c
877+ }
878+
879+ // Bounds returns the domain for which At can return non-zero color.
880+ func (b Buffer) Bounds() image.Rectangle {
881+ x0, y0, x1, y1 := 0, 0, 0, 0
882+ for p := range b.CellMap {
883+ if p.X > x1 {
884+ x1 = p.X
885+ }
886+ if p.X < x0 {
887+ x0 = p.X
888+ }
889+ if p.Y > y1 {
890+ y1 = p.Y
891+ }
892+ if p.Y < y0 {
893+ y0 = p.Y
894+ }
895+ }
896+ return image.Rect(x0, y0, x1+1, y1+1)
897+ }
898+
899+ // SetArea assigns a new rect area to Buffer b.
900+ func (b *Buffer) SetArea(r image.Rectangle) {
901+ b.Area.Max = r.Max
902+ b.Area.Min = r.Min
903+ }
904+
905+ // Sync sets drawing area to the buffer's bound
906+ func (b *Buffer) Sync() {
907+ b.SetArea(b.Bounds())
908+ }
909+
910+ // NewCell returns a new cell
911+ func NewCell(ch rune, fg, bg Attribute) Cell {
912+ return Cell{ch, fg, bg}
913+ }
914+
915+ // Merge merges bs Buffers onto b
916+ func (b *Buffer) Merge(bs ...Buffer) {
917+ for _, buf := range bs {
918+ for p, v := range buf.CellMap {
919+ b.Set(p.X, p.Y, v)
920+ }
921+ b.SetArea(b.Area.Union(buf.Area))
922+ }
923+ }
924+
925+ // NewBuffer returns a new Buffer
926+ func NewBuffer() Buffer {
927+ return Buffer{
928+ CellMap: make(map[image.Point]Cell),
929+ Area: image.Rectangle{}}
930+ }
931+
932+ // Fill fills the Buffer b with ch,fg and bg.
933+ func (b Buffer) Fill(ch rune, fg, bg Attribute) {
934+ for x := b.Area.Min.X; x < b.Area.Max.X; x++ {
935+ for y := b.Area.Min.Y; y < b.Area.Max.Y; y++ {
936+ b.Set(x, y, Cell{ch, fg, bg})
937+ }
938+ }
939+ }
940+
941+ // NewFilledBuffer returns a new Buffer filled with ch, fb and bg.
942+ func NewFilledBuffer(x0, y0, x1, y1 int, ch rune, fg, bg Attribute) Buffer {
943+ buf := NewBuffer()
944+ buf.Area.Min = image.Pt(x0, y0)
945+ buf.Area.Max = image.Pt(x1, y1)
946+
947+ for x := buf.Area.Min.X; x < buf.Area.Max.X; x++ {
948+ for y := buf.Area.Min.Y; y < buf.Area.Max.Y; y++ {
949+ buf.Set(x, y, Cell{ch, fg, bg})
950+ }
951+ }
952+ return buf
953+ }
954 diff --git a/vendor/github.com/gizak/termui/buffer_test.go b/vendor/github.com/gizak/termui/buffer_test.go
955new file mode 100644
956index 0000000..aae9d08
957--- /dev/null
958+++ b/vendor/github.com/gizak/termui/buffer_test.go
959 @@ -0,0 +1,23 @@
960+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
961+ // Use of this source code is governed by a MIT license that can
962+ // be found in the LICENSE file.
963+
964+ package termui
965+
966+ import (
967+ "image"
968+ "testing"
969+ )
970+
971+ func TestBufferUnion(t *testing.T) {
972+ b0 := NewBuffer()
973+ b1 := NewBuffer()
974+
975+ b1.Area.Max.X = 100
976+ b1.Area.Max.Y = 100
977+ b0.Area.Max.X = 50
978+ b0.Merge(b1)
979+ if b0.Area.Max.X != 100 {
980+ t.Errorf("Buffer.Merge unions Area failed: should:%v, actual %v,%v", image.Rect(0, 0, 50, 0).Union(image.Rect(0, 0, 100, 100)), b1.Area, b0.Area)
981+ }
982+ }
983 diff --git a/vendor/github.com/gizak/termui/canvas.go b/vendor/github.com/gizak/termui/canvas.go
984new file mode 100644
985index 0000000..6d2513e
986--- /dev/null
987+++ b/vendor/github.com/gizak/termui/canvas.go
988 @@ -0,0 +1,72 @@
989+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
990+ // Use of this source code is governed by a MIT license that can
991+ // be found in the LICENSE file.
992+
993+ package termui
994+
995+ /*
996+ dots:
997+ ,___,
998+ |1 4|
999+ |2 5|
1000+ |3 6|
1001+ |7 8|
1002+ `````
1003+ */
1004+
1005+ var brailleBase = '\u2800'
1006+
1007+ var brailleOftMap = [4][2]rune{
1008+ {'\u0001', '\u0008'},
1009+ {'\u0002', '\u0010'},
1010+ {'\u0004', '\u0020'},
1011+ {'\u0040', '\u0080'}}
1012+
1013+ // Canvas contains drawing map: i,j -> rune
1014+ type Canvas map[[2]int]rune
1015+
1016+ // NewCanvas returns an empty Canvas
1017+ func NewCanvas() Canvas {
1018+ return make(map[[2]int]rune)
1019+ }
1020+
1021+ func chOft(x, y int) rune {
1022+ return brailleOftMap[y%4][x%2]
1023+ }
1024+
1025+ func (c Canvas) rawCh(x, y int) rune {
1026+ if ch, ok := c[[2]int{x, y}]; ok {
1027+ return ch
1028+ }
1029+ return '\u0000' //brailleOffset
1030+ }
1031+
1032+ // return coordinate in terminal
1033+ func chPos(x, y int) (int, int) {
1034+ return y / 4, x / 2
1035+ }
1036+
1037+ // Set sets a point (x,y) in the virtual coordinate
1038+ func (c Canvas) Set(x, y int) {
1039+ i, j := chPos(x, y)
1040+ ch := c.rawCh(i, j)
1041+ ch |= chOft(x, y)
1042+ c[[2]int{i, j}] = ch
1043+ }
1044+
1045+ // Unset removes point (x,y)
1046+ func (c Canvas) Unset(x, y int) {
1047+ i, j := chPos(x, y)
1048+ ch := c.rawCh(i, j)
1049+ ch &= ^chOft(x, y)
1050+ c[[2]int{i, j}] = ch
1051+ }
1052+
1053+ // Buffer returns un-styled points
1054+ func (c Canvas) Buffer() Buffer {
1055+ buf := NewBuffer()
1056+ for k, v := range c {
1057+ buf.Set(k[0], k[1], Cell{Ch: v + brailleBase})
1058+ }
1059+ return buf
1060+ }
1061 diff --git a/vendor/github.com/gizak/termui/canvas_test.go b/vendor/github.com/gizak/termui/canvas_test.go
1062new file mode 100644
1063index 0000000..f73ce48
1064--- /dev/null
1065+++ b/vendor/github.com/gizak/termui/canvas_test.go
1066 @@ -0,0 +1,57 @@
1067+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1068+ // Use of this source code is governed by a MIT license that can
1069+ // be found in the LICENSE file.
1070+
1071+ // +build ignore
1072+
1073+ package termui
1074+
1075+ import (
1076+ "testing"
1077+
1078+ "github.com/davecgh/go-spew/spew"
1079+ )
1080+
1081+ func TestCanvasSet(t *testing.T) {
1082+ c := NewCanvas()
1083+ c.Set(0, 0)
1084+ c.Set(0, 1)
1085+ c.Set(0, 2)
1086+ c.Set(0, 3)
1087+ c.Set(1, 3)
1088+ c.Set(2, 3)
1089+ c.Set(3, 3)
1090+ c.Set(4, 3)
1091+ c.Set(5, 3)
1092+ spew.Dump(c)
1093+ }
1094+
1095+ func TestCanvasUnset(t *testing.T) {
1096+ c := NewCanvas()
1097+ c.Set(0, 0)
1098+ c.Set(0, 1)
1099+ c.Set(0, 2)
1100+ c.Unset(0, 2)
1101+ spew.Dump(c)
1102+ c.Unset(0, 3)
1103+ spew.Dump(c)
1104+ }
1105+
1106+ func TestCanvasBuffer(t *testing.T) {
1107+ c := NewCanvas()
1108+ c.Set(0, 0)
1109+ c.Set(0, 1)
1110+ c.Set(0, 2)
1111+ c.Set(0, 3)
1112+ c.Set(1, 3)
1113+ c.Set(2, 3)
1114+ c.Set(3, 3)
1115+ c.Set(4, 3)
1116+ c.Set(5, 3)
1117+ c.Set(6, 3)
1118+ c.Set(7, 2)
1119+ c.Set(8, 1)
1120+ c.Set(9, 0)
1121+ bufs := c.Buffer()
1122+ spew.Dump(bufs)
1123+ }
1124 diff --git a/vendor/github.com/gizak/termui/config.py b/vendor/github.com/gizak/termui/config.py
1125new file mode 100644
1126index 0000000..30fadcf
1127--- /dev/null
1128+++ b/vendor/github.com/gizak/termui/config.py
1129 @@ -0,0 +1,54 @@
1130+ #!/usr/bin/env python3
1131+
1132+ import re
1133+ import os
1134+ import io
1135+
1136+ copyright = """// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1137+ // Use of this source code is governed by a MIT license that can
1138+ // be found in the LICENSE file.
1139+
1140+ """
1141+
1142+ exclude_dirs = [".git", "_docs"]
1143+ exclude_files = []
1144+ include_dirs = [".", "debug", "extra", "test", "_example"]
1145+
1146+
1147+ def is_target(fpath):
1148+ if os.path.splitext(fpath)[-1] == ".go":
1149+ return True
1150+ return False
1151+
1152+
1153+ def update_copyright(fpath):
1154+ print("processing " + fpath)
1155+ f = io.open(fpath, 'r', encoding='utf-8')
1156+ fstr = f.read()
1157+ f.close()
1158+
1159+ # remove old
1160+ m = re.search('^// Copyright .+?\r?\n\r?\n', fstr, re.MULTILINE|re.DOTALL)
1161+ if m:
1162+ fstr = fstr[m.end():]
1163+
1164+ # add new
1165+ fstr = copyright + fstr
1166+ f = io.open(fpath, 'w',encoding='utf-8')
1167+ f.write(fstr)
1168+ f.close()
1169+
1170+
1171+ def main():
1172+ for d in include_dirs:
1173+ files = [
1174+ os.path.join(d, f) for f in os.listdir(d)
1175+ if os.path.isfile(os.path.join(d, f))
1176+ ]
1177+ for f in files:
1178+ if is_target(f):
1179+ update_copyright(f)
1180+
1181+
1182+ if __name__ == '__main__':
1183+ main()
1184 diff --git a/vendor/github.com/gizak/termui/doc.go b/vendor/github.com/gizak/termui/doc.go
1185new file mode 100644
1186index 0000000..13924eb
1187--- /dev/null
1188+++ b/vendor/github.com/gizak/termui/doc.go
1189 @@ -0,0 +1,29 @@
1190+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1191+ // Use of this source code is governed by a MIT license that can
1192+ // be found in the LICENSE file.
1193+
1194+ /*
1195+ Package termui is a library designed for creating command line UI. For more info, goto http://github.com/gizak/termui
1196+
1197+ A simplest example:
1198+ package main
1199+
1200+ import ui "github.com/gizak/termui"
1201+
1202+ func main() {
1203+ if err:=ui.Init(); err != nil {
1204+ panic(err)
1205+ }
1206+ defer ui.Close()
1207+
1208+ g := ui.NewGauge()
1209+ g.Percent = 50
1210+ g.Width = 50
1211+ g.BorderLabel = "Gauge"
1212+
1213+ ui.Render(g)
1214+
1215+ ui.Loop()
1216+ }
1217+ */
1218+ package termui
1219 diff --git a/vendor/github.com/gizak/termui/events.go b/vendor/github.com/gizak/termui/events.go
1220new file mode 100644
1221index 0000000..eb7319b
1222--- /dev/null
1223+++ b/vendor/github.com/gizak/termui/events.go
1224 @@ -0,0 +1,323 @@
1225+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1226+ // Use of this source code is governed by a MIT license that can
1227+ // be found in the LICENSE file.
1228+
1229+ package termui
1230+
1231+ import (
1232+ "path"
1233+ "strconv"
1234+ "sync"
1235+ "time"
1236+
1237+ "github.com/nsf/termbox-go"
1238+ )
1239+
1240+ type Event struct {
1241+ Type string
1242+ Path string
1243+ From string
1244+ To string
1245+ Data interface{}
1246+ Time int64
1247+ }
1248+
1249+ var sysEvtChs []chan Event
1250+
1251+ type EvtKbd struct {
1252+ KeyStr string
1253+ }
1254+
1255+ func evtKbd(e termbox.Event) EvtKbd {
1256+ ek := EvtKbd{}
1257+
1258+ k := string(e.Ch)
1259+ pre := ""
1260+ mod := ""
1261+
1262+ if e.Mod == termbox.ModAlt {
1263+ mod = "M-"
1264+ }
1265+ if e.Ch == 0 {
1266+ if e.Key > 0xFFFF-12 {
1267+ k = "<f" + strconv.Itoa(0xFFFF-int(e.Key)+1) + ">"
1268+ } else if e.Key > 0xFFFF-25 {
1269+ ks := []string{"<insert>", "<delete>", "<home>", "<end>", "<previous>", "<next>", "<up>", "<down>", "<left>", "<right>"}
1270+ k = ks[0xFFFF-int(e.Key)-12]
1271+ }
1272+
1273+ if e.Key <= 0x7F {
1274+ pre = "C-"
1275+ k = string('a' - 1 + int(e.Key))
1276+ kmap := map[termbox.Key][2]string{
1277+ termbox.KeyCtrlSpace: {"C-", "<space>"},
1278+ termbox.KeyBackspace: {"", "<backspace>"},
1279+ termbox.KeyTab: {"", "<tab>"},
1280+ termbox.KeyEnter: {"", "<enter>"},
1281+ termbox.KeyEsc: {"", "<escape>"},
1282+ termbox.KeyCtrlBackslash: {"C-", "\\"},
1283+ termbox.KeyCtrlSlash: {"C-", "/"},
1284+ termbox.KeySpace: {"", "<space>"},
1285+ termbox.KeyCtrl8: {"C-", "8"},
1286+ }
1287+ if sk, ok := kmap[e.Key]; ok {
1288+ pre = sk[0]
1289+ k = sk[1]
1290+ }
1291+ }
1292+ }
1293+
1294+ ek.KeyStr = pre + mod + k
1295+ return ek
1296+ }
1297+
1298+ func crtTermboxEvt(e termbox.Event) Event {
1299+ systypemap := map[termbox.EventType]string{
1300+ termbox.EventKey: "keyboard",
1301+ termbox.EventResize: "window",
1302+ termbox.EventMouse: "mouse",
1303+ termbox.EventError: "error",
1304+ termbox.EventInterrupt: "interrupt",
1305+ }
1306+ ne := Event{From: "/sys", Time: time.Now().Unix()}
1307+ typ := e.Type
1308+ ne.Type = systypemap[typ]
1309+
1310+ switch typ {
1311+ case termbox.EventKey:
1312+ kbd := evtKbd(e)
1313+ ne.Path = "/sys/kbd/" + kbd.KeyStr
1314+ ne.Data = kbd
1315+ case termbox.EventResize:
1316+ wnd := EvtWnd{}
1317+ wnd.Width = e.Width
1318+ wnd.Height = e.Height
1319+ ne.Path = "/sys/wnd/resize"
1320+ ne.Data = wnd
1321+ case termbox.EventError:
1322+ err := EvtErr(e.Err)
1323+ ne.Path = "/sys/err"
1324+ ne.Data = err
1325+ case termbox.EventMouse:
1326+ m := EvtMouse{}
1327+ m.X = e.MouseX
1328+ m.Y = e.MouseY
1329+ ne.Path = "/sys/mouse"
1330+ ne.Data = m
1331+ }
1332+ return ne
1333+ }
1334+
1335+ type EvtWnd struct {
1336+ Width int
1337+ Height int
1338+ }
1339+
1340+ type EvtMouse struct {
1341+ X int
1342+ Y int
1343+ Press string
1344+ }
1345+
1346+ type EvtErr error
1347+
1348+ func hookTermboxEvt() {
1349+ for {
1350+ e := termbox.PollEvent()
1351+
1352+ for _, c := range sysEvtChs {
1353+ go func(ch chan Event) {
1354+ ch <- crtTermboxEvt(e)
1355+ }(c)
1356+ }
1357+ }
1358+ }
1359+
1360+ func NewSysEvtCh() chan Event {
1361+ ec := make(chan Event)
1362+ sysEvtChs = append(sysEvtChs, ec)
1363+ return ec
1364+ }
1365+
1366+ var DefaultEvtStream = NewEvtStream()
1367+
1368+ type EvtStream struct {
1369+ sync.RWMutex
1370+ srcMap map[string]chan Event
1371+ stream chan Event
1372+ wg sync.WaitGroup
1373+ sigStopLoop chan Event
1374+ Handlers map[string]func(Event)
1375+ hook func(Event)
1376+ }
1377+
1378+ func NewEvtStream() *EvtStream {
1379+ return &EvtStream{
1380+ srcMap: make(map[string]chan Event),
1381+ stream: make(chan Event),
1382+ Handlers: make(map[string]func(Event)),
1383+ sigStopLoop: make(chan Event),
1384+ }
1385+ }
1386+
1387+ func (es *EvtStream) Init() {
1388+ es.Merge("internal", es.sigStopLoop)
1389+ go func() {
1390+ es.wg.Wait()
1391+ close(es.stream)
1392+ }()
1393+ }
1394+
1395+ func cleanPath(p string) string {
1396+ if p == "" {
1397+ return "/"
1398+ }
1399+ if p[0] != '/' {
1400+ p = "/" + p
1401+ }
1402+ return path.Clean(p)
1403+ }
1404+
1405+ func isPathMatch(pattern, path string) bool {
1406+ if len(pattern) == 0 {
1407+ return false
1408+ }
1409+ n := len(pattern)
1410+ return len(path) >= n && path[0:n] == pattern
1411+ }
1412+
1413+ func (es *EvtStream) Merge(name string, ec chan Event) {
1414+ es.Lock()
1415+ defer es.Unlock()
1416+
1417+ es.wg.Add(1)
1418+ es.srcMap[name] = ec
1419+
1420+ go func(a chan Event) {
1421+ for n := range a {
1422+ n.From = name
1423+ es.stream <- n
1424+ }
1425+ es.wg.Done()
1426+ }(ec)
1427+ }
1428+
1429+ func (es *EvtStream) Handle(path string, handler func(Event)) {
1430+ es.Handlers[cleanPath(path)] = handler
1431+ }
1432+
1433+ func findMatch(mux map[string]func(Event), path string) string {
1434+ n := -1
1435+ pattern := ""
1436+ for m := range mux {
1437+ if !isPathMatch(m, path) {
1438+ continue
1439+ }
1440+ if len(m) > n {
1441+ pattern = m
1442+ n = len(m)
1443+ }
1444+ }
1445+ return pattern
1446+
1447+ }
1448+ // Remove all existing defined Handlers from the map
1449+ func (es *EvtStream) ResetHandlers() {
1450+ for Path, _ := range es.Handlers {
1451+ delete(es.Handlers, Path)
1452+ }
1453+ return
1454+ }
1455+
1456+ func (es *EvtStream) match(path string) string {
1457+ return findMatch(es.Handlers, path)
1458+ }
1459+
1460+ func (es *EvtStream) Hook(f func(Event)) {
1461+ es.hook = f
1462+ }
1463+
1464+ func (es *EvtStream) Loop() {
1465+ for e := range es.stream {
1466+ switch e.Path {
1467+ case "/sig/stoploop":
1468+ return
1469+ }
1470+ go func(a Event) {
1471+ es.RLock()
1472+ defer es.RUnlock()
1473+ if pattern := es.match(a.Path); pattern != "" {
1474+ es.Handlers[pattern](a)
1475+ }
1476+ }(e)
1477+ if es.hook != nil {
1478+ es.hook(e)
1479+ }
1480+ }
1481+ }
1482+
1483+ func (es *EvtStream) StopLoop() {
1484+ go func() {
1485+ e := Event{
1486+ Path: "/sig/stoploop",
1487+ }
1488+ es.sigStopLoop <- e
1489+ }()
1490+ }
1491+
1492+ func Merge(name string, ec chan Event) {
1493+ DefaultEvtStream.Merge(name, ec)
1494+ }
1495+
1496+ func Handle(path string, handler func(Event)) {
1497+ DefaultEvtStream.Handle(path, handler)
1498+ }
1499+
1500+ func Loop() {
1501+ DefaultEvtStream.Loop()
1502+ }
1503+
1504+ func StopLoop() {
1505+ DefaultEvtStream.StopLoop()
1506+ }
1507+
1508+ type EvtTimer struct {
1509+ Duration time.Duration
1510+ Count uint64
1511+ }
1512+
1513+ func NewTimerCh(du time.Duration) chan Event {
1514+ t := make(chan Event)
1515+
1516+ go func(a chan Event) {
1517+ n := uint64(0)
1518+ for {
1519+ n++
1520+ time.Sleep(du)
1521+ e := Event{}
1522+ e.Type = "timer"
1523+ e.Path = "/timer/" + du.String()
1524+ e.Time = time.Now().Unix()
1525+ e.Data = EvtTimer{
1526+ Duration: du,
1527+ Count: n,
1528+ }
1529+ t <- e
1530+
1531+ }
1532+ }(t)
1533+ return t
1534+ }
1535+
1536+ var DefualtHandler = func(e Event) {
1537+ }
1538+
1539+ var usrEvtCh = make(chan Event)
1540+
1541+ func SendCustomEvt(path string, data interface{}) {
1542+ e := Event{}
1543+ e.Path = path
1544+ e.Data = data
1545+ e.Time = time.Now().Unix()
1546+ usrEvtCh <- e
1547+ }
1548 diff --git a/vendor/github.com/gizak/termui/events_test.go b/vendor/github.com/gizak/termui/events_test.go
1549new file mode 100644
1550index 0000000..4e369e5
1551--- /dev/null
1552+++ b/vendor/github.com/gizak/termui/events_test.go
1553 @@ -0,0 +1,37 @@
1554+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1555+ // Use of this source code is governed by a MIT license that can
1556+ // be found in the LICENSE file.
1557+
1558+ package termui
1559+
1560+ import "testing"
1561+
1562+ var ps = []string{
1563+ "",
1564+ "/",
1565+ "/a",
1566+ "/b",
1567+ "/a/c",
1568+ "/a/b",
1569+ "/a/b/c",
1570+ "/a/b/c/d",
1571+ "/a/b/c/d/"}
1572+
1573+ func TestMatchScore(t *testing.T) {
1574+ chk := func(a, b string, s bool) {
1575+ if c := isPathMatch(a, b); c != s {
1576+ t.Errorf("\na:%s\nb:%s\nshould:%t\nactual:%t", a, b, s, c)
1577+ }
1578+ }
1579+
1580+ chk(ps[1], ps[1], true)
1581+ chk(ps[1], ps[2], true)
1582+ chk(ps[2], ps[1], false)
1583+ chk(ps[4], ps[1], false)
1584+ chk(ps[6], ps[2], false)
1585+ chk(ps[4], ps[5], false)
1586+ }
1587+
1588+ func TestCrtEvt(t *testing.T) {
1589+
1590+ }
1591 diff --git a/vendor/github.com/gizak/termui/gauge.go b/vendor/github.com/gizak/termui/gauge.go
1592new file mode 100644
1593index 0000000..9f6ce3a
1594--- /dev/null
1595+++ b/vendor/github.com/gizak/termui/gauge.go
1596 @@ -0,0 +1,109 @@
1597+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1598+ // Use of this source code is governed by a MIT license that can
1599+ // be found in the LICENSE file.
1600+
1601+ package termui
1602+
1603+ import (
1604+ "strconv"
1605+ "strings"
1606+ )
1607+
1608+ // Gauge is a progress bar like widget.
1609+ // A simple example:
1610+ /*
1611+ g := termui.NewGauge()
1612+ g.Percent = 40
1613+ g.Width = 50
1614+ g.Height = 3
1615+ g.BorderLabel = "Slim Gauge"
1616+ g.BarColor = termui.ColorRed
1617+ g.PercentColor = termui.ColorBlue
1618+ */
1619+
1620+ const ColorUndef Attribute = Attribute(^uint16(0))
1621+
1622+ type Gauge struct {
1623+ Block
1624+ Percent int
1625+ BarColor Attribute
1626+ PercentColor Attribute
1627+ PercentColorHighlighted Attribute
1628+ Label string
1629+ LabelAlign Align
1630+ }
1631+
1632+ // NewGauge return a new gauge with current theme.
1633+ func NewGauge() *Gauge {
1634+ g := &Gauge{
1635+ Block: *NewBlock(),
1636+ PercentColor: ThemeAttr("gauge.percent.fg"),
1637+ BarColor: ThemeAttr("gauge.bar.bg"),
1638+ Label: "{{percent}}%",
1639+ LabelAlign: AlignCenter,
1640+ PercentColorHighlighted: ColorUndef,
1641+ }
1642+
1643+ g.Width = 12
1644+ g.Height = 5
1645+ return g
1646+ }
1647+
1648+ // Buffer implements Bufferer interface.
1649+ func (g *Gauge) Buffer() Buffer {
1650+ buf := g.Block.Buffer()
1651+
1652+ // plot bar
1653+ w := g.Percent * g.innerArea.Dx() / 100
1654+ for i := 0; i < g.innerArea.Dy(); i++ {
1655+ for j := 0; j < w; j++ {
1656+ c := Cell{}
1657+ c.Ch = ' '
1658+ c.Bg = g.BarColor
1659+ if c.Bg == ColorDefault {
1660+ c.Bg |= AttrReverse
1661+ }
1662+ buf.Set(g.innerArea.Min.X+j, g.innerArea.Min.Y+i, c)
1663+ }
1664+ }
1665+
1666+ // plot percentage
1667+ s := strings.Replace(g.Label, "{{percent}}", strconv.Itoa(g.Percent), -1)
1668+ pry := g.innerArea.Min.Y + g.innerArea.Dy()/2
1669+ rs := str2runes(s)
1670+ var pos int
1671+ switch g.LabelAlign {
1672+ case AlignLeft:
1673+ pos = 0
1674+
1675+ case AlignCenter:
1676+ pos = (g.innerArea.Dx() - strWidth(s)) / 2
1677+
1678+ case AlignRight:
1679+ pos = g.innerArea.Dx() - strWidth(s) - 1
1680+ }
1681+ pos += g.innerArea.Min.X
1682+
1683+ for i, v := range rs {
1684+ c := Cell{
1685+ Ch: v,
1686+ Fg: g.PercentColor,
1687+ }
1688+
1689+ if w+g.innerArea.Min.X > pos+i {
1690+ c.Bg = g.BarColor
1691+ if c.Bg == ColorDefault {
1692+ c.Bg |= AttrReverse
1693+ }
1694+
1695+ if g.PercentColorHighlighted != ColorUndef {
1696+ c.Fg = g.PercentColorHighlighted
1697+ }
1698+ } else {
1699+ c.Bg = g.Block.Bg
1700+ }
1701+
1702+ buf.Set(1+pos+i, pry, c)
1703+ }
1704+ return buf
1705+ }
1706 diff --git a/vendor/github.com/gizak/termui/glide.lock b/vendor/github.com/gizak/termui/glide.lock
1707new file mode 100644
1708index 0000000..be5952d
1709--- /dev/null
1710+++ b/vendor/github.com/gizak/termui/glide.lock
1711 @@ -0,0 +1,30 @@
1712+ hash: 7a754ba100256404a978b2fc8738aee337beb822458e4b6060399fb89ebd215c
1713+ updated: 2016-11-03T17:39:24.323773674-04:00
1714+ imports:
1715+ - name: github.com/maruel/panicparse
1716+ version: ad661195ed0e88491e0f14be6613304e3b1141d6
1717+ subpackages:
1718+ - stack
1719+ - name: github.com/mattn/go-runewidth
1720+ version: 737072b4e32b7a5018b4a7125da8d12de90e8045
1721+ - name: github.com/mitchellh/go-wordwrap
1722+ version: ad45545899c7b13c020ea92b2072220eefad42b8
1723+ - name: github.com/nsf/termbox-go
1724+ version: b6acae516ace002cb8105a89024544a1480655a5
1725+ - name: golang.org/x/net
1726+ version: 569280fa63be4e201b975e5411e30a92178f0118
1727+ subpackages:
1728+ - websocket
1729+ testImports:
1730+ - name: github.com/davecgh/go-spew
1731+ version: 346938d642f2ec3594ed81d874461961cd0faa76
1732+ subpackages:
1733+ - spew
1734+ - name: github.com/pmezard/go-difflib
1735+ version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
1736+ subpackages:
1737+ - difflib
1738+ - name: github.com/stretchr/testify
1739+ version: 976c720a22c8eb4eb6a0b4348ad85ad12491a506
1740+ subpackages:
1741+ - assert
1742 diff --git a/vendor/github.com/gizak/termui/glide.yaml b/vendor/github.com/gizak/termui/glide.yaml
1743new file mode 100644
1744index 0000000..a681231
1745--- /dev/null
1746+++ b/vendor/github.com/gizak/termui/glide.yaml
1747 @@ -0,0 +1,9 @@
1748+ package: github.com/gizak/termui
1749+ import:
1750+ - package: github.com/mattn/go-runewidth
1751+ - package: github.com/mitchellh/go-wordwrap
1752+ - package: github.com/nsf/termbox-go
1753+ - package: golang.org/x/net
1754+ subpackages:
1755+ - websocket
1756+ - package: github.com/maruel/panicparse
1757 diff --git a/vendor/github.com/gizak/termui/grid.go b/vendor/github.com/gizak/termui/grid.go
1758new file mode 100644
1759index 0000000..a950232
1760--- /dev/null
1761+++ b/vendor/github.com/gizak/termui/grid.go
1762 @@ -0,0 +1,279 @@
1763+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
1764+ // Use of this source code is governed by a MIT license that can
1765+ // be found in the LICENSE file.
1766+
1767+ package termui
1768+
1769+ // GridBufferer introduces a Bufferer that can be manipulated by Grid.
1770+ type GridBufferer interface {
1771+ Bufferer
1772+ GetHeight() int
1773+ SetWidth(int)
1774+ SetX(int)
1775+ SetY(int)
1776+ }
1777+
1778+ // Row builds a layout tree
1779+ type Row struct {
1780+ Cols []*Row //children
1781+ Widget GridBufferer // root
1782+ X int
1783+ Y int
1784+ Width int
1785+ Height int
1786+ Span int
1787+ Offset int
1788+ }
1789+
1790+ // calculate and set the underlying layout tree's x, y, height and width.
1791+ func (r *Row) calcLayout() {
1792+ r.assignWidth(r.Width)
1793+ r.Height = r.solveHeight()
1794+ r.assignX(r.X)
1795+ r.assignY(r.Y)
1796+ }
1797+
1798+ // tell if the node is leaf in the tree.
1799+ func (r *Row) isLeaf() bool {
1800+ return r.Cols == nil || len(r.Cols) == 0
1801+ }
1802+
1803+ func (r *Row) isRenderableLeaf() bool {
1804+ return r.isLeaf() && r.Widget != nil
1805+ }
1806+
1807+ // assign widgets' (and their parent rows') width recursively.
1808+ func (r *Row) assignWidth(w int) {
1809+ r.SetWidth(w)
1810+
1811+ accW := 0 // acc span and offset
1812+ calcW := make([]int, len(r.Cols)) // calculated width
1813+ calcOftX := make([]int, len(r.Cols)) // computated start position of x
1814+
1815+ for i, c := range r.Cols {
1816+ accW += c.Span + c.Offset
1817+ cw := int(float64(c.Span*r.Width) / 12.0)
1818+
1819+ if i >= 1 {
1820+ calcOftX[i] = calcOftX[i-1] +
1821+ calcW[i-1] +
1822+ int(float64(r.Cols[i-1].Offset*r.Width)/12.0)
1823+ }
1824+
1825+ // use up the space if it is the last col
1826+ if i == len(r.Cols)-1 && accW == 12 {
1827+ cw = r.Width - calcOftX[i]
1828+ }
1829+ calcW[i] = cw
1830+ r.Cols[i].assignWidth(cw)
1831+ }
1832+ }
1833+
1834+ // bottom up calc and set rows' (and their widgets') height,
1835+ // return r's total height.
1836+ func (r *Row) solveHeight() int {
1837+ if r.isRenderableLeaf() {
1838+ r.Height = r.Widget.GetHeight()
1839+ return r.Widget.GetHeight()
1840+ }
1841+
1842+ maxh := 0
1843+ if !r.isLeaf() {
1844+ for _, c := range r.Cols {
1845+ nh := c.solveHeight()
1846+ // when embed rows in Cols, row widgets stack up
1847+ if r.Widget != nil {
1848+ nh += r.Widget.GetHeight()
1849+ }
1850+ if nh > maxh {
1851+ maxh = nh
1852+ }
1853+ }
1854+ }
1855+
1856+ r.Height = maxh
1857+ return maxh
1858+ }
1859+
1860+ // recursively assign x position for r tree.
1861+ func (r *Row) assignX(x int) {
1862+ r.SetX(x)
1863+
1864+ if !r.isLeaf() {
1865+ acc := 0
1866+ for i, c := range r.Cols {
1867+ if c.Offset != 0 {
1868+ acc += int(float64(c.Offset*r.Width) / 12.0)
1869+ }
1870+ r.Cols[i].assignX(x + acc)
1871+ acc += c.Width
1872+ }
1873+ }
1874+ }
1875+
1876+ // recursively assign y position to r.
1877+ func (r *Row) assignY(y int) {
1878+ r.SetY(y)
1879+
1880+ if r.isLeaf() {
1881+ return
1882+ }
1883+
1884+ for i := range r.Cols {
1885+ acc := 0
1886+ if r.Widget != nil {
1887+ acc = r.Widget.GetHeight()
1888+ }
1889+ r.Cols[i].assignY(y + acc)
1890+ }
1891+
1892+ }
1893+
1894+ // GetHeight implements GridBufferer interface.
1895+ func (r Row) GetHeight() int {
1896+ return r.Height
1897+ }
1898+
1899+ // SetX implements GridBufferer interface.
1900+ func (r *Row) SetX(x int) {
1901+ r.X = x
1902+ if r.Widget != nil {
1903+ r.Widget.SetX(x)
1904+ }
1905+ }
1906+
1907+ // SetY implements GridBufferer interface.
1908+ func (r *Row) SetY(y int) {
1909+ r.Y = y
1910+ if r.Widget != nil {
1911+ r.Widget.SetY(y)
1912+ }
1913+ }
1914+
1915+ // SetWidth implements GridBufferer interface.
1916+ func (r *Row) SetWidth(w int) {
1917+ r.Width = w
1918+ if r.Widget != nil {
1919+ r.Widget.SetWidth(w)
1920+ }
1921+ }
1922+
1923+ // Buffer implements Bufferer interface,
1924+ // recursively merge all widgets buffer
1925+ func (r *Row) Buffer() Buffer {
1926+ merged := NewBuffer()
1927+
1928+ if r.isRenderableLeaf() {
1929+ return r.Widget.Buffer()
1930+ }
1931+
1932+ // for those are not leaves but have a renderable widget
1933+ if r.Widget != nil {
1934+ merged.Merge(r.Widget.Buffer())
1935+ }
1936+
1937+ // collect buffer from children
1938+ if !r.isLeaf() {
1939+ for _, c := range r.Cols {
1940+ merged.Merge(c.Buffer())
1941+ }
1942+ }
1943+
1944+ return merged
1945+ }
1946+
1947+ // Grid implements 12 columns system.
1948+ // A simple example:
1949+ /*
1950+ import ui "github.com/gizak/termui"
1951+ // init and create widgets...
1952+
1953+ // build
1954+ ui.Body.AddRows(
1955+ ui.NewRow(
1956+ ui.NewCol(6, 0, widget0),
1957+ ui.NewCol(6, 0, widget1)),
1958+ ui.NewRow(
1959+ ui.NewCol(3, 0, widget2),
1960+ ui.NewCol(3, 0, widget30, widget31, widget32),
1961+ ui.NewCol(6, 0, widget4)))
1962+
1963+ // calculate layout
1964+ ui.Body.Align()
1965+
1966+ ui.Render(ui.Body)
1967+ */
1968+ type Grid struct {
1969+ Rows []*Row
1970+ Width int
1971+ X int
1972+ Y int
1973+ BgColor Attribute
1974+ }
1975+
1976+ // NewGrid returns *Grid with given rows.
1977+ func NewGrid(rows ...*Row) *Grid {
1978+ return &Grid{Rows: rows}
1979+ }
1980+
1981+ // AddRows appends given rows to Grid.
1982+ func (g *Grid) AddRows(rs ...*Row) {
1983+ g.Rows = append(g.Rows, rs...)
1984+ }
1985+
1986+ // NewRow creates a new row out of given columns.
1987+ func NewRow(cols ...*Row) *Row {
1988+ rs := &Row{Span: 12, Cols: cols}
1989+ return rs
1990+ }
1991+
1992+ // NewCol accepts: widgets are LayoutBufferer or widgets is A NewRow.
1993+ // Note that if multiple widgets are provided, they will stack up in the col.
1994+ func NewCol(span, offset int, widgets ...GridBufferer) *Row {
1995+ r := &Row{Span: span, Offset: offset}
1996+
1997+ if widgets != nil && len(widgets) == 1 {
1998+ wgt := widgets[0]
1999+ nw, isRow := wgt.(*Row)
2000+ if isRow {
2001+ r.Cols = nw.Cols
2002+ } else {
2003+ r.Widget = wgt
2004+ }
2005+ return r
2006+ }
2007+
2008+ r.Cols = []*Row{}
2009+ ir := r
2010+ for _, w := range widgets {
2011+ nr := &Row{Span: 12, Widget: w}
2012+ ir.Cols = []*Row{nr}
2013+ ir = nr
2014+ }
2015+
2016+ return r
2017+ }
2018+
2019+ // Align calculate each rows' layout.
2020+ func (g *Grid) Align() {
2021+ h := 0
2022+ for _, r := range g.Rows {
2023+ r.SetWidth(g.Width)
2024+ r.SetX(g.X)
2025+ r.SetY(g.Y + h)
2026+ r.calcLayout()
2027+ h += r.GetHeight()
2028+ }
2029+ }
2030+
2031+ // Buffer implments Bufferer interface.
2032+ func (g Grid) Buffer() Buffer {
2033+ buf := NewBuffer()
2034+
2035+ for _, r := range g.Rows {
2036+ buf.Merge(r.Buffer())
2037+ }
2038+ return buf
2039+ }
2040+
2041+ var Body *Grid
2042 diff --git a/vendor/github.com/gizak/termui/grid_test.go b/vendor/github.com/gizak/termui/grid_test.go
2043new file mode 100644
2044index 0000000..7b7b0b7
2045--- /dev/null
2046+++ b/vendor/github.com/gizak/termui/grid_test.go
2047 @@ -0,0 +1,80 @@
2048+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2049+ // Use of this source code is governed by a MIT license that can
2050+ // be found in the LICENSE file.
2051+
2052+ package termui
2053+
2054+ import (
2055+ "testing"
2056+
2057+ "github.com/davecgh/go-spew/spew"
2058+ )
2059+
2060+ var r *Row
2061+
2062+ func TestRowWidth(t *testing.T) {
2063+ p0 := NewBlock()
2064+ p0.Height = 1
2065+ p1 := NewBlock()
2066+ p1.Height = 1
2067+ p2 := NewBlock()
2068+ p2.Height = 1
2069+ p3 := NewBlock()
2070+ p3.Height = 1
2071+
2072+ /* test against tree:
2073+
2074+ r
2075+ / \
2076+ 0:w 1
2077+ / \
2078+ 10:w 11
2079+ /
2080+ 110:w
2081+ /
2082+ 1100:w
2083+ */
2084+
2085+ r = NewRow(
2086+ NewCol(6, 0, p0),
2087+ NewCol(6, 0,
2088+ NewRow(
2089+ NewCol(6, 0, p1),
2090+ NewCol(6, 0, p2, p3))))
2091+
2092+ r.assignWidth(100)
2093+ if r.Width != 100 ||
2094+ (r.Cols[0].Width) != 50 ||
2095+ (r.Cols[1].Width) != 50 ||
2096+ (r.Cols[1].Cols[0].Width) != 25 ||
2097+ (r.Cols[1].Cols[1].Width) != 25 ||
2098+ (r.Cols[1].Cols[1].Cols[0].Width) != 25 ||
2099+ (r.Cols[1].Cols[1].Cols[0].Cols[0].Width) != 25 {
2100+ t.Error("assignWidth fails")
2101+ }
2102+ }
2103+
2104+ func TestRowHeight(t *testing.T) {
2105+ spew.Dump()
2106+
2107+ if (r.solveHeight()) != 2 ||
2108+ (r.Cols[1].Cols[1].Height) != 2 ||
2109+ (r.Cols[1].Cols[1].Cols[0].Height) != 2 ||
2110+ (r.Cols[1].Cols[0].Height) != 1 {
2111+ t.Error("solveHeight fails")
2112+ }
2113+ }
2114+
2115+ func TestAssignXY(t *testing.T) {
2116+ r.assignX(0)
2117+ r.assignY(0)
2118+ if (r.Cols[0].X) != 0 ||
2119+ (r.Cols[1].Cols[0].X) != 50 ||
2120+ (r.Cols[1].Cols[1].X) != 75 ||
2121+ (r.Cols[1].Cols[1].Cols[0].X) != 75 ||
2122+ (r.Cols[1].Cols[0].Y) != 0 ||
2123+ (r.Cols[1].Cols[1].Cols[0].Y) != 0 ||
2124+ (r.Cols[1].Cols[1].Cols[0].Cols[0].Y) != 1 {
2125+ t.Error("assignXY fails")
2126+ }
2127+ }
2128 diff --git a/vendor/github.com/gizak/termui/helper.go b/vendor/github.com/gizak/termui/helper.go
2129new file mode 100644
2130index 0000000..18a6770
2131--- /dev/null
2132+++ b/vendor/github.com/gizak/termui/helper.go
2133 @@ -0,0 +1,222 @@
2134+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2135+ // Use of this source code is governed by a MIT license that can
2136+ // be found in the LICENSE file.
2137+
2138+ package termui
2139+
2140+ import (
2141+ "regexp"
2142+ "strings"
2143+
2144+ tm "github.com/nsf/termbox-go"
2145+ )
2146+ import rw "github.com/mattn/go-runewidth"
2147+
2148+ /* ---------------Port from termbox-go --------------------- */
2149+
2150+ // Attribute is printable cell's color and style.
2151+ type Attribute uint16
2152+
2153+ // 8 basic clolrs
2154+ const (
2155+ ColorDefault Attribute = iota
2156+ ColorBlack
2157+ ColorRed
2158+ ColorGreen
2159+ ColorYellow
2160+ ColorBlue
2161+ ColorMagenta
2162+ ColorCyan
2163+ ColorWhite
2164+ )
2165+
2166+ //Have a constant that defines number of colors
2167+ const NumberofColors = 8
2168+
2169+ // Text style
2170+ const (
2171+ AttrBold Attribute = 1 << (iota + 9)
2172+ AttrUnderline
2173+ AttrReverse
2174+ )
2175+
2176+ var (
2177+ dot = "…"
2178+ dotw = rw.StringWidth(dot)
2179+ )
2180+
2181+ /* ----------------------- End ----------------------------- */
2182+
2183+ func toTmAttr(x Attribute) tm.Attribute {
2184+ return tm.Attribute(x)
2185+ }
2186+
2187+ func str2runes(s string) []rune {
2188+ return []rune(s)
2189+ }
2190+
2191+ // Here for backwards-compatibility.
2192+ func trimStr2Runes(s string, w int) []rune {
2193+ return TrimStr2Runes(s, w)
2194+ }
2195+
2196+ // TrimStr2Runes trims string to w[-1 rune], appends …, and returns the runes
2197+ // of that string if string is grather then n. If string is small then w,
2198+ // return the runes.
2199+ func TrimStr2Runes(s string, w int) []rune {
2200+ if w <= 0 {
2201+ return []rune{}
2202+ }
2203+
2204+ sw := rw.StringWidth(s)
2205+ if sw > w {
2206+ return []rune(rw.Truncate(s, w, dot))
2207+ }
2208+ return str2runes(s)
2209+ }
2210+
2211+ // TrimStrIfAppropriate trim string to "s[:-1] + …"
2212+ // if string > width otherwise return string
2213+ func TrimStrIfAppropriate(s string, w int) string {
2214+ if w <= 0 {
2215+ return ""
2216+ }
2217+
2218+ sw := rw.StringWidth(s)
2219+ if sw > w {
2220+ return rw.Truncate(s, w, dot)
2221+ }
2222+
2223+ return s
2224+ }
2225+
2226+ func strWidth(s string) int {
2227+ return rw.StringWidth(s)
2228+ }
2229+
2230+ func charWidth(ch rune) int {
2231+ return rw.RuneWidth(ch)
2232+ }
2233+
2234+ var whiteSpaceRegex = regexp.MustCompile(`\s`)
2235+
2236+ // StringToAttribute converts text to a termui attribute. You may specifiy more
2237+ // then one attribute like that: "BLACK, BOLD, ...". All whitespaces
2238+ // are ignored.
2239+ func StringToAttribute(text string) Attribute {
2240+ text = whiteSpaceRegex.ReplaceAllString(strings.ToLower(text), "")
2241+ attributes := strings.Split(text, ",")
2242+ result := Attribute(0)
2243+
2244+ for _, theAttribute := range attributes {
2245+ var match Attribute
2246+ switch theAttribute {
2247+ case "reset", "default":
2248+ match = ColorDefault
2249+
2250+ case "black":
2251+ match = ColorBlack
2252+
2253+ case "red":
2254+ match = ColorRed
2255+
2256+ case "green":
2257+ match = ColorGreen
2258+
2259+ case "yellow":
2260+ match = ColorYellow
2261+
2262+ case "blue":
2263+ match = ColorBlue
2264+
2265+ case "magenta":
2266+ match = ColorMagenta
2267+
2268+ case "cyan":
2269+ match = ColorCyan
2270+
2271+ case "white":
2272+ match = ColorWhite
2273+
2274+ case "bold":
2275+ match = AttrBold
2276+
2277+ case "underline":
2278+ match = AttrUnderline
2279+
2280+ case "reverse":
2281+ match = AttrReverse
2282+ }
2283+
2284+ result |= match
2285+ }
2286+
2287+ return result
2288+ }
2289+
2290+ // TextCells returns a coloured text cells []Cell
2291+ func TextCells(s string, fg, bg Attribute) []Cell {
2292+ cs := make([]Cell, 0, len(s))
2293+
2294+ // sequence := MarkdownTextRendererFactory{}.TextRenderer(s).Render(fg, bg)
2295+ // runes := []rune(sequence.NormalizedText)
2296+ runes := str2runes(s)
2297+
2298+ for n := range runes {
2299+ // point, _ := sequence.PointAt(n, 0, 0)
2300+ // cs = append(cs, Cell{point.Ch, point.Fg, point.Bg})
2301+ cs = append(cs, Cell{runes[n], fg, bg})
2302+ }
2303+ return cs
2304+ }
2305+
2306+ // Width returns the actual screen space the cell takes (usually 1 or 2).
2307+ func (c Cell) Width() int {
2308+ return charWidth(c.Ch)
2309+ }
2310+
2311+ // Copy return a copy of c
2312+ func (c Cell) Copy() Cell {
2313+ return c
2314+ }
2315+
2316+ // TrimTxCells trims the overflowed text cells sequence.
2317+ func TrimTxCells(cs []Cell, w int) []Cell {
2318+ if len(cs) <= w {
2319+ return cs
2320+ }
2321+ return cs[:w]
2322+ }
2323+
2324+ // DTrimTxCls trims the overflowed text cells sequence and append dots at the end.
2325+ func DTrimTxCls(cs []Cell, w int) []Cell {
2326+ l := len(cs)
2327+ if l <= 0 {
2328+ return []Cell{}
2329+ }
2330+
2331+ rt := make([]Cell, 0, w)
2332+ csw := 0
2333+ for i := 0; i < l && csw <= w; i++ {
2334+ c := cs[i]
2335+ cw := c.Width()
2336+
2337+ if cw+csw < w {
2338+ rt = append(rt, c)
2339+ csw += cw
2340+ } else {
2341+ rt = append(rt, Cell{'…', c.Fg, c.Bg})
2342+ break
2343+ }
2344+ }
2345+
2346+ return rt
2347+ }
2348+
2349+ func CellsToStr(cs []Cell) string {
2350+ str := ""
2351+ for _, c := range cs {
2352+ str += string(c.Ch)
2353+ }
2354+ return str
2355+ }
2356 diff --git a/vendor/github.com/gizak/termui/helper_test.go b/vendor/github.com/gizak/termui/helper_test.go
2357new file mode 100644
2358index 0000000..0b4b13e
2359--- /dev/null
2360+++ b/vendor/github.com/gizak/termui/helper_test.go
2361 @@ -0,0 +1,70 @@
2362+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2363+ // Use of this source code is governed by a MIT license that can
2364+ // be found in the LICENSE file.
2365+
2366+ package termui
2367+
2368+ import (
2369+ "testing"
2370+
2371+ "github.com/stretchr/testify/assert"
2372+ )
2373+
2374+ func TestStr2Rune(t *testing.T) {
2375+ s := "你好,世界."
2376+ rs := str2runes(s)
2377+ if len(rs) != 6 {
2378+ t.Error(t)
2379+ }
2380+ }
2381+
2382+ func TestWidth(t *testing.T) {
2383+ s0 := "つのだ☆HIRO"
2384+ s1 := "11111111111"
2385+ // above not align for setting East Asian Ambiguous to wide!!
2386+
2387+ if strWidth(s0) != strWidth(s1) {
2388+ t.Error("str len failed")
2389+ }
2390+
2391+ len1 := []rune{'a', '2', '&', '「', 'オ', '。'} //will false: 'ᆵ', 'ᄚ', 'ᄒ'
2392+ for _, v := range len1 {
2393+ if charWidth(v) != 1 {
2394+ t.Error("len1 failed")
2395+ }
2396+ }
2397+
2398+ len2 := []rune{'漢', '字', '한', '자', '你', '好', 'だ', '。', '%', 's', 'E', 'ョ', '、', 'ヲ'}
2399+ for _, v := range len2 {
2400+ if charWidth(v) != 2 {
2401+ t.Error("len2 failed")
2402+ }
2403+ }
2404+ }
2405+
2406+ func TestTrim(t *testing.T) {
2407+ s := "つのだ☆HIRO"
2408+ if string(trimStr2Runes(s, 10)) != "つのだ☆HI"+dot {
2409+ t.Error("trim failed")
2410+ }
2411+ if string(trimStr2Runes(s, 11)) != "つのだ☆HIRO" {
2412+ t.Error("avoid tail trim failed")
2413+ }
2414+ if string(trimStr2Runes(s, 15)) != "つのだ☆HIRO" {
2415+ t.Error("avoid trim failed")
2416+ }
2417+ }
2418+
2419+ func TestTrimStrIfAppropriate_NoTrim(t *testing.T) {
2420+ assert.Equal(t, "hello", TrimStrIfAppropriate("hello", 5))
2421+ }
2422+
2423+ func TestTrimStrIfAppropriate(t *testing.T) {
2424+ assert.Equal(t, "hel…", TrimStrIfAppropriate("hello", 4))
2425+ assert.Equal(t, "h…", TrimStrIfAppropriate("hello", 2))
2426+ }
2427+
2428+ func TestStringToAttribute(t *testing.T) {
2429+ assert.Equal(t, ColorRed, StringToAttribute("ReD"))
2430+ assert.Equal(t, ColorRed|AttrBold, StringToAttribute("RED, bold"))
2431+ }
2432 diff --git a/vendor/github.com/gizak/termui/linechart.go b/vendor/github.com/gizak/termui/linechart.go
2433new file mode 100644
2434index 0000000..f7eea28
2435--- /dev/null
2436+++ b/vendor/github.com/gizak/termui/linechart.go
2437 @@ -0,0 +1,331 @@
2438+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2439+ // Use of this source code is governed by a MIT license that can
2440+ // be found in the LICENSE file.
2441+
2442+ package termui
2443+
2444+ import (
2445+ "fmt"
2446+ "math"
2447+ )
2448+
2449+ // only 16 possible combinations, why bother
2450+ var braillePatterns = map[[2]int]rune{
2451+ [2]int{0, 0}: '⣀',
2452+ [2]int{0, 1}: '⡠',
2453+ [2]int{0, 2}: '⡐',
2454+ [2]int{0, 3}: '⡈',
2455+
2456+ [2]int{1, 0}: '⢄',
2457+ [2]int{1, 1}: '⠤',
2458+ [2]int{1, 2}: '⠔',
2459+ [2]int{1, 3}: '⠌',
2460+
2461+ [2]int{2, 0}: '⢂',
2462+ [2]int{2, 1}: '⠢',
2463+ [2]int{2, 2}: '⠒',
2464+ [2]int{2, 3}: '⠊',
2465+
2466+ [2]int{3, 0}: '⢁',
2467+ [2]int{3, 1}: '⠡',
2468+ [2]int{3, 2}: '⠑',
2469+ [2]int{3, 3}: '⠉',
2470+ }
2471+
2472+ var lSingleBraille = [4]rune{'\u2840', '⠄', '⠂', '⠁'}
2473+ var rSingleBraille = [4]rune{'\u2880', '⠠', '⠐', '⠈'}
2474+
2475+ // LineChart has two modes: braille(default) and dot. Using braille gives 2x capicity as dot mode,
2476+ // because one braille char can represent two data points.
2477+ /*
2478+ lc := termui.NewLineChart()
2479+ lc.BorderLabel = "braille-mode Line Chart"
2480+ lc.Data = [1.2, 1.3, 1.5, 1.7, 1.5, 1.6, 1.8, 2.0]
2481+ lc.Width = 50
2482+ lc.Height = 12
2483+ lc.AxesColor = termui.ColorWhite
2484+ lc.LineColor = termui.ColorGreen | termui.AttrBold
2485+ // termui.Render(lc)...
2486+ */
2487+ type LineChart struct {
2488+ Block
2489+ Data []float64
2490+ DataLabels []string // if unset, the data indices will be used
2491+ Mode string // braille | dot
2492+ DotStyle rune
2493+ LineColor Attribute
2494+ scale float64 // data span per cell on y-axis
2495+ AxesColor Attribute
2496+ drawingX int
2497+ drawingY int
2498+ axisYHeight int
2499+ axisXWidth int
2500+ axisYLabelGap int
2501+ axisXLabelGap int
2502+ topValue float64
2503+ bottomValue float64
2504+ labelX [][]rune
2505+ labelY [][]rune
2506+ labelYSpace int
2507+ maxY float64
2508+ minY float64
2509+ autoLabels bool
2510+ }
2511+
2512+ // NewLineChart returns a new LineChart with current theme.
2513+ func NewLineChart() *LineChart {
2514+ lc := &LineChart{Block: *NewBlock()}
2515+ lc.AxesColor = ThemeAttr("linechart.axes.fg")
2516+ lc.LineColor = ThemeAttr("linechart.line.fg")
2517+ lc.Mode = "braille"
2518+ lc.DotStyle = '•'
2519+ lc.axisXLabelGap = 2
2520+ lc.axisYLabelGap = 1
2521+ lc.bottomValue = math.Inf(1)
2522+ lc.topValue = math.Inf(-1)
2523+ return lc
2524+ }
2525+
2526+ // one cell contains two data points
2527+ // so the capicity is 2x as dot-mode
2528+ func (lc *LineChart) renderBraille() Buffer {
2529+ buf := NewBuffer()
2530+
2531+ // return: b -> which cell should the point be in
2532+ // m -> in the cell, divided into 4 equal height levels, which subcell?
2533+ getPos := func(d float64) (b, m int) {
2534+ cnt4 := int((d-lc.bottomValue)/(lc.scale/4) + 0.5)
2535+ b = cnt4 / 4
2536+ m = cnt4 % 4
2537+ return
2538+ }
2539+ // plot points
2540+ for i := 0; 2*i+1 < len(lc.Data) && i < lc.axisXWidth; i++ {
2541+ b0, m0 := getPos(lc.Data[2*i])
2542+ b1, m1 := getPos(lc.Data[2*i+1])
2543+
2544+ if b0 == b1 {
2545+ c := Cell{
2546+ Ch: braillePatterns[[2]int{m0, m1}],
2547+ Bg: lc.Bg,
2548+ Fg: lc.LineColor,
2549+ }
2550+ y := lc.innerArea.Min.Y + lc.innerArea.Dy() - 3 - b0
2551+ x := lc.innerArea.Min.X + lc.labelYSpace + 1 + i
2552+ buf.Set(x, y, c)
2553+ } else {
2554+ c0 := Cell{Ch: lSingleBraille[m0],
2555+ Fg: lc.LineColor,
2556+ Bg: lc.Bg}
2557+ x0 := lc.innerArea.Min.X + lc.labelYSpace + 1 + i
2558+ y0 := lc.innerArea.Min.Y + lc.innerArea.Dy() - 3 - b0
2559+ buf.Set(x0, y0, c0)
2560+
2561+ c1 := Cell{Ch: rSingleBraille[m1],
2562+ Fg: lc.LineColor,
2563+ Bg: lc.Bg}
2564+ x1 := lc.innerArea.Min.X + lc.labelYSpace + 1 + i
2565+ y1 := lc.innerArea.Min.Y + lc.innerArea.Dy() - 3 - b1
2566+ buf.Set(x1, y1, c1)
2567+ }
2568+
2569+ }
2570+ return buf
2571+ }
2572+
2573+ func (lc *LineChart) renderDot() Buffer {
2574+ buf := NewBuffer()
2575+ for i := 0; i < len(lc.Data) && i < lc.axisXWidth; i++ {
2576+ c := Cell{
2577+ Ch: lc.DotStyle,
2578+ Fg: lc.LineColor,
2579+ Bg: lc.Bg,
2580+ }
2581+ x := lc.innerArea.Min.X + lc.labelYSpace + 1 + i
2582+ y := lc.innerArea.Min.Y + lc.innerArea.Dy() - 3 - int((lc.Data[i]-lc.bottomValue)/lc.scale+0.5)
2583+ buf.Set(x, y, c)
2584+ }
2585+
2586+ return buf
2587+ }
2588+
2589+ func (lc *LineChart) calcLabelX() {
2590+ lc.labelX = [][]rune{}
2591+
2592+ for i, l := 0, 0; i < len(lc.DataLabels) && l < lc.axisXWidth; i++ {
2593+ if lc.Mode == "dot" {
2594+ if l >= len(lc.DataLabels) {
2595+ break
2596+ }
2597+
2598+ s := str2runes(lc.DataLabels[l])
2599+ w := strWidth(lc.DataLabels[l])
2600+ if l+w <= lc.axisXWidth {
2601+ lc.labelX = append(lc.labelX, s)
2602+ }
2603+ l += w + lc.axisXLabelGap
2604+ } else { // braille
2605+ if 2*l >= len(lc.DataLabels) {
2606+ break
2607+ }
2608+
2609+ s := str2runes(lc.DataLabels[2*l])
2610+ w := strWidth(lc.DataLabels[2*l])
2611+ if l+w <= lc.axisXWidth {
2612+ lc.labelX = append(lc.labelX, s)
2613+ }
2614+ l += w + lc.axisXLabelGap
2615+
2616+ }
2617+ }
2618+ }
2619+
2620+ func shortenFloatVal(x float64) string {
2621+ s := fmt.Sprintf("%.2f", x)
2622+ if len(s)-3 > 3 {
2623+ s = fmt.Sprintf("%.2e", x)
2624+ }
2625+
2626+ if x < 0 {
2627+ s = fmt.Sprintf("%.2f", x)
2628+ }
2629+ return s
2630+ }
2631+
2632+ func (lc *LineChart) calcLabelY() {
2633+ span := lc.topValue - lc.bottomValue
2634+ lc.scale = span / float64(lc.axisYHeight)
2635+
2636+ n := (1 + lc.axisYHeight) / (lc.axisYLabelGap + 1)
2637+ lc.labelY = make([][]rune, n)
2638+ maxLen := 0
2639+ for i := 0; i < n; i++ {
2640+ s := str2runes(shortenFloatVal(lc.bottomValue + float64(i)*span/float64(n)))
2641+ if len(s) > maxLen {
2642+ maxLen = len(s)
2643+ }
2644+ lc.labelY[i] = s
2645+ }
2646+
2647+ lc.labelYSpace = maxLen
2648+ }
2649+
2650+ func (lc *LineChart) calcLayout() {
2651+ // set datalabels if it is not provided
2652+ if (lc.DataLabels == nil || len(lc.DataLabels) == 0) || lc.autoLabels {
2653+ lc.autoLabels = true
2654+ lc.DataLabels = make([]string, len(lc.Data))
2655+ for i := range lc.Data {
2656+ lc.DataLabels[i] = fmt.Sprint(i)
2657+ }
2658+ }
2659+
2660+ // lazy increase, to avoid y shaking frequently
2661+ // update bound Y when drawing is gonna overflow
2662+ lc.minY = lc.Data[0]
2663+ lc.maxY = lc.Data[0]
2664+
2665+ // valid visible range
2666+ vrange := lc.innerArea.Dx()
2667+ if lc.Mode == "braille" {
2668+ vrange = 2 * lc.innerArea.Dx()
2669+ }
2670+ if vrange > len(lc.Data) {
2671+ vrange = len(lc.Data)
2672+ }
2673+
2674+ for _, v := range lc.Data[:vrange] {
2675+ if v > lc.maxY {
2676+ lc.maxY = v
2677+ }
2678+ if v < lc.minY {
2679+ lc.minY = v
2680+ }
2681+ }
2682+
2683+ span := lc.maxY - lc.minY
2684+
2685+ if lc.minY < lc.bottomValue {
2686+ lc.bottomValue = lc.minY - 0.2*span
2687+ }
2688+
2689+ if lc.maxY > lc.topValue {
2690+ lc.topValue = lc.maxY + 0.2*span
2691+ }
2692+
2693+ lc.axisYHeight = lc.innerArea.Dy() - 2
2694+ lc.calcLabelY()
2695+
2696+ lc.axisXWidth = lc.innerArea.Dx() - 1 - lc.labelYSpace
2697+ lc.calcLabelX()
2698+
2699+ lc.drawingX = lc.innerArea.Min.X + 1 + lc.labelYSpace
2700+ lc.drawingY = lc.innerArea.Min.Y
2701+ }
2702+
2703+ func (lc *LineChart) plotAxes() Buffer {
2704+ buf := NewBuffer()
2705+
2706+ origY := lc.innerArea.Min.Y + lc.innerArea.Dy() - 2
2707+ origX := lc.innerArea.Min.X + lc.labelYSpace
2708+
2709+ buf.Set(origX, origY, Cell{Ch: ORIGIN, Fg: lc.AxesColor, Bg: lc.Bg})
2710+
2711+ for x := origX + 1; x < origX+lc.axisXWidth; x++ {
2712+ buf.Set(x, origY, Cell{Ch: HDASH, Fg: lc.AxesColor, Bg: lc.Bg})
2713+ }
2714+
2715+ for dy := 1; dy <= lc.axisYHeight; dy++ {
2716+ buf.Set(origX, origY-dy, Cell{Ch: VDASH, Fg: lc.AxesColor, Bg: lc.Bg})
2717+ }
2718+
2719+ // x label
2720+ oft := 0
2721+ for _, rs := range lc.labelX {
2722+ if oft+len(rs) > lc.axisXWidth {
2723+ break
2724+ }
2725+ for j, r := range rs {
2726+ c := Cell{
2727+ Ch: r,
2728+ Fg: lc.AxesColor,
2729+ Bg: lc.Bg,
2730+ }
2731+ x := origX + oft + j
2732+ y := lc.innerArea.Min.Y + lc.innerArea.Dy() - 1
2733+ buf.Set(x, y, c)
2734+ }
2735+ oft += len(rs) + lc.axisXLabelGap
2736+ }
2737+
2738+ // y labels
2739+ for i, rs := range lc.labelY {
2740+ for j, r := range rs {
2741+ buf.Set(
2742+ lc.innerArea.Min.X+j,
2743+ origY-i*(lc.axisYLabelGap+1),
2744+ Cell{Ch: r, Fg: lc.AxesColor, Bg: lc.Bg})
2745+ }
2746+ }
2747+
2748+ return buf
2749+ }
2750+
2751+ // Buffer implements Bufferer interface.
2752+ func (lc *LineChart) Buffer() Buffer {
2753+ buf := lc.Block.Buffer()
2754+
2755+ if lc.Data == nil || len(lc.Data) == 0 {
2756+ return buf
2757+ }
2758+ lc.calcLayout()
2759+ buf.Merge(lc.plotAxes())
2760+
2761+ if lc.Mode == "dot" {
2762+ buf.Merge(lc.renderDot())
2763+ } else {
2764+ buf.Merge(lc.renderBraille())
2765+ }
2766+
2767+ return buf
2768+ }
2769 diff --git a/vendor/github.com/gizak/termui/linechart_others.go b/vendor/github.com/gizak/termui/linechart_others.go
2770new file mode 100644
2771index 0000000..14897ea
2772--- /dev/null
2773+++ b/vendor/github.com/gizak/termui/linechart_others.go
2774 @@ -0,0 +1,11 @@
2775+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2776+ // Use of this source code is governed by a MIT license that can
2777+ // be found in the LICENSE file.
2778+
2779+ // +build !windows
2780+
2781+ package termui
2782+
2783+ const VDASH = '┊'
2784+ const HDASH = '┈'
2785+ const ORIGIN = '└'
2786 diff --git a/vendor/github.com/gizak/termui/linechart_windows.go b/vendor/github.com/gizak/termui/linechart_windows.go
2787new file mode 100644
2788index 0000000..994d3e5
2789--- /dev/null
2790+++ b/vendor/github.com/gizak/termui/linechart_windows.go
2791 @@ -0,0 +1,11 @@
2792+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2793+ // Use of this source code is governed by a MIT license that can
2794+ // be found in the LICENSE file.
2795+
2796+ // +build windows
2797+
2798+ package termui
2799+
2800+ const VDASH = '|'
2801+ const HDASH = '-'
2802+ const ORIGIN = '+'
2803 diff --git a/vendor/github.com/gizak/termui/list.go b/vendor/github.com/gizak/termui/list.go
2804new file mode 100644
2805index 0000000..ea6635e
2806--- /dev/null
2807+++ b/vendor/github.com/gizak/termui/list.go
2808 @@ -0,0 +1,89 @@
2809+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2810+ // Use of this source code is governed by a MIT license that can
2811+ // be found in the LICENSE file.
2812+
2813+ package termui
2814+
2815+ import "strings"
2816+
2817+ // List displays []string as its items,
2818+ // it has a Overflow option (default is "hidden"), when set to "hidden",
2819+ // the item exceeding List's width is truncated, but when set to "wrap",
2820+ // the overflowed text breaks into next line.
2821+ /*
2822+ strs := []string{
2823+ "[0] github.com/gizak/termui",
2824+ "[1] editbox.go",
2825+ "[2] iterrupt.go",
2826+ "[3] keyboard.go",
2827+ "[4] output.go",
2828+ "[5] random_out.go",
2829+ "[6] dashboard.go",
2830+ "[7] nsf/termbox-go"}
2831+
2832+ ls := termui.NewList()
2833+ ls.Items = strs
2834+ ls.ItemFgColor = termui.ColorYellow
2835+ ls.BorderLabel = "List"
2836+ ls.Height = 7
2837+ ls.Width = 25
2838+ ls.Y = 0
2839+ */
2840+ type List struct {
2841+ Block
2842+ Items []string
2843+ Overflow string
2844+ ItemFgColor Attribute
2845+ ItemBgColor Attribute
2846+ }
2847+
2848+ // NewList returns a new *List with current theme.
2849+ func NewList() *List {
2850+ l := &List{Block: *NewBlock()}
2851+ l.Overflow = "hidden"
2852+ l.ItemFgColor = ThemeAttr("list.item.fg")
2853+ l.ItemBgColor = ThemeAttr("list.item.bg")
2854+ return l
2855+ }
2856+
2857+ // Buffer implements Bufferer interface.
2858+ func (l *List) Buffer() Buffer {
2859+ buf := l.Block.Buffer()
2860+
2861+ switch l.Overflow {
2862+ case "wrap":
2863+ cs := DefaultTxBuilder.Build(strings.Join(l.Items, "\n"), l.ItemFgColor, l.ItemBgColor)
2864+ i, j, k := 0, 0, 0
2865+ for i < l.innerArea.Dy() && k < len(cs) {
2866+ w := cs[k].Width()
2867+ if cs[k].Ch == '\n' || j+w > l.innerArea.Dx() {
2868+ i++
2869+ j = 0
2870+ if cs[k].Ch == '\n' {
2871+ k++
2872+ }
2873+ continue
2874+ }
2875+ buf.Set(l.innerArea.Min.X+j, l.innerArea.Min.Y+i, cs[k])
2876+
2877+ k++
2878+ j++
2879+ }
2880+
2881+ case "hidden":
2882+ trimItems := l.Items
2883+ if len(trimItems) > l.innerArea.Dy() {
2884+ trimItems = trimItems[:l.innerArea.Dy()]
2885+ }
2886+ for i, v := range trimItems {
2887+ cs := DTrimTxCls(DefaultTxBuilder.Build(v, l.ItemFgColor, l.ItemBgColor), l.innerArea.Dx())
2888+ j := 0
2889+ for _, vv := range cs {
2890+ w := vv.Width()
2891+ buf.Set(l.innerArea.Min.X+j, l.innerArea.Min.Y+i, vv)
2892+ j += w
2893+ }
2894+ }
2895+ }
2896+ return buf
2897+ }
2898 diff --git a/vendor/github.com/gizak/termui/mbarchart.go b/vendor/github.com/gizak/termui/mbarchart.go
2899new file mode 100644
2900index 0000000..0f91e97
2901--- /dev/null
2902+++ b/vendor/github.com/gizak/termui/mbarchart.go
2903 @@ -0,0 +1,242 @@
2904+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2905+ // Use of this source code is governed by a MIT license that can
2906+ // be found in the LICENSE file.
2907+
2908+ package termui
2909+
2910+ import (
2911+ "fmt"
2912+ )
2913+
2914+ // This is the implemetation of multi-colored or stacked bar graph. This is different from default barGraph which is implemented in bar.go
2915+ // Multi-Colored-BarChart creates multiple bars in a widget:
2916+ /*
2917+ bc := termui.NewMBarChart()
2918+ data := make([][]int, 2)
2919+ data[0] := []int{3, 2, 5, 7, 9, 4}
2920+ data[1] := []int{7, 8, 5, 3, 1, 6}
2921+ bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
2922+ bc.BorderLabel = "Bar Chart"
2923+ bc.Data = data
2924+ bc.Width = 26
2925+ bc.Height = 10
2926+ bc.DataLabels = bclabels
2927+ bc.TextColor = termui.ColorGreen
2928+ bc.BarColor = termui.ColorRed
2929+ bc.NumColor = termui.ColorYellow
2930+ */
2931+ type MBarChart struct {
2932+ Block
2933+ BarColor [NumberofColors]Attribute
2934+ TextColor Attribute
2935+ NumColor [NumberofColors]Attribute
2936+ Data [NumberofColors][]int
2937+ DataLabels []string
2938+ BarWidth int
2939+ BarGap int
2940+ labels [][]rune
2941+ dataNum [NumberofColors][][]rune
2942+ numBar int
2943+ scale float64
2944+ max int
2945+ minDataLen int
2946+ numStack int
2947+ ShowScale bool
2948+ maxScale []rune
2949+ }
2950+
2951+ // NewBarChart returns a new *BarChart with current theme.
2952+ func NewMBarChart() *MBarChart {
2953+ bc := &MBarChart{Block: *NewBlock()}
2954+ bc.BarColor[0] = ThemeAttr("mbarchart.bar.bg")
2955+ bc.NumColor[0] = ThemeAttr("mbarchart.num.fg")
2956+ bc.TextColor = ThemeAttr("mbarchart.text.fg")
2957+ bc.BarGap = 1
2958+ bc.BarWidth = 3
2959+ return bc
2960+ }
2961+
2962+ func (bc *MBarChart) layout() {
2963+ bc.numBar = bc.innerArea.Dx() / (bc.BarGap + bc.BarWidth)
2964+ bc.labels = make([][]rune, bc.numBar)
2965+ DataLen := 0
2966+ LabelLen := len(bc.DataLabels)
2967+ bc.minDataLen = 9999 //Set this to some very hight value so that we find the minimum one We want to know which array among data[][] has got the least length
2968+
2969+ // We need to know how many stack/data array data[0] , data[1] are there
2970+ for i := 0; i < len(bc.Data); i++ {
2971+ if bc.Data[i] == nil {
2972+ break
2973+ }
2974+ DataLen++
2975+ }
2976+ bc.numStack = DataLen
2977+
2978+ //We need to know what is the mimimum size of data array data[0] could have 10 elements data[1] could have only 5, so we plot only 5 bar graphs
2979+
2980+ for i := 0; i < DataLen; i++ {
2981+ if bc.minDataLen > len(bc.Data[i]) {
2982+ bc.minDataLen = len(bc.Data[i])
2983+ }
2984+ }
2985+
2986+ if LabelLen > bc.minDataLen {
2987+ LabelLen = bc.minDataLen
2988+ }
2989+
2990+ for i := 0; i < LabelLen && i < bc.numBar; i++ {
2991+ bc.labels[i] = trimStr2Runes(bc.DataLabels[i], bc.BarWidth)
2992+ }
2993+
2994+ for i := 0; i < bc.numStack; i++ {
2995+ bc.dataNum[i] = make([][]rune, len(bc.Data[i]))
2996+ //For each stack of bar calcualte the rune
2997+ for j := 0; j < LabelLen && i < bc.numBar; j++ {
2998+ n := bc.Data[i][j]
2999+ s := fmt.Sprint(n)
3000+ bc.dataNum[i][j] = trimStr2Runes(s, bc.BarWidth)
3001+ }
3002+ //If color is not defined by default then populate a color that is different from the prevous bar
3003+ if bc.BarColor[i] == ColorDefault && bc.NumColor[i] == ColorDefault {
3004+ if i == 0 {
3005+ bc.BarColor[i] = ColorBlack
3006+ } else {
3007+ bc.BarColor[i] = bc.BarColor[i-1] + 1
3008+ if bc.BarColor[i] > NumberofColors {
3009+ bc.BarColor[i] = ColorBlack
3010+ }
3011+ }
3012+ bc.NumColor[i] = (NumberofColors + 1) - bc.BarColor[i] //Make NumColor opposite of barColor for visibility
3013+ }
3014+ }
3015+
3016+ //If Max value is not set then we have to populate, this time the max value will be max(sum(d1[0],d2[0],d3[0]) .... sum(d1[n], d2[n], d3[n]))
3017+
3018+ if bc.max == 0 {
3019+ bc.max = -1
3020+ }
3021+ for i := 0; i < bc.minDataLen && i < LabelLen; i++ {
3022+ var dsum int
3023+ for j := 0; j < bc.numStack; j++ {
3024+ dsum += bc.Data[j][i]
3025+ }
3026+ if dsum > bc.max {
3027+ bc.max = dsum
3028+ }
3029+ }
3030+
3031+ //Finally Calculate max sale
3032+ if bc.ShowScale {
3033+ s := fmt.Sprintf("%d", bc.max)
3034+ bc.maxScale = trimStr2Runes(s, len(s))
3035+ bc.scale = float64(bc.max) / float64(bc.innerArea.Dy()-2)
3036+ } else {
3037+ bc.scale = float64(bc.max) / float64(bc.innerArea.Dy()-1)
3038+ }
3039+
3040+ }
3041+
3042+ func (bc *MBarChart) SetMax(max int) {
3043+
3044+ if max > 0 {
3045+ bc.max = max
3046+ }
3047+ }
3048+
3049+ // Buffer implements Bufferer interface.
3050+ func (bc *MBarChart) Buffer() Buffer {
3051+ buf := bc.Block.Buffer()
3052+ bc.layout()
3053+ var oftX int
3054+
3055+ for i := 0; i < bc.numBar && i < bc.minDataLen && i < len(bc.DataLabels); i++ {
3056+ ph := 0 //Previous Height to stack up
3057+ oftX = i * (bc.BarWidth + bc.BarGap)
3058+ for i1 := 0; i1 < bc.numStack; i1++ {
3059+ h := int(float64(bc.Data[i1][i]) / bc.scale)
3060+ // plot bars
3061+ for j := 0; j < bc.BarWidth; j++ {
3062+ for k := 0; k < h; k++ {
3063+ c := Cell{
3064+ Ch: ' ',
3065+ Bg: bc.BarColor[i1],
3066+ }
3067+ if bc.BarColor[i1] == ColorDefault { // when color is default, space char treated as transparent!
3068+ c.Bg |= AttrReverse
3069+ }
3070+ x := bc.innerArea.Min.X + i*(bc.BarWidth+bc.BarGap) + j
3071+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2 - k - ph
3072+ buf.Set(x, y, c)
3073+
3074+ }
3075+ }
3076+ ph += h
3077+ }
3078+ // plot text
3079+ for j, k := 0, 0; j < len(bc.labels[i]); j++ {
3080+ w := charWidth(bc.labels[i][j])
3081+ c := Cell{
3082+ Ch: bc.labels[i][j],
3083+ Bg: bc.Bg,
3084+ Fg: bc.TextColor,
3085+ }
3086+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 1
3087+ x := bc.innerArea.Max.X + oftX + ((bc.BarWidth - len(bc.labels[i])) / 2) + k
3088+ buf.Set(x, y, c)
3089+ k += w
3090+ }
3091+ // plot num
3092+ ph = 0 //re-initialize previous height
3093+ for i1 := 0; i1 < bc.numStack; i1++ {
3094+ h := int(float64(bc.Data[i1][i]) / bc.scale)
3095+ for j := 0; j < len(bc.dataNum[i1][i]) && h > 0; j++ {
3096+ c := Cell{
3097+ Ch: bc.dataNum[i1][i][j],
3098+ Fg: bc.NumColor[i1],
3099+ Bg: bc.BarColor[i1],
3100+ }
3101+ if bc.BarColor[i1] == ColorDefault { // the same as above
3102+ c.Bg |= AttrReverse
3103+ }
3104+ if h == 0 {
3105+ c.Bg = bc.Bg
3106+ }
3107+ x := bc.innerArea.Min.X + oftX + (bc.BarWidth-len(bc.dataNum[i1][i]))/2 + j
3108+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2 - ph
3109+ buf.Set(x, y, c)
3110+ }
3111+ ph += h
3112+ }
3113+ }
3114+
3115+ if bc.ShowScale {
3116+ //Currently bar graph only supprts data range from 0 to MAX
3117+ //Plot 0
3118+ c := Cell{
3119+ Ch: '0',
3120+ Bg: bc.Bg,
3121+ Fg: bc.TextColor,
3122+ }
3123+
3124+ y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2
3125+ x := bc.X
3126+ buf.Set(x, y, c)
3127+
3128+ //Plot the maximum sacle value
3129+ for i := 0; i < len(bc.maxScale); i++ {
3130+ c := Cell{
3131+ Ch: bc.maxScale[i],
3132+ Bg: bc.Bg,
3133+ Fg: bc.TextColor,
3134+ }
3135+
3136+ y := bc.innerArea.Min.Y
3137+ x := bc.X + i
3138+
3139+ buf.Set(x, y, c)
3140+ }
3141+
3142+ }
3143+
3144+ return buf
3145+ }
3146 diff --git a/vendor/github.com/gizak/termui/mkdocs.yml b/vendor/github.com/gizak/termui/mkdocs.yml
3147new file mode 100644
3148index 0000000..2ab45f0
3149--- /dev/null
3150+++ b/vendor/github.com/gizak/termui/mkdocs.yml
3151 @@ -0,0 +1,28 @@
3152+ pages:
3153+ - Home: 'index.md'
3154+ - Quickstart: 'quickstart.md'
3155+ - Recipes: 'recipes.md'
3156+ - References:
3157+ - Layouts: 'layouts.md'
3158+ - Components: 'components.md'
3159+ - Events: 'events.md'
3160+ - Themes: 'themes.md'
3161+ - Versions: 'versions.md'
3162+ - About: 'about.md'
3163+
3164+ site_name: termui
3165+ repo_url: https://github.com/gizak/termui/
3166+ site_description: 'termui user guide'
3167+ site_author: gizak
3168+
3169+ docs_dir: '_docs'
3170+
3171+ theme: readthedocs
3172+
3173+ markdown_extensions:
3174+ - smarty
3175+ - admonition
3176+ - toc
3177+
3178+ extra:
3179+ version: 1.0
3180 diff --git a/vendor/github.com/gizak/termui/par.go b/vendor/github.com/gizak/termui/par.go
3181new file mode 100644
3182index 0000000..29b6d46
3183--- /dev/null
3184+++ b/vendor/github.com/gizak/termui/par.go
3185 @@ -0,0 +1,73 @@
3186+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3187+ // Use of this source code is governed by a MIT license that can
3188+ // be found in the LICENSE file.
3189+
3190+ package termui
3191+
3192+ // Par displays a paragraph.
3193+ /*
3194+ par := termui.NewPar("Simple Text")
3195+ par.Height = 3
3196+ par.Width = 17
3197+ par.BorderLabel = "Label"
3198+ */
3199+ type Par struct {
3200+ Block
3201+ Text string
3202+ TextFgColor Attribute
3203+ TextBgColor Attribute
3204+ WrapLength int // words wrap limit. Note it may not work properly with multi-width char
3205+ }
3206+
3207+ // NewPar returns a new *Par with given text as its content.
3208+ func NewPar(s string) *Par {
3209+ return &Par{
3210+ Block: *NewBlock(),
3211+ Text: s,
3212+ TextFgColor: ThemeAttr("par.text.fg"),
3213+ TextBgColor: ThemeAttr("par.text.bg"),
3214+ WrapLength: 0,
3215+ }
3216+ }
3217+
3218+ // Buffer implements Bufferer interface.
3219+ func (p *Par) Buffer() Buffer {
3220+ buf := p.Block.Buffer()
3221+
3222+ fg, bg := p.TextFgColor, p.TextBgColor
3223+ cs := DefaultTxBuilder.Build(p.Text, fg, bg)
3224+
3225+ // wrap if WrapLength set
3226+ if p.WrapLength < 0 {
3227+ cs = wrapTx(cs, p.Width-2)
3228+ } else if p.WrapLength > 0 {
3229+ cs = wrapTx(cs, p.WrapLength)
3230+ }
3231+
3232+ y, x, n := 0, 0, 0
3233+ for y < p.innerArea.Dy() && n < len(cs) {
3234+ w := cs[n].Width()
3235+ if cs[n].Ch == '\n' || x+w > p.innerArea.Dx() {
3236+ y++
3237+ x = 0 // set x = 0
3238+ if cs[n].Ch == '\n' {
3239+ n++
3240+ }
3241+
3242+ if y >= p.innerArea.Dy() {
3243+ buf.Set(p.innerArea.Min.X+p.innerArea.Dx()-1,
3244+ p.innerArea.Min.Y+p.innerArea.Dy()-1,
3245+ Cell{Ch: '…', Fg: p.TextFgColor, Bg: p.TextBgColor})
3246+ break
3247+ }
3248+ continue
3249+ }
3250+
3251+ buf.Set(p.innerArea.Min.X+x, p.innerArea.Min.Y+y, cs[n])
3252+
3253+ n++
3254+ x += w
3255+ }
3256+
3257+ return buf
3258+ }
3259 diff --git a/vendor/github.com/gizak/termui/par_test.go b/vendor/github.com/gizak/termui/par_test.go
3260new file mode 100644
3261index 0000000..4d28f4d
3262--- /dev/null
3263+++ b/vendor/github.com/gizak/termui/par_test.go
3264 @@ -0,0 +1,24 @@
3265+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3266+ // Use of this source code is governed by a MIT license that can
3267+ // be found in the LICENSE file.
3268+
3269+ package termui
3270+
3271+ import "testing"
3272+
3273+ func TestPar_NoBorderBackground(t *testing.T) {
3274+ par := NewPar("a")
3275+ par.Border = false
3276+ par.Bg = ColorBlue
3277+ par.TextBgColor = ColorBlue
3278+ par.Width = 2
3279+ par.Height = 2
3280+
3281+ pts := par.Buffer()
3282+ for _, p := range pts.CellMap {
3283+ t.Log(p)
3284+ if p.Bg != par.Bg {
3285+ t.Errorf("expected color to be %v but got %v", par.Bg, p.Bg)
3286+ }
3287+ }
3288+ }
3289 diff --git a/vendor/github.com/gizak/termui/pos.go b/vendor/github.com/gizak/termui/pos.go
3290new file mode 100644
3291index 0000000..c7d647f
3292--- /dev/null
3293+++ b/vendor/github.com/gizak/termui/pos.go
3294 @@ -0,0 +1,78 @@
3295+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3296+ // Use of this source code is governed by a MIT license that can
3297+ // be found in the LICENSE file.
3298+
3299+ package termui
3300+
3301+ import "image"
3302+
3303+ // Align is the position of the gauge's label.
3304+ type Align uint
3305+
3306+ // All supported positions.
3307+ const (
3308+ AlignNone Align = 0
3309+ AlignLeft Align = 1 << iota
3310+ AlignRight
3311+ AlignBottom
3312+ AlignTop
3313+ AlignCenterVertical
3314+ AlignCenterHorizontal
3315+ AlignCenter = AlignCenterVertical | AlignCenterHorizontal
3316+ )
3317+
3318+ func AlignArea(parent, child image.Rectangle, a Align) image.Rectangle {
3319+ w, h := child.Dx(), child.Dy()
3320+
3321+ // parent center
3322+ pcx, pcy := parent.Min.X+parent.Dx()/2, parent.Min.Y+parent.Dy()/2
3323+ // child center
3324+ ccx, ccy := child.Min.X+child.Dx()/2, child.Min.Y+child.Dy()/2
3325+
3326+ if a&AlignLeft == AlignLeft {
3327+ child.Min.X = parent.Min.X
3328+ child.Max.X = child.Min.X + w
3329+ }
3330+
3331+ if a&AlignRight == AlignRight {
3332+ child.Max.X = parent.Max.X
3333+ child.Min.X = child.Max.X - w
3334+ }
3335+
3336+ if a&AlignBottom == AlignBottom {
3337+ child.Max.Y = parent.Max.Y
3338+ child.Min.Y = child.Max.Y - h
3339+ }
3340+
3341+ if a&AlignTop == AlignRight {
3342+ child.Min.Y = parent.Min.Y
3343+ child.Max.Y = child.Min.Y + h
3344+ }
3345+
3346+ if a&AlignCenterHorizontal == AlignCenterHorizontal {
3347+ child.Min.X += pcx - ccx
3348+ child.Max.X = child.Min.X + w
3349+ }
3350+
3351+ if a&AlignCenterVertical == AlignCenterVertical {
3352+ child.Min.Y += pcy - ccy
3353+ child.Max.Y = child.Min.Y + h
3354+ }
3355+
3356+ return child
3357+ }
3358+
3359+ func MoveArea(a image.Rectangle, dx, dy int) image.Rectangle {
3360+ a.Min.X += dx
3361+ a.Max.X += dx
3362+ a.Min.Y += dy
3363+ a.Max.Y += dy
3364+ return a
3365+ }
3366+
3367+ var termWidth int
3368+ var termHeight int
3369+
3370+ func TermRect() image.Rectangle {
3371+ return image.Rect(0, 0, termWidth, termHeight)
3372+ }
3373 diff --git a/vendor/github.com/gizak/termui/pos_test.go b/vendor/github.com/gizak/termui/pos_test.go
3374new file mode 100644
3375index 0000000..448876b
3376--- /dev/null
3377+++ b/vendor/github.com/gizak/termui/pos_test.go
3378 @@ -0,0 +1,38 @@
3379+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3380+ // Use of this source code is governed by a MIT license that can
3381+ // be found in the LICENSE file.
3382+
3383+ package termui
3384+
3385+ import (
3386+ "image"
3387+ "testing"
3388+ )
3389+
3390+ func TestAlignArea(t *testing.T) {
3391+ p := image.Rect(0, 0, 100, 100)
3392+ c := image.Rect(10, 10, 20, 20)
3393+
3394+ nc := AlignArea(p, c, AlignLeft)
3395+ if nc.Min.X != 0 || nc.Max.Y != 20 {
3396+ t.Errorf("AlignLeft failed:\n%+v", nc)
3397+ }
3398+
3399+ nc = AlignArea(p, c, AlignCenter)
3400+ if nc.Min.X != 45 || nc.Max.Y != 55 {
3401+ t.Error("AlignCenter failed")
3402+ }
3403+
3404+ nc = AlignArea(p, c, AlignBottom|AlignRight)
3405+ if nc.Min.X != 90 || nc.Max.Y != 100 {
3406+ t.Errorf("AlignBottom|AlignRight failed\n%+v", nc)
3407+ }
3408+ }
3409+
3410+ func TestMoveArea(t *testing.T) {
3411+ a := image.Rect(10, 10, 20, 20)
3412+ a = MoveArea(a, 5, 10)
3413+ if a.Min.X != 15 || a.Min.Y != 20 || a.Max.X != 25 || a.Max.Y != 30 {
3414+ t.Error("MoveArea failed")
3415+ }
3416+ }
3417 diff --git a/vendor/github.com/gizak/termui/render.go b/vendor/github.com/gizak/termui/render.go
3418new file mode 100644
3419index 0000000..5b58409
3420--- /dev/null
3421+++ b/vendor/github.com/gizak/termui/render.go
3422 @@ -0,0 +1,164 @@
3423+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3424+ // Use of this source code is governed by a MIT license that can
3425+ // be found in the LICENSE file.
3426+
3427+ package termui
3428+
3429+ import (
3430+ "image"
3431+ "io"
3432+ "sync"
3433+ "time"
3434+
3435+ "fmt"
3436+
3437+ "os"
3438+
3439+ "runtime/debug"
3440+
3441+ "bytes"
3442+
3443+ "github.com/maruel/panicparse/stack"
3444+ tm "github.com/nsf/termbox-go"
3445+ )
3446+
3447+ // Bufferer should be implemented by all renderable components.
3448+ type Bufferer interface {
3449+ Buffer() Buffer
3450+ }
3451+
3452+ // Init initializes termui library. This function should be called before any others.
3453+ // After initialization, the library must be finalized by 'Close' function.
3454+ func Init() error {
3455+ if err := tm.Init(); err != nil {
3456+ return err
3457+ }
3458+
3459+ sysEvtChs = make([]chan Event, 0)
3460+ go hookTermboxEvt()
3461+
3462+ renderJobs = make(chan []Bufferer)
3463+ //renderLock = new(sync.RWMutex)
3464+
3465+ Body = NewGrid()
3466+ Body.X = 0
3467+ Body.Y = 0
3468+ Body.BgColor = ThemeAttr("bg")
3469+ Body.Width = TermWidth()
3470+
3471+ DefaultEvtStream.Init()
3472+ DefaultEvtStream.Merge("termbox", NewSysEvtCh())
3473+ DefaultEvtStream.Merge("timer", NewTimerCh(time.Second))
3474+ DefaultEvtStream.Merge("custom", usrEvtCh)
3475+
3476+ DefaultEvtStream.Handle("/", DefualtHandler)
3477+ DefaultEvtStream.Handle("/sys/wnd/resize", func(e Event) {
3478+ w := e.Data.(EvtWnd)
3479+ Body.Width = w.Width
3480+ })
3481+
3482+ DefaultWgtMgr = NewWgtMgr()
3483+ DefaultEvtStream.Hook(DefaultWgtMgr.WgtHandlersHook())
3484+
3485+ go func() {
3486+ for bs := range renderJobs {
3487+ render(bs...)
3488+ }
3489+ }()
3490+
3491+ return nil
3492+ }
3493+
3494+ // Close finalizes termui library,
3495+ // should be called after successful initialization when termui's functionality isn't required anymore.
3496+ func Close() {
3497+ tm.Close()
3498+ }
3499+
3500+ var renderLock sync.Mutex
3501+
3502+ func termSync() {
3503+ renderLock.Lock()
3504+ tm.Sync()
3505+ termWidth, termHeight = tm.Size()
3506+ renderLock.Unlock()
3507+ }
3508+
3509+ // TermWidth returns the current terminal's width.
3510+ func TermWidth() int {
3511+ termSync()
3512+ return termWidth
3513+ }
3514+
3515+ // TermHeight returns the current terminal's height.
3516+ func TermHeight() int {
3517+ termSync()
3518+ return termHeight
3519+ }
3520+
3521+ // Render renders all Bufferer in the given order from left to right,
3522+ // right could overlap on left ones.
3523+ func render(bs ...Bufferer) {
3524+ defer func() {
3525+ if e := recover(); e != nil {
3526+ Close()
3527+ fmt.Fprintf(os.Stderr, "Captured a panic(value=%v) when rendering Bufferer. Exit termui and clean terminal...\nPrint stack trace:\n\n", e)
3528+ //debug.PrintStack()
3529+ gs, err := stack.ParseDump(bytes.NewReader(debug.Stack()), os.Stderr)
3530+ if err != nil {
3531+ debug.PrintStack()
3532+ os.Exit(1)
3533+ }
3534+ p := &stack.Palette{}
3535+ buckets := stack.SortBuckets(stack.Bucketize(gs, stack.AnyValue))
3536+ srcLen, pkgLen := stack.CalcLengths(buckets, false)
3537+ for _, bucket := range buckets {
3538+ io.WriteString(os.Stdout, p.BucketHeader(&bucket, false, len(buckets) > 1))
3539+ io.WriteString(os.Stdout, p.StackLines(&bucket.Signature, srcLen, pkgLen, false))
3540+ }
3541+ os.Exit(1)
3542+ }
3543+ }()
3544+ for _, b := range bs {
3545+
3546+ buf := b.Buffer()
3547+ // set cels in buf
3548+ for p, c := range buf.CellMap {
3549+ if p.In(buf.Area) {
3550+
3551+ tm.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
3552+
3553+ }
3554+ }
3555+
3556+ }
3557+
3558+ renderLock.Lock()
3559+ // render
3560+ tm.Flush()
3561+ renderLock.Unlock()
3562+ }
3563+
3564+ func Clear() {
3565+ tm.Clear(tm.ColorDefault, toTmAttr(ThemeAttr("bg")))
3566+ }
3567+
3568+ func clearArea(r image.Rectangle, bg Attribute) {
3569+ for i := r.Min.X; i < r.Max.X; i++ {
3570+ for j := r.Min.Y; j < r.Max.Y; j++ {
3571+ tm.SetCell(i, j, ' ', tm.ColorDefault, toTmAttr(bg))
3572+ }
3573+ }
3574+ }
3575+
3576+ func ClearArea(r image.Rectangle, bg Attribute) {
3577+ clearArea(r, bg)
3578+ tm.Flush()
3579+ }
3580+
3581+ var renderJobs chan []Bufferer
3582+
3583+ func Render(bs ...Bufferer) {
3584+ //go func() { renderJobs <- bs }()
3585+ renderJobs <- bs
3586+ }
3587 diff --git a/vendor/github.com/gizak/termui/sparkline.go b/vendor/github.com/gizak/termui/sparkline.go
3588new file mode 100644
3589index 0000000..d906e49
3590--- /dev/null
3591+++ b/vendor/github.com/gizak/termui/sparkline.go
3592 @@ -0,0 +1,167 @@
3593+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3594+ // Use of this source code is governed by a MIT license that can
3595+ // be found in the LICENSE file.
3596+
3597+ package termui
3598+
3599+ // Sparkline is like: ▅▆▂▂▅▇▂▂▃▆▆▆▅▃. The data points should be non-negative integers.
3600+ /*
3601+ data := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1}
3602+ spl := termui.NewSparkline()
3603+ spl.Data = data
3604+ spl.Title = "Sparkline 0"
3605+ spl.LineColor = termui.ColorGreen
3606+ */
3607+ type Sparkline struct {
3608+ Data []int
3609+ Height int
3610+ Title string
3611+ TitleColor Attribute
3612+ LineColor Attribute
3613+ displayHeight int
3614+ scale float32
3615+ max int
3616+ }
3617+
3618+ // Sparklines is a renderable widget which groups together the given sparklines.
3619+ /*
3620+ spls := termui.NewSparklines(spl0,spl1,spl2) //...
3621+ spls.Height = 2
3622+ spls.Width = 20
3623+ */
3624+ type Sparklines struct {
3625+ Block
3626+ Lines []Sparkline
3627+ displayLines int
3628+ displayWidth int
3629+ }
3630+
3631+ var sparks = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}
3632+
3633+ // Add appends a given Sparkline to s *Sparklines.
3634+ func (s *Sparklines) Add(sl Sparkline) {
3635+ s.Lines = append(s.Lines, sl)
3636+ }
3637+
3638+ // NewSparkline returns a unrenderable single sparkline that intended to be added into Sparklines.
3639+ func NewSparkline() Sparkline {
3640+ return Sparkline{
3641+ Height: 1,
3642+ TitleColor: ThemeAttr("sparkline.title.fg"),
3643+ LineColor: ThemeAttr("sparkline.line.fg")}
3644+ }
3645+
3646+ // NewSparklines return a new *Spaklines with given Sparkline(s), you can always add a new Sparkline later.
3647+ func NewSparklines(ss ...Sparkline) *Sparklines {
3648+ s := &Sparklines{Block: *NewBlock(), Lines: ss}
3649+ return s
3650+ }
3651+
3652+ func (sl *Sparklines) update() {
3653+ for i, v := range sl.Lines {
3654+ if v.Title == "" {
3655+ sl.Lines[i].displayHeight = v.Height
3656+ } else {
3657+ sl.Lines[i].displayHeight = v.Height + 1
3658+ }
3659+ }
3660+ sl.displayWidth = sl.innerArea.Dx()
3661+
3662+ // get how many lines gotta display
3663+ h := 0
3664+ sl.displayLines = 0
3665+ for _, v := range sl.Lines {
3666+ if h+v.displayHeight <= sl.innerArea.Dy() {
3667+ sl.displayLines++
3668+ } else {
3669+ break
3670+ }
3671+ h += v.displayHeight
3672+ }
3673+
3674+ for i := 0; i < sl.displayLines; i++ {
3675+ data := sl.Lines[i].Data
3676+
3677+ max := 0
3678+ for _, v := range data {
3679+ if max < v {
3680+ max = v
3681+ }
3682+ }
3683+ sl.Lines[i].max = max
3684+ if max != 0 {
3685+ sl.Lines[i].scale = float32(8*sl.Lines[i].Height) / float32(max)
3686+ } else { // when all negative
3687+ sl.Lines[i].scale = 0
3688+ }
3689+ }
3690+ }
3691+
3692+ // Buffer implements Bufferer interface.
3693+ func (sl *Sparklines) Buffer() Buffer {
3694+ buf := sl.Block.Buffer()
3695+ sl.update()
3696+
3697+ oftY := 0
3698+ for i := 0; i < sl.displayLines; i++ {
3699+ l := sl.Lines[i]
3700+ data := l.Data
3701+
3702+ if len(data) > sl.innerArea.Dx() {
3703+ data = data[len(data)-sl.innerArea.Dx():]
3704+ }
3705+
3706+ if l.Title != "" {
3707+ rs := trimStr2Runes(l.Title, sl.innerArea.Dx())
3708+ oftX := 0
3709+ for _, v := range rs {
3710+ w := charWidth(v)
3711+ c := Cell{
3712+ Ch: v,
3713+ Fg: l.TitleColor,
3714+ Bg: sl.Bg,
3715+ }
3716+ x := sl.innerArea.Min.X + oftX
3717+ y := sl.innerArea.Min.Y + oftY
3718+ buf.Set(x, y, c)
3719+ oftX += w
3720+ }
3721+ }
3722+
3723+ for j, v := range data {
3724+ // display height of the data point, zero when data is negative
3725+ h := int(float32(v)*l.scale + 0.5)
3726+ if v < 0 {
3727+ h = 0
3728+ }
3729+
3730+ barCnt := h / 8
3731+ barMod := h % 8
3732+ for jj := 0; jj < barCnt; jj++ {
3733+ c := Cell{
3734+ Ch: ' ', // => sparks[7]
3735+ Bg: l.LineColor,
3736+ }
3737+ x := sl.innerArea.Min.X + j
3738+ y := sl.innerArea.Min.Y + oftY + l.Height - jj
3739+
3740+ //p.Bg = sl.BgColor
3741+ buf.Set(x, y, c)
3742+ }
3743+ if barMod != 0 {
3744+ c := Cell{
3745+ Ch: sparks[barMod-1],
3746+ Fg: l.LineColor,
3747+ Bg: sl.Bg,
3748+ }
3749+ x := sl.innerArea.Min.X + j
3750+ y := sl.innerArea.Min.Y + oftY + l.Height - barCnt
3751+ buf.Set(x, y, c)
3752+ }
3753+ }
3754+
3755+ oftY += l.displayHeight
3756+ }
3757+
3758+ return buf
3759+ }
3760 diff --git a/vendor/github.com/gizak/termui/table.go b/vendor/github.com/gizak/termui/table.go
3761new file mode 100644
3762index 0000000..e3d1bbf
3763--- /dev/null
3764+++ b/vendor/github.com/gizak/termui/table.go
3765 @@ -0,0 +1,185 @@
3766+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3767+ // Use of this source code is governed by a MIT license that can
3768+ // be found in the LICENSE file.
3769+
3770+ package termui
3771+
3772+ import "strings"
3773+
3774+ /* Table is like:
3775+
3776+ ┌Awesome Table ────────────────────────────────────────────────┐
3777+ │ Col0 | Col1 | Col2 | Col3 | Col4 | Col5 | Col6 |
3778+ │──────────────────────────────────────────────────────────────│
3779+ │ Some Item #1 | AAA | 123 | CCCCC | EEEEE | GGGGG | IIIII |
3780+ │──────────────────────────────────────────────────────────────│
3781+ │ Some Item #2 | BBB | 456 | DDDDD | FFFFF | HHHHH | JJJJJ |
3782+ └──────────────────────────────────────────────────────────────┘
3783+
3784+ Datapoints are a two dimensional array of strings: [][]string
3785+
3786+ Example:
3787+ data := [][]string{
3788+ {"Col0", "Col1", "Col3", "Col4", "Col5", "Col6"},
3789+ {"Some Item #1", "AAA", "123", "CCCCC", "EEEEE", "GGGGG", "IIIII"},
3790+ {"Some Item #2", "BBB", "456", "DDDDD", "FFFFF", "HHHHH", "JJJJJ"},
3791+ }
3792+
3793+ table := termui.NewTable()
3794+ table.Rows = data // type [][]string
3795+ table.FgColor = termui.ColorWhite
3796+ table.BgColor = termui.ColorDefault
3797+ table.Height = 7
3798+ table.Width = 62
3799+ table.Y = 0
3800+ table.X = 0
3801+ table.Border = true
3802+ */
3803+
3804+ // Table tracks all the attributes of a Table instance
3805+ type Table struct {
3806+ Block
3807+ Rows [][]string
3808+ CellWidth []int
3809+ FgColor Attribute
3810+ BgColor Attribute
3811+ FgColors []Attribute
3812+ BgColors []Attribute
3813+ Separator bool
3814+ TextAlign Align
3815+ }
3816+
3817+ // NewTable returns a new Table instance
3818+ func NewTable() *Table {
3819+ table := &Table{Block: *NewBlock()}
3820+ table.FgColor = ColorWhite
3821+ table.BgColor = ColorDefault
3822+ table.Separator = true
3823+ return table
3824+ }
3825+
3826+ // CellsWidth calculates the width of a cell array and returns an int
3827+ func cellsWidth(cells []Cell) int {
3828+ width := 0
3829+ for _, c := range cells {
3830+ width += c.Width()
3831+ }
3832+ return width
3833+ }
3834+
3835+ // Analysis generates and returns an array of []Cell that represent all columns in the Table
3836+ func (table *Table) Analysis() [][]Cell {
3837+ var rowCells [][]Cell
3838+ length := len(table.Rows)
3839+ if length < 1 {
3840+ return rowCells
3841+ }
3842+
3843+ if len(table.FgColors) == 0 {
3844+ table.FgColors = make([]Attribute, len(table.Rows))
3845+ }
3846+ if len(table.BgColors) == 0 {
3847+ table.BgColors = make([]Attribute, len(table.Rows))
3848+ }
3849+
3850+ cellWidths := make([]int, len(table.Rows[0]))
3851+
3852+ for y, row := range table.Rows {
3853+ if table.FgColors[y] == 0 {
3854+ table.FgColors[y] = table.FgColor
3855+ }
3856+ if table.BgColors[y] == 0 {
3857+ table.BgColors[y] = table.BgColor
3858+ }
3859+ for x, str := range row {
3860+ cells := DefaultTxBuilder.Build(str, table.FgColors[y], table.BgColors[y])
3861+ cw := cellsWidth(cells)
3862+ if cellWidths[x] < cw {
3863+ cellWidths[x] = cw
3864+ }
3865+ rowCells = append(rowCells, cells)
3866+ }
3867+ }
3868+ table.CellWidth = cellWidths
3869+ return rowCells
3870+ }
3871+
3872+ // SetSize calculates the table size and sets the internal value
3873+ func (table *Table) SetSize() {
3874+ length := len(table.Rows)
3875+ if table.Separator {
3876+ table.Height = length*2 + 1
3877+ } else {
3878+ table.Height = length + 2
3879+ }
3880+ table.Width = 2
3881+ if length != 0 {
3882+ for _, cellWidth := range table.CellWidth {
3883+ table.Width += cellWidth + 3
3884+ }
3885+ }
3886+ }
3887+
3888+ // CalculatePosition ...
3889+ func (table *Table) CalculatePosition(x int, y int, coordinateX *int, coordinateY *int, cellStart *int) {
3890+ if table.Separator {
3891+ *coordinateY = table.innerArea.Min.Y + y*2
3892+ } else {
3893+ *coordinateY = table.innerArea.Min.Y + y
3894+ }
3895+ if x == 0 {
3896+ *cellStart = table.innerArea.Min.X
3897+ } else {
3898+ *cellStart += table.CellWidth[x-1] + 3
3899+ }
3900+
3901+ switch table.TextAlign {
3902+ case AlignRight:
3903+ *coordinateX = *cellStart + (table.CellWidth[x] - len(table.Rows[y][x])) + 2
3904+ case AlignCenter:
3905+ *coordinateX = *cellStart + (table.CellWidth[x]-len(table.Rows[y][x]))/2 + 2
3906+ default:
3907+ *coordinateX = *cellStart + 2
3908+ }
3909+ }
3910+
3911+ // Buffer ...
3912+ func (table *Table) Buffer() Buffer {
3913+ buffer := table.Block.Buffer()
3914+ rowCells := table.Analysis()
3915+ pointerX := table.innerArea.Min.X + 2
3916+ pointerY := table.innerArea.Min.Y
3917+ borderPointerX := table.innerArea.Min.X
3918+ for y, row := range table.Rows {
3919+ for x := range row {
3920+ table.CalculatePosition(x, y, &pointerX, &pointerY, &borderPointerX)
3921+ background := DefaultTxBuilder.Build(strings.Repeat(" ", table.CellWidth[x]+3), table.BgColors[y], table.BgColors[y])
3922+ cells := rowCells[y*len(row)+x]
3923+ for i, back := range background {
3924+ buffer.Set(borderPointerX+i, pointerY, back)
3925+ }
3926+
3927+ coordinateX := pointerX
3928+ for _, printer := range cells {
3929+ buffer.Set(coordinateX, pointerY, printer)
3930+ coordinateX += printer.Width()
3931+ }
3932+
3933+ if x != 0 {
3934+ dividors := DefaultTxBuilder.Build("|", table.FgColors[y], table.BgColors[y])
3935+ for _, dividor := range dividors {
3936+ buffer.Set(borderPointerX, pointerY, dividor)
3937+ }
3938+ }
3939+ }
3940+
3941+ if table.Separator {
3942+ border := DefaultTxBuilder.Build(strings.Repeat("─", table.Width-2), table.FgColor, table.BgColor)
3943+ for i, cell := range border {
3944+ buffer.Set(i+1, pointerY+1, cell)
3945+ }
3946+ }
3947+ }
3948+
3949+ return buffer
3950+ }
3951 diff --git a/vendor/github.com/gizak/termui/textbuilder.go b/vendor/github.com/gizak/termui/textbuilder.go
3952new file mode 100644
3953index 0000000..12e2055
3954--- /dev/null
3955+++ b/vendor/github.com/gizak/termui/textbuilder.go
3956 @@ -0,0 +1,278 @@
3957+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
3958+ // Use of this source code is governed by a MIT license that can
3959+ // be found in the LICENSE file.
3960+
3961+ package termui
3962+
3963+ import (
3964+ "regexp"
3965+ "strings"
3966+
3967+ "github.com/mitchellh/go-wordwrap"
3968+ )
3969+
3970+ // TextBuilder is a minimal interface to produce text []Cell using specific syntax (markdown).
3971+ type TextBuilder interface {
3972+ Build(s string, fg, bg Attribute) []Cell
3973+ }
3974+
3975+ // DefaultTxBuilder is set to be MarkdownTxBuilder.
3976+ var DefaultTxBuilder = NewMarkdownTxBuilder()
3977+
3978+ // MarkdownTxBuilder implements TextBuilder interface, using markdown syntax.
3979+ type MarkdownTxBuilder struct {
3980+ baseFg Attribute
3981+ baseBg Attribute
3982+ plainTx []rune
3983+ markers []marker
3984+ }
3985+
3986+ type marker struct {
3987+ st int
3988+ ed int
3989+ fg Attribute
3990+ bg Attribute
3991+ }
3992+
3993+ var colorMap = map[string]Attribute{
3994+ "red": ColorRed,
3995+ "blue": ColorBlue,
3996+ "black": ColorBlack,
3997+ "cyan": ColorCyan,
3998+ "yellow": ColorYellow,
3999+ "white": ColorWhite,
4000+ "default": ColorDefault,
4001+ "green": ColorGreen,
4002+ "magenta": ColorMagenta,
4003+ }
4004+
4005+ var attrMap = map[string]Attribute{
4006+ "bold": AttrBold,
4007+ "underline": AttrUnderline,
4008+ "reverse": AttrReverse,
4009+ }
4010+
4011+ func rmSpc(s string) string {
4012+ reg := regexp.MustCompile(`\s+`)
4013+ return reg.ReplaceAllString(s, "")
4014+ }
4015+
4016+ // readAttr translates strings like `fg-red,fg-bold,bg-white` to fg and bg Attribute
4017+ func (mtb MarkdownTxBuilder) readAttr(s string) (Attribute, Attribute) {
4018+ fg := mtb.baseFg
4019+ bg := mtb.baseBg
4020+
4021+ updateAttr := func(a Attribute, attrs []string) Attribute {
4022+ for _, s := range attrs {
4023+ // replace the color
4024+ if c, ok := colorMap[s]; ok {
4025+ a &= 0xFF00 // erase clr 0 ~ 8 bits
4026+ a |= c // set clr
4027+ }
4028+ // add attrs
4029+ if c, ok := attrMap[s]; ok {
4030+ a |= c
4031+ }
4032+ }
4033+ return a
4034+ }
4035+
4036+ ss := strings.Split(s, ",")
4037+ fgs := []string{}
4038+ bgs := []string{}
4039+ for _, v := range ss {
4040+ subs := strings.Split(v, "-")
4041+ if len(subs) > 1 {
4042+ if subs[0] == "fg" {
4043+ fgs = append(fgs, subs[1])
4044+ }
4045+ if subs[0] == "bg" {
4046+ bgs = append(bgs, subs[1])
4047+ }
4048+ }
4049+ }
4050+
4051+ fg = updateAttr(fg, fgs)
4052+ bg = updateAttr(bg, bgs)
4053+ return fg, bg
4054+ }
4055+
4056+ func (mtb *MarkdownTxBuilder) reset() {
4057+ mtb.plainTx = []rune{}
4058+ mtb.markers = []marker{}
4059+ }
4060+
4061+ // parse streams and parses text into normalized text and render sequence.
4062+ func (mtb *MarkdownTxBuilder) parse(str string) {
4063+ rs := str2runes(str)
4064+ normTx := []rune{}
4065+ square := []rune{}
4066+ brackt := []rune{}
4067+ accSquare := false
4068+ accBrackt := false
4069+ cntSquare := 0
4070+
4071+ reset := func() {
4072+ square = []rune{}
4073+ brackt = []rune{}
4074+ accSquare = false
4075+ accBrackt = false
4076+ cntSquare = 0
4077+ }
4078+ // pipe stacks into normTx and clear
4079+ rollback := func() {
4080+ normTx = append(normTx, square...)
4081+ normTx = append(normTx, brackt...)
4082+ reset()
4083+ }
4084+ // chop first and last
4085+ chop := func(s []rune) []rune {
4086+ return s[1 : len(s)-1]
4087+ }
4088+
4089+ for i, r := range rs {
4090+ switch {
4091+ // stacking brackt
4092+ case accBrackt:
4093+ brackt = append(brackt, r)
4094+ if ')' == r {
4095+ fg, bg := mtb.readAttr(string(chop(brackt)))
4096+ st := len(normTx)
4097+ ed := len(normTx) + len(square) - 2
4098+ mtb.markers = append(mtb.markers, marker{st, ed, fg, bg})
4099+ normTx = append(normTx, chop(square)...)
4100+ reset()
4101+ } else if i+1 == len(rs) {
4102+ rollback()
4103+ }
4104+ // stacking square
4105+ case accSquare:
4106+ switch {
4107+ // squares closed and followed by a '('
4108+ case cntSquare == 0 && '(' == r:
4109+ accBrackt = true
4110+ brackt = append(brackt, '(')
4111+ // squares closed but not followed by a '('
4112+ case cntSquare == 0:
4113+ rollback()
4114+ if '[' == r {
4115+ accSquare = true
4116+ cntSquare = 1
4117+ brackt = append(brackt, '[')
4118+ } else {
4119+ normTx = append(normTx, r)
4120+ }
4121+ // hit the end
4122+ case i+1 == len(rs):
4123+ square = append(square, r)
4124+ rollback()
4125+ case '[' == r:
4126+ cntSquare++
4127+ square = append(square, '[')
4128+ case ']' == r:
4129+ cntSquare--
4130+ square = append(square, ']')
4131+ // normal char
4132+ default:
4133+ square = append(square, r)
4134+ }
4135+ // stacking normTx
4136+ default:
4137+ if '[' == r {
4138+ accSquare = true
4139+ cntSquare = 1
4140+ square = append(square, '[')
4141+ } else {
4142+ normTx = append(normTx, r)
4143+ }
4144+ }
4145+ }
4146+
4147+ mtb.plainTx = normTx
4148+ }
4149+
4150+ func wrapTx(cs []Cell, wl int) []Cell {
4151+ tmpCell := make([]Cell, len(cs))
4152+ copy(tmpCell, cs)
4153+
4154+ // get the plaintext
4155+ plain := CellsToStr(cs)
4156+
4157+ // wrap
4158+ plainWrapped := wordwrap.WrapString(plain, uint(wl))
4159+
4160+ // find differences and insert
4161+ finalCell := tmpCell // finalcell will get the inserts and is what is returned
4162+
4163+ plainRune := []rune(plain)
4164+ plainWrappedRune := []rune(plainWrapped)
4165+ trigger := "go"
4166+ plainRuneNew := plainRune
4167+
4168+ for trigger != "stop" {
4169+ plainRune = plainRuneNew
4170+ for i := range plainRune {
4171+ if plainRune[i] == plainWrappedRune[i] {
4172+ trigger = "stop"
4173+ } else if plainRune[i] != plainWrappedRune[i] && plainWrappedRune[i] == 10 {
4174+ trigger = "go"
4175+ cell := Cell{10, 0, 0}
4176+ j := i - 0
4177+
4178+ // insert a cell into the []Cell in correct position
4179+ tmpCell[i] = cell
4180+
4181+ // insert the newline into plain so we avoid indexing errors
4182+ plainRuneNew = append(plainRune, 10)
4183+ copy(plainRuneNew[j+1:], plainRuneNew[j:])
4184+ plainRuneNew[j] = plainWrappedRune[j]
4185+
4186+ // restart the inner for loop until plain and plain wrapped are
4187+ // the same; yeah, it's inefficient, but the text amounts
4188+ // should be small
4189+ break
4190+
4191+ } else if plainRune[i] != plainWrappedRune[i] &&
4192+ plainWrappedRune[i-1] == 10 && // if the prior rune is a newline
4193+ plainRune[i] == 32 { // and this rune is a space
4194+ trigger = "go"
4195+ // need to delete plainRune[i] because it gets rid of an extra
4196+ // space
4197+ plainRuneNew = append(plainRune[:i], plainRune[i+1:]...)
4198+ break
4199+
4200+ } else {
4201+ trigger = "stop" // stops the outer for loop
4202+ }
4203+ }
4204+ }
4205+
4206+ finalCell = tmpCell
4207+
4208+ return finalCell
4209+ }
4210+
4211+ // Build implements TextBuilder interface.
4212+ func (mtb MarkdownTxBuilder) Build(s string, fg, bg Attribute) []Cell {
4213+ mtb.baseFg = fg
4214+ mtb.baseBg = bg
4215+ mtb.reset()
4216+ mtb.parse(s)
4217+ cs := make([]Cell, len(mtb.plainTx))
4218+ for i := range cs {
4219+ cs[i] = Cell{Ch: mtb.plainTx[i], Fg: fg, Bg: bg}
4220+ }
4221+ for _, mrk := range mtb.markers {
4222+ for i := mrk.st; i < mrk.ed; i++ {
4223+ cs[i].Fg = mrk.fg
4224+ cs[i].Bg = mrk.bg
4225+ }
4226+ }
4227+
4228+ return cs
4229+ }
4230+
4231+ // NewMarkdownTxBuilder returns a TextBuilder employing markdown syntax.
4232+ func NewMarkdownTxBuilder() TextBuilder {
4233+ return MarkdownTxBuilder{}
4234+ }
4235 diff --git a/vendor/github.com/gizak/termui/textbuilder_test.go b/vendor/github.com/gizak/termui/textbuilder_test.go
4236new file mode 100644
4237index 0000000..8f458ec
4238--- /dev/null
4239+++ b/vendor/github.com/gizak/termui/textbuilder_test.go
4240 @@ -0,0 +1,70 @@
4241+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
4242+ // Use of this source code is governed by a MIT license that can
4243+ // be found in the LICENSE file.
4244+
4245+ package termui
4246+
4247+ import "testing"
4248+
4249+ func TestReadAttr(t *testing.T) {
4250+ m := MarkdownTxBuilder{}
4251+ m.baseFg = ColorCyan | AttrUnderline
4252+ m.baseBg = ColorBlue | AttrBold
4253+ fg, bg := m.readAttr("fg-red,bg-reverse")
4254+ if fg != ColorRed|AttrUnderline || bg != ColorBlue|AttrBold|AttrReverse {
4255+ t.Error("readAttr failed")
4256+ }
4257+ }
4258+
4259+ func TestMTBParse(t *testing.T) {
4260+ /*
4261+ str := func(cs []Cell) string {
4262+ rs := make([]rune, len(cs))
4263+ for i := range cs {
4264+ rs[i] = cs[i].Ch
4265+ }
4266+ return string(rs)
4267+ }
4268+ */
4269+
4270+ tbls := [][]string{
4271+ {"hello world", "hello world"},
4272+ {"[hello](fg-red) world", "hello world"},
4273+ {"[[hello]](bg-red) world", "[hello] world"},
4274+ {"[1] hello world", "[1] hello world"},
4275+ {"[[1]](bg-white) [hello] world", "[1] [hello] world"},
4276+ {"[hello world]", "[hello world]"},
4277+ {"", ""},
4278+ {"[hello world)", "[hello world)"},
4279+ {"[0] [hello](bg-red)[ world](fg-blue)!", "[0] hello world!"},
4280+ }
4281+
4282+ m := MarkdownTxBuilder{}
4283+ m.baseFg = ColorWhite
4284+ m.baseBg = ColorDefault
4285+ for _, s := range tbls {
4286+ m.reset()
4287+ m.parse(s[0])
4288+ res := string(m.plainTx)
4289+ if s[1] != res {
4290+ t.Errorf("\ninput :%s\nshould:%s\noutput:%s", s[0], s[1], res)
4291+ }
4292+ }
4293+
4294+ m.reset()
4295+ m.parse("[0] [hello](bg-red)[ world](fg-blue)")
4296+ if len(m.markers) != 2 &&
4297+ m.markers[0].st == 4 &&
4298+ m.markers[0].ed == 11 &&
4299+ m.markers[0].fg == ColorWhite &&
4300+ m.markers[0].bg == ColorRed {
4301+ t.Error("markers dismatch")
4302+ }
4303+
4304+ m2 := NewMarkdownTxBuilder()
4305+ cs := m2.Build("[0] [hellob-e) wrd]fgblue)!", ColorWhite, ColorBlack)
4306+ cs = m2.Build("[0] [hello](bg-red) [world](fg-blue)!", ColorWhite, ColorBlack)
4307+ if cs[4].Ch != 'h' && cs[4].Bg != ColorRed && cs[4].Fg != ColorWhite {
4308+ t.Error("dismatch in Build")
4309+ }
4310+ }
4311 diff --git a/vendor/github.com/gizak/termui/theme.go b/vendor/github.com/gizak/termui/theme.go
4312new file mode 100644
4313index 0000000..21fb3bf
4314--- /dev/null
4315+++ b/vendor/github.com/gizak/termui/theme.go
4316 @@ -0,0 +1,140 @@
4317+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
4318+ // Use of this source code is governed by a MIT license that can
4319+ // be found in the LICENSE file.
4320+
4321+ package termui
4322+
4323+ import "strings"
4324+
4325+ /*
4326+ // A ColorScheme represents the current look-and-feel of the dashboard.
4327+ type ColorScheme struct {
4328+ BodyBg Attribute
4329+ BlockBg Attribute
4330+ HasBorder bool
4331+ BorderFg Attribute
4332+ BorderBg Attribute
4333+ BorderLabelTextFg Attribute
4334+ BorderLabelTextBg Attribute
4335+ ParTextFg Attribute
4336+ ParTextBg Attribute
4337+ SparklineLine Attribute
4338+ SparklineTitle Attribute
4339+ GaugeBar Attribute
4340+ GaugePercent Attribute
4341+ LineChartLine Attribute
4342+ LineChartAxes Attribute
4343+ ListItemFg Attribute
4344+ ListItemBg Attribute
4345+ BarChartBar Attribute
4346+ BarChartText Attribute
4347+ BarChartNum Attribute
4348+ MBarChartBar Attribute
4349+ MBarChartText Attribute
4350+ MBarChartNum Attribute
4351+ TabActiveBg Attribute
4352+ }
4353+
4354+ // default color scheme depends on the user's terminal setting.
4355+ var themeDefault = ColorScheme{HasBorder: true}
4356+
4357+ var themeHelloWorld = ColorScheme{
4358+ BodyBg: ColorBlack,
4359+ BlockBg: ColorBlack,
4360+ HasBorder: true,
4361+ BorderFg: ColorWhite,
4362+ BorderBg: ColorBlack,
4363+ BorderLabelTextBg: ColorBlack,
4364+ BorderLabelTextFg: ColorGreen,
4365+ ParTextBg: ColorBlack,
4366+ ParTextFg: ColorWhite,
4367+ SparklineLine: ColorMagenta,
4368+ SparklineTitle: ColorWhite,
4369+ GaugeBar: ColorRed,
4370+ GaugePercent: ColorWhite,
4371+ LineChartLine: ColorYellow | AttrBold,
4372+ LineChartAxes: ColorWhite,
4373+ ListItemBg: ColorBlack,
4374+ ListItemFg: ColorYellow,
4375+ BarChartBar: ColorRed,
4376+ BarChartNum: ColorWhite,
4377+ BarChartText: ColorCyan,
4378+ MBarChartBar: ColorRed,
4379+ MBarChartNum: ColorWhite,
4380+ MBarChartText: ColorCyan,
4381+ TabActiveBg: ColorMagenta,
4382+ }
4383+
4384+ var theme = themeDefault // global dep
4385+
4386+ // Theme returns the currently used theme.
4387+ func Theme() ColorScheme {
4388+ return theme
4389+ }
4390+
4391+ // SetTheme sets a new, custom theme.
4392+ func SetTheme(newTheme ColorScheme) {
4393+ theme = newTheme
4394+ }
4395+
4396+ // UseTheme sets a predefined scheme. Currently available: "hello-world" and
4397+ // "black-and-white".
4398+ func UseTheme(th string) {
4399+ switch th {
4400+ case "helloworld":
4401+ theme = themeHelloWorld
4402+ default:
4403+ theme = themeDefault
4404+ }
4405+ }
4406+ */
4407+
4408+ var ColorMap = map[string]Attribute{
4409+ "fg": ColorWhite,
4410+ "bg": ColorDefault,
4411+ "border.fg": ColorWhite,
4412+ "label.fg": ColorGreen,
4413+ "par.fg": ColorYellow,
4414+ "par.label.bg": ColorWhite,
4415+ }
4416+
4417+ func ThemeAttr(name string) Attribute {
4418+ return lookUpAttr(ColorMap, name)
4419+ }
4420+
4421+ func lookUpAttr(clrmap map[string]Attribute, name string) Attribute {
4422+
4423+ a, ok := clrmap[name]
4424+ if ok {
4425+ return a
4426+ }
4427+
4428+ ns := strings.Split(name, ".")
4429+ for i := range ns {
4430+ nn := strings.Join(ns[i:len(ns)], ".")
4431+ a, ok = ColorMap[nn]
4432+ if ok {
4433+ break
4434+ }
4435+ }
4436+
4437+ return a
4438+ }
4439+
4440+ // 0<=r,g,b <= 5
4441+ func ColorRGB(r, g, b int) Attribute {
4442+ within := func(n int) int {
4443+ if n < 0 {
4444+ return 0
4445+ }
4446+
4447+ if n > 5 {
4448+ return 5
4449+ }
4450+
4451+ return n
4452+ }
4453+
4454+ r, b, g = within(r), within(b), within(g)
4455+ return Attribute(0x0f + 36*r + 6*g + b)
4456+ }
4457 diff --git a/vendor/github.com/gizak/termui/theme_test.go b/vendor/github.com/gizak/termui/theme_test.go
4458new file mode 100644
4459index 0000000..f3d327c
4460--- /dev/null
4461+++ b/vendor/github.com/gizak/termui/theme_test.go
4462 @@ -0,0 +1,35 @@
4463+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
4464+ // Use of this source code is governed by a MIT license that can
4465+ // be found in the LICENSE file.
4466+
4467+ package termui
4468+
4469+ import "testing"
4470+
4471+ var cmap = map[string]Attribute{
4472+ "fg": ColorWhite,
4473+ "bg": ColorDefault,
4474+ "border.fg": ColorWhite,
4475+ "label.fg": ColorGreen,
4476+ "par.fg": ColorYellow,
4477+ "par.label.bg": ColorWhite,
4478+ }
4479+
4480+ func TestLoopUpAttr(t *testing.T) {
4481+ tbl := []struct {
4482+ name string
4483+ should Attribute
4484+ }{
4485+ {"par.label.bg", ColorWhite},
4486+ {"par.label.fg", ColorGreen},
4487+ {"par.bg", ColorDefault},
4488+ {"bar.border.fg", ColorWhite},
4489+ {"bar.label.bg", ColorDefault},
4490+ }
4491+
4492+ for _, v := range tbl {
4493+ if lookUpAttr(cmap, v.name) != v.should {
4494+ t.Error(v.name)
4495+ }
4496+ }
4497+ }
4498 diff --git a/vendor/github.com/gizak/termui/widget.go b/vendor/github.com/gizak/termui/widget.go
4499new file mode 100644
4500index 0000000..80276bf
4501--- /dev/null
4502+++ b/vendor/github.com/gizak/termui/widget.go
4503 @@ -0,0 +1,94 @@
4504+ // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
4505+ // Use of this source code is governed by a MIT license that can
4506+ // be found in the LICENSE file.
4507+
4508+ package termui
4509+
4510+ import (
4511+ "fmt"
4512+ "sync"
4513+ )
4514+
4515+ // event mixins
4516+ type WgtMgr map[string]WgtInfo
4517+
4518+ type WgtInfo struct {
4519+ Handlers map[string]func(Event)
4520+ WgtRef Widget
4521+ Id string
4522+ }
4523+
4524+ type Widget interface {
4525+ Id() string
4526+ }
4527+
4528+ func NewWgtInfo(wgt Widget) WgtInfo {
4529+ return WgtInfo{
4530+ Handlers: make(map[string]func(Event)),
4531+ WgtRef: wgt,
4532+ Id: wgt.Id(),
4533+ }
4534+ }
4535+
4536+ func NewWgtMgr() WgtMgr {
4537+ wm := WgtMgr(make(map[string]WgtInfo))
4538+ return wm
4539+
4540+ }
4541+
4542+ func (wm WgtMgr) AddWgt(wgt Widget) {
4543+ wm[wgt.Id()] = NewWgtInfo(wgt)
4544+ }
4545+
4546+ func (wm WgtMgr) RmWgt(wgt Widget) {
4547+ wm.RmWgtById(wgt.Id())
4548+ }
4549+
4550+ func (wm WgtMgr) RmWgtById(id string) {
4551+ delete(wm, id)
4552+ }
4553+
4554+ func (wm WgtMgr) AddWgtHandler(id, path string, h func(Event)) {
4555+ if w, ok := wm[id]; ok {
4556+ w.Handlers[path] = h
4557+ }
4558+ }
4559+
4560+ func (wm WgtMgr) RmWgtHandler(id, path string) {
4561+ if w, ok := wm[id]; ok {
4562+ delete(w.Handlers, path)
4563+ }
4564+ }
4565+
4566+ var counter struct {
4567+ sync.RWMutex
4568+ count int
4569+ }
4570+
4571+ func GenId() string {
4572+ counter.Lock()
4573+ defer counter.Unlock()
4574+
4575+ counter.count += 1
4576+ return fmt.Sprintf("%d", counter.count)
4577+ }
4578+
4579+ func (wm WgtMgr) WgtHandlersHook() func(Event) {
4580+ return func(e Event) {
4581+ for _, v := range wm {
4582+ if k := findMatch(v.Handlers, e.Path); k != "" {
4583+ v.Handlers[k](e)
4584+ }
4585+ }
4586+ }
4587+ }
4588+
4589+ var DefaultWgtMgr WgtMgr
4590+
4591+ func (b *Block) Handle(path string, handler func(Event)) {
4592+ if _, ok := DefaultWgtMgr[b.Id()]; !ok {
4593+ DefaultWgtMgr.AddWgt(b)
4594+ }
4595+
4596+ DefaultWgtMgr.AddWgtHandler(b.Id(), path, handler)
4597+ }
4598 diff --git a/vendor/github.com/gosuri/uilive/.travis.yml b/vendor/github.com/gosuri/uilive/.travis.yml
4599deleted file mode 100644
4600index 04c834a..0000000
4601--- a/vendor/github.com/gosuri/uilive/.travis.yml
4602+++ /dev/null
4603 @@ -1,7 +0,0 @@
4604- language: go
4605- sudo: false
4606- install:
4607- - go get ./...
4608- go:
4609- - 1.4
4610- - tip
4611 diff --git a/vendor/github.com/gosuri/uilive/LICENSE b/vendor/github.com/gosuri/uilive/LICENSE
4612deleted file mode 100644
4613index e436d90..0000000
4614--- a/vendor/github.com/gosuri/uilive/LICENSE
4615+++ /dev/null
4616 @@ -1,10 +0,0 @@
4617- MIT License
4618- ===========
4619-
4620- Copyright (c) 2015, Greg Osuri
4621-
4622- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4623-
4624- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4625-
4626- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4627 diff --git a/vendor/github.com/gosuri/uilive/README.md b/vendor/github.com/gosuri/uilive/README.md
4628deleted file mode 100644
4629index 5de7d82..0000000
4630--- a/vendor/github.com/gosuri/uilive/README.md
4631+++ /dev/null
4632 @@ -1,31 +0,0 @@
4633- # uilive [![GoDoc](https://godoc.org/github.com/gosuri/uilive?status.svg)](https://godoc.org/github.com/gosuri/uilive) [![Build Status](https://travis-ci.org/gosuri/uilive.svg?branch=master)](https://travis-ci.org/gosuri/uilive)
4634-
4635- uilive is a go library for updating terminal output in realtime. It provides a buffered [io.Writer](https://golang.org/pkg/io/#Writer) that is flushed at a timed interval. uilive powers [uiprogress](https://github.com/gosuri/uiprogress).
4636-
4637- ## Usage Example
4638-
4639- Calling `uilive.New()` will create a new writer. To start rendering, simply call `writer.Start()` and update the ui by writing to the `writer`. Full source for the below example is in [example/main.go](example/main.go).
4640-
4641- ```go
4642- writer := uilive.New()
4643- // start listening for updates and render
4644- writer.Start()
4645-
4646- for i := 0; i <= 100; i++ {
4647- fmt.Fprintf(writer, "Downloading.. (%d/%d) GB\n", i, 100)
4648- time.Sleep(time.Millisecond * 5)
4649- }
4650-
4651- fmt.Fprintln(writer, "Finished: Downloaded 100GB")
4652- writer.Stop() // flush and stop rendering
4653- ```
4654-
4655- The above will render
4656-
4657- ![example](doc/example.gif)
4658-
4659- ## Installation
4660-
4661- ```sh
4662- $ go get -v github.com/gosuri/uilive
4663- ```
4664 diff --git a/vendor/github.com/gosuri/uilive/doc.go b/vendor/github.com/gosuri/uilive/doc.go
4665deleted file mode 100644
4666index d481098..0000000
4667--- a/vendor/github.com/gosuri/uilive/doc.go
4668+++ /dev/null
4669 @@ -1,2 +0,0 @@
4670- // Package uilive provides a writer that live updates the terminal. It provides a buffered io.Writer that is flushed at a timed interval.
4671- package uilive
4672 diff --git a/vendor/github.com/gosuri/uilive/doc/example.gif b/vendor/github.com/gosuri/uilive/doc/example.gif
4673deleted file mode 100644
4674index f85bca2..0000000
4675 Binary files a/vendor/github.com/gosuri/uilive/doc/example.gif and /dev/null differ
4676 diff --git a/vendor/github.com/gosuri/uilive/example/main.go b/vendor/github.com/gosuri/uilive/example/main.go
4677deleted file mode 100644
4678index 31662b9..0000000
4679--- a/vendor/github.com/gosuri/uilive/example/main.go
4680+++ /dev/null
4681 @@ -1,26 +0,0 @@
4682- package main
4683-
4684- import (
4685- "fmt"
4686- "time"
4687-
4688- "github.com/gosuri/uilive"
4689- )
4690-
4691- func main() {
4692- writer := uilive.New()
4693-
4694- // start listening for updates and render
4695- writer.Start()
4696-
4697- for _, f := range []string{"Foo.zip", "Bar.iso"} {
4698- for i := 0; i <= 50; i++ {
4699- fmt.Fprintf(writer, "Downloading %s.. (%d/%d) GB\n", f, i, 50)
4700- time.Sleep(time.Millisecond * 25)
4701- }
4702- fmt.Fprintf(writer.Bypass(), "Downloaded %s\n", f)
4703- }
4704-
4705- fmt.Fprintln(writer, "Finished: Downloaded 100GB")
4706- writer.Stop() // flush and stop rendering
4707- }
4708 diff --git a/vendor/github.com/gosuri/uilive/example_test.go b/vendor/github.com/gosuri/uilive/example_test.go
4709deleted file mode 100644
4710index bc3ca08..0000000
4711--- a/vendor/github.com/gosuri/uilive/example_test.go
4712+++ /dev/null
4713 @@ -1,23 +0,0 @@
4714- package uilive_test
4715-
4716- import (
4717- "fmt"
4718- "time"
4719-
4720- "github.com/gosuri/uilive"
4721- )
4722-
4723- func Example() {
4724- writer := uilive.New()
4725-
4726- // start listening to updates and render
4727- writer.Start()
4728-
4729- for i := 0; i <= 100; i++ {
4730- fmt.Fprintf(writer, "Downloading.. (%d/%d) GB\n", i, 100)
4731- time.Sleep(time.Millisecond * 5)
4732- }
4733-
4734- fmt.Fprintln(writer, "Finished: Downloaded 100GB")
4735- writer.Stop() // flush and stop rendering
4736- }
4737 diff --git a/vendor/github.com/gosuri/uilive/writer.go b/vendor/github.com/gosuri/uilive/writer.go
4738deleted file mode 100644
4739index 2639887..0000000
4740--- a/vendor/github.com/gosuri/uilive/writer.go
4741+++ /dev/null
4742 @@ -1,138 +0,0 @@
4743- package uilive
4744-
4745- import (
4746- "bytes"
4747- "errors"
4748- "io"
4749- "os"
4750- "sync"
4751- "time"
4752- )
4753-
4754- // ESC is the ASCII code for escape character
4755- const ESC = 27
4756-
4757- // RefreshInterval is the default refresh interval to update the ui
4758- var RefreshInterval = time.Millisecond
4759-
4760- // Out is the default output writer for the Writer
4761- var Out = os.Stdout
4762-
4763- // ErrClosedPipe is the error returned when trying to writer is not listening
4764- var ErrClosedPipe = errors.New("uilive: read/write on closed pipe")
4765-
4766- // FdWriter is a writer with a file descriptor.
4767- type FdWriter interface {
4768- io.Writer
4769- Fd() uintptr
4770- }
4771-
4772- // Writer is a buffered the writer that updates the terminal. The contents of writer will be flushed on a timed interval or when Flush is called.
4773- type Writer struct {
4774- // Out is the writer to write to
4775- Out io.Writer
4776-
4777- // RefreshInterval is the time the UI sould refresh
4778- RefreshInterval time.Duration
4779-
4780- ticker *time.Ticker
4781- tdone chan bool
4782-
4783- buf bytes.Buffer
4784- mtx *sync.Mutex
4785- lineCount int
4786- }
4787-
4788- type bypass struct {
4789- writer *Writer
4790- }
4791-
4792- // New returns a new Writer with defaults
4793- func New() *Writer {
4794- return &Writer{
4795- Out: Out,
4796- RefreshInterval: RefreshInterval,
4797-
4798- mtx: &sync.Mutex{},
4799- }
4800- }
4801-
4802- // Flush writes to the out and resets the buffer. It should be called after the last call to Write to ensure that any data buffered in the Writer is written to output.
4803- // Any incomplete escape sequence at the end is considered complete for formatting purposes.
4804- // An error is returned if the contents of the buffer cannot be written to the underlying output stream
4805- func (w *Writer) Flush() error {
4806- w.mtx.Lock()
4807- defer w.mtx.Unlock()
4808-
4809- // do nothing is buffer is empty
4810- if len(w.buf.Bytes()) == 0 {
4811- return nil
4812- }
4813- w.clearLines()
4814-
4815- lines := 0
4816- for _, b := range w.buf.Bytes() {
4817- if b == '\n' {
4818- lines++
4819- }
4820- }
4821- w.lineCount = lines
4822- _, err := w.Out.Write(w.buf.Bytes())
4823- w.buf.Reset()
4824- return err
4825- }
4826-
4827- // Start starts the listener in a non-blocking manner
4828- func (w *Writer) Start() {
4829- if w.ticker == nil {
4830- w.ticker = time.NewTicker(w.RefreshInterval)
4831- w.tdone = make(chan bool, 1)
4832- }
4833-
4834- go w.Listen()
4835- }
4836-
4837- // Stop stops the listener that updates the terminal
4838- func (w *Writer) Stop() {
4839- w.Flush()
4840- close(w.tdone)
4841- }
4842-
4843- // Listen listens for updates to the writer's buffer and flushes to the out provided. It blocks the runtime.
4844- func (w *Writer) Listen() {
4845- for {
4846- select {
4847- case <-w.ticker.C:
4848- if w.ticker != nil {
4849- w.Flush()
4850- }
4851- case <-w.tdone:
4852- w.mtx.Lock()
4853- w.ticker.Stop()
4854- w.ticker = nil
4855- w.mtx.Unlock()
4856- return
4857- }
4858- }
4859- }
4860-
4861- // Write save the contents of b to its buffers. The only errors returned are ones encountered while writing to the underlying buffer.
4862- func (w *Writer) Write(b []byte) (n int, err error) {
4863- w.mtx.Lock()
4864- defer w.mtx.Unlock()
4865- return w.buf.Write(b)
4866- }
4867-
4868- // Bypass creates an io.Writer which allows non-buffered output to be written to the underlying output
4869- func (w *Writer) Bypass() io.Writer {
4870- return &bypass{writer: w}
4871- }
4872-
4873- func (b *bypass) Write(p []byte) (n int, err error) {
4874- b.writer.mtx.Lock()
4875- defer b.writer.mtx.Unlock()
4876-
4877- b.writer.clearLines()
4878- b.writer.lineCount = 0
4879- return b.writer.Out.Write(p)
4880- }
4881 diff --git a/vendor/github.com/gosuri/uilive/writer_posix.go b/vendor/github.com/gosuri/uilive/writer_posix.go
4882deleted file mode 100644
4883index bec6a1d..0000000
4884--- a/vendor/github.com/gosuri/uilive/writer_posix.go
4885+++ /dev/null
4886 @@ -1,14 +0,0 @@
4887- // +build !windows
4888-
4889- package uilive
4890-
4891- import (
4892- "fmt"
4893- )
4894-
4895- func (w *Writer) clearLines() {
4896- for i := 0; i < w.lineCount; i++ {
4897- fmt.Fprintf(w.Out, "%c[2K", ESC) // clear the line
4898- fmt.Fprintf(w.Out, "%c[%dA", ESC, 1) // move the cursor up
4899- }
4900- }
4901 diff --git a/vendor/github.com/gosuri/uilive/writer_test.go b/vendor/github.com/gosuri/uilive/writer_test.go
4902deleted file mode 100644
4903index 5ed200f..0000000
4904--- a/vendor/github.com/gosuri/uilive/writer_test.go
4905+++ /dev/null
4906 @@ -1,24 +0,0 @@
4907- package uilive
4908-
4909- import (
4910- "bytes"
4911- "fmt"
4912- "testing"
4913- )
4914-
4915- func TestWriter(t *testing.T) {
4916- w := New()
4917- b := &bytes.Buffer{}
4918- w.Out = b
4919- w.Start()
4920- for i := 0; i < 2; i++ {
4921- fmt.Fprintln(w, "foo")
4922- }
4923- w.Stop()
4924- fmt.Fprintln(b, "bar")
4925-
4926- want := "foo\nfoo\nbar\n"
4927- if b.String() != want {
4928- t.Fatalf("want %q, got %q", want, b.String())
4929- }
4930- }
4931 diff --git a/vendor/github.com/gosuri/uilive/writer_windows.go b/vendor/github.com/gosuri/uilive/writer_windows.go
4932deleted file mode 100644
4933index 4de3b36..0000000
4934--- a/vendor/github.com/gosuri/uilive/writer_windows.go
4935+++ /dev/null
4936 @@ -1,74 +0,0 @@
4937- // +build windows
4938-
4939- package uilive
4940-
4941- import (
4942- "fmt"
4943- "github.com/mattn/go-isatty"
4944- "syscall"
4945- "unsafe"
4946- )
4947-
4948- var kernel32 = syscall.NewLazyDLL("kernel32.dll")
4949-
4950- var (
4951- procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
4952- procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
4953- procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
4954- procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
4955- )
4956-
4957- type short int16
4958- type dword uint32
4959- type word uint16
4960-
4961- type coord struct {
4962- x short
4963- y short
4964- }
4965-
4966- type smallRect struct {
4967- left short
4968- top short
4969- right short
4970- bottom short
4971- }
4972-
4973- type consoleScreenBufferInfo struct {
4974- size coord
4975- cursorPosition coord
4976- attributes word
4977- window smallRect
4978- maximumWindowSize coord
4979- }
4980-
4981- func (w *Writer) clearLines() {
4982- f, ok := w.Out.(FdWriter)
4983- if ok && !isatty.IsTerminal(f.Fd()) {
4984- ok = false
4985- }
4986- if !ok {
4987- for i := 0; i < w.lineCount; i++ {
4988- fmt.Fprintf(w.Out, "%c[%dA", ESC, 0) // move the cursor up
4989- fmt.Fprintf(w.Out, "%c[2K\r", ESC) // clear the line
4990- }
4991- return
4992- }
4993- fd := f.Fd()
4994- var csbi consoleScreenBufferInfo
4995- procGetConsoleScreenBufferInfo.Call(fd, uintptr(unsafe.Pointer(&csbi)))
4996-
4997- for i := 0; i < w.lineCount; i++ {
4998- // move the cursor up
4999- csbi.cursorPosition.y--
5000- procSetConsoleCursorPosition.Call(fd, uintptr(*(*int32)(unsafe.Pointer(&csbi.cursorPosition))))
5001- // clear the line
5002- cursor := coord{
5003- x: csbi.window.left,
5004- y: csbi.window.top + csbi.cursorPosition.y,
5005- }
5006- var count, w dword
5007- count = dword(csbi.size.x)
5008- procFillConsoleOutputCharacter.Call(fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&w)))
5009- }
5010- }
5011 diff --git a/vendor/github.com/jawher/mow.cli/testdata/help-output.txt b/vendor/github.com/jawher/mow.cli/testdata/help-output.txt
5012deleted file mode 100644
5013index 1ac03c3..0000000
5014--- a/vendor/github.com/jawher/mow.cli/testdata/help-output.txt
5015+++ /dev/null
5016 @@ -1,45 +0,0 @@
5017-
5018- Usage: app [-bdsuikqs] BOOL1 [STR1] INT3... COMMAND [arg...]
5019-
5020- App Desc
5021-
5022- Arguments:
5023- BOOL1 Bool Argument 1 (env $BOOL1)
5024- BOOL2 Bool Argument 2 (default true)
5025- BOOL3 Bool Argument 3 (env $BOOL3)
5026- STR1 String Argument 1 (env $STR1)
5027- STR2 String Argument 2 (env $STR2) (default "a value")
5028- STR3 String Argument 3 (env $STR3)
5029- INT1 Int Argument 1 (env $INT1) (default 0)
5030- INT2 Int Argument 2 (env $INT2) (default 1)
5031- INT3 Int Argument 3 (env $INT3)
5032- STRS1 Strings Argument 1 (env $STRS1)
5033- STRS2 (env $STRS2) (default ["value1", "value2"])
5034- STRS3 Strings Argument 3 (env $STRS3)
5035- INTS1 Ints Argument 1 (env $INTS1)
5036- INTS2 Ints Argument 2 (env $INTS2) (default [1, 2, 3])
5037- INTS3 Ints Argument 3 (env $INTS3)
5038-
5039- Options:
5040- -b, --bool1 Bool Option 1 (env $BOOL1)
5041- --bool2 Bool Option 2 (default true)
5042- -d Bool Option 3 (env $BOOL3)
5043- -s, --str1 String Option 1 (env $STR1)
5044- --str2 String Option 2 (default "a value")
5045- -u String Option 3 (env $STR3)
5046- -i, --int1 (env $INT1, $ALIAS_INT1) (default 0)
5047- --int2 Int Option 2 (env $INT2) (default 1)
5048- -k Int Option 3 (env $INT3)
5049- -x, --strs1 Strings Option 1 (env $STRS1)
5050- --strs2 Strings Option 2 (env $STRS2) (default ["value1", "value2"])
5051- -z Strings Option 3 (env $STRS3)
5052- -q, --ints1 Ints Option 1 (env $INTS1)
5053- --ints2 Ints Option 2 (env $INTS2) (default [1, 2, 3])
5054- -s Ints Option 3 (env $INTS3)
5055-
5056- Commands:
5057- command1 command1 description
5058- command2 command2 description
5059- command3 command3 description
5060-
5061- Run 'app COMMAND --help' for more information on a command.
5062 diff --git a/vendor/github.com/jawher/mow.cli/testdata/long-help-output.txt b/vendor/github.com/jawher/mow.cli/testdata/long-help-output.txt
5063deleted file mode 100644
5064index e47bf93..0000000
5065--- a/vendor/github.com/jawher/mow.cli/testdata/long-help-output.txt
5066+++ /dev/null
5067 @@ -1,10 +0,0 @@
5068-
5069- Usage: app [-o] ARG
5070-
5071- Longer App Desc
5072-
5073- Arguments:
5074- ARG Argument
5075-
5076- Options:
5077- -o, --opt Option
5078 diff --git a/vendor/github.com/maruel/panicparse/.travis.yml b/vendor/github.com/maruel/panicparse/.travis.yml
5079new file mode 100644
5080index 0000000..1174e42
5081--- /dev/null
5082+++ b/vendor/github.com/maruel/panicparse/.travis.yml
5083 @@ -0,0 +1,16 @@
5084+ # Copyright 2014 Marc-Antoine Ruel. All rights reserved.
5085+ # Use of this source code is governed under the Apache License, Version 2.0
5086+ # that can be found in the LICENSE file.
5087+
5088+ sudo: false
5089+ language: go
5090+
5091+ go:
5092+ - 1.8.x
5093+ - 1.x
5094+
5095+ before_install:
5096+ - go get github.com/maruel/pre-commit-go/cmd/pcg
5097+
5098+ script:
5099+ - pcg
5100 diff --git a/vendor/github.com/maruel/panicparse/Gopkg.lock b/vendor/github.com/maruel/panicparse/Gopkg.lock
5101new file mode 100644
5102index 0000000..fac5700
5103--- /dev/null
5104+++ b/vendor/github.com/maruel/panicparse/Gopkg.lock
5105 @@ -0,0 +1,57 @@
5106+ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
5107+
5108+
5109+ [[projects]]
5110+ branch = "master"
5111+ name = "github.com/kr/pretty"
5112+ packages = ["."]
5113+ revision = "cfb55aafdaf3ec08f0db22699ab822c50091b1c4"
5114+
5115+ [[projects]]
5116+ branch = "master"
5117+ name = "github.com/kr/text"
5118+ packages = ["."]
5119+ revision = "7cafcd837844e784b526369c9bce262804aebc60"
5120+
5121+ [[projects]]
5122+ name = "github.com/maruel/ut"
5123+ packages = ["."]
5124+ revision = "a9c9f15ccfa6f8b90182a53df32f4745586fbae3"
5125+ version = "v1.0.0"
5126+
5127+ [[projects]]
5128+ name = "github.com/mattn/go-colorable"
5129+ packages = ["."]
5130+ revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
5131+ version = "v0.0.9"
5132+
5133+ [[projects]]
5134+ name = "github.com/mattn/go-isatty"
5135+ packages = ["."]
5136+ revision = "fc9e8d8ef48496124e79ae0df75490096eccf6fe"
5137+ version = "v0.0.2"
5138+
5139+ [[projects]]
5140+ branch = "master"
5141+ name = "github.com/mgutz/ansi"
5142+ packages = ["."]
5143+ revision = "9520e82c474b0a04dd04f8a40959027271bab992"
5144+
5145+ [[projects]]
5146+ name = "github.com/pmezard/go-difflib"
5147+ packages = ["difflib"]
5148+ revision = "792786c7400a136282c1664665ae0a8db921c6c2"
5149+ version = "v1.0.0"
5150+
5151+ [[projects]]
5152+ branch = "master"
5153+ name = "golang.org/x/sys"
5154+ packages = ["unix"]
5155+ revision = "e42485b6e20ae7d2304ec72e535b103ed350cc02"
5156+
5157+ [solve-meta]
5158+ analyzer-name = "dep"
5159+ analyzer-version = 1
5160+ inputs-digest = "64e1c923b988d687243b43f8168fc7a83ceb603bf1ce4126022d34625cada8d9"
5161+ solver-name = "gps-cdcl"
5162+ solver-version = 1
5163 diff --git a/vendor/github.com/maruel/panicparse/Gopkg.toml b/vendor/github.com/maruel/panicparse/Gopkg.toml
5164new file mode 100644
5165index 0000000..1aa8264
5166--- /dev/null
5167+++ b/vendor/github.com/maruel/panicparse/Gopkg.toml
5168 @@ -0,0 +1,38 @@
5169+
5170+ # Gopkg.toml example
5171+ #
5172+ # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5173+ # for detailed Gopkg.toml documentation.
5174+ #
5175+ # required = ["github.com/user/thing/cmd/thing"]
5176+ # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
5177+ #
5178+ # [[constraint]]
5179+ # name = "github.com/user/project"
5180+ # version = "1.0.0"
5181+ #
5182+ # [[constraint]]
5183+ # name = "github.com/user/project2"
5184+ # branch = "dev"
5185+ # source = "github.com/myfork/project2"
5186+ #
5187+ # [[override]]
5188+ # name = "github.com/x/y"
5189+ # version = "2.4.0"
5190+
5191+
5192+ [[constraint]]
5193+ name = "github.com/maruel/ut"
5194+ version = "1.0.0"
5195+
5196+ [[constraint]]
5197+ name = "github.com/mattn/go-colorable"
5198+ version = "0.0.9"
5199+
5200+ [[constraint]]
5201+ name = "github.com/mattn/go-isatty"
5202+ version = "0.0.2"
5203+
5204+ [[constraint]]
5205+ branch = "master"
5206+ name = "github.com/mgutz/ansi"
5207 diff --git a/vendor/github.com/maruel/panicparse/LICENSE b/vendor/github.com/maruel/panicparse/LICENSE
5208new file mode 100644
5209index 0000000..b76840c
5210--- /dev/null
5211+++ b/vendor/github.com/maruel/panicparse/LICENSE
5212 @@ -0,0 +1,201 @@
5213+ Apache License
5214+ Version 2.0, January 2004
5215+ http://www.apache.org/licenses/
5216+
5217+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
5218+
5219+ 1. Definitions.
5220+
5221+ "License" shall mean the terms and conditions for use, reproduction,
5222+ and distribution as defined by Sections 1 through 9 of this document.
5223+
5224+ "Licensor" shall mean the copyright owner or entity authorized by
5225+ the copyright owner that is granting the License.
5226+
5227+ "Legal Entity" shall mean the union of the acting entity and all
5228+ other entities that control, are controlled by, or are under common
5229+ control with that entity. For the purposes of this definition,
5230+ "control" means (i) the power, direct or indirect, to cause the
5231+ direction or management of such entity, whether by contract or
5232+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
5233+ outstanding shares, or (iii) beneficial ownership of such entity.
5234+
5235+ "You" (or "Your") shall mean an individual or Legal Entity
5236+ exercising permissions granted by this License.
5237+
5238+ "Source" form shall mean the preferred form for making modifications,
5239+ including but not limited to software source code, documentation
5240+ source, and configuration files.
5241+
5242+ "Object" form shall mean any form resulting from mechanical
5243+ transformation or translation of a Source form, including but
5244+ not limited to compiled object code, generated documentation,
5245+ and conversions to other media types.
5246+
5247+ "Work" shall mean the work of authorship, whether in Source or
5248+ Object form, made available under the License, as indicated by a
5249+ copyright notice that is included in or attached to the work
5250+ (an example is provided in the Appendix below).
5251+
5252+ "Derivative Works" shall mean any work, whether in Source or Object
5253+ form, that is based on (or derived from) the Work and for which the
5254+ editorial revisions, annotations, elaborations, or other modifications
5255+ represent, as a whole, an original work of authorship. For the purposes
5256+ of this License, Derivative Works shall not include works that remain
5257+ separable from, or merely link (or bind by name) to the interfaces of,
5258+ the Work and Derivative Works thereof.
5259+
5260+ "Contribution" shall mean any work of authorship, including
5261+ the original version of the Work and any modifications or additions
5262+ to that Work or Derivative Works thereof, that is intentionally
5263+ submitted to Licensor for inclusion in the Work by the copyright owner
5264+ or by an individual or Legal Entity authorized to submit on behalf of
5265+ the copyright owner. For the purposes of this definition, "submitted"
5266+ means any form of electronic, verbal, or written communication sent
5267+ to the Licensor or its representatives, including but not limited to
5268+ communication on electronic mailing lists, source code control systems,
5269+ and issue tracking systems that are managed by, or on behalf of, the
5270+ Licensor for the purpose of discussing and improving the Work, but
5271+ excluding communication that is conspicuously marked or otherwise
5272+ designated in writing by the copyright owner as "Not a Contribution."
5273+
5274+ "Contributor" shall mean Licensor and any individual or Legal Entity
5275+ on behalf of whom a Contribution has been received by Licensor and
5276+ subsequently incorporated within the Work.
5277+
5278+ 2. Grant of Copyright License. Subject to the terms and conditions of
5279+ this License, each Contributor hereby grants to You a perpetual,
5280+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
5281+ copyright license to reproduce, prepare Derivative Works of,
5282+ publicly display, publicly perform, sublicense, and distribute the
5283+ Work and such Derivative Works in Source or Object form.
5284+
5285+ 3. Grant of Patent License. Subject to the terms and conditions of
5286+ this License, each Contributor hereby grants to You a perpetual,
5287+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
5288+ (except as stated in this section) patent license to make, have made,
5289+ use, offer to sell, sell, import, and otherwise transfer the Work,
5290+ where such license applies only to those patent claims licensable
5291+ by such Contributor that are necessarily infringed by their
5292+ Contribution(s) alone or by combination of their Contribution(s)
5293+ with the Work to which such Contribution(s) was submitted. If You
5294+ institute patent litigation against any entity (including a
5295+ cross-claim or counterclaim in a lawsuit) alleging that the Work
5296+ or a Contribution incorporated within the Work constitutes direct
5297+ or contributory patent infringement, then any patent licenses
5298+ granted to You under this License for that Work shall terminate
5299+ as of the date such litigation is filed.
5300+
5301+ 4. Redistribution. You may reproduce and distribute copies of the
5302+ Work or Derivative Works thereof in any medium, with or without
5303+ modifications, and in Source or Object form, provided that You
5304+ meet the following conditions:
5305+
5306+ (a) You must give any other recipients of the Work or
5307+ Derivative Works a copy of this License; and
5308+
5309+ (b) You must cause any modified files to carry prominent notices
5310+ stating that You changed the files; and
5311+
5312+ (c) You must retain, in the Source form of any Derivative Works
5313+ that You distribute, all copyright, patent, trademark, and
5314+ attribution notices from the Source form of the Work,
5315+ excluding those notices that do not pertain to any part of
5316+ the Derivative Works; and
5317+
5318+ (d) If the Work includes a "NOTICE" text file as part of its
5319+ distribution, then any Derivative Works that You distribute must
5320+ include a readable copy of the attribution notices contained
5321+ within such NOTICE file, excluding those notices that do not
5322+ pertain to any part of the Derivative Works, in at least one
5323+ of the following places: within a NOTICE text file distributed
5324+ as part of the Derivative Works; within the Source form or
5325+ documentation, if provided along with the Derivative Works; or,
5326+ within a display generated by the Derivative Works, if and
5327+ wherever such third-party notices normally appear. The contents
5328+ of the NOTICE file are for informational purposes only and
5329+ do not modify the License. You may add Your own attribution
5330+ notices within Derivative Works that You distribute, alongside
5331+ or as an addendum to the NOTICE text from the Work, provided
5332+ that such additional attribution notices cannot be construed
5333+ as modifying the License.
5334+
5335+ You may add Your own copyright statement to Your modifications and
5336+ may provide additional or different license terms and conditions
5337+ for use, reproduction, or distribution of Your modifications, or
5338+ for any such Derivative Works as a whole, provided Your use,
5339+ reproduction, and distribution of the Work otherwise complies with
5340+ the conditions stated in this License.
5341+
5342+ 5. Submission of Contributions. Unless You explicitly state otherwise,
5343+ any Contribution intentionally submitted for inclusion in the Work
5344+ by You to the Licensor shall be under the terms and conditions of
5345+ this License, without any additional terms or conditions.
5346+ Notwithstanding the above, nothing herein shall supersede or modify
5347+ the terms of any separate license agreement you may have executed
5348+ with Licensor regarding such Contributions.
5349+
5350+ 6. Trademarks. This License does not grant permission to use the trade
5351+ names, trademarks, service marks, or product names of the Licensor,
5352+ except as required for reasonable and customary use in describing the
5353+ origin of the Work and reproducing the content of the NOTICE file.
5354+
5355+ 7. Disclaimer of Warranty. Unless required by applicable law or
5356+ agreed to in writing, Licensor provides the Work (and each
5357+ Contributor provides its Contributions) on an "AS IS" BASIS,
5358+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
5359+ implied, including, without limitation, any warranties or conditions
5360+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
5361+ PARTICULAR PURPOSE. You are solely responsible for determining the
5362+ appropriateness of using or redistributing the Work and assume any
5363+ risks associated with Your exercise of permissions under this License.
5364+
5365+ 8. Limitation of Liability. In no event and under no legal theory,
5366+ whether in tort (including negligence), contract, or otherwise,
5367+ unless required by applicable law (such as deliberate and grossly
5368+ negligent acts) or agreed to in writing, shall any Contributor be
5369+ liable to You for damages, including any direct, indirect, special,
5370+ incidental, or consequential damages of any character arising as a
5371+ result of this License or out of the use or inability to use the
5372+ Work (including but not limited to damages for loss of goodwill,
5373+ work stoppage, computer failure or malfunction, or any and all
5374+ other commercial damages or losses), even if such Contributor
5375+ has been advised of the possibility of such damages.
5376+
5377+ 9. Accepting Warranty or Additional Liability. While redistributing
5378+ the Work or Derivative Works thereof, You may choose to offer,
5379+ and charge a fee for, acceptance of support, warranty, indemnity,
5380+ or other liability obligations and/or rights consistent with this
5381+ License. However, in accepting such obligations, You may act only
5382+ on Your own behalf and on Your sole responsibility, not on behalf
5383+ of any other Contributor, and only if You agree to indemnify,
5384+ defend, and hold each Contributor harmless for any liability
5385+ incurred by, or claims asserted against, such Contributor by reason
5386+ of your accepting any such warranty or additional liability.
5387+
5388+ END OF TERMS AND CONDITIONS
5389+
5390+ APPENDIX: How to apply the Apache License to your work.
5391+
5392+ To apply the Apache License to your work, attach the following
5393+ boilerplate notice, with the fields enclosed by brackets "{}"
5394+ replaced with your own identifying information. (Don't include
5395+ the brackets!) The text should be enclosed in the appropriate
5396+ comment syntax for the file format. We also recommend that a
5397+ file or class name and description of purpose be included on the
5398+ same "printed page" as the copyright notice for easier
5399+ identification within third-party archives.
5400+
5401+ Copyright 2015 Marc-Antoine Ruel
5402+
5403+ Licensed under the Apache License, Version 2.0 (the "License");
5404+ you may not use this file except in compliance with the License.
5405+ You may obtain a copy of the License at
5406+
5407+ http://www.apache.org/licenses/LICENSE-2.0
5408+
5409+ Unless required by applicable law or agreed to in writing, software
5410+ distributed under the License is distributed on an "AS IS" BASIS,
5411+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5412+ See the License for the specific language governing permissions and
5413+ limitations under the License.
5414 diff --git a/vendor/github.com/maruel/panicparse/README.md b/vendor/github.com/maruel/panicparse/README.md
5415new file mode 100644
5416index 0000000..0bcd133
5417--- /dev/null
5418+++ b/vendor/github.com/maruel/panicparse/README.md
5419 @@ -0,0 +1,139 @@
5420+ panicparse
5421+ ==========
5422+
5423+ Parses panic stack traces, densifies and deduplicates goroutines with similar
5424+ stack traces. Helps debugging crashes and deadlocks in heavily parallelized
5425+ process.
5426+
5427+ [![Build Status](https://travis-ci.org/maruel/panicparse.svg?branch=master)](https://travis-ci.org/maruel/panicparse)
5428+
5429+ panicparse helps make sense of Go crash dumps:
5430+
5431+ ![Screencast](https://raw.githubusercontent.com/wiki/maruel/panicparse/parse.gif "Screencast")
5432+
5433+
5434+ Features
5435+ --------
5436+
5437+ * &gt;50% more compact output than original stack dump yet more readable.
5438+ * Exported symbols are bold, private symbols are darker.
5439+ * Stdlib is green, main is yellow, rest is red.
5440+ * Deduplicates redundant goroutine stacks. Useful for large server crashes.
5441+ * Arguments as pointer IDs instead of raw pointer values.
5442+ * Pushes stdlib-only stacks at the bottom to help focus on important code.
5443+ * Usable as a library!
5444+ [![GoDoc](https://godoc.org/github.com/maruel/panicparse/stack?status.svg)](https://godoc.org/github.com/maruel/panicparse/stack)
5445+ * Warning: please pin the version (e.g. vendor it). Breaking changes are
5446+ not planned but may happen.
5447+ * Parses the source files if available to augment the output.
5448+ * Works on Windows.
5449+
5450+
5451+ Installation
5452+ ------------
5453+
5454+ go get github.com/maruel/panicparse/cmd/pp
5455+
5456+
5457+ Usage
5458+ -----
5459+
5460+ ### Piping a stack trace from another process
5461+
5462+ #### TL;DR
5463+
5464+ * Ubuntu (bash v4 or zsh): `|&`
5465+ * OSX, [install bash 4+](README.md#updating-bash-on-osx), then: `|&`
5466+ * Windows _or_ OSX with stock bash v3: `2>&1 |`
5467+ * [Fish](http://fishshell.com/) shell: `^|`
5468+
5469+
5470+ #### Longer version
5471+
5472+ `pp` streams its stdin to stdout as long as it doesn't detect any panic.
5473+ `panic()` and Go's native deadlock detector [print to
5474+ stderr](https://golang.org/src/runtime/panic1.go) via the native [`print()`
5475+ function](https://golang.org/pkg/builtin/#print).
5476+
5477+
5478+ **Bash v4** or **zsh**: `|&` tells the shell to redirect stderr to stdout,
5479+ it's an alias for `2>&1 |` ([bash
5480+ v4](https://www.gnu.org/software/bash/manual/bash.html#Pipelines),
5481+ [zsh](http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines)):
5482+
5483+ go test -v |&pp
5484+
5485+
5486+ **Windows or OSX native bash** [(which is
5487+ 3.2.57)](http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/): They don't
5488+ have this shortcut, so use the long form:
5489+
5490+ go test -v 2>&1 | pp
5491+
5492+
5493+ **Fish**: It uses [^ for stderr
5494+ redirection](http://fishshell.com/docs/current/tutorial.html#tut_pipes_and_redirections)
5495+ so the shortcut is `^|`:
5496+
5497+ go test -v ^|pp
5498+
5499+
5500+ **PowerShell**: [It has broken `2>&1` redirection](https://connect.microsoft.com/PowerShell/feedback/details/765551/in-powershell-v3-you-cant-redirect-stderr-to-stdout-without-generating-error-records). The workaround is to shell out to cmd.exe. :(
5501+
5502+
5503+ ### Investigate deadlock
5504+
5505+ On POSIX, use `Ctrl-\` to send SIGQUIT to your process, `pp` will ignore
5506+ the signal and will parse the stack trace.
5507+
5508+
5509+ ### Parsing from a file
5510+
5511+ To dump to a file then parse, pass the file path of a stack trace
5512+
5513+ go test 2> stack.txt
5514+ pp stack.txt
5515+
5516+
5517+ Tips
5518+ ----
5519+
5520+ ### GOTRACEBACK
5521+
5522+ Starting with Go 1.6, [`GOTRACEBACK`](https://golang.org/pkg/runtime/) defaults
5523+ to `single` instead of `all` / `1` that was used in 1.5 and before. To get all
5524+ goroutines trace and not just the crashing one, set the environment variable:
5525+
5526+ export GOTRACEBACK=all
5527+
5528+ or `set GOTRACEBACK=all` on Windows. Probably worth to put it in your `.bashrc`.
5529+
5530+
5531+ ### Updating bash on OSX
5532+
5533+ Install bash v4+ on OSX via [homebrew](http://brew.sh) or
5534+ [macports](https://www.macports.org/). Your future self will appreciate having
5535+ done that.
5536+
5537+
5538+ ### If you have `/usr/bin/pp` installed
5539+
5540+ If you try `pp` for the first time and you get:
5541+
5542+ Creating tables and indexes...
5543+ Done.
5544+
5545+ and/or
5546+
5547+ /usr/bin/pp5.18: No input files specified
5548+
5549+ you may be running the _Perl PAR Packager_ instead of panicparse.
5550+
5551+ You have two choices, either you put `$GOPATH/bin` at the begining of `$PATH` or
5552+ use long name `panicparse` with:
5553+
5554+ go get github.com/maruel/panicparse
5555+
5556+ then using `panicparse` instead of `pp`:
5557+
5558+ go test 2> panicparse
5559 diff --git a/vendor/github.com/maruel/panicparse/main.go b/vendor/github.com/maruel/panicparse/main.go
5560new file mode 100644
5561index 0000000..67d8e1a
5562--- /dev/null
5563+++ b/vendor/github.com/maruel/panicparse/main.go
5564 @@ -0,0 +1,31 @@
5565+ // Copyright 2015 Marc-Antoine Ruel. All rights reserved.
5566+ // Use of this source code is governed under the Apache License, Version 2.0
5567+ // that can be found in the LICENSE file.
5568+
5569+ // panicparse: analyzes stack dump of Go processes and simplifies it.
5570+ //
5571+ // It is mostly useful on servers will large number of identical goroutines,
5572+ // making the crash dump harder to read than strictly necesary.
5573+ //
5574+ // Colors:
5575+ // - Magenta: first goroutine to be listed.
5576+ // - Yellow: main package.
5577+ // - Green: standard library.
5578+ // - Red: other packages.
5579+ //
5580+ // Bright colors are used for exported symbols.
5581+ package main
5582+
5583+ import (
5584+ "fmt"
5585+ "os"
5586+
5587+ "github.com/maruel/panicparse/internal"
5588+ )
5589+
5590+ func main() {
5591+ if err := internal.Main(); err != nil {
5592+ fmt.Fprintf(os.Stderr, "Failed: %s\n", err)
5593+ os.Exit(1)
5594+ }
5595+ }
5596 diff --git a/vendor/github.com/maruel/panicparse/stack/source.go b/vendor/github.com/maruel/panicparse/stack/source.go
5597new file mode 100644
5598index 0000000..a747250
5599--- /dev/null
5600+++ b/vendor/github.com/maruel/panicparse/stack/source.go
5601 @@ -0,0 +1,302 @@
5602+ // Copyright 2015 Marc-Antoine Ruel. All rights reserved.
5603+ // Use of this source code is governed under the Apache License, Version 2.0
5604+ // that can be found in the LICENSE file.
5605+
5606+ // This file contains the code to process sources, to be able to deduct the
5607+ // original types.
5608+
5609+ package stack
5610+
5611+ import (
5612+ "bytes"
5613+ "fmt"
5614+ "go/ast"
5615+ "go/parser"
5616+ "go/token"
5617+ "io/ioutil"
5618+ "log"
5619+ "math"
5620+ "strings"
5621+ )
5622+
5623+ // cache is a cache of sources on the file system.
5624+ type cache struct {
5625+ files map[string][]byte
5626+ parsed map[string]*parsedFile
5627+ }
5628+
5629+ // Augment processes source files to improve calls to be more descriptive.
5630+ //
5631+ // It modifies goroutines in place.
5632+ func Augment(goroutines []Goroutine) {
5633+ c := &cache{}
5634+ for i := range goroutines {
5635+ c.augmentGoroutine(&goroutines[i])
5636+ }
5637+ }
5638+
5639+ // augmentGoroutine processes source files to improve call to be more
5640+ // descriptive.
5641+ //
5642+ // It modifies the routine.
5643+ func (c *cache) augmentGoroutine(goroutine *Goroutine) {
5644+ if c.files == nil {
5645+ c.files = map[string][]byte{}
5646+ }
5647+ if c.parsed == nil {
5648+ c.parsed = map[string]*parsedFile{}
5649+ }
5650+ // For each call site, look at the next call and populate it. Then we can
5651+ // walk back and reformat things.
5652+ for i := range goroutine.Stack.Calls {
5653+ c.load(goroutine.Stack.Calls[i].SourcePath)
5654+ }
5655+
5656+ // Once all loaded, we can look at the next call when available.
5657+ for i := 0; i < len(goroutine.Stack.Calls)-1; i++ {
5658+ // Get the AST from the previous call and process the call line with it.
5659+ if f := c.getFuncAST(&goroutine.Stack.Calls[i]); f != nil {
5660+ processCall(&goroutine.Stack.Calls[i], f)
5661+ }
5662+ }
5663+ }
5664+
5665+ // Private stuff.
5666+
5667+ // load loads a source file and parses the AST tree. Failures are ignored.
5668+ func (c *cache) load(fileName string) {
5669+ if _, ok := c.parsed[fileName]; ok {
5670+ return
5671+ }
5672+ c.parsed[fileName] = nil
5673+ if !strings.HasSuffix(fileName, ".go") {
5674+ // Ignore C and assembly.
5675+ c.files[fileName] = nil
5676+ return
5677+ }
5678+ log.Printf("load(%s)", fileName)
5679+ if _, ok := c.files[fileName]; !ok {
5680+ var err error
5681+ if c.files[fileName], err = ioutil.ReadFile(fileName); err != nil {
5682+ log.Printf("Failed to read %s: %s", fileName, err)
5683+ c.files[fileName] = nil
5684+ return
5685+ }
5686+ }
5687+ fset := token.NewFileSet()
5688+ src := c.files[fileName]
5689+ parsed, err := parser.ParseFile(fset, fileName, src, 0)
5690+ if err != nil {
5691+ log.Printf("Failed to parse %s: %s", fileName, err)
5692+ return
5693+ }
5694+ // Convert the line number into raw file offset.
5695+ offsets := []int{0, 0}
5696+ start := 0
5697+ for l := 1; start < len(src); l++ {
5698+ start += bytes.IndexByte(src[start:], '\n') + 1
5699+ offsets = append(offsets, start)
5700+ }
5701+ c.parsed[fileName] = &parsedFile{offsets, parsed}
5702+ }
5703+
5704+ func (c *cache) getFuncAST(call *Call) *ast.FuncDecl {
5705+ if p := c.parsed[call.SourcePath]; p != nil {
5706+ return p.getFuncAST(call.Func.Name(), call.Line)
5707+ }
5708+ return nil
5709+ }
5710+
5711+ type parsedFile struct {
5712+ lineToByteOffset []int
5713+ parsed *ast.File
5714+ }
5715+
5716+ // getFuncAST gets the callee site function AST representation for the code
5717+ // inside the function f at line l.
5718+ func (p *parsedFile) getFuncAST(f string, l int) (d *ast.FuncDecl) {
5719+ if len(p.lineToByteOffset) <= l {
5720+ // The line number in the stack trace line does not exist in the file. That
5721+ // can only mean that the sources on disk do not match the sources used to
5722+ // build the binary.
5723+ // TODO(maruel): This should be surfaced, so that source parsing is
5724+ // completely ignored.
5725+ return
5726+ }
5727+
5728+ // Walk the AST to find the lineToByteOffset that fits the line number.
5729+ var lastFunc *ast.FuncDecl
5730+ var found ast.Node
5731+ // Inspect() goes depth first. This means for example that a function like:
5732+ // func a() {
5733+ // b := func() {}
5734+ // c()
5735+ // }
5736+ //
5737+ // Were we are looking at the c() call can return confused values. It is
5738+ // important to look at the actual ast.Node hierarchy.
5739+ ast.Inspect(p.parsed, func(n ast.Node) bool {
5740+ if d != nil {
5741+ return false
5742+ }
5743+ if n == nil {
5744+ return true
5745+ }
5746+ if found != nil {
5747+ // We are walking up.
5748+ }
5749+ if int(n.Pos()) >= p.lineToByteOffset[l] {
5750+ // We are expecting a ast.CallExpr node. It can be harder to figure out
5751+ // when there are multiple calls on a single line, as the stack trace
5752+ // doesn't have file byte offset information, only line based.
5753+ // gofmt will always format to one function call per line but there can
5754+ // be edge cases, like:
5755+ // a = A{Foo(), Bar()}
5756+ d = lastFunc
5757+ //p.processNode(call, n)
5758+ return false
5759+ } else if f, ok := n.(*ast.FuncDecl); ok {
5760+ lastFunc = f
5761+ }
5762+ return true
5763+ })
5764+ return
5765+ }
5766+
5767+ func name(n ast.Node) string {
5768+ switch t := n.(type) {
5769+ case *ast.InterfaceType:
5770+ return "interface{}"
5771+ case *ast.Ident:
5772+ return t.Name
5773+ case *ast.SelectorExpr:
5774+ return t.Sel.Name
5775+ case *ast.StarExpr:
5776+ return "*" + name(t.X)
5777+ default:
5778+ return "<unknown>"
5779+ }
5780+ }
5781+
5782+ // fieldToType returns the type name and whether if it's an ellipsis.
5783+ func fieldToType(f *ast.Field) (string, bool) {
5784+ switch arg := f.Type.(type) {
5785+ case *ast.ArrayType:
5786+ return "[]" + name(arg.Elt), false
5787+ case *ast.Ellipsis:
5788+ return name(arg.Elt), true
5789+ case *ast.FuncType:
5790+ // Do not print the function signature to not overload the trace.
5791+ return "func", false
5792+ case *ast.Ident:
5793+ return arg.Name, false
5794+ case *ast.InterfaceType:
5795+ return "interface{}", false
5796+ case *ast.SelectorExpr:
5797+ return arg.Sel.Name, false
5798+ case *ast.StarExpr:
5799+ return "*" + name(arg.X), false
5800+ case *ast.MapType:
5801+ return fmt.Sprintf("map[%s]%s", name(arg.Key), name(arg.Value)), false
5802+ case *ast.ChanType:
5803+ return fmt.Sprintf("chan %s", name(arg.Value)), false
5804+ default:
5805+ // TODO(maruel): Implement anything missing.
5806+ return "<unknown>", false
5807+ }
5808+ }
5809+
5810+ // extractArgumentsType returns the name of the type of each input argument.
5811+ func extractArgumentsType(f *ast.FuncDecl) ([]string, bool) {
5812+ var fields []*ast.Field
5813+ if f.Recv != nil {
5814+ if len(f.Recv.List) != 1 {
5815+ panic("Expect only one receiver; please fix panicparse's code")
5816+ }
5817+ // If it is an object receiver (vs a pointer receiver), its address is not
5818+ // printed in the stack trace so it needs to be ignored.
5819+ if _, ok := f.Recv.List[0].Type.(*ast.StarExpr); ok {
5820+ fields = append(fields, f.Recv.List[0])
5821+ }
5822+ }
5823+ var types []string
5824+ extra := false
5825+ for _, arg := range append(fields, f.Type.Params.List...) {
5826+ // Assert that extra is only set on the last item of fields?
5827+ var t string
5828+ t, extra = fieldToType(arg)
5829+ mult := len(arg.Names)
5830+ if mult == 0 {
5831+ mult = 1
5832+ }
5833+ for i := 0; i < mult; i++ {
5834+ types = append(types, t)
5835+ }
5836+ }
5837+ return types, extra
5838+ }
5839+
5840+ // processCall walks the function and populate call accordingly.
5841+ func processCall(call *Call, f *ast.FuncDecl) {
5842+ values := make([]uint64, len(call.Args.Values))
5843+ for i := range call.Args.Values {
5844+ values[i] = call.Args.Values[i].Value
5845+ }
5846+ index := 0
5847+ pop := func() uint64 {
5848+ if len(values) != 0 {
5849+ x := values[0]
5850+ values = values[1:]
5851+ index++
5852+ return x
5853+ }
5854+ return 0
5855+ }
5856+ popName := func() string {
5857+ n := call.Args.Values[index].Name
5858+ v := pop()
5859+ if len(n) == 0 {
5860+ return fmt.Sprintf("0x%x", v)
5861+ }
5862+ return n
5863+ }
5864+
5865+ types, extra := extractArgumentsType(f)
5866+ for i := 0; len(values) != 0; i++ {
5867+ var t string
5868+ if i >= len(types) {
5869+ if !extra {
5870+ // These are unexpected value! Print them as hex.
5871+ call.Args.Processed = append(call.Args.Processed, popName())
5872+ continue
5873+ }
5874+ t = types[len(types)-1]
5875+ } else {
5876+ t = types[i]
5877+ }
5878+ switch t {
5879+ case "float32":
5880+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%g", math.Float32frombits(uint32(pop()))))
5881+ case "float64":
5882+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%g", math.Float64frombits(pop())))
5883+ case "int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64":
5884+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%d", pop()))
5885+ case "string":
5886+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%s(%s, len=%d)", t, popName(), pop()))
5887+ default:
5888+ if strings.HasPrefix(t, "*") {
5889+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%s(%s)", t, popName()))
5890+ } else if strings.HasPrefix(t, "[]") {
5891+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%s(%s len=%d cap=%d)", t, popName(), pop(), pop()))
5892+ } else {
5893+ // Assumes it's an interface. For now, discard the object value, which
5894+ // is probably not a good idea.
5895+ call.Args.Processed = append(call.Args.Processed, fmt.Sprintf("%s(%s)", t, popName()))
5896+ pop()
5897+ }
5898+ }
5899+ if len(values) == 0 && call.Args.Elided {
5900+ return
5901+ }
5902+ }
5903+ }
5904 diff --git a/vendor/github.com/maruel/panicparse/stack/source_test.go b/vendor/github.com/maruel/panicparse/stack/source_test.go
5905new file mode 100644
5906index 0000000..1c5d194
5907--- /dev/null
5908+++ b/vendor/github.com/maruel/panicparse/stack/source_test.go
5909 @@ -0,0 +1,563 @@
5910+ // Copyright 2015 Marc-Antoine Ruel. All rights reserved.
5911+ // Use of this source code is governed under the Apache License, Version 2.0
5912+ // that can be found in the LICENSE file.
5913+
5914+ package stack
5915+
5916+ import (
5917+ "bytes"
5918+ "fmt"
5919+ "io/ioutil"
5920+ "os"
5921+ "os/exec"
5922+ "path/filepath"
5923+ "strings"
5924+ "testing"
5925+
5926+ "github.com/maruel/ut"
5927+ )
5928+
5929+ func TestAugment(t *testing.T) {
5930+ data := []struct {
5931+ name string
5932+ input string
5933+ expected Stack
5934+ }{
5935+ {
5936+ "Local function doesn't interfere",
5937+ `package main
5938+ func f(s string) {
5939+ a := func(i int) int {
5940+ return 1 + i
5941+ }
5942+ _ = a(3)
5943+ panic("ooh")
5944+ }
5945+ func main() {
5946+ f("yo")
5947+ }`,
5948+ Stack{
5949+ Calls: []Call{
5950+ {
5951+ SourcePath: "main.go", Line: 7, Func: Function{"main.f"},
5952+ Args: Args{
5953+ Values: []Arg{{Value: pointer, Name: ""}, {Value: 0x2}},
5954+ },
5955+ },
5956+ {SourcePath: "main.go", Line: 10, Func: Function{"main.main"}},
5957+ },
5958+ },
5959+ },
5960+ {
5961+ "func",
5962+ `package main
5963+ func f(a func() string) {
5964+ panic(a())
5965+ }
5966+ func main() {
5967+ f(func() string { return "ooh" })
5968+ }`,
5969+ Stack{
5970+ Calls: []Call{
5971+ {
5972+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
5973+ Args: Args{Values: []Arg{{Value: pointer}}},
5974+ },
5975+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
5976+ },
5977+ },
5978+ },
5979+ {
5980+ "func ellipsis",
5981+ `package main
5982+ func f(a ...func() string) {
5983+ panic(a[0]())
5984+ }
5985+ func main() {
5986+ f(func() string { return "ooh" })
5987+ }`,
5988+ Stack{
5989+ Calls: []Call{
5990+ {
5991+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
5992+ Args: Args{
5993+ Values: []Arg{{Value: pointer}, {Value: 0x1}, {Value: 0x1}},
5994+ },
5995+ },
5996+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
5997+ },
5998+ },
5999+ },
6000+ {
6001+ "interface{}",
6002+ `package main
6003+ func f(a []interface{}) {
6004+ panic("ooh")
6005+ }
6006+ func main() {
6007+ f(make([]interface{}, 5, 7))
6008+ }`,
6009+ Stack{
6010+ Calls: []Call{
6011+ {
6012+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6013+ Args: Args{
6014+ Values: []Arg{{Value: pointer}, {Value: 0x5}, {Value: 0x7}},
6015+ },
6016+ },
6017+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6018+ },
6019+ },
6020+ },
6021+ {
6022+ "[]int",
6023+ `package main
6024+ func f(a []int) {
6025+ panic("ooh")
6026+ }
6027+ func main() {
6028+ f(make([]int, 5, 7))
6029+ }`,
6030+ Stack{
6031+ Calls: []Call{
6032+ {
6033+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6034+ Args: Args{
6035+ Values: []Arg{{Value: pointer}, {Value: 5}, {Value: 7}},
6036+ },
6037+ },
6038+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6039+ },
6040+ },
6041+ },
6042+ {
6043+ "[]interface{}",
6044+ `package main
6045+ func f(a []interface{}) {
6046+ panic(a[0].(string))
6047+ }
6048+ func main() {
6049+ f([]interface{}{"ooh"})
6050+ }`,
6051+ Stack{
6052+ Calls: []Call{
6053+ {
6054+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6055+ Args: Args{
6056+ Values: []Arg{{Value: pointer}, {Value: 1}, {Value: 1}},
6057+ },
6058+ },
6059+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6060+ },
6061+ },
6062+ },
6063+ {
6064+ "map[int]int",
6065+ `package main
6066+ func f(a map[int]int) {
6067+ panic("ooh")
6068+ }
6069+ func main() {
6070+ f(map[int]int{1: 2})
6071+ }`,
6072+ Stack{
6073+ Calls: []Call{
6074+ {
6075+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6076+ Args: Args{
6077+ Values: []Arg{{Value: pointer}},
6078+ },
6079+ },
6080+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6081+ },
6082+ },
6083+ },
6084+ {
6085+ "map[interface{}]interface{}",
6086+ `package main
6087+ func f(a map[interface{}]interface{}) {
6088+ panic("ooh")
6089+ }
6090+ func main() {
6091+ f(make(map[interface{}]interface{}))
6092+ }`,
6093+ Stack{
6094+ Calls: []Call{
6095+ {
6096+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6097+ Args: Args{
6098+ Values: []Arg{{Value: pointer}},
6099+ },
6100+ },
6101+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6102+ },
6103+ },
6104+ },
6105+ {
6106+ "chan int",
6107+ `package main
6108+ func f(a chan int) {
6109+ panic("ooh")
6110+ }
6111+ func main() {
6112+ f(make(chan int))
6113+ }`,
6114+ Stack{
6115+ Calls: []Call{
6116+ {
6117+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6118+ Args: Args{
6119+ Values: []Arg{{Value: pointer}},
6120+ },
6121+ },
6122+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6123+ },
6124+ },
6125+ },
6126+ {
6127+ "chan interface{}",
6128+ `package main
6129+ func f(a chan interface{}) {
6130+ panic("ooh")
6131+ }
6132+ func main() {
6133+ f(make(chan interface{}))
6134+ }`,
6135+ Stack{
6136+ Calls: []Call{
6137+ {
6138+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6139+ Args: Args{
6140+ Values: []Arg{{Value: pointer}},
6141+ },
6142+ },
6143+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6144+ },
6145+ },
6146+ },
6147+ {
6148+ "non-pointer method",
6149+ `package main
6150+ type S struct {
6151+ }
6152+ func (s S) f() {
6153+ panic("ooh")
6154+ }
6155+ func main() {
6156+ var s S
6157+ s.f()
6158+ }`,
6159+ Stack{
6160+ Calls: []Call{
6161+ {SourcePath: "main.go", Line: 5, Func: Function{Raw: "main.S.f"}},
6162+ {SourcePath: "main.go", Line: 9, Func: Function{Raw: "main.main"}},
6163+ },
6164+ },
6165+ },
6166+ {
6167+ "pointer method",
6168+ `package main
6169+ type S struct {
6170+ }
6171+ func (s *S) f() {
6172+ panic("ooh")
6173+ }
6174+ func main() {
6175+ var s S
6176+ s.f()
6177+ }`,
6178+ Stack{
6179+ Calls: []Call{
6180+ {
6181+ SourcePath: "main.go", Line: 5, Func: Function{Raw: "main.(*S).f"},
6182+ Args: Args{Values: []Arg{{Value: pointer}}},
6183+ },
6184+ {SourcePath: "main.go", Line: 9, Func: Function{Raw: "main.main"}},
6185+ },
6186+ },
6187+ },
6188+ {
6189+ "string",
6190+ `package main
6191+ func f(s string) {
6192+ panic(s)
6193+ }
6194+ func main() {
6195+ f("ooh")
6196+ }`,
6197+ Stack{
6198+ Calls: []Call{
6199+ {
6200+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6201+ Args: Args{Values: []Arg{{Value: pointer}, {Value: 0x3}}},
6202+ },
6203+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6204+ },
6205+ },
6206+ },
6207+ {
6208+ "string and int",
6209+ `package main
6210+ func f(s string, i int) {
6211+ panic(s)
6212+ }
6213+ func main() {
6214+ f("ooh", 42)
6215+ }`,
6216+ Stack{
6217+ Calls: []Call{
6218+ {
6219+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6220+ Args: Args{Values: []Arg{{Value: pointer}, {Value: 0x3}, {Value: 42}}},
6221+ },
6222+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6223+ },
6224+ },
6225+ },
6226+ {
6227+ "values are elided",
6228+ `package main
6229+ func f(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12 int, s13 interface{}) {
6230+ panic("ooh")
6231+ }
6232+ func main() {
6233+ f(0, 0, 0, 0, 0, 0, 0, 0, 42, 43, 44, 45, nil)
6234+ }`,
6235+ Stack{
6236+ Calls: []Call{
6237+ {
6238+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6239+ Args: Args{
6240+ Values: []Arg{{}, {}, {}, {}, {}, {}, {}, {}, {Value: 42}, {Value: 43}},
6241+ Elided: true,
6242+ },
6243+ },
6244+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6245+ },
6246+ },
6247+ },
6248+ {
6249+ "error",
6250+ `package main
6251+ import "errors"
6252+ func f(err error) {
6253+ panic(err.Error())
6254+ }
6255+ func main() {
6256+ f(errors.New("ooh"))
6257+ }`,
6258+ Stack{
6259+ Calls: []Call{
6260+ {
6261+ SourcePath: "main.go", Line: 4, Func: Function{Raw: "main.f"},
6262+ Args: Args{
6263+ Values: []Arg{{Value: pointer}, {Value: pointer}},
6264+ },
6265+ },
6266+ {SourcePath: "main.go", Line: 7, Func: Function{Raw: "main.main"}},
6267+ },
6268+ },
6269+ },
6270+ {
6271+ "error unnamed",
6272+ `package main
6273+ import "errors"
6274+ func f(error) {
6275+ panic("ooh")
6276+ }
6277+ func main() {
6278+ f(errors.New("ooh"))
6279+ }`,
6280+ Stack{
6281+ Calls: []Call{
6282+ {
6283+ SourcePath: "main.go", Line: 4, Func: Function{Raw: "main.f"},
6284+ Args: Args{
6285+ Values: []Arg{{Value: pointer}, {Value: pointer}},
6286+ },
6287+ },
6288+ {SourcePath: "main.go", Line: 7, Func: Function{Raw: "main.main"}},
6289+ },
6290+ },
6291+ },
6292+ {
6293+ "float32",
6294+ `package main
6295+ func f(v float32) {
6296+ panic("ooh")
6297+ }
6298+ func main() {
6299+ f(0.5)
6300+ }`,
6301+ Stack{
6302+ Calls: []Call{
6303+ {
6304+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6305+ Args: Args{
6306+ // The value is NOT a pointer but floating point encoding is not
6307+ // deterministic.
6308+ Values: []Arg{{Value: pointer}},
6309+ },
6310+ },
6311+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6312+ },
6313+ },
6314+ },
6315+ {
6316+ "float64",
6317+ `package main
6318+ func f(v float64) {
6319+ panic("ooh")
6320+ }
6321+ func main() {
6322+ f(0.5)
6323+ }`,
6324+ Stack{
6325+ Calls: []Call{
6326+ {
6327+ SourcePath: "main.go", Line: 3, Func: Function{Raw: "main.f"},
6328+ Args: Args{
6329+ // The value is NOT a pointer but floating point encoding is not
6330+ // deterministic.
6331+ Values: []Arg{{Value: pointer}},
6332+ },
6333+ },
6334+ {SourcePath: "main.go", Line: 6, Func: Function{Raw: "main.main"}},
6335+ },
6336+ },
6337+ },
6338+ }
6339+
6340+ for i, line := range data {
6341+ extra := bytes.Buffer{}
6342+ _, content := getCrash(t, line.input)
6343+ goroutines, err := ParseDump(bytes.NewBuffer(content), &extra)
6344+ if err != nil {
6345+ t.Fatalf("failed to parse input for test %s: %v", line.name, err)
6346+ }
6347+ // On go1.4, there's one less space.
6348+ actual := extra.String()
6349+ if actual != "panic: ooh\n\nexit status 2\n" && actual != "panic: ooh\nexit status 2\n" {
6350+ t.Fatalf("Unexpected panic output:\n%#v", actual)
6351+ }
6352+ s := goroutines[0].Signature.Stack
6353+ t.Logf("Test: %v", line.name)
6354+ zapPointers(t, line.name, &line.expected, &s)
6355+ zapPaths(&s)
6356+ ut.AssertEqualIndex(t, i, line.expected, s)
6357+ }
6358+ }
6359+
6360+ func TestAugmentDummy(t *testing.T) {
6361+ goroutines := []Goroutine{
6362+ {
6363+ Signature: Signature{
6364+ Stack: Stack{
6365+ Calls: []Call{{SourcePath: "missing.go"}},
6366+ },
6367+ },
6368+ },
6369+ }
6370+ Augment(goroutines)
6371+ }
6372+
6373+ func TestLoad(t *testing.T) {
6374+ c := &cache{
6375+ files: map[string][]byte{"bad.go": []byte("bad content")},
6376+ parsed: map[string]*parsedFile{},
6377+ }
6378+ c.load("foo.asm")
6379+ c.load("bad.go")
6380+ c.load("doesnt_exist.go")
6381+ if l := len(c.parsed); l != 3 {
6382+ t.Fatalf("expected 3, got %d", l)
6383+ }
6384+ if c.parsed["foo.asm"] != nil {
6385+ t.Fatalf("foo.asm is not present; should not have been loaded")
6386+ }
6387+ if c.parsed["bad.go"] != nil {
6388+ t.Fatalf("bad.go is not valid code; should not have been loaded")
6389+ }
6390+ if c.parsed["doesnt_exist.go"] != nil {
6391+ t.Fatalf("doesnt_exist.go is not present; should not have been loaded")
6392+ }
6393+ if c.getFuncAST(&Call{SourcePath: "other"}) != nil {
6394+ t.Fatalf("there's no 'other'")
6395+ }
6396+ }
6397+
6398+ //
6399+
6400+ const pointer = uint64(0xfffffffff)
6401+ const pointerStr = "0xfffffffff"
6402+
6403+ func overrideEnv(env []string, key, value string) []string {
6404+ prefix := key + "="
6405+ for i, e := range env {
6406+ if strings.HasPrefix(e, prefix) {
6407+ env[i] = prefix + value
6408+ return env
6409+ }
6410+ }
6411+ return append(env, prefix+value)
6412+ }
6413+
6414+ func getCrash(t *testing.T, content string) (string, []byte) {
6415+ name, err := ioutil.TempDir("", "panicparse")
6416+ if err != nil {
6417+ t.Fatalf("failed to create temporary directory: %v", err)
6418+ }
6419+ defer func() {
6420+ if err := os.RemoveAll(name); err != nil {
6421+ t.Fatalf("failed to remove temporary directory %q: %v", name, err)
6422+ }
6423+ }()
6424+ main := filepath.Join(name, "main.go")
6425+ if err := ioutil.WriteFile(main, []byte(content), 0500); err != nil {
6426+ t.Fatalf("failed to write %q: %v", main, err)
6427+ }
6428+ cmd := exec.Command("go", "run", main)
6429+ // Use the Go 1.4 compatible format.
6430+ cmd.Env = overrideEnv(os.Environ(), "GOTRACEBACK", "1")
6431+ out, err := cmd.CombinedOutput()
6432+ if err == nil {
6433+ t.Fatal("expected error since this is supposed to crash")
6434+ }
6435+ return main, out
6436+ }
6437+
6438+ // zapPointers zaps out pointers.
6439+ func zapPointers(t *testing.T, name string, expected, s *Stack) {
6440+ for i := range s.Calls {
6441+ if i >= len(expected.Calls) {
6442+ // When using GOTRACEBACK=2, it'll include runtime.main() and
6443+ // runtime.goexit(). Ignore these since they could be changed in a future
6444+ // version.
6445+ s.Calls = s.Calls[:len(expected.Calls)]
6446+ break
6447+ }
6448+ for j := range s.Calls[i].Args.Values {
6449+ if j >= len(expected.Calls[i].Args.Values) {
6450+ break
6451+ }
6452+ if expected.Calls[i].Args.Values[j].Value == pointer {
6453+ // Replace the pointer value.
6454+ if s.Calls[i].Args.Values[j].Value == 0 {
6455+ t.Fatalf("%s: Call %d, value %d, expected pointer, got 0", name, i, j)
6456+ }
6457+ old := fmt.Sprintf("0x%x", s.Calls[i].Args.Values[j].Value)
6458+ s.Calls[i].Args.Values[j].Value = pointer
6459+ for k := range s.Calls[i].Args.Processed {
6460+ s.Calls[i].Args.Processed[k] = strings.Replace(s.Calls[i].Args.Processed[k], old, pointerStr, -1)
6461+ }
6462+ }
6463+ }
6464+ }
6465+ }
6466+
6467+ // zapPaths removes the directory part and only keep the base file name.
6468+ func zapPaths(s *Stack) {
6469+ for j := range s.Calls {
6470+ s.Calls[j].SourcePath = filepath.Base(s.Calls[j].SourcePath)
6471+ }
6472+ }
6473 diff --git a/vendor/github.com/maruel/panicparse/stack/stack.go b/vendor/github.com/maruel/panicparse/stack/stack.go
6474new file mode 100644
6475index 0000000..a9917ed
6476--- /dev/null
6477+++ b/vendor/github.com/maruel/panicparse/stack/stack.go
6478 @@ -0,0 +1,832 @@
6479+ // Copyright 2015 Marc-Antoine Ruel. All rights reserved.
6480+ // Use of this source code is governed under the Apache License, Version 2.0
6481+ // that can be found in the LICENSE file.
6482+
6483+ // Package stack analyzes stack dump of Go processes and simplifies it.
6484+ //
6485+ // It is mostly useful on servers will large number of identical goroutines,
6486+ // making the crash dump harder to read than strictly necesary.
6487+ package stack
6488+
6489+ import (
6490+ "bufio"
6491+ "bytes"
6492+ "errors"
6493+ "fmt"
6494+ "io"
6495+ "math"
6496+ "net/url"
6497+ "os"
6498+ "path/filepath"
6499+ "regexp"
6500+ "runtime"
6501+ "sort"
6502+ "strconv"
6503+ "strings"
6504+ "unicode"
6505+ "unicode/utf8"
6506+ )
6507+
6508+ const lockedToThread = "locked to thread"
6509+
6510+ var (
6511+ // TODO(maruel): Handle corrupted stack cases:
6512+ // - missed stack barrier
6513+ // - found next stack barrier at 0x123; expected
6514+ // - runtime: unexpected return pc for FUNC_NAME called from 0x123
6515+
6516+ reRoutineHeader = regexp.MustCompile("^goroutine (\\d+) \\[([^\\]]+)\\]\\:\r?\n$")
6517+ reMinutes = regexp.MustCompile("^(\\d+) minutes$")
6518+ reUnavail = regexp.MustCompile("^(?:\t| +)goroutine running on other thread; stack unavailable")
6519+ // See gentraceback() in src/runtime/traceback.go for more information.
6520+ // - Sometimes the source file comes up as "<autogenerated>". It is the
6521+ // compiler than generated these, not the runtime.
6522+ // - The tab may be replaced with spaces when a user copy-paste it, handle
6523+ // this transparently.
6524+ // - "runtime.gopanic" is explicitly replaced with "panic" by gentraceback().
6525+ // - The +0x123 byte offset is printed when frame.pc > _func.entry. _func is
6526+ // generated by the linker.
6527+ // - The +0x123 byte offset is not included with generated code, e.g. unnamed
6528+ // functions "func·006()" which is generally go func() { ... }()
6529+ // statements. Since the _func is generated at runtime, it's probably why
6530+ // _func.entry is not set.
6531+ // - C calls may have fp=0x123 sp=0x123 appended. I think it normally happens
6532+ // when a signal is not correctly handled. It is printed with m.throwing>0.
6533+ // These are discarded.
6534+ // - For cgo, the source file may be "??".
6535+ reFile = regexp.MustCompile("^(?:\t| +)(\\?\\?|\\<autogenerated\\>|.+\\.(?:c|go|s))\\:(\\d+)(?:| \\+0x[0-9a-f]+)(?:| fp=0x[0-9a-f]+ sp=0x[0-9a-f]+)\r?\n$")
6536+ // Sadly, it doesn't note the goroutine number so we could cascade them per
6537+ // parenthood.
6538+ reCreated = regexp.MustCompile("^created by (.+)\r?\n$")
6539+ reFunc = regexp.MustCompile("^(.+)\\((.*)\\)\r?\n$")
6540+ reElided = regexp.MustCompile("^\\.\\.\\.additional frames elided\\.\\.\\.\r?\n$")
6541+ // Include frequent GOROOT value on Windows, distro provided and user
6542+ // installed path. This simplifies the user's life when processing a trace
6543+ // generated on another VM.
6544+ // TODO(maruel): Guess the path automatically via traces containing the
6545+ // 'runtime' package, which is very frequent. This would be "less bad" than
6546+ // throwing up random values at the parser.
6547+ goroots = []string{runtime.GOROOT(), "c:/go", "/usr/lib/go", "/usr/local/go"}
6548+ )
6549+
6550+ // Similarity is the level at which two call lines arguments must match to be
6551+ // considered similar enough to coalesce them.
6552+ type Similarity int
6553+
6554+ const (
6555+ // ExactFlags requires same bits (e.g. Locked).
6556+ ExactFlags Similarity = iota
6557+ // ExactLines requests the exact same arguments on the call line.
6558+ ExactLines
6559+ // AnyPointer considers different pointers a similar call line.
6560+ AnyPointer
6561+ // AnyValue accepts any value as similar call line.
6562+ AnyValue
6563+ )
6564+
6565+ // Function is a function call.
6566+ //
6567+ // Go stack traces print a mangled function call, this wrapper unmangle the
6568+ // string before printing and adds other filtering methods.
6569+ type Function struct {
6570+ Raw string
6571+ }
6572+
6573+ // String is the fully qualified function name.
6574+ //
6575+ // Sadly Go is a bit confused when the package name doesn't match the directory
6576+ // containing the source file and will use the directory name instead of the
6577+ // real package name.
6578+ func (f Function) String() string {
6579+ s, _ := url.QueryUnescape(f.Raw)
6580+ return s
6581+ }
6582+
6583+ // Name is the naked function name.
6584+ func (f Function) Name() string {
6585+ parts := strings.SplitN(filepath.Base(f.Raw), ".", 2)
6586+ if len(parts) == 1 {
6587+ return parts[0]
6588+ }
6589+ return parts[1]
6590+ }
6591+
6592+ // PkgName is the package name for this function reference.
6593+ func (f Function) PkgName() string {
6594+ parts := strings.SplitN(filepath.Base(f.Raw), ".", 2)
6595+ if len(parts) == 1 {
6596+ return ""
6597+ }
6598+ s, _ := url.QueryUnescape(parts[0])
6599+ return s
6600+ }
6601+
6602+ // PkgDotName returns "<package>.<func>" format.
6603+ func (f Function) PkgDotName() string {
6604+ parts := strings.SplitN(filepath.Base(f.Raw), ".", 2)
6605+ s, _ := url.QueryUnescape(parts[0])
6606+ if len(parts) == 1 {
6607+ return parts[0]
6608+ }
6609+ if s != "" || parts[1] != "" {
6610+ return s + "." + parts[1]
6611+ }
6612+ return ""
6613+ }
6614+
6615+ // IsExported returns true if the function is exported.
6616+ func (f Function) IsExported() bool {
6617+ name := f.Name()
6618+ parts := strings.Split(name, ".")
6619+ r, _ := utf8.DecodeRuneInString(parts[len(parts)-1])
6620+ if unicode.ToUpper(r) == r {
6621+ return true
6622+ }
6623+ return f.PkgName() == "main" && name == "main"
6624+ }
6625+
6626+ // Arg is an argument on a Call.
6627+ type Arg struct {
6628+ Value uint64 // Value is the raw value as found in the stack trace
6629+ Name string // Name is a pseudo name given to the argument
6630+ }
6631+
6632+ // IsPtr returns true if we guess it's a pointer. It's only a guess, it can be
6633+ // easily be confused by a bitmask.
6634+ func (a *Arg) IsPtr() bool {
6635+ // Assumes all pointers are above 16Mb and positive.
6636+ return a.Value > 16*1024*1024 && a.Value < math.MaxInt64
6637+ }
6638+
6639+ func (a Arg) String() string {
6640+ if a.Name != "" {
6641+ return a.Name
6642+ }
6643+ if a.Value == 0 {
6644+ return "0"
6645+ }
6646+ return fmt.Sprintf("0x%x", a.Value)
6647+ }
6648+
6649+ // Args is a series of function call arguments.
6650+ type Args struct {
6651+ Values []Arg // Values is the arguments as shown on the stack trace. They are mangled via simplification.
6652+ Processed []string // Processed is the arguments generated from processing the source files. It can have a length lower than Values.
6653+ Elided bool // If set, it means there was a trailing ", ..."
6654+ }
6655+
6656+ func (a Args) String() string {
6657+ var v []string
6658+ if len(a.Processed) != 0 {
6659+ v = make([]string, 0, len(a.Processed))
6660+ for _, item := range a.Processed {
6661+ v = append(v, item)
6662+ }
6663+ } else {
6664+ v = make([]string, 0, len(a.Values))
6665+ for _, item := range a.Values {
6666+ v = append(v, item.String())
6667+ }
6668+ }
6669+ if a.Elided {
6670+ v = append(v, "...")
6671+ }
6672+ return strings.Join(v, ", ")
6673+ }
6674+
6675+ // Equal returns true only if both arguments are exactly equal.
6676+ func (a *Args) Equal(r *Args) bool {
6677+ if a.Elided != r.Elided || len(a.Values) != len(r.Values) {
6678+ return false
6679+ }
6680+ for i, l := range a.Values {
6681+ if l != r.Values[i] {
6682+ return false
6683+ }
6684+ }
6685+ return true
6686+ }
6687+
6688+ // Similar returns true if the two Args are equal or almost but not quite
6689+ // equal.
6690+ func (a *Args) Similar(r *Args, similar Similarity) bool {
6691+ if a.Elided != r.Elided || len(a.Values) != len(r.Values) {
6692+ return false
6693+ }
6694+ if similar == AnyValue {
6695+ return true
6696+ }
6697+ for i, l := range a.Values {
6698+ switch similar {
6699+ case ExactFlags, ExactLines:
6700+ if l != r.Values[i] {
6701+ return false
6702+ }
6703+ default:
6704+ if l.IsPtr() != r.Values[i].IsPtr() || (!l.IsPtr() && l != r.Values[i]) {
6705+ return false
6706+ }
6707+ }
6708+ }
6709+ return true
6710+ }
6711+
6712+ // Merge merges two similar Args, zapping out differences.
6713+ func (a *Args) Merge(r *Args) Args {
6714+ out := Args{
6715+ Values: make([]Arg, len(a.Values)),
6716+ Elided: a.Elided,
6717+ }
6718+ for i, l := range a.Values {
6719+ if l != r.Values[i] {
6720+ out.Values[i].Name = "*"
6721+ out.Values[i].Value = l.Value
6722+ } else {
6723+ out.Values[i] = l
6724+ }
6725+ }
6726+ return out
6727+ }
6728+
6729+ // Call is an item in the stack trace.
6730+ type Call struct {
6731+ SourcePath string // Full path name of the source file
6732+ Line int // Line number
6733+ Func Function // Fully qualified function name (encoded).
6734+ Args Args // Call arguments
6735+ }
6736+
6737+ // Equal returns true only if both calls are exactly equal.
6738+ func (c *Call) Equal(r *Call) bool {
6739+ return c.SourcePath == r.SourcePath && c.Line == r.Line && c.Func == r.Func && c.Args.Equal(&r.Args)
6740+ }
6741+
6742+ // Similar returns true if the two Call are equal or almost but not quite
6743+ // equal.
6744+ func (c *Call) Similar(r *Call, similar Similarity) bool {
6745+ return c.SourcePath == r.SourcePath && c.Line == r.Line && c.Func == r.Func && c.Args.Similar(&r.Args, similar)
6746+ }
6747+
6748+ // Merge merges two similar Call, zapping out differences.
6749+ func (c *Call) Merge(r *Call) Call {
6750+ return Call{
6751+ SourcePath: c.SourcePath,
6752+ Line: c.Line,
6753+ Func: c.Func,
6754+ Args: c.Args.Merge(&r.Args),
6755+ }
6756+ }
6757+
6758+ // SourceName returns the base file name of the source file.
6759+ func (c *Call) SourceName() string {
6760+ return filepath.Base(c.SourcePath)
6761+ }
6762+
6763+ // SourceLine returns "source.go:line", including only the base file name.
6764+ func (c *Call) SourceLine() string {
6765+ return fmt.Sprintf("%s:%d", c.SourceName(), c.Line)
6766+ }
6767+
6768+ // FullSourceLine returns "/path/to/source.go:line".
6769+ func (c *Call) FullSourceLine() string {
6770+ return fmt.Sprintf("%s:%d", c.SourcePath, c.Line)
6771+ }
6772+
6773+ // PkgSource is one directory plus the file name of the source file.
6774+ func (c *Call) PkgSource() string {
6775+ return filepath.Join(filepath.Base(filepath.Dir(c.SourcePath)), c.SourceName())
6776+ }
6777+
6778+ const testMainSource = "_test" + string(os.PathSeparator) + "_testmain.go"
6779+
6780+ // IsStdlib returns true if it is a Go standard library function. This includes
6781+ // the 'go test' generated main executable.
6782+ func (c *Call) IsStdlib() bool {
6783+ for _, goroot := range goroots {
6784+ if strings.HasPrefix(c.SourcePath, goroot) {
6785+ return true
6786+ }
6787+ }
6788+ // Consider _test/_testmain.go as stdlib since it's injected by "go test".
6789+ return c.PkgSource() == testMainSource
6790+ }
6791+
6792+ // IsPkgMain returns true if it is in the main package.
6793+ func (c *Call) IsPkgMain() bool {
6794+ return c.Func.PkgName() == "main"
6795+ }
6796+
6797+ // Stack is a call stack.
6798+ type Stack struct {
6799+ Calls []Call // Call stack. First is original function, last is leaf function.
6800+ Elided bool // Happens when there's >100 items in Stack, currently hardcoded in package runtime.
6801+ }
6802+
6803+ // Equal returns true on if both call stacks are exactly equal.
6804+ func (s *Stack) Equal(r *Stack) bool {
6805+ if len(s.Calls) != len(r.Calls) || s.Elided != r.Elided {
6806+ return false
6807+ }
6808+ for i := range s.Calls {
6809+ if !s.Calls[i].Equal(&r.Calls[i]) {
6810+ return false
6811+ }
6812+ }
6813+ return true
6814+ }
6815+
6816+ // Similar returns true if the two Stack are equal or almost but not quite
6817+ // equal.
6818+ func (s *Stack) Similar(r *Stack, similar Similarity) bool {
6819+ if len(s.Calls) != len(r.Calls) || s.Elided != r.Elided {
6820+ return false
6821+ }
6822+ for i := range s.Calls {
6823+ if !s.Calls[i].Similar(&r.Calls[i], similar) {
6824+ return false
6825+ }
6826+ }
6827+ return true
6828+ }
6829+
6830+ // Merge merges two similar Stack, zapping out differences.
6831+ func (s *Stack) Merge(r *Stack) *Stack {
6832+ // Assumes similar stacks have the same length.
6833+ out := &Stack{
6834+ Calls: make([]Call, len(s.Calls)),
6835+ Elided: s.Elided,
6836+ }
6837+ for i := range s.Calls {
6838+ out.Calls[i] = s.Calls[i].Merge(&r.Calls[i])
6839+ }
6840+ return out
6841+ }
6842+
6843+ // Less compares two Stack, where the ones that are less are more
6844+ // important, so they come up front. A Stack with more private functions is
6845+ // 'less' so it is at the top. Inversely, a Stack with only public
6846+ // functions is 'more' so it is at the bottom.
6847+ func (s *Stack) Less(r *Stack) bool {
6848+ lStdlib := 0
6849+ lPrivate := 0
6850+ for _, c := range s.Calls {
6851+ if c.IsStdlib() {
6852+ lStdlib++
6853+ } else {
6854+ lPrivate++
6855+ }
6856+ }
6857+ rStdlib := 0
6858+ rPrivate := 0
6859+ for _, s := range r.Calls {
6860+ if s.IsStdlib() {
6861+ rStdlib++
6862+ } else {
6863+ rPrivate++
6864+ }
6865+ }
6866+ if lPrivate > rPrivate {
6867+ return true
6868+ }
6869+ if lPrivate < rPrivate {
6870+ return false
6871+ }
6872+ if lStdlib > rStdlib {
6873+ return false
6874+ }
6875+ if lStdlib < rStdlib {
6876+ return true
6877+ }
6878+
6879+ // Stack lengths are the same.
6880+ for x := range s.Calls {
6881+ if s.Calls[x].Func.Raw < r.Calls[x].Func.Raw {
6882+ return true
6883+ }
6884+ if s.Calls[x].Func.Raw > r.Calls[x].Func.Raw {
6885+ return true
6886+ }
6887+ if s.Calls[x].PkgSource() < r.Calls[x].PkgSource() {
6888+ return true
6889+ }
6890+ if s.Calls[x].PkgSource() > r.Calls[x].PkgSource() {
6891+ return true
6892+ }
6893+ if s.Calls[x].Line < r.Calls[x].Line {
6894+ return true
6895+ }
6896+ if s.Calls[x].Line > r.Calls[x].Line {
6897+ return true
6898+ }
6899+ }
6900+ return false
6901+ }
6902+
6903+ // Signature represents the signature of one or multiple goroutines.
6904+ //
6905+ // It is effectively the stack trace plus the goroutine internal bits, like
6906+ // it's state, if it is thread locked, which call site created this goroutine,
6907+ // etc.
6908+ type Signature struct {
6909+ // Use git grep 'gopark(|unlock)\(' to find them all plus everything listed
6910+ // in runtime/traceback.go. Valid values includes:
6911+ // - chan send, chan receive, select
6912+ // - finalizer wait, mark wait (idle),
6913+ // - Concurrent GC wait, GC sweep wait, force gc (idle)
6914+ // - IO wait, panicwait
6915+ // - semacquire, semarelease
6916+ // - sleep, timer goroutine (idle)
6917+ // - trace reader (blocked)
6918+ // Stuck cases:
6919+ // - chan send (nil chan), chan receive (nil chan), select (no cases)
6920+ // Runnable states:
6921+ // - idle, runnable, running, syscall, waiting, dead, enqueue, copystack,
6922+ // Scan states:
6923+ // - scan, scanrunnable, scanrunning, scansyscall, scanwaiting, scandead,
6924+ // scanenqueue
6925+ State string
6926+ CreatedBy Call // Which other goroutine which created this one.
6927+ SleepMin int // Wait time in minutes, if applicable.
6928+ SleepMax int // Wait time in minutes, if applicable.
6929+ Stack Stack
6930+ Locked bool // Locked to an OS thread.
6931+ }
6932+
6933+ // Equal returns true only if both signatures are exactly equal.
6934+ func (s *Signature) Equal(r *Signature) bool {
6935+ if s.State != r.State || !s.CreatedBy.Equal(&r.CreatedBy) || s.Locked != r.Locked || s.SleepMin != r.SleepMin || s.SleepMax != r.SleepMax {
6936+ return false
6937+ }
6938+ return s.Stack.Equal(&r.Stack)
6939+ }
6940+
6941+ // Similar returns true if the two Signature are equal or almost but not quite
6942+ // equal.
6943+ func (s *Signature) Similar(r *Signature, similar Similarity) bool {
6944+ if s.State != r.State || !s.CreatedBy.Similar(&r.CreatedBy, similar) {
6945+ return false
6946+ }
6947+ if similar == ExactFlags && s.Locked != r.Locked {
6948+ return false
6949+ }
6950+ return s.Stack.Similar(&r.Stack, similar)
6951+ }
6952+
6953+ // Merge merges two similar Signature, zapping out differences.
6954+ func (s *Signature) Merge(r *Signature) *Signature {
6955+ min := s.SleepMin
6956+ if r.SleepMin < min {
6957+ min = r.SleepMin
6958+ }
6959+ max := s.SleepMax
6960+ if r.SleepMax > max {
6961+ max = r.SleepMax
6962+ }
6963+ return &Signature{
6964+ State: s.State, // Drop right side.
6965+ CreatedBy: s.CreatedBy, // Drop right side.
6966+ SleepMin: min,
6967+ SleepMax: max,
6968+ Stack: *s.Stack.Merge(&r.Stack),
6969+ Locked: s.Locked || r.Locked, // TODO(maruel): This is weirdo.
6970+ }
6971+ }
6972+
6973+ // Less compares two Signature, where the ones that are less are more
6974+ // important, so they come up front. A Signature with more private functions is
6975+ // 'less' so it is at the top. Inversely, a Signature with only public
6976+ // functions is 'more' so it is at the bottom.
6977+ func (s *Signature) Less(r *Signature) bool {
6978+ if s.Stack.Less(&r.Stack) {
6979+ return true
6980+ }
6981+ if r.Stack.Less(&s.Stack) {
6982+ return false
6983+ }
6984+ if s.Locked && !r.Locked {
6985+ return true
6986+ }
6987+ if r.Locked && !s.Locked {
6988+ return false
6989+ }
6990+ if s.State < r.State {
6991+ return true
6992+ }
6993+ if s.State > r.State {
6994+ return false
6995+ }
6996+ return false
6997+ }
6998+
6999+ // Goroutine represents the state of one goroutine, including the stack trace.
7000+ type Goroutine struct {
7001+ Signature // It's stack trace, internal bits, state, which call site created it, etc.
7002+ ID int // Goroutine ID.
7003+ First bool // First is the goroutine first printed, normally the one that crashed.
7004+ }
7005+
7006+ // Bucketize returns the number of similar goroutines.
7007+ func Bucketize(goroutines []Goroutine, similar Similarity) map[*Signature][]Goroutine {
7008+ out := map[*Signature][]Goroutine{}
7009+ // O(n²). Fix eventually.
7010+ for _, routine := range goroutines {
7011+ found := false
7012+ for key := range out {
7013+ // When a match is found, this effectively drops the other goroutine ID.
7014+ if key.Similar(&routine.Signature, similar) {
7015+ found = true
7016+ if !key.Equal(&routine.Signature) {
7017+ // Almost but not quite equal. There's different pointers passed
7018+ // around but the same values. Zap out the different values.
7019+ newKey := key.Merge(&routine.Signature)
7020+ out[newKey] = append(out[key], routine)
7021+ delete(out, key)
7022+ } else {
7023+ out[key] = append(out[key], routine)
7024+ }
7025+ break
7026+ }
7027+ }
7028+ if !found {
7029+ key := &Signature{}
7030+ *key = routine.Signature
7031+ out[key] = []Goroutine{routine}
7032+ }
7033+ }
7034+ return out
7035+ }
7036+
7037+ // Bucket is a stack trace signature and the list of goroutines that fits this
7038+ // signature.
7039+ type Bucket struct {
7040+ Signature
7041+ Routines []Goroutine
7042+ }
7043+
7044+ // First returns true if it contains the first goroutine, e.g. the ones that
7045+ // likely generated the panic() call, if any.
7046+ func (b *Bucket) First() bool {
7047+ for _, r := range b.Routines {
7048+ if r.First {
7049+ return true
7050+ }
7051+ }
7052+ return false
7053+ }
7054+
7055+ // Less does reverse sort.
7056+ func (b *Bucket) Less(r *Bucket) bool {
7057+ if b.First() {
7058+ return true
7059+ }
7060+ if r.First() {
7061+ return false
7062+ }
7063+ return b.Signature.Less(&r.Signature)
7064+ }
7065+
7066+ // Buckets is a list of Bucket sorted by repeation count.
7067+ type Buckets []Bucket
7068+
7069+ func (b Buckets) Len() int {
7070+ return len(b)
7071+ }
7072+
7073+ func (b Buckets) Less(i, j int) bool {
7074+ return b[i].Less(&b[j])
7075+ }
7076+
7077+ func (b Buckets) Swap(i, j int) {
7078+ b[j], b[i] = b[i], b[j]
7079+ }
7080+
7081+ // SortBuckets creates a list of Bucket from each goroutine stack trace count.
7082+ func SortBuckets(buckets map[*Signature][]Goroutine) Buckets {
7083+ out := make(Buckets, 0, len(buckets))
7084+ for signature, count := range buckets {
7085+ out = append(out, Bucket{*signature, count})
7086+ }
7087+ sort.Sort(out)
7088+ return out
7089+ }
7090+
7091+ // scanLines is similar to bufio.ScanLines except that it:
7092+ // - doesn't drop '\n'
7093+ // - doesn't strip '\r'
7094+ // - returns when the data is bufio.MaxScanTokenSize bytes
7095+ func scanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
7096+ if atEOF && len(data) == 0 {
7097+ return 0, nil, nil
7098+ }
7099+ if i := bytes.IndexByte(data, '\n'); i >= 0 {
7100+ return i + 1, data[0 : i+1], nil
7101+ }
7102+ if atEOF {
7103+ return len(data), data, nil
7104+ }
7105+ if len(data) >= bufio.MaxScanTokenSize {
7106+ // Returns the line even if it is not at EOF nor has a '\n', otherwise the
7107+ // scanner will return bufio.ErrTooLong which is definitely not what we
7108+ // want.
7109+ return len(data), data, nil
7110+ }
7111+ return 0, nil, nil
7112+ }
7113+
7114+ // ParseDump processes the output from runtime.Stack().
7115+ //
7116+ // It supports piping from another command and assumes there is junk before the
7117+ // actual stack trace. The junk is streamed to out.
7118+ func ParseDump(r io.Reader, out io.Writer) ([]Goroutine, error) {
7119+ goroutines := make([]Goroutine, 0, 16)
7120+ var goroutine *Goroutine
7121+ scanner := bufio.NewScanner(r)
7122+ scanner.Split(scanLines)
7123+ // TODO(maruel): Use a formal state machine. Patterns follows:
7124+ // - reRoutineHeader
7125+ // Either:
7126+ // - reUnavail
7127+ // - reFunc + reFile in a loop
7128+ // - reElided
7129+ // Optionally ends with:
7130+ // - reCreated + reFile
7131+ // Between each goroutine stack dump: an empty line
7132+ created := false
7133+ // firstLine is the first line after the reRoutineHeader header line.
7134+ firstLine := false
7135+ for scanner.Scan() {
7136+ line := scanner.Text()
7137+ if line == "\n" || line == "\r\n" {
7138+ if goroutine != nil {
7139+ goroutine = nil
7140+ continue
7141+ }
7142+ } else if line[len(line)-1] == '\n' {
7143+ if goroutine == nil {
7144+ if match := reRoutineHeader.FindStringSubmatch(line); match != nil {
7145+ if id, err := strconv.Atoi(match[1]); err == nil {
7146+ // See runtime/traceback.go.
7147+ // "<state>, \d+ minutes, locked to thread"
7148+ items := strings.Split(match[2], ", ")
7149+ sleep := 0
7150+ locked := false
7151+ for i := 1; i < len(items); i++ {
7152+ if items[i] == lockedToThread {
7153+ locked = true
7154+ continue
7155+ }
7156+ // Look for duration, if any.
7157+ if match2 := reMinutes.FindStringSubmatch(items[i]); match2 != nil {
7158+ sleep, _ = strconv.Atoi(match2[1])
7159+ }
7160+ }
7161+ goroutines = append(goroutines, Goroutine{
7162+ Signature: Signature{
7163+ State: items[0],
7164+ SleepMin: sleep,
7165+ SleepMax: sleep,
7166+ Locked: locked,
7167+ },
7168+ ID: id,
7169+ First: len(goroutines) == 0,
7170+ })
7171+ goroutine = &goroutines[len(goroutines)-1]
7172+ firstLine = true
7173+ continue
7174+ }
7175+ }
7176+ } else {
7177+ if firstLine {
7178+ firstLine = false
7179+ if match := reUnavail.FindStringSubmatch(line); match != nil {
7180+ // Generate a fake stack entry.
7181+ goroutine.Stack.Calls = []Call{{SourcePath: "<unavailable>"}}
7182+ continue
7183+ }
7184+ }
7185+
7186+ if match := reFile.FindStringSubmatch(line); match != nil {
7187+ // Triggers after a reFunc or a reCreated.
7188+ num, err := strconv.Atoi(match[2])
7189+ if err != nil {
7190+ return goroutines, fmt.Errorf("failed to parse int on line: \"%s\"", line)
7191+ }
7192+ if created {
7193+ created = false
7194+ goroutine.CreatedBy.SourcePath = match[1]
7195+ goroutine.CreatedBy.Line = num
7196+ } else {
7197+ i := len(goroutine.Stack.Calls) - 1
7198+ if i < 0 {
7199+ return goroutines, errors.New("unexpected order")
7200+ }
7201+ goroutine.Stack.Calls[i].SourcePath = match[1]
7202+ goroutine.Stack.Calls[i].Line = num
7203+ }
7204+ continue
7205+ }
7206+
7207+ if match := reCreated.FindStringSubmatch(line); match != nil {
7208+ created = true
7209+ goroutine.CreatedBy.Func.Raw = match[1]
7210+ continue
7211+ }
7212+
7213+ if match := reFunc.FindStringSubmatch(line); match != nil {
7214+ args := Args{}
7215+ for _, a := range strings.Split(match[2], ", ") {
7216+ if a == "..." {
7217+ args.Elided = true
7218+ continue
7219+ }
7220+ if a == "" {
7221+ // Remaining values were dropped.
7222+ break
7223+ }
7224+ v, err := strconv.ParseUint(a, 0, 64)
7225+ if err != nil {
7226+ return goroutines, fmt.Errorf("failed to parse int on line: \"%s\"", line)
7227+ }
7228+ args.Values = append(args.Values, Arg{Value: v})
7229+ }
7230+ goroutine.Stack.Calls = append(goroutine.Stack.Calls, Call{Func: Function{match[1]}, Args: args})
7231+ continue
7232+ }
7233+
7234+ if match := reElided.FindStringSubmatch(line); match != nil {
7235+ goroutine.Stack.Elided = true
7236+ continue
7237+ }
7238+ }
7239+ }
7240+ _, _ = io.WriteString(out, line)
7241+ goroutine = nil
7242+ }
7243+ nameArguments(goroutines)
7244+ return goroutines, scanner.Err()
7245+ }
7246+
7247+ // Private stuff.
7248+
7249+ func nameArguments(goroutines []Goroutine) {
7250+ // Set a name for any pointer occuring more than once.
7251+ type object struct {
7252+ args []*Arg
7253+ inPrimary bool
7254+ id int
7255+ }
7256+ objects := map[uint64]object{}
7257+ // Enumerate all the arguments.
7258+ for i := range goroutines {
7259+ for j := range goroutines[i].Stack.Calls {
7260+ for k := range goroutines[i].Stack.Calls[j].Args.Values {
7261+ arg := goroutines[i].Stack.Calls[j].Args.Values[k]
7262+ if arg.IsPtr() {
7263+ objects[arg.Value] = object{
7264+ args: append(objects[arg.Value].args, &goroutines[i].Stack.Calls[j].Args.Values[k]),
7265+ inPrimary: objects[arg.Value].inPrimary || i == 0,
7266+ }
7267+ }
7268+ }
7269+ }
7270+ // CreatedBy.Args is never set.
7271+ }
7272+ order := uint64Slice{}
7273+ for k, obj := range objects {
7274+ if len(obj.args) > 1 && obj.inPrimary {
7275+ order = append(order, k)
7276+ }
7277+ }
7278+ sort.Sort(order)
7279+ nextID := 1
7280+ for _, k := range order {
7281+ for _, arg := range objects[k].args {
7282+ arg.Name = fmt.Sprintf("#%d", nextID)
7283+ }
7284+ nextID++
7285+ }
7286+
7287+ // Now do the rest. This is done so the output is deterministic.
7288+ order = uint64Slice{}
7289+ for k := range objects {
7290+ order = append(order, k)
7291+ }
7292+ sort.Sort(order)
7293+ for _, k := range order {
7294+ // Process the remaining pointers, they were not referenced by primary
7295+ // thread so will have higher IDs.
7296+ if objects[k].inPrimary {
7297+ continue
7298+ }
7299+ for _, arg := range objects[k].args {
7300+ arg.Name = fmt.Sprintf("#%d", nextID)
7301+ }
7302+ nextID++
7303+ }
7304+ }
7305+
7306+ type uint64Slice []uint64
7307+
7308+ func (a uint64Slice) Len() int { return len(a) }
7309+ func (a uint64Slice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
7310+ func (a uint64Slice) Less(i, j int) bool { return a[i] < a[j] }
7311 diff --git a/vendor/github.com/maruel/panicparse/stack/stack_test.go b/vendor/github.com/maruel/panicparse/stack/stack_test.go
7312new file mode 100644
7313index 0000000..883025b
7314--- /dev/null
7315+++ b/vendor/github.com/maruel/panicparse/stack/stack_test.go
7316 @@ -0,0 +1,1018 @@
7317+ // Copyright 2015 Marc-Antoine Ruel. All rights reserved.
7318+ // Use of this source code is governed under the Apache License, Version 2.0
7319+ // that can be found in the LICENSE file.
7320+
7321+ package stack
7322+
7323+ import (
7324+ "bufio"
7325+ "bytes"
7326+ "errors"
7327+ "io"
7328+ "io/ioutil"
7329+ "os"
7330+ "path/filepath"
7331+ "strings"
7332+ "testing"
7333+
7334+ "github.com/maruel/ut"
7335+ )
7336+
7337+ var goroot = goroots[0]
7338+
7339+ const crash = `panic: oh no!
7340+
7341+ goroutine 1 [running]:
7342+ panic(0x0, 0x0)
7343+ /home/user/src/golang/src/runtime/panic.go:464 +0x3e6
7344+ main.crash2(0x7fe50b49d028, 0xc82000a1e0)
7345+ /home/user/src/foo.go:45 +0x23
7346+ main.main()
7347+ /home/user/src/foo.go:50 +0xa6
7348+ `
7349+
7350+ func Example() {
7351+ in := bytes.NewBufferString(crash)
7352+ goroutines, err := ParseDump(in, os.Stdout)
7353+ if err != nil {
7354+ return
7355+ }
7356+
7357+ // Optional: Check for GOTRACEBACK being set, in particular if there is only
7358+ // one goroutine returned.
7359+
7360+ // Use a color palette based on ANSI code.
7361+ p := &Palette{}
7362+ buckets := SortBuckets(Bucketize(goroutines, AnyValue))
7363+ srcLen, pkgLen := CalcLengths(buckets, false)
7364+ for _, bucket := range buckets {
7365+ io.WriteString(os.Stdout, p.BucketHeader(&bucket, false, len(buckets) > 1))
7366+ io.WriteString(os.Stdout, p.StackLines(&bucket.Signature, srcLen, pkgLen, false))
7367+ }
7368+ // Output:
7369+ // panic: oh no!
7370+ //
7371+ // 1: running
7372+ // panic.go:464 panic(0, 0)
7373+ // main foo.go:45 crash2(0x7fe50b49d028, 0xc82000a1e0)
7374+ // main foo.go:50 main()
7375+ }
7376+
7377+ func TestParseDump1(t *testing.T) {
7378+ // One call from main, one from stdlib, one from third party.
7379+ // Create a long first line that will be ignored. It is to guard against
7380+ // https://github.com/maruel/panicparse/issues/17.
7381+ long := strings.Repeat("a", bufio.MaxScanTokenSize+1)
7382+ data := []string{
7383+ long,
7384+ "panic: reflect.Set: value of type",
7385+ "",
7386+ "goroutine 1 [running]:",
7387+ "github.com/cockroachdb/cockroach/storage/engine._Cfunc_DBIterSeek()",
7388+ " ??:0 +0x6d",
7389+ "gopkg.in/yaml%2ev2.handleErr(0xc208033b20)",
7390+ " /gopath/src/gopkg.in/yaml.v2/yaml.go:153 +0xc6",
7391+ "reflect.Value.assignTo(0x570860, 0xc20803f3e0, 0x15)",
7392+ " " + goroot + "/src/reflect/value.go:2125 +0x368",
7393+ "main.main()",
7394+ " /gopath/src/github.com/foo/bar/baz.go:428 +0x27",
7395+ "",
7396+ }
7397+ extra := &bytes.Buffer{}
7398+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7399+ ut.AssertEqual(t, nil, err)
7400+ ut.AssertEqual(t, long+"\npanic: reflect.Set: value of type\n\n", extra.String())
7401+ expected := []Goroutine{
7402+ {
7403+ Signature: Signature{
7404+ State: "running",
7405+ Stack: Stack{
7406+ Calls: []Call{
7407+ {
7408+ SourcePath: "??",
7409+ Func: Function{"github.com/cockroachdb/cockroach/storage/engine._Cfunc_DBIterSeek"},
7410+ },
7411+ {
7412+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
7413+ Line: 153,
7414+ Func: Function{"gopkg.in/yaml%2ev2.handleErr"},
7415+ Args: Args{Values: []Arg{{Value: 0xc208033b20}}},
7416+ },
7417+ {
7418+ SourcePath: goroot + "/src/reflect/value.go",
7419+ Line: 2125,
7420+ Func: Function{"reflect.Value.assignTo"},
7421+ Args: Args{Values: []Arg{{Value: 0x570860}, {Value: 0xc20803f3e0}, {Value: 0x15}}},
7422+ },
7423+ {
7424+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7425+ Line: 428,
7426+ Func: Function{"main.main"},
7427+ },
7428+ },
7429+ },
7430+ },
7431+ ID: 1,
7432+ First: true,
7433+ },
7434+ }
7435+ ut.AssertEqual(t, expected, goroutines)
7436+ }
7437+
7438+ func TestParseDumpLongWait(t *testing.T) {
7439+ // One call from main, one from stdlib, one from third party.
7440+ data := []string{
7441+ "panic: bleh",
7442+ "",
7443+ "goroutine 1 [chan send, 100 minutes]:",
7444+ "gopkg.in/yaml%2ev2.handleErr(0xc208033b20)",
7445+ " /gopath/src/gopkg.in/yaml.v2/yaml.go:153 +0xc6",
7446+ "",
7447+ "goroutine 2 [chan send, locked to thread]:",
7448+ "gopkg.in/yaml%2ev2.handleErr(0xc208033b21)",
7449+ " /gopath/src/gopkg.in/yaml.v2/yaml.go:153 +0xc6",
7450+ "",
7451+ "goroutine 3 [chan send, 101 minutes, locked to thread]:",
7452+ "gopkg.in/yaml%2ev2.handleErr(0xc208033b22)",
7453+ " /gopath/src/gopkg.in/yaml.v2/yaml.go:153 +0xc6",
7454+ "",
7455+ }
7456+ extra := &bytes.Buffer{}
7457+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7458+ ut.AssertEqual(t, nil, err)
7459+ ut.AssertEqual(t, "panic: bleh\n\n", extra.String())
7460+ expected := []Goroutine{
7461+ {
7462+ Signature: Signature{
7463+ State: "chan send",
7464+ SleepMin: 100,
7465+ SleepMax: 100,
7466+ Stack: Stack{
7467+ Calls: []Call{
7468+ {
7469+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
7470+ Line: 153,
7471+ Func: Function{"gopkg.in/yaml%2ev2.handleErr"},
7472+ Args: Args{Values: []Arg{{Value: 0xc208033b20}}},
7473+ },
7474+ },
7475+ },
7476+ },
7477+ ID: 1,
7478+ First: true,
7479+ },
7480+ {
7481+ Signature: Signature{
7482+ State: "chan send",
7483+ Locked: true,
7484+ Stack: Stack{
7485+ Calls: []Call{
7486+ {
7487+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
7488+ Line: 153,
7489+ Func: Function{"gopkg.in/yaml%2ev2.handleErr"},
7490+ Args: Args{Values: []Arg{{Value: 0xc208033b21, Name: "#1"}}},
7491+ },
7492+ },
7493+ },
7494+ },
7495+ ID: 2,
7496+ },
7497+ {
7498+ Signature: Signature{
7499+ State: "chan send",
7500+ SleepMin: 101,
7501+ SleepMax: 101,
7502+ Stack: Stack{
7503+ Calls: []Call{
7504+ {
7505+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
7506+ Line: 153,
7507+ Func: Function{"gopkg.in/yaml%2ev2.handleErr"},
7508+ Args: Args{Values: []Arg{{Value: 0xc208033b22, Name: "#2"}}},
7509+ },
7510+ },
7511+ },
7512+ Locked: true,
7513+ },
7514+ ID: 3,
7515+ },
7516+ }
7517+ ut.AssertEqual(t, expected, goroutines)
7518+ }
7519+
7520+ func TestParseDumpAsm(t *testing.T) {
7521+ data := []string{
7522+ "panic: reflect.Set: value of type",
7523+ "",
7524+ "goroutine 16 [garbage collection]:",
7525+ "runtime.switchtoM()",
7526+ "\t" + goroot + "/src/runtime/asm_amd64.s:198 fp=0xc20cfb80d8 sp=0xc20cfb80d0",
7527+ "",
7528+ }
7529+ extra := &bytes.Buffer{}
7530+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7531+ ut.AssertEqual(t, nil, err)
7532+ expected := []Goroutine{
7533+ {
7534+ Signature: Signature{
7535+ State: "garbage collection",
7536+ Stack: Stack{
7537+ Calls: []Call{
7538+ {
7539+ SourcePath: goroot + "/src/runtime/asm_amd64.s",
7540+ Line: 198,
7541+ Func: Function{Raw: "runtime.switchtoM"},
7542+ },
7543+ },
7544+ },
7545+ },
7546+ ID: 16,
7547+ First: true,
7548+ },
7549+ }
7550+ ut.AssertEqual(t, expected, goroutines)
7551+ ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
7552+ }
7553+
7554+ func TestParseDumpLineErr(t *testing.T) {
7555+ data := []string{
7556+ "panic: reflect.Set: value of type",
7557+ "",
7558+ "goroutine 1 [running]:",
7559+ "github.com/foo/bar.recurseType()",
7560+ "\t/gopath/src/github.com/foo/bar/baz.go:12345678901234567890",
7561+ "",
7562+ }
7563+ extra := &bytes.Buffer{}
7564+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7565+ ut.AssertEqual(t, errors.New("failed to parse int on line: \"\t/gopath/src/github.com/foo/bar/baz.go:12345678901234567890\n\""), err)
7566+ expected := []Goroutine{
7567+ {
7568+ Signature: Signature{
7569+ State: "running",
7570+ Stack: Stack{Calls: []Call{{Func: Function{Raw: "github.com/foo/bar.recurseType"}}}},
7571+ },
7572+ ID: 1,
7573+ First: true,
7574+ },
7575+ }
7576+
7577+ ut.AssertEqual(t, expected, goroutines)
7578+ }
7579+
7580+ func TestParseDumpValueErr(t *testing.T) {
7581+ data := []string{
7582+ "panic: reflect.Set: value of type",
7583+ "",
7584+ "goroutine 1 [running]:",
7585+ "github.com/foo/bar.recurseType(123456789012345678901)",
7586+ "\t/gopath/src/github.com/foo/bar/baz.go:9",
7587+ "",
7588+ }
7589+ extra := &bytes.Buffer{}
7590+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7591+ ut.AssertEqual(t, errors.New("failed to parse int on line: \"github.com/foo/bar.recurseType(123456789012345678901)\n\""), err)
7592+ expected := []Goroutine{
7593+ {
7594+ Signature: Signature{State: "running"},
7595+ ID: 1,
7596+ First: true,
7597+ },
7598+ }
7599+
7600+ ut.AssertEqual(t, expected, goroutines)
7601+ }
7602+
7603+ func TestParseDumpOrderErr(t *testing.T) {
7604+ data := []string{
7605+ "panic: reflect.Set: value of type",
7606+ "",
7607+ "goroutine 16 [garbage collection]:",
7608+ " /gopath/src/gopkg.in/yaml.v2/yaml.go:153 +0xc6",
7609+ "runtime.switchtoM()",
7610+ "\t" + goroot + "/src/runtime/asm_amd64.s:198 fp=0xc20cfb80d8 sp=0xc20cfb80d0",
7611+ "",
7612+ }
7613+ extra := &bytes.Buffer{}
7614+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7615+ ut.AssertEqual(t, errors.New("unexpected order"), err)
7616+ expected := []Goroutine{
7617+ {
7618+ Signature: Signature{State: "garbage collection"},
7619+ ID: 16,
7620+ First: true,
7621+ },
7622+ }
7623+ ut.AssertEqual(t, expected, goroutines)
7624+ ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
7625+ }
7626+
7627+ func TestParseDumpElided(t *testing.T) {
7628+ data := []string{
7629+ "panic: reflect.Set: value of type",
7630+ "",
7631+ "goroutine 16 [garbage collection]:",
7632+ "github.com/foo/bar.recurseType(0x7f4fa9a3ec70, 0xc208062580, 0x7f4fa9a3e818, 0x50a820, 0xc20803a8a0)",
7633+ "\t/gopath/src/github.com/foo/bar/baz.go:53 +0x845 fp=0xc20cfc66d8 sp=0xc20cfc6470",
7634+ "...additional frames elided...",
7635+ "created by testing.RunTests",
7636+ "\t" + goroot + "/src/testing/testing.go:555 +0xa8b",
7637+ "",
7638+ }
7639+ extra := &bytes.Buffer{}
7640+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7641+ ut.AssertEqual(t, nil, err)
7642+ expected := []Goroutine{
7643+ {
7644+ Signature: Signature{
7645+ State: "garbage collection",
7646+ Stack: Stack{
7647+ Calls: []Call{
7648+ {
7649+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7650+ Line: 53,
7651+ Func: Function{Raw: "github.com/foo/bar.recurseType"},
7652+ Args: Args{
7653+ Values: []Arg{
7654+ {Value: 0x7f4fa9a3ec70},
7655+ {Value: 0xc208062580},
7656+ {Value: 0x7f4fa9a3e818},
7657+ {Value: 0x50a820},
7658+ {Value: 0xc20803a8a0},
7659+ },
7660+ },
7661+ },
7662+ },
7663+ Elided: true,
7664+ },
7665+ CreatedBy: Call{
7666+ SourcePath: goroot + "/src/testing/testing.go",
7667+ Line: 555,
7668+ Func: Function{Raw: "testing.RunTests"},
7669+ },
7670+ },
7671+ ID: 16,
7672+ First: true,
7673+ },
7674+ }
7675+ ut.AssertEqual(t, expected, goroutines)
7676+ ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
7677+ }
7678+
7679+ func TestParseDumpSysCall(t *testing.T) {
7680+ data := []string{
7681+ "panic: reflect.Set: value of type",
7682+ "",
7683+ "goroutine 5 [syscall]:",
7684+ "runtime.notetsleepg(0x918100, 0xffffffffffffffff, 0x1)",
7685+ "\t" + goroot + "/src/runtime/lock_futex.go:201 +0x52 fp=0xc208018f68 sp=0xc208018f40",
7686+ "runtime.signal_recv(0x0)",
7687+ "\t" + goroot + "/src/runtime/sigqueue.go:109 +0x135 fp=0xc208018fa0 sp=0xc208018f68",
7688+ "os/signal.loop()",
7689+ "\t" + goroot + "/src/os/signal/signal_unix.go:21 +0x1f fp=0xc208018fe0 sp=0xc208018fa0",
7690+ "runtime.goexit()",
7691+ "\t" + goroot + "/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc208018fe8 sp=0xc208018fe0",
7692+ "created by os/signal.init·1",
7693+ "\t" + goroot + "/src/os/signal/signal_unix.go:27 +0x35",
7694+ "",
7695+ }
7696+ extra := &bytes.Buffer{}
7697+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7698+ ut.AssertEqual(t, nil, err)
7699+ expected := []Goroutine{
7700+ {
7701+ Signature: Signature{
7702+ State: "syscall",
7703+ Stack: Stack{
7704+ Calls: []Call{
7705+ {
7706+ SourcePath: goroot + "/src/runtime/lock_futex.go",
7707+ Line: 201,
7708+ Func: Function{Raw: "runtime.notetsleepg"},
7709+ Args: Args{
7710+ Values: []Arg{
7711+ {Value: 0x918100},
7712+ {Value: 0xffffffffffffffff},
7713+ {Value: 0x1},
7714+ },
7715+ },
7716+ },
7717+ {
7718+ SourcePath: goroot + "/src/runtime/sigqueue.go",
7719+ Line: 109,
7720+ Func: Function{Raw: "runtime.signal_recv"},
7721+ Args: Args{
7722+ Values: []Arg{{}},
7723+ },
7724+ },
7725+ {
7726+ SourcePath: goroot + "/src/os/signal/signal_unix.go",
7727+ Line: 21,
7728+ Func: Function{Raw: "os/signal.loop"},
7729+ },
7730+ {
7731+ SourcePath: goroot + "/src/runtime/asm_amd64.s",
7732+ Line: 2232,
7733+ Func: Function{Raw: "runtime.goexit"},
7734+ },
7735+ },
7736+ },
7737+ CreatedBy: Call{
7738+ SourcePath: goroot + "/src/os/signal/signal_unix.go",
7739+ Line: 27,
7740+ Func: Function{Raw: "os/signal.init·1"},
7741+ },
7742+ },
7743+ ID: 5,
7744+ First: true,
7745+ },
7746+ }
7747+ ut.AssertEqual(t, expected, goroutines)
7748+ ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
7749+ }
7750+
7751+ func TestParseDumpUnavail(t *testing.T) {
7752+ data := []string{
7753+ "panic: reflect.Set: value of type",
7754+ "",
7755+ "goroutine 24 [running]:",
7756+ "\tgoroutine running on other thread; stack unavailable",
7757+ "created by github.com/foo.New",
7758+ "\t/gopath/src/github.com/foo/bar.go:131 +0x381",
7759+ "",
7760+ }
7761+ extra := &bytes.Buffer{}
7762+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), extra)
7763+ ut.AssertEqual(t, nil, err)
7764+ expected := []Goroutine{
7765+ {
7766+ Signature: Signature{
7767+ State: "running",
7768+ Stack: Stack{
7769+ Calls: []Call{{SourcePath: "<unavailable>"}},
7770+ },
7771+ CreatedBy: Call{
7772+ SourcePath: "/gopath/src/github.com/foo/bar.go",
7773+ Line: 131,
7774+ Func: Function{Raw: "github.com/foo.New"},
7775+ },
7776+ },
7777+ ID: 24,
7778+ First: true,
7779+ },
7780+ }
7781+ ut.AssertEqual(t, expected, goroutines)
7782+ ut.AssertEqual(t, "panic: reflect.Set: value of type\n\n", extra.String())
7783+ }
7784+
7785+ func TestParseDumpSameBucket(t *testing.T) {
7786+ // 2 goroutines with the same signature
7787+ data := []string{
7788+ "panic: runtime error: index out of range",
7789+ "",
7790+ "goroutine 6 [chan receive]:",
7791+ "main.func·001()",
7792+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7793+ "created by main.mainImpl",
7794+ " /gopath/src/github.com/foo/bar/baz.go:74 +0xeb",
7795+ "",
7796+ "goroutine 7 [chan receive]:",
7797+ "main.func·001()",
7798+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7799+ "created by main.mainImpl",
7800+ " /gopath/src/github.com/foo/bar/baz.go:74 +0xeb",
7801+ "",
7802+ }
7803+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
7804+ ut.AssertEqual(t, nil, err)
7805+ expectedGR := []Goroutine{
7806+ {
7807+ Signature: Signature{
7808+ State: "chan receive",
7809+ Stack: Stack{
7810+ Calls: []Call{
7811+ {
7812+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7813+ Line: 72,
7814+ Func: Function{"main.func·001"},
7815+ },
7816+ },
7817+ },
7818+ CreatedBy: Call{
7819+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7820+ Line: 74,
7821+ Func: Function{"main.mainImpl"},
7822+ },
7823+ },
7824+ ID: 6,
7825+ First: true,
7826+ },
7827+ {
7828+ Signature: Signature{
7829+ State: "chan receive",
7830+ Stack: Stack{
7831+ Calls: []Call{
7832+ {
7833+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7834+ Line: 72,
7835+ Func: Function{"main.func·001"},
7836+ },
7837+ },
7838+ },
7839+ CreatedBy: Call{
7840+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7841+ Line: 74,
7842+ Func: Function{"main.mainImpl"},
7843+ },
7844+ },
7845+ ID: 7,
7846+ },
7847+ }
7848+ ut.AssertEqual(t, expectedGR, goroutines)
7849+ expectedBuckets := Buckets{{expectedGR[0].Signature, []Goroutine{expectedGR[0], expectedGR[1]}}}
7850+ ut.AssertEqual(t, expectedBuckets, SortBuckets(Bucketize(goroutines, ExactLines)))
7851+ }
7852+
7853+ func TestBucketizeNotAggressive(t *testing.T) {
7854+ // 2 goroutines with the same signature
7855+ data := []string{
7856+ "panic: runtime error: index out of range",
7857+ "",
7858+ "goroutine 6 [chan receive]:",
7859+ "main.func·001(0x11000000, 2)",
7860+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7861+ "",
7862+ "goroutine 7 [chan receive]:",
7863+ "main.func·001(0x21000000, 2)",
7864+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7865+ "",
7866+ }
7867+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
7868+ ut.AssertEqual(t, nil, err)
7869+ expectedGR := []Goroutine{
7870+ {
7871+ Signature: Signature{
7872+ State: "chan receive",
7873+ Stack: Stack{
7874+ Calls: []Call{
7875+ {
7876+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7877+ Line: 72,
7878+ Func: Function{"main.func·001"},
7879+ Args: Args{Values: []Arg{{0x11000000, ""}, {Value: 2}}},
7880+ },
7881+ },
7882+ },
7883+ },
7884+ ID: 6,
7885+ First: true,
7886+ },
7887+ {
7888+ Signature: Signature{
7889+ State: "chan receive",
7890+ Stack: Stack{
7891+ Calls: []Call{
7892+ {
7893+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7894+ Line: 72,
7895+ Func: Function{"main.func·001"},
7896+ Args: Args{Values: []Arg{{0x21000000, "#1"}, {Value: 2}}},
7897+ },
7898+ },
7899+ },
7900+ },
7901+ ID: 7,
7902+ },
7903+ }
7904+ ut.AssertEqual(t, expectedGR, goroutines)
7905+ expectedBuckets := Buckets{
7906+ {expectedGR[0].Signature, []Goroutine{expectedGR[0]}},
7907+ {expectedGR[1].Signature, []Goroutine{expectedGR[1]}},
7908+ }
7909+ ut.AssertEqual(t, expectedBuckets, SortBuckets(Bucketize(goroutines, ExactLines)))
7910+ }
7911+
7912+ func TestBucketizeAggressive(t *testing.T) {
7913+ // 2 goroutines with the same signature
7914+ data := []string{
7915+ "panic: runtime error: index out of range",
7916+ "",
7917+ "goroutine 6 [chan receive, 10 minutes]:",
7918+ "main.func·001(0x11000000, 2)",
7919+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7920+ "",
7921+ "goroutine 7 [chan receive, 50 minutes]:",
7922+ "main.func·001(0x21000000, 2)",
7923+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7924+ "",
7925+ "goroutine 8 [chan receive, 100 minutes]:",
7926+ "main.func·001(0x21000000, 2)",
7927+ " /gopath/src/github.com/foo/bar/baz.go:72 +0x49",
7928+ "",
7929+ }
7930+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
7931+ ut.AssertEqual(t, nil, err)
7932+ expectedGR := []Goroutine{
7933+ {
7934+ Signature: Signature{
7935+ State: "chan receive",
7936+ SleepMin: 10,
7937+ SleepMax: 10,
7938+ Stack: Stack{
7939+ Calls: []Call{
7940+ {
7941+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7942+ Line: 72,
7943+ Func: Function{"main.func·001"},
7944+ Args: Args{Values: []Arg{{0x11000000, ""}, {Value: 2}}},
7945+ },
7946+ },
7947+ },
7948+ },
7949+ ID: 6,
7950+ First: true,
7951+ },
7952+ {
7953+ Signature: Signature{
7954+ State: "chan receive",
7955+ SleepMin: 50,
7956+ SleepMax: 50,
7957+ Stack: Stack{
7958+ Calls: []Call{
7959+ {
7960+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7961+ Line: 72,
7962+ Func: Function{"main.func·001"},
7963+ Args: Args{Values: []Arg{{0x21000000, "#1"}, {Value: 2}}},
7964+ },
7965+ },
7966+ },
7967+ },
7968+ ID: 7,
7969+ },
7970+ {
7971+ Signature: Signature{
7972+ State: "chan receive",
7973+ SleepMin: 100,
7974+ SleepMax: 100,
7975+ Stack: Stack{
7976+ Calls: []Call{
7977+ {
7978+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7979+ Line: 72,
7980+ Func: Function{"main.func·001"},
7981+ Args: Args{Values: []Arg{{0x21000000, "#1"}, {Value: 2}}},
7982+ },
7983+ },
7984+ },
7985+ },
7986+ ID: 8,
7987+ },
7988+ }
7989+ ut.AssertEqual(t, expectedGR, goroutines)
7990+ signature := Signature{
7991+ State: "chan receive",
7992+ SleepMin: 10,
7993+ SleepMax: 100,
7994+ Stack: Stack{
7995+ Calls: []Call{
7996+ {
7997+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
7998+ Line: 72,
7999+ Func: Function{"main.func·001"},
8000+ Args: Args{Values: []Arg{{0x11000000, "*"}, {Value: 2}}},
8001+ },
8002+ },
8003+ },
8004+ }
8005+ expectedBuckets := Buckets{{signature, []Goroutine{expectedGR[0], expectedGR[1], expectedGR[2]}}}
8006+ ut.AssertEqual(t, expectedBuckets, SortBuckets(Bucketize(goroutines, AnyPointer)))
8007+ }
8008+
8009+ func TestParseDumpNoOffset(t *testing.T) {
8010+ data := []string{
8011+ "panic: runtime error: index out of range",
8012+ "",
8013+ "goroutine 37 [runnable]:",
8014+ "github.com/foo.func·002()",
8015+ " /gopath/src/github.com/foo/bar.go:110",
8016+ "created by github.com/foo.New",
8017+ " /gopath/src/github.com/foo/bar.go:113 +0x43b",
8018+ "",
8019+ }
8020+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
8021+ ut.AssertEqual(t, nil, err)
8022+ expectedGR := []Goroutine{
8023+ {
8024+ Signature: Signature{
8025+ State: "runnable",
8026+ Stack: Stack{
8027+ Calls: []Call{
8028+ {
8029+ SourcePath: "/gopath/src/github.com/foo/bar.go",
8030+ Line: 110,
8031+ Func: Function{"github.com/foo.func·002"},
8032+ },
8033+ },
8034+ },
8035+ CreatedBy: Call{
8036+ SourcePath: "/gopath/src/github.com/foo/bar.go",
8037+ Line: 113,
8038+ Func: Function{"github.com/foo.New"},
8039+ },
8040+ },
8041+ ID: 37,
8042+ First: true,
8043+ },
8044+ }
8045+ ut.AssertEqual(t, expectedGR, goroutines)
8046+ }
8047+
8048+ func TestParseDumpJunk(t *testing.T) {
8049+ // For coverage of scanLines.
8050+ data := []string{
8051+ "panic: reflect.Set: value of type",
8052+ "",
8053+ "goroutine 1 [running]:",
8054+ "junk",
8055+ }
8056+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
8057+ ut.AssertEqual(t, nil, err)
8058+ expectedGR := []Goroutine{
8059+ {
8060+ Signature: Signature{State: "running"},
8061+ ID: 1,
8062+ First: true,
8063+ },
8064+ }
8065+ ut.AssertEqual(t, expectedGR, goroutines)
8066+ }
8067+
8068+ func TestParseCCode(t *testing.T) {
8069+ data := []string{
8070+ "SIGQUIT: quit",
8071+ "PC=0x43f349",
8072+ "",
8073+ "goroutine 0 [idle]:",
8074+ "runtime.epollwait(0x4, 0x7fff671c7118, 0xffffffff00000080, 0x0, 0xffffffff0028c1be, 0x0, 0x0, 0x0, 0x0, 0x0, ...)",
8075+ " " + goroot + "/src/runtime/sys_linux_amd64.s:400 +0x19",
8076+ "runtime.netpoll(0x901b01, 0x0)",
8077+ " " + goroot + "/src/runtime/netpoll_epoll.go:68 +0xa3",
8078+ "findrunnable(0xc208012000)",
8079+ " " + goroot + "/src/runtime/proc.c:1472 +0x485",
8080+ "schedule()",
8081+ " " + goroot + "/src/runtime/proc.c:1575 +0x151",
8082+ "runtime.park_m(0xc2080017a0)",
8083+ " " + goroot + "/src/runtime/proc.c:1654 +0x113",
8084+ "runtime.mcall(0x432684)",
8085+ " " + goroot + "/src/runtime/asm_amd64.s:186 +0x5a",
8086+ "",
8087+ }
8088+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\n")), &bytes.Buffer{})
8089+ ut.AssertEqual(t, nil, err)
8090+ expectedGR := []Goroutine{
8091+ {
8092+ Signature: Signature{
8093+ State: "idle",
8094+ Stack: Stack{
8095+ Calls: []Call{
8096+ {
8097+ SourcePath: goroot + "/src/runtime/sys_linux_amd64.s",
8098+ Line: 400,
8099+ Func: Function{"runtime.epollwait"},
8100+ Args: Args{
8101+ Values: []Arg{
8102+ {Value: 0x4},
8103+ {Value: 0x7fff671c7118},
8104+ {Value: 0xffffffff00000080},
8105+ {},
8106+ {Value: 0xffffffff0028c1be},
8107+ {},
8108+ {},
8109+ {},
8110+ {},
8111+ {},
8112+ },
8113+ Elided: true,
8114+ },
8115+ },
8116+ {
8117+ SourcePath: goroot + "/src/runtime/netpoll_epoll.go",
8118+ Line: 68,
8119+ Func: Function{"runtime.netpoll"},
8120+ Args: Args{Values: []Arg{{Value: 0x901b01}, {}}},
8121+ },
8122+ {
8123+ SourcePath: goroot + "/src/runtime/proc.c",
8124+ Line: 1472,
8125+ Func: Function{"findrunnable"},
8126+ Args: Args{Values: []Arg{{Value: 0xc208012000}}},
8127+ },
8128+ {
8129+ SourcePath: goroot + "/src/runtime/proc.c",
8130+ Line: 1575,
8131+ Func: Function{"schedule"},
8132+ },
8133+ {
8134+ SourcePath: goroot + "/src/runtime/proc.c",
8135+ Line: 1654,
8136+ Func: Function{"runtime.park_m"},
8137+ Args: Args{Values: []Arg{{Value: 0xc2080017a0}}},
8138+ },
8139+ {
8140+ SourcePath: goroot + "/src/runtime/asm_amd64.s",
8141+ Line: 186,
8142+ Func: Function{"runtime.mcall"},
8143+ Args: Args{Values: []Arg{{Value: 0x432684}}},
8144+ },
8145+ },
8146+ },
8147+ },
8148+ ID: 0,
8149+ First: true,
8150+ },
8151+ }
8152+ ut.AssertEqual(t, expectedGR, goroutines)
8153+ }
8154+
8155+ func TestParseWithCarriageReturn(t *testing.T) {
8156+ data := []string{
8157+ "goroutine 1 [running]:",
8158+ "github.com/cockroachdb/cockroach/storage/engine._Cfunc_DBIterSeek()",
8159+ " ??:0 +0x6d",
8160+ "gopkg.in/yaml%2ev2.handleErr(0xc208033b20)",
8161+ " /gopath/src/gopkg.in/yaml.v2/yaml.go:153 +0xc6",
8162+ "reflect.Value.assignTo(0x570860, 0xc20803f3e0, 0x15)",
8163+ " " + goroot + "/src/reflect/value.go:2125 +0x368",
8164+ "main.main()",
8165+ " /gopath/src/github.com/foo/bar/baz.go:428 +0x27",
8166+ "",
8167+ }
8168+
8169+ goroutines, err := ParseDump(bytes.NewBufferString(strings.Join(data, "\r\n")), ioutil.Discard)
8170+ ut.AssertEqual(t, nil, err)
8171+ expected := []Goroutine{
8172+ {
8173+ Signature: Signature{
8174+ State: "running",
8175+ Stack: Stack{
8176+ Calls: []Call{
8177+ {
8178+ SourcePath: "??",
8179+ Func: Function{"github.com/cockroachdb/cockroach/storage/engine._Cfunc_DBIterSeek"},
8180+ },
8181+ {
8182+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
8183+ Line: 153,
8184+ Func: Function{"gopkg.in/yaml%2ev2.handleErr"},
8185+ Args: Args{Values: []Arg{{Value: 0xc208033b20}}},
8186+ },
8187+ {
8188+ SourcePath: goroot + "/src/reflect/value.go",
8189+ Line: 2125,
8190+ Func: Function{"reflect.Value.assignTo"},
8191+ Args: Args{Values: []Arg{{Value: 0x570860}, {Value: 0xc20803f3e0}, {Value: 0x15}}},
8192+ },
8193+ {
8194+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
8195+ Line: 428,
8196+ Func: Function{"main.main"},
8197+ },
8198+ },
8199+ },
8200+ },
8201+ ID: 1,
8202+ First: true,
8203+ },
8204+ }
8205+ ut.AssertEqual(t, expected, goroutines)
8206+ }
8207+
8208+ func TestCallPkg1(t *testing.T) {
8209+ c := Call{
8210+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
8211+ Line: 153,
8212+ Func: Function{"gopkg.in/yaml%2ev2.handleErr"},
8213+ Args: Args{Values: []Arg{{Value: 0xc208033b20}}},
8214+ }
8215+ ut.AssertEqual(t, "yaml.go", c.SourceName())
8216+ ut.AssertEqual(t, filepath.Join("yaml.v2", "yaml.go"), c.PkgSource())
8217+ ut.AssertEqual(t, "gopkg.in/yaml.v2.handleErr", c.Func.String())
8218+ ut.AssertEqual(t, "handleErr", c.Func.Name())
8219+ // This is due to directory name not matching the package name.
8220+ ut.AssertEqual(t, "yaml.v2", c.Func.PkgName())
8221+ ut.AssertEqual(t, false, c.Func.IsExported())
8222+ ut.AssertEqual(t, false, c.IsStdlib())
8223+ ut.AssertEqual(t, false, c.IsPkgMain())
8224+ }
8225+
8226+ func TestCallPkg2(t *testing.T) {
8227+ c := Call{
8228+ SourcePath: "/gopath/src/gopkg.in/yaml.v2/yaml.go",
8229+ Line: 153,
8230+ Func: Function{"gopkg.in/yaml%2ev2.(*decoder).unmarshal"},
8231+ Args: Args{Values: []Arg{{Value: 0xc208033b20}}},
8232+ }
8233+ ut.AssertEqual(t, "yaml.go", c.SourceName())
8234+ ut.AssertEqual(t, filepath.Join("yaml.v2", "yaml.go"), c.PkgSource())
8235+ // TODO(maruel): Using '/' for this function is inconsistent on Windows
8236+ // w.r.t. other functions.
8237+ ut.AssertEqual(t, "gopkg.in/yaml.v2.(*decoder).unmarshal", c.Func.String())
8238+ ut.AssertEqual(t, "(*decoder).unmarshal", c.Func.Name())
8239+ // This is due to directory name not matching the package name.
8240+ ut.AssertEqual(t, "yaml.v2", c.Func.PkgName())
8241+ ut.AssertEqual(t, false, c.Func.IsExported())
8242+ ut.AssertEqual(t, false, c.IsStdlib())
8243+ ut.AssertEqual(t, false, c.IsPkgMain())
8244+ }
8245+
8246+ func TestCallStdlib(t *testing.T) {
8247+ c := Call{
8248+ SourcePath: goroot + "/src/reflect/value.go",
8249+ Line: 2125,
8250+ Func: Function{"reflect.Value.assignTo"},
8251+ Args: Args{Values: []Arg{{Value: 0x570860}, {Value: 0xc20803f3e0}, {Value: 0x15}}},
8252+ }
8253+ ut.AssertEqual(t, "value.go", c.SourceName())
8254+ ut.AssertEqual(t, "value.go:2125", c.SourceLine())
8255+ ut.AssertEqual(t, filepath.Join("reflect", "value.go"), c.PkgSource())
8256+ ut.AssertEqual(t, "reflect.Value.assignTo", c.Func.String())
8257+ ut.AssertEqual(t, "Value.assignTo", c.Func.Name())
8258+ ut.AssertEqual(t, "reflect", c.Func.PkgName())
8259+ ut.AssertEqual(t, false, c.Func.IsExported())
8260+ ut.AssertEqual(t, true, c.IsStdlib())
8261+ ut.AssertEqual(t, false, c.IsPkgMain())
8262+ }
8263+
8264+ func TestCallMain(t *testing.T) {
8265+ c := Call{
8266+ SourcePath: "/gopath/src/github.com/foo/bar/main.go",
8267+ Line: 428,
8268+ Func: Function{"main.main"},
8269+ }
8270+ ut.AssertEqual(t, "main.go", c.SourceName())
8271+ ut.AssertEqual(t, "main.go:428", c.SourceLine())
8272+ ut.AssertEqual(t, filepath.Join("bar", "main.go"), c.PkgSource())
8273+ ut.AssertEqual(t, "main.main", c.Func.String())
8274+ ut.AssertEqual(t, "main", c.Func.Name())
8275+ ut.AssertEqual(t, "main", c.Func.PkgName())
8276+ ut.AssertEqual(t, true, c.Func.IsExported())
8277+ ut.AssertEqual(t, false, c.IsStdlib())
8278+ ut.AssertEqual(t, true, c.IsPkgMain())
8279+ }
8280+
8281+ func TestCallC(t *testing.T) {
8282+ c := Call{
8283+ SourcePath: goroot + "/src/runtime/proc.c",
8284+ Line: 1472,
8285+ Func: Function{"findrunnable"},
8286+ Args: Args{Values: []Arg{{Value: 0xc208012000}}},
8287+ }
8288+ ut.AssertEqual(t, "proc.c", c.SourceName())
8289+ ut.AssertEqual(t, "proc.c:1472", c.SourceLine())
8290+ ut.AssertEqual(t, filepath.Join("runtime", "proc.c"), c.PkgSource())
8291+ ut.AssertEqual(t, "findrunnable", c.Func.String())
8292+ ut.AssertEqual(t, "findrunnable", c.Func.Name())
8293+ ut.AssertEqual(t, "", c.Func.PkgName())
8294+ ut.AssertEqual(t, false, c.Func.IsExported())
8295+ ut.AssertEqual(t, true, c.IsStdlib())
8296+ ut.AssertEqual(t, false, c.IsPkgMain())
8297+ }
8298+
8299+ func TestArgs(t *testing.T) {
8300+ a := Args{
8301+ Values: []Arg{
8302+ {Value: 0x4},
8303+ {Value: 0x7fff671c7118},
8304+ {Value: 0xffffffff00000080},
8305+ {},
8306+ {Value: 0xffffffff0028c1be},
8307+ {},
8308+ {},
8309+ {},
8310+ {},
8311+ {},
8312+ },
8313+ Elided: true,
8314+ }
8315+ ut.AssertEqual(t, "0x4, 0x7fff671c7118, 0xffffffff00000080, 0, 0xffffffff0028c1be, 0, 0, 0, 0, 0, ...", a.String())
8316+ }
8317+
8318+ func TestFunctionAnonymous(t *testing.T) {
8319+ f := Function{"main.func·001"}
8320+ ut.AssertEqual(t, "main.func·001", f.String())
8321+ ut.AssertEqual(t, "main.func·001", f.PkgDotName())
8322+ ut.AssertEqual(t, "func·001", f.Name())
8323+ ut.AssertEqual(t, "main", f.PkgName())
8324+ ut.AssertEqual(t, false, f.IsExported())
8325+ }
8326+
8327+ func TestFunctionGC(t *testing.T) {
8328+ f := Function{"gc"}
8329+ ut.AssertEqual(t, "gc", f.String())
8330+ ut.AssertEqual(t, "gc", f.PkgDotName())
8331+ ut.AssertEqual(t, "gc", f.Name())
8332+ ut.AssertEqual(t, "", f.PkgName())
8333+ ut.AssertEqual(t, false, f.IsExported())
8334+ }
8335 diff --git a/vendor/github.com/maruel/panicparse/stack/ui.go b/vendor/github.com/maruel/panicparse/stack/ui.go
8336new file mode 100644
8337index 0000000..b125fc9
8338--- /dev/null
8339+++ b/vendor/github.com/maruel/panicparse/stack/ui.go
8340 @@ -0,0 +1,139 @@
8341+ // Copyright 2016 Marc-Antoine Ruel. All rights reserved.
8342+ // Use of this source code is governed under the Apache License, Version 2.0
8343+ // that can be found in the LICENSE file.
8344+
8345+ package stack
8346+
8347+ import (
8348+ "fmt"
8349+ "strings"
8350+ )
8351+
8352+ // Palette defines the color used.
8353+ //
8354+ // An empty object Palette{} can be used to disable coloring.
8355+ type Palette struct {
8356+ EOLReset string
8357+
8358+ // Routine header.
8359+ RoutineFirst string // The first routine printed.
8360+ Routine string // Following routines.
8361+ CreatedBy string
8362+
8363+ // Call line.
8364+ Package string
8365+ SourceFile string
8366+ FunctionStdLib string
8367+ FunctionStdLibExported string
8368+ FunctionMain string
8369+ FunctionOther string
8370+ FunctionOtherExported string
8371+ Arguments string
8372+ }
8373+
8374+ // CalcLengths returns the maximum length of the source lines and package names.
8375+ func CalcLengths(buckets Buckets, fullPath bool) (int, int) {
8376+ srcLen := 0
8377+ pkgLen := 0
8378+ for _, bucket := range buckets {
8379+ for _, line := range bucket.Signature.Stack.Calls {
8380+ l := 0
8381+ if fullPath {
8382+ l = len(line.FullSourceLine())
8383+ } else {
8384+ l = len(line.SourceLine())
8385+ }
8386+ if l > srcLen {
8387+ srcLen = l
8388+ }
8389+ l = len(line.Func.PkgName())
8390+ if l > pkgLen {
8391+ pkgLen = l
8392+ }
8393+ }
8394+ }
8395+ return srcLen, pkgLen
8396+ }
8397+
8398+ // functionColor returns the color to be used for the function name based on
8399+ // the type of package the function is in.
8400+ func (p *Palette) functionColor(line *Call) string {
8401+ if line.IsStdlib() {
8402+ if line.Func.IsExported() {
8403+ return p.FunctionStdLibExported
8404+ }
8405+ return p.FunctionStdLib
8406+ } else if line.IsPkgMain() {
8407+ return p.FunctionMain
8408+ } else if line.Func.IsExported() {
8409+ return p.FunctionOtherExported
8410+ }
8411+ return p.FunctionOther
8412+ }
8413+
8414+ // routineColor returns the color for the header of the goroutines bucket.
8415+ func (p *Palette) routineColor(bucket *Bucket, multipleBuckets bool) string {
8416+ if bucket.First() && multipleBuckets {
8417+ return p.RoutineFirst
8418+ }
8419+ return p.Routine
8420+ }
8421+
8422+ // BucketHeader prints the header of a goroutine signature.
8423+ func (p *Palette) BucketHeader(bucket *Bucket, fullPath, multipleBuckets bool) string {
8424+ extra := ""
8425+ if bucket.SleepMax != 0 {
8426+ if bucket.SleepMin != bucket.SleepMax {
8427+ extra += fmt.Sprintf(" [%d~%d minutes]", bucket.SleepMin, bucket.SleepMax)
8428+ } else {
8429+ extra += fmt.Sprintf(" [%d minutes]", bucket.SleepMax)
8430+ }
8431+ }
8432+ if bucket.Locked {
8433+ extra += " [locked]"
8434+ }
8435+ created := bucket.CreatedBy.Func.PkgDotName()
8436+ if created != "" {
8437+ created += " @ "
8438+ if fullPath {
8439+ created += bucket.CreatedBy.FullSourceLine()
8440+ } else {
8441+ created += bucket.CreatedBy.SourceLine()
8442+ }
8443+ extra += p.CreatedBy + " [Created by " + created + "]"
8444+ }
8445+ return fmt.Sprintf(
8446+ "%s%d: %s%s%s\n",
8447+ p.routineColor(bucket, multipleBuckets), len(bucket.Routines),
8448+ bucket.State, extra,
8449+ p.EOLReset)
8450+ }
8451+
8452+ // callLine prints one stack line.
8453+ func (p *Palette) callLine(line *Call, srcLen, pkgLen int, fullPath bool) string {
8454+ src := ""
8455+ if fullPath {
8456+ src = line.FullSourceLine()
8457+ } else {
8458+ src = line.SourceLine()
8459+ }
8460+ return fmt.Sprintf(
8461+ " %s%-*s %s%-*s %s%s%s(%s)%s",
8462+ p.Package, pkgLen, line.Func.PkgName(),
8463+ p.SourceFile, srcLen, src,
8464+ p.functionColor(line), line.Func.Name(),
8465+ p.Arguments, line.Args,
8466+ p.EOLReset)
8467+ }
8468+
8469+ // StackLines prints one complete stack trace, without the header.
8470+ func (p *Palette) StackLines(signature *Signature, srcLen, pkgLen int, fullPath bool) string {
8471+ out := make([]string, len(signature.Stack.Calls))
8472+ for i := range signature.Stack.Calls {
8473+ out[i] = p.callLine(&signature.Stack.Calls[i], srcLen, pkgLen, fullPath)
8474+ }
8475+ if signature.Stack.Elided {
8476+ out = append(out, " (...)")
8477+ }
8478+ return strings.Join(out, "\n") + "\n"
8479+ }
8480 diff --git a/vendor/github.com/maruel/panicparse/stack/ui_test.go b/vendor/github.com/maruel/panicparse/stack/ui_test.go
8481new file mode 100644
8482index 0000000..d50c588
8483--- /dev/null
8484+++ b/vendor/github.com/maruel/panicparse/stack/ui_test.go
8485 @@ -0,0 +1,149 @@
8486+ // Copyright 2016 Marc-Antoine Ruel. All rights reserved.
8487+ // Use of this source code is governed under the Apache License, Version 2.0
8488+ // that can be found in the LICENSE file.
8489+
8490+ package stack
8491+
8492+ import (
8493+ "testing"
8494+
8495+ "github.com/maruel/ut"
8496+ )
8497+
8498+ var p = &Palette{
8499+ EOLReset: "A",
8500+ RoutineFirst: "B",
8501+ Routine: "C",
8502+ CreatedBy: "D",
8503+ Package: "E",
8504+ SourceFile: "F",
8505+ FunctionStdLib: "G",
8506+ FunctionStdLibExported: "H",
8507+ FunctionMain: "I",
8508+ FunctionOther: "J",
8509+ FunctionOtherExported: "K",
8510+ Arguments: "L",
8511+ }
8512+
8513+ func TestCalcLengths(t *testing.T) {
8514+ t.Parallel()
8515+ b := Buckets{
8516+ {
8517+ Signature{Stack: Stack{Calls: []Call{{SourcePath: "/gopath/baz.go", Func: Function{"main.func·001"}}}}},
8518+ nil,
8519+ },
8520+ }
8521+ srcLen, pkgLen := CalcLengths(b, true)
8522+ ut.AssertEqual(t, 16, srcLen)
8523+ ut.AssertEqual(t, 4, pkgLen)
8524+ srcLen, pkgLen = CalcLengths(b, false)
8525+ ut.AssertEqual(t, 8, srcLen)
8526+ ut.AssertEqual(t, 4, pkgLen)
8527+ }
8528+
8529+ func TestBucketHeader(t *testing.T) {
8530+ t.Parallel()
8531+ b := &Bucket{
8532+ Signature{
8533+ State: "chan receive",
8534+ CreatedBy: Call{
8535+ SourcePath: "/gopath/src/github.com/foo/bar/baz.go",
8536+ Line: 74,
8537+ Func: Function{"main.mainImpl"},
8538+ },
8539+ SleepMax: 6,
8540+ SleepMin: 2,
8541+ },
8542+ []Goroutine{
8543+ {
8544+ First: true,
8545+ },
8546+ {},
8547+ },
8548+ }
8549+ ut.AssertEqual(t, "B2: chan receive [2~6 minutes]D [Created by main.mainImpl @ /gopath/src/github.com/foo/bar/baz.go:74]A\n", p.BucketHeader(b, true, true))
8550+ ut.AssertEqual(t, "C2: chan receive [2~6 minutes]D [Created by main.mainImpl @ /gopath/src/github.com/foo/bar/baz.go:74]A\n", p.BucketHeader(b, true, false))
8551+ ut.AssertEqual(t, "B2: chan receive [2~6 minutes]D [Created by main.mainImpl @ baz.go:74]A\n", p.BucketHeader(b, false, true))
8552+ ut.AssertEqual(t, "C2: chan receive [2~6 minutes]D [Created by main.mainImpl @ baz.go:74]A\n", p.BucketHeader(b, false, false))
8553+
8554+ b = &Bucket{
8555+ Signature{
8556+ State: "b0rked",
8557+ SleepMax: 6,
8558+ SleepMin: 6,
8559+ Locked: true,
8560+ },
8561+ nil,
8562+ }
8563+ ut.AssertEqual(t, "C0: b0rked [6 minutes] [locked]A\n", p.BucketHeader(b, false, false))
8564+ }
8565+
8566+ func TestStackLines(t *testing.T) {
8567+ t.Parallel()
8568+ s := &Signature{
8569+ State: "idle",
8570+ Stack: Stack{
8571+ Calls: []Call{
8572+ {
8573+ SourcePath: goroot + "/src/runtime/sys_linux_amd64.s",
8574+ Line: 400,
8575+ Func: Function{"runtime.Epollwait"},
8576+ Args: Args{
8577+ Values: []Arg{
8578+ {Value: 0x4},
8579+ {Value: 0x7fff671c7118},
8580+ {Value: 0xffffffff00000080},
8581+ {},
8582+ {Value: 0xffffffff0028c1be},
8583+ {},
8584+ {},
8585+ {},
8586+ {},
8587+ {},
8588+ },
8589+ Elided: true,
8590+ },
8591+ },
8592+ {
8593+ SourcePath: goroot + "/src/runtime/netpoll_epoll.go",
8594+ Line: 68,
8595+ Func: Function{"runtime.netpoll"},
8596+ Args: Args{Values: []Arg{{Value: 0x901b01}, {}}},
8597+ },
8598+ {
8599+ SourcePath: "/src/main.go",
8600+ Line: 1472,
8601+ Func: Function{"main.Main"},
8602+ Args: Args{Values: []Arg{{Value: 0xc208012000}}},
8603+ },
8604+ {
8605+ SourcePath: "/src/foo/bar.go",
8606+ Line: 1575,
8607+ Func: Function{"foo.OtherExported"},
8608+ },
8609+ {
8610+ SourcePath: "/src/foo/bar.go",
8611+ Line: 10,
8612+ Func: Function{"foo.otherPrivate"},
8613+ },
8614+ },
8615+ Elided: true,
8616+ },
8617+ }
8618+ expected := "" +
8619+ " Eruntime F" + goroot + "/src/runtime/sys_linux_amd64.s:400 HEpollwaitL(0x4, 0x7fff671c7118, 0xffffffff00000080, 0, 0xffffffff0028c1be, 0, 0, 0, 0, 0, ...)A\n" +
8620+ " Eruntime F" + goroot + "/src/runtime/netpoll_epoll.go:68 GnetpollL(0x901b01, 0)A\n" +
8621+ " Emain F/src/main.go:1472 IMainL(0xc208012000)A\n" +
8622+ " Efoo F/src/foo/bar.go:1575 KOtherExportedL()A\n" +
8623+ " Efoo F/src/foo/bar.go:10 JotherPrivateL()A\n" +
8624+ " (...)\n"
8625+ ut.AssertEqual(t, expected, p.StackLines(s, 10, 10, true))
8626+ expected = "" +
8627+ " Eruntime Fsys_linux_amd64.s:400 HEpollwaitL(0x4, 0x7fff671c7118, 0xffffffff00000080, 0, 0xffffffff0028c1be, 0, 0, 0, 0, 0, ...)A\n" +
8628+ " Eruntime Fnetpoll_epoll.go:68 GnetpollL(0x901b01, 0)A\n" +
8629+ " Emain Fmain.go:1472 IMainL(0xc208012000)A\n" +
8630+ " Efoo Fbar.go:1575 KOtherExportedL()A\n" +
8631+ " Efoo Fbar.go:10 JotherPrivateL()A\n" +
8632+ " (...)\n"
8633+ ut.AssertEqual(t, expected, p.StackLines(s, 10, 10, false))
8634+ }
8635 diff --git a/vendor/github.com/mattn/go-colorable/_example/escape-seq/main.go b/vendor/github.com/mattn/go-colorable/_example/escape-seq/main.go
8636deleted file mode 100644
8637index 8cbcb90..0000000
8638--- a/vendor/github.com/mattn/go-colorable/_example/escape-seq/main.go
8639+++ /dev/null
8640 @@ -1,16 +0,0 @@
8641- package main
8642-
8643- import (
8644- "bufio"
8645- "fmt"
8646-
8647- "github.com/mattn/go-colorable"
8648- )
8649-
8650- func main() {
8651- stdOut := bufio.NewWriter(colorable.NewColorableStdout())
8652-
8653- fmt.Fprint(stdOut, "\x1B[3GMove to 3rd Column\n")
8654- fmt.Fprint(stdOut, "\x1B[1;2HMove to 2nd Column on 1st Line\n")
8655- stdOut.Flush()
8656- }
8657 diff --git a/vendor/github.com/mattn/go-colorable/_example/logrus/main.go b/vendor/github.com/mattn/go-colorable/_example/logrus/main.go
8658deleted file mode 100644
8659index c569164..0000000
8660--- a/vendor/github.com/mattn/go-colorable/_example/logrus/main.go
8661+++ /dev/null
8662 @@ -1,16 +0,0 @@
8663- package main
8664-
8665- import (
8666- "github.com/mattn/go-colorable"
8667- "github.com/sirupsen/logrus"
8668- )
8669-
8670- func main() {
8671- logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
8672- logrus.SetOutput(colorable.NewColorableStdout())
8673-
8674- logrus.Info("succeeded")
8675- logrus.Warn("not correct")
8676- logrus.Error("something error")
8677- logrus.Fatal("panic")
8678- }
8679 diff --git a/vendor/github.com/mattn/go-colorable/_example/title/main.go b/vendor/github.com/mattn/go-colorable/_example/title/main.go
8680deleted file mode 100644
8681index e208870..0000000
8682--- a/vendor/github.com/mattn/go-colorable/_example/title/main.go
8683+++ /dev/null
8684 @@ -1,14 +0,0 @@
8685- package main
8686-
8687- import (
8688- "fmt"
8689- "os"
8690- . "github.com/mattn/go-colorable"
8691- )
8692-
8693- func main() {
8694- out := NewColorableStdout()
8695- fmt.Fprint(out, "\x1B]0;TITLE Changed\007(See title and hit any key)")
8696- var c [1]byte
8697- os.Stdin.Read(c[:])
8698- }
8699 diff --git a/vendor/github.com/mattn/go-runewidth/.travis.yml b/vendor/github.com/mattn/go-runewidth/.travis.yml
8700new file mode 100644
8701index 0000000..5c9c2a3
8702--- /dev/null
8703+++ b/vendor/github.com/mattn/go-runewidth/.travis.yml
8704 @@ -0,0 +1,8 @@
8705+ language: go
8706+ go:
8707+ - tip
8708+ before_install:
8709+ - go get github.com/mattn/goveralls
8710+ - go get golang.org/x/tools/cmd/cover
8711+ script:
8712+ - $HOME/gopath/bin/goveralls -repotoken lAKAWPzcGsD3A8yBX3BGGtRUdJ6CaGERL
8713 diff --git a/vendor/github.com/mattn/go-runewidth/LICENSE b/vendor/github.com/mattn/go-runewidth/LICENSE
8714new file mode 100644
8715index 0000000..91b5cef
8716--- /dev/null
8717+++ b/vendor/github.com/mattn/go-runewidth/LICENSE
8718 @@ -0,0 +1,21 @@
8719+ The MIT License (MIT)
8720+
8721+ Copyright (c) 2016 Yasuhiro Matsumoto
8722+
8723+ Permission is hereby granted, free of charge, to any person obtaining a copy
8724+ of this software and associated documentation files (the "Software"), to deal
8725+ in the Software without restriction, including without limitation the rights
8726+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8727+ copies of the Software, and to permit persons to whom the Software is
8728+ furnished to do so, subject to the following conditions:
8729+
8730+ The above copyright notice and this permission notice shall be included in all
8731+ copies or substantial portions of the Software.
8732+
8733+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8734+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8735+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8736+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8737+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
8738+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
8739+ SOFTWARE.
8740 diff --git a/vendor/github.com/mattn/go-runewidth/README.mkd b/vendor/github.com/mattn/go-runewidth/README.mkd
8741new file mode 100644
8742index 0000000..66663a9
8743--- /dev/null
8744+++ b/vendor/github.com/mattn/go-runewidth/README.mkd
8745 @@ -0,0 +1,27 @@
8746+ go-runewidth
8747+ ============
8748+
8749+ [![Build Status](https://travis-ci.org/mattn/go-runewidth.png?branch=master)](https://travis-ci.org/mattn/go-runewidth)
8750+ [![Coverage Status](https://coveralls.io/repos/mattn/go-runewidth/badge.png?branch=HEAD)](https://coveralls.io/r/mattn/go-runewidth?branch=HEAD)
8751+ [![GoDoc](https://godoc.org/github.com/mattn/go-runewidth?status.svg)](http://godoc.org/github.com/mattn/go-runewidth)
8752+ [![Go Report Card](https://goreportcard.com/badge/github.com/mattn/go-runewidth)](https://goreportcard.com/report/github.com/mattn/go-runewidth)
8753+
8754+ Provides functions to get fixed width of the character or string.
8755+
8756+ Usage
8757+ -----
8758+
8759+ ```go
8760+ runewidth.StringWidth("つのだ☆HIRO") == 12
8761+ ```
8762+
8763+
8764+ Author
8765+ ------
8766+
8767+ Yasuhiro Matsumoto
8768+
8769+ License
8770+ -------
8771+
8772+ under the MIT License: http://mattn.mit-license.org/2013
8773 diff --git a/vendor/github.com/mattn/go-runewidth/runewidth.go b/vendor/github.com/mattn/go-runewidth/runewidth.go
8774new file mode 100644
8775index 0000000..2164497
8776--- /dev/null
8777+++ b/vendor/github.com/mattn/go-runewidth/runewidth.go
8778 @@ -0,0 +1,1223 @@
8779+ package runewidth
8780+
8781+ var (
8782+ // EastAsianWidth will be set true if the current locale is CJK
8783+ EastAsianWidth = IsEastAsian()
8784+
8785+ // DefaultCondition is a condition in current locale
8786+ DefaultCondition = &Condition{EastAsianWidth}
8787+ )
8788+
8789+ type interval struct {
8790+ first rune
8791+ last rune
8792+ }
8793+
8794+ type table []interval
8795+
8796+ func inTables(r rune, ts ...table) bool {
8797+ for _, t := range ts {
8798+ if inTable(r, t) {
8799+ return true
8800+ }
8801+ }
8802+ return false
8803+ }
8804+
8805+ func inTable(r rune, t table) bool {
8806+ // func (t table) IncludesRune(r rune) bool {
8807+ if r < t[0].first {
8808+ return false
8809+ }
8810+
8811+ bot := 0
8812+ top := len(t) - 1
8813+ for top >= bot {
8814+ mid := (bot + top) / 2
8815+
8816+ switch {
8817+ case t[mid].last < r:
8818+ bot = mid + 1
8819+ case t[mid].first > r:
8820+ top = mid - 1
8821+ default:
8822+ return true
8823+ }
8824+ }
8825+
8826+ return false
8827+ }
8828+
8829+ var private = table{
8830+ {0x00E000, 0x00F8FF}, {0x0F0000, 0x0FFFFD}, {0x100000, 0x10FFFD},
8831+ }
8832+
8833+ var nonprint = table{
8834+ {0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD},
8835+ {0x070F, 0x070F}, {0x180B, 0x180E}, {0x200B, 0x200F},
8836+ {0x202A, 0x202E}, {0x206A, 0x206F}, {0xD800, 0xDFFF},
8837+ {0xFEFF, 0xFEFF}, {0xFFF9, 0xFFFB}, {0xFFFE, 0xFFFF},
8838+ }
8839+
8840+ var combining = table{
8841+ {0x0300, 0x036F}, {0x0483, 0x0489}, {0x0591, 0x05BD},
8842+ {0x05BF, 0x05BF}, {0x05C1, 0x05C2}, {0x05C4, 0x05C5},
8843+ {0x05C7, 0x05C7}, {0x0610, 0x061A}, {0x064B, 0x065F},
8844+ {0x0670, 0x0670}, {0x06D6, 0x06DC}, {0x06DF, 0x06E4},
8845+ {0x06E7, 0x06E8}, {0x06EA, 0x06ED}, {0x0711, 0x0711},
8846+ {0x0730, 0x074A}, {0x07A6, 0x07B0}, {0x07EB, 0x07F3},
8847+ {0x0816, 0x0819}, {0x081B, 0x0823}, {0x0825, 0x0827},
8848+ {0x0829, 0x082D}, {0x0859, 0x085B}, {0x08D4, 0x08E1},
8849+ {0x08E3, 0x0903}, {0x093A, 0x093C}, {0x093E, 0x094F},
8850+ {0x0951, 0x0957}, {0x0962, 0x0963}, {0x0981, 0x0983},
8851+ {0x09BC, 0x09BC}, {0x09BE, 0x09C4}, {0x09C7, 0x09C8},
8852+ {0x09CB, 0x09CD}, {0x09D7, 0x09D7}, {0x09E2, 0x09E3},
8853+ {0x0A01, 0x0A03}, {0x0A3C, 0x0A3C}, {0x0A3E, 0x0A42},
8854+ {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D}, {0x0A51, 0x0A51},
8855+ {0x0A70, 0x0A71}, {0x0A75, 0x0A75}, {0x0A81, 0x0A83},
8856+ {0x0ABC, 0x0ABC}, {0x0ABE, 0x0AC5}, {0x0AC7, 0x0AC9},
8857+ {0x0ACB, 0x0ACD}, {0x0AE2, 0x0AE3}, {0x0B01, 0x0B03},
8858+ {0x0B3C, 0x0B3C}, {0x0B3E, 0x0B44}, {0x0B47, 0x0B48},
8859+ {0x0B4B, 0x0B4D}, {0x0B56, 0x0B57}, {0x0B62, 0x0B63},
8860+ {0x0B82, 0x0B82}, {0x0BBE, 0x0BC2}, {0x0BC6, 0x0BC8},
8861+ {0x0BCA, 0x0BCD}, {0x0BD7, 0x0BD7}, {0x0C00, 0x0C03},
8862+ {0x0C3E, 0x0C44}, {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D},
8863+ {0x0C55, 0x0C56}, {0x0C62, 0x0C63}, {0x0C81, 0x0C83},
8864+ {0x0CBC, 0x0CBC}, {0x0CBE, 0x0CC4}, {0x0CC6, 0x0CC8},
8865+ {0x0CCA, 0x0CCD}, {0x0CD5, 0x0CD6}, {0x0CE2, 0x0CE3},
8866+ {0x0D01, 0x0D03}, {0x0D3E, 0x0D44}, {0x0D46, 0x0D48},
8867+ {0x0D4A, 0x0D4D}, {0x0D57, 0x0D57}, {0x0D62, 0x0D63},
8868+ {0x0D82, 0x0D83}, {0x0DCA, 0x0DCA}, {0x0DCF, 0x0DD4},
8869+ {0x0DD6, 0x0DD6}, {0x0DD8, 0x0DDF}, {0x0DF2, 0x0DF3},
8870+ {0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E},
8871+ {0x0EB1, 0x0EB1}, {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC},
8872+ {0x0EC8, 0x0ECD}, {0x0F18, 0x0F19}, {0x0F35, 0x0F35},
8873+ {0x0F37, 0x0F37}, {0x0F39, 0x0F39}, {0x0F3E, 0x0F3F},
8874+ {0x0F71, 0x0F84}, {0x0F86, 0x0F87}, {0x0F8D, 0x0F97},
8875+ {0x0F99, 0x0FBC}, {0x0FC6, 0x0FC6}, {0x102B, 0x103E},
8876+ {0x1056, 0x1059}, {0x105E, 0x1060}, {0x1062, 0x1064},
8877+ {0x1067, 0x106D}, {0x1071, 0x1074}, {0x1082, 0x108D},
8878+ {0x108F, 0x108F}, {0x109A, 0x109D}, {0x135D, 0x135F},
8879+ {0x1712, 0x1714}, {0x1732, 0x1734}, {0x1752, 0x1753},
8880+ {0x1772, 0x1773}, {0x17B4, 0x17D3}, {0x17DD, 0x17DD},
8881+ {0x180B, 0x180D}, {0x1885, 0x1886}, {0x18A9, 0x18A9},
8882+ {0x1920, 0x192B}, {0x1930, 0x193B}, {0x1A17, 0x1A1B},
8883+ {0x1A55, 0x1A5E}, {0x1A60, 0x1A7C}, {0x1A7F, 0x1A7F},
8884+ {0x1AB0, 0x1ABE}, {0x1B00, 0x1B04}, {0x1B34, 0x1B44},
8885+ {0x1B6B, 0x1B73}, {0x1B80, 0x1B82}, {0x1BA1, 0x1BAD},
8886+ {0x1BE6, 0x1BF3}, {0x1C24, 0x1C37}, {0x1CD0, 0x1CD2},
8887+ {0x1CD4, 0x1CE8}, {0x1CED, 0x1CED}, {0x1CF2, 0x1CF4},
8888+ {0x1CF8, 0x1CF9}, {0x1DC0, 0x1DF5}, {0x1DFB, 0x1DFF},
8889+ {0x20D0, 0x20F0}, {0x2CEF, 0x2CF1}, {0x2D7F, 0x2D7F},
8890+ {0x2DE0, 0x2DFF}, {0x302A, 0x302F}, {0x3099, 0x309A},
8891+ {0xA66F, 0xA672}, {0xA674, 0xA67D}, {0xA69E, 0xA69F},
8892+ {0xA6F0, 0xA6F1}, {0xA802, 0xA802}, {0xA806, 0xA806},
8893+ {0xA80B, 0xA80B}, {0xA823, 0xA827}, {0xA880, 0xA881},
8894+ {0xA8B4, 0xA8C5}, {0xA8E0, 0xA8F1}, {0xA926, 0xA92D},
8895+ {0xA947, 0xA953}, {0xA980, 0xA983}, {0xA9B3, 0xA9C0},
8896+ {0xA9E5, 0xA9E5}, {0xAA29, 0xAA36}, {0xAA43, 0xAA43},
8897+ {0xAA4C, 0xAA4D}, {0xAA7B, 0xAA7D}, {0xAAB0, 0xAAB0},
8898+ {0xAAB2, 0xAAB4}, {0xAAB7, 0xAAB8}, {0xAABE, 0xAABF},
8899+ {0xAAC1, 0xAAC1}, {0xAAEB, 0xAAEF}, {0xAAF5, 0xAAF6},
8900+ {0xABE3, 0xABEA}, {0xABEC, 0xABED}, {0xFB1E, 0xFB1E},
8901+ {0xFE00, 0xFE0F}, {0xFE20, 0xFE2F}, {0x101FD, 0x101FD},
8902+ {0x102E0, 0x102E0}, {0x10376, 0x1037A}, {0x10A01, 0x10A03},
8903+ {0x10A05, 0x10A06}, {0x10A0C, 0x10A0F}, {0x10A38, 0x10A3A},
8904+ {0x10A3F, 0x10A3F}, {0x10AE5, 0x10AE6}, {0x11000, 0x11002},
8905+ {0x11038, 0x11046}, {0x1107F, 0x11082}, {0x110B0, 0x110BA},
8906+ {0x11100, 0x11102}, {0x11127, 0x11134}, {0x11173, 0x11173},
8907+ {0x11180, 0x11182}, {0x111B3, 0x111C0}, {0x111CA, 0x111CC},
8908+ {0x1122C, 0x11237}, {0x1123E, 0x1123E}, {0x112DF, 0x112EA},
8909+ {0x11300, 0x11303}, {0x1133C, 0x1133C}, {0x1133E, 0x11344},
8910+ {0x11347, 0x11348}, {0x1134B, 0x1134D}, {0x11357, 0x11357},
8911+ {0x11362, 0x11363}, {0x11366, 0x1136C}, {0x11370, 0x11374},
8912+ {0x11435, 0x11446}, {0x114B0, 0x114C3}, {0x115AF, 0x115B5},
8913+ {0x115B8, 0x115C0}, {0x115DC, 0x115DD}, {0x11630, 0x11640},
8914+ {0x116AB, 0x116B7}, {0x1171D, 0x1172B}, {0x11C2F, 0x11C36},
8915+ {0x11C38, 0x11C3F}, {0x11C92, 0x11CA7}, {0x11CA9, 0x11CB6},
8916+ {0x16AF0, 0x16AF4}, {0x16B30, 0x16B36}, {0x16F51, 0x16F7E},
8917+ {0x16F8F, 0x16F92}, {0x1BC9D, 0x1BC9E}, {0x1D165, 0x1D169},
8918+ {0x1D16D, 0x1D172}, {0x1D17B, 0x1D182}, {0x1D185, 0x1D18B},
8919+ {0x1D1AA, 0x1D1AD}, {0x1D242, 0x1D244}, {0x1DA00, 0x1DA36},
8920+ {0x1DA3B, 0x1DA6C}, {0x1DA75, 0x1DA75}, {0x1DA84, 0x1DA84},
8921+ {0x1DA9B, 0x1DA9F}, {0x1DAA1, 0x1DAAF}, {0x1E000, 0x1E006},
8922+ {0x1E008, 0x1E018}, {0x1E01B, 0x1E021}, {0x1E023, 0x1E024},
8923+ {0x1E026, 0x1E02A}, {0x1E8D0, 0x1E8D6}, {0x1E944, 0x1E94A},
8924+ {0xE0100, 0xE01EF},
8925+ }
8926+
8927+ var doublewidth = table{
8928+ {0x1100, 0x115F}, {0x231A, 0x231B}, {0x2329, 0x232A},
8929+ {0x23E9, 0x23EC}, {0x23F0, 0x23F0}, {0x23F3, 0x23F3},
8930+ {0x25FD, 0x25FE}, {0x2614, 0x2615}, {0x2648, 0x2653},
8931+ {0x267F, 0x267F}, {0x2693, 0x2693}, {0x26A1, 0x26A1},
8932+ {0x26AA, 0x26AB}, {0x26BD, 0x26BE}, {0x26C4, 0x26C5},
8933+ {0x26CE, 0x26CE}, {0x26D4, 0x26D4}, {0x26EA, 0x26EA},
8934+ {0x26F2, 0x26F3}, {0x26F5, 0x26F5}, {0x26FA, 0x26FA},
8935+ {0x26FD, 0x26FD}, {0x2705, 0x2705}, {0x270A, 0x270B},
8936+ {0x2728, 0x2728}, {0x274C, 0x274C}, {0x274E, 0x274E},
8937+ {0x2753, 0x2755}, {0x2757, 0x2757}, {0x2795, 0x2797},
8938+ {0x27B0, 0x27B0}, {0x27BF, 0x27BF}, {0x2B1B, 0x2B1C},
8939+ {0x2B50, 0x2B50}, {0x2B55, 0x2B55}, {0x2E80, 0x2E99},
8940+ {0x2E9B, 0x2EF3}, {0x2F00, 0x2FD5}, {0x2FF0, 0x2FFB},
8941+ {0x3000, 0x303E}, {0x3041, 0x3096}, {0x3099, 0x30FF},
8942+ {0x3105, 0x312D}, {0x3131, 0x318E}, {0x3190, 0x31BA},
8943+ {0x31C0, 0x31E3}, {0x31F0, 0x321E}, {0x3220, 0x3247},
8944+ {0x3250, 0x32FE}, {0x3300, 0x4DBF}, {0x4E00, 0xA48C},
8945+ {0xA490, 0xA4C6}, {0xA960, 0xA97C}, {0xAC00, 0xD7A3},
8946+ {0xF900, 0xFAFF}, {0xFE10, 0xFE19}, {0xFE30, 0xFE52},
8947+ {0xFE54, 0xFE66}, {0xFE68, 0xFE6B}, {0xFF01, 0xFF60},
8948+ {0xFFE0, 0xFFE6}, {0x16FE0, 0x16FE0}, {0x17000, 0x187EC},
8949+ {0x18800, 0x18AF2}, {0x1B000, 0x1B001}, {0x1F004, 0x1F004},
8950+ {0x1F0CF, 0x1F0CF}, {0x1F18E, 0x1F18E}, {0x1F191, 0x1F19A},
8951+ {0x1F200, 0x1F202}, {0x1F210, 0x1F23B}, {0x1F240, 0x1F248},
8952+ {0x1F250, 0x1F251}, {0x1F300, 0x1F320}, {0x1F32D, 0x1F335},
8953+ {0x1F337, 0x1F37C}, {0x1F37E, 0x1F393}, {0x1F3A0, 0x1F3CA},
8954+ {0x1F3CF, 0x1F3D3}, {0x1F3E0, 0x1F3F0}, {0x1F3F4, 0x1F3F4},
8955+ {0x1F3F8, 0x1F43E}, {0x1F440, 0x1F440}, {0x1F442, 0x1F4FC},
8956+ {0x1F4FF, 0x1F53D}, {0x1F54B, 0x1F54E}, {0x1F550, 0x1F567},
8957+ {0x1F57A, 0x1F57A}, {0x1F595, 0x1F596}, {0x1F5A4, 0x1F5A4},
8958+ {0x1F5FB, 0x1F64F}, {0x1F680, 0x1F6C5}, {0x1F6CC, 0x1F6CC},
8959+ {0x1F6D0, 0x1F6D2}, {0x1F6EB, 0x1F6EC}, {0x1F6F4, 0x1F6F6},
8960+ {0x1F910, 0x1F91E}, {0x1F920, 0x1F927}, {0x1F930, 0x1F930},
8961+ {0x1F933, 0x1F93E}, {0x1F940, 0x1F94B}, {0x1F950, 0x1F95E},
8962+ {0x1F980, 0x1F991}, {0x1F9C0, 0x1F9C0}, {0x20000, 0x2FFFD},
8963+ {0x30000, 0x3FFFD},
8964+ }
8965+
8966+ var ambiguous = table{
8967+ {0x00A1, 0x00A1}, {0x00A4, 0x00A4}, {0x00A7, 0x00A8},
8968+ {0x00AA, 0x00AA}, {0x00AD, 0x00AE}, {0x00B0, 0x00B4},
8969+ {0x00B6, 0x00BA}, {0x00BC, 0x00BF}, {0x00C6, 0x00C6},
8970+ {0x00D0, 0x00D0}, {0x00D7, 0x00D8}, {0x00DE, 0x00E1},
8971+ {0x00E6, 0x00E6}, {0x00E8, 0x00EA}, {0x00EC, 0x00ED},
8972+ {0x00F0, 0x00F0}, {0x00F2, 0x00F3}, {0x00F7, 0x00FA},
8973+ {0x00FC, 0x00FC}, {0x00FE, 0x00FE}, {0x0101, 0x0101},
8974+ {0x0111, 0x0111}, {0x0113, 0x0113}, {0x011B, 0x011B},
8975+ {0x0126, 0x0127}, {0x012B, 0x012B}, {0x0131, 0x0133},
8976+ {0x0138, 0x0138}, {0x013F, 0x0142}, {0x0144, 0x0144},
8977+ {0x0148, 0x014B}, {0x014D, 0x014D}, {0x0152, 0x0153},
8978+ {0x0166, 0x0167}, {0x016B, 0x016B}, {0x01CE, 0x01CE},
8979+ {0x01D0, 0x01D0}, {0x01D2, 0x01D2}, {0x01D4, 0x01D4},
8980+ {0x01D6, 0x01D6}, {0x01D8, 0x01D8}, {0x01DA, 0x01DA},
8981+ {0x01DC, 0x01DC}, {0x0251, 0x0251}, {0x0261, 0x0261},
8982+ {0x02C4, 0x02C4}, {0x02C7, 0x02C7}, {0x02C9, 0x02CB},
8983+ {0x02CD, 0x02CD}, {0x02D0, 0x02D0}, {0x02D8, 0x02DB},
8984+ {0x02DD, 0x02DD}, {0x02DF, 0x02DF}, {0x0300, 0x036F},
8985+ {0x0391, 0x03A1}, {0x03A3, 0x03A9}, {0x03B1, 0x03C1},
8986+ {0x03C3, 0x03C9}, {0x0401, 0x0401}, {0x0410, 0x044F},
8987+ {0x0451, 0x0451}, {0x2010, 0x2010}, {0x2013, 0x2016},
8988+ {0x2018, 0x2019}, {0x201C, 0x201D}, {0x2020, 0x2022},
8989+ {0x2024, 0x2027}, {0x2030, 0x2030}, {0x2032, 0x2033},
8990+ {0x2035, 0x2035}, {0x203B, 0x203B}, {0x203E, 0x203E},
8991+ {0x2074, 0x2074}, {0x207F, 0x207F}, {0x2081, 0x2084},
8992+ {0x20AC, 0x20AC}, {0x2103, 0x2103}, {0x2105, 0x2105},
8993+ {0x2109, 0x2109}, {0x2113, 0x2113}, {0x2116, 0x2116},
8994+ {0x2121, 0x2122}, {0x2126, 0x2126}, {0x212B, 0x212B},
8995+ {0x2153, 0x2154}, {0x215B, 0x215E}, {0x2160, 0x216B},
8996+ {0x2170, 0x2179}, {0x2189, 0x2189}, {0x2190, 0x2199},
8997+ {0x21B8, 0x21B9}, {0x21D2, 0x21D2}, {0x21D4, 0x21D4},
8998+ {0x21E7, 0x21E7}, {0x2200, 0x2200}, {0x2202, 0x2203},
8999+ {0x2207, 0x2208}, {0x220B, 0x220B}, {0x220F, 0x220F},
9000+ {0x2211, 0x2211}, {0x2215, 0x2215}, {0x221A, 0x221A},
9001+ {0x221D, 0x2220}, {0x2223, 0x2223}, {0x2225, 0x2225},
9002+ {0x2227, 0x222C}, {0x222E, 0x222E}, {0x2234, 0x2237},
9003+ {0x223C, 0x223D}, {0x2248, 0x2248}, {0x224C, 0x224C},
9004+ {0x2252, 0x2252}, {0x2260, 0x2261}, {0x2264, 0x2267},
9005+ {0x226A, 0x226B}, {0x226E, 0x226F}, {0x2282, 0x2283},
9006+ {0x2286, 0x2287}, {0x2295, 0x2295}, {0x2299, 0x2299},
9007+ {0x22A5, 0x22A5}, {0x22BF, 0x22BF}, {0x2312, 0x2312},
9008+ {0x2460, 0x24E9}, {0x24EB, 0x254B}, {0x2550, 0x2573},
9009+ {0x2580, 0x258F}, {0x2592, 0x2595}, {0x25A0, 0x25A1},
9010+ {0x25A3, 0x25A9}, {0x25B2, 0x25B3}, {0x25B6, 0x25B7},
9011+ {0x25BC, 0x25BD}, {0x25C0, 0x25C1}, {0x25C6, 0x25C8},
9012+ {0x25CB, 0x25CB}, {0x25CE, 0x25D1}, {0x25E2, 0x25E5},
9013+ {0x25EF, 0x25EF}, {0x2605, 0x2606}, {0x2609, 0x2609},
9014+ {0x260E, 0x260F}, {0x261C, 0x261C}, {0x261E, 0x261E},
9015+ {0x2640, 0x2640}, {0x2642, 0x2642}, {0x2660, 0x2661},
9016+ {0x2663, 0x2665}, {0x2667, 0x266A}, {0x266C, 0x266D},
9017+ {0x266F, 0x266F}, {0x269E, 0x269F}, {0x26BF, 0x26BF},
9018+ {0x26C6, 0x26CD}, {0x26CF, 0x26D3}, {0x26D5, 0x26E1},
9019+ {0x26E3, 0x26E3}, {0x26E8, 0x26E9}, {0x26EB, 0x26F1},
9020+ {0x26F4, 0x26F4}, {0x26F6, 0x26F9}, {0x26FB, 0x26FC},
9021+ {0x26FE, 0x26FF}, {0x273D, 0x273D}, {0x2776, 0x277F},
9022+ {0x2B56, 0x2B59}, {0x3248, 0x324F}, {0xE000, 0xF8FF},
9023+ {0xFE00, 0xFE0F}, {0xFFFD, 0xFFFD}, {0x1F100, 0x1F10A},
9024+ {0x1F110, 0x1F12D}, {0x1F130, 0x1F169}, {0x1F170, 0x1F18D},
9025+ {0x1F18F, 0x1F190}, {0x1F19B, 0x1F1AC}, {0xE0100, 0xE01EF},
9026+ {0xF0000, 0xFFFFD}, {0x100000, 0x10FFFD},
9027+ }
9028+
9029+ var emoji = table{
9030+ {0x1F1E6, 0x1F1FF}, {0x1F321, 0x1F321}, {0x1F324, 0x1F32C},
9031+ {0x1F336, 0x1F336}, {0x1F37D, 0x1F37D}, {0x1F396, 0x1F397},
9032+ {0x1F399, 0x1F39B}, {0x1F39E, 0x1F39F}, {0x1F3CB, 0x1F3CE},
9033+ {0x1F3D4, 0x1F3DF}, {0x1F3F3, 0x1F3F5}, {0x1F3F7, 0x1F3F7},
9034+ {0x1F43F, 0x1F43F}, {0x1F441, 0x1F441}, {0x1F4FD, 0x1F4FD},
9035+ {0x1F549, 0x1F54A}, {0x1F56F, 0x1F570}, {0x1F573, 0x1F579},
9036+ {0x1F587, 0x1F587}, {0x1F58A, 0x1F58D}, {0x1F590, 0x1F590},
9037+ {0x1F5A5, 0x1F5A5}, {0x1F5A8, 0x1F5A8}, {0x1F5B1, 0x1F5B2},
9038+ {0x1F5BC, 0x1F5BC}, {0x1F5C2, 0x1F5C4}, {0x1F5D1, 0x1F5D3},
9039+ {0x1F5DC, 0x1F5DE}, {0x1F5E1, 0x1F5E1}, {0x1F5E3, 0x1F5E3},
9040+ {0x1F5E8, 0x1F5E8}, {0x1F5EF, 0x1F5EF}, {0x1F5F3, 0x1F5F3},
9041+ {0x1F5FA, 0x1F5FA}, {0x1F6CB, 0x1F6CF}, {0x1F6E0, 0x1F6E5},
9042+ {0x1F6E9, 0x1F6E9}, {0x1F6F0, 0x1F6F0}, {0x1F6F3, 0x1F6F3},
9043+ }
9044+
9045+ var notassigned = table{
9046+ {0x0378, 0x0379}, {0x0380, 0x0383}, {0x038B, 0x038B},
9047+ {0x038D, 0x038D}, {0x03A2, 0x03A2}, {0x0530, 0x0530},
9048+ {0x0557, 0x0558}, {0x0560, 0x0560}, {0x0588, 0x0588},
9049+ {0x058B, 0x058C}, {0x0590, 0x0590}, {0x05C8, 0x05CF},
9050+ {0x05EB, 0x05EF}, {0x05F5, 0x05FF}, {0x061D, 0x061D},
9051+ {0x070E, 0x070E}, {0x074B, 0x074C}, {0x07B2, 0x07BF},
9052+ {0x07FB, 0x07FF}, {0x082E, 0x082F}, {0x083F, 0x083F},
9053+ {0x085C, 0x085D}, {0x085F, 0x089F}, {0x08B5, 0x08B5},
9054+ {0x08BE, 0x08D3}, {0x0984, 0x0984}, {0x098D, 0x098E},
9055+ {0x0991, 0x0992}, {0x09A9, 0x09A9}, {0x09B1, 0x09B1},
9056+ {0x09B3, 0x09B5}, {0x09BA, 0x09BB}, {0x09C5, 0x09C6},
9057+ {0x09C9, 0x09CA}, {0x09CF, 0x09D6}, {0x09D8, 0x09DB},
9058+ {0x09DE, 0x09DE}, {0x09E4, 0x09E5}, {0x09FC, 0x0A00},
9059+ {0x0A04, 0x0A04}, {0x0A0B, 0x0A0E}, {0x0A11, 0x0A12},
9060+ {0x0A29, 0x0A29}, {0x0A31, 0x0A31}, {0x0A34, 0x0A34},
9061+ {0x0A37, 0x0A37}, {0x0A3A, 0x0A3B}, {0x0A3D, 0x0A3D},
9062+ {0x0A43, 0x0A46}, {0x0A49, 0x0A4A}, {0x0A4E, 0x0A50},
9063+ {0x0A52, 0x0A58}, {0x0A5D, 0x0A5D}, {0x0A5F, 0x0A65},
9064+ {0x0A76, 0x0A80}, {0x0A84, 0x0A84}, {0x0A8E, 0x0A8E},
9065+ {0x0A92, 0x0A92}, {0x0AA9, 0x0AA9}, {0x0AB1, 0x0AB1},
9066+ {0x0AB4, 0x0AB4}, {0x0ABA, 0x0ABB}, {0x0AC6, 0x0AC6},
9067+ {0x0ACA, 0x0ACA}, {0x0ACE, 0x0ACF}, {0x0AD1, 0x0ADF},
9068+ {0x0AE4, 0x0AE5}, {0x0AF2, 0x0AF8}, {0x0AFA, 0x0B00},
9069+ {0x0B04, 0x0B04}, {0x0B0D, 0x0B0E}, {0x0B11, 0x0B12},
9070+ {0x0B29, 0x0B29}, {0x0B31, 0x0B31}, {0x0B34, 0x0B34},
9071+ {0x0B3A, 0x0B3B}, {0x0B45, 0x0B46}, {0x0B49, 0x0B4A},
9072+ {0x0B4E, 0x0B55}, {0x0B58, 0x0B5B}, {0x0B5E, 0x0B5E},
9073+ {0x0B64, 0x0B65}, {0x0B78, 0x0B81}, {0x0B84, 0x0B84},
9074+ {0x0B8B, 0x0B8D}, {0x0B91, 0x0B91}, {0x0B96, 0x0B98},
9075+ {0x0B9B, 0x0B9B}, {0x0B9D, 0x0B9D}, {0x0BA0, 0x0BA2},
9076+ {0x0BA5, 0x0BA7}, {0x0BAB, 0x0BAD}, {0x0BBA, 0x0BBD},
9077+ {0x0BC3, 0x0BC5}, {0x0BC9, 0x0BC9}, {0x0BCE, 0x0BCF},
9078+ {0x0BD1, 0x0BD6}, {0x0BD8, 0x0BE5}, {0x0BFB, 0x0BFF},
9079+ {0x0C04, 0x0C04}, {0x0C0D, 0x0C0D}, {0x0C11, 0x0C11},
9080+ {0x0C29, 0x0C29}, {0x0C3A, 0x0C3C}, {0x0C45, 0x0C45},
9081+ {0x0C49, 0x0C49}, {0x0C4E, 0x0C54}, {0x0C57, 0x0C57},
9082+ {0x0C5B, 0x0C5F}, {0x0C64, 0x0C65}, {0x0C70, 0x0C77},
9083+ {0x0C84, 0x0C84}, {0x0C8D, 0x0C8D}, {0x0C91, 0x0C91},
9084+ {0x0CA9, 0x0CA9}, {0x0CB4, 0x0CB4}, {0x0CBA, 0x0CBB},
9085+ {0x0CC5, 0x0CC5}, {0x0CC9, 0x0CC9}, {0x0CCE, 0x0CD4},
9086+ {0x0CD7, 0x0CDD}, {0x0CDF, 0x0CDF}, {0x0CE4, 0x0CE5},
9087+ {0x0CF0, 0x0CF0}, {0x0CF3, 0x0D00}, {0x0D04, 0x0D04},
9088+ {0x0D0D, 0x0D0D}, {0x0D11, 0x0D11}, {0x0D3B, 0x0D3C},
9089+ {0x0D45, 0x0D45}, {0x0D49, 0x0D49}, {0x0D50, 0x0D53},
9090+ {0x0D64, 0x0D65}, {0x0D80, 0x0D81}, {0x0D84, 0x0D84},
9091+ {0x0D97, 0x0D99}, {0x0DB2, 0x0DB2}, {0x0DBC, 0x0DBC},
9092+ {0x0DBE, 0x0DBF}, {0x0DC7, 0x0DC9}, {0x0DCB, 0x0DCE},
9093+ {0x0DD5, 0x0DD5}, {0x0DD7, 0x0DD7}, {0x0DE0, 0x0DE5},
9094+ {0x0DF0, 0x0DF1}, {0x0DF5, 0x0E00}, {0x0E3B, 0x0E3E},
9095+ {0x0E5C, 0x0E80}, {0x0E83, 0x0E83}, {0x0E85, 0x0E86},
9096+ {0x0E89, 0x0E89}, {0x0E8B, 0x0E8C}, {0x0E8E, 0x0E93},
9097+ {0x0E98, 0x0E98}, {0x0EA0, 0x0EA0}, {0x0EA4, 0x0EA4},
9098+ {0x0EA6, 0x0EA6}, {0x0EA8, 0x0EA9}, {0x0EAC, 0x0EAC},
9099+ {0x0EBA, 0x0EBA}, {0x0EBE, 0x0EBF}, {0x0EC5, 0x0EC5},
9100+ {0x0EC7, 0x0EC7}, {0x0ECE, 0x0ECF}, {0x0EDA, 0x0EDB},
9101+ {0x0EE0, 0x0EFF}, {0x0F48, 0x0F48}, {0x0F6D, 0x0F70},
9102+ {0x0F98, 0x0F98}, {0x0FBD, 0x0FBD}, {0x0FCD, 0x0FCD},
9103+ {0x0FDB, 0x0FFF}, {0x10C6, 0x10C6}, {0x10C8, 0x10CC},
9104+ {0x10CE, 0x10CF}, {0x1249, 0x1249}, {0x124E, 0x124F},
9105+ {0x1257, 0x1257}, {0x1259, 0x1259}, {0x125E, 0x125F},
9106+ {0x1289, 0x1289}, {0x128E, 0x128F}, {0x12B1, 0x12B1},
9107+ {0x12B6, 0x12B7}, {0x12BF, 0x12BF}, {0x12C1, 0x12C1},
9108+ {0x12C6, 0x12C7}, {0x12D7, 0x12D7}, {0x1311, 0x1311},
9109+ {0x1316, 0x1317}, {0x135B, 0x135C}, {0x137D, 0x137F},
9110+ {0x139A, 0x139F}, {0x13F6, 0x13F7}, {0x13FE, 0x13FF},
9111+ {0x169D, 0x169F}, {0x16F9, 0x16FF}, {0x170D, 0x170D},
9112+ {0x1715, 0x171F}, {0x1737, 0x173F}, {0x1754, 0x175F},
9113+ {0x176D, 0x176D}, {0x1771, 0x1771}, {0x1774, 0x177F},
9114+ {0x17DE, 0x17DF}, {0x17EA, 0x17EF}, {0x17FA, 0x17FF},
9115+ {0x180F, 0x180F}, {0x181A, 0x181F}, {0x1878, 0x187F},
9116+ {0x18AB, 0x18AF}, {0x18F6, 0x18FF}, {0x191F, 0x191F},
9117+ {0x192C, 0x192F}, {0x193C, 0x193F}, {0x1941, 0x1943},
9118+ {0x196E, 0x196F}, {0x1975, 0x197F}, {0x19AC, 0x19AF},
9119+ {0x19CA, 0x19CF}, {0x19DB, 0x19DD}, {0x1A1C, 0x1A1D},
9120+ {0x1A5F, 0x1A5F}, {0x1A7D, 0x1A7E}, {0x1A8A, 0x1A8F},
9121+ {0x1A9A, 0x1A9F}, {0x1AAE, 0x1AAF}, {0x1ABF, 0x1AFF},
9122+ {0x1B4C, 0x1B4F}, {0x1B7D, 0x1B7F}, {0x1BF4, 0x1BFB},
9123+ {0x1C38, 0x1C3A}, {0x1C4A, 0x1C4C}, {0x1C89, 0x1CBF},
9124+ {0x1CC8, 0x1CCF}, {0x1CF7, 0x1CF7}, {0x1CFA, 0x1CFF},
9125+ {0x1DF6, 0x1DFA}, {0x1F16, 0x1F17}, {0x1F1E, 0x1F1F},
9126+ {0x1F46, 0x1F47}, {0x1F4E, 0x1F4F}, {0x1F58, 0x1F58},
9127+ {0x1F5A, 0x1F5A}, {0x1F5C, 0x1F5C}, {0x1F5E, 0x1F5E},
9128+ {0x1F7E, 0x1F7F}, {0x1FB5, 0x1FB5}, {0x1FC5, 0x1FC5},
9129+ {0x1FD4, 0x1FD5}, {0x1FDC, 0x1FDC}, {0x1FF0, 0x1FF1},
9130+ {0x1FF5, 0x1FF5}, {0x1FFF, 0x1FFF}, {0x2065, 0x2065},
9131+ {0x2072, 0x2073}, {0x208F, 0x208F}, {0x209D, 0x209F},
9132+ {0x20BF, 0x20CF}, {0x20F1, 0x20FF}, {0x218C, 0x218F},
9133+ {0x23FF, 0x23FF}, {0x2427, 0x243F}, {0x244B, 0x245F},
9134+ {0x2B74, 0x2B75}, {0x2B96, 0x2B97}, {0x2BBA, 0x2BBC},
9135+ {0x2BC9, 0x2BC9}, {0x2BD2, 0x2BEB}, {0x2BF0, 0x2BFF},
9136+ {0x2C2F, 0x2C2F}, {0x2C5F, 0x2C5F}, {0x2CF4, 0x2CF8},
9137+ {0x2D26, 0x2D26}, {0x2D28, 0x2D2C}, {0x2D2E, 0x2D2F},
9138+ {0x2D68, 0x2D6E}, {0x2D71, 0x2D7E}, {0x2D97, 0x2D9F},
9139+ {0x2DA7, 0x2DA7}, {0x2DAF, 0x2DAF}, {0x2DB7, 0x2DB7},
9140+ {0x2DBF, 0x2DBF}, {0x2DC7, 0x2DC7}, {0x2DCF, 0x2DCF},
9141+ {0x2DD7, 0x2DD7}, {0x2DDF, 0x2DDF}, {0x2E45, 0x2E7F},
9142+ {0x2E9A, 0x2E9A}, {0x2EF4, 0x2EFF}, {0x2FD6, 0x2FEF},
9143+ {0x2FFC, 0x2FFF}, {0x3040, 0x3040}, {0x3097, 0x3098},
9144+ {0x3100, 0x3104}, {0x312E, 0x3130}, {0x318F, 0x318F},
9145+ {0x31BB, 0x31BF}, {0x31E4, 0x31EF}, {0x321F, 0x321F},
9146+ {0x32FF, 0x32FF}, {0x4DB6, 0x4DBF}, {0x9FD6, 0x9FFF},
9147+ {0xA48D, 0xA48F}, {0xA4C7, 0xA4CF}, {0xA62C, 0xA63F},
9148+ {0xA6F8, 0xA6FF}, {0xA7AF, 0xA7AF}, {0xA7B8, 0xA7F6},
9149+ {0xA82C, 0xA82F}, {0xA83A, 0xA83F}, {0xA878, 0xA87F},
9150+ {0xA8C6, 0xA8CD}, {0xA8DA, 0xA8DF}, {0xA8FE, 0xA8FF},
9151+ {0xA954, 0xA95E}, {0xA97D, 0xA97F}, {0xA9CE, 0xA9CE},
9152+ {0xA9DA, 0xA9DD}, {0xA9FF, 0xA9FF}, {0xAA37, 0xAA3F},
9153+ {0xAA4E, 0xAA4F}, {0xAA5A, 0xAA5B}, {0xAAC3, 0xAADA},
9154+ {0xAAF7, 0xAB00}, {0xAB07, 0xAB08}, {0xAB0F, 0xAB10},
9155+ {0xAB17, 0xAB1F}, {0xAB27, 0xAB27}, {0xAB2F, 0xAB2F},
9156+ {0xAB66, 0xAB6F}, {0xABEE, 0xABEF}, {0xABFA, 0xABFF},
9157+ {0xD7A4, 0xD7AF}, {0xD7C7, 0xD7CA}, {0xD7FC, 0xD7FF},
9158+ {0xFA6E, 0xFA6F}, {0xFADA, 0xFAFF}, {0xFB07, 0xFB12},
9159+ {0xFB18, 0xFB1C}, {0xFB37, 0xFB37}, {0xFB3D, 0xFB3D},
9160+ {0xFB3F, 0xFB3F}, {0xFB42, 0xFB42}, {0xFB45, 0xFB45},
9161+ {0xFBC2, 0xFBD2}, {0xFD40, 0xFD4F}, {0xFD90, 0xFD91},
9162+ {0xFDC8, 0xFDEF}, {0xFDFE, 0xFDFF}, {0xFE1A, 0xFE1F},
9163+ {0xFE53, 0xFE53}, {0xFE67, 0xFE67}, {0xFE6C, 0xFE6F},
9164+ {0xFE75, 0xFE75}, {0xFEFD, 0xFEFE}, {0xFF00, 0xFF00},
9165+ {0xFFBF, 0xFFC1}, {0xFFC8, 0xFFC9}, {0xFFD0, 0xFFD1},
9166+ {0xFFD8, 0xFFD9}, {0xFFDD, 0xFFDF}, {0xFFE7, 0xFFE7},
9167+ {0xFFEF, 0xFFF8}, {0xFFFE, 0xFFFF}, {0x1000C, 0x1000C},
9168+ {0x10027, 0x10027}, {0x1003B, 0x1003B}, {0x1003E, 0x1003E},
9169+ {0x1004E, 0x1004F}, {0x1005E, 0x1007F}, {0x100FB, 0x100FF},
9170+ {0x10103, 0x10106}, {0x10134, 0x10136}, {0x1018F, 0x1018F},
9171+ {0x1019C, 0x1019F}, {0x101A1, 0x101CF}, {0x101FE, 0x1027F},
9172+ {0x1029D, 0x1029F}, {0x102D1, 0x102DF}, {0x102FC, 0x102FF},
9173+ {0x10324, 0x1032F}, {0x1034B, 0x1034F}, {0x1037B, 0x1037F},
9174+ {0x1039E, 0x1039E}, {0x103C4, 0x103C7}, {0x103D6, 0x103FF},
9175+ {0x1049E, 0x1049F}, {0x104AA, 0x104AF}, {0x104D4, 0x104D7},
9176+ {0x104FC, 0x104FF}, {0x10528, 0x1052F}, {0x10564, 0x1056E},
9177+ {0x10570, 0x105FF}, {0x10737, 0x1073F}, {0x10756, 0x1075F},
9178+ {0x10768, 0x107FF}, {0x10806, 0x10807}, {0x10809, 0x10809},
9179+ {0x10836, 0x10836}, {0x10839, 0x1083B}, {0x1083D, 0x1083E},
9180+ {0x10856, 0x10856}, {0x1089F, 0x108A6}, {0x108B0, 0x108DF},
9181+ {0x108F3, 0x108F3}, {0x108F6, 0x108FA}, {0x1091C, 0x1091E},
9182+ {0x1093A, 0x1093E}, {0x10940, 0x1097F}, {0x109B8, 0x109BB},
9183+ {0x109D0, 0x109D1}, {0x10A04, 0x10A04}, {0x10A07, 0x10A0B},
9184+ {0x10A14, 0x10A14}, {0x10A18, 0x10A18}, {0x10A34, 0x10A37},
9185+ {0x10A3B, 0x10A3E}, {0x10A48, 0x10A4F}, {0x10A59, 0x10A5F},
9186+ {0x10AA0, 0x10ABF}, {0x10AE7, 0x10AEA}, {0x10AF7, 0x10AFF},
9187+ {0x10B36, 0x10B38}, {0x10B56, 0x10B57}, {0x10B73, 0x10B77},
9188+ {0x10B92, 0x10B98}, {0x10B9D, 0x10BA8}, {0x10BB0, 0x10BFF},
9189+ {0x10C49, 0x10C7F}, {0x10CB3, 0x10CBF}, {0x10CF3, 0x10CF9},
9190+ {0x10D00, 0x10E5F}, {0x10E7F, 0x10FFF}, {0x1104E, 0x11051},
9191+ {0x11070, 0x1107E}, {0x110C2, 0x110CF}, {0x110E9, 0x110EF},
9192+ {0x110FA, 0x110FF}, {0x11135, 0x11135}, {0x11144, 0x1114F},
9193+ {0x11177, 0x1117F}, {0x111CE, 0x111CF}, {0x111E0, 0x111E0},
9194+ {0x111F5, 0x111FF}, {0x11212, 0x11212}, {0x1123F, 0x1127F},
9195+ {0x11287, 0x11287}, {0x11289, 0x11289}, {0x1128E, 0x1128E},
9196+ {0x1129E, 0x1129E}, {0x112AA, 0x112AF}, {0x112EB, 0x112EF},
9197+ {0x112FA, 0x112FF}, {0x11304, 0x11304}, {0x1130D, 0x1130E},
9198+ {0x11311, 0x11312}, {0x11329, 0x11329}, {0x11331, 0x11331},
9199+ {0x11334, 0x11334}, {0x1133A, 0x1133B}, {0x11345, 0x11346},
9200+ {0x11349, 0x1134A}, {0x1134E, 0x1134F}, {0x11351, 0x11356},
9201+ {0x11358, 0x1135C}, {0x11364, 0x11365}, {0x1136D, 0x1136F},
9202+ {0x11375, 0x113FF}, {0x1145A, 0x1145A}, {0x1145C, 0x1145C},
9203+ {0x1145E, 0x1147F}, {0x114C8, 0x114CF}, {0x114DA, 0x1157F},
9204+ {0x115B6, 0x115B7}, {0x115DE, 0x115FF}, {0x11645, 0x1164F},
9205+ {0x1165A, 0x1165F}, {0x1166D, 0x1167F}, {0x116B8, 0x116BF},
9206+ {0x116CA, 0x116FF}, {0x1171A, 0x1171C}, {0x1172C, 0x1172F},
9207+ {0x11740, 0x1189F}, {0x118F3, 0x118FE}, {0x11900, 0x11ABF},
9208+ {0x11AF9, 0x11BFF}, {0x11C09, 0x11C09}, {0x11C37, 0x11C37},
9209+ {0x11C46, 0x11C4F}, {0x11C6D, 0x11C6F}, {0x11C90, 0x11C91},
9210+ {0x11CA8, 0x11CA8}, {0x11CB7, 0x11FFF}, {0x1239A, 0x123FF},
9211+ {0x1246F, 0x1246F}, {0x12475, 0x1247F}, {0x12544, 0x12FFF},
9212+ {0x1342F, 0x143FF}, {0x14647, 0x167FF}, {0x16A39, 0x16A3F},
9213+ {0x16A5F, 0x16A5F}, {0x16A6A, 0x16A6D}, {0x16A70, 0x16ACF},
9214+ {0x16AEE, 0x16AEF}, {0x16AF6, 0x16AFF}, {0x16B46, 0x16B4F},
9215+ {0x16B5A, 0x16B5A}, {0x16B62, 0x16B62}, {0x16B78, 0x16B7C},
9216+ {0x16B90, 0x16EFF}, {0x16F45, 0x16F4F}, {0x16F7F, 0x16F8E},
9217+ {0x16FA0, 0x16FDF}, {0x16FE1, 0x16FFF}, {0x187ED, 0x187FF},
9218+ {0x18AF3, 0x1AFFF}, {0x1B002, 0x1BBFF}, {0x1BC6B, 0x1BC6F},
9219+ {0x1BC7D, 0x1BC7F}, {0x1BC89, 0x1BC8F}, {0x1BC9A, 0x1BC9B},
9220+ {0x1BCA4, 0x1CFFF}, {0x1D0F6, 0x1D0FF}, {0x1D127, 0x1D128},
9221+ {0x1D1E9, 0x1D1FF}, {0x1D246, 0x1D2FF}, {0x1D357, 0x1D35F},
9222+ {0x1D372, 0x1D3FF}, {0x1D455, 0x1D455}, {0x1D49D, 0x1D49D},
9223+ {0x1D4A0, 0x1D4A1}, {0x1D4A3, 0x1D4A4}, {0x1D4A7, 0x1D4A8},
9224+ {0x1D4AD, 0x1D4AD}, {0x1D4BA, 0x1D4BA}, {0x1D4BC, 0x1D4BC},
9225+ {0x1D4C4, 0x1D4C4}, {0x1D506, 0x1D506}, {0x1D50B, 0x1D50C},
9226+ {0x1D515, 0x1D515}, {0x1D51D, 0x1D51D}, {0x1D53A, 0x1D53A},
9227+ {0x1D53F, 0x1D53F}, {0x1D545, 0x1D545}, {0x1D547, 0x1D549},
9228+ {0x1D551, 0x1D551}, {0x1D6A6, 0x1D6A7}, {0x1D7CC, 0x1D7CD},
9229+ {0x1DA8C, 0x1DA9A}, {0x1DAA0, 0x1DAA0}, {0x1DAB0, 0x1DFFF},
9230+ {0x1E007, 0x1E007}, {0x1E019, 0x1E01A}, {0x1E022, 0x1E022},
9231+ {0x1E025, 0x1E025}, {0x1E02B, 0x1E7FF}, {0x1E8C5, 0x1E8C6},
9232+ {0x1E8D7, 0x1E8FF}, {0x1E94B, 0x1E94F}, {0x1E95A, 0x1E95D},
9233+ {0x1E960, 0x1EDFF}, {0x1EE04, 0x1EE04}, {0x1EE20, 0x1EE20},
9234+ {0x1EE23, 0x1EE23}, {0x1EE25, 0x1EE26}, {0x1EE28, 0x1EE28},
9235+ {0x1EE33, 0x1EE33}, {0x1EE38, 0x1EE38}, {0x1EE3A, 0x1EE3A},
9236+ {0x1EE3C, 0x1EE41}, {0x1EE43, 0x1EE46}, {0x1EE48, 0x1EE48},
9237+ {0x1EE4A, 0x1EE4A}, {0x1EE4C, 0x1EE4C}, {0x1EE50, 0x1EE50},
9238+ {0x1EE53, 0x1EE53}, {0x1EE55, 0x1EE56}, {0x1EE58, 0x1EE58},
9239+ {0x1EE5A, 0x1EE5A}, {0x1EE5C, 0x1EE5C}, {0x1EE5E, 0x1EE5E},
9240+ {0x1EE60, 0x1EE60}, {0x1EE63, 0x1EE63}, {0x1EE65, 0x1EE66},
9241+ {0x1EE6B, 0x1EE6B}, {0x1EE73, 0x1EE73}, {0x1EE78, 0x1EE78},
9242+ {0x1EE7D, 0x1EE7D}, {0x1EE7F, 0x1EE7F}, {0x1EE8A, 0x1EE8A},
9243+ {0x1EE9C, 0x1EEA0}, {0x1EEA4, 0x1EEA4}, {0x1EEAA, 0x1EEAA},
9244+ {0x1EEBC, 0x1EEEF}, {0x1EEF2, 0x1EFFF}, {0x1F02C, 0x1F02F},
9245+ {0x1F094, 0x1F09F}, {0x1F0AF, 0x1F0B0}, {0x1F0C0, 0x1F0C0},
9246+ {0x1F0D0, 0x1F0D0}, {0x1F0F6, 0x1F0FF}, {0x1F10D, 0x1F10F},
9247+ {0x1F12F, 0x1F12F}, {0x1F16C, 0x1F16F}, {0x1F1AD, 0x1F1E5},
9248+ {0x1F203, 0x1F20F}, {0x1F23C, 0x1F23F}, {0x1F249, 0x1F24F},
9249+ {0x1F252, 0x1F2FF}, {0x1F6D3, 0x1F6DF}, {0x1F6ED, 0x1F6EF},
9250+ {0x1F6F7, 0x1F6FF}, {0x1F774, 0x1F77F}, {0x1F7D5, 0x1F7FF},
9251+ {0x1F80C, 0x1F80F}, {0x1F848, 0x1F84F}, {0x1F85A, 0x1F85F},
9252+ {0x1F888, 0x1F88F}, {0x1F8AE, 0x1F90F}, {0x1F91F, 0x1F91F},
9253+ {0x1F928, 0x1F92F}, {0x1F931, 0x1F932}, {0x1F93F, 0x1F93F},
9254+ {0x1F94C, 0x1F94F}, {0x1F95F, 0x1F97F}, {0x1F992, 0x1F9BF},
9255+ {0x1F9C1, 0x1FFFF}, {0x2A6D7, 0x2A6FF}, {0x2B735, 0x2B73F},
9256+ {0x2B81E, 0x2B81F}, {0x2CEA2, 0x2F7FF}, {0x2FA1E, 0xE0000},
9257+ {0xE0002, 0xE001F}, {0xE0080, 0xE00FF}, {0xE01F0, 0xEFFFF},
9258+ {0xFFFFE, 0xFFFFF},
9259+ }
9260+
9261+ var neutral = table{
9262+ {0x0000, 0x001F}, {0x007F, 0x007F}, {0x0080, 0x009F},
9263+ {0x00A0, 0x00A0}, {0x00A9, 0x00A9}, {0x00AB, 0x00AB},
9264+ {0x00B5, 0x00B5}, {0x00BB, 0x00BB}, {0x00C0, 0x00C5},
9265+ {0x00C7, 0x00CF}, {0x00D1, 0x00D6}, {0x00D9, 0x00DD},
9266+ {0x00E2, 0x00E5}, {0x00E7, 0x00E7}, {0x00EB, 0x00EB},
9267+ {0x00EE, 0x00EF}, {0x00F1, 0x00F1}, {0x00F4, 0x00F6},
9268+ {0x00FB, 0x00FB}, {0x00FD, 0x00FD}, {0x00FF, 0x00FF},
9269+ {0x0100, 0x0100}, {0x0102, 0x0110}, {0x0112, 0x0112},
9270+ {0x0114, 0x011A}, {0x011C, 0x0125}, {0x0128, 0x012A},
9271+ {0x012C, 0x0130}, {0x0134, 0x0137}, {0x0139, 0x013E},
9272+ {0x0143, 0x0143}, {0x0145, 0x0147}, {0x014C, 0x014C},
9273+ {0x014E, 0x0151}, {0x0154, 0x0165}, {0x0168, 0x016A},
9274+ {0x016C, 0x017F}, {0x0180, 0x01BA}, {0x01BB, 0x01BB},
9275+ {0x01BC, 0x01BF}, {0x01C0, 0x01C3}, {0x01C4, 0x01CD},
9276+ {0x01CF, 0x01CF}, {0x01D1, 0x01D1}, {0x01D3, 0x01D3},
9277+ {0x01D5, 0x01D5}, {0x01D7, 0x01D7}, {0x01D9, 0x01D9},
9278+ {0x01DB, 0x01DB}, {0x01DD, 0x024F}, {0x0250, 0x0250},
9279+ {0x0252, 0x0260}, {0x0262, 0x0293}, {0x0294, 0x0294},
9280+ {0x0295, 0x02AF}, {0x02B0, 0x02C1}, {0x02C2, 0x02C3},
9281+ {0x02C5, 0x02C5}, {0x02C6, 0x02C6}, {0x02C8, 0x02C8},
9282+ {0x02CC, 0x02CC}, {0x02CE, 0x02CF}, {0x02D1, 0x02D1},
9283+ {0x02D2, 0x02D7}, {0x02DC, 0x02DC}, {0x02DE, 0x02DE},
9284+ {0x02E0, 0x02E4}, {0x02E5, 0x02EB}, {0x02EC, 0x02EC},
9285+ {0x02ED, 0x02ED}, {0x02EE, 0x02EE}, {0x02EF, 0x02FF},
9286+ {0x0370, 0x0373}, {0x0374, 0x0374}, {0x0375, 0x0375},
9287+ {0x0376, 0x0377}, {0x037A, 0x037A}, {0x037B, 0x037D},
9288+ {0x037E, 0x037E}, {0x037F, 0x037F}, {0x0384, 0x0385},
9289+ {0x0386, 0x0386}, {0x0387, 0x0387}, {0x0388, 0x038A},
9290+ {0x038C, 0x038C}, {0x038E, 0x0390}, {0x03AA, 0x03B0},
9291+ {0x03C2, 0x03C2}, {0x03CA, 0x03F5}, {0x03F6, 0x03F6},
9292+ {0x03F7, 0x03FF}, {0x0400, 0x0400}, {0x0402, 0x040F},
9293+ {0x0450, 0x0450}, {0x0452, 0x0481}, {0x0482, 0x0482},
9294+ {0x0483, 0x0487}, {0x0488, 0x0489}, {0x048A, 0x04FF},
9295+ {0x0500, 0x052F}, {0x0531, 0x0556}, {0x0559, 0x0559},
9296+ {0x055A, 0x055F}, {0x0561, 0x0587}, {0x0589, 0x0589},
9297+ {0x058A, 0x058A}, {0x058D, 0x058E}, {0x058F, 0x058F},
9298+ {0x0591, 0x05BD}, {0x05BE, 0x05BE}, {0x05BF, 0x05BF},
9299+ {0x05C0, 0x05C0}, {0x05C1, 0x05C2}, {0x05C3, 0x05C3},
9300+ {0x05C4, 0x05C5}, {0x05C6, 0x05C6}, {0x05C7, 0x05C7},
9301+ {0x05D0, 0x05EA}, {0x05F0, 0x05F2}, {0x05F3, 0x05F4},
9302+ {0x0600, 0x0605}, {0x0606, 0x0608}, {0x0609, 0x060A},
9303+ {0x060B, 0x060B}, {0x060C, 0x060D}, {0x060E, 0x060F},
9304+ {0x0610, 0x061A}, {0x061B, 0x061B}, {0x061C, 0x061C},
9305+ {0x061E, 0x061F}, {0x0620, 0x063F}, {0x0640, 0x0640},
9306+ {0x0641, 0x064A}, {0x064B, 0x065F}, {0x0660, 0x0669},
9307+ {0x066A, 0x066D}, {0x066E, 0x066F}, {0x0670, 0x0670},
9308+ {0x0671, 0x06D3}, {0x06D4, 0x06D4}, {0x06D5, 0x06D5},
9309+ {0x06D6, 0x06DC}, {0x06DD, 0x06DD}, {0x06DE, 0x06DE},
9310+ {0x06DF, 0x06E4}, {0x06E5, 0x06E6}, {0x06E7, 0x06E8},
9311+ {0x06E9, 0x06E9}, {0x06EA, 0x06ED}, {0x06EE, 0x06EF},
9312+ {0x06F0, 0x06F9}, {0x06FA, 0x06FC}, {0x06FD, 0x06FE},
9313+ {0x06FF, 0x06FF}, {0x0700, 0x070D}, {0x070F, 0x070F},
9314+ {0x0710, 0x0710}, {0x0711, 0x0711}, {0x0712, 0x072F},
9315+ {0x0730, 0x074A}, {0x074D, 0x074F}, {0x0750, 0x077F},
9316+ {0x0780, 0x07A5}, {0x07A6, 0x07B0}, {0x07B1, 0x07B1},
9317+ {0x07C0, 0x07C9}, {0x07CA, 0x07EA}, {0x07EB, 0x07F3},
9318+ {0x07F4, 0x07F5}, {0x07F6, 0x07F6}, {0x07F7, 0x07F9},
9319+ {0x07FA, 0x07FA}, {0x0800, 0x0815}, {0x0816, 0x0819},
9320+ {0x081A, 0x081A}, {0x081B, 0x0823}, {0x0824, 0x0824},
9321+ {0x0825, 0x0827}, {0x0828, 0x0828}, {0x0829, 0x082D},
9322+ {0x0830, 0x083E}, {0x0840, 0x0858}, {0x0859, 0x085B},
9323+ {0x085E, 0x085E}, {0x08A0, 0x08B4}, {0x08B6, 0x08BD},
9324+ {0x08D4, 0x08E1}, {0x08E2, 0x08E2}, {0x08E3, 0x08FF},
9325+ {0x0900, 0x0902}, {0x0903, 0x0903}, {0x0904, 0x0939},
9326+ {0x093A, 0x093A}, {0x093B, 0x093B}, {0x093C, 0x093C},
9327+ {0x093D, 0x093D}, {0x093E, 0x0940}, {0x0941, 0x0948},
9328+ {0x0949, 0x094C}, {0x094D, 0x094D}, {0x094E, 0x094F},
9329+ {0x0950, 0x0950}, {0x0951, 0x0957}, {0x0958, 0x0961},
9330+ {0x0962, 0x0963}, {0x0964, 0x0965}, {0x0966, 0x096F},
9331+ {0x0970, 0x0970}, {0x0971, 0x0971}, {0x0972, 0x097F},
9332+ {0x0980, 0x0980}, {0x0981, 0x0981}, {0x0982, 0x0983},
9333+ {0x0985, 0x098C}, {0x098F, 0x0990}, {0x0993, 0x09A8},
9334+ {0x09AA, 0x09B0}, {0x09B2, 0x09B2}, {0x09B6, 0x09B9},
9335+ {0x09BC, 0x09BC}, {0x09BD, 0x09BD}, {0x09BE, 0x09C0},
9336+ {0x09C1, 0x09C4}, {0x09C7, 0x09C8}, {0x09CB, 0x09CC},
9337+ {0x09CD, 0x09CD}, {0x09CE, 0x09CE}, {0x09D7, 0x09D7},
9338+ {0x09DC, 0x09DD}, {0x09DF, 0x09E1}, {0x09E2, 0x09E3},
9339+ {0x09E6, 0x09EF}, {0x09F0, 0x09F1}, {0x09F2, 0x09F3},
9340+ {0x09F4, 0x09F9}, {0x09FA, 0x09FA}, {0x09FB, 0x09FB},
9341+ {0x0A01, 0x0A02}, {0x0A03, 0x0A03}, {0x0A05, 0x0A0A},
9342+ {0x0A0F, 0x0A10}, {0x0A13, 0x0A28}, {0x0A2A, 0x0A30},
9343+ {0x0A32, 0x0A33}, {0x0A35, 0x0A36}, {0x0A38, 0x0A39},
9344+ {0x0A3C, 0x0A3C}, {0x0A3E, 0x0A40}, {0x0A41, 0x0A42},
9345+ {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D}, {0x0A51, 0x0A51},
9346+ {0x0A59, 0x0A5C}, {0x0A5E, 0x0A5E}, {0x0A66, 0x0A6F},
9347+ {0x0A70, 0x0A71}, {0x0A72, 0x0A74}, {0x0A75, 0x0A75},
9348+ {0x0A81, 0x0A82}, {0x0A83, 0x0A83}, {0x0A85, 0x0A8D},
9349+ {0x0A8F, 0x0A91}, {0x0A93, 0x0AA8}, {0x0AAA, 0x0AB0},
9350+ {0x0AB2, 0x0AB3}, {0x0AB5, 0x0AB9}, {0x0ABC, 0x0ABC},
9351+ {0x0ABD, 0x0ABD}, {0x0ABE, 0x0AC0}, {0x0AC1, 0x0AC5},
9352+ {0x0AC7, 0x0AC8}, {0x0AC9, 0x0AC9}, {0x0ACB, 0x0ACC},
9353+ {0x0ACD, 0x0ACD}, {0x0AD0, 0x0AD0}, {0x0AE0, 0x0AE1},
9354+ {0x0AE2, 0x0AE3}, {0x0AE6, 0x0AEF}, {0x0AF0, 0x0AF0},
9355+ {0x0AF1, 0x0AF1}, {0x0AF9, 0x0AF9}, {0x0B01, 0x0B01},
9356+ {0x0B02, 0x0B03}, {0x0B05, 0x0B0C}, {0x0B0F, 0x0B10},
9357+ {0x0B13, 0x0B28}, {0x0B2A, 0x0B30}, {0x0B32, 0x0B33},
9358+ {0x0B35, 0x0B39}, {0x0B3C, 0x0B3C}, {0x0B3D, 0x0B3D},
9359+ {0x0B3E, 0x0B3E}, {0x0B3F, 0x0B3F}, {0x0B40, 0x0B40},
9360+ {0x0B41, 0x0B44}, {0x0B47, 0x0B48}, {0x0B4B, 0x0B4C},
9361+ {0x0B4D, 0x0B4D}, {0x0B56, 0x0B56}, {0x0B57, 0x0B57},
9362+ {0x0B5C, 0x0B5D}, {0x0B5F, 0x0B61}, {0x0B62, 0x0B63},
9363+ {0x0B66, 0x0B6F}, {0x0B70, 0x0B70}, {0x0B71, 0x0B71},
9364+ {0x0B72, 0x0B77}, {0x0B82, 0x0B82}, {0x0B83, 0x0B83},
9365+ {0x0B85, 0x0B8A}, {0x0B8E, 0x0B90}, {0x0B92, 0x0B95},
9366+ {0x0B99, 0x0B9A}, {0x0B9C, 0x0B9C}, {0x0B9E, 0x0B9F},
9367+ {0x0BA3, 0x0BA4}, {0x0BA8, 0x0BAA}, {0x0BAE, 0x0BB9},
9368+ {0x0BBE, 0x0BBF}, {0x0BC0, 0x0BC0}, {0x0BC1, 0x0BC2},
9369+ {0x0BC6, 0x0BC8}, {0x0BCA, 0x0BCC}, {0x0BCD, 0x0BCD},
9370+ {0x0BD0, 0x0BD0}, {0x0BD7, 0x0BD7}, {0x0BE6, 0x0BEF},
9371+ {0x0BF0, 0x0BF2}, {0x0BF3, 0x0BF8}, {0x0BF9, 0x0BF9},
9372+ {0x0BFA, 0x0BFA}, {0x0C00, 0x0C00}, {0x0C01, 0x0C03},
9373+ {0x0C05, 0x0C0C}, {0x0C0E, 0x0C10}, {0x0C12, 0x0C28},
9374+ {0x0C2A, 0x0C39}, {0x0C3D, 0x0C3D}, {0x0C3E, 0x0C40},
9375+ {0x0C41, 0x0C44}, {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D},
9376+ {0x0C55, 0x0C56}, {0x0C58, 0x0C5A}, {0x0C60, 0x0C61},
9377+ {0x0C62, 0x0C63}, {0x0C66, 0x0C6F}, {0x0C78, 0x0C7E},
9378+ {0x0C7F, 0x0C7F}, {0x0C80, 0x0C80}, {0x0C81, 0x0C81},
9379+ {0x0C82, 0x0C83}, {0x0C85, 0x0C8C}, {0x0C8E, 0x0C90},
9380+ {0x0C92, 0x0CA8}, {0x0CAA, 0x0CB3}, {0x0CB5, 0x0CB9},
9381+ {0x0CBC, 0x0CBC}, {0x0CBD, 0x0CBD}, {0x0CBE, 0x0CBE},
9382+ {0x0CBF, 0x0CBF}, {0x0CC0, 0x0CC4}, {0x0CC6, 0x0CC6},
9383+ {0x0CC7, 0x0CC8}, {0x0CCA, 0x0CCB}, {0x0CCC, 0x0CCD},
9384+ {0x0CD5, 0x0CD6}, {0x0CDE, 0x0CDE}, {0x0CE0, 0x0CE1},
9385+ {0x0CE2, 0x0CE3}, {0x0CE6, 0x0CEF}, {0x0CF1, 0x0CF2},
9386+ {0x0D01, 0x0D01}, {0x0D02, 0x0D03}, {0x0D05, 0x0D0C},
9387+ {0x0D0E, 0x0D10}, {0x0D12, 0x0D3A}, {0x0D3D, 0x0D3D},
9388+ {0x0D3E, 0x0D40}, {0x0D41, 0x0D44}, {0x0D46, 0x0D48},
9389+ {0x0D4A, 0x0D4C}, {0x0D4D, 0x0D4D}, {0x0D4E, 0x0D4E},
9390+ {0x0D4F, 0x0D4F}, {0x0D54, 0x0D56}, {0x0D57, 0x0D57},
9391+ {0x0D58, 0x0D5E}, {0x0D5F, 0x0D61}, {0x0D62, 0x0D63},
9392+ {0x0D66, 0x0D6F}, {0x0D70, 0x0D78}, {0x0D79, 0x0D79},
9393+ {0x0D7A, 0x0D7F}, {0x0D82, 0x0D83}, {0x0D85, 0x0D96},
9394+ {0x0D9A, 0x0DB1}, {0x0DB3, 0x0DBB}, {0x0DBD, 0x0DBD},
9395+ {0x0DC0, 0x0DC6}, {0x0DCA, 0x0DCA}, {0x0DCF, 0x0DD1},
9396+ {0x0DD2, 0x0DD4}, {0x0DD6, 0x0DD6}, {0x0DD8, 0x0DDF},
9397+ {0x0DE6, 0x0DEF}, {0x0DF2, 0x0DF3}, {0x0DF4, 0x0DF4},
9398+ {0x0E01, 0x0E30}, {0x0E31, 0x0E31}, {0x0E32, 0x0E33},
9399+ {0x0E34, 0x0E3A}, {0x0E3F, 0x0E3F}, {0x0E40, 0x0E45},
9400+ {0x0E46, 0x0E46}, {0x0E47, 0x0E4E}, {0x0E4F, 0x0E4F},
9401+ {0x0E50, 0x0E59}, {0x0E5A, 0x0E5B}, {0x0E81, 0x0E82},
9402+ {0x0E84, 0x0E84}, {0x0E87, 0x0E88}, {0x0E8A, 0x0E8A},
9403+ {0x0E8D, 0x0E8D}, {0x0E94, 0x0E97}, {0x0E99, 0x0E9F},
9404+ {0x0EA1, 0x0EA3}, {0x0EA5, 0x0EA5}, {0x0EA7, 0x0EA7},
9405+ {0x0EAA, 0x0EAB}, {0x0EAD, 0x0EB0}, {0x0EB1, 0x0EB1},
9406+ {0x0EB2, 0x0EB3}, {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC},
9407+ {0x0EBD, 0x0EBD}, {0x0EC0, 0x0EC4}, {0x0EC6, 0x0EC6},
9408+ {0x0EC8, 0x0ECD}, {0x0ED0, 0x0ED9}, {0x0EDC, 0x0EDF},
9409+ {0x0F00, 0x0F00}, {0x0F01, 0x0F03}, {0x0F04, 0x0F12},
9410+ {0x0F13, 0x0F13}, {0x0F14, 0x0F14}, {0x0F15, 0x0F17},
9411+ {0x0F18, 0x0F19}, {0x0F1A, 0x0F1F}, {0x0F20, 0x0F29},
9412+ {0x0F2A, 0x0F33}, {0x0F34, 0x0F34}, {0x0F35, 0x0F35},
9413+ {0x0F36, 0x0F36}, {0x0F37, 0x0F37}, {0x0F38, 0x0F38},
9414+ {0x0F39, 0x0F39}, {0x0F3A, 0x0F3A}, {0x0F3B, 0x0F3B},
9415+ {0x0F3C, 0x0F3C}, {0x0F3D, 0x0F3D}, {0x0F3E, 0x0F3F},
9416+ {0x0F40, 0x0F47}, {0x0F49, 0x0F6C}, {0x0F71, 0x0F7E},
9417+ {0x0F7F, 0x0F7F}, {0x0F80, 0x0F84}, {0x0F85, 0x0F85},
9418+ {0x0F86, 0x0F87}, {0x0F88, 0x0F8C}, {0x0F8D, 0x0F97},
9419+ {0x0F99, 0x0FBC}, {0x0FBE, 0x0FC5}, {0x0FC6, 0x0FC6},
9420+ {0x0FC7, 0x0FCC}, {0x0FCE, 0x0FCF}, {0x0FD0, 0x0FD4},
9421+ {0x0FD5, 0x0FD8}, {0x0FD9, 0x0FDA}, {0x1000, 0x102A},
9422+ {0x102B, 0x102C}, {0x102D, 0x1030}, {0x1031, 0x1031},
9423+ {0x1032, 0x1037}, {0x1038, 0x1038}, {0x1039, 0x103A},
9424+ {0x103B, 0x103C}, {0x103D, 0x103E}, {0x103F, 0x103F},
9425+ {0x1040, 0x1049}, {0x104A, 0x104F}, {0x1050, 0x1055},
9426+ {0x1056, 0x1057}, {0x1058, 0x1059}, {0x105A, 0x105D},
9427+ {0x105E, 0x1060}, {0x1061, 0x1061}, {0x1062, 0x1064},
9428+ {0x1065, 0x1066}, {0x1067, 0x106D}, {0x106E, 0x1070},
9429+ {0x1071, 0x1074}, {0x1075, 0x1081}, {0x1082, 0x1082},
9430+ {0x1083, 0x1084}, {0x1085, 0x1086}, {0x1087, 0x108C},
9431+ {0x108D, 0x108D}, {0x108E, 0x108E}, {0x108F, 0x108F},
9432+ {0x1090, 0x1099}, {0x109A, 0x109C}, {0x109D, 0x109D},
9433+ {0x109E, 0x109F}, {0x10A0, 0x10C5}, {0x10C7, 0x10C7},
9434+ {0x10CD, 0x10CD}, {0x10D0, 0x10FA}, {0x10FB, 0x10FB},
9435+ {0x10FC, 0x10FC}, {0x10FD, 0x10FF}, {0x1160, 0x11FF},
9436+ {0x1200, 0x1248}, {0x124A, 0x124D}, {0x1250, 0x1256},
9437+ {0x1258, 0x1258}, {0x125A, 0x125D}, {0x1260, 0x1288},
9438+ {0x128A, 0x128D}, {0x1290, 0x12B0}, {0x12B2, 0x12B5},
9439+ {0x12B8, 0x12BE}, {0x12C0, 0x12C0}, {0x12C2, 0x12C5},
9440+ {0x12C8, 0x12D6}, {0x12D8, 0x1310}, {0x1312, 0x1315},
9441+ {0x1318, 0x135A}, {0x135D, 0x135F}, {0x1360, 0x1368},
9442+ {0x1369, 0x137C}, {0x1380, 0x138F}, {0x1390, 0x1399},
9443+ {0x13A0, 0x13F5}, {0x13F8, 0x13FD}, {0x1400, 0x1400},
9444+ {0x1401, 0x166C}, {0x166D, 0x166E}, {0x166F, 0x167F},
9445+ {0x1680, 0x1680}, {0x1681, 0x169A}, {0x169B, 0x169B},
9446+ {0x169C, 0x169C}, {0x16A0, 0x16EA}, {0x16EB, 0x16ED},
9447+ {0x16EE, 0x16F0}, {0x16F1, 0x16F8}, {0x1700, 0x170C},
9448+ {0x170E, 0x1711}, {0x1712, 0x1714}, {0x1720, 0x1731},
9449+ {0x1732, 0x1734}, {0x1735, 0x1736}, {0x1740, 0x1751},
9450+ {0x1752, 0x1753}, {0x1760, 0x176C}, {0x176E, 0x1770},
9451+ {0x1772, 0x1773}, {0x1780, 0x17B3}, {0x17B4, 0x17B5},
9452+ {0x17B6, 0x17B6}, {0x17B7, 0x17BD}, {0x17BE, 0x17C5},
9453+ {0x17C6, 0x17C6}, {0x17C7, 0x17C8}, {0x17C9, 0x17D3},
9454+ {0x17D4, 0x17D6}, {0x17D7, 0x17D7}, {0x17D8, 0x17DA},
9455+ {0x17DB, 0x17DB}, {0x17DC, 0x17DC}, {0x17DD, 0x17DD},
9456+ {0x17E0, 0x17E9}, {0x17F0, 0x17F9}, {0x1800, 0x1805},
9457+ {0x1806, 0x1806}, {0x1807, 0x180A}, {0x180B, 0x180D},
9458+ {0x180E, 0x180E}, {0x1810, 0x1819}, {0x1820, 0x1842},
9459+ {0x1843, 0x1843}, {0x1844, 0x1877}, {0x1880, 0x1884},
9460+ {0x1885, 0x1886}, {0x1887, 0x18A8}, {0x18A9, 0x18A9},
9461+ {0x18AA, 0x18AA}, {0x18B0, 0x18F5}, {0x1900, 0x191E},
9462+ {0x1920, 0x1922}, {0x1923, 0x1926}, {0x1927, 0x1928},
9463+ {0x1929, 0x192B}, {0x1930, 0x1931}, {0x1932, 0x1932},
9464+ {0x1933, 0x1938}, {0x1939, 0x193B}, {0x1940, 0x1940},
9465+ {0x1944, 0x1945}, {0x1946, 0x194F}, {0x1950, 0x196D},
9466+ {0x1970, 0x1974}, {0x1980, 0x19AB}, {0x19B0, 0x19C9},
9467+ {0x19D0, 0x19D9}, {0x19DA, 0x19DA}, {0x19DE, 0x19DF},
9468+ {0x19E0, 0x19FF}, {0x1A00, 0x1A16}, {0x1A17, 0x1A18},
9469+ {0x1A19, 0x1A1A}, {0x1A1B, 0x1A1B}, {0x1A1E, 0x1A1F},
9470+ {0x1A20, 0x1A54}, {0x1A55, 0x1A55}, {0x1A56, 0x1A56},
9471+ {0x1A57, 0x1A57}, {0x1A58, 0x1A5E}, {0x1A60, 0x1A60},
9472+ {0x1A61, 0x1A61}, {0x1A62, 0x1A62}, {0x1A63, 0x1A64},
9473+ {0x1A65, 0x1A6C}, {0x1A6D, 0x1A72}, {0x1A73, 0x1A7C},
9474+ {0x1A7F, 0x1A7F}, {0x1A80, 0x1A89}, {0x1A90, 0x1A99},
9475+ {0x1AA0, 0x1AA6}, {0x1AA7, 0x1AA7}, {0x1AA8, 0x1AAD},
9476+ {0x1AB0, 0x1ABD}, {0x1ABE, 0x1ABE}, {0x1B00, 0x1B03},
9477+ {0x1B04, 0x1B04}, {0x1B05, 0x1B33}, {0x1B34, 0x1B34},
9478+ {0x1B35, 0x1B35}, {0x1B36, 0x1B3A}, {0x1B3B, 0x1B3B},
9479+ {0x1B3C, 0x1B3C}, {0x1B3D, 0x1B41}, {0x1B42, 0x1B42},
9480+ {0x1B43, 0x1B44}, {0x1B45, 0x1B4B}, {0x1B50, 0x1B59},
9481+ {0x1B5A, 0x1B60}, {0x1B61, 0x1B6A}, {0x1B6B, 0x1B73},
9482+ {0x1B74, 0x1B7C}, {0x1B80, 0x1B81}, {0x1B82, 0x1B82},
9483+ {0x1B83, 0x1BA0}, {0x1BA1, 0x1BA1}, {0x1BA2, 0x1BA5},
9484+ {0x1BA6, 0x1BA7}, {0x1BA8, 0x1BA9}, {0x1BAA, 0x1BAA},
9485+ {0x1BAB, 0x1BAD}, {0x1BAE, 0x1BAF}, {0x1BB0, 0x1BB9},
9486+ {0x1BBA, 0x1BBF}, {0x1BC0, 0x1BE5}, {0x1BE6, 0x1BE6},
9487+ {0x1BE7, 0x1BE7}, {0x1BE8, 0x1BE9}, {0x1BEA, 0x1BEC},
9488+ {0x1BED, 0x1BED}, {0x1BEE, 0x1BEE}, {0x1BEF, 0x1BF1},
9489+ {0x1BF2, 0x1BF3}, {0x1BFC, 0x1BFF}, {0x1C00, 0x1C23},
9490+ {0x1C24, 0x1C2B}, {0x1C2C, 0x1C33}, {0x1C34, 0x1C35},
9491+ {0x1C36, 0x1C37}, {0x1C3B, 0x1C3F}, {0x1C40, 0x1C49},
9492+ {0x1C4D, 0x1C4F}, {0x1C50, 0x1C59}, {0x1C5A, 0x1C77},
9493+ {0x1C78, 0x1C7D}, {0x1C7E, 0x1C7F}, {0x1C80, 0x1C88},
9494+ {0x1CC0, 0x1CC7}, {0x1CD0, 0x1CD2}, {0x1CD3, 0x1CD3},
9495+ {0x1CD4, 0x1CE0}, {0x1CE1, 0x1CE1}, {0x1CE2, 0x1CE8},
9496+ {0x1CE9, 0x1CEC}, {0x1CED, 0x1CED}, {0x1CEE, 0x1CF1},
9497+ {0x1CF2, 0x1CF3}, {0x1CF4, 0x1CF4}, {0x1CF5, 0x1CF6},
9498+ {0x1CF8, 0x1CF9}, {0x1D00, 0x1D2B}, {0x1D2C, 0x1D6A},
9499+ {0x1D6B, 0x1D77}, {0x1D78, 0x1D78}, {0x1D79, 0x1D7F},
9500+ {0x1D80, 0x1D9A}, {0x1D9B, 0x1DBF}, {0x1DC0, 0x1DF5},
9501+ {0x1DFB, 0x1DFF}, {0x1E00, 0x1EFF}, {0x1F00, 0x1F15},
9502+ {0x1F18, 0x1F1D}, {0x1F20, 0x1F45}, {0x1F48, 0x1F4D},
9503+ {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, {0x1F5B, 0x1F5B},
9504+ {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4},
9505+ {0x1FB6, 0x1FBC}, {0x1FBD, 0x1FBD}, {0x1FBE, 0x1FBE},
9506+ {0x1FBF, 0x1FC1}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC},
9507+ {0x1FCD, 0x1FCF}, {0x1FD0, 0x1FD3}, {0x1FD6, 0x1FDB},
9508+ {0x1FDD, 0x1FDF}, {0x1FE0, 0x1FEC}, {0x1FED, 0x1FEF},
9509+ {0x1FF2, 0x1FF4}, {0x1FF6, 0x1FFC}, {0x1FFD, 0x1FFE},
9510+ {0x2000, 0x200A}, {0x200B, 0x200F}, {0x2011, 0x2012},
9511+ {0x2017, 0x2017}, {0x201A, 0x201A}, {0x201B, 0x201B},
9512+ {0x201E, 0x201E}, {0x201F, 0x201F}, {0x2023, 0x2023},
9513+ {0x2028, 0x2028}, {0x2029, 0x2029}, {0x202A, 0x202E},
9514+ {0x202F, 0x202F}, {0x2031, 0x2031}, {0x2034, 0x2034},
9515+ {0x2036, 0x2038}, {0x2039, 0x2039}, {0x203A, 0x203A},
9516+ {0x203C, 0x203D}, {0x203F, 0x2040}, {0x2041, 0x2043},
9517+ {0x2044, 0x2044}, {0x2045, 0x2045}, {0x2046, 0x2046},
9518+ {0x2047, 0x2051}, {0x2052, 0x2052}, {0x2053, 0x2053},
9519+ {0x2054, 0x2054}, {0x2055, 0x205E}, {0x205F, 0x205F},
9520+ {0x2060, 0x2064}, {0x2066, 0x206F}, {0x2070, 0x2070},
9521+ {0x2071, 0x2071}, {0x2075, 0x2079}, {0x207A, 0x207C},
9522+ {0x207D, 0x207D}, {0x207E, 0x207E}, {0x2080, 0x2080},
9523+ {0x2085, 0x2089}, {0x208A, 0x208C}, {0x208D, 0x208D},
9524+ {0x208E, 0x208E}, {0x2090, 0x209C}, {0x20A0, 0x20A8},
9525+ {0x20AA, 0x20AB}, {0x20AD, 0x20BE}, {0x20D0, 0x20DC},
9526+ {0x20DD, 0x20E0}, {0x20E1, 0x20E1}, {0x20E2, 0x20E4},
9527+ {0x20E5, 0x20F0}, {0x2100, 0x2101}, {0x2102, 0x2102},
9528+ {0x2104, 0x2104}, {0x2106, 0x2106}, {0x2107, 0x2107},
9529+ {0x2108, 0x2108}, {0x210A, 0x2112}, {0x2114, 0x2114},
9530+ {0x2115, 0x2115}, {0x2117, 0x2117}, {0x2118, 0x2118},
9531+ {0x2119, 0x211D}, {0x211E, 0x2120}, {0x2123, 0x2123},
9532+ {0x2124, 0x2124}, {0x2125, 0x2125}, {0x2127, 0x2127},
9533+ {0x2128, 0x2128}, {0x2129, 0x2129}, {0x212A, 0x212A},
9534+ {0x212C, 0x212D}, {0x212E, 0x212E}, {0x212F, 0x2134},
9535+ {0x2135, 0x2138}, {0x2139, 0x2139}, {0x213A, 0x213B},
9536+ {0x213C, 0x213F}, {0x2140, 0x2144}, {0x2145, 0x2149},
9537+ {0x214A, 0x214A}, {0x214B, 0x214B}, {0x214C, 0x214D},
9538+ {0x214E, 0x214E}, {0x214F, 0x214F}, {0x2150, 0x2152},
9539+ {0x2155, 0x215A}, {0x215F, 0x215F}, {0x216C, 0x216F},
9540+ {0x217A, 0x2182}, {0x2183, 0x2184}, {0x2185, 0x2188},
9541+ {0x218A, 0x218B}, {0x219A, 0x219B}, {0x219C, 0x219F},
9542+ {0x21A0, 0x21A0}, {0x21A1, 0x21A2}, {0x21A3, 0x21A3},
9543+ {0x21A4, 0x21A5}, {0x21A6, 0x21A6}, {0x21A7, 0x21AD},
9544+ {0x21AE, 0x21AE}, {0x21AF, 0x21B7}, {0x21BA, 0x21CD},
9545+ {0x21CE, 0x21CF}, {0x21D0, 0x21D1}, {0x21D3, 0x21D3},
9546+ {0x21D5, 0x21E6}, {0x21E8, 0x21F3}, {0x21F4, 0x21FF},
9547+ {0x2201, 0x2201}, {0x2204, 0x2206}, {0x2209, 0x220A},
9548+ {0x220C, 0x220E}, {0x2210, 0x2210}, {0x2212, 0x2214},
9549+ {0x2216, 0x2219}, {0x221B, 0x221C}, {0x2221, 0x2222},
9550+ {0x2224, 0x2224}, {0x2226, 0x2226}, {0x222D, 0x222D},
9551+ {0x222F, 0x2233}, {0x2238, 0x223B}, {0x223E, 0x2247},
9552+ {0x2249, 0x224B}, {0x224D, 0x2251}, {0x2253, 0x225F},
9553+ {0x2262, 0x2263}, {0x2268, 0x2269}, {0x226C, 0x226D},
9554+ {0x2270, 0x2281}, {0x2284, 0x2285}, {0x2288, 0x2294},
9555+ {0x2296, 0x2298}, {0x229A, 0x22A4}, {0x22A6, 0x22BE},
9556+ {0x22C0, 0x22FF}, {0x2300, 0x2307}, {0x2308, 0x2308},
9557+ {0x2309, 0x2309}, {0x230A, 0x230A}, {0x230B, 0x230B},
9558+ {0x230C, 0x2311}, {0x2313, 0x2319}, {0x231C, 0x231F},
9559+ {0x2320, 0x2321}, {0x2322, 0x2328}, {0x232B, 0x237B},
9560+ {0x237C, 0x237C}, {0x237D, 0x239A}, {0x239B, 0x23B3},
9561+ {0x23B4, 0x23DB}, {0x23DC, 0x23E1}, {0x23E2, 0x23E8},
9562+ {0x23ED, 0x23EF}, {0x23F1, 0x23F2}, {0x23F4, 0x23FE},
9563+ {0x2400, 0x2426}, {0x2440, 0x244A}, {0x24EA, 0x24EA},
9564+ {0x254C, 0x254F}, {0x2574, 0x257F}, {0x2590, 0x2591},
9565+ {0x2596, 0x259F}, {0x25A2, 0x25A2}, {0x25AA, 0x25B1},
9566+ {0x25B4, 0x25B5}, {0x25B8, 0x25BB}, {0x25BE, 0x25BF},
9567+ {0x25C2, 0x25C5}, {0x25C9, 0x25CA}, {0x25CC, 0x25CD},
9568+ {0x25D2, 0x25E1}, {0x25E6, 0x25EE}, {0x25F0, 0x25F7},
9569+ {0x25F8, 0x25FC}, {0x25FF, 0x25FF}, {0x2600, 0x2604},
9570+ {0x2607, 0x2608}, {0x260A, 0x260D}, {0x2610, 0x2613},
9571+ {0x2616, 0x261B}, {0x261D, 0x261D}, {0x261F, 0x263F},
9572+ {0x2641, 0x2641}, {0x2643, 0x2647}, {0x2654, 0x265F},
9573+ {0x2662, 0x2662}, {0x2666, 0x2666}, {0x266B, 0x266B},
9574+ {0x266E, 0x266E}, {0x2670, 0x267E}, {0x2680, 0x2692},
9575+ {0x2694, 0x269D}, {0x26A0, 0x26A0}, {0x26A2, 0x26A9},
9576+ {0x26AC, 0x26BC}, {0x26C0, 0x26C3}, {0x26E2, 0x26E2},
9577+ {0x26E4, 0x26E7}, {0x2700, 0x2704}, {0x2706, 0x2709},
9578+ {0x270C, 0x2727}, {0x2729, 0x273C}, {0x273E, 0x274B},
9579+ {0x274D, 0x274D}, {0x274F, 0x2752}, {0x2756, 0x2756},
9580+ {0x2758, 0x2767}, {0x2768, 0x2768}, {0x2769, 0x2769},
9581+ {0x276A, 0x276A}, {0x276B, 0x276B}, {0x276C, 0x276C},
9582+ {0x276D, 0x276D}, {0x276E, 0x276E}, {0x276F, 0x276F},
9583+ {0x2770, 0x2770}, {0x2771, 0x2771}, {0x2772, 0x2772},
9584+ {0x2773, 0x2773}, {0x2774, 0x2774}, {0x2775, 0x2775},
9585+ {0x2780, 0x2793}, {0x2794, 0x2794}, {0x2798, 0x27AF},
9586+ {0x27B1, 0x27BE}, {0x27C0, 0x27C4}, {0x27C5, 0x27C5},
9587+ {0x27C6, 0x27C6}, {0x27C7, 0x27E5}, {0x27EE, 0x27EE},
9588+ {0x27EF, 0x27EF}, {0x27F0, 0x27FF}, {0x2800, 0x28FF},
9589+ {0x2900, 0x297F}, {0x2980, 0x2982}, {0x2983, 0x2983},
9590+ {0x2984, 0x2984}, {0x2987, 0x2987}, {0x2988, 0x2988},
9591+ {0x2989, 0x2989}, {0x298A, 0x298A}, {0x298B, 0x298B},
9592+ {0x298C, 0x298C}, {0x298D, 0x298D}, {0x298E, 0x298E},
9593+ {0x298F, 0x298F}, {0x2990, 0x2990}, {0x2991, 0x2991},
9594+ {0x2992, 0x2992}, {0x2993, 0x2993}, {0x2994, 0x2994},
9595+ {0x2995, 0x2995}, {0x2996, 0x2996}, {0x2997, 0x2997},
9596+ {0x2998, 0x2998}, {0x2999, 0x29D7}, {0x29D8, 0x29D8},
9597+ {0x29D9, 0x29D9}, {0x29DA, 0x29DA}, {0x29DB, 0x29DB},
9598+ {0x29DC, 0x29FB}, {0x29FC, 0x29FC}, {0x29FD, 0x29FD},
9599+ {0x29FE, 0x29FF}, {0x2A00, 0x2AFF}, {0x2B00, 0x2B1A},
9600+ {0x2B1D, 0x2B2F}, {0x2B30, 0x2B44}, {0x2B45, 0x2B46},
9601+ {0x2B47, 0x2B4C}, {0x2B4D, 0x2B4F}, {0x2B51, 0x2B54},
9602+ {0x2B5A, 0x2B73}, {0x2B76, 0x2B95}, {0x2B98, 0x2BB9},
9603+ {0x2BBD, 0x2BC8}, {0x2BCA, 0x2BD1}, {0x2BEC, 0x2BEF},
9604+ {0x2C00, 0x2C2E}, {0x2C30, 0x2C5E}, {0x2C60, 0x2C7B},
9605+ {0x2C7C, 0x2C7D}, {0x2C7E, 0x2C7F}, {0x2C80, 0x2CE4},
9606+ {0x2CE5, 0x2CEA}, {0x2CEB, 0x2CEE}, {0x2CEF, 0x2CF1},
9607+ {0x2CF2, 0x2CF3}, {0x2CF9, 0x2CFC}, {0x2CFD, 0x2CFD},
9608+ {0x2CFE, 0x2CFF}, {0x2D00, 0x2D25}, {0x2D27, 0x2D27},
9609+ {0x2D2D, 0x2D2D}, {0x2D30, 0x2D67}, {0x2D6F, 0x2D6F},
9610+ {0x2D70, 0x2D70}, {0x2D7F, 0x2D7F}, {0x2D80, 0x2D96},
9611+ {0x2DA0, 0x2DA6}, {0x2DA8, 0x2DAE}, {0x2DB0, 0x2DB6},
9612+ {0x2DB8, 0x2DBE}, {0x2DC0, 0x2DC6}, {0x2DC8, 0x2DCE},
9613+ {0x2DD0, 0x2DD6}, {0x2DD8, 0x2DDE}, {0x2DE0, 0x2DFF},
9614+ {0x2E00, 0x2E01}, {0x2E02, 0x2E02}, {0x2E03, 0x2E03},
9615+ {0x2E04, 0x2E04}, {0x2E05, 0x2E05}, {0x2E06, 0x2E08},
9616+ {0x2E09, 0x2E09}, {0x2E0A, 0x2E0A}, {0x2E0B, 0x2E0B},
9617+ {0x2E0C, 0x2E0C}, {0x2E0D, 0x2E0D}, {0x2E0E, 0x2E16},
9618+ {0x2E17, 0x2E17}, {0x2E18, 0x2E19}, {0x2E1A, 0x2E1A},
9619+ {0x2E1B, 0x2E1B}, {0x2E1C, 0x2E1C}, {0x2E1D, 0x2E1D},
9620+ {0x2E1E, 0x2E1F}, {0x2E20, 0x2E20}, {0x2E21, 0x2E21},
9621+ {0x2E22, 0x2E22}, {0x2E23, 0x2E23}, {0x2E24, 0x2E24},
9622+ {0x2E25, 0x2E25}, {0x2E26, 0x2E26}, {0x2E27, 0x2E27},
9623+ {0x2E28, 0x2E28}, {0x2E29, 0x2E29}, {0x2E2A, 0x2E2E},
9624+ {0x2E2F, 0x2E2F}, {0x2E30, 0x2E39}, {0x2E3A, 0x2E3B},
9625+ {0x2E3C, 0x2E3F}, {0x2E40, 0x2E40}, {0x2E41, 0x2E41},
9626+ {0x2E42, 0x2E42}, {0x2E43, 0x2E44}, {0x303F, 0x303F},
9627+ {0x4DC0, 0x4DFF}, {0xA4D0, 0xA4F7}, {0xA4F8, 0xA4FD},
9628+ {0xA4FE, 0xA4FF}, {0xA500, 0xA60B}, {0xA60C, 0xA60C},
9629+ {0xA60D, 0xA60F}, {0xA610, 0xA61F}, {0xA620, 0xA629},
9630+ {0xA62A, 0xA62B}, {0xA640, 0xA66D}, {0xA66E, 0xA66E},
9631+ {0xA66F, 0xA66F}, {0xA670, 0xA672}, {0xA673, 0xA673},
9632+ {0xA674, 0xA67D}, {0xA67E, 0xA67E}, {0xA67F, 0xA67F},
9633+ {0xA680, 0xA69B}, {0xA69C, 0xA69D}, {0xA69E, 0xA69F},
9634+ {0xA6A0, 0xA6E5}, {0xA6E6, 0xA6EF}, {0xA6F0, 0xA6F1},
9635+ {0xA6F2, 0xA6F7}, {0xA700, 0xA716}, {0xA717, 0xA71F},
9636+ {0xA720, 0xA721}, {0xA722, 0xA76F}, {0xA770, 0xA770},
9637+ {0xA771, 0xA787}, {0xA788, 0xA788}, {0xA789, 0xA78A},
9638+ {0xA78B, 0xA78E}, {0xA78F, 0xA78F}, {0xA790, 0xA7AE},
9639+ {0xA7B0, 0xA7B7}, {0xA7F7, 0xA7F7}, {0xA7F8, 0xA7F9},
9640+ {0xA7FA, 0xA7FA}, {0xA7FB, 0xA7FF}, {0xA800, 0xA801},
9641+ {0xA802, 0xA802}, {0xA803, 0xA805}, {0xA806, 0xA806},
9642+ {0xA807, 0xA80A}, {0xA80B, 0xA80B}, {0xA80C, 0xA822},
9643+ {0xA823, 0xA824}, {0xA825, 0xA826}, {0xA827, 0xA827},
9644+ {0xA828, 0xA82B}, {0xA830, 0xA835}, {0xA836, 0xA837},
9645+ {0xA838, 0xA838}, {0xA839, 0xA839}, {0xA840, 0xA873},
9646+ {0xA874, 0xA877}, {0xA880, 0xA881}, {0xA882, 0xA8B3},
9647+ {0xA8B4, 0xA8C3}, {0xA8C4, 0xA8C5}, {0xA8CE, 0xA8CF},
9648+ {0xA8D0, 0xA8D9}, {0xA8E0, 0xA8F1}, {0xA8F2, 0xA8F7},
9649+ {0xA8F8, 0xA8FA}, {0xA8FB, 0xA8FB}, {0xA8FC, 0xA8FC},
9650+ {0xA8FD, 0xA8FD}, {0xA900, 0xA909}, {0xA90A, 0xA925},
9651+ {0xA926, 0xA92D}, {0xA92E, 0xA92F}, {0xA930, 0xA946},
9652+ {0xA947, 0xA951}, {0xA952, 0xA953}, {0xA95F, 0xA95F},
9653+ {0xA980, 0xA982}, {0xA983, 0xA983}, {0xA984, 0xA9B2},
9654+ {0xA9B3, 0xA9B3}, {0xA9B4, 0xA9B5}, {0xA9B6, 0xA9B9},
9655+ {0xA9BA, 0xA9BB}, {0xA9BC, 0xA9BC}, {0xA9BD, 0xA9C0},
9656+ {0xA9C1, 0xA9CD}, {0xA9CF, 0xA9CF}, {0xA9D0, 0xA9D9},
9657+ {0xA9DE, 0xA9DF}, {0xA9E0, 0xA9E4}, {0xA9E5, 0xA9E5},
9658+ {0xA9E6, 0xA9E6}, {0xA9E7, 0xA9EF}, {0xA9F0, 0xA9F9},
9659+ {0xA9FA, 0xA9FE}, {0xAA00, 0xAA28}, {0xAA29, 0xAA2E},
9660+ {0xAA2F, 0xAA30}, {0xAA31, 0xAA32}, {0xAA33, 0xAA34},
9661+ {0xAA35, 0xAA36}, {0xAA40, 0xAA42}, {0xAA43, 0xAA43},
9662+ {0xAA44, 0xAA4B}, {0xAA4C, 0xAA4C}, {0xAA4D, 0xAA4D},
9663+ {0xAA50, 0xAA59}, {0xAA5C, 0xAA5F}, {0xAA60, 0xAA6F},
9664+ {0xAA70, 0xAA70}, {0xAA71, 0xAA76}, {0xAA77, 0xAA79},
9665+ {0xAA7A, 0xAA7A}, {0xAA7B, 0xAA7B}, {0xAA7C, 0xAA7C},
9666+ {0xAA7D, 0xAA7D}, {0xAA7E, 0xAA7F}, {0xAA80, 0xAAAF},
9667+ {0xAAB0, 0xAAB0}, {0xAAB1, 0xAAB1}, {0xAAB2, 0xAAB4},
9668+ {0xAAB5, 0xAAB6}, {0xAAB7, 0xAAB8}, {0xAAB9, 0xAABD},
9669+ {0xAABE, 0xAABF}, {0xAAC0, 0xAAC0}, {0xAAC1, 0xAAC1},
9670+ {0xAAC2, 0xAAC2}, {0xAADB, 0xAADC}, {0xAADD, 0xAADD},
9671+ {0xAADE, 0xAADF}, {0xAAE0, 0xAAEA}, {0xAAEB, 0xAAEB},
9672+ {0xAAEC, 0xAAED}, {0xAAEE, 0xAAEF}, {0xAAF0, 0xAAF1},
9673+ {0xAAF2, 0xAAF2}, {0xAAF3, 0xAAF4}, {0xAAF5, 0xAAF5},
9674+ {0xAAF6, 0xAAF6}, {0xAB01, 0xAB06}, {0xAB09, 0xAB0E},
9675+ {0xAB11, 0xAB16}, {0xAB20, 0xAB26}, {0xAB28, 0xAB2E},
9676+ {0xAB30, 0xAB5A}, {0xAB5B, 0xAB5B}, {0xAB5C, 0xAB5F},
9677+ {0xAB60, 0xAB65}, {0xAB70, 0xABBF}, {0xABC0, 0xABE2},
9678+ {0xABE3, 0xABE4}, {0xABE5, 0xABE5}, {0xABE6, 0xABE7},
9679+ {0xABE8, 0xABE8}, {0xABE9, 0xABEA}, {0xABEB, 0xABEB},
9680+ {0xABEC, 0xABEC}, {0xABED, 0xABED}, {0xABF0, 0xABF9},
9681+ {0xD7B0, 0xD7C6}, {0xD7CB, 0xD7FB}, {0xD800, 0xDB7F},
9682+ {0xDB80, 0xDBFF}, {0xDC00, 0xDFFF}, {0xFB00, 0xFB06},
9683+ {0xFB13, 0xFB17}, {0xFB1D, 0xFB1D}, {0xFB1E, 0xFB1E},
9684+ {0xFB1F, 0xFB28}, {0xFB29, 0xFB29}, {0xFB2A, 0xFB36},
9685+ {0xFB38, 0xFB3C}, {0xFB3E, 0xFB3E}, {0xFB40, 0xFB41},
9686+ {0xFB43, 0xFB44}, {0xFB46, 0xFB4F}, {0xFB50, 0xFBB1},
9687+ {0xFBB2, 0xFBC1}, {0xFBD3, 0xFD3D}, {0xFD3E, 0xFD3E},
9688+ {0xFD3F, 0xFD3F}, {0xFD50, 0xFD8F}, {0xFD92, 0xFDC7},
9689+ {0xFDF0, 0xFDFB}, {0xFDFC, 0xFDFC}, {0xFDFD, 0xFDFD},
9690+ {0xFE20, 0xFE2F}, {0xFE70, 0xFE74}, {0xFE76, 0xFEFC},
9691+ {0xFEFF, 0xFEFF}, {0xFFF9, 0xFFFB}, {0xFFFC, 0xFFFC},
9692+ {0x10000, 0x1000B}, {0x1000D, 0x10026}, {0x10028, 0x1003A},
9693+ {0x1003C, 0x1003D}, {0x1003F, 0x1004D}, {0x10050, 0x1005D},
9694+ {0x10080, 0x100FA}, {0x10100, 0x10102}, {0x10107, 0x10133},
9695+ {0x10137, 0x1013F}, {0x10140, 0x10174}, {0x10175, 0x10178},
9696+ {0x10179, 0x10189}, {0x1018A, 0x1018B}, {0x1018C, 0x1018E},
9697+ {0x10190, 0x1019B}, {0x101A0, 0x101A0}, {0x101D0, 0x101FC},
9698+ {0x101FD, 0x101FD}, {0x10280, 0x1029C}, {0x102A0, 0x102D0},
9699+ {0x102E0, 0x102E0}, {0x102E1, 0x102FB}, {0x10300, 0x1031F},
9700+ {0x10320, 0x10323}, {0x10330, 0x10340}, {0x10341, 0x10341},
9701+ {0x10342, 0x10349}, {0x1034A, 0x1034A}, {0x10350, 0x10375},
9702+ {0x10376, 0x1037A}, {0x10380, 0x1039D}, {0x1039F, 0x1039F},
9703+ {0x103A0, 0x103C3}, {0x103C8, 0x103CF}, {0x103D0, 0x103D0},
9704+ {0x103D1, 0x103D5}, {0x10400, 0x1044F}, {0x10450, 0x1047F},
9705+ {0x10480, 0x1049D}, {0x104A0, 0x104A9}, {0x104B0, 0x104D3},
9706+ {0x104D8, 0x104FB}, {0x10500, 0x10527}, {0x10530, 0x10563},
9707+ {0x1056F, 0x1056F}, {0x10600, 0x10736}, {0x10740, 0x10755},
9708+ {0x10760, 0x10767}, {0x10800, 0x10805}, {0x10808, 0x10808},
9709+ {0x1080A, 0x10835}, {0x10837, 0x10838}, {0x1083C, 0x1083C},
9710+ {0x1083F, 0x1083F}, {0x10840, 0x10855}, {0x10857, 0x10857},
9711+ {0x10858, 0x1085F}, {0x10860, 0x10876}, {0x10877, 0x10878},
9712+ {0x10879, 0x1087F}, {0x10880, 0x1089E}, {0x108A7, 0x108AF},
9713+ {0x108E0, 0x108F2}, {0x108F4, 0x108F5}, {0x108FB, 0x108FF},
9714+ {0x10900, 0x10915}, {0x10916, 0x1091B}, {0x1091F, 0x1091F},
9715+ {0x10920, 0x10939}, {0x1093F, 0x1093F}, {0x10980, 0x1099F},
9716+ {0x109A0, 0x109B7}, {0x109BC, 0x109BD}, {0x109BE, 0x109BF},
9717+ {0x109C0, 0x109CF}, {0x109D2, 0x109FF}, {0x10A00, 0x10A00},
9718+ {0x10A01, 0x10A03}, {0x10A05, 0x10A06}, {0x10A0C, 0x10A0F},
9719+ {0x10A10, 0x10A13}, {0x10A15, 0x10A17}, {0x10A19, 0x10A33},
9720+ {0x10A38, 0x10A3A}, {0x10A3F, 0x10A3F}, {0x10A40, 0x10A47},
9721+ {0x10A50, 0x10A58}, {0x10A60, 0x10A7C}, {0x10A7D, 0x10A7E},
9722+ {0x10A7F, 0x10A7F}, {0x10A80, 0x10A9C}, {0x10A9D, 0x10A9F},
9723+ {0x10AC0, 0x10AC7}, {0x10AC8, 0x10AC8}, {0x10AC9, 0x10AE4},
9724+ {0x10AE5, 0x10AE6}, {0x10AEB, 0x10AEF}, {0x10AF0, 0x10AF6},
9725+ {0x10B00, 0x10B35}, {0x10B39, 0x10B3F}, {0x10B40, 0x10B55},
9726+ {0x10B58, 0x10B5F}, {0x10B60, 0x10B72}, {0x10B78, 0x10B7F},
9727+ {0x10B80, 0x10B91}, {0x10B99, 0x10B9C}, {0x10BA9, 0x10BAF},
9728+ {0x10C00, 0x10C48}, {0x10C80, 0x10CB2}, {0x10CC0, 0x10CF2},
9729+ {0x10CFA, 0x10CFF}, {0x10E60, 0x10E7E}, {0x11000, 0x11000},
9730+ {0x11001, 0x11001}, {0x11002, 0x11002}, {0x11003, 0x11037},
9731+ {0x11038, 0x11046}, {0x11047, 0x1104D}, {0x11052, 0x11065},
9732+ {0x11066, 0x1106F}, {0x1107F, 0x1107F}, {0x11080, 0x11081},
9733+ {0x11082, 0x11082}, {0x11083, 0x110AF}, {0x110B0, 0x110B2},
9734+ {0x110B3, 0x110B6}, {0x110B7, 0x110B8}, {0x110B9, 0x110BA},
9735+ {0x110BB, 0x110BC}, {0x110BD, 0x110BD}, {0x110BE, 0x110C1},
9736+ {0x110D0, 0x110E8}, {0x110F0, 0x110F9}, {0x11100, 0x11102},
9737+ {0x11103, 0x11126}, {0x11127, 0x1112B}, {0x1112C, 0x1112C},
9738+ {0x1112D, 0x11134}, {0x11136, 0x1113F}, {0x11140, 0x11143},
9739+ {0x11150, 0x11172}, {0x11173, 0x11173}, {0x11174, 0x11175},
9740+ {0x11176, 0x11176}, {0x11180, 0x11181}, {0x11182, 0x11182},
9741+ {0x11183, 0x111B2}, {0x111B3, 0x111B5}, {0x111B6, 0x111BE},
9742+ {0x111BF, 0x111C0}, {0x111C1, 0x111C4}, {0x111C5, 0x111C9},
9743+ {0x111CA, 0x111CC}, {0x111CD, 0x111CD}, {0x111D0, 0x111D9},
9744+ {0x111DA, 0x111DA}, {0x111DB, 0x111DB}, {0x111DC, 0x111DC},
9745+ {0x111DD, 0x111DF}, {0x111E1, 0x111F4}, {0x11200, 0x11211},
9746+ {0x11213, 0x1122B}, {0x1122C, 0x1122E}, {0x1122F, 0x11231},
9747+ {0x11232, 0x11233}, {0x11234, 0x11234}, {0x11235, 0x11235},
9748+ {0x11236, 0x11237}, {0x11238, 0x1123D}, {0x1123E, 0x1123E},
9749+ {0x11280, 0x11286}, {0x11288, 0x11288}, {0x1128A, 0x1128D},
9750+ {0x1128F, 0x1129D}, {0x1129F, 0x112A8}, {0x112A9, 0x112A9},
9751+ {0x112B0, 0x112DE}, {0x112DF, 0x112DF}, {0x112E0, 0x112E2},
9752+ {0x112E3, 0x112EA}, {0x112F0, 0x112F9}, {0x11300, 0x11301},
9753+ {0x11302, 0x11303}, {0x11305, 0x1130C}, {0x1130F, 0x11310},
9754+ {0x11313, 0x11328}, {0x1132A, 0x11330}, {0x11332, 0x11333},
9755+ {0x11335, 0x11339}, {0x1133C, 0x1133C}, {0x1133D, 0x1133D},
9756+ {0x1133E, 0x1133F}, {0x11340, 0x11340}, {0x11341, 0x11344},
9757+ {0x11347, 0x11348}, {0x1134B, 0x1134D}, {0x11350, 0x11350},
9758+ {0x11357, 0x11357}, {0x1135D, 0x11361}, {0x11362, 0x11363},
9759+ {0x11366, 0x1136C}, {0x11370, 0x11374}, {0x11400, 0x11434},
9760+ {0x11435, 0x11437}, {0x11438, 0x1143F}, {0x11440, 0x11441},
9761+ {0x11442, 0x11444}, {0x11445, 0x11445}, {0x11446, 0x11446},
9762+ {0x11447, 0x1144A}, {0x1144B, 0x1144F}, {0x11450, 0x11459},
9763+ {0x1145B, 0x1145B}, {0x1145D, 0x1145D}, {0x11480, 0x114AF},
9764+ {0x114B0, 0x114B2}, {0x114B3, 0x114B8}, {0x114B9, 0x114B9},
9765+ {0x114BA, 0x114BA}, {0x114BB, 0x114BE}, {0x114BF, 0x114C0},
9766+ {0x114C1, 0x114C1}, {0x114C2, 0x114C3}, {0x114C4, 0x114C5},
9767+ {0x114C6, 0x114C6}, {0x114C7, 0x114C7}, {0x114D0, 0x114D9},
9768+ {0x11580, 0x115AE}, {0x115AF, 0x115B1}, {0x115B2, 0x115B5},
9769+ {0x115B8, 0x115BB}, {0x115BC, 0x115BD}, {0x115BE, 0x115BE},
9770+ {0x115BF, 0x115C0}, {0x115C1, 0x115D7}, {0x115D8, 0x115DB},
9771+ {0x115DC, 0x115DD}, {0x11600, 0x1162F}, {0x11630, 0x11632},
9772+ {0x11633, 0x1163A}, {0x1163B, 0x1163C}, {0x1163D, 0x1163D},
9773+ {0x1163E, 0x1163E}, {0x1163F, 0x11640}, {0x11641, 0x11643},
9774+ {0x11644, 0x11644}, {0x11650, 0x11659}, {0x11660, 0x1166C},
9775+ {0x11680, 0x116AA}, {0x116AB, 0x116AB}, {0x116AC, 0x116AC},
9776+ {0x116AD, 0x116AD}, {0x116AE, 0x116AF}, {0x116B0, 0x116B5},
9777+ {0x116B6, 0x116B6}, {0x116B7, 0x116B7}, {0x116C0, 0x116C9},
9778+ {0x11700, 0x11719}, {0x1171D, 0x1171F}, {0x11720, 0x11721},
9779+ {0x11722, 0x11725}, {0x11726, 0x11726}, {0x11727, 0x1172B},
9780+ {0x11730, 0x11739}, {0x1173A, 0x1173B}, {0x1173C, 0x1173E},
9781+ {0x1173F, 0x1173F}, {0x118A0, 0x118DF}, {0x118E0, 0x118E9},
9782+ {0x118EA, 0x118F2}, {0x118FF, 0x118FF}, {0x11AC0, 0x11AF8},
9783+ {0x11C00, 0x11C08}, {0x11C0A, 0x11C2E}, {0x11C2F, 0x11C2F},
9784+ {0x11C30, 0x11C36}, {0x11C38, 0x11C3D}, {0x11C3E, 0x11C3E},
9785+ {0x11C3F, 0x11C3F}, {0x11C40, 0x11C40}, {0x11C41, 0x11C45},
9786+ {0x11C50, 0x11C59}, {0x11C5A, 0x11C6C}, {0x11C70, 0x11C71},
9787+ {0x11C72, 0x11C8F}, {0x11C92, 0x11CA7}, {0x11CA9, 0x11CA9},
9788+ {0x11CAA, 0x11CB0}, {0x11CB1, 0x11CB1}, {0x11CB2, 0x11CB3},
9789+ {0x11CB4, 0x11CB4}, {0x11CB5, 0x11CB6}, {0x12000, 0x12399},
9790+ {0x12400, 0x1246E}, {0x12470, 0x12474}, {0x12480, 0x12543},
9791+ {0x13000, 0x1342E}, {0x14400, 0x14646}, {0x16800, 0x16A38},
9792+ {0x16A40, 0x16A5E}, {0x16A60, 0x16A69}, {0x16A6E, 0x16A6F},
9793+ {0x16AD0, 0x16AED}, {0x16AF0, 0x16AF4}, {0x16AF5, 0x16AF5},
9794+ {0x16B00, 0x16B2F}, {0x16B30, 0x16B36}, {0x16B37, 0x16B3B},
9795+ {0x16B3C, 0x16B3F}, {0x16B40, 0x16B43}, {0x16B44, 0x16B44},
9796+ {0x16B45, 0x16B45}, {0x16B50, 0x16B59}, {0x16B5B, 0x16B61},
9797+ {0x16B63, 0x16B77}, {0x16B7D, 0x16B8F}, {0x16F00, 0x16F44},
9798+ {0x16F50, 0x16F50}, {0x16F51, 0x16F7E}, {0x16F8F, 0x16F92},
9799+ {0x16F93, 0x16F9F}, {0x1BC00, 0x1BC6A}, {0x1BC70, 0x1BC7C},
9800+ {0x1BC80, 0x1BC88}, {0x1BC90, 0x1BC99}, {0x1BC9C, 0x1BC9C},
9801+ {0x1BC9D, 0x1BC9E}, {0x1BC9F, 0x1BC9F}, {0x1BCA0, 0x1BCA3},
9802+ {0x1D000, 0x1D0F5}, {0x1D100, 0x1D126}, {0x1D129, 0x1D164},
9803+ {0x1D165, 0x1D166}, {0x1D167, 0x1D169}, {0x1D16A, 0x1D16C},
9804+ {0x1D16D, 0x1D172}, {0x1D173, 0x1D17A}, {0x1D17B, 0x1D182},
9805+ {0x1D183, 0x1D184}, {0x1D185, 0x1D18B}, {0x1D18C, 0x1D1A9},
9806+ {0x1D1AA, 0x1D1AD}, {0x1D1AE, 0x1D1E8}, {0x1D200, 0x1D241},
9807+ {0x1D242, 0x1D244}, {0x1D245, 0x1D245}, {0x1D300, 0x1D356},
9808+ {0x1D360, 0x1D371}, {0x1D400, 0x1D454}, {0x1D456, 0x1D49C},
9809+ {0x1D49E, 0x1D49F}, {0x1D4A2, 0x1D4A2}, {0x1D4A5, 0x1D4A6},
9810+ {0x1D4A9, 0x1D4AC}, {0x1D4AE, 0x1D4B9}, {0x1D4BB, 0x1D4BB},
9811+ {0x1D4BD, 0x1D4C3}, {0x1D4C5, 0x1D505}, {0x1D507, 0x1D50A},
9812+ {0x1D50D, 0x1D514}, {0x1D516, 0x1D51C}, {0x1D51E, 0x1D539},
9813+ {0x1D53B, 0x1D53E}, {0x1D540, 0x1D544}, {0x1D546, 0x1D546},
9814+ {0x1D54A, 0x1D550}, {0x1D552, 0x1D6A5}, {0x1D6A8, 0x1D6C0},
9815+ {0x1D6C1, 0x1D6C1}, {0x1D6C2, 0x1D6DA}, {0x1D6DB, 0x1D6DB},
9816+ {0x1D6DC, 0x1D6FA}, {0x1D6FB, 0x1D6FB}, {0x1D6FC, 0x1D714},
9817+ {0x1D715, 0x1D715}, {0x1D716, 0x1D734}, {0x1D735, 0x1D735},
9818+ {0x1D736, 0x1D74E}, {0x1D74F, 0x1D74F}, {0x1D750, 0x1D76E},
9819+ {0x1D76F, 0x1D76F}, {0x1D770, 0x1D788}, {0x1D789, 0x1D789},
9820+ {0x1D78A, 0x1D7A8}, {0x1D7A9, 0x1D7A9}, {0x1D7AA, 0x1D7C2},
9821+ {0x1D7C3, 0x1D7C3}, {0x1D7C4, 0x1D7CB}, {0x1D7CE, 0x1D7FF},
9822+ {0x1D800, 0x1D9FF}, {0x1DA00, 0x1DA36}, {0x1DA37, 0x1DA3A},
9823+ {0x1DA3B, 0x1DA6C}, {0x1DA6D, 0x1DA74}, {0x1DA75, 0x1DA75},
9824+ {0x1DA76, 0x1DA83}, {0x1DA84, 0x1DA84}, {0x1DA85, 0x1DA86},
9825+ {0x1DA87, 0x1DA8B}, {0x1DA9B, 0x1DA9F}, {0x1DAA1, 0x1DAAF},
9826+ {0x1E000, 0x1E006}, {0x1E008, 0x1E018}, {0x1E01B, 0x1E021},
9827+ {0x1E023, 0x1E024}, {0x1E026, 0x1E02A}, {0x1E800, 0x1E8C4},
9828+ {0x1E8C7, 0x1E8CF}, {0x1E8D0, 0x1E8D6}, {0x1E900, 0x1E943},
9829+ {0x1E944, 0x1E94A}, {0x1E950, 0x1E959}, {0x1E95E, 0x1E95F},
9830+ {0x1EE00, 0x1EE03}, {0x1EE05, 0x1EE1F}, {0x1EE21, 0x1EE22},
9831+ {0x1EE24, 0x1EE24}, {0x1EE27, 0x1EE27}, {0x1EE29, 0x1EE32},
9832+ {0x1EE34, 0x1EE37}, {0x1EE39, 0x1EE39}, {0x1EE3B, 0x1EE3B},
9833+ {0x1EE42, 0x1EE42}, {0x1EE47, 0x1EE47}, {0x1EE49, 0x1EE49},
9834+ {0x1EE4B, 0x1EE4B}, {0x1EE4D, 0x1EE4F}, {0x1EE51, 0x1EE52},
9835+ {0x1EE54, 0x1EE54}, {0x1EE57, 0x1EE57}, {0x1EE59, 0x1EE59},
9836+ {0x1EE5B, 0x1EE5B}, {0x1EE5D, 0x1EE5D}, {0x1EE5F, 0x1EE5F},
9837+ {0x1EE61, 0x1EE62}, {0x1EE64, 0x1EE64}, {0x1EE67, 0x1EE6A},
9838+ {0x1EE6C, 0x1EE72}, {0x1EE74, 0x1EE77}, {0x1EE79, 0x1EE7C},
9839+ {0x1EE7E, 0x1EE7E}, {0x1EE80, 0x1EE89}, {0x1EE8B, 0x1EE9B},
9840+ {0x1EEA1, 0x1EEA3}, {0x1EEA5, 0x1EEA9}, {0x1EEAB, 0x1EEBB},
9841+ {0x1EEF0, 0x1EEF1}, {0x1F000, 0x1F003}, {0x1F005, 0x1F02B},
9842+ {0x1F030, 0x1F093}, {0x1F0A0, 0x1F0AE}, {0x1F0B1, 0x1F0BF},
9843+ {0x1F0C1, 0x1F0CE}, {0x1F0D1, 0x1F0F5}, {0x1F10B, 0x1F10C},
9844+ {0x1F12E, 0x1F12E}, {0x1F16A, 0x1F16B}, {0x1F1E6, 0x1F1FF},
9845+ {0x1F321, 0x1F32C}, {0x1F336, 0x1F336}, {0x1F37D, 0x1F37D},
9846+ {0x1F394, 0x1F39F}, {0x1F3CB, 0x1F3CE}, {0x1F3D4, 0x1F3DF},
9847+ {0x1F3F1, 0x1F3F3}, {0x1F3F5, 0x1F3F7}, {0x1F43F, 0x1F43F},
9848+ {0x1F441, 0x1F441}, {0x1F4FD, 0x1F4FE}, {0x1F53E, 0x1F54A},
9849+ {0x1F54F, 0x1F54F}, {0x1F568, 0x1F579}, {0x1F57B, 0x1F594},
9850+ {0x1F597, 0x1F5A3}, {0x1F5A5, 0x1F5FA}, {0x1F650, 0x1F67F},
9851+ {0x1F6C6, 0x1F6CB}, {0x1F6CD, 0x1F6CF}, {0x1F6E0, 0x1F6EA},
9852+ {0x1F6F0, 0x1F6F3}, {0x1F700, 0x1F773}, {0x1F780, 0x1F7D4},
9853+ {0x1F800, 0x1F80B}, {0x1F810, 0x1F847}, {0x1F850, 0x1F859},
9854+ {0x1F860, 0x1F887}, {0x1F890, 0x1F8AD}, {0xE0001, 0xE0001},
9855+ {0xE0020, 0xE007F},
9856+ }
9857+
9858+ // Condition have flag EastAsianWidth whether the current locale is CJK or not.
9859+ type Condition struct {
9860+ EastAsianWidth bool
9861+ }
9862+
9863+ // NewCondition return new instance of Condition which is current locale.
9864+ func NewCondition() *Condition {
9865+ return &Condition{EastAsianWidth}
9866+ }
9867+
9868+ // RuneWidth returns the number of cells in r.
9869+ // See http://www.unicode.org/reports/tr11/
9870+ func (c *Condition) RuneWidth(r rune) int {
9871+ switch {
9872+ case r < 0 || r > 0x10FFFF ||
9873+ inTables(r, nonprint, combining, notassigned):
9874+ return 0
9875+ case (c.EastAsianWidth && IsAmbiguousWidth(r)) ||
9876+ inTables(r, doublewidth, emoji):
9877+ return 2
9878+ default:
9879+ return 1
9880+ }
9881+ }
9882+
9883+ // StringWidth return width as you can see
9884+ func (c *Condition) StringWidth(s string) (width int) {
9885+ for _, r := range []rune(s) {
9886+ width += c.RuneWidth(r)
9887+ }
9888+ return width
9889+ }
9890+
9891+ // Truncate return string truncated with w cells
9892+ func (c *Condition) Truncate(s string, w int, tail string) string {
9893+ if c.StringWidth(s) <= w {
9894+ return s
9895+ }
9896+ r := []rune(s)
9897+ tw := c.StringWidth(tail)
9898+ w -= tw
9899+ width := 0
9900+ i := 0
9901+ for ; i < len(r); i++ {
9902+ cw := c.RuneWidth(r[i])
9903+ if width+cw > w {
9904+ break
9905+ }
9906+ width += cw
9907+ }
9908+ return string(r[0:i]) + tail
9909+ }
9910+
9911+ // Wrap return string wrapped with w cells
9912+ func (c *Condition) Wrap(s string, w int) string {
9913+ width := 0
9914+ out := ""
9915+ for _, r := range []rune(s) {
9916+ cw := RuneWidth(r)
9917+ if r == '\n' {
9918+ out += string(r)
9919+ width = 0
9920+ continue
9921+ } else if width+cw > w {
9922+ out += "\n"
9923+ width = 0
9924+ out += string(r)
9925+ width += cw
9926+ continue
9927+ }
9928+ out += string(r)
9929+ width += cw
9930+ }
9931+ return out
9932+ }
9933+
9934+ // FillLeft return string filled in left by spaces in w cells
9935+ func (c *Condition) FillLeft(s string, w int) string {
9936+ width := c.StringWidth(s)
9937+ count := w - width
9938+ if count > 0 {
9939+ b := make([]byte, count)
9940+ for i := range b {
9941+ b[i] = ' '
9942+ }
9943+ return string(b) + s
9944+ }
9945+ return s
9946+ }
9947+
9948+ // FillRight return string filled in left by spaces in w cells
9949+ func (c *Condition) FillRight(s string, w int) string {
9950+ width := c.StringWidth(s)
9951+ count := w - width
9952+ if count > 0 {
9953+ b := make([]byte, count)
9954+ for i := range b {
9955+ b[i] = ' '
9956+ }
9957+ return s + string(b)
9958+ }
9959+ return s
9960+ }
9961+
9962+ // RuneWidth returns the number of cells in r.
9963+ // See http://www.unicode.org/reports/tr11/
9964+ func RuneWidth(r rune) int {
9965+ return DefaultCondition.RuneWidth(r)
9966+ }
9967+
9968+ // IsAmbiguousWidth returns whether is ambiguous width or not.
9969+ func IsAmbiguousWidth(r rune) bool {
9970+ return inTables(r, private, ambiguous)
9971+ }
9972+
9973+ // IsNeutralWidth returns whether is neutral width or not.
9974+ func IsNeutralWidth(r rune) bool {
9975+ return inTable(r, neutral)
9976+ }
9977+
9978+ // StringWidth return width as you can see
9979+ func StringWidth(s string) (width int) {
9980+ return DefaultCondition.StringWidth(s)
9981+ }
9982+
9983+ // Truncate return string truncated with w cells
9984+ func Truncate(s string, w int, tail string) string {
9985+ return DefaultCondition.Truncate(s, w, tail)
9986+ }
9987+
9988+ // Wrap return string wrapped with w cells
9989+ func Wrap(s string, w int) string {
9990+ return DefaultCondition.Wrap(s, w)
9991+ }
9992+
9993+ // FillLeft return string filled in left by spaces in w cells
9994+ func FillLeft(s string, w int) string {
9995+ return DefaultCondition.FillLeft(s, w)
9996+ }
9997+
9998+ // FillRight return string filled in left by spaces in w cells
9999+ func FillRight(s string, w int) string {
10000+ return DefaultCondition.FillRight(s, w)
10001+ }
10002 diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_js.go b/vendor/github.com/mattn/go-runewidth/runewidth_js.go
10003new file mode 100644
10004index 0000000..0ce32c5
10005--- /dev/null
10006+++ b/vendor/github.com/mattn/go-runewidth/runewidth_js.go
10007 @@ -0,0 +1,8 @@
10008+ // +build js
10009+
10010+ package runewidth
10011+
10012+ func IsEastAsian() bool {
10013+ // TODO: Implement this for the web. Detect east asian in a compatible way, and return true.
10014+ return false
10015+ }
10016 diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_posix.go b/vendor/github.com/mattn/go-runewidth/runewidth_posix.go
10017new file mode 100644
10018index 0000000..c579e9a
10019--- /dev/null
10020+++ b/vendor/github.com/mattn/go-runewidth/runewidth_posix.go
10021 @@ -0,0 +1,77 @@
10022+ // +build !windows,!js
10023+
10024+ package runewidth
10025+
10026+ import (
10027+ "os"
10028+ "regexp"
10029+ "strings"
10030+ )
10031+
10032+ var reLoc = regexp.MustCompile(`^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)`)
10033+
10034+ var mblenTable = map[string]int{
10035+ "utf-8": 6,
10036+ "utf8": 6,
10037+ "jis": 8,
10038+ "eucjp": 3,
10039+ "euckr": 2,
10040+ "euccn": 2,
10041+ "sjis": 2,
10042+ "cp932": 2,
10043+ "cp51932": 2,
10044+ "cp936": 2,
10045+ "cp949": 2,
10046+ "cp950": 2,
10047+ "big5": 2,
10048+ "gbk": 2,
10049+ "gb2312": 2,
10050+ }
10051+
10052+ func isEastAsian(locale string) bool {
10053+ charset := strings.ToLower(locale)
10054+ r := reLoc.FindStringSubmatch(locale)
10055+ if len(r) == 2 {
10056+ charset = strings.ToLower(r[1])
10057+ }
10058+
10059+ if strings.HasSuffix(charset, "@cjk_narrow") {
10060+ return false
10061+ }
10062+
10063+ for pos, b := range []byte(charset) {
10064+ if b == '@' {
10065+ charset = charset[:pos]
10066+ break
10067+ }
10068+ }
10069+ max := 1
10070+ if m, ok := mblenTable[charset]; ok {
10071+ max = m
10072+ }
10073+ if max > 1 && (charset[0] != 'u' ||
10074+ strings.HasPrefix(locale, "ja") ||
10075+ strings.HasPrefix(locale, "ko") ||
10076+ strings.HasPrefix(locale, "zh")) {
10077+ return true
10078+ }
10079+ return false
10080+ }
10081+
10082+ // IsEastAsian return true if the current locale is CJK
10083+ func IsEastAsian() bool {
10084+ locale := os.Getenv("LC_CTYPE")
10085+ if locale == "" {
10086+ locale = os.Getenv("LANG")
10087+ }
10088+
10089+ // ignore C locale
10090+ if locale == "POSIX" || locale == "C" {
10091+ return false
10092+ }
10093+ if len(locale) > 1 && locale[0] == 'C' && (locale[1] == '.' || locale[1] == '-') {
10094+ return false
10095+ }
10096+
10097+ return isEastAsian(locale)
10098+ }
10099 diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_test.go b/vendor/github.com/mattn/go-runewidth/runewidth_test.go
10100new file mode 100644
10101index 0000000..b0378a1
10102--- /dev/null
10103+++ b/vendor/github.com/mattn/go-runewidth/runewidth_test.go
10104 @@ -0,0 +1,275 @@
10105+ package runewidth
10106+
10107+ import (
10108+ "sort"
10109+ "testing"
10110+ )
10111+
10112+ var _ sort.Interface = (*table)(nil)
10113+
10114+ func (t table) Len() int {
10115+ return len(t)
10116+ }
10117+
10118+ func (t table) Less(i, j int) bool {
10119+ return t[i].first < t[j].first
10120+ }
10121+
10122+ func (t *table) Swap(i, j int) {
10123+ (*t)[i], (*t)[j] = (*t)[j], (*t)[i]
10124+ }
10125+
10126+ var tables = []table{
10127+ private,
10128+ nonprint,
10129+ combining,
10130+ doublewidth,
10131+ ambiguous,
10132+ emoji,
10133+ notassigned,
10134+ neutral,
10135+ }
10136+
10137+ func TestSorted(t *testing.T) {
10138+ for _, tbl := range tables {
10139+ if !sort.IsSorted(&tbl) {
10140+ t.Errorf("not sorted")
10141+ }
10142+ }
10143+ }
10144+
10145+ var runewidthtests = []struct {
10146+ in rune
10147+ out int
10148+ eaout int
10149+ }{
10150+ {'世', 2, 2},
10151+ {'界', 2, 2},
10152+ {'セ', 1, 1},
10153+ {'カ', 1, 1},
10154+ {'イ', 1, 1},
10155+ {'☆', 1, 2}, // double width in ambiguous
10156+ {'\x00', 0, 0},
10157+ {'\x01', 0, 0},
10158+ {'\u0300', 0, 0},
10159+ }
10160+
10161+ func TestRuneWidth(t *testing.T) {
10162+ c := NewCondition()
10163+ for _, tt := range runewidthtests {
10164+ if out := c.RuneWidth(tt.in); out != tt.out {
10165+ t.Errorf("RuneWidth(%q) = %d, want %d", tt.in, out, tt.out)
10166+ }
10167+ }
10168+ c.EastAsianWidth = true
10169+ for _, tt := range runewidthtests {
10170+ if out := c.RuneWidth(tt.in); out != tt.eaout {
10171+ t.Errorf("RuneWidth(%q) = %d, want %d", tt.in, out, tt.eaout)
10172+ }
10173+ }
10174+ }
10175+
10176+ var isambiguouswidthtests = []struct {
10177+ in rune
10178+ out bool
10179+ }{
10180+ {'世', false},
10181+ {'■', true},
10182+ {'界', false},
10183+ {'○', true},
10184+ {'㈱', false},
10185+ {'①', true},
10186+ {'②', true},
10187+ {'③', true},
10188+ {'④', true},
10189+ {'⑤', true},
10190+ {'⑥', true},
10191+ {'⑦', true},
10192+ {'⑧', true},
10193+ {'⑨', true},
10194+ {'⑩', true},
10195+ {'⑪', true},
10196+ {'⑫', true},
10197+ {'⑬', true},
10198+ {'⑭', true},
10199+ {'⑮', true},
10200+ {'⑯', true},
10201+ {'⑰', true},
10202+ {'⑱', true},
10203+ {'⑲', true},
10204+ {'⑳', true},
10205+ {'☆', true},
10206+ }
10207+
10208+ func TestIsAmbiguousWidth(t *testing.T) {
10209+ for _, tt := range isambiguouswidthtests {
10210+ if out := IsAmbiguousWidth(tt.in); out != tt.out {
10211+ t.Errorf("IsAmbiguousWidth(%q) = %v, want %v", tt.in, out, tt.out)
10212+ }
10213+ }
10214+ }
10215+
10216+ var stringwidthtests = []struct {
10217+ in string
10218+ out int
10219+ eaout int
10220+ }{
10221+ {"■㈱の世界①", 10, 12},
10222+ {"スター☆", 7, 8},
10223+ {"つのだ☆HIRO", 11, 12},
10224+ }
10225+
10226+ func TestStringWidth(t *testing.T) {
10227+ c := NewCondition()
10228+ for _, tt := range stringwidthtests {
10229+ if out := c.StringWidth(tt.in); out != tt.out {
10230+ t.Errorf("StringWidth(%q) = %q, want %q", tt.in, out, tt.out)
10231+ }
10232+ }
10233+ c.EastAsianWidth = true
10234+ for _, tt := range stringwidthtests {
10235+ if out := c.StringWidth(tt.in); out != tt.eaout {
10236+ t.Errorf("StringWidth(%q) = %q, want %q", tt.in, out, tt.eaout)
10237+ }
10238+ }
10239+ }
10240+
10241+ func TestStringWidthInvalid(t *testing.T) {
10242+ s := "こんにちわ\x00世界"
10243+ if out := StringWidth(s); out != 14 {
10244+ t.Errorf("StringWidth(%q) = %q, want %q", s, out, 14)
10245+ }
10246+ }
10247+
10248+ func TestTruncateSmaller(t *testing.T) {
10249+ s := "あいうえお"
10250+ expected := "あいうえお"
10251+
10252+ if out := Truncate(s, 10, "..."); out != expected {
10253+ t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
10254+ }
10255+ }
10256+
10257+ func TestTruncate(t *testing.T) {
10258+ s := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
10259+ expected := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおお..."
10260+ out := Truncate(s, 80, "...")
10261+ if out != expected {
10262+ t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
10263+ }
10264+ width := StringWidth(out)
10265+ if width != 79 {
10266+ t.Errorf("width of Truncate(%q) should be %d, but %d", s, 79, width)
10267+ }
10268+ }
10269+
10270+ func TestTruncateFit(t *testing.T) {
10271+ s := "aあいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
10272+ expected := "aあいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおお..."
10273+
10274+ out := Truncate(s, 80, "...")
10275+ if out != expected {
10276+ t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
10277+ }
10278+ width := StringWidth(out)
10279+ if width != 80 {
10280+ t.Errorf("width of Truncate(%q) should be %d, but %d", s, 80, width)
10281+ }
10282+ }
10283+
10284+ func TestTruncateJustFit(t *testing.T) {
10285+ s := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
10286+ expected := "あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおお"
10287+
10288+ out := Truncate(s, 80, "...")
10289+ if out != expected {
10290+ t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
10291+ }
10292+ width := StringWidth(out)
10293+ if width != 80 {
10294+ t.Errorf("width of Truncate(%q) should be %d, but %d", s, 80, width)
10295+ }
10296+ }
10297+
10298+ func TestWrap(t *testing.T) {
10299+ s := `東京特許許可局局長はよく柿喰う客だ/東京特許許可局局長はよく柿喰う客だ
10300+ 123456789012345678901234567890
10301+
10302+ END`
10303+ expected := `東京特許許可局局長はよく柿喰う
10304+ 客だ/東京特許許可局局長はよく
10305+ 柿喰う客だ
10306+ 123456789012345678901234567890
10307+
10308+ END`
10309+
10310+ if out := Wrap(s, 30); out != expected {
10311+ t.Errorf("Wrap(%q) = %q, want %q", s, out, expected)
10312+ }
10313+ }
10314+
10315+ func TestTruncateNoNeeded(t *testing.T) {
10316+ s := "あいうえおあい"
10317+ expected := "あいうえおあい"
10318+
10319+ if out := Truncate(s, 80, "..."); out != expected {
10320+ t.Errorf("Truncate(%q) = %q, want %q", s, out, expected)
10321+ }
10322+ }
10323+
10324+ var isneutralwidthtests = []struct {
10325+ in rune
10326+ out bool
10327+ }{
10328+ {'→', false},
10329+ {'┊', false},
10330+ {'┈', false},
10331+ {'~', false},
10332+ {'└', false},
10333+ {'⣀', true},
10334+ {'⣀', true},
10335+ }
10336+
10337+ func TestIsNeutralWidth(t *testing.T) {
10338+ for _, tt := range isneutralwidthtests {
10339+ if out := IsNeutralWidth(tt.in); out != tt.out {
10340+ t.Errorf("IsNeutralWidth(%q) = %v, want %v", tt.in, out, tt.out)
10341+ }
10342+ }
10343+ }
10344+
10345+ func TestFillLeft(t *testing.T) {
10346+ s := "あxいうえお"
10347+ expected := " あxいうえお"
10348+
10349+ if out := FillLeft(s, 15); out != expected {
10350+ t.Errorf("FillLeft(%q) = %q, want %q", s, out, expected)
10351+ }
10352+ }
10353+
10354+ func TestFillLeftFit(t *testing.T) {
10355+ s := "あいうえお"
10356+ expected := "あいうえお"
10357+
10358+ if out := FillLeft(s, 10); out != expected {
10359+ t.Errorf("FillLeft(%q) = %q, want %q", s, out, expected)
10360+ }
10361+ }
10362+
10363+ func TestFillRight(t *testing.T) {
10364+ s := "あxいうえお"
10365+ expected := "あxいうえお "
10366+
10367+ if out := FillRight(s, 15); out != expected {
10368+ t.Errorf("FillRight(%q) = %q, want %q", s, out, expected)
10369+ }
10370+ }
10371+
10372+ func TestFillRightFit(t *testing.T) {
10373+ s := "あいうえお"
10374+ expected := "あいうえお"
10375+
10376+ if out := FillRight(s, 10); out != expected {
10377+ t.Errorf("FillRight(%q) = %q, want %q", s, out, expected)
10378+ }
10379+ }
10380 diff --git a/vendor/github.com/mattn/go-runewidth/runewidth_windows.go b/vendor/github.com/mattn/go-runewidth/runewidth_windows.go
10381new file mode 100644
10382index 0000000..0258876
10383--- /dev/null
10384+++ b/vendor/github.com/mattn/go-runewidth/runewidth_windows.go
10385 @@ -0,0 +1,25 @@
10386+ package runewidth
10387+
10388+ import (
10389+ "syscall"
10390+ )
10391+
10392+ var (
10393+ kernel32 = syscall.NewLazyDLL("kernel32")
10394+ procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP")
10395+ )
10396+
10397+ // IsEastAsian return true if the current locale is CJK
10398+ func IsEastAsian() bool {
10399+ r1, _, _ := procGetConsoleOutputCP.Call()
10400+ if r1 == 0 {
10401+ return false
10402+ }
10403+
10404+ switch int(r1) {
10405+ case 932, 51932, 936, 949, 950:
10406+ return true
10407+ }
10408+
10409+ return false
10410+ }
10411 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/custom_func/main.go b/vendor/github.com/mattn/go-sqlite3/_example/custom_func/main.go
10412deleted file mode 100644
10413index 85657e6..0000000
10414--- a/vendor/github.com/mattn/go-sqlite3/_example/custom_func/main.go
10415+++ /dev/null
10416 @@ -1,133 +0,0 @@
10417- package main
10418-
10419- import (
10420- "database/sql"
10421- "fmt"
10422- "log"
10423- "math"
10424- "math/rand"
10425-
10426- sqlite "github.com/mattn/go-sqlite3"
10427- )
10428-
10429- // Computes x^y
10430- func pow(x, y int64) int64 {
10431- return int64(math.Pow(float64(x), float64(y)))
10432- }
10433-
10434- // Computes the bitwise exclusive-or of all its arguments
10435- func xor(xs ...int64) int64 {
10436- var ret int64
10437- for _, x := range xs {
10438- ret ^= x
10439- }
10440- return ret
10441- }
10442-
10443- // Returns a random number. It's actually deterministic here because
10444- // we don't seed the RNG, but it's an example of a non-pure function
10445- // from SQLite's POV.
10446- func getrand() int64 {
10447- return rand.Int63()
10448- }
10449-
10450- // Computes the standard deviation of a GROUPed BY set of values
10451- type stddev struct {
10452- xs []int64
10453- // Running average calculation
10454- sum int64
10455- n int64
10456- }
10457-
10458- func newStddev() *stddev { return &stddev{} }
10459-
10460- func (s *stddev) Step(x int64) {
10461- s.xs = append(s.xs, x)
10462- s.sum += x
10463- s.n++
10464- }
10465-
10466- func (s *stddev) Done() float64 {
10467- mean := float64(s.sum) / float64(s.n)
10468- var sqDiff []float64
10469- for _, x := range s.xs {
10470- sqDiff = append(sqDiff, math.Pow(float64(x)-mean, 2))
10471- }
10472- var dev float64
10473- for _, x := range sqDiff {
10474- dev += x
10475- }
10476- dev /= float64(len(sqDiff))
10477- return math.Sqrt(dev)
10478- }
10479-
10480- func main() {
10481- sql.Register("sqlite3_custom", &sqlite.SQLiteDriver{
10482- ConnectHook: func(conn *sqlite.SQLiteConn) error {
10483- if err := conn.RegisterFunc("pow", pow, true); err != nil {
10484- return err
10485- }
10486- if err := conn.RegisterFunc("xor", xor, true); err != nil {
10487- return err
10488- }
10489- if err := conn.RegisterFunc("rand", getrand, false); err != nil {
10490- return err
10491- }
10492- if err := conn.RegisterAggregator("stddev", newStddev, true); err != nil {
10493- return err
10494- }
10495- return nil
10496- },
10497- })
10498-
10499- db, err := sql.Open("sqlite3_custom", ":memory:")
10500- if err != nil {
10501- log.Fatal("Failed to open database:", err)
10502- }
10503- defer db.Close()
10504-
10505- var i int64
10506- err = db.QueryRow("SELECT pow(2,3)").Scan(&i)
10507- if err != nil {
10508- log.Fatal("POW query error:", err)
10509- }
10510- fmt.Println("pow(2,3) =", i) // 8
10511-
10512- err = db.QueryRow("SELECT xor(1,2,3,4,5,6)").Scan(&i)
10513- if err != nil {
10514- log.Fatal("XOR query error:", err)
10515- }
10516- fmt.Println("xor(1,2,3,4,5) =", i) // 7
10517-
10518- err = db.QueryRow("SELECT rand()").Scan(&i)
10519- if err != nil {
10520- log.Fatal("RAND query error:", err)
10521- }
10522- fmt.Println("rand() =", i) // pseudorandom
10523-
10524- _, err = db.Exec("create table foo (department integer, profits integer)")
10525- if err != nil {
10526- log.Fatal("Failed to create table:", err)
10527- }
10528- _, err = db.Exec("insert into foo values (1, 10), (1, 20), (1, 45), (2, 42), (2, 115)")
10529- if err != nil {
10530- log.Fatal("Failed to insert records:", err)
10531- }
10532-
10533- rows, err := db.Query("select department, stddev(profits) from foo group by department")
10534- if err != nil {
10535- log.Fatal("STDDEV query error:", err)
10536- }
10537- defer rows.Close()
10538- for rows.Next() {
10539- var dept int64
10540- var dev float64
10541- if err := rows.Scan(&dept, &dev); err != nil {
10542- log.Fatal(err)
10543- }
10544- fmt.Printf("dept=%d stddev=%f\n", dept, dev)
10545- }
10546- if err := rows.Err(); err != nil {
10547- log.Fatal(err)
10548- }
10549- }
10550 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/hook/hook.go b/vendor/github.com/mattn/go-sqlite3/_example/hook/hook.go
10551deleted file mode 100644
10552index 6023181..0000000
10553--- a/vendor/github.com/mattn/go-sqlite3/_example/hook/hook.go
10554+++ /dev/null
10555 @@ -1,78 +0,0 @@
10556- package main
10557-
10558- import (
10559- "database/sql"
10560- "log"
10561- "os"
10562-
10563- "github.com/mattn/go-sqlite3"
10564- )
10565-
10566- func main() {
10567- sqlite3conn := []*sqlite3.SQLiteConn{}
10568- sql.Register("sqlite3_with_hook_example",
10569- &sqlite3.SQLiteDriver{
10570- ConnectHook: func(conn *sqlite3.SQLiteConn) error {
10571- sqlite3conn = append(sqlite3conn, conn)
10572- conn.RegisterUpdateHook(func(op int, db string, table string, rowid int64) {
10573- switch op {
10574- case sqlite3.SQLITE_INSERT:
10575- log.Println("Notified of insert on db", db, "table", table, "rowid", rowid)
10576- }
10577- })
10578- return nil
10579- },
10580- })
10581- os.Remove("./foo.db")
10582- os.Remove("./bar.db")
10583-
10584- srcDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
10585- if err != nil {
10586- log.Fatal(err)
10587- }
10588- defer srcDb.Close()
10589- srcDb.Ping()
10590-
10591- _, err = srcDb.Exec("create table foo(id int, value text)")
10592- if err != nil {
10593- log.Fatal(err)
10594- }
10595- _, err = srcDb.Exec("insert into foo values(1, 'foo')")
10596- if err != nil {
10597- log.Fatal(err)
10598- }
10599- _, err = srcDb.Exec("insert into foo values(2, 'bar')")
10600- if err != nil {
10601- log.Fatal(err)
10602- }
10603- _, err = srcDb.Query("select * from foo")
10604- if err != nil {
10605- log.Fatal(err)
10606- }
10607- destDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
10608- if err != nil {
10609- log.Fatal(err)
10610- }
10611- defer destDb.Close()
10612- destDb.Ping()
10613-
10614- bk, err := sqlite3conn[1].Backup("main", sqlite3conn[0], "main")
10615- if err != nil {
10616- log.Fatal(err)
10617- }
10618-
10619- _, err = bk.Step(-1)
10620- if err != nil {
10621- log.Fatal(err)
10622- }
10623- _, err = destDb.Query("select * from foo")
10624- if err != nil {
10625- log.Fatal(err)
10626- }
10627- _, err = destDb.Exec("insert into foo values(3, 'bar')")
10628- if err != nil {
10629- log.Fatal(err)
10630- }
10631-
10632- bk.Finish()
10633- }
10634 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/limit/limit.go b/vendor/github.com/mattn/go-sqlite3/_example/limit/limit.go
10635deleted file mode 100644
10636index 4e4b897..0000000
10637--- a/vendor/github.com/mattn/go-sqlite3/_example/limit/limit.go
10638+++ /dev/null
10639 @@ -1,113 +0,0 @@
10640- package main
10641-
10642- import (
10643- "database/sql"
10644- "fmt"
10645- "log"
10646- "os"
10647- "strings"
10648-
10649- "github.com/mattn/go-sqlite3"
10650- )
10651-
10652- func createBulkInsertQuery(n int, start int) (query string, args []interface{}) {
10653- values := make([]string, n)
10654- args = make([]interface{}, n*2)
10655- pos := 0
10656- for i := 0; i < n; i++ {
10657- values[i] = "(?, ?)"
10658- args[pos] = start + i
10659- args[pos+1] = fmt.Sprintf("こんにちわ世界%03d", i)
10660- pos += 2
10661- }
10662- query = fmt.Sprintf(
10663- "insert into foo(id, name) values %s",
10664- strings.Join(values, ", "),
10665- )
10666- return
10667- }
10668-
10669- func bukInsert(db *sql.DB, query string, args []interface{}) (err error) {
10670- stmt, err := db.Prepare(query)
10671- if err != nil {
10672- return
10673- }
10674-
10675- _, err = stmt.Exec(args...)
10676- if err != nil {
10677- return
10678- }
10679-
10680- return
10681- }
10682-
10683- func main() {
10684- var sqlite3conn *sqlite3.SQLiteConn
10685- sql.Register("sqlite3_with_limit", &sqlite3.SQLiteDriver{
10686- ConnectHook: func(conn *sqlite3.SQLiteConn) error {
10687- sqlite3conn = conn
10688- return nil
10689- },
10690- })
10691-
10692- os.Remove("./foo.db")
10693- db, err := sql.Open("sqlite3_with_limit", "./foo.db")
10694- if err != nil {
10695- log.Fatal(err)
10696- }
10697- defer db.Close()
10698-
10699- sqlStmt := `
10700- create table foo (id integer not null primary key, name text);
10701- delete from foo;
10702- `
10703- _, err = db.Exec(sqlStmt)
10704- if err != nil {
10705- log.Printf("%q: %s\n", err, sqlStmt)
10706- return
10707- }
10708-
10709- if sqlite3conn == nil {
10710- log.Fatal("not set sqlite3 connection")
10711- }
10712-
10713- limitVariableNumber := sqlite3conn.GetLimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER)
10714- log.Printf("default SQLITE_LIMIT_VARIABLE_NUMBER: %d", limitVariableNumber)
10715-
10716- num := 400
10717- query, args := createBulkInsertQuery(num, 0)
10718- err = bukInsert(db, query, args)
10719- if err != nil {
10720- log.Fatal(err)
10721- }
10722-
10723- smallLimitVariableNumber := 100
10724- sqlite3conn.SetLimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER, smallLimitVariableNumber)
10725-
10726- limitVariableNumber = sqlite3conn.GetLimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER)
10727- log.Printf("updated SQLITE_LIMIT_VARIABLE_NUMBER: %d", limitVariableNumber)
10728-
10729- query, args = createBulkInsertQuery(num, num)
10730- err = bukInsert(db, query, args)
10731- if err != nil {
10732- if err != nil {
10733- log.Printf("expect failed since SQLITE_LIMIT_VARIABLE_NUMBER is too small: %v", err)
10734- }
10735- }
10736-
10737- bigLimitVariableNumber := 999999
10738- sqlite3conn.SetLimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER, bigLimitVariableNumber)
10739- limitVariableNumber = sqlite3conn.GetLimit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER)
10740- log.Printf("set SQLITE_LIMIT_VARIABLE_NUMBER: %d", bigLimitVariableNumber)
10741- log.Printf("updated SQLITE_LIMIT_VARIABLE_NUMBER: %d", limitVariableNumber)
10742-
10743- query, args = createBulkInsertQuery(500, num+num)
10744- err = bukInsert(db, query, args)
10745- if err != nil {
10746- if err != nil {
10747- log.Fatal(err)
10748- }
10749- }
10750-
10751- log.Println("no error if SQLITE_LIMIT_VARIABLE_NUMBER > 999")
10752- }
10753 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/Makefile b/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/Makefile
10754deleted file mode 100644
10755index 97b1e0f..0000000
10756--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/Makefile
10757+++ /dev/null
10758 @@ -1,22 +0,0 @@
10759- ifeq ($(OS),Windows_NT)
10760- EXE=extension.exe
10761- EXT=sqlite3_mod_regexp.dll
10762- RM=cmd /c del
10763- LDFLAG=
10764- else
10765- EXE=extension
10766- EXT=sqlite3_mod_regexp.so
10767- RM=rm
10768- LDFLAG=-fPIC
10769- endif
10770-
10771- all : $(EXE) $(EXT)
10772-
10773- $(EXE) : extension.go
10774- go build $<
10775-
10776- $(EXT) : sqlite3_mod_regexp.c
10777- gcc $(LDFLAG) -shared -o $@ $< -lsqlite3 -lpcre
10778-
10779- clean :
10780- @-$(RM) $(EXE) $(EXT)
10781 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/extension.go b/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/extension.go
10782deleted file mode 100644
10783index 61ceb55..0000000
10784--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/extension.go
10785+++ /dev/null
10786 @@ -1,43 +0,0 @@
10787- package main
10788-
10789- import (
10790- "database/sql"
10791- "fmt"
10792- "github.com/mattn/go-sqlite3"
10793- "log"
10794- )
10795-
10796- func main() {
10797- sql.Register("sqlite3_with_extensions",
10798- &sqlite3.SQLiteDriver{
10799- Extensions: []string{
10800- "sqlite3_mod_regexp",
10801- },
10802- })
10803-
10804- db, err := sql.Open("sqlite3_with_extensions", ":memory:")
10805- if err != nil {
10806- log.Fatal(err)
10807- }
10808- defer db.Close()
10809-
10810- // Force db to make a new connection in pool
10811- // by putting the original in a transaction
10812- tx, err := db.Begin()
10813- if err != nil {
10814- log.Fatal(err)
10815- }
10816- defer tx.Commit()
10817-
10818- // New connection works (hopefully!)
10819- rows, err := db.Query("select 'hello world' where 'hello world' regexp '^hello.*d$'")
10820- if err != nil {
10821- log.Fatal(err)
10822- }
10823- defer rows.Close()
10824- for rows.Next() {
10825- var helloworld string
10826- rows.Scan(&helloworld)
10827- fmt.Println(helloworld)
10828- }
10829- }
10830 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/sqlite3_mod_regexp.c b/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/sqlite3_mod_regexp.c
10831deleted file mode 100644
10832index 277764d..0000000
10833--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_regexp/sqlite3_mod_regexp.c
10834+++ /dev/null
10835 @@ -1,31 +0,0 @@
10836- #include <pcre.h>
10837- #include <string.h>
10838- #include <stdio.h>
10839- #include <sqlite3ext.h>
10840-
10841- SQLITE_EXTENSION_INIT1
10842- static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
10843- if (argc >= 2) {
10844- const char *target = (const char *)sqlite3_value_text(argv[1]);
10845- const char *pattern = (const char *)sqlite3_value_text(argv[0]);
10846- const char* errstr = NULL;
10847- int erroff = 0;
10848- int vec[500];
10849- int n, rc;
10850- pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
10851- rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
10852- if (rc <= 0) {
10853- sqlite3_result_error(context, errstr, 0);
10854- return;
10855- }
10856- sqlite3_result_int(context, 1);
10857- }
10858- }
10859-
10860- #ifdef _WIN32
10861- __declspec(dllexport)
10862- #endif
10863- int sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) {
10864- SQLITE_EXTENSION_INIT2(api);
10865- return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, (void*)db, regexp_func, NULL, NULL);
10866- }
10867 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/Makefile b/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/Makefile
10868deleted file mode 100644
10869index cdd4853..0000000
10870--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/Makefile
10871+++ /dev/null
10872 @@ -1,24 +0,0 @@
10873- ifeq ($(OS),Windows_NT)
10874- EXE=extension.exe
10875- EXT=sqlite3_mod_vtable.dll
10876- RM=cmd /c del
10877- LIBCURL=-lcurldll
10878- LDFLAG=
10879- else
10880- EXE=extension
10881- EXT=sqlite3_mod_vtable.so
10882- RM=rm
10883- LDFLAG=-fPIC
10884- LIBCURL=-lcurl
10885- endif
10886-
10887- all : $(EXE) $(EXT)
10888-
10889- $(EXE) : extension.go
10890- go build $<
10891-
10892- $(EXT) : sqlite3_mod_vtable.cc
10893- g++ $(LDFLAG) -shared -o $@ $< -lsqlite3 $(LIBCURL)
10894-
10895- clean :
10896- @-$(RM) $(EXE) $(EXT)
10897 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go b/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go
10898deleted file mode 100644
10899index f738af6..0000000
10900--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go
10901+++ /dev/null
10902 @@ -1,37 +0,0 @@
10903- package main
10904-
10905- import (
10906- "database/sql"
10907- "fmt"
10908- "log"
10909-
10910- "github.com/mattn/go-sqlite3"
10911- )
10912-
10913- func main() {
10914- sql.Register("sqlite3_with_extensions",
10915- &sqlite3.SQLiteDriver{
10916- Extensions: []string{
10917- "sqlite3_mod_vtable",
10918- },
10919- })
10920-
10921- db, err := sql.Open("sqlite3_with_extensions", ":memory:")
10922- if err != nil {
10923- log.Fatal(err)
10924- }
10925- defer db.Close()
10926-
10927- db.Exec("create virtual table repo using github(id, full_name, description, html_url)")
10928-
10929- rows, err := db.Query("select id, full_name, description, html_url from repo")
10930- if err != nil {
10931- log.Fatal(err)
10932- }
10933- defer rows.Close()
10934- for rows.Next() {
10935- var id, fullName, description, htmlURL string
10936- rows.Scan(&id, &fullName, &description, &htmlURL)
10937- fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
10938- }
10939- }
10940 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/picojson.h b/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/picojson.h
10941deleted file mode 100644
10942index 2142647..0000000
10943--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/picojson.h
10944+++ /dev/null
10945 @@ -1,1040 +0,0 @@
10946- /*
10947- * Copyright 2009-2010 Cybozu Labs, Inc.
10948- * Copyright 2011 Kazuho Oku
10949- *
10950- * Redistribution and use in source and binary forms, with or without
10951- * modification, are permitted provided that the following conditions are met:
10952- *
10953- * 1. Redistributions of source code must retain the above copyright notice,
10954- * this list of conditions and the following disclaimer.
10955- * 2. Redistributions in binary form must reproduce the above copyright notice,
10956- * this list of conditions and the following disclaimer in the documentation
10957- * and/or other materials provided with the distribution.
10958- *
10959- * THIS SOFTWARE IS PROVIDED BY CYBOZU LABS, INC. ``AS IS'' AND ANY EXPRESS OR
10960- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
10961- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
10962- * EVENT SHALL CYBOZU LABS, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10963- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10964- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
10965- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
10966- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
10967- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
10968- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10969- *
10970- * The views and conclusions contained in the software and documentation are
10971- * those of the authors and should not be interpreted as representing official
10972- * policies, either expressed or implied, of Cybozu Labs, Inc.
10973- *
10974- */
10975- #ifndef picojson_h
10976- #define picojson_h
10977-
10978- #include <algorithm>
10979- #include <cassert>
10980- #include <cmath>
10981- #include <cstdio>
10982- #include <cstdlib>
10983- #include <cstring>
10984- #include <iostream>
10985- #include <iterator>
10986- #include <map>
10987- #include <string>
10988- #include <vector>
10989-
10990- #ifdef _MSC_VER
10991- #define SNPRINTF _snprintf_s
10992- #pragma warning(push)
10993- #pragma warning(disable : 4244) // conversion from int to char
10994- #else
10995- #define SNPRINTF snprintf
10996- #endif
10997-
10998- namespace picojson {
10999-
11000- enum {
11001- null_type,
11002- boolean_type,
11003- number_type,
11004- string_type,
11005- array_type,
11006- object_type
11007- };
11008-
11009- struct null {};
11010-
11011- class value {
11012- public:
11013- typedef std::vector<value> array;
11014- typedef std::map<std::string, value> object;
11015- union _storage {
11016- bool boolean_;
11017- double number_;
11018- std::string* string_;
11019- array* array_;
11020- object* object_;
11021- };
11022- protected:
11023- int type_;
11024- _storage u_;
11025- public:
11026- value();
11027- value(int type, bool);
11028- explicit value(bool b);
11029- explicit value(double n);
11030- explicit value(const std::string& s);
11031- explicit value(const array& a);
11032- explicit value(const object& o);
11033- explicit value(const char* s);
11034- value(const char* s, size_t len);
11035- ~value();
11036- value(const value& x);
11037- value& operator=(const value& x);
11038- void swap(value& x);
11039- template <typename T> bool is() const;
11040- template <typename T> const T& get() const;
11041- template <typename T> T& get();
11042- bool evaluate_as_boolean() const;
11043- const value& get(size_t idx) const;
11044- const value& get(const std::string& key) const;
11045- bool contains(size_t idx) const;
11046- bool contains(const std::string& key) const;
11047- std::string to_str() const;
11048- template <typename Iter> void serialize(Iter os) const;
11049- std::string serialize() const;
11050- private:
11051- template <typename T> value(const T*); // intentionally defined to block implicit conversion of pointer to bool
11052- };
11053-
11054- typedef value::array array;
11055- typedef value::object object;
11056-
11057- inline value::value() : type_(null_type) {}
11058-
11059- inline value::value(int type, bool) : type_(type) {
11060- switch (type) {
11061- #define INIT(p, v) case p##type: u_.p = v; break
11062- INIT(boolean_, false);
11063- INIT(number_, 0.0);
11064- INIT(string_, new std::string());
11065- INIT(array_, new array());
11066- INIT(object_, new object());
11067- #undef INIT
11068- default: break;
11069- }
11070- }
11071-
11072- inline value::value(bool b) : type_(boolean_type) {
11073- u_.boolean_ = b;
11074- }
11075-
11076- inline value::value(double n) : type_(number_type) {
11077- u_.number_ = n;
11078- }
11079-
11080- inline value::value(const std::string& s) : type_(string_type) {
11081- u_.string_ = new std::string(s);
11082- }
11083-
11084- inline value::value(const array& a) : type_(array_type) {
11085- u_.array_ = new array(a);
11086- }
11087-
11088- inline value::value(const object& o) : type_(object_type) {
11089- u_.object_ = new object(o);
11090- }
11091-
11092- inline value::value(const char* s) : type_(string_type) {
11093- u_.string_ = new std::string(s);
11094- }
11095-
11096- inline value::value(const char* s, size_t len) : type_(string_type) {
11097- u_.string_ = new std::string(s, len);
11098- }
11099-
11100- inline value::~value() {
11101- switch (type_) {
11102- #define DEINIT(p) case p##type: delete u_.p; break
11103- DEINIT(string_);
11104- DEINIT(array_);
11105- DEINIT(object_);
11106- #undef DEINIT
11107- default: break;
11108- }
11109- }
11110-
11111- inline value::value(const value& x) : type_(x.type_) {
11112- switch (type_) {
11113- #define INIT(p, v) case p##type: u_.p = v; break
11114- INIT(string_, new std::string(*x.u_.string_));
11115- INIT(array_, new array(*x.u_.array_));
11116- INIT(object_, new object(*x.u_.object_));
11117- #undef INIT
11118- default:
11119- u_ = x.u_;
11120- break;
11121- }
11122- }
11123-
11124- inline value& value::operator=(const value& x) {
11125- if (this != &x) {
11126- this->~value();
11127- new (this) value(x);
11128- }
11129- return *this;
11130- }
11131-
11132- inline void value::swap(value& x) {
11133- std::swap(type_, x.type_);
11134- std::swap(u_, x.u_);
11135- }
11136-
11137- #define IS(ctype, jtype) \
11138- template <> inline bool value::is<ctype>() const { \
11139- return type_ == jtype##_type; \
11140- }
11141- IS(null, null)
11142- IS(bool, boolean)
11143- IS(int, number)
11144- IS(double, number)
11145- IS(std::string, string)
11146- IS(array, array)
11147- IS(object, object)
11148- #undef IS
11149-
11150- #define GET(ctype, var) \
11151- template <> inline const ctype& value::get<ctype>() const { \
11152- assert("type mismatch! call vis<type>() before get<type>()" \
11153- && is<ctype>()); \
11154- return var; \
11155- } \
11156- template <> inline ctype& value::get<ctype>() { \
11157- assert("type mismatch! call is<type>() before get<type>()" \
11158- && is<ctype>()); \
11159- return var; \
11160- }
11161- GET(bool, u_.boolean_)
11162- GET(double, u_.number_)
11163- GET(std::string, *u_.string_)
11164- GET(array, *u_.array_)
11165- GET(object, *u_.object_)
11166- #undef GET
11167-
11168- inline bool value::evaluate_as_boolean() const {
11169- switch (type_) {
11170- case null_type:
11171- return false;
11172- case boolean_type:
11173- return u_.boolean_;
11174- case number_type:
11175- return u_.number_ != 0;
11176- case string_type:
11177- return ! u_.string_->empty();
11178- default:
11179- return true;
11180- }
11181- }
11182-
11183- inline const value& value::get(size_t idx) const {
11184- static value s_null;
11185- assert(is<array>());
11186- return idx < u_.array_->size() ? (*u_.array_)[idx] : s_null;
11187- }
11188-
11189- inline const value& value::get(const std::string& key) const {
11190- static value s_null;
11191- assert(is<object>());
11192- object::const_iterator i = u_.object_->find(key);
11193- return i != u_.object_->end() ? i->second : s_null;
11194- }
11195-
11196- inline bool value::contains(size_t idx) const {
11197- assert(is<array>());
11198- return idx < u_.array_->size();
11199- }
11200-
11201- inline bool value::contains(const std::string& key) const {
11202- assert(is<object>());
11203- object::const_iterator i = u_.object_->find(key);
11204- return i != u_.object_->end();
11205- }
11206-
11207- inline std::string value::to_str() const {
11208- switch (type_) {
11209- case null_type: return "null";
11210- case boolean_type: return u_.boolean_ ? "true" : "false";
11211- case number_type: {
11212- char buf[256];
11213- double tmp;
11214- SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g", u_.number_);
11215- return buf;
11216- }
11217- case string_type: return *u_.string_;
11218- case array_type: return "array";
11219- case object_type: return "object";
11220- default: assert(0);
11221- #ifdef _MSC_VER
11222- __assume(0);
11223- #endif
11224- }
11225- return std::string();
11226- }
11227-
11228- template <typename Iter> void copy(const std::string& s, Iter oi) {
11229- std::copy(s.begin(), s.end(), oi);
11230- }
11231-
11232- template <typename Iter> void serialize_str(const std::string& s, Iter oi) {
11233- *oi++ = '"';
11234- for (std::string::const_iterator i = s.begin(); i != s.end(); ++i) {
11235- switch (*i) {
11236- #define MAP(val, sym) case val: copy(sym, oi); break
11237- MAP('"', "\\\"");
11238- MAP('\\', "\\\\");
11239- MAP('/', "\\/");
11240- MAP('\b', "\\b");
11241- MAP('\f', "\\f");
11242- MAP('\n', "\\n");
11243- MAP('\r', "\\r");
11244- MAP('\t', "\\t");
11245- #undef MAP
11246- default:
11247- if ((unsigned char)*i < 0x20 || *i == 0x7f) {
11248- char buf[7];
11249- SNPRINTF(buf, sizeof(buf), "\\u%04x", *i & 0xff);
11250- copy(buf, buf + 6, oi);
11251- } else {
11252- *oi++ = *i;
11253- }
11254- break;
11255- }
11256- }
11257- *oi++ = '"';
11258- }
11259-
11260- template <typename Iter> void value::serialize(Iter oi) const {
11261- switch (type_) {
11262- case string_type:
11263- serialize_str(*u_.string_, oi);
11264- break;
11265- case array_type: {
11266- *oi++ = '[';
11267- for (array::const_iterator i = u_.array_->begin();
11268- i != u_.array_->end();
11269- ++i) {
11270- if (i != u_.array_->begin()) {
11271- *oi++ = ',';
11272- }
11273- i->serialize(oi);
11274- }
11275- *oi++ = ']';
11276- break;
11277- }
11278- case object_type: {
11279- *oi++ = '{';
11280- for (object::const_iterator i = u_.object_->begin();
11281- i != u_.object_->end();
11282- ++i) {
11283- if (i != u_.object_->begin()) {
11284- *oi++ = ',';
11285- }
11286- serialize_str(i->first, oi);
11287- *oi++ = ':';
11288- i->second.serialize(oi);
11289- }
11290- *oi++ = '}';
11291- break;
11292- }
11293- default:
11294- copy(to_str(), oi);
11295- break;
11296- }
11297- }
11298-
11299- inline std::string value::serialize() const {
11300- std::string s;
11301- serialize(std::back_inserter(s));
11302- return s;
11303- }
11304-
11305- template <typename Iter> class input {
11306- protected:
11307- Iter cur_, end_;
11308- int last_ch_;
11309- bool ungot_;
11310- int line_;
11311- public:
11312- input(const Iter& first, const Iter& last) : cur_(first), end_(last), last_ch_(-1), ungot_(false), line_(1) {}
11313- int getc() {
11314- if (ungot_) {
11315- ungot_ = false;
11316- return last_ch_;
11317- }
11318- if (cur_ == end_) {
11319- last_ch_ = -1;
11320- return -1;
11321- }
11322- if (last_ch_ == '\n') {
11323- line_++;
11324- }
11325- last_ch_ = *cur_++ & 0xff;
11326- return last_ch_;
11327- }
11328- void ungetc() {
11329- if (last_ch_ != -1) {
11330- assert(! ungot_);
11331- ungot_ = true;
11332- }
11333- }
11334- Iter cur() const { return cur_; }
11335- int line() const { return line_; }
11336- void skip_ws() {
11337- while (1) {
11338- int ch = getc();
11339- if (! (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) {
11340- ungetc();
11341- break;
11342- }
11343- }
11344- }
11345- bool expect(int expect) {
11346- skip_ws();
11347- if (getc() != expect) {
11348- ungetc();
11349- return false;
11350- }
11351- return true;
11352- }
11353- bool match(const std::string& pattern) {
11354- for (std::string::const_iterator pi(pattern.begin());
11355- pi != pattern.end();
11356- ++pi) {
11357- if (getc() != *pi) {
11358- ungetc();
11359- return false;
11360- }
11361- }
11362- return true;
11363- }
11364- };
11365-
11366- template<typename Iter> inline int _parse_quadhex(input<Iter> &in) {
11367- int uni_ch = 0, hex;
11368- for (int i = 0; i < 4; i++) {
11369- if ((hex = in.getc()) == -1) {
11370- return -1;
11371- }
11372- if ('0' <= hex && hex <= '9') {
11373- hex -= '0';
11374- } else if ('A' <= hex && hex <= 'F') {
11375- hex -= 'A' - 0xa;
11376- } else if ('a' <= hex && hex <= 'f') {
11377- hex -= 'a' - 0xa;
11378- } else {
11379- in.ungetc();
11380- return -1;
11381- }
11382- uni_ch = uni_ch * 16 + hex;
11383- }
11384- return uni_ch;
11385- }
11386-
11387- template<typename String, typename Iter> inline bool _parse_codepoint(String& out, input<Iter>& in) {
11388- int uni_ch;
11389- if ((uni_ch = _parse_quadhex(in)) == -1) {
11390- return false;
11391- }
11392- if (0xd800 <= uni_ch && uni_ch <= 0xdfff) {
11393- if (0xdc00 <= uni_ch) {
11394- // a second 16-bit of a surrogate pair appeared
11395- return false;
11396- }
11397- // first 16-bit of surrogate pair, get the next one
11398- if (in.getc() != '\\' || in.getc() != 'u') {
11399- in.ungetc();
11400- return false;
11401- }
11402- int second = _parse_quadhex(in);
11403- if (! (0xdc00 <= second && second <= 0xdfff)) {
11404- return false;
11405- }
11406- uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff);
11407- uni_ch += 0x10000;
11408- }
11409- if (uni_ch < 0x80) {
11410- out.push_back(uni_ch);
11411- } else {
11412- if (uni_ch < 0x800) {
11413- out.push_back(0xc0 | (uni_ch >> 6));
11414- } else {
11415- if (uni_ch < 0x10000) {
11416- out.push_back(0xe0 | (uni_ch >> 12));
11417- } else {
11418- out.push_back(0xf0 | (uni_ch >> 18));
11419- out.push_back(0x80 | ((uni_ch >> 12) & 0x3f));
11420- }
11421- out.push_back(0x80 | ((uni_ch >> 6) & 0x3f));
11422- }
11423- out.push_back(0x80 | (uni_ch & 0x3f));
11424- }
11425- return true;
11426- }
11427-
11428- template<typename String, typename Iter> inline bool _parse_string(String& out, input<Iter>& in) {
11429- while (1) {
11430- int ch = in.getc();
11431- if (ch < ' ') {
11432- in.ungetc();
11433- return false;
11434- } else if (ch == '"') {
11435- return true;
11436- } else if (ch == '\\') {
11437- if ((ch = in.getc()) == -1) {
11438- return false;
11439- }
11440- switch (ch) {
11441- #define MAP(sym, val) case sym: out.push_back(val); break
11442- MAP('"', '\"');
11443- MAP('\\', '\\');
11444- MAP('/', '/');
11445- MAP('b', '\b');
11446- MAP('f', '\f');
11447- MAP('n', '\n');
11448- MAP('r', '\r');
11449- MAP('t', '\t');
11450- #undef MAP
11451- case 'u':
11452- if (! _parse_codepoint(out, in)) {
11453- return false;
11454- }
11455- break;
11456- default:
11457- return false;
11458- }
11459- } else {
11460- out.push_back(ch);
11461- }
11462- }
11463- return false;
11464- }
11465-
11466- template <typename Context, typename Iter> inline bool _parse_array(Context& ctx, input<Iter>& in) {
11467- if (! ctx.parse_array_start()) {
11468- return false;
11469- }
11470- size_t idx = 0;
11471- if (in.expect(']')) {
11472- return ctx.parse_array_stop(idx);
11473- }
11474- do {
11475- if (! ctx.parse_array_item(in, idx)) {
11476- return false;
11477- }
11478- idx++;
11479- } while (in.expect(','));
11480- return in.expect(']') && ctx.parse_array_stop(idx);
11481- }
11482-
11483- template <typename Context, typename Iter> inline bool _parse_object(Context& ctx, input<Iter>& in) {
11484- if (! ctx.parse_object_start()) {
11485- return false;
11486- }
11487- if (in.expect('}')) {
11488- return true;
11489- }
11490- do {
11491- std::string key;
11492- if (! in.expect('"')
11493- || ! _parse_string(key, in)
11494- || ! in.expect(':')) {
11495- return false;
11496- }
11497- if (! ctx.parse_object_item(in, key)) {
11498- return false;
11499- }
11500- } while (in.expect(','));
11501- return in.expect('}');
11502- }
11503-
11504- template <typename Iter> inline bool _parse_number(double& out, input<Iter>& in) {
11505- std::string num_str;
11506- while (1) {
11507- int ch = in.getc();
11508- if (('0' <= ch && ch <= '9') || ch == '+' || ch == '-' || ch == '.'
11509- || ch == 'e' || ch == 'E') {
11510- num_str.push_back(ch);
11511- } else {
11512- in.ungetc();
11513- break;
11514- }
11515- }
11516- char* endp;
11517- out = strtod(num_str.c_str(), &endp);
11518- return endp == num_str.c_str() + num_str.size();
11519- }
11520-
11521- template <typename Context, typename Iter> inline bool _parse(Context& ctx, input<Iter>& in) {
11522- in.skip_ws();
11523- int ch = in.getc();
11524- switch (ch) {
11525- #define IS(ch, text, op) case ch: \
11526- if (in.match(text) && op) { \
11527- return true; \
11528- } else { \
11529- return false; \
11530- }
11531- IS('n', "ull", ctx.set_null());
11532- IS('f', "alse", ctx.set_bool(false));
11533- IS('t', "rue", ctx.set_bool(true));
11534- #undef IS
11535- case '"':
11536- return ctx.parse_string(in);
11537- case '[':
11538- return _parse_array(ctx, in);
11539- case '{':
11540- return _parse_object(ctx, in);
11541- default:
11542- if (('0' <= ch && ch <= '9') || ch == '-') {
11543- in.ungetc();
11544- double f;
11545- if (_parse_number(f, in)) {
11546- ctx.set_number(f);
11547- return true;
11548- } else {
11549- return false;
11550- }
11551- }
11552- break;
11553- }
11554- in.ungetc();
11555- return false;
11556- }
11557-
11558- class deny_parse_context {
11559- public:
11560- bool set_null() { return false; }
11561- bool set_bool(bool) { return false; }
11562- bool set_number(double) { return false; }
11563- template <typename Iter> bool parse_string(input<Iter>&) { return false; }
11564- bool parse_array_start() { return false; }
11565- template <typename Iter> bool parse_array_item(input<Iter>&, size_t) {
11566- return false;
11567- }
11568- bool parse_array_stop(size_t) { return false; }
11569- bool parse_object_start() { return false; }
11570- template <typename Iter> bool parse_object_item(input<Iter>&, const std::string&) {
11571- return false;
11572- }
11573- };
11574-
11575- class default_parse_context {
11576- protected:
11577- value* out_;
11578- public:
11579- default_parse_context(value* out) : out_(out) {}
11580- bool set_null() {
11581- *out_ = value();
11582- return true;
11583- }
11584- bool set_bool(bool b) {
11585- *out_ = value(b);
11586- return true;
11587- }
11588- bool set_number(double f) {
11589- *out_ = value(f);
11590- return true;
11591- }
11592- template<typename Iter> bool parse_string(input<Iter>& in) {
11593- *out_ = value(string_type, false);
11594- return _parse_string(out_->get<std::string>(), in);
11595- }
11596- bool parse_array_start() {
11597- *out_ = value(array_type, false);
11598- return true;
11599- }
11600- template <typename Iter> bool parse_array_item(input<Iter>& in, size_t) {
11601- array& a = out_->get<array>();
11602- a.push_back(value());
11603- default_parse_context ctx(&a.back());
11604- return _parse(ctx, in);
11605- }
11606- bool parse_array_stop(size_t) { return true; }
11607- bool parse_object_start() {
11608- *out_ = value(object_type, false);
11609- return true;
11610- }
11611- template <typename Iter> bool parse_object_item(input<Iter>& in, const std::string& key) {
11612- object& o = out_->get<object>();
11613- default_parse_context ctx(&o[key]);
11614- return _parse(ctx, in);
11615- }
11616- private:
11617- default_parse_context(const default_parse_context&);
11618- default_parse_context& operator=(const default_parse_context&);
11619- };
11620-
11621- class null_parse_context {
11622- public:
11623- struct dummy_str {
11624- void push_back(int) {}
11625- };
11626- public:
11627- null_parse_context() {}
11628- bool set_null() { return true; }
11629- bool set_bool(bool) { return true; }
11630- bool set_number(double) { return true; }
11631- template <typename Iter> bool parse_string(input<Iter>& in) {
11632- dummy_str s;
11633- return _parse_string(s, in);
11634- }
11635- bool parse_array_start() { return true; }
11636- template <typename Iter> bool parse_array_item(input<Iter>& in, size_t) {
11637- return _parse(*this, in);
11638- }
11639- bool parse_array_stop(size_t) { return true; }
11640- bool parse_object_start() { return true; }
11641- template <typename Iter> bool parse_object_item(input<Iter>& in, const std::string&) {
11642- return _parse(*this, in);
11643- }
11644- private:
11645- null_parse_context(const null_parse_context&);
11646- null_parse_context& operator=(const null_parse_context&);
11647- };
11648-
11649- // obsolete, use the version below
11650- template <typename Iter> inline std::string parse(value& out, Iter& pos, const Iter& last) {
11651- std::string err;
11652- pos = parse(out, pos, last, &err);
11653- return err;
11654- }
11655-
11656- template <typename Context, typename Iter> inline Iter _parse(Context& ctx, const Iter& first, const Iter& last, std::string* err) {
11657- input<Iter> in(first, last);
11658- if (! _parse(ctx, in) && err != NULL) {
11659- char buf[64];
11660- SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line());
11661- *err = buf;
11662- while (1) {
11663- int ch = in.getc();
11664- if (ch == -1 || ch == '\n') {
11665- break;
11666- } else if (ch >= ' ') {
11667- err->push_back(ch);
11668- }
11669- }
11670- }
11671- return in.cur();
11672- }
11673-
11674- template <typename Iter> inline Iter parse(value& out, const Iter& first, const Iter& last, std::string* err) {
11675- default_parse_context ctx(&out);
11676- return _parse(ctx, first, last, err);
11677- }
11678-
11679- inline std::string parse(value& out, std::istream& is) {
11680- std::string err;
11681- parse(out, std::istreambuf_iterator<char>(is.rdbuf()),
11682- std::istreambuf_iterator<char>(), &err);
11683- return err;
11684- }
11685-
11686- template <typename T> struct last_error_t {
11687- static std::string s;
11688- };
11689- template <typename T> std::string last_error_t<T>::s;
11690-
11691- inline void set_last_error(const std::string& s) {
11692- last_error_t<bool>::s = s;
11693- }
11694-
11695- inline const std::string& get_last_error() {
11696- return last_error_t<bool>::s;
11697- }
11698-
11699- inline bool operator==(const value& x, const value& y) {
11700- if (x.is<null>())
11701- return y.is<null>();
11702- #define PICOJSON_CMP(type) \
11703- if (x.is<type>()) \
11704- return y.is<type>() && x.get<type>() == y.get<type>()
11705- PICOJSON_CMP(bool);
11706- PICOJSON_CMP(double);
11707- PICOJSON_CMP(std::string);
11708- PICOJSON_CMP(array);
11709- PICOJSON_CMP(object);
11710- #undef PICOJSON_CMP
11711- assert(0);
11712- #ifdef _MSC_VER
11713- __assume(0);
11714- #endif
11715- return false;
11716- }
11717-
11718- inline bool operator!=(const value& x, const value& y) {
11719- return ! (x == y);
11720- }
11721- }
11722-
11723- namespace std {
11724- template<> inline void swap(picojson::value& x, picojson::value& y)
11725- {
11726- x.swap(y);
11727- }
11728- }
11729-
11730- inline std::istream& operator>>(std::istream& is, picojson::value& x)
11731- {
11732- picojson::set_last_error(std::string());
11733- std::string err = picojson::parse(x, is);
11734- if (! err.empty()) {
11735- picojson::set_last_error(err);
11736- is.setstate(std::ios::failbit);
11737- }
11738- return is;
11739- }
11740-
11741- inline std::ostream& operator<<(std::ostream& os, const picojson::value& x)
11742- {
11743- x.serialize(std::ostream_iterator<char>(os));
11744- return os;
11745- }
11746- #ifdef _MSC_VER
11747- #pragma warning(pop)
11748- #endif
11749-
11750- #endif
11751- #ifdef TEST_PICOJSON
11752- #ifdef _MSC_VER
11753- #pragma warning(disable : 4127) // conditional expression is constant
11754- #endif
11755-
11756- using namespace std;
11757-
11758- static void plan(int num)
11759- {
11760- printf("1..%d\n", num);
11761- }
11762-
11763- static bool success = true;
11764-
11765- static void ok(bool b, const char* name = "")
11766- {
11767- static int n = 1;
11768- if (! b)
11769- success = false;
11770- printf("%s %d - %s\n", b ? "ok" : "ng", n++, name);
11771- }
11772-
11773- template <typename T> void is(const T& x, const T& y, const char* name = "")
11774- {
11775- if (x == y) {
11776- ok(true, name);
11777- } else {
11778- ok(false, name);
11779- }
11780- }
11781-
11782- #include <algorithm>
11783- #include <sstream>
11784- #include <float.h>
11785- #include <limits.h>
11786-
11787- int main(void)
11788- {
11789- plan(85);
11790-
11791- // constructors
11792- #define TEST(expr, expected) \
11793- is(picojson::value expr .serialize(), string(expected), "picojson::value" #expr)
11794-
11795- TEST( (true), "true");
11796- TEST( (false), "false");
11797- TEST( (42.0), "42");
11798- TEST( (string("hello")), "\"hello\"");
11799- TEST( ("hello"), "\"hello\"");
11800- TEST( ("hello", 4), "\"hell\"");
11801-
11802- {
11803- double a = 1;
11804- for (int i = 0; i < 1024; i++) {
11805- picojson::value vi(a);
11806- std::stringstream ss;
11807- ss << vi;
11808- picojson::value vo;
11809- ss >> vo;
11810- double b = vo.get<double>();
11811- if ((i < 53 && a != b) || fabs(a - b) / b > 1e-8) {
11812- printf("ng i=%d a=%.18e b=%.18e\n", i, a, b);
11813- }
11814- a *= 2;
11815- }
11816- }
11817-
11818- #undef TEST
11819-
11820- #define TEST(in, type, cmp, serialize_test) { \
11821- picojson::value v; \
11822- const char* s = in; \
11823- string err = picojson::parse(v, s, s + strlen(s)); \
11824- ok(err.empty(), in " no error"); \
11825- ok(v.is<type>(), in " check type"); \
11826- is<type>(v.get<type>(), cmp, in " correct output"); \
11827- is(*s, '\0', in " read to eof"); \
11828- if (serialize_test) { \
11829- is(v.serialize(), string(in), in " serialize"); \
11830- } \
11831- }
11832- TEST("false", bool, false, true);
11833- TEST("true", bool, true, true);
11834- TEST("90.5", double, 90.5, false);
11835- TEST("1.7976931348623157e+308", double, DBL_MAX, false);
11836- TEST("\"hello\"", string, string("hello"), true);
11837- TEST("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\"", string, string("\"\\/\b\f\n\r\t"),
11838- true);
11839- TEST("\"\\u0061\\u30af\\u30ea\\u30b9\"", string,
11840- string("a\xe3\x82\xaf\xe3\x83\xaa\xe3\x82\xb9"), false);
11841- TEST("\"\\ud840\\udc0b\"", string, string("\xf0\xa0\x80\x8b"), false);
11842- #undef TEST
11843-
11844- #define TEST(type, expr) { \
11845- picojson::value v; \
11846- const char *s = expr; \
11847- string err = picojson::parse(v, s, s + strlen(s)); \
11848- ok(err.empty(), "empty " #type " no error"); \
11849- ok(v.is<picojson::type>(), "empty " #type " check type"); \
11850- ok(v.get<picojson::type>().empty(), "check " #type " array size"); \
11851- }
11852- TEST(array, "[]");
11853- TEST(object, "{}");
11854- #undef TEST
11855-
11856- {
11857- picojson::value v;
11858- const char *s = "[1,true,\"hello\"]";
11859- string err = picojson::parse(v, s, s + strlen(s));
11860- ok(err.empty(), "array no error");
11861- ok(v.is<picojson::array>(), "array check type");
11862- is(v.get<picojson::array>().size(), size_t(3), "check array size");
11863- ok(v.contains(0), "check contains array[0]");
11864- ok(v.get(0).is<double>(), "check array[0] type");
11865- is(v.get(0).get<double>(), 1.0, "check array[0] value");
11866- ok(v.contains(1), "check contains array[1]");
11867- ok(v.get(1).is<bool>(), "check array[1] type");
11868- ok(v.get(1).get<bool>(), "check array[1] value");
11869- ok(v.contains(2), "check contains array[2]");
11870- ok(v.get(2).is<string>(), "check array[2] type");
11871- is(v.get(2).get<string>(), string("hello"), "check array[2] value");
11872- ok(!v.contains(3), "check not contains array[3]");
11873- }
11874-
11875- {
11876- picojson::value v;
11877- const char *s = "{ \"a\": true }";
11878- string err = picojson::parse(v, s, s + strlen(s));
11879- ok(err.empty(), "object no error");
11880- ok(v.is<picojson::object>(), "object check type");
11881- is(v.get<picojson::object>().size(), size_t(1), "check object size");
11882- ok(v.contains("a"), "check contains property");
11883- ok(v.get("a").is<bool>(), "check bool property exists");
11884- is(v.get("a").get<bool>(), true, "check bool property value");
11885- is(v.serialize(), string("{\"a\":true}"), "serialize object");
11886- ok(!v.contains("z"), "check not contains property");
11887- }
11888-
11889- #define TEST(json, msg) do { \
11890- picojson::value v; \
11891- const char *s = json; \
11892- string err = picojson::parse(v, s, s + strlen(s)); \
11893- is(err, string("syntax error at line " msg), msg); \
11894- } while (0)
11895- TEST("falsoa", "1 near: oa");
11896- TEST("{]", "1 near: ]");
11897- TEST("\n\bbell", "2 near: bell");
11898- TEST("\"abc\nd\"", "1 near: ");
11899- #undef TEST
11900-
11901- {
11902- picojson::value v1, v2;
11903- const char *s;
11904- string err;
11905- s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
11906- err = picojson::parse(v1, s, s + strlen(s));
11907- s = "{ \"d\": 2.0, \"b\": true, \"a\": [1,2,\"three\"] }";
11908- err = picojson::parse(v2, s, s + strlen(s));
11909- ok((v1 == v2), "check == operator in deep comparison");
11910- }
11911-
11912- {
11913- picojson::value v1, v2;
11914- const char *s;
11915- string err;
11916- s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
11917- err = picojson::parse(v1, s, s + strlen(s));
11918- s = "{ \"d\": 2.0, \"a\": [1,\"three\"], \"b\": true }";
11919- err = picojson::parse(v2, s, s + strlen(s));
11920- ok((v1 != v2), "check != operator for array in deep comparison");
11921- }
11922-
11923- {
11924- picojson::value v1, v2;
11925- const char *s;
11926- string err;
11927- s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
11928- err = picojson::parse(v1, s, s + strlen(s));
11929- s = "{ \"d\": 2.0, \"a\": [1,2,\"three\"], \"b\": false }";
11930- err = picojson::parse(v2, s, s + strlen(s));
11931- ok((v1 != v2), "check != operator for object in deep comparison");
11932- }
11933-
11934- {
11935- picojson::value v1, v2;
11936- const char *s;
11937- string err;
11938- s = "{ \"b\": true, \"a\": [1,2,\"three\"], \"d\": 2 }";
11939- err = picojson::parse(v1, s, s + strlen(s));
11940- picojson::object& o = v1.get<picojson::object>();
11941- o.erase("b");
11942- picojson::array& a = o["a"].get<picojson::array>();
11943- picojson::array::iterator i;
11944- i = std::remove(a.begin(), a.end(), picojson::value(std::string("three")));
11945- a.erase(i, a.end());
11946- s = "{ \"a\": [1,2], \"d\": 2 }";
11947- err = picojson::parse(v2, s, s + strlen(s));
11948- ok((v1 == v2), "check erase()");
11949- }
11950-
11951- ok(picojson::value(3.0).serialize() == "3",
11952- "integral number should be serialized as a integer");
11953-
11954- {
11955- const char* s = "{ \"a\": [1,2], \"d\": 2 }";
11956- picojson::null_parse_context ctx;
11957- string err;
11958- picojson::_parse(ctx, s, s + strlen(s), &err);
11959- ok(err.empty(), "null_parse_context");
11960- }
11961-
11962- {
11963- picojson::value v1, v2;
11964- v1 = picojson::value(true);
11965- swap(v1, v2);
11966- ok(v1.is<picojson::null>(), "swap (null)");
11967- ok(v2.get<bool>() == true, "swap (bool)");
11968-
11969- v1 = picojson::value("a");
11970- v2 = picojson::value(1.0);
11971- swap(v1, v2);
11972- ok(v1.get<double>() == 1.0, "swap (dobule)");
11973- ok(v2.get<string>() == "a", "swap (string)");
11974-
11975- v1 = picojson::value(picojson::object());
11976- v2 = picojson::value(picojson::array());
11977- swap(v1, v2);
11978- ok(v1.is<picojson::array>(), "swap (array)");
11979- ok(v2.is<picojson::object>(), "swap (object)");
11980- }
11981-
11982- return success ? 0 : 1;
11983- }
11984-
11985- #endif
11986 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/sqlite3_mod_vtable.cc b/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/sqlite3_mod_vtable.cc
11987deleted file mode 100644
11988index 5bd4e66..0000000
11989--- a/vendor/github.com/mattn/go-sqlite3/_example/mod_vtable/sqlite3_mod_vtable.cc
11990+++ /dev/null
11991 @@ -1,238 +0,0 @@
11992- #include <string>
11993- #include <sstream>
11994- #include <sqlite3-binding.h>
11995- #include <sqlite3ext.h>
11996- #include <curl/curl.h>
11997- #include "picojson.h"
11998-
11999- #ifdef _WIN32
12000- # define EXPORT __declspec(dllexport)
12001- #else
12002- # define EXPORT
12003- #endif
12004-
12005- SQLITE_EXTENSION_INIT1;
12006-
12007- typedef struct {
12008- char* data; // response data from server
12009- size_t size; // response size of data
12010- } MEMFILE;
12011-
12012- MEMFILE*
12013- memfopen() {
12014- MEMFILE* mf = (MEMFILE*) malloc(sizeof(MEMFILE));
12015- if (mf) {
12016- mf->data = NULL;
12017- mf->size = 0;
12018- }
12019- return mf;
12020- }
12021-
12022- void
12023- memfclose(MEMFILE* mf) {
12024- if (mf->data) free(mf->data);
12025- free(mf);
12026- }
12027-
12028- size_t
12029- memfwrite(char* ptr, size_t size, size_t nmemb, void* stream) {
12030- MEMFILE* mf = (MEMFILE*) stream;
12031- int block = size * nmemb;
12032- if (!mf) return block; // through
12033- if (!mf->data)
12034- mf->data = (char*) malloc(block);
12035- else
12036- mf->data = (char*) realloc(mf->data, mf->size + block);
12037- if (mf->data) {
12038- memcpy(mf->data + mf->size, ptr, block);
12039- mf->size += block;
12040- }
12041- return block;
12042- }
12043-
12044- char*
12045- memfstrdup(MEMFILE* mf) {
12046- char* buf;
12047- if (mf->size == 0) return NULL;
12048- buf = (char*) malloc(mf->size + 1);
12049- memcpy(buf, mf->data, mf->size);
12050- buf[mf->size] = 0;
12051- return buf;
12052- }
12053-
12054- static int
12055- my_connect(sqlite3 *db, void *pAux, int argc, const char * const *argv, sqlite3_vtab **ppVTab, char **c) {
12056- std::stringstream ss;
12057- ss << "CREATE TABLE " << argv[0]
12058- << "(id int, full_name text, description text, html_url text)";
12059- int rc = sqlite3_declare_vtab(db, ss.str().c_str());
12060- *ppVTab = (sqlite3_vtab *) sqlite3_malloc(sizeof(sqlite3_vtab));
12061- memset(*ppVTab, 0, sizeof(sqlite3_vtab));
12062- return rc;
12063- }
12064-
12065- static int
12066- my_create(sqlite3 *db, void *pAux, int argc, const char * const * argv, sqlite3_vtab **ppVTab, char **c) {
12067- return my_connect(db, pAux, argc, argv, ppVTab, c);
12068- }
12069-
12070- static int my_disconnect(sqlite3_vtab *pVTab) {
12071- sqlite3_free(pVTab);
12072- return SQLITE_OK;
12073- }
12074-
12075- static int
12076- my_destroy(sqlite3_vtab *pVTab) {
12077- sqlite3_free(pVTab);
12078- return SQLITE_OK;
12079- }
12080-
12081- typedef struct {
12082- sqlite3_vtab_cursor base;
12083- int index;
12084- picojson::value* rows;
12085- } cursor;
12086-
12087- static int
12088- my_open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor) {
12089- MEMFILE* mf;
12090- CURL* curl;
12091- char* json;
12092- CURLcode res = CURLE_OK;
12093- char error[CURL_ERROR_SIZE] = {0};
12094- char* cert_file = getenv("SSL_CERT_FILE");
12095-
12096- mf = memfopen();
12097- curl = curl_easy_init();
12098- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
12099- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
12100- curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.29.0");
12101- curl_easy_setopt(curl, CURLOPT_URL, "https://api.github.com/repositories");
12102- if (cert_file)
12103- curl_easy_setopt(curl, CURLOPT_CAINFO, cert_file);
12104- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
12105- curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
12106- curl_easy_setopt(curl, CURLOPT_WRITEDATA, mf);
12107- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memfwrite);
12108- res = curl_easy_perform(curl);
12109- curl_easy_cleanup(curl);
12110- if (res != CURLE_OK) {
12111- std::cerr << error << std::endl;
12112- return SQLITE_FAIL;
12113- }
12114-
12115- picojson::value* v = new picojson::value;
12116- std::string err;
12117- picojson::parse(*v, mf->data, mf->data + mf->size, &err);
12118- memfclose(mf);
12119-
12120- if (!err.empty()) {
12121- delete v;
12122- std::cerr << err << std::endl;
12123- return SQLITE_FAIL;
12124- }
12125-
12126- cursor *c = (cursor *)sqlite3_malloc(sizeof(cursor));
12127- c->rows = v;
12128- c->index = 0;
12129- *ppCursor = &c->base;
12130- return SQLITE_OK;
12131- }
12132-
12133- static int
12134- my_close(cursor *c) {
12135- delete c->rows;
12136- sqlite3_free(c);
12137- return SQLITE_OK;
12138- }
12139-
12140- static int
12141- my_filter(cursor *c, int idxNum, const char *idxStr, int argc, sqlite3_value **argv) {
12142- c->index = 0;
12143- return SQLITE_OK;
12144- }
12145-
12146- static int
12147- my_next(cursor *c) {
12148- c->index++;
12149- return SQLITE_OK;
12150- }
12151-
12152- static int
12153- my_eof(cursor *c) {
12154- return c->index >= c->rows->get<picojson::array>().size() ? 1 : 0;
12155- }
12156-
12157- static int
12158- my_column(cursor *c, sqlite3_context *ctxt, int i) {
12159- picojson::value v = c->rows->get<picojson::array>()[c->index];
12160- picojson::object row = v.get<picojson::object>();
12161- const char* p = NULL;
12162- switch (i) {
12163- case 0:
12164- p = row["id"].to_str().c_str();
12165- break;
12166- case 1:
12167- p = row["full_name"].to_str().c_str();
12168- break;
12169- case 2:
12170- p = row["description"].to_str().c_str();
12171- break;
12172- case 3:
12173- p = row["html_url"].to_str().c_str();
12174- break;
12175- }
12176- sqlite3_result_text(ctxt, strdup(p), strlen(p), free);
12177- return SQLITE_OK;
12178- }
12179-
12180- static int
12181- my_rowid(cursor *c, sqlite3_int64 *pRowid) {
12182- *pRowid = c->index;
12183- return SQLITE_OK;
12184- }
12185-
12186- static int
12187- my_bestindex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo) {
12188- return SQLITE_OK;
12189- }
12190-
12191- static const sqlite3_module module = {
12192- 0,
12193- my_create,
12194- my_connect,
12195- my_bestindex,
12196- my_disconnect,
12197- my_destroy,
12198- my_open,
12199- (int (*)(sqlite3_vtab_cursor *)) my_close,
12200- (int (*)(sqlite3_vtab_cursor *, int, char const *, int, sqlite3_value **)) my_filter,
12201- (int (*)(sqlite3_vtab_cursor *)) my_next,
12202- (int (*)(sqlite3_vtab_cursor *)) my_eof,
12203- (int (*)(sqlite3_vtab_cursor *, sqlite3_context *, int)) my_column,
12204- (int (*)(sqlite3_vtab_cursor *, sqlite3_int64 *)) my_rowid,
12205- NULL, // my_update
12206- NULL, // my_begin
12207- NULL, // my_sync
12208- NULL, // my_commit
12209- NULL, // my_rollback
12210- NULL, // my_findfunction
12211- NULL, // my_rename
12212- };
12213-
12214- static void
12215- destructor(void *arg) {
12216- return;
12217- }
12218-
12219-
12220- extern "C" {
12221-
12222- EXPORT int
12223- sqlite3_extension_init(sqlite3 *db, char **errmsg, const sqlite3_api_routines *api) {
12224- SQLITE_EXTENSION_INIT2(api);
12225- sqlite3_create_module_v2(db, "github", &module, NULL, destructor);
12226- return 0;
12227- }
12228-
12229- }
12230 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/simple/simple.go b/vendor/github.com/mattn/go-sqlite3/_example/simple/simple.go
12231deleted file mode 100644
12232index 261ed4d..0000000
12233--- a/vendor/github.com/mattn/go-sqlite3/_example/simple/simple.go
12234+++ /dev/null
12235 @@ -1,106 +0,0 @@
12236- package main
12237-
12238- import (
12239- "database/sql"
12240- "fmt"
12241- _ "github.com/mattn/go-sqlite3"
12242- "log"
12243- "os"
12244- )
12245-
12246- func main() {
12247- os.Remove("./foo.db")
12248-
12249- db, err := sql.Open("sqlite3", "./foo.db")
12250- if err != nil {
12251- log.Fatal(err)
12252- }
12253- defer db.Close()
12254-
12255- sqlStmt := `
12256- create table foo (id integer not null primary key, name text);
12257- delete from foo;
12258- `
12259- _, err = db.Exec(sqlStmt)
12260- if err != nil {
12261- log.Printf("%q: %s\n", err, sqlStmt)
12262- return
12263- }
12264-
12265- tx, err := db.Begin()
12266- if err != nil {
12267- log.Fatal(err)
12268- }
12269- stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)")
12270- if err != nil {
12271- log.Fatal(err)
12272- }
12273- defer stmt.Close()
12274- for i := 0; i < 100; i++ {
12275- _, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i))
12276- if err != nil {
12277- log.Fatal(err)
12278- }
12279- }
12280- tx.Commit()
12281-
12282- rows, err := db.Query("select id, name from foo")
12283- if err != nil {
12284- log.Fatal(err)
12285- }
12286- defer rows.Close()
12287- for rows.Next() {
12288- var id int
12289- var name string
12290- err = rows.Scan(&id, &name)
12291- if err != nil {
12292- log.Fatal(err)
12293- }
12294- fmt.Println(id, name)
12295- }
12296- err = rows.Err()
12297- if err != nil {
12298- log.Fatal(err)
12299- }
12300-
12301- stmt, err = db.Prepare("select name from foo where id = ?")
12302- if err != nil {
12303- log.Fatal(err)
12304- }
12305- defer stmt.Close()
12306- var name string
12307- err = stmt.QueryRow("3").Scan(&name)
12308- if err != nil {
12309- log.Fatal(err)
12310- }
12311- fmt.Println(name)
12312-
12313- _, err = db.Exec("delete from foo")
12314- if err != nil {
12315- log.Fatal(err)
12316- }
12317-
12318- _, err = db.Exec("insert into foo(id, name) values(1, 'foo'), (2, 'bar'), (3, 'baz')")
12319- if err != nil {
12320- log.Fatal(err)
12321- }
12322-
12323- rows, err = db.Query("select id, name from foo")
12324- if err != nil {
12325- log.Fatal(err)
12326- }
12327- defer rows.Close()
12328- for rows.Next() {
12329- var id int
12330- var name string
12331- err = rows.Scan(&id, &name)
12332- if err != nil {
12333- log.Fatal(err)
12334- }
12335- fmt.Println(id, name)
12336- }
12337- err = rows.Err()
12338- if err != nil {
12339- log.Fatal(err)
12340- }
12341- }
12342 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/trace/main.go b/vendor/github.com/mattn/go-sqlite3/_example/trace/main.go
12343deleted file mode 100644
12344index 9f83ee1..0000000
12345--- a/vendor/github.com/mattn/go-sqlite3/_example/trace/main.go
12346+++ /dev/null
12347 @@ -1,264 +0,0 @@
12348- package main
12349-
12350- import (
12351- "database/sql"
12352- "fmt"
12353- "log"
12354- "os"
12355-
12356- sqlite3 "github.com/mattn/go-sqlite3"
12357- )
12358-
12359- func traceCallback(info sqlite3.TraceInfo) int {
12360- // Not very readable but may be useful; uncomment next line in case of doubt:
12361- //fmt.Printf("Trace: %#v\n", info)
12362-
12363- var dbErrText string
12364- if info.DBError.Code != 0 || info.DBError.ExtendedCode != 0 {
12365- dbErrText = fmt.Sprintf("; DB error: %#v", info.DBError)
12366- } else {
12367- dbErrText = "."
12368- }
12369-
12370- // Show the Statement-or-Trigger text in curly braces ('{', '}')
12371- // since from the *paired* ASCII characters they are
12372- // the least used in SQL syntax, therefore better visual delimiters.
12373- // Maybe show 'ExpandedSQL' the same way as 'StmtOrTrigger'.
12374- //
12375- // A known use of curly braces (outside strings) is
12376- // for ODBC escape sequences. Not likely to appear here.
12377- //
12378- // Template languages, etc. don't matter, we should see their *result*
12379- // at *this* level.
12380- // Strange curly braces in SQL code that reached the database driver
12381- // suggest that there is a bug in the application.
12382- // The braces are likely to be either template syntax or
12383- // a programming language's string interpolation syntax.
12384-
12385- var expandedText string
12386- if info.ExpandedSQL != "" {
12387- if info.ExpandedSQL == info.StmtOrTrigger {
12388- expandedText = " = exp"
12389- } else {
12390- expandedText = fmt.Sprintf(" expanded {%q}", info.ExpandedSQL)
12391- }
12392- } else {
12393- expandedText = ""
12394- }
12395-
12396- // SQLite docs as of September 6, 2016: Tracing and Profiling Functions
12397- // https://www.sqlite.org/c3ref/profile.html
12398- //
12399- // The profile callback time is in units of nanoseconds, however
12400- // the current implementation is only capable of millisecond resolution
12401- // so the six least significant digits in the time are meaningless.
12402- // Future versions of SQLite might provide greater resolution on the profiler callback.
12403-
12404- var runTimeText string
12405- if info.RunTimeNanosec == 0 {
12406- if info.EventCode == sqlite3.TraceProfile {
12407- //runTimeText = "; no time" // seems confusing
12408- runTimeText = "; time 0" // no measurement unit
12409- } else {
12410- //runTimeText = "; no time" // seems useless and confusing
12411- }
12412- } else {
12413- const nanosPerMillisec = 1000000
12414- if info.RunTimeNanosec%nanosPerMillisec == 0 {
12415- runTimeText = fmt.Sprintf("; time %d ms", info.RunTimeNanosec/nanosPerMillisec)
12416- } else {
12417- // unexpected: better than millisecond resolution
12418- runTimeText = fmt.Sprintf("; time %d ns!!!", info.RunTimeNanosec)
12419- }
12420- }
12421-
12422- var modeText string
12423- if info.AutoCommit {
12424- modeText = "-AC-"
12425- } else {
12426- modeText = "+Tx+"
12427- }
12428-
12429- fmt.Printf("Trace: ev %d %s conn 0x%x, stmt 0x%x {%q}%s%s%s\n",
12430- info.EventCode, modeText, info.ConnHandle, info.StmtHandle,
12431- info.StmtOrTrigger, expandedText,
12432- runTimeText,
12433- dbErrText)
12434- return 0
12435- }
12436-
12437- func main() {
12438- eventMask := sqlite3.TraceStmt | sqlite3.TraceProfile | sqlite3.TraceRow | sqlite3.TraceClose
12439-
12440- sql.Register("sqlite3_tracing",
12441- &sqlite3.SQLiteDriver{
12442- ConnectHook: func(conn *sqlite3.SQLiteConn) error {
12443- err := conn.SetTrace(&sqlite3.TraceConfig{
12444- Callback: traceCallback,
12445- EventMask: uint(eventMask),
12446- WantExpandedSQL: true,
12447- })
12448- return err
12449- },
12450- })
12451-
12452- os.Exit(dbMain())
12453- }
12454-
12455- // Harder to do DB work in main().
12456- // It's better with a separate function because
12457- // 'defer' and 'os.Exit' don't go well together.
12458- //
12459- // DO NOT use 'log.Fatal...' below: remember that it's equivalent to
12460- // Print() followed by a call to os.Exit(1) --- and
12461- // we want to avoid Exit() so 'defer' can do cleanup.
12462- // Use 'log.Panic...' instead.
12463-
12464- func dbMain() int {
12465- db, err := sql.Open("sqlite3_tracing", ":memory:")
12466- if err != nil {
12467- fmt.Printf("Failed to open database: %#+v\n", err)
12468- return 1
12469- }
12470- defer db.Close()
12471-
12472- err = db.Ping()
12473- if err != nil {
12474- log.Panic(err)
12475- }
12476-
12477- dbSetup(db)
12478-
12479- dbDoInsert(db)
12480- dbDoInsertPrepared(db)
12481- dbDoSelect(db)
12482- dbDoSelectPrepared(db)
12483-
12484- return 0
12485- }
12486-
12487- // 'DDL' stands for "Data Definition Language":
12488-
12489- // Note: "INTEGER PRIMARY KEY NOT NULL AUTOINCREMENT" causes the error
12490- // 'near "AUTOINCREMENT": syntax error'; without "NOT NULL" it works.
12491- const tableDDL = `CREATE TABLE t1 (
12492- id INTEGER PRIMARY KEY AUTOINCREMENT,
12493- note VARCHAR NOT NULL
12494- )`
12495-
12496- // 'DML' stands for "Data Manipulation Language":
12497-
12498- const insertDML = "INSERT INTO t1 (note) VALUES (?)"
12499- const selectDML = "SELECT id, note FROM t1 WHERE note LIKE ?"
12500-
12501- const textPrefix = "bla-1234567890-"
12502- const noteTextPattern = "%Prep%"
12503-
12504- const nGenRows = 4 // Number of Rows to Generate (for *each* approach tested)
12505-
12506- func dbSetup(db *sql.DB) {
12507- var err error
12508-
12509- _, err = db.Exec("DROP TABLE IF EXISTS t1")
12510- if err != nil {
12511- log.Panic(err)
12512- }
12513- _, err = db.Exec(tableDDL)
12514- if err != nil {
12515- log.Panic(err)
12516- }
12517- }
12518-
12519- func dbDoInsert(db *sql.DB) {
12520- const Descr = "DB-Exec"
12521- for i := 0; i < nGenRows; i++ {
12522- result, err := db.Exec(insertDML, textPrefix+Descr)
12523- if err != nil {
12524- log.Panic(err)
12525- }
12526-
12527- resultDoCheck(result, Descr, i)
12528- }
12529- }
12530-
12531- func dbDoInsertPrepared(db *sql.DB) {
12532- const Descr = "DB-Prepare"
12533-
12534- stmt, err := db.Prepare(insertDML)
12535- if err != nil {
12536- log.Panic(err)
12537- }
12538- defer stmt.Close()
12539-
12540- for i := 0; i < nGenRows; i++ {
12541- result, err := stmt.Exec(textPrefix + Descr)
12542- if err != nil {
12543- log.Panic(err)
12544- }
12545-
12546- resultDoCheck(result, Descr, i)
12547- }
12548- }
12549-
12550- func resultDoCheck(result sql.Result, callerDescr string, callIndex int) {
12551- lastID, err := result.LastInsertId()
12552- if err != nil {
12553- log.Panic(err)
12554- }
12555- nAffected, err := result.RowsAffected()
12556- if err != nil {
12557- log.Panic(err)
12558- }
12559-
12560- log.Printf("Exec result for %s (%d): ID = %d, affected = %d\n", callerDescr, callIndex, lastID, nAffected)
12561- }
12562-
12563- func dbDoSelect(db *sql.DB) {
12564- const Descr = "DB-Query"
12565-
12566- rows, err := db.Query(selectDML, noteTextPattern)
12567- if err != nil {
12568- log.Panic(err)
12569- }
12570- defer rows.Close()
12571-
12572- rowsDoFetch(rows, Descr)
12573- }
12574-
12575- func dbDoSelectPrepared(db *sql.DB) {
12576- const Descr = "DB-Prepare"
12577-
12578- stmt, err := db.Prepare(selectDML)
12579- if err != nil {
12580- log.Panic(err)
12581- }
12582- defer stmt.Close()
12583-
12584- rows, err := stmt.Query(noteTextPattern)
12585- if err != nil {
12586- log.Panic(err)
12587- }
12588- defer rows.Close()
12589-
12590- rowsDoFetch(rows, Descr)
12591- }
12592-
12593- func rowsDoFetch(rows *sql.Rows, callerDescr string) {
12594- var nRows int
12595- var id int64
12596- var note string
12597-
12598- for rows.Next() {
12599- err := rows.Scan(&id, &note)
12600- if err != nil {
12601- log.Panic(err)
12602- }
12603- log.Printf("Row for %s (%d): id=%d, note=%q\n",
12604- callerDescr, nRows, id, note)
12605- nRows++
12606- }
12607- if err := rows.Err(); err != nil {
12608- log.Panic(err)
12609- }
12610- log.Printf("Total %d rows for %s.\n", nRows, callerDescr)
12611- }
12612 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/vtable/main.go b/vendor/github.com/mattn/go-sqlite3/_example/vtable/main.go
12613deleted file mode 100644
12614index aad8dda..0000000
12615--- a/vendor/github.com/mattn/go-sqlite3/_example/vtable/main.go
12616+++ /dev/null
12617 @@ -1,38 +0,0 @@
12618- package main
12619-
12620- import (
12621- "database/sql"
12622- "fmt"
12623- "log"
12624-
12625- "github.com/mattn/go-sqlite3"
12626- )
12627-
12628- func main() {
12629- sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
12630- ConnectHook: func(conn *sqlite3.SQLiteConn) error {
12631- return conn.CreateModule("github", &githubModule{})
12632- },
12633- })
12634- db, err := sql.Open("sqlite3_with_extensions", ":memory:")
12635- if err != nil {
12636- log.Fatal(err)
12637- }
12638- defer db.Close()
12639-
12640- _, err = db.Exec("create virtual table repo using github(id, full_name, description, html_url)")
12641- if err != nil {
12642- log.Fatal(err)
12643- }
12644-
12645- rows, err := db.Query("select id, full_name, description, html_url from repo")
12646- if err != nil {
12647- log.Fatal(err)
12648- }
12649- defer rows.Close()
12650- for rows.Next() {
12651- var id, fullName, description, htmlURL string
12652- rows.Scan(&id, &fullName, &description, &htmlURL)
12653- fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
12654- }
12655- }
12656 diff --git a/vendor/github.com/mattn/go-sqlite3/_example/vtable/vtable.go b/vendor/github.com/mattn/go-sqlite3/_example/vtable/vtable.go
12657deleted file mode 100644
12658index 1d6d824..0000000
12659--- a/vendor/github.com/mattn/go-sqlite3/_example/vtable/vtable.go
12660+++ /dev/null
12661 @@ -1,111 +0,0 @@
12662- package main
12663-
12664- import (
12665- "encoding/json"
12666- "fmt"
12667- "io/ioutil"
12668- "net/http"
12669-
12670- "github.com/mattn/go-sqlite3"
12671- )
12672-
12673- type githubRepo struct {
12674- ID int `json:"id"`
12675- FullName string `json:"full_name"`
12676- Description string `json:"description"`
12677- HTMLURL string `json:"html_url"`
12678- }
12679-
12680- type githubModule struct {
12681- }
12682-
12683- func (m *githubModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
12684- err := c.DeclareVTab(fmt.Sprintf(`
12685- CREATE TABLE %s (
12686- id INT,
12687- full_name TEXT,
12688- description TEXT,
12689- html_url TEXT
12690- )`, args[0]))
12691- if err != nil {
12692- return nil, err
12693- }
12694- return &ghRepoTable{}, nil
12695- }
12696-
12697- func (m *githubModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
12698- return m.Create(c, args)
12699- }
12700-
12701- func (m *githubModule) DestroyModule() {}
12702-
12703- type ghRepoTable struct {
12704- repos []githubRepo
12705- }
12706-
12707- func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
12708- resp, err := http.Get("https://api.github.com/repositories")
12709- if err != nil {
12710- return nil, err
12711- }
12712- defer resp.Body.Close()
12713-
12714- body, err := ioutil.ReadAll(resp.Body)
12715- if err != nil {
12716- return nil, err
12717- }
12718-
12719- var repos []githubRepo
12720- if err := json.Unmarshal(body, &repos); err != nil {
12721- return nil, err
12722- }
12723- return &ghRepoCursor{0, repos}, nil
12724- }
12725-
12726- func (v *ghRepoTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
12727- return &sqlite3.IndexResult{}, nil
12728- }
12729-
12730- func (v *ghRepoTable) Disconnect() error { return nil }
12731- func (v *ghRepoTable) Destroy() error { return nil }
12732-
12733- type ghRepoCursor struct {
12734- index int
12735- repos []githubRepo
12736- }
12737-
12738- func (vc *ghRepoCursor) Column(c *sqlite3.SQLiteContext, col int) error {
12739- switch col {
12740- case 0:
12741- c.ResultInt(vc.repos[vc.index].ID)
12742- case 1:
12743- c.ResultText(vc.repos[vc.index].FullName)
12744- case 2:
12745- c.ResultText(vc.repos[vc.index].Description)
12746- case 3:
12747- c.ResultText(vc.repos[vc.index].HTMLURL)
12748- }
12749- return nil
12750- }
12751-
12752- func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
12753- vc.index = 0
12754- return nil
12755- }
12756-
12757- func (vc *ghRepoCursor) Next() error {
12758- vc.index++
12759- return nil
12760- }
12761-
12762- func (vc *ghRepoCursor) EOF() bool {
12763- return vc.index >= len(vc.repos)
12764- }
12765-
12766- func (vc *ghRepoCursor) Rowid() (int64, error) {
12767- return int64(vc.index), nil
12768- }
12769-
12770- func (vc *ghRepoCursor) Close() error {
12771- return nil
12772- }
12773 diff --git a/vendor/github.com/mattn/go-sqlite3/tool/upgrade.go b/vendor/github.com/mattn/go-sqlite3/tool/upgrade.go
12774deleted file mode 100644
12775index 94ed39d..0000000
12776--- a/vendor/github.com/mattn/go-sqlite3/tool/upgrade.go
12777+++ /dev/null
12778 @@ -1,111 +0,0 @@
12779- // +build ignore
12780-
12781- package main
12782-
12783- import (
12784- "archive/zip"
12785- "bufio"
12786- "bytes"
12787- "fmt"
12788- "io"
12789- "io/ioutil"
12790- "log"
12791- "net/http"
12792- "os"
12793- "path"
12794- "path/filepath"
12795- "strings"
12796-
12797- "github.com/PuerkitoBio/goquery"
12798- )
12799-
12800- func main() {
12801- site := "https://www.sqlite.org/download.html"
12802- fmt.Printf("scraping %v\n", site)
12803- doc, err := goquery.NewDocument(site)
12804- if err != nil {
12805- log.Fatal(err)
12806- }
12807- var url string
12808- doc.Find("a").Each(func(_ int, s *goquery.Selection) {
12809- if url == "" && strings.HasPrefix(s.Text(), "sqlite-amalgamation-") {
12810- url = "https://www.sqlite.org/2017/" + s.Text()
12811- }
12812- })
12813- if url == "" {
12814- return
12815- }
12816- fmt.Printf("downloading %v\n", url)
12817- resp, err := http.Get(url)
12818- if err != nil {
12819- log.Fatal(err)
12820- }
12821-
12822- b, err := ioutil.ReadAll(resp.Body)
12823- if err != nil {
12824- resp.Body.Close()
12825- log.Fatal(err)
12826- }
12827-
12828- fmt.Printf("extracting %v\n", path.Base(url))
12829- r, err := zip.NewReader(bytes.NewReader(b), resp.ContentLength)
12830- if err != nil {
12831- resp.Body.Close()
12832- log.Fatal(err)
12833- }
12834- resp.Body.Close()
12835-
12836- for _, zf := range r.File {
12837- var f *os.File
12838- switch path.Base(zf.Name) {
12839- case "sqlite3.c":
12840- f, err = os.Create("sqlite3-binding.c")
12841- case "sqlite3.h":
12842- f, err = os.Create("sqlite3-binding.h")
12843- case "sqlite3ext.h":
12844- f, err = os.Create("sqlite3ext.h")
12845- default:
12846- continue
12847- }
12848- if err != nil {
12849- log.Fatal(err)
12850- }
12851- zr, err := zf.Open()
12852- if err != nil {
12853- log.Fatal(err)
12854- }
12855-
12856- _, err = io.WriteString(f, "#ifndef USE_LIBSQLITE3\n")
12857- if err != nil {
12858- zr.Close()
12859- f.Close()
12860- log.Fatal(err)
12861- }
12862- scanner := bufio.NewScanner(zr)
12863- for scanner.Scan() {
12864- text := scanner.Text()
12865- if text == `#include "sqlite3.h"` {
12866- text = `#include "sqlite3-binding.h"`
12867- }
12868- _, err = fmt.Fprintln(f, text)
12869- if err != nil {
12870- break
12871- }
12872- }
12873- err = scanner.Err()
12874- if err != nil {
12875- zr.Close()
12876- f.Close()
12877- log.Fatal(err)
12878- }
12879- _, err = io.WriteString(f, "#else // USE_LIBSQLITE3\n // If users really want to link against the system sqlite3 we\n// need to make this file a noop.\n #endif")
12880- if err != nil {
12881- zr.Close()
12882- f.Close()
12883- log.Fatal(err)
12884- }
12885- zr.Close()
12886- f.Close()
12887- fmt.Printf("extracted %v\n", filepath.Base(f.Name()))
12888- }
12889- }
12890 diff --git a/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md b/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md
12891new file mode 100644
12892index 0000000..2298515
12893--- /dev/null
12894+++ b/vendor/github.com/mitchellh/go-wordwrap/LICENSE.md
12895 @@ -0,0 +1,21 @@
12896+ The MIT License (MIT)
12897+
12898+ Copyright (c) 2014 Mitchell Hashimoto
12899+
12900+ Permission is hereby granted, free of charge, to any person obtaining a copy
12901+ of this software and associated documentation files (the "Software"), to deal
12902+ in the Software without restriction, including without limitation the rights
12903+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12904+ copies of the Software, and to permit persons to whom the Software is
12905+ furnished to do so, subject to the following conditions:
12906+
12907+ The above copyright notice and this permission notice shall be included in
12908+ all copies or substantial portions of the Software.
12909+
12910+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12911+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12912+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
12913+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12914+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12915+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
12916+ THE SOFTWARE.
12917 diff --git a/vendor/github.com/mitchellh/go-wordwrap/README.md b/vendor/github.com/mitchellh/go-wordwrap/README.md
12918new file mode 100644
12919index 0000000..60ae311
12920--- /dev/null
12921+++ b/vendor/github.com/mitchellh/go-wordwrap/README.md
12922 @@ -0,0 +1,39 @@
12923+ # go-wordwrap
12924+
12925+ `go-wordwrap` (Golang package: `wordwrap`) is a package for Go that
12926+ automatically wraps words into multiple lines. The primary use case for this
12927+ is in formatting CLI output, but of course word wrapping is a generally useful
12928+ thing to do.
12929+
12930+ ## Installation and Usage
12931+
12932+ Install using `go get github.com/mitchellh/go-wordwrap`.
12933+
12934+ Full documentation is available at
12935+ http://godoc.org/github.com/mitchellh/go-wordwrap
12936+
12937+ Below is an example of its usage ignoring errors:
12938+
12939+ ```go
12940+ wrapped := wordwrap.WrapString("foo bar baz", 3)
12941+ fmt.Println(wrapped)
12942+ ```
12943+
12944+ Would output:
12945+
12946+ ```
12947+ foo
12948+ bar
12949+ baz
12950+ ```
12951+
12952+ ## Word Wrap Algorithm
12953+
12954+ This library doesn't use any clever algorithm for word wrapping. The wrapping
12955+ is actually very naive: whenever there is whitespace or an explicit linebreak.
12956+ The goal of this library is for word wrapping CLI output, so the input is
12957+ typically pretty well controlled human language. Because of this, the naive
12958+ approach typically works just fine.
12959+
12960+ In the future, we'd like to make the algorithm more advanced. We would do
12961+ so without breaking the API.
12962 diff --git a/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go b/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go
12963new file mode 100644
12964index 0000000..ac67205
12965--- /dev/null
12966+++ b/vendor/github.com/mitchellh/go-wordwrap/wordwrap.go
12967 @@ -0,0 +1,73 @@
12968+ package wordwrap
12969+
12970+ import (
12971+ "bytes"
12972+ "unicode"
12973+ )
12974+
12975+ // WrapString wraps the given string within lim width in characters.
12976+ //
12977+ // Wrapping is currently naive and only happens at white-space. A future
12978+ // version of the library will implement smarter wrapping. This means that
12979+ // pathological cases can dramatically reach past the limit, such as a very
12980+ // long word.
12981+ func WrapString(s string, lim uint) string {
12982+ // Initialize a buffer with a slightly larger size to account for breaks
12983+ init := make([]byte, 0, len(s))
12984+ buf := bytes.NewBuffer(init)
12985+
12986+ var current uint
12987+ var wordBuf, spaceBuf bytes.Buffer
12988+
12989+ for _, char := range s {
12990+ if char == '\n' {
12991+ if wordBuf.Len() == 0 {
12992+ if current+uint(spaceBuf.Len()) > lim {
12993+ current = 0
12994+ } else {
12995+ current += uint(spaceBuf.Len())
12996+ spaceBuf.WriteTo(buf)
12997+ }
12998+ spaceBuf.Reset()
12999+ } else {
13000+ current += uint(spaceBuf.Len() + wordBuf.Len())
13001+ spaceBuf.WriteTo(buf)
13002+ spaceBuf.Reset()
13003+ wordBuf.WriteTo(buf)
13004+ wordBuf.Reset()
13005+ }
13006+ buf.WriteRune(char)
13007+ current = 0
13008+ } else if unicode.IsSpace(char) {
13009+ if spaceBuf.Len() == 0 || wordBuf.Len() > 0 {
13010+ current += uint(spaceBuf.Len() + wordBuf.Len())
13011+ spaceBuf.WriteTo(buf)
13012+ spaceBuf.Reset()
13013+ wordBuf.WriteTo(buf)
13014+ wordBuf.Reset()
13015+ }
13016+
13017+ spaceBuf.WriteRune(char)
13018+ } else {
13019+
13020+ wordBuf.WriteRune(char)
13021+
13022+ if current+uint(spaceBuf.Len()+wordBuf.Len()) > lim && uint(wordBuf.Len()) < lim {
13023+ buf.WriteRune('\n')
13024+ current = 0
13025+ spaceBuf.Reset()
13026+ }
13027+ }
13028+ }
13029+
13030+ if wordBuf.Len() == 0 {
13031+ if current+uint(spaceBuf.Len()) <= lim {
13032+ spaceBuf.WriteTo(buf)
13033+ }
13034+ } else {
13035+ spaceBuf.WriteTo(buf)
13036+ wordBuf.WriteTo(buf)
13037+ }
13038+
13039+ return buf.String()
13040+ }
13041 diff --git a/vendor/github.com/mitchellh/go-wordwrap/wordwrap_test.go b/vendor/github.com/mitchellh/go-wordwrap/wordwrap_test.go
13042new file mode 100644
13043index 0000000..bf6ae13
13044--- /dev/null
13045+++ b/vendor/github.com/mitchellh/go-wordwrap/wordwrap_test.go
13046 @@ -0,0 +1,85 @@
13047+ package wordwrap
13048+
13049+ import (
13050+ "testing"
13051+ )
13052+
13053+ func TestWrapString(t *testing.T) {
13054+ cases := []struct {
13055+ Input, Output string
13056+ Lim uint
13057+ }{
13058+ // A simple word passes through.
13059+ {
13060+ "foo",
13061+ "foo",
13062+ 4,
13063+ },
13064+ // A single word that is too long passes through.
13065+ // We do not break words.
13066+ {
13067+ "foobarbaz",
13068+ "foobarbaz",
13069+ 4,
13070+ },
13071+ // Lines are broken at whitespace.
13072+ {
13073+ "foo bar baz",
13074+ "foo\nbar\nbaz",
13075+ 4,
13076+ },
13077+ // Lines are broken at whitespace, even if words
13078+ // are too long. We do not break words.
13079+ {
13080+ "foo bars bazzes",
13081+ "foo\nbars\nbazzes",
13082+ 4,
13083+ },
13084+ // A word that would run beyond the width is wrapped.
13085+ {
13086+ "fo sop",
13087+ "fo\nsop",
13088+ 4,
13089+ },
13090+ // Whitespace that trails a line and fits the width
13091+ // passes through, as does whitespace prefixing an
13092+ // explicit line break. A tab counts as one character.
13093+ {
13094+ "foo\nb\t r\n baz",
13095+ "foo\nb\t r\n baz",
13096+ 4,
13097+ },
13098+ // Trailing whitespace is removed if it doesn't fit the width.
13099+ // Runs of whitespace on which a line is broken are removed.
13100+ {
13101+ "foo \nb ar ",
13102+ "foo\nb\nar",
13103+ 4,
13104+ },
13105+ // An explicit line break at the end of the input is preserved.
13106+ {
13107+ "foo bar baz\n",
13108+ "foo\nbar\nbaz\n",
13109+ 4,
13110+ },
13111+ // Explicit break are always preserved.
13112+ {
13113+ "\nfoo bar\n\n\nbaz\n",
13114+ "\nfoo\nbar\n\n\nbaz\n",
13115+ 4,
13116+ },
13117+ // Complete example:
13118+ {
13119+ " This is a list: \n\n\t* foo\n\t* bar\n\n\n\t* baz \nBAM ",
13120+ " This\nis a\nlist: \n\n\t* foo\n\t* bar\n\n\n\t* baz\nBAM",
13121+ 6,
13122+ },
13123+ }
13124+
13125+ for i, tc := range cases {
13126+ actual := WrapString(tc.Input, tc.Lim)
13127+ if actual != tc.Output {
13128+ t.Fatalf("Case %d Input:\n\n`%s`\n\nActual Output:\n\n`%s`", i, tc.Input, actual)
13129+ }
13130+ }
13131+ }
13132 diff --git a/vendor/github.com/nsf/termbox-go/AUTHORS b/vendor/github.com/nsf/termbox-go/AUTHORS
13133new file mode 100644
13134index 0000000..fe26fb0
13135--- /dev/null
13136+++ b/vendor/github.com/nsf/termbox-go/AUTHORS
13137 @@ -0,0 +1,4 @@
13138+ # Please keep this file sorted.
13139+
13140+ Georg Reinke <guelfey@googlemail.com>
13141+ nsf <no.smile.face@gmail.com>
13142 diff --git a/vendor/github.com/nsf/termbox-go/LICENSE b/vendor/github.com/nsf/termbox-go/LICENSE
13143new file mode 100644
13144index 0000000..d9bc068
13145--- /dev/null
13146+++ b/vendor/github.com/nsf/termbox-go/LICENSE
13147 @@ -0,0 +1,19 @@
13148+ Copyright (C) 2012 termbox-go authors
13149+
13150+ Permission is hereby granted, free of charge, to any person obtaining a copy
13151+ of this software and associated documentation files (the "Software"), to deal
13152+ in the Software without restriction, including without limitation the rights
13153+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13154+ copies of the Software, and to permit persons to whom the Software is
13155+ furnished to do so, subject to the following conditions:
13156+
13157+ The above copyright notice and this permission notice shall be included in
13158+ all copies or substantial portions of the Software.
13159+
13160+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13161+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13162+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13163+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13164+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
13165+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13166+ THE SOFTWARE.
13167 diff --git a/vendor/github.com/nsf/termbox-go/README.md b/vendor/github.com/nsf/termbox-go/README.md
13168new file mode 100644
13169index 0000000..35dcf1b
13170--- /dev/null
13171+++ b/vendor/github.com/nsf/termbox-go/README.md
13172 @@ -0,0 +1,39 @@
13173+ ## Termbox
13174+ Termbox is a library that provides a minimalistic API which allows the programmer to write text-based user interfaces. The library is crossplatform and has both terminal-based implementations on *nix operating systems and a winapi console based implementation for windows operating systems. The basic idea is an abstraction of the greatest common subset of features available on all major terminals and other terminal-like APIs in a minimalistic fashion. Small API means it is easy to implement, test, maintain and learn it, that's what makes the termbox a distinct library in its area.
13175+
13176+ ### Installation
13177+ Install and update this go package with `go get -u github.com/nsf/termbox-go`
13178+
13179+ ### Examples
13180+ For examples of what can be done take a look at demos in the _demos directory. You can try them with go run: `go run _demos/keyboard.go`
13181+
13182+ There are also some interesting projects using termbox-go:
13183+ - [godit](https://github.com/nsf/godit) is an emacsish lightweight text editor written using termbox.
13184+ - [gomatrix](https://github.com/GeertJohan/gomatrix) connects to The Matrix and displays its data streams in your terminal.
13185+ - [gotetris](https://github.com/jjinux/gotetris) is an implementation of Tetris.
13186+ - [sokoban-go](https://github.com/rn2dy/sokoban-go) is an implementation of sokoban game.
13187+ - [hecate](https://github.com/evanmiller/hecate) is a hex editor designed by Satan.
13188+ - [httopd](https://github.com/verdverm/httopd) is top for httpd logs.
13189+ - [mop](https://github.com/mop-tracker/mop) is stock market tracker for hackers.
13190+ - [termui](https://github.com/gizak/termui) is a terminal dashboard.
13191+ - [termloop](https://github.com/JoelOtter/termloop) is a terminal game engine.
13192+ - [xterm-color-chart](https://github.com/kutuluk/xterm-color-chart) is a XTerm 256 color chart.
13193+ - [gocui](https://github.com/jroimartin/gocui) is a minimalist Go library aimed at creating console user interfaces.
13194+ - [dry](https://github.com/moncho/dry) is an interactive cli to manage Docker containers.
13195+ - [pxl](https://github.com/ichinaski/pxl) displays images in the terminal.
13196+ - [snake-game](https://github.com/DyegoCosta/snake-game) is an implementation of the Snake game.
13197+ - [gone](https://github.com/guillaumebreton/gone) is a CLI pomodoro® timer.
13198+ - [Spoof.go](https://github.com/sabey/spoofgo) controllable movement spoofing from the cli
13199+ - [lf](https://github.com/gokcehan/lf) is a terminal file manager
13200+ - [rat](https://github.com/ericfreese/rat) lets you compose shell commands to build terminal applications.
13201+ - [httplab](https://github.com/gchaincl/httplab) An interactive web server.
13202+ - [tetris](https://github.com/MichaelS11/tetris) Go Tetris with AI option
13203+ - [wot](https://github.com/kyu-suke/wot) Wait time during command is completed.
13204+ - [2048-go](https://github.com/1984weed/2048-go) is 2048 in Go
13205+ - [jv](https://github.com/maxzender/jv) helps you view JSON on the command-line.
13206+ - [pinger](https://github.com/hirose31/pinger) helps you to monitor numerous hosts using ICMP ECHO_REQUEST.
13207+ - [vixl44](https://github.com/sebashwa/vixl44) lets you create pixel art inside your terminal using vim movements
13208+ - [zterm](https://github.com/varunrau/zterm) is a typing game inspired by http://zty.pe/
13209+
13210+ ### API reference
13211+ [godoc.org/github.com/nsf/termbox-go](http://godoc.org/github.com/nsf/termbox-go)
13212 diff --git a/vendor/github.com/nsf/termbox-go/api.go b/vendor/github.com/nsf/termbox-go/api.go
13213new file mode 100644
13214index 0000000..d530ab5
13215--- /dev/null
13216+++ b/vendor/github.com/nsf/termbox-go/api.go
13217 @@ -0,0 +1,489 @@
13218+ // +build !windows
13219+
13220+ package termbox
13221+
13222+ import "github.com/mattn/go-runewidth"
13223+ import "fmt"
13224+ import "os"
13225+ import "os/signal"
13226+ import "syscall"
13227+ import "runtime"
13228+ import "time"
13229+
13230+ // public API
13231+
13232+ // Initializes termbox library. This function should be called before any other functions.
13233+ // After successful initialization, the library must be finalized using 'Close' function.
13234+ //
13235+ // Example usage:
13236+ // err := termbox.Init()
13237+ // if err != nil {
13238+ // panic(err)
13239+ // }
13240+ // defer termbox.Close()
13241+ func Init() error {
13242+ var err error
13243+
13244+ out, err = os.OpenFile("/dev/tty", syscall.O_WRONLY, 0)
13245+ if err != nil {
13246+ return err
13247+ }
13248+ in, err = syscall.Open("/dev/tty", syscall.O_RDONLY, 0)
13249+ if err != nil {
13250+ return err
13251+ }
13252+
13253+ err = setup_term()
13254+ if err != nil {
13255+ return fmt.Errorf("termbox: error while reading terminfo data: %v", err)
13256+ }
13257+
13258+ signal.Notify(sigwinch, syscall.SIGWINCH)
13259+ signal.Notify(sigio, syscall.SIGIO)
13260+
13261+ _, err = fcntl(in, syscall.F_SETFL, syscall.O_ASYNC|syscall.O_NONBLOCK)
13262+ if err != nil {
13263+ return err
13264+ }
13265+ _, err = fcntl(in, syscall.F_SETOWN, syscall.Getpid())
13266+ if runtime.GOOS != "darwin" && err != nil {
13267+ return err
13268+ }
13269+ err = tcgetattr(out.Fd(), &orig_tios)
13270+ if err != nil {
13271+ return err
13272+ }
13273+
13274+ tios := orig_tios
13275+ tios.Iflag &^= syscall_IGNBRK | syscall_BRKINT | syscall_PARMRK |
13276+ syscall_ISTRIP | syscall_INLCR | syscall_IGNCR |
13277+ syscall_ICRNL | syscall_IXON
13278+ tios.Lflag &^= syscall_ECHO | syscall_ECHONL | syscall_ICANON |
13279+ syscall_ISIG | syscall_IEXTEN
13280+ tios.Cflag &^= syscall_CSIZE | syscall_PARENB
13281+ tios.Cflag |= syscall_CS8
13282+ tios.Cc[syscall_VMIN] = 1
13283+ tios.Cc[syscall_VTIME] = 0
13284+
13285+ err = tcsetattr(out.Fd(), &tios)
13286+ if err != nil {
13287+ return err
13288+ }
13289+
13290+ out.WriteString(funcs[t_enter_ca])
13291+ out.WriteString(funcs[t_enter_keypad])
13292+ out.WriteString(funcs[t_hide_cursor])
13293+ out.WriteString(funcs[t_clear_screen])
13294+
13295+ termw, termh = get_term_size(out.Fd())
13296+ back_buffer.init(termw, termh)
13297+ front_buffer.init(termw, termh)
13298+ back_buffer.clear()
13299+ front_buffer.clear()
13300+
13301+ go func() {
13302+ buf := make([]byte, 128)
13303+ for {
13304+ select {
13305+ case <-sigio:
13306+ for {
13307+ n, err := syscall.Read(in, buf)
13308+ if err == syscall.EAGAIN || err == syscall.EWOULDBLOCK {
13309+ break
13310+ }
13311+ select {
13312+ case input_comm <- input_event{buf[:n], err}:
13313+ ie := <-input_comm
13314+ buf = ie.data[:128]
13315+ case <-quit:
13316+ return
13317+ }
13318+ }
13319+ case <-quit:
13320+ return
13321+ }
13322+ }
13323+ }()
13324+
13325+ IsInit = true
13326+ return nil
13327+ }
13328+
13329+ // Interrupt an in-progress call to PollEvent by causing it to return
13330+ // EventInterrupt. Note that this function will block until the PollEvent
13331+ // function has successfully been interrupted.
13332+ func Interrupt() {
13333+ interrupt_comm <- struct{}{}
13334+ }
13335+
13336+ // Finalizes termbox library, should be called after successful initialization
13337+ // when termbox's functionality isn't required anymore.
13338+ func Close() {
13339+ quit <- 1
13340+ out.WriteString(funcs[t_show_cursor])
13341+ out.WriteString(funcs[t_sgr0])
13342+ out.WriteString(funcs[t_clear_screen])
13343+ out.WriteString(funcs[t_exit_ca])
13344+ out.WriteString(funcs[t_exit_keypad])
13345+ out.WriteString(funcs[t_exit_mouse])
13346+ tcsetattr(out.Fd(), &orig_tios)
13347+
13348+ out.Close()
13349+ syscall.Close(in)
13350+
13351+ // reset the state, so that on next Init() it will work again
13352+ termw = 0
13353+ termh = 0
13354+ input_mode = InputEsc
13355+ out = nil
13356+ in = 0
13357+ lastfg = attr_invalid
13358+ lastbg = attr_invalid
13359+ lastx = coord_invalid
13360+ lasty = coord_invalid
13361+ cursor_x = cursor_hidden
13362+ cursor_y = cursor_hidden
13363+ foreground = ColorDefault
13364+ background = ColorDefault
13365+ IsInit = false
13366+ }
13367+
13368+ // Synchronizes the internal back buffer with the terminal.
13369+ func Flush() error {
13370+ // invalidate cursor position
13371+ lastx = coord_invalid
13372+ lasty = coord_invalid
13373+
13374+ update_size_maybe()
13375+
13376+ for y := 0; y < front_buffer.height; y++ {
13377+ line_offset := y * front_buffer.width
13378+ for x := 0; x < front_buffer.width; {
13379+ cell_offset := line_offset + x
13380+ back := &back_buffer.cells[cell_offset]
13381+ front := &front_buffer.cells[cell_offset]
13382+ if back.Ch < ' ' {
13383+ back.Ch = ' '
13384+ }
13385+ w := runewidth.RuneWidth(back.Ch)
13386+ if w == 0 || w == 2 && runewidth.IsAmbiguousWidth(back.Ch) {
13387+ w = 1
13388+ }
13389+ if *back == *front {
13390+ x += w
13391+ continue
13392+ }
13393+ *front = *back
13394+ send_attr(back.Fg, back.Bg)
13395+
13396+ if w == 2 && x == front_buffer.width-1 {
13397+ // there's not enough space for 2-cells rune,
13398+ // let's just put a space in there
13399+ send_char(x, y, ' ')
13400+ } else {
13401+ send_char(x, y, back.Ch)
13402+ if w == 2 {
13403+ next := cell_offset + 1
13404+ front_buffer.cells[next] = Cell{
13405+ Ch: 0,
13406+ Fg: back.Fg,
13407+ Bg: back.Bg,
13408+ }
13409+ }
13410+ }
13411+ x += w
13412+ }
13413+ }
13414+ if !is_cursor_hidden(cursor_x, cursor_y) {
13415+ write_cursor(cursor_x, cursor_y)
13416+ }
13417+ return flush()
13418+ }
13419+
13420+ // Sets the position of the cursor. See also HideCursor().
13421+ func SetCursor(x, y int) {
13422+ if is_cursor_hidden(cursor_x, cursor_y) && !is_cursor_hidden(x, y) {
13423+ outbuf.WriteString(funcs[t_show_cursor])
13424+ }
13425+
13426+ if !is_cursor_hidden(cursor_x, cursor_y) && is_cursor_hidden(x, y) {
13427+ outbuf.WriteString(funcs[t_hide_cursor])
13428+ }
13429+
13430+ cursor_x, cursor_y = x, y
13431+ if !is_cursor_hidden(cursor_x, cursor_y) {
13432+ write_cursor(cursor_x, cursor_y)
13433+ }
13434+ }
13435+
13436+ // The shortcut for SetCursor(-1, -1).
13437+ func HideCursor() {
13438+ SetCursor(cursor_hidden, cursor_hidden)
13439+ }
13440+
13441+ // Changes cell's parameters in the internal back buffer at the specified
13442+ // position.
13443+ func SetCell(x, y int, ch rune, fg, bg Attribute) {
13444+ if x < 0 || x >= back_buffer.width {
13445+ return
13446+ }
13447+ if y < 0 || y >= back_buffer.height {
13448+ return
13449+ }
13450+
13451+ back_buffer.cells[y*back_buffer.width+x] = Cell{ch, fg, bg}
13452+ }
13453+
13454+ // Returns a slice into the termbox's back buffer. You can get its dimensions
13455+ // using 'Size' function. The slice remains valid as long as no 'Clear' or
13456+ // 'Flush' function calls were made after call to this function.
13457+ func CellBuffer() []Cell {
13458+ return back_buffer.cells
13459+ }
13460+
13461+ // After getting a raw event from PollRawEvent function call, you can parse it
13462+ // again into an ordinary one using termbox logic. That is parse an event as
13463+ // termbox would do it. Returned event in addition to usual Event struct fields
13464+ // sets N field to the amount of bytes used within 'data' slice. If the length
13465+ // of 'data' slice is zero or event cannot be parsed for some other reason, the
13466+ // function will return a special event type: EventNone.
13467+ //
13468+ // IMPORTANT: EventNone may contain a non-zero N, which means you should skip
13469+ // these bytes, because termbox cannot recognize them.
13470+ //
13471+ // NOTE: This API is experimental and may change in future.
13472+ func ParseEvent(data []byte) Event {
13473+ event := Event{Type: EventKey}
13474+ status := extract_event(data, &event, false)
13475+ if status != event_extracted {
13476+ return Event{Type: EventNone, N: event.N}
13477+ }
13478+ return event
13479+ }
13480+
13481+ // Wait for an event and return it. This is a blocking function call. Instead
13482+ // of EventKey and EventMouse it returns EventRaw events. Raw event is written
13483+ // into `data` slice and Event's N field is set to the amount of bytes written.
13484+ // The minimum required length of the 'data' slice is 1. This requirement may
13485+ // vary on different platforms.
13486+ //
13487+ // NOTE: This API is experimental and may change in future.
13488+ func PollRawEvent(data []byte) Event {
13489+ if len(data) == 0 {
13490+ panic("len(data) >= 1 is a requirement")
13491+ }
13492+
13493+ var event Event
13494+ if extract_raw_event(data, &event) {
13495+ return event
13496+ }
13497+
13498+ for {
13499+ select {
13500+ case ev := <-input_comm:
13501+ if ev.err != nil {
13502+ return Event{Type: EventError, Err: ev.err}
13503+ }
13504+
13505+ inbuf = append(inbuf, ev.data...)
13506+ input_comm <- ev
13507+ if extract_raw_event(data, &event) {
13508+ return event
13509+ }
13510+ case <-interrupt_comm:
13511+ event.Type = EventInterrupt
13512+ return event
13513+
13514+ case <-sigwinch:
13515+ event.Type = EventResize
13516+ event.Width, event.Height = get_term_size(out.Fd())
13517+ return event
13518+ }
13519+ }
13520+ }
13521+
13522+ // Wait for an event and return it. This is a blocking function call.
13523+ func PollEvent() Event {
13524+ // Constant governing macOS specific behavior. See https://github.com/nsf/termbox-go/issues/132
13525+ // This is an arbitrary delay which hopefully will be enough time for any lagging
13526+ // partial escape sequences to come through.
13527+ const esc_wait_delay = 100 * time.Millisecond
13528+
13529+ var event Event
13530+ var esc_wait_timer *time.Timer
13531+ var esc_timeout <-chan time.Time
13532+
13533+ // try to extract event from input buffer, return on success
13534+ event.Type = EventKey
13535+ status := extract_event(inbuf, &event, true)
13536+ if event.N != 0 {
13537+ copy(inbuf, inbuf[event.N:])
13538+ inbuf = inbuf[:len(inbuf)-event.N]
13539+ }
13540+ if status == event_extracted {
13541+ return event
13542+ } else if status == esc_wait {
13543+ esc_wait_timer = time.NewTimer(esc_wait_delay)
13544+ esc_timeout = esc_wait_timer.C
13545+ }
13546+
13547+ for {
13548+ select {
13549+ case ev := <-input_comm:
13550+ if esc_wait_timer != nil {
13551+ if !esc_wait_timer.Stop() {
13552+ <-esc_wait_timer.C
13553+ }
13554+ esc_wait_timer = nil
13555+ }
13556+
13557+ if ev.err != nil {
13558+ return Event{Type: EventError, Err: ev.err}
13559+ }
13560+
13561+ inbuf = append(inbuf, ev.data...)
13562+ input_comm <- ev
13563+ status := extract_event(inbuf, &event, true)
13564+ if event.N != 0 {
13565+ copy(inbuf, inbuf[event.N:])
13566+ inbuf = inbuf[:len(inbuf)-event.N]
13567+ }
13568+ if status == event_extracted {
13569+ return event
13570+ } else if status == esc_wait {
13571+ esc_wait_timer = time.NewTimer(esc_wait_delay)
13572+ esc_timeout = esc_wait_timer.C
13573+ }
13574+ case <-esc_timeout:
13575+ esc_wait_timer = nil
13576+
13577+ status := extract_event(inbuf, &event, false)
13578+ if event.N != 0 {
13579+ copy(inbuf, inbuf[event.N:])
13580+ inbuf = inbuf[:len(inbuf)-event.N]
13581+ }
13582+ if status == event_extracted {
13583+ return event
13584+ }
13585+ case <-interrupt_comm:
13586+ event.Type = EventInterrupt
13587+ return event
13588+
13589+ case <-sigwinch:
13590+ event.Type = EventResize
13591+ event.Width, event.Height = get_term_size(out.Fd())
13592+ return event
13593+ }
13594+ }
13595+ }
13596+
13597+ // Returns the size of the internal back buffer (which is mostly the same as
13598+ // terminal's window size in characters). But it doesn't always match the size
13599+ // of the terminal window, after the terminal size has changed, the internal
13600+ // back buffer will get in sync only after Clear or Flush function calls.
13601+ func Size() (width int, height int) {
13602+ return termw, termh
13603+ }
13604+
13605+ // Clears the internal back buffer.
13606+ func Clear(fg, bg Attribute) error {
13607+ foreground, background = fg, bg
13608+ err := update_size_maybe()
13609+ back_buffer.clear()
13610+ return err
13611+ }
13612+
13613+ // Sets termbox input mode. Termbox has two input modes:
13614+ //
13615+ // 1. Esc input mode. When ESC sequence is in the buffer and it doesn't match
13616+ // any known sequence. ESC means KeyEsc. This is the default input mode.
13617+ //
13618+ // 2. Alt input mode. When ESC sequence is in the buffer and it doesn't match
13619+ // any known sequence. ESC enables ModAlt modifier for the next keyboard event.
13620+ //
13621+ // Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will
13622+ // enable mouse button press/release and drag events.
13623+ //
13624+ // If 'mode' is InputCurrent, returns the current input mode. See also Input*
13625+ // constants.
13626+ func SetInputMode(mode InputMode) InputMode {
13627+ if mode == InputCurrent {
13628+ return input_mode
13629+ }
13630+ if mode&(InputEsc|InputAlt) == 0 {
13631+ mode |= InputEsc
13632+ }
13633+ if mode&(InputEsc|InputAlt) == InputEsc|InputAlt {
13634+ mode &^= InputAlt
13635+ }
13636+ if mode&InputMouse != 0 {
13637+ out.WriteString(funcs[t_enter_mouse])
13638+ } else {
13639+ out.WriteString(funcs[t_exit_mouse])
13640+ }
13641+
13642+ input_mode = mode
13643+ return input_mode
13644+ }
13645+
13646+ // Sets the termbox output mode. Termbox has four output options:
13647+ //
13648+ // 1. OutputNormal => [1..8]
13649+ // This mode provides 8 different colors:
13650+ // black, red, green, yellow, blue, magenta, cyan, white
13651+ // Shortcut: ColorBlack, ColorRed, ...
13652+ // Attributes: AttrBold, AttrUnderline, AttrReverse
13653+ //
13654+ // Example usage:
13655+ // SetCell(x, y, '@', ColorBlack | AttrBold, ColorRed);
13656+ //
13657+ // 2. Output256 => [1..256]
13658+ // In this mode you can leverage the 256 terminal mode:
13659+ // 0x01 - 0x08: the 8 colors as in OutputNormal
13660+ // 0x09 - 0x10: Color* | AttrBold
13661+ // 0x11 - 0xe8: 216 different colors
13662+ // 0xe9 - 0x1ff: 24 different shades of grey
13663+ //
13664+ // Example usage:
13665+ // SetCell(x, y, '@', 184, 240);
13666+ // SetCell(x, y, '@', 0xb8, 0xf0);
13667+ //
13668+ // 3. Output216 => [1..216]
13669+ // This mode supports the 3rd range of the 256 mode only.
13670+ // But you don't need to provide an offset.
13671+ //
13672+ // 4. OutputGrayscale => [1..26]
13673+ // This mode supports the 4th range of the 256 mode
13674+ // and black and white colors from 3th range of the 256 mode
13675+ // But you don't need to provide an offset.
13676+ //
13677+ // In all modes, 0x00 represents the default color.
13678+ //
13679+ // `go run _demos/output.go` to see its impact on your terminal.
13680+ //
13681+ // If 'mode' is OutputCurrent, it returns the current output mode.
13682+ //
13683+ // Note that this may return a different OutputMode than the one requested,
13684+ // as the requested mode may not be available on the target platform.
13685+ func SetOutputMode(mode OutputMode) OutputMode {
13686+ if mode == OutputCurrent {
13687+ return output_mode
13688+ }
13689+
13690+ output_mode = mode
13691+ return output_mode
13692+ }
13693+
13694+ // Sync comes handy when something causes desync between termbox's understanding
13695+ // of a terminal buffer and the reality. Such as a third party process. Sync
13696+ // forces a complete resync between the termbox and a terminal, it may not be
13697+ // visually pretty though.
13698+ func Sync() error {
13699+ front_buffer.clear()
13700+ err := send_clear()
13701+ if err != nil {
13702+ return err
13703+ }
13704+
13705+ return Flush()
13706+ }
13707 diff --git a/vendor/github.com/nsf/termbox-go/api_common.go b/vendor/github.com/nsf/termbox-go/api_common.go
13708new file mode 100644
13709index 0000000..5ca1371
13710--- /dev/null
13711+++ b/vendor/github.com/nsf/termbox-go/api_common.go
13712 @@ -0,0 +1,187 @@
13713+ // termbox is a library for creating cross-platform text-based interfaces
13714+ package termbox
13715+
13716+ // public API, common OS agnostic part
13717+
13718+ type (
13719+ InputMode int
13720+ OutputMode int
13721+ EventType uint8
13722+ Modifier uint8
13723+ Key uint16
13724+ Attribute uint16
13725+ )
13726+
13727+ // This type represents a termbox event. The 'Mod', 'Key' and 'Ch' fields are
13728+ // valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if
13729+ // 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.
13730+ type Event struct {
13731+ Type EventType // one of Event* constants
13732+ Mod Modifier // one of Mod* constants or 0
13733+ Key Key // one of Key* constants, invalid if 'Ch' is not 0
13734+ Ch rune // a unicode character
13735+ Width int // width of the screen
13736+ Height int // height of the screen
13737+ Err error // error in case if input failed
13738+ MouseX int // x coord of mouse
13739+ MouseY int // y coord of mouse
13740+ N int // number of bytes written when getting a raw event
13741+ }
13742+
13743+ // A cell, single conceptual entity on the screen. The screen is basically a 2d
13744+ // array of cells. 'Ch' is a unicode character, 'Fg' and 'Bg' are foreground
13745+ // and background attributes respectively.
13746+ type Cell struct {
13747+ Ch rune
13748+ Fg Attribute
13749+ Bg Attribute
13750+ }
13751+
13752+ // To know if termbox has been initialized or not
13753+ var (
13754+ IsInit bool = false
13755+ )
13756+
13757+ // Key constants, see Event.Key field.
13758+ const (
13759+ KeyF1 Key = 0xFFFF - iota
13760+ KeyF2
13761+ KeyF3
13762+ KeyF4
13763+ KeyF5
13764+ KeyF6
13765+ KeyF7
13766+ KeyF8
13767+ KeyF9
13768+ KeyF10
13769+ KeyF11
13770+ KeyF12
13771+ KeyInsert
13772+ KeyDelete
13773+ KeyHome
13774+ KeyEnd
13775+ KeyPgup
13776+ KeyPgdn
13777+ KeyArrowUp
13778+ KeyArrowDown
13779+ KeyArrowLeft
13780+ KeyArrowRight
13781+ key_min // see terminfo
13782+ MouseLeft
13783+ MouseMiddle
13784+ MouseRight
13785+ MouseRelease
13786+ MouseWheelUp
13787+ MouseWheelDown
13788+ )
13789+
13790+ const (
13791+ KeyCtrlTilde Key = 0x00
13792+ KeyCtrl2 Key = 0x00
13793+ KeyCtrlSpace Key = 0x00
13794+ KeyCtrlA Key = 0x01
13795+ KeyCtrlB Key = 0x02
13796+ KeyCtrlC Key = 0x03
13797+ KeyCtrlD Key = 0x04
13798+ KeyCtrlE Key = 0x05
13799+ KeyCtrlF Key = 0x06
13800+ KeyCtrlG Key = 0x07
13801+ KeyBackspace Key = 0x08
13802+ KeyCtrlH Key = 0x08
13803+ KeyTab Key = 0x09
13804+ KeyCtrlI Key = 0x09
13805+ KeyCtrlJ Key = 0x0A
13806+ KeyCtrlK Key = 0x0B
13807+ KeyCtrlL Key = 0x0C
13808+ KeyEnter Key = 0x0D
13809+ KeyCtrlM Key = 0x0D
13810+ KeyCtrlN Key = 0x0E
13811+ KeyCtrlO Key = 0x0F
13812+ KeyCtrlP Key = 0x10
13813+ KeyCtrlQ Key = 0x11
13814+ KeyCtrlR Key = 0x12
13815+ KeyCtrlS Key = 0x13
13816+ KeyCtrlT Key = 0x14
13817+ KeyCtrlU Key = 0x15
13818+ KeyCtrlV Key = 0x16
13819+ KeyCtrlW Key = 0x17
13820+ KeyCtrlX Key = 0x18
13821+ KeyCtrlY Key = 0x19
13822+ KeyCtrlZ Key = 0x1A
13823+ KeyEsc Key = 0x1B
13824+ KeyCtrlLsqBracket Key = 0x1B
13825+ KeyCtrl3 Key = 0x1B
13826+ KeyCtrl4 Key = 0x1C
13827+ KeyCtrlBackslash Key = 0x1C
13828+ KeyCtrl5 Key = 0x1D
13829+ KeyCtrlRsqBracket Key = 0x1D
13830+ KeyCtrl6 Key = 0x1E
13831+ KeyCtrl7 Key = 0x1F
13832+ KeyCtrlSlash Key = 0x1F
13833+ KeyCtrlUnderscore Key = 0x1F
13834+ KeySpace Key = 0x20
13835+ KeyBackspace2 Key = 0x7F
13836+ KeyCtrl8 Key = 0x7F
13837+ )
13838+
13839+ // Alt modifier constant, see Event.Mod field and SetInputMode function.
13840+ const (
13841+ ModAlt Modifier = 1 << iota
13842+ ModMotion
13843+ )
13844+
13845+ // Cell colors, you can combine a color with multiple attributes using bitwise
13846+ // OR ('|').
13847+ const (
13848+ ColorDefault Attribute = iota
13849+ ColorBlack
13850+ ColorRed
13851+ ColorGreen
13852+ ColorYellow
13853+ ColorBlue
13854+ ColorMagenta
13855+ ColorCyan
13856+ ColorWhite
13857+ )
13858+
13859+ // Cell attributes, it is possible to use multiple attributes by combining them
13860+ // using bitwise OR ('|'). Although, colors cannot be combined. But you can
13861+ // combine attributes and a single color.
13862+ //
13863+ // It's worth mentioning that some platforms don't support certain attributes.
13864+ // For example windows console doesn't support AttrUnderline. And on some
13865+ // terminals applying AttrBold to background may result in blinking text. Use
13866+ // them with caution and test your code on various terminals.
13867+ const (
13868+ AttrBold Attribute = 1 << (iota + 9)
13869+ AttrUnderline
13870+ AttrReverse
13871+ )
13872+
13873+ // Input mode. See SetInputMode function.
13874+ const (
13875+ InputEsc InputMode = 1 << iota
13876+ InputAlt
13877+ InputMouse
13878+ InputCurrent InputMode = 0
13879+ )
13880+
13881+ // Output mode. See SetOutputMode function.
13882+ const (
13883+ OutputCurrent OutputMode = iota
13884+ OutputNormal
13885+ Output256
13886+ Output216
13887+ OutputGrayscale
13888+ )
13889+
13890+ // Event type. See Event.Type field.
13891+ const (
13892+ EventKey EventType = iota
13893+ EventResize
13894+ EventMouse
13895+ EventError
13896+ EventInterrupt
13897+ EventRaw
13898+ EventNone
13899+ )
13900 diff --git a/vendor/github.com/nsf/termbox-go/api_windows.go b/vendor/github.com/nsf/termbox-go/api_windows.go
13901new file mode 100644
13902index 0000000..7def30a
13903--- /dev/null
13904+++ b/vendor/github.com/nsf/termbox-go/api_windows.go
13905 @@ -0,0 +1,239 @@
13906+ package termbox
13907+
13908+ import (
13909+ "syscall"
13910+ )
13911+
13912+ // public API
13913+
13914+ // Initializes termbox library. This function should be called before any other functions.
13915+ // After successful initialization, the library must be finalized using 'Close' function.
13916+ //
13917+ // Example usage:
13918+ // err := termbox.Init()
13919+ // if err != nil {
13920+ // panic(err)
13921+ // }
13922+ // defer termbox.Close()
13923+ func Init() error {
13924+ var err error
13925+
13926+ interrupt, err = create_event()
13927+ if err != nil {
13928+ return err
13929+ }
13930+
13931+ in, err = syscall.Open("CONIN$", syscall.O_RDWR, 0)
13932+ if err != nil {
13933+ return err
13934+ }
13935+ out, err = syscall.Open("CONOUT$", syscall.O_RDWR, 0)
13936+ if err != nil {
13937+ return err
13938+ }
13939+
13940+ err = get_console_mode(in, &orig_mode)
13941+ if err != nil {
13942+ return err
13943+ }
13944+
13945+ err = set_console_mode(in, enable_window_input)
13946+ if err != nil {
13947+ return err
13948+ }
13949+
13950+ orig_size = get_term_size(out)
13951+ win_size := get_win_size(out)
13952+
13953+ err = set_console_screen_buffer_size(out, win_size)
13954+ if err != nil {
13955+ return err
13956+ }
13957+
13958+ err = get_console_cursor_info(out, &orig_cursor_info)
13959+ if err != nil {
13960+ return err
13961+ }
13962+
13963+ show_cursor(false)
13964+ term_size = get_term_size(out)
13965+ back_buffer.init(int(term_size.x), int(term_size.y))
13966+ front_buffer.init(int(term_size.x), int(term_size.y))
13967+ back_buffer.clear()
13968+ front_buffer.clear()
13969+ clear()
13970+
13971+ diffbuf = make([]diff_msg, 0, 32)
13972+
13973+ go input_event_producer()
13974+ IsInit = true
13975+ return nil
13976+ }
13977+
13978+ // Finalizes termbox library, should be called after successful initialization
13979+ // when termbox's functionality isn't required anymore.
13980+ func Close() {
13981+ // we ignore errors here, because we can't really do anything about them
13982+ Clear(0, 0)
13983+ Flush()
13984+
13985+ // stop event producer
13986+ cancel_comm <- true
13987+ set_event(interrupt)
13988+ select {
13989+ case <-input_comm:
13990+ default:
13991+ }
13992+ <-cancel_done_comm
13993+
13994+ set_console_cursor_info(out, &orig_cursor_info)
13995+ set_console_cursor_position(out, coord{})
13996+ set_console_screen_buffer_size(out, orig_size)
13997+ set_console_mode(in, orig_mode)
13998+ syscall.Close(in)
13999+ syscall.Close(out)
14000+ syscall.Close(interrupt)
14001+ IsInit = false
14002+ }
14003+
14004+ // Interrupt an in-progress call to PollEvent by causing it to return
14005+ // EventInterrupt. Note that this function will block until the PollEvent
14006+ // function has successfully been interrupted.
14007+ func Interrupt() {
14008+ interrupt_comm <- struct{}{}
14009+ }
14010+
14011+ // Synchronizes the internal back buffer with the terminal.
14012+ func Flush() error {
14013+ update_size_maybe()
14014+ prepare_diff_messages()
14015+ for _, diff := range diffbuf {
14016+ r := small_rect{
14017+ left: 0,
14018+ top: diff.pos,
14019+ right: term_size.x - 1,
14020+ bottom: diff.pos + diff.lines - 1,
14021+ }
14022+ write_console_output(out, diff.chars, r)
14023+ }
14024+ if !is_cursor_hidden(cursor_x, cursor_y) {
14025+ move_cursor(cursor_x, cursor_y)
14026+ }
14027+ return nil
14028+ }
14029+
14030+ // Sets the position of the cursor. See also HideCursor().
14031+ func SetCursor(x, y int) {
14032+ if is_cursor_hidden(cursor_x, cursor_y) && !is_cursor_hidden(x, y) {
14033+ show_cursor(true)
14034+ }
14035+
14036+ if !is_cursor_hidden(cursor_x, cursor_y) && is_cursor_hidden(x, y) {
14037+ show_cursor(false)
14038+ }
14039+
14040+ cursor_x, cursor_y = x, y
14041+ if !is_cursor_hidden(cursor_x, cursor_y) {
14042+ move_cursor(cursor_x, cursor_y)
14043+ }
14044+ }
14045+
14046+ // The shortcut for SetCursor(-1, -1).
14047+ func HideCursor() {
14048+ SetCursor(cursor_hidden, cursor_hidden)
14049+ }
14050+
14051+ // Changes cell's parameters in the internal back buffer at the specified
14052+ // position.
14053+ func SetCell(x, y int, ch rune, fg, bg Attribute) {
14054+ if x < 0 || x >= back_buffer.width {
14055+ return
14056+ }
14057+ if y < 0 || y >= back_buffer.height {
14058+ return
14059+ }
14060+
14061+ back_buffer.cells[y*back_buffer.width+x] = Cell{ch, fg, bg}
14062+ }
14063+
14064+ // Returns a slice into the termbox's back buffer. You can get its dimensions
14065+ // using 'Size' function. The slice remains valid as long as no 'Clear' or
14066+ // 'Flush' function calls were made after call to this function.
14067+ func CellBuffer() []Cell {
14068+ return back_buffer.cells
14069+ }
14070+
14071+ // Wait for an event and return it. This is a blocking function call.
14072+ func PollEvent() Event {
14073+ select {
14074+ case ev := <-input_comm:
14075+ return ev
14076+ case <-interrupt_comm:
14077+ return Event{Type: EventInterrupt}
14078+ }
14079+ }
14080+
14081+ // Returns the size of the internal back buffer (which is mostly the same as
14082+ // console's window size in characters). But it doesn't always match the size
14083+ // of the console window, after the console size has changed, the internal back
14084+ // buffer will get in sync only after Clear or Flush function calls.
14085+ func Size() (int, int) {
14086+ return int(term_size.x), int(term_size.y)
14087+ }
14088+
14089+ // Clears the internal back buffer.
14090+ func Clear(fg, bg Attribute) error {
14091+ foreground, background = fg, bg
14092+ update_size_maybe()
14093+ back_buffer.clear()
14094+ return nil
14095+ }
14096+
14097+ // Sets termbox input mode. Termbox has two input modes:
14098+ //
14099+ // 1. Esc input mode. When ESC sequence is in the buffer and it doesn't match
14100+ // any known sequence. ESC means KeyEsc. This is the default input mode.
14101+ //
14102+ // 2. Alt input mode. When ESC sequence is in the buffer and it doesn't match
14103+ // any known sequence. ESC enables ModAlt modifier for the next keyboard event.
14104+ //
14105+ // Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will
14106+ // enable mouse button press/release and drag events.
14107+ //
14108+ // If 'mode' is InputCurrent, returns the current input mode. See also Input*
14109+ // constants.
14110+ func SetInputMode(mode InputMode) InputMode {
14111+ if mode == InputCurrent {
14112+ return input_mode
14113+ }
14114+ if mode&InputMouse != 0 {
14115+ err := set_console_mode(in, enable_window_input|enable_mouse_input|enable_extended_flags)
14116+ if err != nil {
14117+ panic(err)
14118+ }
14119+ } else {
14120+ err := set_console_mode(in, enable_window_input)
14121+ if err != nil {
14122+ panic(err)
14123+ }
14124+ }
14125+
14126+ input_mode = mode
14127+ return input_mode
14128+ }
14129+
14130+ // Sets the termbox output mode.
14131+ //
14132+ // Windows console does not support extra colour modes,
14133+ // so this will always set and return OutputNormal.
14134+ func SetOutputMode(mode OutputMode) OutputMode {
14135+ return OutputNormal
14136+ }
14137+
14138+ // Sync comes handy when something causes desync between termbox's understanding
14139+ // of a terminal buffer and the reality. Such as a third party process. Sync
14140+ // forces a complete resync between the termbox and a terminal, it may not be
14141+ // visually pretty though. At the moment on Windows it does nothing.
14142+ func Sync() error {
14143+ return nil
14144+ }
14145 diff --git a/vendor/github.com/nsf/termbox-go/collect_terminfo.py b/vendor/github.com/nsf/termbox-go/collect_terminfo.py
14146new file mode 100755
14147index 0000000..5e50975
14148--- /dev/null
14149+++ b/vendor/github.com/nsf/termbox-go/collect_terminfo.py
14150 @@ -0,0 +1,110 @@
14151+ #!/usr/bin/env python
14152+
14153+ import sys, os, subprocess
14154+
14155+ def escaped(s):
14156+ return repr(s)[1:-1]
14157+
14158+ def tput(term, name):
14159+ try:
14160+ return subprocess.check_output(['tput', '-T%s' % term, name]).decode()
14161+ except subprocess.CalledProcessError as e:
14162+ return e.output.decode()
14163+
14164+
14165+ def w(s):
14166+ if s == None:
14167+ return
14168+ sys.stdout.write(s)
14169+
14170+ terminals = {
14171+ 'xterm' : 'xterm',
14172+ 'rxvt-256color' : 'rxvt_256color',
14173+ 'rxvt-unicode' : 'rxvt_unicode',
14174+ 'linux' : 'linux',
14175+ 'Eterm' : 'eterm',
14176+ 'screen' : 'screen'
14177+ }
14178+
14179+ keys = [
14180+ "F1", "kf1",
14181+ "F2", "kf2",
14182+ "F3", "kf3",
14183+ "F4", "kf4",
14184+ "F5", "kf5",
14185+ "F6", "kf6",
14186+ "F7", "kf7",
14187+ "F8", "kf8",
14188+ "F9", "kf9",
14189+ "F10", "kf10",
14190+ "F11", "kf11",
14191+ "F12", "kf12",
14192+ "INSERT", "kich1",
14193+ "DELETE", "kdch1",
14194+ "HOME", "khome",
14195+ "END", "kend",
14196+ "PGUP", "kpp",
14197+ "PGDN", "knp",
14198+ "KEY_UP", "kcuu1",
14199+ "KEY_DOWN", "kcud1",
14200+ "KEY_LEFT", "kcub1",
14201+ "KEY_RIGHT", "kcuf1"
14202+ ]
14203+
14204+ funcs = [
14205+ "T_ENTER_CA", "smcup",
14206+ "T_EXIT_CA", "rmcup",
14207+ "T_SHOW_CURSOR", "cnorm",
14208+ "T_HIDE_CURSOR", "civis",
14209+ "T_CLEAR_SCREEN", "clear",
14210+ "T_SGR0", "sgr0",
14211+ "T_UNDERLINE", "smul",
14212+ "T_BOLD", "bold",
14213+ "T_BLINK", "blink",
14214+ "T_REVERSE", "rev",
14215+ "T_ENTER_KEYPAD", "smkx",
14216+ "T_EXIT_KEYPAD", "rmkx"
14217+ ]
14218+
14219+ def iter_pairs(iterable):
14220+ iterable = iter(iterable)
14221+ while True:
14222+ yield (next(iterable), next(iterable))
14223+
14224+ def do_term(term, nick):
14225+ w("// %s\n" % term)
14226+ w("var %s_keys = []string{\n\t" % nick)
14227+ for k, v in iter_pairs(keys):
14228+ w('"')
14229+ w(escaped(tput(term, v)))
14230+ w('",')
14231+ w("\n}\n")
14232+ w("var %s_funcs = []string{\n\t" % nick)
14233+ for k,v in iter_pairs(funcs):
14234+ w('"')
14235+ if v == "sgr":
14236+ w("\\033[3%d;4%dm")
14237+ elif v == "cup":
14238+ w("\\033[%d;%dH")
14239+ else:
14240+ w(escaped(tput(term, v)))
14241+ w('", ')
14242+ w("\n}\n\n")
14243+
14244+ def do_terms(d):
14245+ w("var terms = []struct {\n")
14246+ w("\tname string\n")
14247+ w("\tkeys []string\n")
14248+ w("\tfuncs []string\n")
14249+ w("}{\n")
14250+ for k, v in d.items():
14251+ w('\t{"%s", %s_keys, %s_funcs},\n' % (k, v, v))
14252+ w("}\n\n")
14253+
14254+ w("// +build !windows\n\npackage termbox\n\n")
14255+
14256+ for k,v in terminals.items():
14257+ do_term(k, v)
14258+
14259+ do_terms(terminals)
14260+
14261 diff --git a/vendor/github.com/nsf/termbox-go/escwait.go b/vendor/github.com/nsf/termbox-go/escwait.go
14262new file mode 100644
14263index 0000000..b7bbb89
14264--- /dev/null
14265+++ b/vendor/github.com/nsf/termbox-go/escwait.go
14266 @@ -0,0 +1,11 @@
14267+ // +build !darwin
14268+
14269+ package termbox
14270+
14271+ // On all systems other than macOS, disable behavior which will wait before
14272+ // deciding that the escape key was pressed, to account for partially send
14273+ // escape sequences, especially with regard to lengthy mouse sequences.
14274+ // See https://github.com/nsf/termbox-go/issues/132
14275+ func enable_wait_for_escape_sequence() bool {
14276+ return false
14277+ }
14278 diff --git a/vendor/github.com/nsf/termbox-go/escwait_darwin.go b/vendor/github.com/nsf/termbox-go/escwait_darwin.go
14279new file mode 100644
14280index 0000000..dde69b6
14281--- /dev/null
14282+++ b/vendor/github.com/nsf/termbox-go/escwait_darwin.go
14283 @@ -0,0 +1,9 @@
14284+ package termbox
14285+
14286+ // On macOS, enable behavior which will wait before deciding that the escape
14287+ // key was pressed, to account for partially send escape sequences, especially
14288+ // with regard to lengthy mouse sequences.
14289+ // See https://github.com/nsf/termbox-go/issues/132
14290+ func enable_wait_for_escape_sequence() bool {
14291+ return true
14292+ }
14293 diff --git a/vendor/github.com/nsf/termbox-go/syscalls.go b/vendor/github.com/nsf/termbox-go/syscalls.go
14294new file mode 100644
14295index 0000000..4f52bb9
14296--- /dev/null
14297+++ b/vendor/github.com/nsf/termbox-go/syscalls.go
14298 @@ -0,0 +1,39 @@
14299+ // +build ignore
14300+
14301+ package termbox
14302+
14303+ /*
14304+ #include <termios.h>
14305+ #include <sys/ioctl.h>
14306+ */
14307+ import "C"
14308+
14309+ type syscall_Termios C.struct_termios
14310+
14311+ const (
14312+ syscall_IGNBRK = C.IGNBRK
14313+ syscall_BRKINT = C.BRKINT
14314+ syscall_PARMRK = C.PARMRK
14315+ syscall_ISTRIP = C.ISTRIP
14316+ syscall_INLCR = C.INLCR
14317+ syscall_IGNCR = C.IGNCR
14318+ syscall_ICRNL = C.ICRNL
14319+ syscall_IXON = C.IXON
14320+ syscall_OPOST = C.OPOST
14321+ syscall_ECHO = C.ECHO
14322+ syscall_ECHONL = C.ECHONL
14323+ syscall_ICANON = C.ICANON
14324+ syscall_ISIG = C.ISIG
14325+ syscall_IEXTEN = C.IEXTEN
14326+ syscall_CSIZE = C.CSIZE
14327+ syscall_PARENB = C.PARENB
14328+ syscall_CS8 = C.CS8
14329+ syscall_VMIN = C.VMIN
14330+ syscall_VTIME = C.VTIME
14331+
14332+ // on darwin change these to (on *bsd too?):
14333+ // C.TIOCGETA
14334+ // C.TIOCSETA
14335+ syscall_TCGETS = C.TCGETS
14336+ syscall_TCSETS = C.TCSETS
14337+ )
14338 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_darwin.go b/vendor/github.com/nsf/termbox-go/syscalls_darwin.go
14339new file mode 100644
14340index 0000000..25b78f7
14341--- /dev/null
14342+++ b/vendor/github.com/nsf/termbox-go/syscalls_darwin.go
14343 @@ -0,0 +1,41 @@
14344+ // Created by cgo -godefs - DO NOT EDIT
14345+ // cgo -godefs syscalls.go
14346+
14347+ // +build !amd64
14348+
14349+ package termbox
14350+
14351+ type syscall_Termios struct {
14352+ Iflag uint32
14353+ Oflag uint32
14354+ Cflag uint32
14355+ Lflag uint32
14356+ Cc [20]uint8
14357+ Ispeed uint32
14358+ Ospeed uint32
14359+ }
14360+
14361+ const (
14362+ syscall_IGNBRK = 0x1
14363+ syscall_BRKINT = 0x2
14364+ syscall_PARMRK = 0x8
14365+ syscall_ISTRIP = 0x20
14366+ syscall_INLCR = 0x40
14367+ syscall_IGNCR = 0x80
14368+ syscall_ICRNL = 0x100
14369+ syscall_IXON = 0x200
14370+ syscall_OPOST = 0x1
14371+ syscall_ECHO = 0x8
14372+ syscall_ECHONL = 0x10
14373+ syscall_ICANON = 0x100
14374+ syscall_ISIG = 0x80
14375+ syscall_IEXTEN = 0x400
14376+ syscall_CSIZE = 0x300
14377+ syscall_PARENB = 0x1000
14378+ syscall_CS8 = 0x300
14379+ syscall_VMIN = 0x10
14380+ syscall_VTIME = 0x11
14381+
14382+ syscall_TCGETS = 0x402c7413
14383+ syscall_TCSETS = 0x802c7414
14384+ )
14385 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_darwin_amd64.go b/vendor/github.com/nsf/termbox-go/syscalls_darwin_amd64.go
14386new file mode 100644
14387index 0000000..11f25be
14388--- /dev/null
14389+++ b/vendor/github.com/nsf/termbox-go/syscalls_darwin_amd64.go
14390 @@ -0,0 +1,40 @@
14391+ // Created by cgo -godefs - DO NOT EDIT
14392+ // cgo -godefs syscalls.go
14393+
14394+ package termbox
14395+
14396+ type syscall_Termios struct {
14397+ Iflag uint64
14398+ Oflag uint64
14399+ Cflag uint64
14400+ Lflag uint64
14401+ Cc [20]uint8
14402+ Pad_cgo_0 [4]byte
14403+ Ispeed uint64
14404+ Ospeed uint64
14405+ }
14406+
14407+ const (
14408+ syscall_IGNBRK = 0x1
14409+ syscall_BRKINT = 0x2
14410+ syscall_PARMRK = 0x8
14411+ syscall_ISTRIP = 0x20
14412+ syscall_INLCR = 0x40
14413+ syscall_IGNCR = 0x80
14414+ syscall_ICRNL = 0x100
14415+ syscall_IXON = 0x200
14416+ syscall_OPOST = 0x1
14417+ syscall_ECHO = 0x8
14418+ syscall_ECHONL = 0x10
14419+ syscall_ICANON = 0x100
14420+ syscall_ISIG = 0x80
14421+ syscall_IEXTEN = 0x400
14422+ syscall_CSIZE = 0x300
14423+ syscall_PARENB = 0x1000
14424+ syscall_CS8 = 0x300
14425+ syscall_VMIN = 0x10
14426+ syscall_VTIME = 0x11
14427+
14428+ syscall_TCGETS = 0x40487413
14429+ syscall_TCSETS = 0x80487414
14430+ )
14431 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_dragonfly.go b/vendor/github.com/nsf/termbox-go/syscalls_dragonfly.go
14432new file mode 100644
14433index 0000000..e03624e
14434--- /dev/null
14435+++ b/vendor/github.com/nsf/termbox-go/syscalls_dragonfly.go
14436 @@ -0,0 +1,39 @@
14437+ // Created by cgo -godefs - DO NOT EDIT
14438+ // cgo -godefs syscalls.go
14439+
14440+ package termbox
14441+
14442+ type syscall_Termios struct {
14443+ Iflag uint32
14444+ Oflag uint32
14445+ Cflag uint32
14446+ Lflag uint32
14447+ Cc [20]uint8
14448+ Ispeed uint32
14449+ Ospeed uint32
14450+ }
14451+
14452+ const (
14453+ syscall_IGNBRK = 0x1
14454+ syscall_BRKINT = 0x2
14455+ syscall_PARMRK = 0x8
14456+ syscall_ISTRIP = 0x20
14457+ syscall_INLCR = 0x40
14458+ syscall_IGNCR = 0x80
14459+ syscall_ICRNL = 0x100
14460+ syscall_IXON = 0x200
14461+ syscall_OPOST = 0x1
14462+ syscall_ECHO = 0x8
14463+ syscall_ECHONL = 0x10
14464+ syscall_ICANON = 0x100
14465+ syscall_ISIG = 0x80
14466+ syscall_IEXTEN = 0x400
14467+ syscall_CSIZE = 0x300
14468+ syscall_PARENB = 0x1000
14469+ syscall_CS8 = 0x300
14470+ syscall_VMIN = 0x10
14471+ syscall_VTIME = 0x11
14472+
14473+ syscall_TCGETS = 0x402c7413
14474+ syscall_TCSETS = 0x802c7414
14475+ )
14476 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_freebsd.go b/vendor/github.com/nsf/termbox-go/syscalls_freebsd.go
14477new file mode 100644
14478index 0000000..e03624e
14479--- /dev/null
14480+++ b/vendor/github.com/nsf/termbox-go/syscalls_freebsd.go
14481 @@ -0,0 +1,39 @@
14482+ // Created by cgo -godefs - DO NOT EDIT
14483+ // cgo -godefs syscalls.go
14484+
14485+ package termbox
14486+
14487+ type syscall_Termios struct {
14488+ Iflag uint32
14489+ Oflag uint32
14490+ Cflag uint32
14491+ Lflag uint32
14492+ Cc [20]uint8
14493+ Ispeed uint32
14494+ Ospeed uint32
14495+ }
14496+
14497+ const (
14498+ syscall_IGNBRK = 0x1
14499+ syscall_BRKINT = 0x2
14500+ syscall_PARMRK = 0x8
14501+ syscall_ISTRIP = 0x20
14502+ syscall_INLCR = 0x40
14503+ syscall_IGNCR = 0x80
14504+ syscall_ICRNL = 0x100
14505+ syscall_IXON = 0x200
14506+ syscall_OPOST = 0x1
14507+ syscall_ECHO = 0x8
14508+ syscall_ECHONL = 0x10
14509+ syscall_ICANON = 0x100
14510+ syscall_ISIG = 0x80
14511+ syscall_IEXTEN = 0x400
14512+ syscall_CSIZE = 0x300
14513+ syscall_PARENB = 0x1000
14514+ syscall_CS8 = 0x300
14515+ syscall_VMIN = 0x10
14516+ syscall_VTIME = 0x11
14517+
14518+ syscall_TCGETS = 0x402c7413
14519+ syscall_TCSETS = 0x802c7414
14520+ )
14521 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_linux.go b/vendor/github.com/nsf/termbox-go/syscalls_linux.go
14522new file mode 100644
14523index 0000000..b88960d
14524--- /dev/null
14525+++ b/vendor/github.com/nsf/termbox-go/syscalls_linux.go
14526 @@ -0,0 +1,33 @@
14527+ // Created by cgo -godefs - DO NOT EDIT
14528+ // cgo -godefs syscalls.go
14529+
14530+ package termbox
14531+
14532+ import "syscall"
14533+
14534+ type syscall_Termios syscall.Termios
14535+
14536+ const (
14537+ syscall_IGNBRK = syscall.IGNBRK
14538+ syscall_BRKINT = syscall.BRKINT
14539+ syscall_PARMRK = syscall.PARMRK
14540+ syscall_ISTRIP = syscall.ISTRIP
14541+ syscall_INLCR = syscall.INLCR
14542+ syscall_IGNCR = syscall.IGNCR
14543+ syscall_ICRNL = syscall.ICRNL
14544+ syscall_IXON = syscall.IXON
14545+ syscall_OPOST = syscall.OPOST
14546+ syscall_ECHO = syscall.ECHO
14547+ syscall_ECHONL = syscall.ECHONL
14548+ syscall_ICANON = syscall.ICANON
14549+ syscall_ISIG = syscall.ISIG
14550+ syscall_IEXTEN = syscall.IEXTEN
14551+ syscall_CSIZE = syscall.CSIZE
14552+ syscall_PARENB = syscall.PARENB
14553+ syscall_CS8 = syscall.CS8
14554+ syscall_VMIN = syscall.VMIN
14555+ syscall_VTIME = syscall.VTIME
14556+
14557+ syscall_TCGETS = syscall.TCGETS
14558+ syscall_TCSETS = syscall.TCSETS
14559+ )
14560 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_netbsd.go b/vendor/github.com/nsf/termbox-go/syscalls_netbsd.go
14561new file mode 100644
14562index 0000000..49a3355
14563--- /dev/null
14564+++ b/vendor/github.com/nsf/termbox-go/syscalls_netbsd.go
14565 @@ -0,0 +1,39 @@
14566+ // Created by cgo -godefs - DO NOT EDIT
14567+ // cgo -godefs syscalls.go
14568+
14569+ package termbox
14570+
14571+ type syscall_Termios struct {
14572+ Iflag uint32
14573+ Oflag uint32
14574+ Cflag uint32
14575+ Lflag uint32
14576+ Cc [20]uint8
14577+ Ispeed int32
14578+ Ospeed int32
14579+ }
14580+
14581+ const (
14582+ syscall_IGNBRK = 0x1
14583+ syscall_BRKINT = 0x2
14584+ syscall_PARMRK = 0x8
14585+ syscall_ISTRIP = 0x20
14586+ syscall_INLCR = 0x40
14587+ syscall_IGNCR = 0x80
14588+ syscall_ICRNL = 0x100
14589+ syscall_IXON = 0x200
14590+ syscall_OPOST = 0x1
14591+ syscall_ECHO = 0x8
14592+ syscall_ECHONL = 0x10
14593+ syscall_ICANON = 0x100
14594+ syscall_ISIG = 0x80
14595+ syscall_IEXTEN = 0x400
14596+ syscall_CSIZE = 0x300
14597+ syscall_PARENB = 0x1000
14598+ syscall_CS8 = 0x300
14599+ syscall_VMIN = 0x10
14600+ syscall_VTIME = 0x11
14601+
14602+ syscall_TCGETS = 0x402c7413
14603+ syscall_TCSETS = 0x802c7414
14604+ )
14605 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_openbsd.go b/vendor/github.com/nsf/termbox-go/syscalls_openbsd.go
14606new file mode 100644
14607index 0000000..49a3355
14608--- /dev/null
14609+++ b/vendor/github.com/nsf/termbox-go/syscalls_openbsd.go
14610 @@ -0,0 +1,39 @@
14611+ // Created by cgo -godefs - DO NOT EDIT
14612+ // cgo -godefs syscalls.go
14613+
14614+ package termbox
14615+
14616+ type syscall_Termios struct {
14617+ Iflag uint32
14618+ Oflag uint32
14619+ Cflag uint32
14620+ Lflag uint32
14621+ Cc [20]uint8
14622+ Ispeed int32
14623+ Ospeed int32
14624+ }
14625+
14626+ const (
14627+ syscall_IGNBRK = 0x1
14628+ syscall_BRKINT = 0x2
14629+ syscall_PARMRK = 0x8
14630+ syscall_ISTRIP = 0x20
14631+ syscall_INLCR = 0x40
14632+ syscall_IGNCR = 0x80
14633+ syscall_ICRNL = 0x100
14634+ syscall_IXON = 0x200
14635+ syscall_OPOST = 0x1
14636+ syscall_ECHO = 0x8
14637+ syscall_ECHONL = 0x10
14638+ syscall_ICANON = 0x100
14639+ syscall_ISIG = 0x80
14640+ syscall_IEXTEN = 0x400
14641+ syscall_CSIZE = 0x300
14642+ syscall_PARENB = 0x1000
14643+ syscall_CS8 = 0x300
14644+ syscall_VMIN = 0x10
14645+ syscall_VTIME = 0x11
14646+
14647+ syscall_TCGETS = 0x402c7413
14648+ syscall_TCSETS = 0x802c7414
14649+ )
14650 diff --git a/vendor/github.com/nsf/termbox-go/syscalls_windows.go b/vendor/github.com/nsf/termbox-go/syscalls_windows.go
14651new file mode 100644
14652index 0000000..472d002
14653--- /dev/null
14654+++ b/vendor/github.com/nsf/termbox-go/syscalls_windows.go
14655 @@ -0,0 +1,61 @@
14656+ // Created by cgo -godefs - DO NOT EDIT
14657+ // cgo -godefs -- -DUNICODE syscalls.go
14658+
14659+ package termbox
14660+
14661+ const (
14662+ foreground_blue = 0x1
14663+ foreground_green = 0x2
14664+ foreground_red = 0x4
14665+ foreground_intensity = 0x8
14666+ background_blue = 0x10
14667+ background_green = 0x20
14668+ background_red = 0x40
14669+ background_intensity = 0x80
14670+ std_input_handle = -0xa
14671+ std_output_handle = -0xb
14672+ key_event = 0x1
14673+ mouse_event = 0x2
14674+ window_buffer_size_event = 0x4
14675+ enable_window_input = 0x8
14676+ enable_mouse_input = 0x10
14677+ enable_extended_flags = 0x80
14678+
14679+ vk_f1 = 0x70
14680+ vk_f2 = 0x71
14681+ vk_f3 = 0x72
14682+ vk_f4 = 0x73
14683+ vk_f5 = 0x74
14684+ vk_f6 = 0x75
14685+ vk_f7 = 0x76
14686+ vk_f8 = 0x77
14687+ vk_f9 = 0x78
14688+ vk_f10 = 0x79
14689+ vk_f11 = 0x7a
14690+ vk_f12 = 0x7b
14691+ vk_insert = 0x2d
14692+ vk_delete = 0x2e
14693+ vk_home = 0x24
14694+ vk_end = 0x23
14695+ vk_pgup = 0x21
14696+ vk_pgdn = 0x22
14697+ vk_arrow_up = 0x26
14698+ vk_arrow_down = 0x28
14699+ vk_arrow_left = 0x25
14700+ vk_arrow_right = 0x27
14701+ vk_backspace = 0x8
14702+ vk_tab = 0x9
14703+ vk_enter = 0xd
14704+ vk_esc = 0x1b
14705+ vk_space = 0x20
14706+
14707+ left_alt_pressed = 0x2
14708+ left_ctrl_pressed = 0x8
14709+ right_alt_pressed = 0x1
14710+ right_ctrl_pressed = 0x4
14711+ shift_pressed = 0x10
14712+
14713+ generic_read = 0x80000000
14714+ generic_write = 0x40000000
14715+ console_textmode_buffer = 0x1
14716+ )
14717 diff --git a/vendor/github.com/nsf/termbox-go/termbox.go b/vendor/github.com/nsf/termbox-go/termbox.go
14718new file mode 100644
14719index 0000000..fbe4c3d
14720--- /dev/null
14721+++ b/vendor/github.com/nsf/termbox-go/termbox.go
14722 @@ -0,0 +1,529 @@
14723+ // +build !windows
14724+
14725+ package termbox
14726+
14727+ import "unicode/utf8"
14728+ import "bytes"
14729+ import "syscall"
14730+ import "unsafe"
14731+ import "strings"
14732+ import "strconv"
14733+ import "os"
14734+ import "io"
14735+
14736+ // private API
14737+
14738+ const (
14739+ t_enter_ca = iota
14740+ t_exit_ca
14741+ t_show_cursor
14742+ t_hide_cursor
14743+ t_clear_screen
14744+ t_sgr0
14745+ t_underline
14746+ t_bold
14747+ t_blink
14748+ t_reverse
14749+ t_enter_keypad
14750+ t_exit_keypad
14751+ t_enter_mouse
14752+ t_exit_mouse
14753+ t_max_funcs
14754+ )
14755+
14756+ const (
14757+ coord_invalid = -2
14758+ attr_invalid = Attribute(0xFFFF)
14759+ )
14760+
14761+ type input_event struct {
14762+ data []byte
14763+ err error
14764+ }
14765+
14766+ type extract_event_res int
14767+
14768+ const (
14769+ event_not_extracted extract_event_res = iota
14770+ event_extracted
14771+ esc_wait
14772+ )
14773+
14774+ var (
14775+ // term specific sequences
14776+ keys []string
14777+ funcs []string
14778+
14779+ // termbox inner state
14780+ orig_tios syscall_Termios
14781+ back_buffer cellbuf
14782+ front_buffer cellbuf
14783+ termw int
14784+ termh int
14785+ input_mode = InputEsc
14786+ output_mode = OutputNormal
14787+ out *os.File
14788+ in int
14789+ lastfg = attr_invalid
14790+ lastbg = attr_invalid
14791+ lastx = coord_invalid
14792+ lasty = coord_invalid
14793+ cursor_x = cursor_hidden
14794+ cursor_y = cursor_hidden
14795+ foreground = ColorDefault
14796+ background = ColorDefault
14797+ inbuf = make([]byte, 0, 64)
14798+ outbuf bytes.Buffer
14799+ sigwinch = make(chan os.Signal, 1)
14800+ sigio = make(chan os.Signal, 1)
14801+ quit = make(chan int)
14802+ input_comm = make(chan input_event)
14803+ interrupt_comm = make(chan struct{})
14804+ intbuf = make([]byte, 0, 16)
14805+
14806+ // grayscale indexes
14807+ grayscale = []Attribute{
14808+ 0, 17, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
14809+ 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 232,
14810+ }
14811+ )
14812+
14813+ func write_cursor(x, y int) {
14814+ outbuf.WriteString("\033[")
14815+ outbuf.Write(strconv.AppendUint(intbuf, uint64(y+1), 10))
14816+ outbuf.WriteString(";")
14817+ outbuf.Write(strconv.AppendUint(intbuf, uint64(x+1), 10))
14818+ outbuf.WriteString("H")
14819+ }
14820+
14821+ func write_sgr_fg(a Attribute) {
14822+ switch output_mode {
14823+ case Output256, Output216, OutputGrayscale:
14824+ outbuf.WriteString("\033[38;5;")
14825+ outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
14826+ outbuf.WriteString("m")
14827+ default:
14828+ outbuf.WriteString("\033[3")
14829+ outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
14830+ outbuf.WriteString("m")
14831+ }
14832+ }
14833+
14834+ func write_sgr_bg(a Attribute) {
14835+ switch output_mode {
14836+ case Output256, Output216, OutputGrayscale:
14837+ outbuf.WriteString("\033[48;5;")
14838+ outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
14839+ outbuf.WriteString("m")
14840+ default:
14841+ outbuf.WriteString("\033[4")
14842+ outbuf.Write(strconv.AppendUint(intbuf, uint64(a-1), 10))
14843+ outbuf.WriteString("m")
14844+ }
14845+ }
14846+
14847+ func write_sgr(fg, bg Attribute) {
14848+ switch output_mode {
14849+ case Output256, Output216, OutputGrayscale:
14850+ outbuf.WriteString("\033[38;5;")
14851+ outbuf.Write(strconv.AppendUint(intbuf, uint64(fg-1), 10))
14852+ outbuf.WriteString("m")
14853+ outbuf.WriteString("\033[48;5;")
14854+ outbuf.Write(strconv.AppendUint(intbuf, uint64(bg-1), 10))
14855+ outbuf.WriteString("m")
14856+ default:
14857+ outbuf.WriteString("\033[3")
14858+ outbuf.Write(strconv.AppendUint(intbuf, uint64(fg-1), 10))
14859+ outbuf.WriteString(";4")
14860+ outbuf.Write(strconv.AppendUint(intbuf, uint64(bg-1), 10))
14861+ outbuf.WriteString("m")
14862+ }
14863+ }
14864+
14865+ type winsize struct {
14866+ rows uint16
14867+ cols uint16
14868+ xpixels uint16
14869+ ypixels uint16
14870+ }
14871+
14872+ func get_term_size(fd uintptr) (int, int) {
14873+ var sz winsize
14874+ _, _, _ = syscall.Syscall(syscall.SYS_IOCTL,
14875+ fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&sz)))
14876+ return int(sz.cols), int(sz.rows)
14877+ }
14878+
14879+ func send_attr(fg, bg Attribute) {
14880+ if fg == lastfg && bg == lastbg {
14881+ return
14882+ }
14883+
14884+ outbuf.WriteString(funcs[t_sgr0])
14885+
14886+ var fgcol, bgcol Attribute
14887+
14888+ switch output_mode {
14889+ case Output256:
14890+ fgcol = fg & 0x1FF
14891+ bgcol = bg & 0x1FF
14892+ case Output216:
14893+ fgcol = fg & 0xFF
14894+ bgcol = bg & 0xFF
14895+ if fgcol > 216 {
14896+ fgcol = ColorDefault
14897+ }
14898+ if bgcol > 216 {
14899+ bgcol = ColorDefault
14900+ }
14901+ if fgcol != ColorDefault {
14902+ fgcol += 0x10
14903+ }
14904+ if bgcol != ColorDefault {
14905+ bgcol += 0x10
14906+ }
14907+ case OutputGrayscale:
14908+ fgcol = fg & 0x1F
14909+ bgcol = bg & 0x1F
14910+ if fgcol > 26 {
14911+ fgcol = ColorDefault
14912+ }
14913+ if bgcol > 26 {
14914+ bgcol = ColorDefault
14915+ }
14916+ if fgcol != ColorDefault {
14917+ fgcol = grayscale[fgcol]
14918+ }
14919+ if bgcol != ColorDefault {
14920+ bgcol = grayscale[bgcol]
14921+ }
14922+ default:
14923+ fgcol = fg & 0x0F
14924+ bgcol = bg & 0x0F
14925+ }
14926+
14927+ if fgcol != ColorDefault {
14928+ if bgcol != ColorDefault {
14929+ write_sgr(fgcol, bgcol)
14930+ } else {
14931+ write_sgr_fg(fgcol)
14932+ }
14933+ } else if bgcol != ColorDefault {
14934+ write_sgr_bg(bgcol)
14935+ }
14936+
14937+ if fg&AttrBold != 0 {
14938+ outbuf.WriteString(funcs[t_bold])
14939+ }
14940+ if bg&AttrBold != 0 {
14941+ outbuf.WriteString(funcs[t_blink])
14942+ }
14943+ if fg&AttrUnderline != 0 {
14944+ outbuf.WriteString(funcs[t_underline])
14945+ }
14946+ if fg&AttrReverse|bg&AttrReverse != 0 {
14947+ outbuf.WriteString(funcs[t_reverse])
14948+ }
14949+
14950+ lastfg, lastbg = fg, bg
14951+ }
14952+
14953+ func send_char(x, y int, ch rune) {
14954+ var buf [8]byte
14955+ n := utf8.EncodeRune(buf[:], ch)
14956+ if x-1 != lastx || y != lasty {
14957+ write_cursor(x, y)
14958+ }
14959+ lastx, lasty = x, y
14960+ outbuf.Write(buf[:n])
14961+ }
14962+
14963+ func flush() error {
14964+ _, err := io.Copy(out, &outbuf)
14965+ outbuf.Reset()
14966+ return err
14967+ }
14968+
14969+ func send_clear() error {
14970+ send_attr(foreground, background)
14971+ outbuf.WriteString(funcs[t_clear_screen])
14972+ if !is_cursor_hidden(cursor_x, cursor_y) {
14973+ write_cursor(cursor_x, cursor_y)
14974+ }
14975+
14976+ // we need to invalidate cursor position too and these two vars are
14977+ // used only for simple cursor positioning optimization, cursor
14978+ // actually may be in the correct place, but we simply discard
14979+ // optimization once and it gives us simple solution for the case when
14980+ // cursor moved
14981+ lastx = coord_invalid
14982+ lasty = coord_invalid
14983+
14984+ return flush()
14985+ }
14986+
14987+ func update_size_maybe() error {
14988+ w, h := get_term_size(out.Fd())
14989+ if w != termw || h != termh {
14990+ termw, termh = w, h
14991+ back_buffer.resize(termw, termh)
14992+ front_buffer.resize(termw, termh)
14993+ front_buffer.clear()
14994+ return send_clear()
14995+ }
14996+ return nil
14997+ }
14998+
14999+ func tcsetattr(fd uintptr, termios *syscall_Termios) error {
15000+ r, _, e := syscall.Syscall(syscall.SYS_IOCTL,
15001+ fd, uintptr(syscall_TCSETS), uintptr(unsafe.Pointer(termios)))
15002+ if r != 0 {
15003+ return os.NewSyscallError("SYS_IOCTL", e)
15004+ }
15005+ return nil
15006+ }
15007+
15008+ func tcgetattr(fd uintptr, termios *syscall_Termios) error {
15009+ r, _, e := syscall.Syscall(syscall.SYS_IOCTL,
15010+ fd, uintptr(syscall_TCGETS), uintptr(unsafe.Pointer(termios)))
15011+ if r != 0 {
15012+ return os.NewSyscallError("SYS_IOCTL", e)
15013+ }
15014+ return nil
15015+ }
15016+
15017+ func parse_mouse_event(event *Event, buf string) (int, bool) {
15018+ if strings.HasPrefix(buf, "\033[M") && len(buf) >= 6 {
15019+ // X10 mouse encoding, the simplest one
15020+ // \033 [ M Cb Cx Cy
15021+ b := buf[3] - 32
15022+ switch b & 3 {
15023+ case 0:
15024+ if b&64 != 0 {
15025+ event.Key = MouseWheelUp
15026+ } else {
15027+ event.Key = MouseLeft
15028+ }
15029+ case 1:
15030+ if b&64 != 0 {
15031+ event.Key = MouseWheelDown
15032+ } else {
15033+ event.Key = MouseMiddle
15034+ }
15035+ case 2:
15036+ event.Key = MouseRight
15037+ case 3:
15038+ event.Key = MouseRelease
15039+ default:
15040+ return 6, false
15041+ }
15042+ event.Type = EventMouse // KeyEvent by default
15043+ if b&32 != 0 {
15044+ event.Mod |= ModMotion
15045+ }
15046+
15047+ // the coord is 1,1 for upper left
15048+ event.MouseX = int(buf[4]) - 1 - 32
15049+ event.MouseY = int(buf[5]) - 1 - 32
15050+ return 6, true
15051+ } else if strings.HasPrefix(buf, "\033[<") || strings.HasPrefix(buf, "\033[") {
15052+ // xterm 1006 extended mode or urxvt 1015 extended mode
15053+ // xterm: \033 [ < Cb ; Cx ; Cy (M or m)
15054+ // urxvt: \033 [ Cb ; Cx ; Cy M
15055+
15056+ // find the first M or m, that's where we stop
15057+ mi := strings.IndexAny(buf, "Mm")
15058+ if mi == -1 {
15059+ return 0, false
15060+ }
15061+
15062+ // whether it's a capital M or not
15063+ isM := buf[mi] == 'M'
15064+
15065+ // whether it's urxvt or not
15066+ isU := false
15067+
15068+ // buf[2] is safe here, because having M or m found means we have at
15069+ // least 3 bytes in a string
15070+ if buf[2] == '<' {
15071+ buf = buf[3:mi]
15072+ } else {
15073+ isU = true
15074+ buf = buf[2:mi]
15075+ }
15076+
15077+ s1 := strings.Index(buf, ";")
15078+ s2 := strings.LastIndex(buf, ";")
15079+ // not found or only one ';'
15080+ if s1 == -1 || s2 == -1 || s1 == s2 {
15081+ return 0, false
15082+ }
15083+
15084+ n1, err := strconv.ParseInt(buf[0:s1], 10, 64)
15085+ if err != nil {
15086+ return 0, false
15087+ }
15088+ n2, err := strconv.ParseInt(buf[s1+1:s2], 10, 64)
15089+ if err != nil {
15090+ return 0, false
15091+ }
15092+ n3, err := strconv.ParseInt(buf[s2+1:], 10, 64)
15093+ if err != nil {
15094+ return 0, false
15095+ }
15096+
15097+ // on urxvt, first number is encoded exactly as in X10, but we need to
15098+ // make it zero-based, on xterm it is zero-based already
15099+ if isU {
15100+ n1 -= 32
15101+ }
15102+ switch n1 & 3 {
15103+ case 0:
15104+ if n1&64 != 0 {
15105+ event.Key = MouseWheelUp
15106+ } else {
15107+ event.Key = MouseLeft
15108+ }
15109+ case 1:
15110+ if n1&64 != 0 {
15111+ event.Key = MouseWheelDown
15112+ } else {
15113+ event.Key = MouseMiddle
15114+ }
15115+ case 2:
15116+ event.Key = MouseRight
15117+ case 3:
15118+ event.Key = MouseRelease
15119+ default:
15120+ return mi + 1, false
15121+ }
15122+ if !isM {
15123+ // on xterm mouse release is signaled by lowercase m
15124+ event.Key = MouseRelease
15125+ }
15126+
15127+ event.Type = EventMouse // KeyEvent by default
15128+ if n1&32 != 0 {
15129+ event.Mod |= ModMotion
15130+ }
15131+
15132+ event.MouseX = int(n2) - 1
15133+ event.MouseY = int(n3) - 1
15134+ return mi + 1, true
15135+ }
15136+
15137+ return 0, false
15138+ }
15139+
15140+ func parse_escape_sequence(event *Event, buf []byte) (int, bool) {
15141+ bufstr := string(buf)
15142+ for i, key := range keys {
15143+ if strings.HasPrefix(bufstr, key) {
15144+ event.Ch = 0
15145+ event.Key = Key(0xFFFF - i)
15146+ return len(key), true
15147+ }
15148+ }
15149+
15150+ // if none of the keys match, let's try mouse sequences
15151+ return parse_mouse_event(event, bufstr)
15152+ }
15153+
15154+ func extract_raw_event(data []byte, event *Event) bool {
15155+ if len(inbuf) == 0 {
15156+ return false
15157+ }
15158+
15159+ n := len(data)
15160+ if n == 0 {
15161+ return false
15162+ }
15163+
15164+ n = copy(data, inbuf)
15165+ copy(inbuf, inbuf[n:])
15166+ inbuf = inbuf[:len(inbuf)-n]
15167+
15168+ event.N = n
15169+ event.Type = EventRaw
15170+ return true
15171+ }
15172+
15173+ func extract_event(inbuf []byte, event *Event, allow_esc_wait bool) extract_event_res {
15174+ if len(inbuf) == 0 {
15175+ event.N = 0
15176+ return event_not_extracted
15177+ }
15178+
15179+ if inbuf[0] == '\033' {
15180+ // possible escape sequence
15181+ if n, ok := parse_escape_sequence(event, inbuf); n != 0 {
15182+ event.N = n
15183+ if ok {
15184+ return event_extracted
15185+ } else {
15186+ return event_not_extracted
15187+ }
15188+ }
15189+
15190+ // possible partially read escape sequence; trigger a wait if appropriate
15191+ if enable_wait_for_escape_sequence() && allow_esc_wait {
15192+ event.N = 0
15193+ return esc_wait
15194+ }
15195+
15196+ // it's not escape sequence, then it's Alt or Esc, check input_mode
15197+ switch {
15198+ case input_mode&InputEsc != 0:
15199+ // if we're in escape mode, fill Esc event, pop buffer, return success
15200+ event.Ch = 0
15201+ event.Key = KeyEsc
15202+ event.Mod = 0
15203+ event.N = 1
15204+ return event_extracted
15205+ case input_mode&InputAlt != 0:
15206+ // if we're in alt mode, set Alt modifier to event and redo parsing
15207+ event.Mod = ModAlt
15208+ status := extract_event(inbuf[1:], event, false)
15209+ if status == event_extracted {
15210+ event.N++
15211+ } else {
15212+ event.N = 0
15213+ }
15214+ return status
15215+ default:
15216+ panic("unreachable")
15217+ }
15218+ }
15219+
15220+ // if we're here, this is not an escape sequence and not an alt sequence
15221+ // so, it's a FUNCTIONAL KEY or a UNICODE character
15222+
15223+ // first of all check if it's a functional key
15224+ if Key(inbuf[0]) <= KeySpace || Key(inbuf[0]) == KeyBackspace2 {
15225+ // fill event, pop buffer, return success
15226+ event.Ch = 0
15227+ event.Key = Key(inbuf[0])
15228+ event.N = 1
15229+ return event_extracted
15230+ }
15231+
15232+ // the only possible option is utf8 rune
15233+ if r, n := utf8.DecodeRune(inbuf); r != utf8.RuneError {
15234+ event.Ch = r
15235+ event.Key = 0
15236+ event.N = n
15237+ return event_extracted
15238+ }
15239+
15240+ return event_not_extracted
15241+ }
15242+
15243+ func fcntl(fd int, cmd int, arg int) (val int, err error) {
15244+ r, _, e := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), uintptr(cmd),
15245+ uintptr(arg))
15246+ val = int(r)
15247+ if e != 0 {
15248+ err = e
15249+ }
15250+ return
15251+ }
15252 diff --git a/vendor/github.com/nsf/termbox-go/termbox_common.go b/vendor/github.com/nsf/termbox-go/termbox_common.go
15253new file mode 100644
15254index 0000000..c3355cc
15255--- /dev/null
15256+++ b/vendor/github.com/nsf/termbox-go/termbox_common.go
15257 @@ -0,0 +1,59 @@
15258+ package termbox
15259+
15260+ // private API, common OS agnostic part
15261+
15262+ type cellbuf struct {
15263+ width int
15264+ height int
15265+ cells []Cell
15266+ }
15267+
15268+ func (this *cellbuf) init(width, height int) {
15269+ this.width = width
15270+ this.height = height
15271+ this.cells = make([]Cell, width*height)
15272+ }
15273+
15274+ func (this *cellbuf) resize(width, height int) {
15275+ if this.width == width && this.height == height {
15276+ return
15277+ }
15278+
15279+ oldw := this.width
15280+ oldh := this.height
15281+ oldcells := this.cells
15282+
15283+ this.init(width, height)
15284+ this.clear()
15285+
15286+ minw, minh := oldw, oldh
15287+
15288+ if width < minw {
15289+ minw = width
15290+ }
15291+ if height < minh {
15292+ minh = height
15293+ }
15294+
15295+ for i := 0; i < minh; i++ {
15296+ srco, dsto := i*oldw, i*width
15297+ src := oldcells[srco : srco+minw]
15298+ dst := this.cells[dsto : dsto+minw]
15299+ copy(dst, src)
15300+ }
15301+ }
15302+
15303+ func (this *cellbuf) clear() {
15304+ for i := range this.cells {
15305+ c := &this.cells[i]
15306+ c.Ch = ' '
15307+ c.Fg = foreground
15308+ c.Bg = background
15309+ }
15310+ }
15311+
15312+ const cursor_hidden = -1
15313+
15314+ func is_cursor_hidden(x, y int) bool {
15315+ return x == cursor_hidden || y == cursor_hidden
15316+ }
15317 diff --git a/vendor/github.com/nsf/termbox-go/termbox_windows.go b/vendor/github.com/nsf/termbox-go/termbox_windows.go
15318new file mode 100644
15319index 0000000..738847c
15320--- /dev/null
15321+++ b/vendor/github.com/nsf/termbox-go/termbox_windows.go
15322 @@ -0,0 +1,889 @@
15323+ package termbox
15324+
15325+ import "syscall"
15326+ import "unsafe"
15327+ import "unicode/utf16"
15328+ import "github.com/mattn/go-runewidth"
15329+
15330+ type (
15331+ wchar uint16
15332+ short int16
15333+ dword uint32
15334+ word uint16
15335+ char_info struct {
15336+ char wchar
15337+ attr word
15338+ }
15339+ coord struct {
15340+ x short
15341+ y short
15342+ }
15343+ small_rect struct {
15344+ left short
15345+ top short
15346+ right short
15347+ bottom short
15348+ }
15349+ console_screen_buffer_info struct {
15350+ size coord
15351+ cursor_position coord
15352+ attributes word
15353+ window small_rect
15354+ maximum_window_size coord
15355+ }
15356+ console_cursor_info struct {
15357+ size dword
15358+ visible int32
15359+ }
15360+ input_record struct {
15361+ event_type word
15362+ _ [2]byte
15363+ event [16]byte
15364+ }
15365+ key_event_record struct {
15366+ key_down int32
15367+ repeat_count word
15368+ virtual_key_code word
15369+ virtual_scan_code word
15370+ unicode_char wchar
15371+ control_key_state dword
15372+ }
15373+ window_buffer_size_record struct {
15374+ size coord
15375+ }
15376+ mouse_event_record struct {
15377+ mouse_pos coord
15378+ button_state dword
15379+ control_key_state dword
15380+ event_flags dword
15381+ }
15382+ )
15383+
15384+ const (
15385+ mouse_lmb = 0x1
15386+ mouse_rmb = 0x2
15387+ mouse_mmb = 0x4 | 0x8 | 0x10
15388+ SM_CXMIN = 28
15389+ SM_CYMIN = 29
15390+ )
15391+
15392+ func (this coord) uintptr() uintptr {
15393+ return uintptr(*(*int32)(unsafe.Pointer(&this)))
15394+ }
15395+
15396+ var kernel32 = syscall.NewLazyDLL("kernel32.dll")
15397+ var moduser32 = syscall.NewLazyDLL("user32.dll")
15398+ var is_cjk = runewidth.IsEastAsian()
15399+
15400+ var (
15401+ proc_set_console_active_screen_buffer = kernel32.NewProc("SetConsoleActiveScreenBuffer")
15402+ proc_set_console_screen_buffer_size = kernel32.NewProc("SetConsoleScreenBufferSize")
15403+ proc_create_console_screen_buffer = kernel32.NewProc("CreateConsoleScreenBuffer")
15404+ proc_get_console_screen_buffer_info = kernel32.NewProc("GetConsoleScreenBufferInfo")
15405+ proc_write_console_output = kernel32.NewProc("WriteConsoleOutputW")
15406+ proc_write_console_output_character = kernel32.NewProc("WriteConsoleOutputCharacterW")
15407+ proc_write_console_output_attribute = kernel32.NewProc("WriteConsoleOutputAttribute")
15408+ proc_set_console_cursor_info = kernel32.NewProc("SetConsoleCursorInfo")
15409+ proc_set_console_cursor_position = kernel32.NewProc("SetConsoleCursorPosition")
15410+ proc_get_console_cursor_info = kernel32.NewProc("GetConsoleCursorInfo")
15411+ proc_read_console_input = kernel32.NewProc("ReadConsoleInputW")
15412+ proc_get_console_mode = kernel32.NewProc("GetConsoleMode")
15413+ proc_set_console_mode = kernel32.NewProc("SetConsoleMode")
15414+ proc_fill_console_output_character = kernel32.NewProc("FillConsoleOutputCharacterW")
15415+ proc_fill_console_output_attribute = kernel32.NewProc("FillConsoleOutputAttribute")
15416+ proc_create_event = kernel32.NewProc("CreateEventW")
15417+ proc_wait_for_multiple_objects = kernel32.NewProc("WaitForMultipleObjects")
15418+ proc_set_event = kernel32.NewProc("SetEvent")
15419+ get_system_metrics = moduser32.NewProc("GetSystemMetrics")
15420+ )
15421+
15422+ func set_console_active_screen_buffer(h syscall.Handle) (err error) {
15423+ r0, _, e1 := syscall.Syscall(proc_set_console_active_screen_buffer.Addr(),
15424+ 1, uintptr(h), 0, 0)
15425+ if int(r0) == 0 {
15426+ if e1 != 0 {
15427+ err = error(e1)
15428+ } else {
15429+ err = syscall.EINVAL
15430+ }
15431+ }
15432+ return
15433+ }
15434+
15435+ func set_console_screen_buffer_size(h syscall.Handle, size coord) (err error) {
15436+ r0, _, e1 := syscall.Syscall(proc_set_console_screen_buffer_size.Addr(),
15437+ 2, uintptr(h), size.uintptr(), 0)
15438+ if int(r0) == 0 {
15439+ if e1 != 0 {
15440+ err = error(e1)
15441+ } else {
15442+ err = syscall.EINVAL
15443+ }
15444+ }
15445+ return
15446+ }
15447+
15448+ func create_console_screen_buffer() (h syscall.Handle, err error) {
15449+ r0, _, e1 := syscall.Syscall6(proc_create_console_screen_buffer.Addr(),
15450+ 5, uintptr(generic_read|generic_write), 0, 0, console_textmode_buffer, 0, 0)
15451+ if int(r0) == 0 {
15452+ if e1 != 0 {
15453+ err = error(e1)
15454+ } else {
15455+ err = syscall.EINVAL
15456+ }
15457+ }
15458+ return syscall.Handle(r0), err
15459+ }
15460+
15461+ func get_console_screen_buffer_info(h syscall.Handle, info *console_screen_buffer_info) (err error) {
15462+ r0, _, e1 := syscall.Syscall(proc_get_console_screen_buffer_info.Addr(),
15463+ 2, uintptr(h), uintptr(unsafe.Pointer(info)), 0)
15464+ if int(r0) == 0 {
15465+ if e1 != 0 {
15466+ err = error(e1)
15467+ } else {
15468+ err = syscall.EINVAL
15469+ }
15470+ }
15471+ return
15472+ }
15473+
15474+ func write_console_output(h syscall.Handle, chars []char_info, dst small_rect) (err error) {
15475+ tmp_coord = coord{dst.right - dst.left + 1, dst.bottom - dst.top + 1}
15476+ tmp_rect = dst
15477+ r0, _, e1 := syscall.Syscall6(proc_write_console_output.Addr(),
15478+ 5, uintptr(h), uintptr(unsafe.Pointer(&chars[0])), tmp_coord.uintptr(),
15479+ tmp_coord0.uintptr(), uintptr(unsafe.Pointer(&tmp_rect)), 0)
15480+ if int(r0) == 0 {
15481+ if e1 != 0 {
15482+ err = error(e1)
15483+ } else {
15484+ err = syscall.EINVAL
15485+ }
15486+ }
15487+ return
15488+ }
15489+
15490+ func write_console_output_character(h syscall.Handle, chars []wchar, pos coord) (err error) {
15491+ r0, _, e1 := syscall.Syscall6(proc_write_console_output_character.Addr(),
15492+ 5, uintptr(h), uintptr(unsafe.Pointer(&chars[0])), uintptr(len(chars)),
15493+ pos.uintptr(), uintptr(unsafe.Pointer(&tmp_arg)), 0)
15494+ if int(r0) == 0 {
15495+ if e1 != 0 {
15496+ err = error(e1)
15497+ } else {
15498+ err = syscall.EINVAL
15499+ }
15500+ }
15501+ return
15502+ }
15503+
15504+ func write_console_output_attribute(h syscall.Handle, attrs []word, pos coord) (err error) {
15505+ r0, _, e1 := syscall.Syscall6(proc_write_console_output_attribute.Addr(),
15506+ 5, uintptr(h), uintptr(unsafe.Pointer(&attrs[0])), uintptr(len(attrs)),
15507+ pos.uintptr(), uintptr(unsafe.Pointer(&tmp_arg)), 0)
15508+ if int(r0) == 0 {
15509+ if e1 != 0 {
15510+ err = error(e1)
15511+ } else {
15512+ err = syscall.EINVAL
15513+ }
15514+ }
15515+ return
15516+ }
15517+
15518+ func set_console_cursor_info(h syscall.Handle, info *console_cursor_info) (err error) {
15519+ r0, _, e1 := syscall.Syscall(proc_set_console_cursor_info.Addr(),
15520+ 2, uintptr(h), uintptr(unsafe.Pointer(info)), 0)
15521+ if int(r0) == 0 {
15522+ if e1 != 0 {
15523+ err = error(e1)
15524+ } else {
15525+ err = syscall.EINVAL
15526+ }
15527+ }
15528+ return
15529+ }
15530+
15531+ func get_console_cursor_info(h syscall.Handle, info *console_cursor_info) (err error) {
15532+ r0, _, e1 := syscall.Syscall(proc_get_console_cursor_info.Addr(),
15533+ 2, uintptr(h), uintptr(unsafe.Pointer(info)), 0)
15534+ if int(r0) == 0 {
15535+ if e1 != 0 {
15536+ err = error(e1)
15537+ } else {
15538+ err = syscall.EINVAL
15539+ }
15540+ }
15541+ return
15542+ }
15543+
15544+ func set_console_cursor_position(h syscall.Handle, pos coord) (err error) {
15545+ r0, _, e1 := syscall.Syscall(proc_set_console_cursor_position.Addr(),
15546+ 2, uintptr(h), pos.uintptr(), 0)
15547+ if int(r0) == 0 {
15548+ if e1 != 0 {
15549+ err = error(e1)
15550+ } else {
15551+ err = syscall.EINVAL
15552+ }
15553+ }
15554+ return
15555+ }
15556+
15557+ func read_console_input(h syscall.Handle, record *input_record) (err error) {
15558+ r0, _, e1 := syscall.Syscall6(proc_read_console_input.Addr(),
15559+ 4, uintptr(h), uintptr(unsafe.Pointer(record)), 1, uintptr(unsafe.Pointer(&tmp_arg)), 0, 0)
15560+ if int(r0) == 0 {
15561+ if e1 != 0 {
15562+ err = error(e1)
15563+ } else {
15564+ err = syscall.EINVAL
15565+ }
15566+ }
15567+ return
15568+ }
15569+
15570+ func get_console_mode(h syscall.Handle, mode *dword) (err error) {
15571+ r0, _, e1 := syscall.Syscall(proc_get_console_mode.Addr(),
15572+ 2, uintptr(h), uintptr(unsafe.Pointer(mode)), 0)
15573+ if int(r0) == 0 {
15574+ if e1 != 0 {
15575+ err = error(e1)
15576+ } else {
15577+ err = syscall.EINVAL
15578+ }
15579+ }
15580+ return
15581+ }
15582+
15583+ func set_console_mode(h syscall.Handle, mode dword) (err error) {
15584+ r0, _, e1 := syscall.Syscall(proc_set_console_mode.Addr(),
15585+ 2, uintptr(h), uintptr(mode), 0)
15586+ if int(r0) == 0 {
15587+ if e1 != 0 {
15588+ err = error(e1)
15589+ } else {
15590+ err = syscall.EINVAL
15591+ }
15592+ }
15593+ return
15594+ }
15595+
15596+ func fill_console_output_character(h syscall.Handle, char wchar, n int) (err error) {
15597+ r0, _, e1 := syscall.Syscall6(proc_fill_console_output_character.Addr(),
15598+ 5, uintptr(h), uintptr(char), uintptr(n), tmp_coord.uintptr(),
15599+ uintptr(unsafe.Pointer(&tmp_arg)), 0)
15600+ if int(r0) == 0 {
15601+ if e1 != 0 {
15602+ err = error(e1)
15603+ } else {
15604+ err = syscall.EINVAL
15605+ }
15606+ }
15607+ return
15608+ }
15609+
15610+ func fill_console_output_attribute(h syscall.Handle, attr word, n int) (err error) {
15611+ r0, _, e1 := syscall.Syscall6(proc_fill_console_output_attribute.Addr(),
15612+ 5, uintptr(h), uintptr(attr), uintptr(n), tmp_coord.uintptr(),
15613+ uintptr(unsafe.Pointer(&tmp_arg)), 0)
15614+ if int(r0) == 0 {
15615+ if e1 != 0 {
15616+ err = error(e1)
15617+ } else {
15618+ err = syscall.EINVAL
15619+ }
15620+ }
15621+ return
15622+ }
15623+
15624+ func create_event() (out syscall.Handle, err error) {
15625+ r0, _, e1 := syscall.Syscall6(proc_create_event.Addr(),
15626+ 4, 0, 0, 0, 0, 0, 0)
15627+ if int(r0) == 0 {
15628+ if e1 != 0 {
15629+ err = error(e1)
15630+ } else {
15631+ err = syscall.EINVAL
15632+ }
15633+ }
15634+ return syscall.Handle(r0), err
15635+ }
15636+
15637+ func wait_for_multiple_objects(objects []syscall.Handle) (err error) {
15638+ r0, _, e1 := syscall.Syscall6(proc_wait_for_multiple_objects.Addr(),
15639+ 4, uintptr(len(objects)), uintptr(unsafe.Pointer(&objects[0])),
15640+ 0, 0xFFFFFFFF, 0, 0)
15641+ if uint32(r0) == 0xFFFFFFFF {
15642+ if e1 != 0 {
15643+ err = error(e1)
15644+ } else {
15645+ err = syscall.EINVAL
15646+ }
15647+ }
15648+ return
15649+ }
15650+
15651+ func set_event(ev syscall.Handle) (err error) {
15652+ r0, _, e1 := syscall.Syscall(proc_set_event.Addr(),
15653+ 1, uintptr(ev), 0, 0)
15654+ if int(r0) == 0 {
15655+ if e1 != 0 {
15656+ err = error(e1)
15657+ } else {
15658+ err = syscall.EINVAL
15659+ }
15660+ }
15661+ return
15662+ }
15663+
15664+ type diff_msg struct {
15665+ pos short
15666+ lines short
15667+ chars []char_info
15668+ }
15669+
15670+ type input_event struct {
15671+ event Event
15672+ err error
15673+ }
15674+
15675+ var (
15676+ orig_cursor_info console_cursor_info
15677+ orig_size coord
15678+ orig_mode dword
15679+ orig_screen syscall.Handle
15680+ back_buffer cellbuf
15681+ front_buffer cellbuf
15682+ term_size coord
15683+ input_mode = InputEsc
15684+ cursor_x = cursor_hidden
15685+ cursor_y = cursor_hidden
15686+ foreground = ColorDefault
15687+ background = ColorDefault
15688+ in syscall.Handle
15689+ out syscall.Handle
15690+ interrupt syscall.Handle
15691+ charbuf []char_info
15692+ diffbuf []diff_msg
15693+ beg_x = -1
15694+ beg_y = -1
15695+ beg_i = -1
15696+ input_comm = make(chan Event)
15697+ interrupt_comm = make(chan struct{})
15698+ cancel_comm = make(chan bool, 1)
15699+ cancel_done_comm = make(chan bool)
15700+ alt_mode_esc = false
15701+
15702+ // these ones just to prevent heap allocs at all costs
15703+ tmp_info console_screen_buffer_info
15704+ tmp_arg dword
15705+ tmp_coord0 = coord{0, 0}
15706+ tmp_coord = coord{0, 0}
15707+ tmp_rect = small_rect{0, 0, 0, 0}
15708+ )
15709+
15710+ func get_cursor_position(out syscall.Handle) coord {
15711+ err := get_console_screen_buffer_info(out, &tmp_info)
15712+ if err != nil {
15713+ panic(err)
15714+ }
15715+ return tmp_info.cursor_position
15716+ }
15717+
15718+ func get_term_size(out syscall.Handle) coord {
15719+ err := get_console_screen_buffer_info(out, &tmp_info)
15720+ if err != nil {
15721+ panic(err)
15722+ }
15723+ return tmp_info.size
15724+ }
15725+
15726+ func get_win_min_size(out syscall.Handle) coord {
15727+ x, _, err := get_system_metrics.Call(SM_CXMIN)
15728+ y, _, err := get_system_metrics.Call(SM_CYMIN)
15729+
15730+ if x == 0 || y == 0 {
15731+ if err != nil {
15732+ panic(err)
15733+ }
15734+ }
15735+
15736+ return coord{
15737+ x: short(x),
15738+ y: short(y),
15739+ }
15740+ }
15741+
15742+ func get_win_size(out syscall.Handle) coord {
15743+ err := get_console_screen_buffer_info(out, &tmp_info)
15744+ if err != nil {
15745+ panic(err)
15746+ }
15747+
15748+ min_size := get_win_min_size(out)
15749+
15750+ size := coord{
15751+ x: tmp_info.window.right - tmp_info.window.left + 1,
15752+ y: tmp_info.window.bottom - tmp_info.window.top + 1,
15753+ }
15754+
15755+ if size.x < min_size.x {
15756+ size.x = min_size.x
15757+ }
15758+
15759+ if size.y < min_size.y {
15760+ size.y = min_size.y
15761+ }
15762+
15763+ return size
15764+ }
15765+
15766+ func update_size_maybe() {
15767+ size := get_term_size(out)
15768+ if size.x != term_size.x || size.y != term_size.y {
15769+ term_size = size
15770+ back_buffer.resize(int(size.x), int(size.y))
15771+ front_buffer.resize(int(size.x), int(size.y))
15772+ front_buffer.clear()
15773+ clear()
15774+
15775+ area := int(size.x) * int(size.y)
15776+ if cap(charbuf) < area {
15777+ charbuf = make([]char_info, 0, area)
15778+ }
15779+ }
15780+ }
15781+
15782+ var color_table_bg = []word{
15783+ 0, // default (black)
15784+ 0, // black
15785+ background_red,
15786+ background_green,
15787+ background_red | background_green, // yellow
15788+ background_blue,
15789+ background_red | background_blue, // magenta
15790+ background_green | background_blue, // cyan
15791+ background_red | background_blue | background_green, // white
15792+ }
15793+
15794+ var color_table_fg = []word{
15795+ foreground_red | foreground_blue | foreground_green, // default (white)
15796+ 0,
15797+ foreground_red,
15798+ foreground_green,
15799+ foreground_red | foreground_green, // yellow
15800+ foreground_blue,
15801+ foreground_red | foreground_blue, // magenta
15802+ foreground_green | foreground_blue, // cyan
15803+ foreground_red | foreground_blue | foreground_green, // white
15804+ }
15805+
15806+ const (
15807+ replacement_char = '\uFFFD'
15808+ max_rune = '\U0010FFFF'
15809+ surr1 = 0xd800
15810+ surr2 = 0xdc00
15811+ surr3 = 0xe000
15812+ surr_self = 0x10000
15813+ )
15814+
15815+ func append_diff_line(y int) int {
15816+ n := 0
15817+ for x := 0; x < front_buffer.width; {
15818+ cell_offset := y*front_buffer.width + x
15819+ back := &back_buffer.cells[cell_offset]
15820+ front := &front_buffer.cells[cell_offset]
15821+ attr, char := cell_to_char_info(*back)
15822+ charbuf = append(charbuf, char_info{attr: attr, char: char[0]})
15823+ *front = *back
15824+ n++
15825+ w := runewidth.RuneWidth(back.Ch)
15826+ if w == 0 || w == 2 && runewidth.IsAmbiguousWidth(back.Ch) {
15827+ w = 1
15828+ }
15829+ x += w
15830+ // If not CJK, fill trailing space with whitespace
15831+ if !is_cjk && w == 2 {
15832+ charbuf = append(charbuf, char_info{attr: attr, char: ' '})
15833+ }
15834+ }
15835+ return n
15836+ }
15837+
15838+ // compares 'back_buffer' with 'front_buffer' and prepares all changes in the form of
15839+ // 'diff_msg's in the 'diff_buf'
15840+ func prepare_diff_messages() {
15841+ // clear buffers
15842+ diffbuf = diffbuf[:0]
15843+ charbuf = charbuf[:0]
15844+
15845+ var diff diff_msg
15846+ gbeg := 0
15847+ for y := 0; y < front_buffer.height; y++ {
15848+ same := true
15849+ line_offset := y * front_buffer.width
15850+ for x := 0; x < front_buffer.width; x++ {
15851+ cell_offset := line_offset + x
15852+ back := &back_buffer.cells[cell_offset]
15853+ front := &front_buffer.cells[cell_offset]
15854+ if *back != *front {
15855+ same = false
15856+ break
15857+ }
15858+ }
15859+ if same && diff.lines > 0 {
15860+ diffbuf = append(diffbuf, diff)
15861+ diff = diff_msg{}
15862+ }
15863+ if !same {
15864+ beg := len(charbuf)
15865+ end := beg + append_diff_line(y)
15866+ if diff.lines == 0 {
15867+ diff.pos = short(y)
15868+ gbeg = beg
15869+ }
15870+ diff.lines++
15871+ diff.chars = charbuf[gbeg:end]
15872+ }
15873+ }
15874+ if diff.lines > 0 {
15875+ diffbuf = append(diffbuf, diff)
15876+ diff = diff_msg{}
15877+ }
15878+ }
15879+
15880+ func get_ct(table []word, idx int) word {
15881+ idx = idx & 0x0F
15882+ if idx >= len(table) {
15883+ idx = len(table) - 1
15884+ }
15885+ return table[idx]
15886+ }
15887+
15888+ func cell_to_char_info(c Cell) (attr word, wc [2]wchar) {
15889+ attr = get_ct(color_table_fg, int(c.Fg)) | get_ct(color_table_bg, int(c.Bg))
15890+ if c.Fg&AttrReverse|c.Bg&AttrReverse != 0 {
15891+ attr = (attr&0xF0)>>4 | (attr&0x0F)<<4
15892+ }
15893+ if c.Fg&AttrBold != 0 {
15894+ attr |= foreground_intensity
15895+ }
15896+ if c.Bg&AttrBold != 0 {
15897+ attr |= background_intensity
15898+ }
15899+
15900+ r0, r1 := utf16.EncodeRune(c.Ch)
15901+ if r0 == 0xFFFD {
15902+ wc[0] = wchar(c.Ch)
15903+ wc[1] = ' '
15904+ } else {
15905+ wc[0] = wchar(r0)
15906+ wc[1] = wchar(r1)
15907+ }
15908+ return
15909+ }
15910+
15911+ func move_cursor(x, y int) {
15912+ err := set_console_cursor_position(out, coord{short(x), short(y)})
15913+ if err != nil {
15914+ panic(err)
15915+ }
15916+ }
15917+
15918+ func show_cursor(visible bool) {
15919+ var v int32
15920+ if visible {
15921+ v = 1
15922+ }
15923+
15924+ var info console_cursor_info
15925+ info.size = 100
15926+ info.visible = v
15927+ err := set_console_cursor_info(out, &info)
15928+ if err != nil {
15929+ panic(err)
15930+ }
15931+ }
15932+
15933+ func clear() {
15934+ var err error
15935+ attr, char := cell_to_char_info(Cell{
15936+ ' ',
15937+ foreground,
15938+ background,
15939+ })
15940+
15941+ area := int(term_size.x) * int(term_size.y)
15942+ err = fill_console_output_attribute(out, attr, area)
15943+ if err != nil {
15944+ panic(err)
15945+ }
15946+ err = fill_console_output_character(out, char[0], area)
15947+ if err != nil {
15948+ panic(err)
15949+ }
15950+ if !is_cursor_hidden(cursor_x, cursor_y) {
15951+ move_cursor(cursor_x, cursor_y)
15952+ }
15953+ }
15954+
15955+ func key_event_record_to_event(r *key_event_record) (Event, bool) {
15956+ if r.key_down == 0 {
15957+ return Event{}, false
15958+ }
15959+
15960+ e := Event{Type: EventKey}
15961+ if input_mode&InputAlt != 0 {
15962+ if alt_mode_esc {
15963+ e.Mod = ModAlt
15964+ alt_mode_esc = false
15965+ }
15966+ if r.control_key_state&(left_alt_pressed|right_alt_pressed) != 0 {
15967+ e.Mod = ModAlt
15968+ }
15969+ }
15970+
15971+ ctrlpressed := r.control_key_state&(left_ctrl_pressed|right_ctrl_pressed) != 0
15972+
15973+ if r.virtual_key_code >= vk_f1 && r.virtual_key_code <= vk_f12 {
15974+ switch r.virtual_key_code {
15975+ case vk_f1:
15976+ e.Key = KeyF1
15977+ case vk_f2:
15978+ e.Key = KeyF2
15979+ case vk_f3:
15980+ e.Key = KeyF3
15981+ case vk_f4:
15982+ e.Key = KeyF4
15983+ case vk_f5:
15984+ e.Key = KeyF5
15985+ case vk_f6:
15986+ e.Key = KeyF6
15987+ case vk_f7:
15988+ e.Key = KeyF7
15989+ case vk_f8:
15990+ e.Key = KeyF8
15991+ case vk_f9:
15992+ e.Key = KeyF9
15993+ case vk_f10:
15994+ e.Key = KeyF10
15995+ case vk_f11:
15996+ e.Key = KeyF11
15997+ case vk_f12:
15998+ e.Key = KeyF12
15999+ default:
16000+ panic("unreachable")
16001+ }
16002+
16003+ return e, true
16004+ }
16005+
16006+ if r.virtual_key_code <= vk_delete {
16007+ switch r.virtual_key_code {
16008+ case vk_insert:
16009+ e.Key = KeyInsert
16010+ case vk_delete:
16011+ e.Key = KeyDelete
16012+ case vk_home:
16013+ e.Key = KeyHome
16014+ case vk_end:
16015+ e.Key = KeyEnd
16016+ case vk_pgup:
16017+ e.Key = KeyPgup
16018+ case vk_pgdn:
16019+ e.Key = KeyPgdn
16020+ case vk_arrow_up:
16021+ e.Key = KeyArrowUp
16022+ case vk_arrow_down:
16023+ e.Key = KeyArrowDown
16024+ case vk_arrow_left:
16025+ e.Key = KeyArrowLeft
16026+ case vk_arrow_right:
16027+ e.Key = KeyArrowRight
16028+ case vk_backspace:
16029+ if ctrlpressed {
16030+ e.Key = KeyBackspace2
16031+ } else {
16032+ e.Key = KeyBackspace
16033+ }
16034+ case vk_tab:
16035+ e.Key = KeyTab
16036+ case vk_enter:
16037+ e.Key = KeyEnter
16038+ case vk_esc:
16039+ switch {
16040+ case input_mode&InputEsc != 0:
16041+ e.Key = KeyEsc
16042+ case input_mode&InputAlt != 0:
16043+ alt_mode_esc = true
16044+ return Event{}, false
16045+ }
16046+ case vk_space:
16047+ if ctrlpressed {
16048+ // manual return here, because KeyCtrlSpace is zero
16049+ e.Key = KeyCtrlSpace
16050+ return e, true
16051+ } else {
16052+ e.Key = KeySpace
16053+ }
16054+ }
16055+
16056+ if e.Key != 0 {
16057+ return e, true
16058+ }
16059+ }
16060+
16061+ if ctrlpressed {
16062+ if Key(r.unicode_char) >= KeyCtrlA && Key(r.unicode_char) <= KeyCtrlRsqBracket {
16063+ e.Key = Key(r.unicode_char)
16064+ if input_mode&InputAlt != 0 && e.Key == KeyEsc {
16065+ alt_mode_esc = true
16066+ return Event{}, false
16067+ }
16068+ return e, true
16069+ }
16070+ switch r.virtual_key_code {
16071+ case 192, 50:
16072+ // manual return here, because KeyCtrl2 is zero
16073+ e.Key = KeyCtrl2
16074+ return e, true
16075+ case 51:
16076+ if input_mode&InputAlt != 0 {
16077+ alt_mode_esc = true
16078+ return Event{}, false
16079+ }
16080+ e.Key = KeyCtrl3
16081+ case 52:
16082+ e.Key = KeyCtrl4
16083+ case 53:
16084+ e.Key = KeyCtrl5
16085+ case 54:
16086+ e.Key = KeyCtrl6
16087+ case 189, 191, 55:
16088+ e.Key = KeyCtrl7
16089+ case 8, 56:
16090+ e.Key = KeyCtrl8
16091+ }
16092+
16093+ if e.Key != 0 {
16094+ return e, true
16095+ }
16096+ }
16097+
16098+ if r.unicode_char != 0 {
16099+ e.Ch = rune(r.unicode_char)
16100+ return e, true
16101+ }
16102+
16103+ return Event{}, false
16104+ }
16105+
16106+ func input_event_producer() {
16107+ var r input_record
16108+ var err error
16109+ var last_button Key
16110+ var last_button_pressed Key
16111+ var last_state = dword(0)
16112+ var last_x, last_y = -1, -1
16113+ handles := []syscall.Handle{in, interrupt}
16114+ for {
16115+ err = wait_for_multiple_objects(handles)
16116+ if err != nil {
16117+ input_comm <- Event{Type: EventError, Err: err}
16118+ }
16119+
16120+ select {
16121+ case <-cancel_comm:
16122+ cancel_done_comm <- true
16123+ return
16124+ default:
16125+ }
16126+
16127+ err = read_console_input(in, &r)
16128+ if err != nil {
16129+ input_comm <- Event{Type: EventError, Err: err}
16130+ }
16131+
16132+ switch r.event_type {
16133+ case key_event:
16134+ kr := (*key_event_record)(unsafe.Pointer(&r.event))
16135+ ev, ok := key_event_record_to_event(kr)
16136+ if ok {
16137+ for i := 0; i < int(kr.repeat_count); i++ {
16138+ input_comm <- ev
16139+ }
16140+ }
16141+ case window_buffer_size_event:
16142+ sr := *(*window_buffer_size_record)(unsafe.Pointer(&r.event))
16143+ input_comm <- Event{
16144+ Type: EventResize,
16145+ Width: int(sr.size.x),
16146+ Height: int(sr.size.y),
16147+ }
16148+ case mouse_event:
16149+ mr := *(*mouse_event_record)(unsafe.Pointer(&r.event))
16150+ ev := Event{Type: EventMouse}
16151+ switch mr.event_flags {
16152+ case 0, 2:
16153+ // single or double click
16154+ cur_state := mr.button_state
16155+ switch {
16156+ case last_state&mouse_lmb == 0 && cur_state&mouse_lmb != 0:
16157+ last_button = MouseLeft
16158+ last_button_pressed = last_button
16159+ case last_state&mouse_rmb == 0 && cur_state&mouse_rmb != 0:
16160+ last_button = MouseRight
16161+ last_button_pressed = last_button
16162+ case last_state&mouse_mmb == 0 && cur_state&mouse_mmb != 0:
16163+ last_button = MouseMiddle
16164+ last_button_pressed = last_button
16165+ case last_state&mouse_lmb != 0 && cur_state&mouse_lmb == 0:
16166+ last_button = MouseRelease
16167+ case last_state&mouse_rmb != 0 && cur_state&mouse_rmb == 0:
16168+ last_button = MouseRelease
16169+ case last_state&mouse_mmb != 0 && cur_state&mouse_mmb == 0:
16170+ last_button = MouseRelease
16171+ default:
16172+ last_state = cur_state
16173+ continue
16174+ }
16175+ last_state = cur_state
16176+ ev.Key = last_button
16177+ last_x, last_y = int(mr.mouse_pos.x), int(mr.mouse_pos.y)
16178+ ev.MouseX = last_x
16179+ ev.MouseY = last_y
16180+ case 1:
16181+ // mouse motion
16182+ x, y := int(mr.mouse_pos.x), int(mr.mouse_pos.y)
16183+ if last_state != 0 && (last_x != x || last_y != y) {
16184+ ev.Key = last_button_pressed
16185+ ev.Mod = ModMotion
16186+ ev.MouseX = x
16187+ ev.MouseY = y
16188+ last_x, last_y = x, y
16189+ } else {
16190+ ev.Type = EventNone
16191+ }
16192+ case 4:
16193+ // mouse wheel
16194+ n := int16(mr.button_state >> 16)
16195+ if n > 0 {
16196+ ev.Key = MouseWheelUp
16197+ } else {
16198+ ev.Key = MouseWheelDown
16199+ }
16200+ last_x, last_y = int(mr.mouse_pos.x), int(mr.mouse_pos.y)
16201+ ev.MouseX = last_x
16202+ ev.MouseY = last_y
16203+ default:
16204+ ev.Type = EventNone
16205+ }
16206+ if ev.Type != EventNone {
16207+ input_comm <- ev
16208+ }
16209+ }
16210+ }
16211+ }
16212 diff --git a/vendor/github.com/nsf/termbox-go/terminfo.go b/vendor/github.com/nsf/termbox-go/terminfo.go
16213new file mode 100644
16214index 0000000..35dbd70
16215--- /dev/null
16216+++ b/vendor/github.com/nsf/termbox-go/terminfo.go
16217 @@ -0,0 +1,221 @@
16218+ // +build !windows
16219+ // This file contains a simple and incomplete implementation of the terminfo
16220+ // database. Information was taken from the ncurses manpages term(5) and
16221+ // terminfo(5). Currently, only the string capabilities for special keys and for
16222+ // functions without parameters are actually used. Colors are still done with
16223+ // ANSI escape sequences. Other special features that are not (yet?) supported
16224+ // are reading from ~/.terminfo, the TERMINFO_DIRS variable, Berkeley database
16225+ // format and extended capabilities.
16226+
16227+ package termbox
16228+
16229+ import (
16230+ "bytes"
16231+ "encoding/binary"
16232+ "encoding/hex"
16233+ "errors"
16234+ "fmt"
16235+ "io/ioutil"
16236+ "os"
16237+ "strings"
16238+ )
16239+
16240+ const (
16241+ ti_magic = 0432
16242+ ti_header_length = 12
16243+ ti_mouse_enter = "\x1b[?1000h\x1b[?1002h\x1b[?1015h\x1b[?1006h"
16244+ ti_mouse_leave = "\x1b[?1006l\x1b[?1015l\x1b[?1002l\x1b[?1000l"
16245+ )
16246+
16247+ func load_terminfo() ([]byte, error) {
16248+ var data []byte
16249+ var err error
16250+
16251+ term := os.Getenv("TERM")
16252+ if term == "" {
16253+ return nil, fmt.Errorf("termbox: TERM not set")
16254+ }
16255+
16256+ // The following behaviour follows the one described in terminfo(5) as
16257+ // distributed by ncurses.
16258+
16259+ terminfo := os.Getenv("TERMINFO")
16260+ if terminfo != "" {
16261+ // if TERMINFO is set, no other directory should be searched
16262+ return ti_try_path(terminfo)
16263+ }
16264+
16265+ // next, consider ~/.terminfo
16266+ home := os.Getenv("HOME")
16267+ if home != "" {
16268+ data, err = ti_try_path(home + "/.terminfo")
16269+ if err == nil {
16270+ return data, nil
16271+ }
16272+ }
16273+
16274+ // next, TERMINFO_DIRS
16275+ dirs := os.Getenv("TERMINFO_DIRS")
16276+ if dirs != "" {
16277+ for _, dir := range strings.Split(dirs, ":") {
16278+ if dir == "" {
16279+ // "" -> "/usr/share/terminfo"
16280+ dir = "/usr/share/terminfo"
16281+ }
16282+ data, err = ti_try_path(dir)
16283+ if err == nil {
16284+ return data, nil
16285+ }
16286+ }
16287+ }
16288+
16289+ // fall back to /usr/share/terminfo
16290+ return ti_try_path("/usr/share/terminfo")
16291+ }
16292+
16293+ func ti_try_path(path string) (data []byte, err error) {
16294+ // load_terminfo already made sure it is set
16295+ term := os.Getenv("TERM")
16296+
16297+ // first try, the typical *nix path
16298+ terminfo := path + "/" + term[0:1] + "/" + term
16299+ data, err = ioutil.ReadFile(terminfo)
16300+ if err == nil {
16301+ return
16302+ }
16303+
16304+ // fallback to darwin specific dirs structure
16305+ terminfo = path + "/" + hex.EncodeToString([]byte(term[:1])) + "/" + term
16306+ data, err = ioutil.ReadFile(terminfo)
16307+ return
16308+ }
16309+
16310+ func setup_term_builtin() error {
16311+ name := os.Getenv("TERM")
16312+ if name == "" {
16313+ return errors.New("termbox: TERM environment variable not set")
16314+ }
16315+
16316+ for _, t := range terms {
16317+ if t.name == name {
16318+ keys = t.keys
16319+ funcs = t.funcs
16320+ return nil
16321+ }
16322+ }
16323+
16324+ compat_table := []struct {
16325+ partial string
16326+ keys []string
16327+ funcs []string
16328+ }{
16329+ {"xterm", xterm_keys, xterm_funcs},
16330+ {"rxvt", rxvt_unicode_keys, rxvt_unicode_funcs},
16331+ {"linux", linux_keys, linux_funcs},
16332+ {"Eterm", eterm_keys, eterm_funcs},
16333+ {"screen", screen_keys, screen_funcs},
16334+ // let's assume that 'cygwin' is xterm compatible
16335+ {"cygwin", xterm_keys, xterm_funcs},
16336+ {"st", xterm_keys, xterm_funcs},
16337+ }
16338+
16339+ // try compatibility variants
16340+ for _, it := range compat_table {
16341+ if strings.Contains(name, it.partial) {
16342+ keys = it.keys
16343+ funcs = it.funcs
16344+ return nil
16345+ }
16346+ }
16347+
16348+ return errors.New("termbox: unsupported terminal")
16349+ }
16350+
16351+ func setup_term() (err error) {
16352+ var data []byte
16353+ var header [6]int16
16354+ var str_offset, table_offset int16
16355+
16356+ data, err = load_terminfo()
16357+ if err != nil {
16358+ return setup_term_builtin()
16359+ }
16360+
16361+ rd := bytes.NewReader(data)
16362+ // 0: magic number, 1: size of names section, 2: size of boolean section, 3:
16363+ // size of numbers section (in integers), 4: size of the strings section (in
16364+ // integers), 5: size of the string table
16365+
16366+ err = binary.Read(rd, binary.LittleEndian, header[:])
16367+ if err != nil {
16368+ return
16369+ }
16370+
16371+ if (header[1]+header[2])%2 != 0 {
16372+ // old quirk to align everything on word boundaries
16373+ header[2] += 1
16374+ }
16375+ str_offset = ti_header_length + header[1] + header[2] + 2*header[3]
16376+ table_offset = str_offset + 2*header[4]
16377+
16378+ keys = make([]string, 0xFFFF-key_min)
16379+ for i, _ := range keys {
16380+ keys[i], err = ti_read_string(rd, str_offset+2*ti_keys[i], table_offset)
16381+ if err != nil {
16382+ return
16383+ }
16384+ }
16385+ funcs = make([]string, t_max_funcs)
16386+ // the last two entries are reserved for mouse. because the table offset is
16387+ // not there, the two entries have to fill in manually
16388+ for i, _ := range funcs[:len(funcs)-2] {
16389+ funcs[i], err = ti_read_string(rd, str_offset+2*ti_funcs[i], table_offset)
16390+ if err != nil {
16391+ return
16392+ }
16393+ }
16394+ funcs[t_max_funcs-2] = ti_mouse_enter
16395+ funcs[t_max_funcs-1] = ti_mouse_leave
16396+ return nil
16397+ }
16398+
16399+ func ti_read_string(rd *bytes.Reader, str_off, table int16) (string, error) {
16400+ var off int16
16401+
16402+ _, err := rd.Seek(int64(str_off), 0)
16403+ if err != nil {
16404+ return "", err
16405+ }
16406+ err = binary.Read(rd, binary.LittleEndian, &off)
16407+ if err != nil {
16408+ return "", err
16409+ }
16410+ _, err = rd.Seek(int64(table+off), 0)
16411+ if err != nil {
16412+ return "", err
16413+ }
16414+ var bs []byte
16415+ for {
16416+ b, err := rd.ReadByte()
16417+ if err != nil {
16418+ return "", err
16419+ }
16420+ if b == byte(0x00) {
16421+ break
16422+ }
16423+ bs = append(bs, b)
16424+ }
16425+ return string(bs), nil
16426+ }
16427+
16428+ // "Maps" the function constants from termbox.go to the number of the respective
16429+ // string capability in the terminfo file. Taken from (ncurses) term.h.
16430+ var ti_funcs = []int16{
16431+ 28, 40, 16, 13, 5, 39, 36, 27, 26, 34, 89, 88,
16432+ }
16433+
16434+ // Same as above for the special keys.
16435+ var ti_keys = []int16{
16436+ 66, 68 /* apparently not a typo; 67 is F10 for whatever reason */, 69, 70,
16437+ 71, 72, 73, 74, 75, 67, 216, 217, 77, 59, 76, 164, 82, 81, 87, 61, 79, 83,
16438+ }
16439 diff --git a/vendor/github.com/nsf/termbox-go/terminfo_builtin.go b/vendor/github.com/nsf/termbox-go/terminfo_builtin.go
16440new file mode 100644
16441index 0000000..a948660
16442--- /dev/null
16443+++ b/vendor/github.com/nsf/termbox-go/terminfo_builtin.go
16444 @@ -0,0 +1,64 @@
16445+ // +build !windows
16446+
16447+ package termbox
16448+
16449+ // Eterm
16450+ var eterm_keys = []string{
16451+ "\x1b[11~", "\x1b[12~", "\x1b[13~", "\x1b[14~", "\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~", "\x1b[2~", "\x1b[3~", "\x1b[7~", "\x1b[8~", "\x1b[5~", "\x1b[6~", "\x1b[A", "\x1b[B", "\x1b[D", "\x1b[C",
16452+ }
16453+ var eterm_funcs = []string{
16454+ "\x1b7\x1b[?47h", "\x1b[2J\x1b[?47l\x1b8", "\x1b[?25h", "\x1b[?25l", "\x1b[H\x1b[2J", "\x1b[m\x0f", "\x1b[4m", "\x1b[1m", "\x1b[5m", "\x1b[7m", "", "", "", "",
16455+ }
16456+
16457+ // screen
16458+ var screen_keys = []string{
16459+ "\x1bOP", "\x1bOQ", "\x1bOR", "\x1bOS", "\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~", "\x1b[2~", "\x1b[3~", "\x1b[1~", "\x1b[4~", "\x1b[5~", "\x1b[6~", "\x1bOA", "\x1bOB", "\x1bOD", "\x1bOC",
16460+ }
16461+ var screen_funcs = []string{
16462+ "\x1b[?1049h", "\x1b[?1049l", "\x1b[34h\x1b[?25h", "\x1b[?25l", "\x1b[H\x1b[J", "\x1b[m\x0f", "\x1b[4m", "\x1b[1m", "\x1b[5m", "\x1b[7m", "\x1b[?1h\x1b=", "\x1b[?1l\x1b>", ti_mouse_enter, ti_mouse_leave,
16463+ }
16464+
16465+ // xterm
16466+ var xterm_keys = []string{
16467+ "\x1bOP", "\x1bOQ", "\x1bOR", "\x1bOS", "\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~", "\x1b[2~", "\x1b[3~", "\x1bOH", "\x1bOF", "\x1b[5~", "\x1b[6~", "\x1bOA", "\x1bOB", "\x1bOD", "\x1bOC",
16468+ }
16469+ var xterm_funcs = []string{
16470+ "\x1b[?1049h", "\x1b[?1049l", "\x1b[?12l\x1b[?25h", "\x1b[?25l", "\x1b[H\x1b[2J", "\x1b(B\x1b[m", "\x1b[4m", "\x1b[1m", "\x1b[5m", "\x1b[7m", "\x1b[?1h\x1b=", "\x1b[?1l\x1b>", ti_mouse_enter, ti_mouse_leave,
16471+ }
16472+
16473+ // rxvt-unicode
16474+ var rxvt_unicode_keys = []string{
16475+ "\x1b[11~", "\x1b[12~", "\x1b[13~", "\x1b[14~", "\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~", "\x1b[2~", "\x1b[3~", "\x1b[7~", "\x1b[8~", "\x1b[5~", "\x1b[6~", "\x1b[A", "\x1b[B", "\x1b[D", "\x1b[C",
16476+ }
16477+ var rxvt_unicode_funcs = []string{
16478+ "\x1b[?1049h", "\x1b[r\x1b[?1049l", "\x1b[?25h", "\x1b[?25l", "\x1b[H\x1b[2J", "\x1b[m\x1b(B", "\x1b[4m", "\x1b[1m", "\x1b[5m", "\x1b[7m", "\x1b=", "\x1b>", ti_mouse_enter, ti_mouse_leave,
16479+ }
16480+
16481+ // linux
16482+ var linux_keys = []string{
16483+ "\x1b[[A", "\x1b[[B", "\x1b[[C", "\x1b[[D", "\x1b[[E", "\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~", "\x1b[2~", "\x1b[3~", "\x1b[1~", "\x1b[4~", "\x1b[5~", "\x1b[6~", "\x1b[A", "\x1b[B", "\x1b[D", "\x1b[C",
16484+ }
16485+ var linux_funcs = []string{
16486+ "", "", "\x1b[?25h\x1b[?0c", "\x1b[?25l\x1b[?1c", "\x1b[H\x1b[J", "\x1b[0;10m", "\x1b[4m", "\x1b[1m", "\x1b[5m", "\x1b[7m", "", "", "", "",
16487+ }
16488+
16489+ // rxvt-256color
16490+ var rxvt_256color_keys = []string{
16491+ "\x1b[11~", "\x1b[12~", "\x1b[13~", "\x1b[14~", "\x1b[15~", "\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~", "\x1b[23~", "\x1b[24~", "\x1b[2~", "\x1b[3~", "\x1b[7~", "\x1b[8~", "\x1b[5~", "\x1b[6~", "\x1b[A", "\x1b[B", "\x1b[D", "\x1b[C",
16492+ }
16493+ var rxvt_256color_funcs = []string{
16494+ "\x1b7\x1b[?47h", "\x1b[2J\x1b[?47l\x1b8", "\x1b[?25h", "\x1b[?25l", "\x1b[H\x1b[2J", "\x1b[m\x0f", "\x1b[4m", "\x1b[1m", "\x1b[5m", "\x1b[7m", "\x1b=", "\x1b>", ti_mouse_enter, ti_mouse_leave,
16495+ }
16496+
16497+ var terms = []struct {
16498+ name string
16499+ keys []string
16500+ funcs []string
16501+ }{
16502+ {"Eterm", eterm_keys, eterm_funcs},
16503+ {"screen", screen_keys, screen_funcs},
16504+ {"xterm", xterm_keys, xterm_funcs},
16505+ {"rxvt-unicode", rxvt_unicode_keys, rxvt_unicode_funcs},
16506+ {"linux", linux_keys, linux_funcs},
16507+ {"rxvt-256color", rxvt_256color_keys, rxvt_256color_funcs},
16508+ }
16509 diff --git a/vendor/golang.org/x/sys/plan9/asm.s b/vendor/golang.org/x/sys/plan9/asm.s
16510deleted file mode 100644
16511index 06449eb..0000000
16512--- a/vendor/golang.org/x/sys/plan9/asm.s
16513+++ /dev/null
16514 @@ -1,8 +0,0 @@
16515- // Copyright 2014 The Go Authors. All rights reserved.
16516- // Use of this source code is governed by a BSD-style
16517- // license that can be found in the LICENSE file.
16518-
16519- #include "textflag.h"
16520-
16521- TEXT ·use(SB),NOSPLIT,$0
16522- RET
16523 diff --git a/vendor/golang.org/x/sys/plan9/asm_plan9_386.s b/vendor/golang.org/x/sys/plan9/asm_plan9_386.s
16524deleted file mode 100644
16525index bc5cab1..0000000
16526--- a/vendor/golang.org/x/sys/plan9/asm_plan9_386.s
16527+++ /dev/null
16528 @@ -1,30 +0,0 @@
16529- // Copyright 2009 The Go Authors. All rights reserved.
16530- // Use of this source code is governed by a BSD-style
16531- // license that can be found in the LICENSE file.
16532-
16533- #include "textflag.h"
16534-
16535- //
16536- // System call support for 386, Plan 9
16537- //
16538-
16539- // Just jump to package syscall's implementation for all these functions.
16540- // The runtime may know about them.
16541-
16542- TEXT ·Syscall(SB),NOSPLIT,$0-32
16543- JMP syscall·Syscall(SB)
16544-
16545- TEXT ·Syscall6(SB),NOSPLIT,$0-44
16546- JMP syscall·Syscall6(SB)
16547-
16548- TEXT ·RawSyscall(SB),NOSPLIT,$0-28
16549- JMP syscall·RawSyscall(SB)
16550-
16551- TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
16552- JMP syscall·RawSyscall6(SB)
16553-
16554- TEXT ·seek(SB),NOSPLIT,$0-36
16555- JMP syscall·seek(SB)
16556-
16557- TEXT ·exit(SB),NOSPLIT,$4-4
16558- JMP syscall·exit(SB)
16559 diff --git a/vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s b/vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s
16560deleted file mode 100644
16561index d3448e6..0000000
16562--- a/vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s
16563+++ /dev/null
16564 @@ -1,30 +0,0 @@
16565- // Copyright 2009 The Go Authors. All rights reserved.
16566- // Use of this source code is governed by a BSD-style
16567- // license that can be found in the LICENSE file.
16568-
16569- #include "textflag.h"
16570-
16571- //
16572- // System call support for amd64, Plan 9
16573- //
16574-
16575- // Just jump to package syscall's implementation for all these functions.
16576- // The runtime may know about them.
16577-
16578- TEXT ·Syscall(SB),NOSPLIT,$0-64
16579- JMP syscall·Syscall(SB)
16580-
16581- TEXT ·Syscall6(SB),NOSPLIT,$0-88
16582- JMP syscall·Syscall6(SB)
16583-
16584- TEXT ·RawSyscall(SB),NOSPLIT,$0-56
16585- JMP syscall·RawSyscall(SB)
16586-
16587- TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
16588- JMP syscall·RawSyscall6(SB)
16589-
16590- TEXT ·seek(SB),NOSPLIT,$0-56
16591- JMP syscall·seek(SB)
16592-
16593- TEXT ·exit(SB),NOSPLIT,$8-8
16594- JMP syscall·exit(SB)
16595 diff --git a/vendor/golang.org/x/sys/plan9/const_plan9.go b/vendor/golang.org/x/sys/plan9/const_plan9.go
16596deleted file mode 100644
16597index b4e85a3..0000000
16598--- a/vendor/golang.org/x/sys/plan9/const_plan9.go
16599+++ /dev/null
16600 @@ -1,70 +0,0 @@
16601- package plan9
16602-
16603- // Plan 9 Constants
16604-
16605- // Open modes
16606- const (
16607- O_RDONLY = 0
16608- O_WRONLY = 1
16609- O_RDWR = 2
16610- O_TRUNC = 16
16611- O_CLOEXEC = 32
16612- O_EXCL = 0x1000
16613- )
16614-
16615- // Rfork flags
16616- const (
16617- RFNAMEG = 1 << 0
16618- RFENVG = 1 << 1
16619- RFFDG = 1 << 2
16620- RFNOTEG = 1 << 3
16621- RFPROC = 1 << 4
16622- RFMEM = 1 << 5
16623- RFNOWAIT = 1 << 6
16624- RFCNAMEG = 1 << 10
16625- RFCENVG = 1 << 11
16626- RFCFDG = 1 << 12
16627- RFREND = 1 << 13
16628- RFNOMNT = 1 << 14
16629- )
16630-
16631- // Qid.Type bits
16632- const (
16633- QTDIR = 0x80
16634- QTAPPEND = 0x40
16635- QTEXCL = 0x20
16636- QTMOUNT = 0x10
16637- QTAUTH = 0x08
16638- QTTMP = 0x04
16639- QTFILE = 0x00
16640- )
16641-
16642- // Dir.Mode bits
16643- const (
16644- DMDIR = 0x80000000
16645- DMAPPEND = 0x40000000
16646- DMEXCL = 0x20000000
16647- DMMOUNT = 0x10000000
16648- DMAUTH = 0x08000000
16649- DMTMP = 0x04000000
16650- DMREAD = 0x4
16651- DMWRITE = 0x2
16652- DMEXEC = 0x1
16653- )
16654-
16655- const (
16656- STATMAX = 65535
16657- ERRMAX = 128
16658- STATFIXLEN = 49
16659- )
16660-
16661- // Mount and bind flags
16662- const (
16663- MREPL = 0x0000
16664- MBEFORE = 0x0001
16665- MAFTER = 0x0002
16666- MORDER = 0x0003
16667- MCREATE = 0x0004
16668- MCACHE = 0x0010
16669- MMASK = 0x0017
16670- )
16671 diff --git a/vendor/golang.org/x/sys/plan9/dir_plan9.go b/vendor/golang.org/x/sys/plan9/dir_plan9.go
16672deleted file mode 100644
16673index 0955e0c..0000000
16674--- a/vendor/golang.org/x/sys/plan9/dir_plan9.go
16675+++ /dev/null
16676 @@ -1,212 +0,0 @@
16677- // Copyright 2012 The Go Authors. All rights reserved.
16678- // Use of this source code is governed by a BSD-style
16679- // license that can be found in the LICENSE file.
16680-
16681- // Plan 9 directory marshalling. See intro(5).
16682-
16683- package plan9
16684-
16685- import "errors"
16686-
16687- var (
16688- ErrShortStat = errors.New("stat buffer too short")
16689- ErrBadStat = errors.New("malformed stat buffer")
16690- ErrBadName = errors.New("bad character in file name")
16691- )
16692-
16693- // A Qid represents a 9P server's unique identification for a file.
16694- type Qid struct {
16695- Path uint64 // the file server's unique identification for the file
16696- Vers uint32 // version number for given Path
16697- Type uint8 // the type of the file (plan9.QTDIR for example)
16698- }
16699-
16700- // A Dir contains the metadata for a file.
16701- type Dir struct {
16702- // system-modified data
16703- Type uint16 // server type
16704- Dev uint32 // server subtype
16705-
16706- // file data
16707- Qid Qid // unique id from server
16708- Mode uint32 // permissions
16709- Atime uint32 // last read time
16710- Mtime uint32 // last write time
16711- Length int64 // file length
16712- Name string // last element of path
16713- Uid string // owner name
16714- Gid string // group name
16715- Muid string // last modifier name
16716- }
16717-
16718- var nullDir = Dir{
16719- Type: ^uint16(0),
16720- Dev: ^uint32(0),
16721- Qid: Qid{
16722- Path: ^uint64(0),
16723- Vers: ^uint32(0),
16724- Type: ^uint8(0),
16725- },
16726- Mode: ^uint32(0),
16727- Atime: ^uint32(0),
16728- Mtime: ^uint32(0),
16729- Length: ^int64(0),
16730- }
16731-
16732- // Null assigns special "don't touch" values to members of d to
16733- // avoid modifying them during plan9.Wstat.
16734- func (d *Dir) Null() { *d = nullDir }
16735-
16736- // Marshal encodes a 9P stat message corresponding to d into b
16737- //
16738- // If there isn't enough space in b for a stat message, ErrShortStat is returned.
16739- func (d *Dir) Marshal(b []byte) (n int, err error) {
16740- n = STATFIXLEN + len(d.Name) + len(d.Uid) + len(d.Gid) + len(d.Muid)
16741- if n > len(b) {
16742- return n, ErrShortStat
16743- }
16744-
16745- for _, c := range d.Name {
16746- if c == '/' {
16747- return n, ErrBadName
16748- }
16749- }
16750-
16751- b = pbit16(b, uint16(n)-2)
16752- b = pbit16(b, d.Type)
16753- b = pbit32(b, d.Dev)
16754- b = pbit8(b, d.Qid.Type)
16755- b = pbit32(b, d.Qid.Vers)
16756- b = pbit64(b, d.Qid.Path)
16757- b = pbit32(b, d.Mode)
16758- b = pbit32(b, d.Atime)
16759- b = pbit32(b, d.Mtime)
16760- b = pbit64(b, uint64(d.Length))
16761- b = pstring(b, d.Name)
16762- b = pstring(b, d.Uid)
16763- b = pstring(b, d.Gid)
16764- b = pstring(b, d.Muid)
16765-
16766- return n, nil
16767- }
16768-
16769- // UnmarshalDir decodes a single 9P stat message from b and returns the resulting Dir.
16770- //
16771- // If b is too small to hold a valid stat message, ErrShortStat is returned.
16772- //
16773- // If the stat message itself is invalid, ErrBadStat is returned.
16774- func UnmarshalDir(b []byte) (*Dir, error) {
16775- if len(b) < STATFIXLEN {
16776- return nil, ErrShortStat
16777- }
16778- size, buf := gbit16(b)
16779- if len(b) != int(size)+2 {
16780- return nil, ErrBadStat
16781- }
16782- b = buf
16783-
16784- var d Dir
16785- d.Type, b = gbit16(b)
16786- d.Dev, b = gbit32(b)
16787- d.Qid.Type, b = gbit8(b)
16788- d.Qid.Vers, b = gbit32(b)
16789- d.Qid.Path, b = gbit64(b)
16790- d.Mode, b = gbit32(b)
16791- d.Atime, b = gbit32(b)
16792- d.Mtime, b = gbit32(b)
16793-
16794- n, b := gbit64(b)
16795- d.Length = int64(n)
16796-
16797- var ok bool
16798- if d.Name, b, ok = gstring(b); !ok {
16799- return nil, ErrBadStat
16800- }
16801- if d.Uid, b, ok = gstring(b); !ok {
16802- return nil, ErrBadStat
16803- }
16804- if d.Gid, b, ok = gstring(b); !ok {
16805- return nil, ErrBadStat
16806- }
16807- if d.Muid, b, ok = gstring(b); !ok {
16808- return nil, ErrBadStat
16809- }
16810-
16811- return &d, nil
16812- }
16813-
16814- // pbit8 copies the 8-bit number v to b and returns the remaining slice of b.
16815- func pbit8(b []byte, v uint8) []byte {
16816- b[0] = byte(v)
16817- return b[1:]
16818- }
16819-
16820- // pbit16 copies the 16-bit number v to b in little-endian order and returns the remaining slice of b.
16821- func pbit16(b []byte, v uint16) []byte {
16822- b[0] = byte(v)
16823- b[1] = byte(v >> 8)
16824- return b[2:]
16825- }
16826-
16827- // pbit32 copies the 32-bit number v to b in little-endian order and returns the remaining slice of b.
16828- func pbit32(b []byte, v uint32) []byte {
16829- b[0] = byte(v)
16830- b[1] = byte(v >> 8)
16831- b[2] = byte(v >> 16)
16832- b[3] = byte(v >> 24)
16833- return b[4:]
16834- }
16835-
16836- // pbit64 copies the 64-bit number v to b in little-endian order and returns the remaining slice of b.
16837- func pbit64(b []byte, v uint64) []byte {
16838- b[0] = byte(v)
16839- b[1] = byte(v >> 8)
16840- b[2] = byte(v >> 16)
16841- b[3] = byte(v >> 24)
16842- b[4] = byte(v >> 32)
16843- b[5] = byte(v >> 40)
16844- b[6] = byte(v >> 48)
16845- b[7] = byte(v >> 56)
16846- return b[8:]
16847- }
16848-
16849- // pstring copies the string s to b, prepending it with a 16-bit length in little-endian order, and
16850- // returning the remaining slice of b..
16851- func pstring(b []byte, s string) []byte {
16852- b = pbit16(b, uint16(len(s)))
16853- n := copy(b, s)
16854- return b[n:]
16855- }
16856-
16857- // gbit8 reads an 8-bit number from b and returns it with the remaining slice of b.
16858- func gbit8(b []byte) (uint8, []byte) {
16859- return uint8(b[0]), b[1:]
16860- }
16861-
16862- // gbit16 reads a 16-bit number in little-endian order from b and returns it with the remaining slice of b.
16863- func gbit16(b []byte) (uint16, []byte) {
16864- return uint16(b[0]) | uint16(b[1])<<8, b[2:]
16865- }
16866-
16867- // gbit32 reads a 32-bit number in little-endian order from b and returns it with the remaining slice of b.
16868- func gbit32(b []byte) (uint32, []byte) {
16869- return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24, b[4:]
16870- }
16871-
16872- // gbit64 reads a 64-bit number in little-endian order from b and returns it with the remaining slice of b.
16873- func gbit64(b []byte) (uint64, []byte) {
16874- lo := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
16875- hi := uint32(b[4]) | uint32(b[5])<<8 | uint32(b[6])<<16 | uint32(b[7])<<24
16876- return uint64(lo) | uint64(hi)<<32, b[8:]
16877- }
16878-
16879- // gstring reads a string from b, prefixed with a 16-bit length in little-endian order.
16880- // It returns the string with the remaining slice of b and a boolean. If the length is
16881- // greater than the number of bytes in b, the boolean will be false.
16882- func gstring(b []byte) (string, []byte, bool) {
16883- n, b := gbit16(b)
16884- if int(n) > len(b) {
16885- return "", b, false
16886- }
16887- return string(b[:n]), b[n:], true
16888- }
16889 diff --git a/vendor/golang.org/x/sys/plan9/env_plan9.go b/vendor/golang.org/x/sys/plan9/env_plan9.go
16890deleted file mode 100644
16891index 8f19180..0000000
16892--- a/vendor/golang.org/x/sys/plan9/env_plan9.go
16893+++ /dev/null
16894 @@ -1,31 +0,0 @@
16895- // Copyright 2011 The Go Authors. All rights reserved.
16896- // Use of this source code is governed by a BSD-style
16897- // license that can be found in the LICENSE file.
16898-
16899- // Plan 9 environment variables.
16900-
16901- package plan9
16902-
16903- import (
16904- "syscall"
16905- )
16906-
16907- func Getenv(key string) (value string, found bool) {
16908- return syscall.Getenv(key)
16909- }
16910-
16911- func Setenv(key, value string) error {
16912- return syscall.Setenv(key, value)
16913- }
16914-
16915- func Clearenv() {
16916- syscall.Clearenv()
16917- }
16918-
16919- func Environ() []string {
16920- return syscall.Environ()
16921- }
16922-
16923- func Unsetenv(key string) error {
16924- return syscall.Unsetenv(key)
16925- }
16926 diff --git a/vendor/golang.org/x/sys/plan9/errors_plan9.go b/vendor/golang.org/x/sys/plan9/errors_plan9.go
16927deleted file mode 100644
16928index 65fe74d..0000000
16929--- a/vendor/golang.org/x/sys/plan9/errors_plan9.go
16930+++ /dev/null
16931 @@ -1,50 +0,0 @@
16932- // Copyright 2011 The Go Authors. All rights reserved.
16933- // Use of this source code is governed by a BSD-style
16934- // license that can be found in the LICENSE file.
16935-
16936- package plan9
16937-
16938- import "syscall"
16939-
16940- // Constants
16941- const (
16942- // Invented values to support what package os expects.
16943- O_CREAT = 0x02000
16944- O_APPEND = 0x00400
16945- O_NOCTTY = 0x00000
16946- O_NONBLOCK = 0x00000
16947- O_SYNC = 0x00000
16948- O_ASYNC = 0x00000
16949-
16950- S_IFMT = 0x1f000
16951- S_IFIFO = 0x1000
16952- S_IFCHR = 0x2000
16953- S_IFDIR = 0x4000
16954- S_IFBLK = 0x6000
16955- S_IFREG = 0x8000
16956- S_IFLNK = 0xa000
16957- S_IFSOCK = 0xc000
16958- )
16959-
16960- // Errors
16961- var (
16962- EINVAL = syscall.NewError("bad arg in system call")
16963- ENOTDIR = syscall.NewError("not a directory")
16964- EISDIR = syscall.NewError("file is a directory")
16965- ENOENT = syscall.NewError("file does not exist")
16966- EEXIST = syscall.NewError("file already exists")
16967- EMFILE = syscall.NewError("no free file descriptors")
16968- EIO = syscall.NewError("i/o error")
16969- ENAMETOOLONG = syscall.NewError("file name too long")
16970- EINTR = syscall.NewError("interrupted")
16971- EPERM = syscall.NewError("permission denied")
16972- EBUSY = syscall.NewError("no free devices")
16973- ETIMEDOUT = syscall.NewError("connection timed out")
16974- EPLAN9 = syscall.NewError("not supported by plan 9")
16975-
16976- // The following errors do not correspond to any
16977- // Plan 9 system messages. Invented to support
16978- // what package os and others expect.
16979- EACCES = syscall.NewError("access permission denied")
16980- EAFNOSUPPORT = syscall.NewError("address family not supported by protocol")
16981- )
16982 diff --git a/vendor/golang.org/x/sys/plan9/mkall.sh b/vendor/golang.org/x/sys/plan9/mkall.sh
16983deleted file mode 100755
16984index 9f73c60..0000000
16985--- a/vendor/golang.org/x/sys/plan9/mkall.sh
16986+++ /dev/null
16987 @@ -1,138 +0,0 @@
16988- #!/usr/bin/env bash
16989- # Copyright 2009 The Go Authors. All rights reserved.
16990- # Use of this source code is governed by a BSD-style
16991- # license that can be found in the LICENSE file.
16992-
16993- # The plan9 package provides access to the raw system call
16994- # interface of the underlying operating system. Porting Go to
16995- # a new architecture/operating system combination requires
16996- # some manual effort, though there are tools that automate
16997- # much of the process. The auto-generated files have names
16998- # beginning with z.
16999- #
17000- # This script runs or (given -n) prints suggested commands to generate z files
17001- # for the current system. Running those commands is not automatic.
17002- # This script is documentation more than anything else.
17003- #
17004- # * asm_${GOOS}_${GOARCH}.s
17005- #
17006- # This hand-written assembly file implements system call dispatch.
17007- # There are three entry points:
17008- #
17009- # func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
17010- # func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
17011- # func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
17012- #
17013- # The first and second are the standard ones; they differ only in
17014- # how many arguments can be passed to the kernel.
17015- # The third is for low-level use by the ForkExec wrapper;
17016- # unlike the first two, it does not call into the scheduler to
17017- # let it know that a system call is running.
17018- #
17019- # * syscall_${GOOS}.go
17020- #
17021- # This hand-written Go file implements system calls that need
17022- # special handling and lists "//sys" comments giving prototypes
17023- # for ones that can be auto-generated. Mksyscall reads those
17024- # comments to generate the stubs.
17025- #
17026- # * syscall_${GOOS}_${GOARCH}.go
17027- #
17028- # Same as syscall_${GOOS}.go except that it contains code specific
17029- # to ${GOOS} on one particular architecture.
17030- #
17031- # * types_${GOOS}.c
17032- #
17033- # This hand-written C file includes standard C headers and then
17034- # creates typedef or enum names beginning with a dollar sign
17035- # (use of $ in variable names is a gcc extension). The hardest
17036- # part about preparing this file is figuring out which headers to
17037- # include and which symbols need to be #defined to get the
17038- # actual data structures that pass through to the kernel system calls.
17039- # Some C libraries present alternate versions for binary compatibility
17040- # and translate them on the way in and out of system calls, but
17041- # there is almost always a #define that can get the real ones.
17042- # See types_darwin.c and types_linux.c for examples.
17043- #
17044- # * zerror_${GOOS}_${GOARCH}.go
17045- #
17046- # This machine-generated file defines the system's error numbers,
17047- # error strings, and signal numbers. The generator is "mkerrors.sh".
17048- # Usually no arguments are needed, but mkerrors.sh will pass its
17049- # arguments on to godefs.
17050- #
17051- # * zsyscall_${GOOS}_${GOARCH}.go
17052- #
17053- # Generated by mksyscall.pl; see syscall_${GOOS}.go above.
17054- #
17055- # * zsysnum_${GOOS}_${GOARCH}.go
17056- #
17057- # Generated by mksysnum_${GOOS}.
17058- #
17059- # * ztypes_${GOOS}_${GOARCH}.go
17060- #
17061- # Generated by godefs; see types_${GOOS}.c above.
17062-
17063- GOOSARCH="${GOOS}_${GOARCH}"
17064-
17065- # defaults
17066- mksyscall="./mksyscall.pl"
17067- mkerrors="./mkerrors.sh"
17068- zerrors="zerrors_$GOOSARCH.go"
17069- mksysctl=""
17070- zsysctl="zsysctl_$GOOSARCH.go"
17071- mksysnum=
17072- mktypes=
17073- run="sh"
17074-
17075- case "$1" in
17076- -syscalls)
17077- for i in zsyscall*go
17078- do
17079- sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
17080- rm _$i
17081- done
17082- exit 0
17083- ;;
17084- -n)
17085- run="cat"
17086- shift
17087- esac
17088-
17089- case "$#" in
17090- 0)
17091- ;;
17092- *)
17093- echo 'usage: mkall.sh [-n]' 1>&2
17094- exit 2
17095- esac
17096-
17097- case "$GOOSARCH" in
17098- _* | *_ | _)
17099- echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
17100- exit 1
17101- ;;
17102- plan9_386)
17103- mkerrors=
17104- mksyscall="./mksyscall.pl -l32 -plan9"
17105- mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
17106- mktypes="XXX"
17107- ;;
17108- *)
17109- echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
17110- exit 1
17111- ;;
17112- esac
17113-
17114- (
17115- if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
17116- case "$GOOS" in
17117- plan9)
17118- syscall_goos="syscall_$GOOS.go"
17119- if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi
17120- ;;
17121- esac
17122- if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
17123- if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
17124- if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |gofmt >ztypes_$GOOSARCH.go"; fi
17125- ) | $run
17126 diff --git a/vendor/golang.org/x/sys/plan9/mkerrors.sh b/vendor/golang.org/x/sys/plan9/mkerrors.sh
17127deleted file mode 100755
17128index 052c86d..0000000
17129--- a/vendor/golang.org/x/sys/plan9/mkerrors.sh
17130+++ /dev/null
17131 @@ -1,246 +0,0 @@
17132- #!/usr/bin/env bash
17133- # Copyright 2009 The Go Authors. All rights reserved.
17134- # Use of this source code is governed by a BSD-style
17135- # license that can be found in the LICENSE file.
17136-
17137- # Generate Go code listing errors and other #defined constant
17138- # values (ENAMETOOLONG etc.), by asking the preprocessor
17139- # about the definitions.
17140-
17141- unset LANG
17142- export LC_ALL=C
17143- export LC_CTYPE=C
17144-
17145- CC=${CC:-gcc}
17146-
17147- uname=$(uname)
17148-
17149- includes='
17150- #include <sys/types.h>
17151- #include <sys/file.h>
17152- #include <fcntl.h>
17153- #include <dirent.h>
17154- #include <sys/socket.h>
17155- #include <netinet/in.h>
17156- #include <netinet/ip.h>
17157- #include <netinet/ip6.h>
17158- #include <netinet/tcp.h>
17159- #include <errno.h>
17160- #include <sys/signal.h>
17161- #include <signal.h>
17162- #include <sys/resource.h>
17163- '
17164-
17165- ccflags="$@"
17166-
17167- # Write go tool cgo -godefs input.
17168- (
17169- echo package plan9
17170- echo
17171- echo '/*'
17172- indirect="includes_$(uname)"
17173- echo "${!indirect} $includes"
17174- echo '*/'
17175- echo 'import "C"'
17176- echo
17177- echo 'const ('
17178-
17179- # The gcc command line prints all the #defines
17180- # it encounters while processing the input
17181- echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags |
17182- awk '
17183- $1 != "#define" || $2 ~ /\(/ || $3 == "" {next}
17184-
17185- $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers
17186- $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next}
17187- $2 ~ /^(SCM_SRCRT)$/ {next}
17188- $2 ~ /^(MAP_FAILED)$/ {next}
17189-
17190- $2 !~ /^ETH_/ &&
17191- $2 !~ /^EPROC_/ &&
17192- $2 !~ /^EQUIV_/ &&
17193- $2 !~ /^EXPR_/ &&
17194- $2 ~ /^E[A-Z0-9_]+$/ ||
17195- $2 ~ /^B[0-9_]+$/ ||
17196- $2 ~ /^V[A-Z0-9]+$/ ||
17197- $2 ~ /^CS[A-Z0-9]/ ||
17198- $2 ~ /^I(SIG|CANON|CRNL|EXTEN|MAXBEL|STRIP|UTF8)$/ ||
17199- $2 ~ /^IGN/ ||
17200- $2 ~ /^IX(ON|ANY|OFF)$/ ||
17201- $2 ~ /^IN(LCR|PCK)$/ ||
17202- $2 ~ /(^FLU?SH)|(FLU?SH$)/ ||
17203- $2 ~ /^C(LOCAL|READ)$/ ||
17204- $2 == "BRKINT" ||
17205- $2 == "HUPCL" ||
17206- $2 == "PENDIN" ||
17207- $2 == "TOSTOP" ||
17208- $2 ~ /^PAR/ ||
17209- $2 ~ /^SIG[^_]/ ||
17210- $2 ~ /^O[CNPFP][A-Z]+[^_][A-Z]+$/ ||
17211- $2 ~ /^IN_/ ||
17212- $2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
17213- $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ ||
17214- $2 == "ICMPV6_FILTER" ||
17215- $2 == "SOMAXCONN" ||
17216- $2 == "NAME_MAX" ||
17217- $2 == "IFNAMSIZ" ||
17218- $2 ~ /^CTL_(MAXNAME|NET|QUERY)$/ ||
17219- $2 ~ /^SYSCTL_VERS/ ||
17220- $2 ~ /^(MS|MNT)_/ ||
17221- $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
17222- $2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ ||
17223- $2 ~ /^LINUX_REBOOT_CMD_/ ||
17224- $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ ||
17225- $2 !~ "NLA_TYPE_MASK" &&
17226- $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ ||
17227- $2 ~ /^SIOC/ ||
17228- $2 ~ /^TIOC/ ||
17229- $2 !~ "RTF_BITS" &&
17230- $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ ||
17231- $2 ~ /^BIOC/ ||
17232- $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ ||
17233- $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ ||
17234- $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ ||
17235- $2 ~ /^CLONE_[A-Z_]+/ ||
17236- $2 !~ /^(BPF_TIMEVAL)$/ &&
17237- $2 ~ /^(BPF|DLT)_/ ||
17238- $2 !~ "WMESGLEN" &&
17239- $2 ~ /^W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", $2, $2)}
17240- $2 ~ /^__WCOREFLAG$/ {next}
17241- $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)}
17242-
17243- {next}
17244- ' | sort
17245-
17246- echo ')'
17247- ) >_const.go
17248-
17249- # Pull out the error names for later.
17250- errors=$(
17251- echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
17252- awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
17253- sort
17254- )
17255-
17256- # Pull out the signal names for later.
17257- signals=$(
17258- echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
17259- awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
17260- egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' |
17261- sort
17262- )
17263-
17264- # Again, writing regexps to a file.
17265- echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
17266- awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' |
17267- sort >_error.grep
17268- echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
17269- awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' |
17270- egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' |
17271- sort >_signal.grep
17272-
17273- echo '// mkerrors.sh' "$@"
17274- echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT'
17275- echo
17276- go tool cgo -godefs -- "$@" _const.go >_error.out
17277- cat _error.out | grep -vf _error.grep | grep -vf _signal.grep
17278- echo
17279- echo '// Errors'
17280- echo 'const ('
17281- cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/'
17282- echo ')'
17283-
17284- echo
17285- echo '// Signals'
17286- echo 'const ('
17287- cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= Signal(\1)/'
17288- echo ')'
17289-
17290- # Run C program to print error and syscall strings.
17291- (
17292- echo -E "
17293- #include <stdio.h>
17294- #include <stdlib.h>
17295- #include <errno.h>
17296- #include <ctype.h>
17297- #include <string.h>
17298- #include <signal.h>
17299-
17300- #define nelem(x) (sizeof(x)/sizeof((x)[0]))
17301-
17302- enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below
17303-
17304- int errors[] = {
17305- "
17306- for i in $errors
17307- do
17308- echo -E ' '$i,
17309- done
17310-
17311- echo -E "
17312- };
17313-
17314- int signals[] = {
17315- "
17316- for i in $signals
17317- do
17318- echo -E ' '$i,
17319- done
17320-
17321- # Use -E because on some systems bash builtin interprets \n itself.
17322- echo -E '
17323- };
17324-
17325- static int
17326- intcmp(const void *a, const void *b)
17327- {
17328- return *(int*)a - *(int*)b;
17329- }
17330-
17331- int
17332- main(void)
17333- {
17334- int i, j, e;
17335- char buf[1024], *p;
17336-
17337- printf("\n\n// Error table\n");
17338- printf("var errors = [...]string {\n");
17339- qsort(errors, nelem(errors), sizeof errors[0], intcmp);
17340- for(i=0; i<nelem(errors); i++) {
17341- e = errors[i];
17342- if(i > 0 && errors[i-1] == e)
17343- continue;
17344- strcpy(buf, strerror(e));
17345- // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
17346- if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
17347- buf[0] += a - A;
17348- printf("\t%d: \"%s\",\n", e, buf);
17349- }
17350- printf("}\n\n");
17351-
17352- printf("\n\n// Signal table\n");
17353- printf("var signals = [...]string {\n");
17354- qsort(signals, nelem(signals), sizeof signals[0], intcmp);
17355- for(i=0; i<nelem(signals); i++) {
17356- e = signals[i];
17357- if(i > 0 && signals[i-1] == e)
17358- continue;
17359- strcpy(buf, strsignal(e));
17360- // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
17361- if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
17362- buf[0] += a - A;
17363- // cut trailing : number.
17364- p = strrchr(buf, ":"[0]);
17365- if(p)
17366- *p = '\0';
17367- printf("\t%d: \"%s\",\n", e, buf);
17368- }
17369- printf("}\n\n");
17370-
17371- return 0;
17372- }
17373-
17374- '
17375- ) >_errors.c
17376-
17377- $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out
17378 diff --git a/vendor/golang.org/x/sys/plan9/mksyscall.pl b/vendor/golang.org/x/sys/plan9/mksyscall.pl
17379deleted file mode 100755
17380index ce8e1e4..0000000
17381--- a/vendor/golang.org/x/sys/plan9/mksyscall.pl
17382+++ /dev/null
17383 @@ -1,319 +0,0 @@
17384- #!/usr/bin/env perl
17385- # Copyright 2009 The Go Authors. All rights reserved.
17386- # Use of this source code is governed by a BSD-style
17387- # license that can be found in the LICENSE file.
17388-
17389- # This program reads a file containing function prototypes
17390- # (like syscall_plan9.go) and generates system call bodies.
17391- # The prototypes are marked by lines beginning with "//sys"
17392- # and read like func declarations if //sys is replaced by func, but:
17393- # * The parameter lists must give a name for each argument.
17394- # This includes return parameters.
17395- # * The parameter lists must give a type for each argument:
17396- # the (x, y, z int) shorthand is not allowed.
17397- # * If the return parameter is an error number, it must be named errno.
17398-
17399- # A line beginning with //sysnb is like //sys, except that the
17400- # goroutine will not be suspended during the execution of the system
17401- # call. This must only be used for system calls which can never
17402- # block, as otherwise the system call could cause all goroutines to
17403- # hang.
17404-
17405- use strict;
17406-
17407- my $cmdline = "mksyscall.pl " . join(' ', @ARGV);
17408- my $errors = 0;
17409- my $_32bit = "";
17410- my $plan9 = 0;
17411- my $openbsd = 0;
17412- my $netbsd = 0;
17413- my $dragonfly = 0;
17414- my $nacl = 0;
17415- my $arm = 0; # 64-bit value should use (even, odd)-pair
17416-
17417- if($ARGV[0] eq "-b32") {
17418- $_32bit = "big-endian";
17419- shift;
17420- } elsif($ARGV[0] eq "-l32") {
17421- $_32bit = "little-endian";
17422- shift;
17423- }
17424- if($ARGV[0] eq "-plan9") {
17425- $plan9 = 1;
17426- shift;
17427- }
17428- if($ARGV[0] eq "-openbsd") {
17429- $openbsd = 1;
17430- shift;
17431- }
17432- if($ARGV[0] eq "-netbsd") {
17433- $netbsd = 1;
17434- shift;
17435- }
17436- if($ARGV[0] eq "-dragonfly") {
17437- $dragonfly = 1;
17438- shift;
17439- }
17440- if($ARGV[0] eq "-nacl") {
17441- $nacl = 1;
17442- shift;
17443- }
17444- if($ARGV[0] eq "-arm") {
17445- $arm = 1;
17446- shift;
17447- }
17448-
17449- if($ARGV[0] =~ /^-/) {
17450- print STDERR "usage: mksyscall.pl [-b32 | -l32] [file ...]\n";
17451- exit 1;
17452- }
17453-
17454- sub parseparamlist($) {
17455- my ($list) = @_;
17456- $list =~ s/^\s*//;
17457- $list =~ s/\s*$//;
17458- if($list eq "") {
17459- return ();
17460- }
17461- return split(/\s*,\s*/, $list);
17462- }
17463-
17464- sub parseparam($) {
17465- my ($p) = @_;
17466- if($p !~ /^(\S*) (\S*)$/) {
17467- print STDERR "$ARGV:$.: malformed parameter: $p\n";
17468- $errors = 1;
17469- return ("xx", "int");
17470- }
17471- return ($1, $2);
17472- }
17473-
17474- my $text = "";
17475- while(<>) {
17476- chomp;
17477- s/\s+/ /g;
17478- s/^\s+//;
17479- s/\s+$//;
17480- my $nonblock = /^\/\/sysnb /;
17481- next if !/^\/\/sys / && !$nonblock;
17482-
17483- # Line must be of the form
17484- # func Open(path string, mode int, perm int) (fd int, errno error)
17485- # Split into name, in params, out params.
17486- if(!/^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$/) {
17487- print STDERR "$ARGV:$.: malformed //sys declaration\n";
17488- $errors = 1;
17489- next;
17490- }
17491- my ($func, $in, $out, $sysname) = ($2, $3, $4, $5);
17492-
17493- # Split argument lists on comma.
17494- my @in = parseparamlist($in);
17495- my @out = parseparamlist($out);
17496-
17497- # Try in vain to keep people from editing this file.
17498- # The theory is that they jump into the middle of the file
17499- # without reading the header.
17500- $text .= "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n";
17501-
17502- # Go function header.
17503- my $out_decl = @out ? sprintf(" (%s)", join(', ', @out)) : "";
17504- $text .= sprintf "func %s(%s)%s {\n", $func, join(', ', @in), $out_decl;
17505-
17506- # Check if err return available
17507- my $errvar = "";
17508- foreach my $p (@out) {
17509- my ($name, $type) = parseparam($p);
17510- if($type eq "error") {
17511- $errvar = $name;
17512- last;
17513- }
17514- }
17515-
17516- # Prepare arguments to Syscall.
17517- my @args = ();
17518- my @uses = ();
17519- my $n = 0;
17520- foreach my $p (@in) {
17521- my ($name, $type) = parseparam($p);
17522- if($type =~ /^\*/) {
17523- push @args, "uintptr(unsafe.Pointer($name))";
17524- } elsif($type eq "string" && $errvar ne "") {
17525- $text .= "\tvar _p$n *byte\n";
17526- $text .= "\t_p$n, $errvar = BytePtrFromString($name)\n";
17527- $text .= "\tif $errvar != nil {\n\t\treturn\n\t}\n";
17528- push @args, "uintptr(unsafe.Pointer(_p$n))";
17529- push @uses, "use(unsafe.Pointer(_p$n))";
17530- $n++;
17531- } elsif($type eq "string") {
17532- print STDERR "$ARGV:$.: $func uses string arguments, but has no error return\n";
17533- $text .= "\tvar _p$n *byte\n";
17534- $text .= "\t_p$n, _ = BytePtrFromString($name)\n";
17535- push @args, "uintptr(unsafe.Pointer(_p$n))";
17536- push @uses, "use(unsafe.Pointer(_p$n))";
17537- $n++;
17538- } elsif($type =~ /^\[\](.*)/) {
17539- # Convert slice into pointer, length.
17540- # Have to be careful not to take address of &a[0] if len == 0:
17541- # pass dummy pointer in that case.
17542- # Used to pass nil, but some OSes or simulators reject write(fd, nil, 0).
17543- $text .= "\tvar _p$n unsafe.Pointer\n";
17544- $text .= "\tif len($name) > 0 {\n\t\t_p$n = unsafe.Pointer(\&${name}[0])\n\t}";
17545- $text .= " else {\n\t\t_p$n = unsafe.Pointer(&_zero)\n\t}";
17546- $text .= "\n";
17547- push @args, "uintptr(_p$n)", "uintptr(len($name))";
17548- $n++;
17549- } elsif($type eq "int64" && ($openbsd || $netbsd)) {
17550- push @args, "0";
17551- if($_32bit eq "big-endian") {
17552- push @args, "uintptr($name>>32)", "uintptr($name)";
17553- } elsif($_32bit eq "little-endian") {
17554- push @args, "uintptr($name)", "uintptr($name>>32)";
17555- } else {
17556- push @args, "uintptr($name)";
17557- }
17558- } elsif($type eq "int64" && $dragonfly) {
17559- if ($func !~ /^extp(read|write)/i) {
17560- push @args, "0";
17561- }
17562- if($_32bit eq "big-endian") {
17563- push @args, "uintptr($name>>32)", "uintptr($name)";
17564- } elsif($_32bit eq "little-endian") {
17565- push @args, "uintptr($name)", "uintptr($name>>32)";
17566- } else {
17567- push @args, "uintptr($name)";
17568- }
17569- } elsif($type eq "int64" && $_32bit ne "") {
17570- if(@args % 2 && $arm) {
17571- # arm abi specifies 64-bit argument uses
17572- # (even, odd) pair
17573- push @args, "0"
17574- }
17575- if($_32bit eq "big-endian") {
17576- push @args, "uintptr($name>>32)", "uintptr($name)";
17577- } else {
17578- push @args, "uintptr($name)", "uintptr($name>>32)";
17579- }
17580- } else {
17581- push @args, "uintptr($name)";
17582- }
17583- }
17584-
17585- # Determine which form to use; pad args with zeros.
17586- my $asm = "Syscall";
17587- if ($nonblock) {
17588- $asm = "RawSyscall";
17589- }
17590- if(@args <= 3) {
17591- while(@args < 3) {
17592- push @args, "0";
17593- }
17594- } elsif(@args <= 6) {
17595- $asm .= "6";
17596- while(@args < 6) {
17597- push @args, "0";
17598- }
17599- } elsif(@args <= 9) {
17600- $asm .= "9";
17601- while(@args < 9) {
17602- push @args, "0";
17603- }
17604- } else {
17605- print STDERR "$ARGV:$.: too many arguments to system call\n";
17606- }
17607-
17608- # System call number.
17609- if($sysname eq "") {
17610- $sysname = "SYS_$func";
17611- $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_Bar
17612- $sysname =~ y/a-z/A-Z/;
17613- if($nacl) {
17614- $sysname =~ y/A-Z/a-z/;
17615- }
17616- }
17617-
17618- # Actual call.
17619- my $args = join(', ', @args);
17620- my $call = "$asm($sysname, $args)";
17621-
17622- # Assign return values.
17623- my $body = "";
17624- my @ret = ("_", "_", "_");
17625- my $do_errno = 0;
17626- for(my $i=0; $i<@out; $i++) {
17627- my $p = $out[$i];
17628- my ($name, $type) = parseparam($p);
17629- my $reg = "";
17630- if($name eq "err" && !$plan9) {
17631- $reg = "e1";
17632- $ret[2] = $reg;
17633- $do_errno = 1;
17634- } elsif($name eq "err" && $plan9) {
17635- $ret[0] = "r0";
17636- $ret[2] = "e1";
17637- next;
17638- } else {
17639- $reg = sprintf("r%d", $i);
17640- $ret[$i] = $reg;
17641- }
17642- if($type eq "bool") {
17643- $reg = "$reg != 0";
17644- }
17645- if($type eq "int64" && $_32bit ne "") {
17646- # 64-bit number in r1:r0 or r0:r1.
17647- if($i+2 > @out) {
17648- print STDERR "$ARGV:$.: not enough registers for int64 return\n";
17649- }
17650- if($_32bit eq "big-endian") {
17651- $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i, $i+1);
17652- } else {
17653- $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i+1, $i);
17654- }
17655- $ret[$i] = sprintf("r%d", $i);
17656- $ret[$i+1] = sprintf("r%d", $i+1);
17657- }
17658- if($reg ne "e1" || $plan9) {
17659- $body .= "\t$name = $type($reg)\n";
17660- }
17661- }
17662- if ($ret[0] eq "_" && $ret[1] eq "_" && $ret[2] eq "_") {
17663- $text .= "\t$call\n";
17664- } else {
17665- $text .= "\t$ret[0], $ret[1], $ret[2] := $call\n";
17666- }
17667- foreach my $use (@uses) {
17668- $text .= "\t$use\n";
17669- }
17670- $text .= $body;
17671-
17672- if ($plan9 && $ret[2] eq "e1") {
17673- $text .= "\tif int32(r0) == -1 {\n";
17674- $text .= "\t\terr = e1\n";
17675- $text .= "\t}\n";
17676- } elsif ($do_errno) {
17677- $text .= "\tif e1 != 0 {\n";
17678- $text .= "\t\terr = e1\n";
17679- $text .= "\t}\n";
17680- }
17681- $text .= "\treturn\n";
17682- $text .= "}\n\n";
17683- }
17684-
17685- chomp $text;
17686- chomp $text;
17687-
17688- if($errors) {
17689- exit 1;
17690- }
17691-
17692- print <<EOF;
17693- // $cmdline
17694- // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
17695-
17696- package plan9
17697-
17698- import "unsafe"
17699-
17700- $text
17701- EOF
17702- exit 0;
17703 diff --git a/vendor/golang.org/x/sys/plan9/mksysnum_plan9.sh b/vendor/golang.org/x/sys/plan9/mksysnum_plan9.sh
17704deleted file mode 100755
17705index 3c3ab05..0000000
17706--- a/vendor/golang.org/x/sys/plan9/mksysnum_plan9.sh
17707+++ /dev/null
17708 @@ -1,23 +0,0 @@
17709- #!/bin/sh
17710- # Copyright 2009 The Go Authors. All rights reserved.
17711- # Use of this source code is governed by a BSD-style
17712- # license that can be found in the LICENSE file.
17713-
17714- COMMAND="mksysnum_plan9.sh $@"
17715-
17716- cat <<EOF
17717- // $COMMAND
17718- // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
17719-
17720- package plan9
17721-
17722- const(
17723- EOF
17724-
17725- SP='[ ]' # space or tab
17726- sed "s/^#define${SP}\\([A-Z0-9_][A-Z0-9_]*\\)${SP}${SP}*\\([0-9][0-9]*\\)/SYS_\\1=\\2/g" \
17727- < $1 | grep -v SYS__
17728-
17729- cat <<EOF
17730- )
17731- EOF
17732 diff --git a/vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go b/vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go
17733deleted file mode 100644
17734index 87ae9d2..0000000
17735--- a/vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go
17736+++ /dev/null
17737 @@ -1,21 +0,0 @@
17738- // Copyright 2015 The Go Authors. All rights reserved.
17739- // Use of this source code is governed by a BSD-style
17740- // license that can be found in the LICENSE file.
17741-
17742- // +build go1.5
17743-
17744- package plan9
17745-
17746- import "syscall"
17747-
17748- func fixwd() {
17749- syscall.Fixwd()
17750- }
17751-
17752- func Getwd() (wd string, err error) {
17753- return syscall.Getwd()
17754- }
17755-
17756- func Chdir(path string) error {
17757- return syscall.Chdir(path)
17758- }
17759 diff --git a/vendor/golang.org/x/sys/plan9/pwd_plan9.go b/vendor/golang.org/x/sys/plan9/pwd_plan9.go
17760deleted file mode 100644
17761index c07c798..0000000
17762--- a/vendor/golang.org/x/sys/plan9/pwd_plan9.go
17763+++ /dev/null
17764 @@ -1,23 +0,0 @@
17765- // Copyright 2015 The Go Authors. All rights reserved.
17766- // Use of this source code is governed by a BSD-style
17767- // license that can be found in the LICENSE file.
17768-
17769- // +build !go1.5
17770-
17771- package plan9
17772-
17773- func fixwd() {
17774- }
17775-
17776- func Getwd() (wd string, err error) {
17777- fd, err := open(".", O_RDONLY)
17778- if err != nil {
17779- return "", err
17780- }
17781- defer Close(fd)
17782- return Fd2path(fd)
17783- }
17784-
17785- func Chdir(path string) error {
17786- return chdir(path)
17787- }
17788 diff --git a/vendor/golang.org/x/sys/plan9/race.go b/vendor/golang.org/x/sys/plan9/race.go
17789deleted file mode 100644
17790index 42edd93..0000000
17791--- a/vendor/golang.org/x/sys/plan9/race.go
17792+++ /dev/null
17793 @@ -1,30 +0,0 @@
17794- // Copyright 2012 The Go Authors. All rights reserved.
17795- // Use of this source code is governed by a BSD-style
17796- // license that can be found in the LICENSE file.
17797-
17798- // +build plan9,race
17799-
17800- package plan9
17801-
17802- import (
17803- "runtime"
17804- "unsafe"
17805- )
17806-
17807- const raceenabled = true
17808-
17809- func raceAcquire(addr unsafe.Pointer) {
17810- runtime.RaceAcquire(addr)
17811- }
17812-
17813- func raceReleaseMerge(addr unsafe.Pointer) {
17814- runtime.RaceReleaseMerge(addr)
17815- }
17816-
17817- func raceReadRange(addr unsafe.Pointer, len int) {
17818- runtime.RaceReadRange(addr, len)
17819- }
17820-
17821- func raceWriteRange(addr unsafe.Pointer, len int) {
17822- runtime.RaceWriteRange(addr, len)
17823- }
17824 diff --git a/vendor/golang.org/x/sys/plan9/race0.go b/vendor/golang.org/x/sys/plan9/race0.go
17825deleted file mode 100644
17826index c89cf8f..0000000
17827--- a/vendor/golang.org/x/sys/plan9/race0.go
17828+++ /dev/null
17829 @@ -1,25 +0,0 @@
17830- // Copyright 2012 The Go Authors. All rights reserved.
17831- // Use of this source code is governed by a BSD-style
17832- // license that can be found in the LICENSE file.
17833-
17834- // +build plan9,!race
17835-
17836- package plan9
17837-
17838- import (
17839- "unsafe"
17840- )
17841-
17842- const raceenabled = false
17843-
17844- func raceAcquire(addr unsafe.Pointer) {
17845- }
17846-
17847- func raceReleaseMerge(addr unsafe.Pointer) {
17848- }
17849-
17850- func raceReadRange(addr unsafe.Pointer, len int) {
17851- }
17852-
17853- func raceWriteRange(addr unsafe.Pointer, len int) {
17854- }
17855 diff --git a/vendor/golang.org/x/sys/plan9/str.go b/vendor/golang.org/x/sys/plan9/str.go
17856deleted file mode 100644
17857index 4f7f9ad..0000000
17858--- a/vendor/golang.org/x/sys/plan9/str.go
17859+++ /dev/null
17860 @@ -1,22 +0,0 @@
17861- // Copyright 2009 The Go Authors. All rights reserved.
17862- // Use of this source code is governed by a BSD-style
17863- // license that can be found in the LICENSE file.
17864-
17865- // +build plan9
17866-
17867- package plan9
17868-
17869- func itoa(val int) string { // do it here rather than with fmt to avoid dependency
17870- if val < 0 {
17871- return "-" + itoa(-val)
17872- }
17873- var buf [32]byte // big enough for int64
17874- i := len(buf) - 1
17875- for val >= 10 {
17876- buf[i] = byte(val%10 + '0')
17877- i--
17878- val /= 10
17879- }
17880- buf[i] = byte(val + '0')
17881- return string(buf[i:])
17882- }
17883 diff --git a/vendor/golang.org/x/sys/plan9/syscall.go b/vendor/golang.org/x/sys/plan9/syscall.go
17884deleted file mode 100644
17885index 5046cfe..0000000
17886--- a/vendor/golang.org/x/sys/plan9/syscall.go
17887+++ /dev/null
17888 @@ -1,74 +0,0 @@
17889- // Copyright 2009 The Go Authors. All rights reserved.
17890- // Use of this source code is governed by a BSD-style
17891- // license that can be found in the LICENSE file.
17892-
17893- // +build plan9
17894-
17895- // Package plan9 contains an interface to the low-level operating system
17896- // primitives. OS details vary depending on the underlying system, and
17897- // by default, godoc will display the OS-specific documentation for the current
17898- // system. If you want godoc to display documentation for another
17899- // system, set $GOOS and $GOARCH to the desired system. For example, if
17900- // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS
17901- // to freebsd and $GOARCH to arm.
17902- // The primary use of this package is inside other packages that provide a more
17903- // portable interface to the system, such as "os", "time" and "net". Use
17904- // those packages rather than this one if you can.
17905- // For details of the functions and data types in this package consult
17906- // the manuals for the appropriate operating system.
17907- // These calls return err == nil to indicate success; otherwise
17908- // err represents an operating system error describing the failure and
17909- // holds a value of type syscall.ErrorString.
17910- package plan9 // import "golang.org/x/sys/plan9"
17911-
17912- import "unsafe"
17913-
17914- // ByteSliceFromString returns a NUL-terminated slice of bytes
17915- // containing the text of s. If s contains a NUL byte at any
17916- // location, it returns (nil, EINVAL).
17917- func ByteSliceFromString(s string) ([]byte, error) {
17918- for i := 0; i < len(s); i++ {
17919- if s[i] == 0 {
17920- return nil, EINVAL
17921- }
17922- }
17923- a := make([]byte, len(s)+1)
17924- copy(a, s)
17925- return a, nil
17926- }
17927-
17928- // BytePtrFromString returns a pointer to a NUL-terminated array of
17929- // bytes containing the text of s. If s contains a NUL byte at any
17930- // location, it returns (nil, EINVAL).
17931- func BytePtrFromString(s string) (*byte, error) {
17932- a, err := ByteSliceFromString(s)
17933- if err != nil {
17934- return nil, err
17935- }
17936- return &a[0], nil
17937- }
17938-
17939- // Single-word zero for use when we need a valid pointer to 0 bytes.
17940- // See mksyscall.pl.
17941- var _zero uintptr
17942-
17943- func (ts *Timespec) Unix() (sec int64, nsec int64) {
17944- return int64(ts.Sec), int64(ts.Nsec)
17945- }
17946-
17947- func (tv *Timeval) Unix() (sec int64, nsec int64) {
17948- return int64(tv.Sec), int64(tv.Usec) * 1000
17949- }
17950-
17951- func (ts *Timespec) Nano() int64 {
17952- return int64(ts.Sec)*1e9 + int64(ts.Nsec)
17953- }
17954-
17955- func (tv *Timeval) Nano() int64 {
17956- return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
17957- }
17958-
17959- // use is a no-op, but the compiler cannot see that it is.
17960- // Calling use(p) ensures that p is kept live until that point.
17961- //go:noescape
17962- func use(p unsafe.Pointer)
17963 diff --git a/vendor/golang.org/x/sys/plan9/syscall_plan9.go b/vendor/golang.org/x/sys/plan9/syscall_plan9.go
17964deleted file mode 100644
17965index d39d07d..0000000
17966--- a/vendor/golang.org/x/sys/plan9/syscall_plan9.go
17967+++ /dev/null
17968 @@ -1,349 +0,0 @@
17969- // Copyright 2011 The Go Authors. All rights reserved.
17970- // Use of this source code is governed by a BSD-style
17971- // license that can be found in the LICENSE file.
17972-
17973- // Plan 9 system calls.
17974- // This file is compiled as ordinary Go code,
17975- // but it is also input to mksyscall,
17976- // which parses the //sys lines and generates system call stubs.
17977- // Note that sometimes we use a lowercase //sys name and
17978- // wrap it in our own nicer implementation.
17979-
17980- package plan9
17981-
17982- import (
17983- "syscall"
17984- "unsafe"
17985- )
17986-
17987- // A Note is a string describing a process note.
17988- // It implements the os.Signal interface.
17989- type Note string
17990-
17991- func (n Note) Signal() {}
17992-
17993- func (n Note) String() string {
17994- return string(n)
17995- }
17996-
17997- var (
17998- Stdin = 0
17999- Stdout = 1
18000- Stderr = 2
18001- )
18002-
18003- // For testing: clients can set this flag to force
18004- // creation of IPv6 sockets to return EAFNOSUPPORT.
18005- var SocketDisableIPv6 bool
18006-
18007- func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
18008- func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
18009- func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
18010- func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
18011-
18012- func atoi(b []byte) (n uint) {
18013- n = 0
18014- for i := 0; i < len(b); i++ {
18015- n = n*10 + uint(b[i]-'0')
18016- }
18017- return
18018- }
18019-
18020- func cstring(s []byte) string {
18021- for i := range s {
18022- if s[i] == 0 {
18023- return string(s[0:i])
18024- }
18025- }
18026- return string(s)
18027- }
18028-
18029- func errstr() string {
18030- var buf [ERRMAX]byte
18031-
18032- RawSyscall(SYS_ERRSTR, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)), 0)
18033-
18034- buf[len(buf)-1] = 0
18035- return cstring(buf[:])
18036- }
18037-
18038- // Implemented in assembly to import from runtime.
18039- func exit(code int)
18040-
18041- func Exit(code int) { exit(code) }
18042-
18043- func readnum(path string) (uint, error) {
18044- var b [12]byte
18045-
18046- fd, e := Open(path, O_RDONLY)
18047- if e != nil {
18048- return 0, e
18049- }
18050- defer Close(fd)
18051-
18052- n, e := Pread(fd, b[:], 0)
18053-
18054- if e != nil {
18055- return 0, e
18056- }
18057-
18058- m := 0
18059- for ; m < n && b[m] == ' '; m++ {
18060- }
18061-
18062- return atoi(b[m : n-1]), nil
18063- }
18064-
18065- func Getpid() (pid int) {
18066- n, _ := readnum("#c/pid")
18067- return int(n)
18068- }
18069-
18070- func Getppid() (ppid int) {
18071- n, _ := readnum("#c/ppid")
18072- return int(n)
18073- }
18074-
18075- func Read(fd int, p []byte) (n int, err error) {
18076- return Pread(fd, p, -1)
18077- }
18078-
18079- func Write(fd int, p []byte) (n int, err error) {
18080- return Pwrite(fd, p, -1)
18081- }
18082-
18083- var ioSync int64
18084-
18085- //sys fd2path(fd int, buf []byte) (err error)
18086- func Fd2path(fd int) (path string, err error) {
18087- var buf [512]byte
18088-
18089- e := fd2path(fd, buf[:])
18090- if e != nil {
18091- return "", e
18092- }
18093- return cstring(buf[:]), nil
18094- }
18095-
18096- //sys pipe(p *[2]int32) (err error)
18097- func Pipe(p []int) (err error) {
18098- if len(p) != 2 {
18099- return syscall.ErrorString("bad arg in system call")
18100- }
18101- var pp [2]int32
18102- err = pipe(&pp)
18103- p[0] = int(pp[0])
18104- p[1] = int(pp[1])
18105- return
18106- }
18107-
18108- // Underlying system call writes to newoffset via pointer.
18109- // Implemented in assembly to avoid allocation.
18110- func seek(placeholder uintptr, fd int, offset int64, whence int) (newoffset int64, err string)
18111-
18112- func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
18113- newoffset, e := seek(0, fd, offset, whence)
18114-
18115- if newoffset == -1 {
18116- err = syscall.ErrorString(e)
18117- }
18118- return
18119- }
18120-
18121- func Mkdir(path string, mode uint32) (err error) {
18122- fd, err := Create(path, O_RDONLY, DMDIR|mode)
18123-
18124- if fd != -1 {
18125- Close(fd)
18126- }
18127-
18128- return
18129- }
18130-
18131- type Waitmsg struct {
18132- Pid int
18133- Time [3]uint32
18134- Msg string
18135- }
18136-
18137- func (w Waitmsg) Exited() bool { return true }
18138- func (w Waitmsg) Signaled() bool { return false }
18139-
18140- func (w Waitmsg) ExitStatus() int {
18141- if len(w.Msg) == 0 {
18142- // a normal exit returns no message
18143- return 0
18144- }
18145- return 1
18146- }
18147-
18148- //sys await(s []byte) (n int, err error)
18149- func Await(w *Waitmsg) (err error) {
18150- var buf [512]byte
18151- var f [5][]byte
18152-
18153- n, err := await(buf[:])
18154-
18155- if err != nil || w == nil {
18156- return
18157- }
18158-
18159- nf := 0
18160- p := 0
18161- for i := 0; i < n && nf < len(f)-1; i++ {
18162- if buf[i] == ' ' {
18163- f[nf] = buf[p:i]
18164- p = i + 1
18165- nf++
18166- }
18167- }
18168- f[nf] = buf[p:]
18169- nf++
18170-
18171- if nf != len(f) {
18172- return syscall.ErrorString("invalid wait message")
18173- }
18174- w.Pid = int(atoi(f[0]))
18175- w.Time[0] = uint32(atoi(f[1]))
18176- w.Time[1] = uint32(atoi(f[2]))
18177- w.Time[2] = uint32(atoi(f[3]))
18178- w.Msg = cstring(f[4])
18179- if w.Msg == "''" {
18180- // await() returns '' for no error
18181- w.Msg = ""
18182- }
18183- return
18184- }
18185-
18186- func Unmount(name, old string) (err error) {
18187- fixwd()
18188- oldp, err := BytePtrFromString(old)
18189- if err != nil {
18190- return err
18191- }
18192- oldptr := uintptr(unsafe.Pointer(oldp))
18193-
18194- var r0 uintptr
18195- var e syscall.ErrorString
18196-
18197- // bind(2) man page: If name is zero, everything bound or mounted upon old is unbound or unmounted.
18198- if name == "" {
18199- r0, _, e = Syscall(SYS_UNMOUNT, _zero, oldptr, 0)
18200- } else {
18201- namep, err := BytePtrFromString(name)
18202- if err != nil {
18203- return err
18204- }
18205- r0, _, e = Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(namep)), oldptr, 0)
18206- }
18207-
18208- if int32(r0) == -1 {
18209- err = e
18210- }
18211- return
18212- }
18213-
18214- func Fchdir(fd int) (err error) {
18215- path, err := Fd2path(fd)
18216-
18217- if err != nil {
18218- return
18219- }
18220-
18221- return Chdir(path)
18222- }
18223-
18224- type Timespec struct {
18225- Sec int32
18226- Nsec int32
18227- }
18228-
18229- type Timeval struct {
18230- Sec int32
18231- Usec int32
18232- }
18233-
18234- func NsecToTimeval(nsec int64) (tv Timeval) {
18235- nsec += 999 // round up to microsecond
18236- tv.Usec = int32(nsec % 1e9 / 1e3)
18237- tv.Sec = int32(nsec / 1e9)
18238- return
18239- }
18240-
18241- func nsec() int64 {
18242- var scratch int64
18243-
18244- r0, _, _ := Syscall(SYS_NSEC, uintptr(unsafe.Pointer(&scratch)), 0, 0)
18245- // TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
18246- if r0 == 0 {
18247- return scratch
18248- }
18249- return int64(r0)
18250- }
18251-
18252- func Gettimeofday(tv *Timeval) error {
18253- nsec := nsec()
18254- *tv = NsecToTimeval(nsec)
18255- return nil
18256- }
18257-
18258- func Getpagesize() int { return 0x1000 }
18259-
18260- func Getegid() (egid int) { return -1 }
18261- func Geteuid() (euid int) { return -1 }
18262- func Getgid() (gid int) { return -1 }
18263- func Getuid() (uid int) { return -1 }
18264-
18265- func Getgroups() (gids []int, err error) {
18266- return make([]int, 0), nil
18267- }
18268-
18269- //sys open(path string, mode int) (fd int, err error)
18270- func Open(path string, mode int) (fd int, err error) {
18271- fixwd()
18272- return open(path, mode)
18273- }
18274-
18275- //sys create(path string, mode int, perm uint32) (fd int, err error)
18276- func Create(path string, mode int, perm uint32) (fd int, err error) {
18277- fixwd()
18278- return create(path, mode, perm)
18279- }
18280-
18281- //sys remove(path string) (err error)
18282- func Remove(path string) error {
18283- fixwd()
18284- return remove(path)
18285- }
18286-
18287- //sys stat(path string, edir []byte) (n int, err error)
18288- func Stat(path string, edir []byte) (n int, err error) {
18289- fixwd()
18290- return stat(path, edir)
18291- }
18292-
18293- //sys bind(name string, old string, flag int) (err error)
18294- func Bind(name string, old string, flag int) (err error) {
18295- fixwd()
18296- return bind(name, old, flag)
18297- }
18298-
18299- //sys mount(fd int, afd int, old string, flag int, aname string) (err error)
18300- func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
18301- fixwd()
18302- return mount(fd, afd, old, flag, aname)
18303- }
18304-
18305- //sys wstat(path string, edir []byte) (err error)
18306- func Wstat(path string, edir []byte) (err error) {
18307- fixwd()
18308- return wstat(path, edir)
18309- }
18310-
18311- //sys chdir(path string) (err error)
18312- //sys Dup(oldfd int, newfd int) (fd int, err error)
18313- //sys Pread(fd int, p []byte, offset int64) (n int, err error)
18314- //sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
18315- //sys Close(fd int) (err error)
18316- //sys Fstat(fd int, edir []byte) (n int, err error)
18317- //sys Fwstat(fd int, edir []byte) (err error)
18318 diff --git a/vendor/golang.org/x/sys/plan9/syscall_test.go b/vendor/golang.org/x/sys/plan9/syscall_test.go
18319deleted file mode 100644
18320index 8f829ba..0000000
18321--- a/vendor/golang.org/x/sys/plan9/syscall_test.go
18322+++ /dev/null
18323 @@ -1,33 +0,0 @@
18324- // Copyright 2013 The Go Authors. All rights reserved.
18325- // Use of this source code is governed by a BSD-style
18326- // license that can be found in the LICENSE file.
18327-
18328- // +build plan9
18329-
18330- package plan9_test
18331-
18332- import (
18333- "testing"
18334-
18335- "golang.org/x/sys/plan9"
18336- )
18337-
18338- func testSetGetenv(t *testing.T, key, value string) {
18339- err := plan9.Setenv(key, value)
18340- if err != nil {
18341- t.Fatalf("Setenv failed to set %q: %v", value, err)
18342- }
18343- newvalue, found := plan9.Getenv(key)
18344- if !found {
18345- t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
18346- }
18347- if newvalue != value {
18348- t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
18349- }
18350- }
18351-
18352- func TestEnv(t *testing.T) {
18353- testSetGetenv(t, "TESTENV", "AVALUE")
18354- // make sure TESTENV gets set to "", not deleted
18355- testSetGetenv(t, "TESTENV", "")
18356- }
18357 diff --git a/vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go b/vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go
18358deleted file mode 100644
18359index b35598a..0000000
18360--- a/vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go
18361+++ /dev/null
18362 @@ -1,292 +0,0 @@
18363- // mksyscall.pl -l32 -plan9 syscall_plan9.go
18364- // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
18365-
18366- package plan9
18367-
18368- import "unsafe"
18369-
18370- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18371-
18372- func fd2path(fd int, buf []byte) (err error) {
18373- var _p0 unsafe.Pointer
18374- if len(buf) > 0 {
18375- _p0 = unsafe.Pointer(&buf[0])
18376- } else {
18377- _p0 = unsafe.Pointer(&_zero)
18378- }
18379- r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
18380- if int32(r0) == -1 {
18381- err = e1
18382- }
18383- return
18384- }
18385-
18386- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18387-
18388- func pipe(p *[2]int32) (err error) {
18389- r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
18390- if int32(r0) == -1 {
18391- err = e1
18392- }
18393- return
18394- }
18395-
18396- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18397-
18398- func await(s []byte) (n int, err error) {
18399- var _p0 unsafe.Pointer
18400- if len(s) > 0 {
18401- _p0 = unsafe.Pointer(&s[0])
18402- } else {
18403- _p0 = unsafe.Pointer(&_zero)
18404- }
18405- r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
18406- n = int(r0)
18407- if int32(r0) == -1 {
18408- err = e1
18409- }
18410- return
18411- }
18412-
18413- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18414-
18415- func open(path string, mode int) (fd int, err error) {
18416- var _p0 *byte
18417- _p0, err = BytePtrFromString(path)
18418- if err != nil {
18419- return
18420- }
18421- r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
18422- use(unsafe.Pointer(_p0))
18423- fd = int(r0)
18424- if int32(r0) == -1 {
18425- err = e1
18426- }
18427- return
18428- }
18429-
18430- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18431-
18432- func create(path string, mode int, perm uint32) (fd int, err error) {
18433- var _p0 *byte
18434- _p0, err = BytePtrFromString(path)
18435- if err != nil {
18436- return
18437- }
18438- r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
18439- use(unsafe.Pointer(_p0))
18440- fd = int(r0)
18441- if int32(r0) == -1 {
18442- err = e1
18443- }
18444- return
18445- }
18446-
18447- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18448-
18449- func remove(path string) (err error) {
18450- var _p0 *byte
18451- _p0, err = BytePtrFromString(path)
18452- if err != nil {
18453- return
18454- }
18455- r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
18456- use(unsafe.Pointer(_p0))
18457- if int32(r0) == -1 {
18458- err = e1
18459- }
18460- return
18461- }
18462-
18463- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18464-
18465- func stat(path string, edir []byte) (n int, err error) {
18466- var _p0 *byte
18467- _p0, err = BytePtrFromString(path)
18468- if err != nil {
18469- return
18470- }
18471- var _p1 unsafe.Pointer
18472- if len(edir) > 0 {
18473- _p1 = unsafe.Pointer(&edir[0])
18474- } else {
18475- _p1 = unsafe.Pointer(&_zero)
18476- }
18477- r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
18478- use(unsafe.Pointer(_p0))
18479- n = int(r0)
18480- if int32(r0) == -1 {
18481- err = e1
18482- }
18483- return
18484- }
18485-
18486- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18487-
18488- func bind(name string, old string, flag int) (err error) {
18489- var _p0 *byte
18490- _p0, err = BytePtrFromString(name)
18491- if err != nil {
18492- return
18493- }
18494- var _p1 *byte
18495- _p1, err = BytePtrFromString(old)
18496- if err != nil {
18497- return
18498- }
18499- r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
18500- use(unsafe.Pointer(_p0))
18501- use(unsafe.Pointer(_p1))
18502- if int32(r0) == -1 {
18503- err = e1
18504- }
18505- return
18506- }
18507-
18508- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18509-
18510- func mount(fd int, afd int, old string, flag int, aname string) (err error) {
18511- var _p0 *byte
18512- _p0, err = BytePtrFromString(old)
18513- if err != nil {
18514- return
18515- }
18516- var _p1 *byte
18517- _p1, err = BytePtrFromString(aname)
18518- if err != nil {
18519- return
18520- }
18521- r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
18522- use(unsafe.Pointer(_p0))
18523- use(unsafe.Pointer(_p1))
18524- if int32(r0) == -1 {
18525- err = e1
18526- }
18527- return
18528- }
18529-
18530- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18531-
18532- func wstat(path string, edir []byte) (err error) {
18533- var _p0 *byte
18534- _p0, err = BytePtrFromString(path)
18535- if err != nil {
18536- return
18537- }
18538- var _p1 unsafe.Pointer
18539- if len(edir) > 0 {
18540- _p1 = unsafe.Pointer(&edir[0])
18541- } else {
18542- _p1 = unsafe.Pointer(&_zero)
18543- }
18544- r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
18545- use(unsafe.Pointer(_p0))
18546- if int32(r0) == -1 {
18547- err = e1
18548- }
18549- return
18550- }
18551-
18552- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18553-
18554- func chdir(path string) (err error) {
18555- var _p0 *byte
18556- _p0, err = BytePtrFromString(path)
18557- if err != nil {
18558- return
18559- }
18560- r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
18561- use(unsafe.Pointer(_p0))
18562- if int32(r0) == -1 {
18563- err = e1
18564- }
18565- return
18566- }
18567-
18568- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18569-
18570- func Dup(oldfd int, newfd int) (fd int, err error) {
18571- r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
18572- fd = int(r0)
18573- if int32(r0) == -1 {
18574- err = e1
18575- }
18576- return
18577- }
18578-
18579- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18580-
18581- func Pread(fd int, p []byte, offset int64) (n int, err error) {
18582- var _p0 unsafe.Pointer
18583- if len(p) > 0 {
18584- _p0 = unsafe.Pointer(&p[0])
18585- } else {
18586- _p0 = unsafe.Pointer(&_zero)
18587- }
18588- r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
18589- n = int(r0)
18590- if int32(r0) == -1 {
18591- err = e1
18592- }
18593- return
18594- }
18595-
18596- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18597-
18598- func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
18599- var _p0 unsafe.Pointer
18600- if len(p) > 0 {
18601- _p0 = unsafe.Pointer(&p[0])
18602- } else {
18603- _p0 = unsafe.Pointer(&_zero)
18604- }
18605- r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
18606- n = int(r0)
18607- if int32(r0) == -1 {
18608- err = e1
18609- }
18610- return
18611- }
18612-
18613- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18614-
18615- func Close(fd int) (err error) {
18616- r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
18617- if int32(r0) == -1 {
18618- err = e1
18619- }
18620- return
18621- }
18622-
18623- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18624-
18625- func Fstat(fd int, edir []byte) (n int, err error) {
18626- var _p0 unsafe.Pointer
18627- if len(edir) > 0 {
18628- _p0 = unsafe.Pointer(&edir[0])
18629- } else {
18630- _p0 = unsafe.Pointer(&_zero)
18631- }
18632- r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
18633- n = int(r0)
18634- if int32(r0) == -1 {
18635- err = e1
18636- }
18637- return
18638- }
18639-
18640- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18641-
18642- func Fwstat(fd int, edir []byte) (err error) {
18643- var _p0 unsafe.Pointer
18644- if len(edir) > 0 {
18645- _p0 = unsafe.Pointer(&edir[0])
18646- } else {
18647- _p0 = unsafe.Pointer(&_zero)
18648- }
18649- r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
18650- if int32(r0) == -1 {
18651- err = e1
18652- }
18653- return
18654- }
18655 diff --git a/vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go b/vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go
18656deleted file mode 100644
18657index b35598a..0000000
18658--- a/vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go
18659+++ /dev/null
18660 @@ -1,292 +0,0 @@
18661- // mksyscall.pl -l32 -plan9 syscall_plan9.go
18662- // MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
18663-
18664- package plan9
18665-
18666- import "unsafe"
18667-
18668- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18669-
18670- func fd2path(fd int, buf []byte) (err error) {
18671- var _p0 unsafe.Pointer
18672- if len(buf) > 0 {
18673- _p0 = unsafe.Pointer(&buf[0])
18674- } else {
18675- _p0 = unsafe.Pointer(&_zero)
18676- }
18677- r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
18678- if int32(r0) == -1 {
18679- err = e1
18680- }
18681- return
18682- }
18683-
18684- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18685-
18686- func pipe(p *[2]int32) (err error) {
18687- r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
18688- if int32(r0) == -1 {
18689- err = e1
18690- }
18691- return
18692- }
18693-
18694- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18695-
18696- func await(s []byte) (n int, err error) {
18697- var _p0 unsafe.Pointer
18698- if len(s) > 0 {
18699- _p0 = unsafe.Pointer(&s[0])
18700- } else {
18701- _p0 = unsafe.Pointer(&_zero)
18702- }
18703- r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
18704- n = int(r0)
18705- if int32(r0) == -1 {
18706- err = e1
18707- }
18708- return
18709- }
18710-
18711- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18712-
18713- func open(path string, mode int) (fd int, err error) {
18714- var _p0 *byte
18715- _p0, err = BytePtrFromString(path)
18716- if err != nil {
18717- return
18718- }
18719- r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
18720- use(unsafe.Pointer(_p0))
18721- fd = int(r0)
18722- if int32(r0) == -1 {
18723- err = e1
18724- }
18725- return
18726- }
18727-
18728- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18729-
18730- func create(path string, mode int, perm uint32) (fd int, err error) {
18731- var _p0 *byte
18732- _p0, err = BytePtrFromString(path)
18733- if err != nil {
18734- return
18735- }
18736- r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
18737- use(unsafe.Pointer(_p0))
18738- fd = int(r0)
18739- if int32(r0) == -1 {
18740- err = e1
18741- }
18742- return
18743- }
18744-
18745- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18746-
18747- func remove(path string) (err error) {
18748- var _p0 *byte
18749- _p0, err = BytePtrFromString(path)
18750- if err != nil {
18751- return
18752- }
18753- r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
18754- use(unsafe.Pointer(_p0))
18755- if int32(r0) == -1 {
18756- err = e1
18757- }
18758- return
18759- }
18760-
18761- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18762-
18763- func stat(path string, edir []byte) (n int, err error) {
18764- var _p0 *byte
18765- _p0, err = BytePtrFromString(path)
18766- if err != nil {
18767- return
18768- }
18769- var _p1 unsafe.Pointer
18770- if len(edir) > 0 {
18771- _p1 = unsafe.Pointer(&edir[0])
18772- } else {
18773- _p1 = unsafe.Pointer(&_zero)
18774- }
18775- r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
18776- use(unsafe.Pointer(_p0))
18777- n = int(r0)
18778- if int32(r0) == -1 {
18779- err = e1
18780- }
18781- return
18782- }
18783-
18784- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18785-
18786- func bind(name string, old string, flag int) (err error) {
18787- var _p0 *byte
18788- _p0, err = BytePtrFromString(name)
18789- if err != nil {
18790- return
18791- }
18792- var _p1 *byte
18793- _p1, err = BytePtrFromString(old)
18794- if err != nil {
18795- return
18796- }
18797- r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
18798- use(unsafe.Pointer(_p0))
18799- use(unsafe.Pointer(_p1))
18800- if int32(r0) == -1 {
18801- err = e1
18802- }
18803- return
18804- }
18805-
18806- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18807-
18808- func mount(fd int, afd int, old string, flag int, aname string) (err error) {
18809- var _p0 *byte
18810- _p0, err = BytePtrFromString(old)
18811- if err != nil {
18812- return
18813- }
18814- var _p1 *byte
18815- _p1, err = BytePtrFromString(aname)
18816- if err != nil {
18817- return
18818- }
18819- r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
18820- use(unsafe.Pointer(_p0))
18821- use(unsafe.Pointer(_p1))
18822- if int32(r0) == -1 {
18823- err = e1
18824- }
18825- return
18826- }
18827-
18828- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18829-
18830- func wstat(path string, edir []byte) (err error) {
18831- var _p0 *byte
18832- _p0, err = BytePtrFromString(path)
18833- if err != nil {
18834- return
18835- }
18836- var _p1 unsafe.Pointer
18837- if len(edir) > 0 {
18838- _p1 = unsafe.Pointer(&edir[0])
18839- } else {
18840- _p1 = unsafe.Pointer(&_zero)
18841- }
18842- r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
18843- use(unsafe.Pointer(_p0))
18844- if int32(r0) == -1 {
18845- err = e1
18846- }
18847- return
18848- }
18849-
18850- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18851-
18852- func chdir(path string) (err error) {
18853- var _p0 *byte
18854- _p0, err = BytePtrFromString(path)
18855- if err != nil {
18856- return
18857- }
18858- r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
18859- use(unsafe.Pointer(_p0))
18860- if int32(r0) == -1 {
18861- err = e1
18862- }
18863- return
18864- }
18865-
18866- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18867-
18868- func Dup(oldfd int, newfd int) (fd int, err error) {
18869- r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
18870- fd = int(r0)
18871- if int32(r0) == -1 {
18872- err = e1
18873- }
18874- return
18875- }
18876-
18877- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18878-
18879- func Pread(fd int, p []byte, offset int64) (n int, err error) {
18880- var _p0 unsafe.Pointer
18881- if len(p) > 0 {
18882- _p0 = unsafe.Pointer(&p[0])
18883- } else {
18884- _p0 = unsafe.Pointer(&_zero)
18885- }
18886- r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
18887- n = int(r0)
18888- if int32(r0) == -1 {
18889- err = e1
18890- }
18891- return
18892- }
18893-
18894- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18895-
18896- func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
18897- var _p0 unsafe.Pointer
18898- if len(p) > 0 {
18899- _p0 = unsafe.Pointer(&p[0])
18900- } else {
18901- _p0 = unsafe.Pointer(&_zero)
18902- }
18903- r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
18904- n = int(r0)
18905- if int32(r0) == -1 {
18906- err = e1
18907- }
18908- return
18909- }
18910-
18911- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18912-
18913- func Close(fd int) (err error) {
18914- r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
18915- if int32(r0) == -1 {
18916- err = e1
18917- }
18918- return
18919- }
18920-
18921- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18922-
18923- func Fstat(fd int, edir []byte) (n int, err error) {
18924- var _p0 unsafe.Pointer
18925- if len(edir) > 0 {
18926- _p0 = unsafe.Pointer(&edir[0])
18927- } else {
18928- _p0 = unsafe.Pointer(&_zero)
18929- }
18930- r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
18931- n = int(r0)
18932- if int32(r0) == -1 {
18933- err = e1
18934- }
18935- return
18936- }
18937-
18938- // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
18939-
18940- func Fwstat(fd int, edir []byte) (err error) {
18941- var _p0 unsafe.Pointer
18942- if len(edir) > 0 {
18943- _p0 = unsafe.Pointer(&edir[0])
18944- } else {
18945- _p0 = unsafe.Pointer(&_zero)
18946- }
18947- r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
18948- if int32(r0) == -1 {
18949- err = e1
18950- }
18951- return
18952- }
18953 diff --git a/vendor/golang.org/x/sys/plan9/zsysnum_plan9.go b/vendor/golang.org/x/sys/plan9/zsysnum_plan9.go
18954deleted file mode 100644
18955index 22e8abd..0000000
18956--- a/vendor/golang.org/x/sys/plan9/zsysnum_plan9.go
18957+++ /dev/null
18958 @@ -1,49 +0,0 @@
18959- // mksysnum_plan9.sh /opt/plan9/sys/src/libc/9syscall/sys.h
18960- // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
18961-
18962- package plan9
18963-
18964- const (
18965- SYS_SYSR1 = 0
18966- SYS_BIND = 2
18967- SYS_CHDIR = 3
18968- SYS_CLOSE = 4
18969- SYS_DUP = 5
18970- SYS_ALARM = 6
18971- SYS_EXEC = 7
18972- SYS_EXITS = 8
18973- SYS_FAUTH = 10
18974- SYS_SEGBRK = 12
18975- SYS_OPEN = 14
18976- SYS_OSEEK = 16
18977- SYS_SLEEP = 17
18978- SYS_RFORK = 19
18979- SYS_PIPE = 21
18980- SYS_CREATE = 22
18981- SYS_FD2PATH = 23
18982- SYS_BRK_ = 24
18983- SYS_REMOVE = 25
18984- SYS_NOTIFY = 28
18985- SYS_NOTED = 29
18986- SYS_SEGATTACH = 30
18987- SYS_SEGDETACH = 31
18988- SYS_SEGFREE = 32
18989- SYS_SEGFLUSH = 33
18990- SYS_RENDEZVOUS = 34
18991- SYS_UNMOUNT = 35
18992- SYS_SEMACQUIRE = 37
18993- SYS_SEMRELEASE = 38
18994- SYS_SEEK = 39
18995- SYS_FVERSION = 40
18996- SYS_ERRSTR = 41
18997- SYS_STAT = 42
18998- SYS_FSTAT = 43
18999- SYS_WSTAT = 44
19000- SYS_FWSTAT = 45
19001- SYS_MOUNT = 46
19002- SYS_AWAIT = 47
19003- SYS_PREAD = 50
19004- SYS_PWRITE = 51
19005- SYS_TSEMACQUIRE = 52
19006- SYS_NSEC = 53
19007- )
19008 diff --git a/vendor/golang.org/x/sys/unix/linux/Dockerfile b/vendor/golang.org/x/sys/unix/linux/Dockerfile
19009deleted file mode 100644
19010index 7fe5fc3..0000000
19011--- a/vendor/golang.org/x/sys/unix/linux/Dockerfile
19012+++ /dev/null
19013 @@ -1,51 +0,0 @@
19014- FROM ubuntu:16.04
19015-
19016- # Use the most recent ubuntu sources
19017- RUN echo 'deb http://en.archive.ubuntu.com/ubuntu/ artful main universe' >> /etc/apt/sources.list
19018-
19019- # Dependencies to get the git sources and go binaries
19020- RUN apt-get update && apt-get install -y \
19021- curl \
19022- git \
19023- && rm -rf /var/lib/apt/lists/*
19024-
19025- # Get the git sources. If not cached, this takes O(5 minutes).
19026- WORKDIR /git
19027- RUN git config --global advice.detachedHead false
19028- # Linux Kernel: Released 03 Sep 2017
19029- RUN git clone --branch v4.13 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux
19030- # GNU C library: Released 02 Aug 2017 (we should try to get a secure way to clone this)
19031- RUN git clone --branch glibc-2.26 --depth 1 git://sourceware.org/git/glibc.git
19032-
19033- # Get Go 1.9.2
19034- ENV GOLANG_VERSION 1.9.2
19035- ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
19036- ENV GOLANG_DOWNLOAD_SHA256 de874549d9a8d8d8062be05808509c09a88a248e77ec14eb77453530829ac02b
19037-
19038- RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
19039- && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \
19040- && tar -C /usr/local -xzf golang.tar.gz \
19041- && rm golang.tar.gz
19042-
19043- ENV PATH /usr/local/go/bin:$PATH
19044-
19045- # Linux and Glibc build dependencies
19046- RUN apt-get update && apt-get install -y \
19047- gawk make python \
19048- gcc gcc-multilib \
19049- gettext texinfo \
19050- && rm -rf /var/lib/apt/lists/*
19051- # Emulator and cross compilers
19052- RUN apt-get update && apt-get install -y \
19053- qemu \
19054- gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi \
19055- gcc-mips-linux-gnu gcc-mips64-linux-gnuabi64 \
19056- gcc-mips64el-linux-gnuabi64 gcc-mipsel-linux-gnu \
19057- gcc-powerpc64-linux-gnu gcc-powerpc64le-linux-gnu \
19058- gcc-s390x-linux-gnu gcc-sparc64-linux-gnu \
19059- && rm -rf /var/lib/apt/lists/*
19060-
19061- # Let the scripts know they are in the docker environment
19062- ENV GOLANG_SYS_BUILD docker
19063- WORKDIR /build
19064- ENTRYPOINT ["go", "run", "linux/mkall.go", "/git/linux", "/git/glibc"]
19065 diff --git a/vendor/golang.org/x/sys/unix/linux/mkall.go b/vendor/golang.org/x/sys/unix/linux/mkall.go
19066deleted file mode 100644
19067index 89b2fe8..0000000
19068--- a/vendor/golang.org/x/sys/unix/linux/mkall.go
19069+++ /dev/null
19070 @@ -1,482 +0,0 @@
19071- // Copyright 2017 The Go Authors. All rights reserved.
19072- // Use of this source code is governed by a BSD-style
19073- // license that can be found in the LICENSE file.
19074-
19075- // linux/mkall.go - Generates all Linux zsysnum, zsyscall, zerror, and ztype
19076- // files for all 11 linux architectures supported by the go compiler. See
19077- // README.md for more information about the build system.
19078-
19079- // To run it you must have a git checkout of the Linux kernel and glibc. Once
19080- // the appropriate sources are ready, the program is run as:
19081- // go run linux/mkall.go <linux_dir> <glibc_dir>
19082-
19083- // +build ignore
19084-
19085- package main
19086-
19087- import (
19088- "bufio"
19089- "bytes"
19090- "fmt"
19091- "io"
19092- "io/ioutil"
19093- "os"
19094- "os/exec"
19095- "path/filepath"
19096- "runtime"
19097- "strings"
19098- "unicode"
19099- )
19100-
19101- // These will be paths to the appropriate source directories.
19102- var LinuxDir string
19103- var GlibcDir string
19104-
19105- const TempDir = "/tmp"
19106- const IncludeDir = TempDir + "/include" // To hold our C headers
19107- const BuildDir = TempDir + "/build" // To hold intermediate build files
19108-
19109- const GOOS = "linux" // Only for Linux targets
19110- const BuildArch = "amd64" // Must be built on this architecture
19111- const MinKernel = "2.6.23" // https://golang.org/doc/install#requirements
19112-
19113- type target struct {
19114- GoArch string // Architecture name according to Go
19115- LinuxArch string // Architecture name according to the Linux Kernel
19116- GNUArch string // Architecture name according to GNU tools (https://wiki.debian.org/Multiarch/Tuples)
19117- BigEndian bool // Default Little Endian
19118- SignedChar bool // Is -fsigned-char needed (default no)
19119- Bits int
19120- }
19121-
19122- // List of the 11 Linux targets supported by the go compiler. sparc64 is not
19123- // currently supported, though a port is in progress.
19124- var targets = []target{
19125- {
19126- GoArch: "386",
19127- LinuxArch: "x86",
19128- GNUArch: "i686-linux-gnu", // Note "i686" not "i386"
19129- Bits: 32,
19130- },
19131- {
19132- GoArch: "amd64",
19133- LinuxArch: "x86",
19134- GNUArch: "x86_64-linux-gnu",
19135- Bits: 64,
19136- },
19137- {
19138- GoArch: "arm64",
19139- LinuxArch: "arm64",
19140- GNUArch: "aarch64-linux-gnu",
19141- SignedChar: true,
19142- Bits: 64,
19143- },
19144- {
19145- GoArch: "arm",
19146- LinuxArch: "arm",
19147- GNUArch: "arm-linux-gnueabi",
19148- Bits: 32,
19149- },
19150- {
19151- GoArch: "mips",
19152- LinuxArch: "mips",
19153- GNUArch: "mips-linux-gnu",
19154- BigEndian: true,
19155- Bits: 32,
19156- },
19157- {
19158- GoArch: "mipsle",
19159- LinuxArch: "mips",
19160- GNUArch: "mipsel-linux-gnu",
19161- Bits: 32,
19162- },
19163- {
19164- GoArch: "mips64",
19165- LinuxArch: "mips",
19166- GNUArch: "mips64-linux-gnuabi64",
19167- BigEndian: true,
19168- Bits: 64,
19169- },
19170- {
19171- GoArch: "mips64le",
19172- LinuxArch: "mips",
19173- GNUArch: "mips64el-linux-gnuabi64",
19174- Bits: 64,
19175- },
19176- {
19177- GoArch: "ppc64",
19178- LinuxArch: "powerpc",
19179- GNUArch: "powerpc64-linux-gnu",
19180- BigEndian: true,
19181- Bits: 64,
19182- },
19183- {
19184- GoArch: "ppc64le",
19185- LinuxArch: "powerpc",
19186- GNUArch: "powerpc64le-linux-gnu",
19187- Bits: 64,
19188- },
19189- {
19190- GoArch: "s390x",
19191- LinuxArch: "s390",
19192- GNUArch: "s390x-linux-gnu",
19193- BigEndian: true,
19194- SignedChar: true,
19195- Bits: 64,
19196- },
19197- // {
19198- // GoArch: "sparc64",
19199- // LinuxArch: "sparc",
19200- // GNUArch: "sparc64-linux-gnu",
19201- // BigEndian: true,
19202- // Bits: 64,
19203- // },
19204- }
19205-
19206- // ptracePairs is a list of pairs of targets that can, in some cases,
19207- // run each other's binaries.
19208- var ptracePairs = []struct{ a1, a2 string }{
19209- {"386", "amd64"},
19210- {"arm", "arm64"},
19211- {"mips", "mips64"},
19212- {"mipsle", "mips64le"},
19213- }
19214-
19215- func main() {
19216- if runtime.GOOS != GOOS || runtime.GOARCH != BuildArch {
19217- fmt.Printf("Build system has GOOS_GOARCH = %s_%s, need %s_%s\n",
19218- runtime.GOOS, runtime.GOARCH, GOOS, BuildArch)
19219- return
19220- }
19221-
19222- // Check that we are using the new build system if we should
19223- if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
19224- fmt.Println("In the new build system, mkall.go should not be called directly.")
19225- fmt.Println("See README.md")
19226- return
19227- }
19228-
19229- // Parse the command line options
19230- if len(os.Args) != 3 {
19231- fmt.Println("USAGE: go run linux/mkall.go <linux_dir> <glibc_dir>")
19232- return
19233- }
19234- LinuxDir = os.Args[1]
19235- GlibcDir = os.Args[2]
19236-
19237- for _, t := range targets {
19238- fmt.Printf("----- GENERATING: %s -----\n", t.GoArch)
19239- if err := t.generateFiles(); err != nil {
19240- fmt.Printf("%v\n***** FAILURE: %s *****\n\n", err, t.GoArch)
19241- } else {
19242- fmt.Printf("----- SUCCESS: %s -----\n\n", t.GoArch)
19243- }
19244- }
19245-
19246- fmt.Printf("----- GENERATING ptrace pairs -----\n")
19247- ok := true
19248- for _, p := range ptracePairs {
19249- if err := generatePtracePair(p.a1, p.a2); err != nil {
19250- fmt.Printf("%v\n***** FAILURE: %s/%s *****\n\n", err, p.a1, p.a2)
19251- ok = false
19252- }
19253- }
19254- if ok {
19255- fmt.Printf("----- SUCCESS ptrace pairs -----\n\n")
19256- }
19257- }
19258-
19259- // Makes an exec.Cmd with Stderr attached to os.Stderr
19260- func makeCommand(name string, args ...string) *exec.Cmd {
19261- cmd := exec.Command(name, args...)
19262- cmd.Stderr = os.Stderr
19263- return cmd
19264- }
19265-
19266- // Runs the command, pipes output to a formatter, pipes that to an output file.
19267- func (t *target) commandFormatOutput(formatter string, outputFile string,
19268- name string, args ...string) (err error) {
19269- mainCmd := makeCommand(name, args...)
19270-
19271- fmtCmd := makeCommand(formatter)
19272- if formatter == "mkpost" {
19273- fmtCmd = makeCommand("go", "run", "mkpost.go")
19274- // Set GOARCH_TARGET so mkpost knows what GOARCH is..
19275- fmtCmd.Env = append(os.Environ(), "GOARCH_TARGET="+t.GoArch)
19276- // Set GOARCH to host arch for mkpost, so it can run natively.
19277- for i, s := range fmtCmd.Env {
19278- if strings.HasPrefix(s, "GOARCH=") {
19279- fmtCmd.Env[i] = "GOARCH=" + BuildArch
19280- }
19281- }
19282- }
19283-
19284- // mainCmd | fmtCmd > outputFile
19285- if fmtCmd.Stdin, err = mainCmd.StdoutPipe(); err != nil {
19286- return
19287- }
19288- if fmtCmd.Stdout, err = os.Create(outputFile); err != nil {
19289- return
19290- }
19291-
19292- // Make sure the formatter eventually closes
19293- if err = fmtCmd.Start(); err != nil {
19294- return
19295- }
19296- defer func() {
19297- fmtErr := fmtCmd.Wait()
19298- if err == nil {
19299- err = fmtErr
19300- }
19301- }()
19302-
19303- return mainCmd.Run()
19304- }
19305-
19306- // Generates all the files for a Linux target
19307- func (t *target) generateFiles() error {
19308- // Setup environment variables
19309- os.Setenv("GOOS", GOOS)
19310- os.Setenv("GOARCH", t.GoArch)
19311-
19312- // Get appropriate compiler and emulator (unless on x86)
19313- if t.LinuxArch != "x86" {
19314- // Check/Setup cross compiler
19315- compiler := t.GNUArch + "-gcc"
19316- if _, err := exec.LookPath(compiler); err != nil {
19317- return err
19318- }
19319- os.Setenv("CC", compiler)
19320-
19321- // Check/Setup emulator (usually first component of GNUArch)
19322- qemuArchName := t.GNUArch[:strings.Index(t.GNUArch, "-")]
19323- if t.LinuxArch == "powerpc" {
19324- qemuArchName = t.GoArch
19325- }
19326- os.Setenv("GORUN", "qemu-"+qemuArchName)
19327- } else {
19328- os.Setenv("CC", "gcc")
19329- }
19330-
19331- // Make the include directory and fill it with headers
19332- if err := os.MkdirAll(IncludeDir, os.ModePerm); err != nil {
19333- return err
19334- }
19335- defer os.RemoveAll(IncludeDir)
19336- if err := t.makeHeaders(); err != nil {
19337- return fmt.Errorf("could not make header files: %v", err)
19338- }
19339- fmt.Println("header files generated")
19340-
19341- // Make each of the four files
19342- if err := t.makeZSysnumFile(); err != nil {
19343- return fmt.Errorf("could not make zsysnum file: %v", err)
19344- }
19345- fmt.Println("zsysnum file generated")
19346-
19347- if err := t.makeZSyscallFile(); err != nil {
19348- return fmt.Errorf("could not make zsyscall file: %v", err)
19349- }
19350- fmt.Println("zsyscall file generated")
19351-
19352- if err := t.makeZTypesFile(); err != nil {
19353- return fmt.Errorf("could not make ztypes file: %v", err)
19354- }
19355- fmt.Println("ztypes file generated")
19356-
19357- if err := t.makeZErrorsFile(); err != nil {
19358- return fmt.Errorf("could not make zerrors file: %v", err)
19359- }
19360- fmt.Println("zerrors file generated")
19361-
19362- return nil
19363- }
19364-
19365- // Create the Linux and glibc headers in the include directory.
19366- func (t *target) makeHeaders() error {
19367- // Make the Linux headers we need for this architecture
19368- linuxMake := makeCommand("make", "headers_install", "ARCH="+t.LinuxArch, "INSTALL_HDR_PATH="+TempDir)
19369- linuxMake.Dir = LinuxDir
19370- if err := linuxMake.Run(); err != nil {
19371- return err
19372- }
19373-
19374- // A Temporary build directory for glibc
19375- if err := os.MkdirAll(BuildDir, os.ModePerm); err != nil {
19376- return err
19377- }
19378- defer os.RemoveAll(BuildDir)
19379-
19380- // Make the glibc headers we need for this architecture
19381- confScript := filepath.Join(GlibcDir, "configure")
19382- glibcConf := makeCommand(confScript, "--prefix="+TempDir, "--host="+t.GNUArch, "--enable-kernel="+MinKernel)
19383- glibcConf.Dir = BuildDir
19384- if err := glibcConf.Run(); err != nil {
19385- return err
19386- }
19387- glibcMake := makeCommand("make", "install-headers")
19388- glibcMake.Dir = BuildDir
19389- if err := glibcMake.Run(); err != nil {
19390- return err
19391- }
19392- // We only need an empty stubs file
19393- stubsFile := filepath.Join(IncludeDir, "gnu/stubs.h")
19394- if file, err := os.Create(stubsFile); err != nil {
19395- return err
19396- } else {
19397- file.Close()
19398- }
19399-
19400- return nil
19401- }
19402-
19403- // makes the zsysnum_linux_$GOARCH.go file
19404- func (t *target) makeZSysnumFile() error {
19405- zsysnumFile := fmt.Sprintf("zsysnum_linux_%s.go", t.GoArch)
19406- unistdFile := filepath.Join(IncludeDir, "asm/unistd.h")
19407-
19408- args := append(t.cFlags(), unistdFile)
19409- return t.commandFormatOutput("gofmt", zsysnumFile, "linux/mksysnum.pl", args...)
19410- }
19411-
19412- // makes the zsyscall_linux_$GOARCH.go file
19413- func (t *target) makeZSyscallFile() error {
19414- zsyscallFile := fmt.Sprintf("zsyscall_linux_%s.go", t.GoArch)
19415- // Find the correct architecture syscall file (might end with x.go)
19416- archSyscallFile := fmt.Sprintf("syscall_linux_%s.go", t.GoArch)
19417- if _, err := os.Stat(archSyscallFile); os.IsNotExist(err) {
19418- shortArch := strings.TrimSuffix(t.GoArch, "le")
19419- archSyscallFile = fmt.Sprintf("syscall_linux_%sx.go", shortArch)
19420- }
19421-
19422- args := append(t.mksyscallFlags(), "-tags", "linux,"+t.GoArch,
19423- "syscall_linux.go", archSyscallFile)
19424- return t.commandFormatOutput("gofmt", zsyscallFile, "./mksyscall.pl", args...)
19425- }
19426-
19427- // makes the zerrors_linux_$GOARCH.go file
19428- func (t *target) makeZErrorsFile() error {
19429- zerrorsFile := fmt.Sprintf("zerrors_linux_%s.go", t.GoArch)
19430-
19431- return t.commandFormatOutput("gofmt", zerrorsFile, "./mkerrors.sh", t.cFlags()...)
19432- }
19433-
19434- // makes the ztypes_linux_$GOARCH.go file
19435- func (t *target) makeZTypesFile() error {
19436- ztypesFile := fmt.Sprintf("ztypes_linux_%s.go", t.GoArch)
19437-
19438- args := []string{"tool", "cgo", "-godefs", "--"}
19439- args = append(args, t.cFlags()...)
19440- args = append(args, "linux/types.go")
19441- return t.commandFormatOutput("mkpost", ztypesFile, "go", args...)
19442- }
19443-
19444- // Flags that should be given to gcc and cgo for this target
19445- func (t *target) cFlags() []string {
19446- // Compile statically to avoid cross-architecture dynamic linking.
19447- flags := []string{"-Wall", "-Werror", "-static", "-I" + IncludeDir}
19448-
19449- // Architecture-specific flags
19450- if t.SignedChar {
19451- flags = append(flags, "-fsigned-char")
19452- }
19453- if t.LinuxArch == "x86" {
19454- flags = append(flags, fmt.Sprintf("-m%d", t.Bits))
19455- }
19456-
19457- return flags
19458- }
19459-
19460- // Flags that should be given to mksyscall for this target
19461- func (t *target) mksyscallFlags() (flags []string) {
19462- if t.Bits == 32 {
19463- if t.BigEndian {
19464- flags = append(flags, "-b32")
19465- } else {
19466- flags = append(flags, "-l32")
19467- }
19468- }
19469-
19470- // This flag menas a 64-bit value should use (even, odd)-pair.
19471- if t.GoArch == "arm" || (t.LinuxArch == "mips" && t.Bits == 32) {
19472- flags = append(flags, "-arm")
19473- }
19474- return
19475- }
19476-
19477- // generatePtracePair takes a pair of GOARCH values that can run each
19478- // other's binaries, such as 386 and amd64. It extracts the PtraceRegs
19479- // type for each one. It writes a new file defining the types
19480- // PtraceRegsArch1 and PtraceRegsArch2 and the corresponding functions
19481- // Ptrace{Get,Set}Regs{arch1,arch2}. This permits debugging the other
19482- // binary on a native system.
19483- func generatePtracePair(arch1, arch2 string) error {
19484- def1, err := ptraceDef(arch1)
19485- if err != nil {
19486- return err
19487- }
19488- def2, err := ptraceDef(arch2)
19489- if err != nil {
19490- return err
19491- }
19492- f, err := os.Create(fmt.Sprintf("zptrace%s_linux.go", arch1))
19493- if err != nil {
19494- return err
19495- }
19496- buf := bufio.NewWriter(f)
19497- fmt.Fprintf(buf, "// Code generated by linux/mkall.go generatePtracePair(%s, %s). DO NOT EDIT.\n", arch1, arch2)
19498- fmt.Fprintf(buf, "\n")
19499- fmt.Fprintf(buf, "// +build linux\n")
19500- fmt.Fprintf(buf, "// +build %s %s\n", arch1, arch2)
19501- fmt.Fprintf(buf, "\n")
19502- fmt.Fprintf(buf, "package unix\n")
19503- fmt.Fprintf(buf, "\n")
19504- fmt.Fprintf(buf, "%s\n", `import "unsafe"`)
19505- fmt.Fprintf(buf, "\n")
19506- writeOnePtrace(buf, arch1, def1)
19507- fmt.Fprintf(buf, "\n")
19508- writeOnePtrace(buf, arch2, def2)
19509- if err := buf.Flush(); err != nil {
19510- return err
19511- }
19512- if err := f.Close(); err != nil {
19513- return err
19514- }
19515- return nil
19516- }
19517-
19518- // ptraceDef returns the definition of PtraceRegs for arch.
19519- func ptraceDef(arch string) (string, error) {
19520- filename := fmt.Sprintf("ztypes_linux_%s.go", arch)
19521- data, err := ioutil.ReadFile(filename)
19522- if err != nil {
19523- return "", fmt.Errorf("reading %s: %v", filename, err)
19524- }
19525- start := bytes.Index(data, []byte("type PtraceRegs struct"))
19526- if start < 0 {
19527- return "", fmt.Errorf("%s: no definition of PtraceRegs", filename)
19528- }
19529- data = data[start:]
19530- end := bytes.Index(data, []byte("\n}\n"))
19531- if end < 0 {
19532- return "", fmt.Errorf("%s: can't find end of PtraceRegs definition", filename)
19533- }
19534- return string(data[:end+2]), nil
19535- }
19536-
19537- // writeOnePtrace writes out the ptrace definitions for arch.
19538- func writeOnePtrace(w io.Writer, arch, def string) {
19539- uarch := string(unicode.ToUpper(rune(arch[0]))) + arch[1:]
19540- fmt.Fprintf(w, "// PtraceRegs%s is the registers used by %s binaries.\n", uarch, arch)
19541- fmt.Fprintf(w, "%s\n", strings.Replace(def, "PtraceRegs", "PtraceRegs"+uarch, 1))
19542- fmt.Fprintf(w, "\n")
19543- fmt.Fprintf(w, "// PtraceGetRegs%s fetches the registers used by %s binaries.\n", uarch, arch)
19544- fmt.Fprintf(w, "func PtraceGetRegs%s(pid int, regsout *PtraceRegs%s) error {\n", uarch, uarch)
19545- fmt.Fprintf(w, "\treturn ptrace(PTRACE_GETREGS, pid, 0, uintptr(unsafe.Pointer(regsout)))\n")
19546- fmt.Fprintf(w, "}\n")
19547- fmt.Fprintf(w, "\n")
19548- fmt.Fprintf(w, "// PtraceSetRegs%s sets the registers used by %s binaries.\n", uarch, arch)
19549- fmt.Fprintf(w, "func PtraceSetRegs%s(pid int, regs *PtraceRegs%s) error {\n", uarch, uarch)
19550- fmt.Fprintf(w, "\treturn ptrace(PTRACE_SETREGS, pid, 0, uintptr(unsafe.Pointer(regs)))\n")
19551- fmt.Fprintf(w, "}\n")
19552- }
19553 diff --git a/vendor/golang.org/x/sys/unix/linux/mksysnum.pl b/vendor/golang.org/x/sys/unix/linux/mksysnum.pl
19554deleted file mode 100755
19555index 63fd800..0000000
19556--- a/vendor/golang.org/x/sys/unix/linux/mksysnum.pl
19557+++ /dev/null
19558 @@ -1,85 +0,0 @@
19559- #!/usr/bin/env perl
19560- # Copyright 2009 The Go Authors. All rights reserved.
19561- # Use of this source code is governed by a BSD-style
19562- # license that can be found in the LICENSE file.
19563-
19564- use strict;
19565-
19566- if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") {
19567- print STDERR "GOARCH or GOOS not defined in environment\n";
19568- exit 1;
19569- }
19570-
19571- # Check that we are using the new build system if we should
19572- if($ENV{'GOLANG_SYS_BUILD'} ne "docker") {
19573- print STDERR "In the new build system, mksysnum should not be called directly.\n";
19574- print STDERR "See README.md\n";
19575- exit 1;
19576- }
19577-
19578- my $command = "$0 ". join(' ', @ARGV);
19579-
19580- print <<EOF;
19581- // $command
19582- // Code generated by the command above; see README.md. DO NOT EDIT.
19583-
19584- // +build $ENV{'GOARCH'},$ENV{'GOOS'}
19585-
19586- package unix
19587-
19588- const(
19589- EOF
19590-
19591- my $offset = 0;
19592-
19593- sub fmt {
19594- my ($name, $num) = @_;
19595- if($num > 999){
19596- # ignore deprecated syscalls that are no longer implemented
19597- # https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716
19598- return;
19599- }
19600- $name =~ y/a-z/A-Z/;
19601- $num = $num + $offset;
19602- print " SYS_$name = $num;\n";
19603- }
19604-
19605- my $prev;
19606- open(CC, "$ENV{'CC'} -E -dD @ARGV |") || die "can't run $ENV{'CC'}";
19607- while(<CC>){
19608- if(/^#define __NR_Linux\s+([0-9]+)/){
19609- # mips/mips64: extract offset
19610- $offset = $1;
19611- }
19612- elsif(/^#define __NR(\w*)_SYSCALL_BASE\s+([0-9]+)/){
19613- # arm: extract offset
19614- $offset = $1;
19615- }
19616- elsif(/^#define __NR_syscalls\s+/) {
19617- # ignore redefinitions of __NR_syscalls
19618- }
19619- elsif(/^#define __NR_(\w*)Linux_syscalls\s+/) {
19620- # mips/mips64: ignore definitions about the number of syscalls
19621- }
19622- elsif(/^#define __NR_(\w+)\s+([0-9]+)/){
19623- $prev = $2;
19624- fmt($1, $2);
19625- }
19626- elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){
19627- $prev = $2;
19628- fmt($1, $2);
19629- }
19630- elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
19631- fmt($1, $prev+$2)
19632- }
19633- elsif(/^#define __NR_(\w+)\s+\(__NR_Linux \+ ([0-9]+)/){
19634- fmt($1, $2);
19635- }
19636- elsif(/^#define __NR_(\w+)\s+\(__NR_SYSCALL_BASE \+ ([0-9]+)/){
19637- fmt($1, $2);
19638- }
19639- }
19640-
19641- print <<EOF;
19642- )
19643- EOF
19644 diff --git a/vendor/golang.org/x/sys/unix/linux/types.go b/vendor/golang.org/x/sys/unix/linux/types.go
19645deleted file mode 100644
19646index 1217fd8..0000000
19647--- a/vendor/golang.org/x/sys/unix/linux/types.go
19648+++ /dev/null
19649 @@ -1,645 +0,0 @@
19650- // Copyright 2009 The Go Authors. All rights reserved.
19651- // Use of this source code is governed by a BSD-style
19652- // license that can be found in the LICENSE file.
19653-
19654- // +build ignore
19655-
19656- /*
19657- Input to cgo -godefs. See README.md
19658- */
19659-
19660- // +godefs map struct_in_addr [4]byte /* in_addr */
19661- // +godefs map struct_in6_addr [16]byte /* in6_addr */
19662-
19663- package unix
19664-
19665- /*
19666- #define _LARGEFILE_SOURCE
19667- #define _LARGEFILE64_SOURCE
19668- #define _FILE_OFFSET_BITS 64
19669- #define _GNU_SOURCE
19670-
19671- #include <dirent.h>
19672- #include <netinet/in.h>
19673- #include <netinet/tcp.h>
19674- #include <netpacket/packet.h>
19675- #include <poll.h>
19676- #include <sched.h>
19677- #include <signal.h>
19678- #include <stdio.h>
19679- #include <sys/epoll.h>
19680- #include <sys/inotify.h>
19681- #include <sys/ioctl.h>
19682- #include <sys/mman.h>
19683- #include <sys/mount.h>
19684- #include <sys/param.h>
19685- #include <sys/ptrace.h>
19686- #include <sys/resource.h>
19687- #include <sys/select.h>
19688- #include <sys/signal.h>
19689- #include <sys/statfs.h>
19690- #include <sys/sysinfo.h>
19691- #include <sys/time.h>
19692- #include <sys/times.h>
19693- #include <sys/timex.h>
19694- #include <sys/un.h>
19695- #include <sys/user.h>
19696- #include <sys/utsname.h>
19697- #include <sys/wait.h>
19698- #include <linux/filter.h>
19699- #include <linux/icmpv6.h>
19700- #include <linux/keyctl.h>
19701- #include <linux/netlink.h>
19702- #include <linux/perf_event.h>
19703- #include <linux/rtnetlink.h>
19704- #include <linux/stat.h>
19705- #include <asm/termbits.h>
19706- #include <asm/ptrace.h>
19707- #include <time.h>
19708- #include <unistd.h>
19709- #include <ustat.h>
19710- #include <utime.h>
19711- #include <linux/can.h>
19712- #include <linux/if_alg.h>
19713- #include <linux/fs.h>
19714- #include <linux/vm_sockets.h>
19715- #include <linux/random.h>
19716- #include <linux/taskstats.h>
19717- #include <linux/cgroupstats.h>
19718- #include <linux/genetlink.h>
19719-
19720- // On mips64, the glibc stat and kernel stat do not agree
19721- #if (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI64)
19722-
19723- // Use the stat defined by the kernel with a few modifications. These are:
19724- // * The time fields (like st_atime and st_atimensec) use the timespec
19725- // struct (like st_atim) for consitancy with the glibc fields.
19726- // * The padding fields get different names to not break compatibility.
19727- // * st_blocks is signed, again for compatibility.
19728- struct stat {
19729- unsigned int st_dev;
19730- unsigned int st_pad1[3]; // Reserved for st_dev expansion
19731-
19732- unsigned long st_ino;
19733-
19734- mode_t st_mode;
19735- __u32 st_nlink;
19736-
19737- uid_t st_uid;
19738- gid_t st_gid;
19739-
19740- unsigned int st_rdev;
19741- unsigned int st_pad2[3]; // Reserved for st_rdev expansion
19742-
19743- off_t st_size;
19744-
19745- // These are declared as speperate fields in the kernel. Here we use
19746- // the timespec struct for consistancy with the other stat structs.
19747- struct timespec st_atim;
19748- struct timespec st_mtim;
19749- struct timespec st_ctim;
19750-
19751- unsigned int st_blksize;
19752- unsigned int st_pad4;
19753-
19754- long st_blocks;
19755- };
19756-
19757- // These are needed because we do not include fcntl.h or sys/types.h
19758- #include <linux/fcntl.h>
19759- #include <linux/fadvise.h>
19760-
19761- #else
19762-
19763- // Use the stat defined by glibc
19764- #include <fcntl.h>
19765- #include <sys/types.h>
19766-
19767- #endif
19768-
19769- // These are defined in linux/fcntl.h, but including it globally causes
19770- // conflicts with fcntl.h
19771- #ifndef AT_STATX_SYNC_TYPE
19772- # define AT_STATX_SYNC_TYPE 0x6000 // Type of synchronisation required from statx()
19773- #endif
19774- #ifndef AT_STATX_SYNC_AS_STAT
19775- # define AT_STATX_SYNC_AS_STAT 0x0000 // - Do whatever stat() does
19776- #endif
19777- #ifndef AT_STATX_FORCE_SYNC
19778- # define AT_STATX_FORCE_SYNC 0x2000 // - Force the attributes to be sync'd with the server
19779- #endif
19780- #ifndef AT_STATX_DONT_SYNC
19781- # define AT_STATX_DONT_SYNC 0x4000 // - Don't sync attributes with the server
19782- #endif
19783-
19784- #ifdef TCSETS2
19785- // On systems that have "struct termios2" use this as type Termios.
19786- typedef struct termios2 termios_t;
19787- #else
19788- typedef struct termios termios_t;
19789- #endif
19790-
19791- enum {
19792- sizeofPtr = sizeof(void*),
19793- };
19794-
19795- union sockaddr_all {
19796- struct sockaddr s1; // this one gets used for fields
19797- struct sockaddr_in s2; // these pad it out
19798- struct sockaddr_in6 s3;
19799- struct sockaddr_un s4;
19800- struct sockaddr_ll s5;
19801- struct sockaddr_nl s6;
19802- };
19803-
19804- struct sockaddr_any {
19805- struct sockaddr addr;
19806- char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
19807- };
19808-
19809- // copied from /usr/include/bluetooth/hci.h
19810- struct sockaddr_hci {
19811- sa_family_t hci_family;
19812- unsigned short hci_dev;
19813- unsigned short hci_channel;
19814- };;
19815-
19816- // copied from /usr/include/linux/un.h
19817- struct my_sockaddr_un {
19818- sa_family_t sun_family;
19819- #if defined(__ARM_EABI__) || defined(__powerpc64__)
19820- // on ARM char is by default unsigned
19821- signed char sun_path[108];
19822- #else
19823- char sun_path[108];
19824- #endif
19825- };
19826-
19827- #ifdef __ARM_EABI__
19828- typedef struct user_regs PtraceRegs;
19829- #elif defined(__aarch64__)
19830- typedef struct user_pt_regs PtraceRegs;
19831- #elif defined(__mips__) || defined(__powerpc64__)
19832- typedef struct pt_regs PtraceRegs;
19833- #elif defined(__s390x__)
19834- typedef struct _user_regs_struct PtraceRegs;
19835- #elif defined(__sparc__)
19836- #include <asm/ptrace.h>
19837- typedef struct pt_regs PtraceRegs;
19838- #else
19839- typedef struct user_regs_struct PtraceRegs;
19840- #endif
19841-
19842- #if defined(__s390x__)
19843- typedef struct _user_psw_struct ptracePsw;
19844- typedef struct _user_fpregs_struct ptraceFpregs;
19845- typedef struct _user_per_struct ptracePer;
19846- #else
19847- typedef struct {} ptracePsw;
19848- typedef struct {} ptraceFpregs;
19849- typedef struct {} ptracePer;
19850- #endif
19851-
19852- // The real epoll_event is a union, and godefs doesn't handle it well.
19853- struct my_epoll_event {
19854- uint32_t events;
19855- #if defined(__ARM_EABI__) || defined(__aarch64__) || (defined(__mips__) && _MIPS_SIM == _ABIO32)
19856- // padding is not specified in linux/eventpoll.h but added to conform to the
19857- // alignment requirements of EABI
19858- int32_t padFd;
19859- #elif defined(__powerpc64__) || defined(__s390x__) || defined(__sparc__)
19860- int32_t _padFd;
19861- #endif
19862- int32_t fd;
19863- int32_t pad;
19864- };
19865-
19866- */
19867- import "C"
19868-
19869- // Machine characteristics; for internal use.
19870-
19871- const (
19872- sizeofPtr = C.sizeofPtr
19873- sizeofShort = C.sizeof_short
19874- sizeofInt = C.sizeof_int
19875- sizeofLong = C.sizeof_long
19876- sizeofLongLong = C.sizeof_longlong
19877- PathMax = C.PATH_MAX
19878- )
19879-
19880- // Basic types
19881-
19882- type (
19883- _C_short C.short
19884- _C_int C.int
19885- _C_long C.long
19886- _C_long_long C.longlong
19887- )
19888-
19889- // Time
19890-
19891- type Timespec C.struct_timespec
19892-
19893- type Timeval C.struct_timeval
19894-
19895- type Timex C.struct_timex
19896-
19897- type Time_t C.time_t
19898-
19899- type Tms C.struct_tms
19900-
19901- type Utimbuf C.struct_utimbuf
19902-
19903- // Processes
19904-
19905- type Rusage C.struct_rusage
19906-
19907- type Rlimit C.struct_rlimit
19908-
19909- type _Gid_t C.gid_t
19910-
19911- // Files
19912-
19913- type Stat_t C.struct_stat
19914-
19915- type Statfs_t C.struct_statfs
19916-
19917- type StatxTimestamp C.struct_statx_timestamp
19918-
19919- type Statx_t C.struct_statx
19920-
19921- type Dirent C.struct_dirent
19922-
19923- type Fsid C.fsid_t
19924-
19925- type Flock_t C.struct_flock
19926-
19927- // Filesystem Encryption
19928-
19929- type FscryptPolicy C.struct_fscrypt_policy
19930-
19931- type FscryptKey C.struct_fscrypt_key
19932-
19933- // Structure for Keyctl
19934-
19935- type KeyctlDHParams C.struct_keyctl_dh_params
19936-
19937- // Advice to Fadvise
19938-
19939- const (
19940- FADV_NORMAL = C.POSIX_FADV_NORMAL
19941- FADV_RANDOM = C.POSIX_FADV_RANDOM
19942- FADV_SEQUENTIAL = C.POSIX_FADV_SEQUENTIAL
19943- FADV_WILLNEED = C.POSIX_FADV_WILLNEED
19944- FADV_DONTNEED = C.POSIX_FADV_DONTNEED
19945- FADV_NOREUSE = C.POSIX_FADV_NOREUSE
19946- )
19947-
19948- // Sockets
19949-
19950- type RawSockaddrInet4 C.struct_sockaddr_in
19951-
19952- type RawSockaddrInet6 C.struct_sockaddr_in6
19953-
19954- type RawSockaddrUnix C.struct_my_sockaddr_un
19955-
19956- type RawSockaddrLinklayer C.struct_sockaddr_ll
19957-
19958- type RawSockaddrNetlink C.struct_sockaddr_nl
19959-
19960- type RawSockaddrHCI C.struct_sockaddr_hci
19961-
19962- type RawSockaddrCAN C.struct_sockaddr_can
19963-
19964- type RawSockaddrALG C.struct_sockaddr_alg
19965-
19966- type RawSockaddrVM C.struct_sockaddr_vm
19967-
19968- type RawSockaddr C.struct_sockaddr
19969-
19970- type RawSockaddrAny C.struct_sockaddr_any
19971-
19972- type _Socklen C.socklen_t
19973-
19974- type Linger C.struct_linger
19975-
19976- type Iovec C.struct_iovec
19977-
19978- type IPMreq C.struct_ip_mreq
19979-
19980- type IPMreqn C.struct_ip_mreqn
19981-
19982- type IPv6Mreq C.struct_ipv6_mreq
19983-
19984- type PacketMreq C.struct_packet_mreq
19985-
19986- type Msghdr C.struct_msghdr
19987-
19988- type Cmsghdr C.struct_cmsghdr
19989-
19990- type Inet4Pktinfo C.struct_in_pktinfo
19991-
19992- type Inet6Pktinfo C.struct_in6_pktinfo
19993-
19994- type IPv6MTUInfo C.struct_ip6_mtuinfo
19995-
19996- type ICMPv6Filter C.struct_icmp6_filter
19997-
19998- type Ucred C.struct_ucred
19999-
20000- type TCPInfo C.struct_tcp_info
20001-
20002- const (
20003- SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in
20004- SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
20005- SizeofSockaddrAny = C.sizeof_struct_sockaddr_any
20006- SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un
20007- SizeofSockaddrLinklayer = C.sizeof_struct_sockaddr_ll
20008- SizeofSockaddrNetlink = C.sizeof_struct_sockaddr_nl
20009- SizeofSockaddrHCI = C.sizeof_struct_sockaddr_hci
20010- SizeofSockaddrCAN = C.sizeof_struct_sockaddr_can
20011- SizeofSockaddrALG = C.sizeof_struct_sockaddr_alg
20012- SizeofSockaddrVM = C.sizeof_struct_sockaddr_vm
20013- SizeofLinger = C.sizeof_struct_linger
20014- SizeofIovec = C.sizeof_struct_iovec
20015- SizeofIPMreq = C.sizeof_struct_ip_mreq
20016- SizeofIPMreqn = C.sizeof_struct_ip_mreqn
20017- SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq
20018- SizeofPacketMreq = C.sizeof_struct_packet_mreq
20019- SizeofMsghdr = C.sizeof_struct_msghdr
20020- SizeofCmsghdr = C.sizeof_struct_cmsghdr
20021- SizeofInet4Pktinfo = C.sizeof_struct_in_pktinfo
20022- SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo
20023- SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo
20024- SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter
20025- SizeofUcred = C.sizeof_struct_ucred
20026- SizeofTCPInfo = C.sizeof_struct_tcp_info
20027- )
20028-
20029- // Netlink routing and interface messages
20030-
20031- const (
20032- IFA_UNSPEC = C.IFA_UNSPEC
20033- IFA_ADDRESS = C.IFA_ADDRESS
20034- IFA_LOCAL = C.IFA_LOCAL
20035- IFA_LABEL = C.IFA_LABEL
20036- IFA_BROADCAST = C.IFA_BROADCAST
20037- IFA_ANYCAST = C.IFA_ANYCAST
20038- IFA_CACHEINFO = C.IFA_CACHEINFO
20039- IFA_MULTICAST = C.IFA_MULTICAST
20040- IFLA_UNSPEC = C.IFLA_UNSPEC
20041- IFLA_ADDRESS = C.IFLA_ADDRESS
20042- IFLA_BROADCAST = C.IFLA_BROADCAST
20043- IFLA_IFNAME = C.IFLA_IFNAME
20044- IFLA_MTU = C.IFLA_MTU
20045- IFLA_LINK = C.IFLA_LINK
20046- IFLA_QDISC = C.IFLA_QDISC
20047- IFLA_STATS = C.IFLA_STATS
20048- IFLA_COST = C.IFLA_COST
20049- IFLA_PRIORITY = C.IFLA_PRIORITY
20050- IFLA_MASTER = C.IFLA_MASTER
20051- IFLA_WIRELESS = C.IFLA_WIRELESS
20052- IFLA_PROTINFO = C.IFLA_PROTINFO
20053- IFLA_TXQLEN = C.IFLA_TXQLEN
20054- IFLA_MAP = C.IFLA_MAP
20055- IFLA_WEIGHT = C.IFLA_WEIGHT
20056- IFLA_OPERSTATE = C.IFLA_OPERSTATE
20057- IFLA_LINKMODE = C.IFLA_LINKMODE
20058- IFLA_LINKINFO = C.IFLA_LINKINFO
20059- IFLA_NET_NS_PID = C.IFLA_NET_NS_PID
20060- IFLA_IFALIAS = C.IFLA_IFALIAS
20061- IFLA_MAX = C.IFLA_MAX
20062- RT_SCOPE_UNIVERSE = C.RT_SCOPE_UNIVERSE
20063- RT_SCOPE_SITE = C.RT_SCOPE_SITE
20064- RT_SCOPE_LINK = C.RT_SCOPE_LINK
20065- RT_SCOPE_HOST = C.RT_SCOPE_HOST
20066- RT_SCOPE_NOWHERE = C.RT_SCOPE_NOWHERE
20067- RT_TABLE_UNSPEC = C.RT_TABLE_UNSPEC
20068- RT_TABLE_COMPAT = C.RT_TABLE_COMPAT
20069- RT_TABLE_DEFAULT = C.RT_TABLE_DEFAULT
20070- RT_TABLE_MAIN = C.RT_TABLE_MAIN
20071- RT_TABLE_LOCAL = C.RT_TABLE_LOCAL
20072- RT_TABLE_MAX = C.RT_TABLE_MAX
20073- RTA_UNSPEC = C.RTA_UNSPEC
20074- RTA_DST = C.RTA_DST
20075- RTA_SRC = C.RTA_SRC
20076- RTA_IIF = C.RTA_IIF
20077- RTA_OIF = C.RTA_OIF
20078- RTA_GATEWAY = C.RTA_GATEWAY
20079- RTA_PRIORITY = C.RTA_PRIORITY
20080- RTA_PREFSRC = C.RTA_PREFSRC
20081- RTA_METRICS = C.RTA_METRICS
20082- RTA_MULTIPATH = C.RTA_MULTIPATH
20083- RTA_FLOW = C.RTA_FLOW
20084- RTA_CACHEINFO = C.RTA_CACHEINFO
20085- RTA_TABLE = C.RTA_TABLE
20086- RTN_UNSPEC = C.RTN_UNSPEC
20087- RTN_UNICAST = C.RTN_UNICAST
20088- RTN_LOCAL = C.RTN_LOCAL
20089- RTN_BROADCAST = C.RTN_BROADCAST
20090- RTN_ANYCAST = C.RTN_ANYCAST
20091- RTN_MULTICAST = C.RTN_MULTICAST
20092- RTN_BLACKHOLE = C.RTN_BLACKHOLE
20093- RTN_UNREACHABLE = C.RTN_UNREACHABLE
20094- RTN_PROHIBIT = C.RTN_PROHIBIT
20095- RTN_THROW = C.RTN_THROW
20096- RTN_NAT = C.RTN_NAT
20097- RTN_XRESOLVE = C.RTN_XRESOLVE
20098- RTNLGRP_NONE = C.RTNLGRP_NONE
20099- RTNLGRP_LINK = C.RTNLGRP_LINK
20100- RTNLGRP_NOTIFY = C.RTNLGRP_NOTIFY
20101- RTNLGRP_NEIGH = C.RTNLGRP_NEIGH
20102- RTNLGRP_TC = C.RTNLGRP_TC
20103- RTNLGRP_IPV4_IFADDR = C.RTNLGRP_IPV4_IFADDR
20104- RTNLGRP_IPV4_MROUTE = C.RTNLGRP_IPV4_MROUTE
20105- RTNLGRP_IPV4_ROUTE = C.RTNLGRP_IPV4_ROUTE
20106- RTNLGRP_IPV4_RULE = C.RTNLGRP_IPV4_RULE
20107- RTNLGRP_IPV6_IFADDR = C.RTNLGRP_IPV6_IFADDR
20108- RTNLGRP_IPV6_MROUTE = C.RTNLGRP_IPV6_MROUTE
20109- RTNLGRP_IPV6_ROUTE = C.RTNLGRP_IPV6_ROUTE
20110- RTNLGRP_IPV6_IFINFO = C.RTNLGRP_IPV6_IFINFO
20111- RTNLGRP_IPV6_PREFIX = C.RTNLGRP_IPV6_PREFIX
20112- RTNLGRP_IPV6_RULE = C.RTNLGRP_IPV6_RULE
20113- RTNLGRP_ND_USEROPT = C.RTNLGRP_ND_USEROPT
20114- SizeofNlMsghdr = C.sizeof_struct_nlmsghdr
20115- SizeofNlMsgerr = C.sizeof_struct_nlmsgerr
20116- SizeofRtGenmsg = C.sizeof_struct_rtgenmsg
20117- SizeofNlAttr = C.sizeof_struct_nlattr
20118- SizeofRtAttr = C.sizeof_struct_rtattr
20119- SizeofIfInfomsg = C.sizeof_struct_ifinfomsg
20120- SizeofIfAddrmsg = C.sizeof_struct_ifaddrmsg
20121- SizeofRtMsg = C.sizeof_struct_rtmsg
20122- SizeofRtNexthop = C.sizeof_struct_rtnexthop
20123- )
20124-
20125- type NlMsghdr C.struct_nlmsghdr
20126-
20127- type NlMsgerr C.struct_nlmsgerr
20128-
20129- type RtGenmsg C.struct_rtgenmsg
20130-
20131- type NlAttr C.struct_nlattr
20132-
20133- type RtAttr C.struct_rtattr
20134-
20135- type IfInfomsg C.struct_ifinfomsg
20136-
20137- type IfAddrmsg C.struct_ifaddrmsg
20138-
20139- type RtMsg C.struct_rtmsg
20140-
20141- type RtNexthop C.struct_rtnexthop
20142-
20143- // Linux socket filter
20144-
20145- const (
20146- SizeofSockFilter = C.sizeof_struct_sock_filter
20147- SizeofSockFprog = C.sizeof_struct_sock_fprog
20148- )
20149-
20150- type SockFilter C.struct_sock_filter
20151-
20152- type SockFprog C.struct_sock_fprog
20153-
20154- // Inotify
20155-
20156- type InotifyEvent C.struct_inotify_event
20157-
20158- const SizeofInotifyEvent = C.sizeof_struct_inotify_event
20159-
20160- // Ptrace
20161-
20162- // Register structures
20163- type PtraceRegs C.PtraceRegs
20164-
20165- // Structures contained in PtraceRegs on s390x (exported by mkpost.go)
20166- type PtracePsw C.ptracePsw
20167-
20168- type PtraceFpregs C.ptraceFpregs
20169-
20170- type PtracePer C.ptracePer
20171-
20172- // Misc
20173-
20174- type FdSet C.fd_set
20175-
20176- type Sysinfo_t C.struct_sysinfo
20177-
20178- type Utsname C.struct_utsname
20179-
20180- type Ustat_t C.struct_ustat
20181-
20182- type EpollEvent C.struct_my_epoll_event
20183-
20184- const (
20185- AT_EMPTY_PATH = C.AT_EMPTY_PATH
20186- AT_FDCWD = C.AT_FDCWD
20187- AT_NO_AUTOMOUNT = C.AT_NO_AUTOMOUNT
20188- AT_REMOVEDIR = C.AT_REMOVEDIR
20189-
20190- AT_STATX_SYNC_AS_STAT = C.AT_STATX_SYNC_AS_STAT
20191- AT_STATX_FORCE_SYNC = C.AT_STATX_FORCE_SYNC
20192- AT_STATX_DONT_SYNC = C.AT_STATX_DONT_SYNC
20193-
20194- AT_SYMLINK_FOLLOW = C.AT_SYMLINK_FOLLOW
20195- AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
20196- )
20197-
20198- type PollFd C.struct_pollfd
20199-
20200- const (
20201- POLLIN = C.POLLIN
20202- POLLPRI = C.POLLPRI
20203- POLLOUT = C.POLLOUT
20204- POLLRDHUP = C.POLLRDHUP
20205- POLLERR = C.POLLERR
20206- POLLHUP = C.POLLHUP
20207- POLLNVAL = C.POLLNVAL
20208- )
20209-
20210- type Sigset_t C.sigset_t
20211-
20212- const RNDGETENTCNT = C.RNDGETENTCNT
20213-
20214- const PERF_IOC_FLAG_GROUP = C.PERF_IOC_FLAG_GROUP
20215-
20216- // Terminal handling
20217-
20218- type Termios C.termios_t
20219-
20220- type Winsize C.struct_winsize
20221-
20222- // Taskstats and cgroup stats.
20223-
20224- type Taskstats C.struct_taskstats
20225-
20226- const (
20227- TASKSTATS_CMD_UNSPEC = C.TASKSTATS_CMD_UNSPEC
20228- TASKSTATS_CMD_GET = C.TASKSTATS_CMD_GET
20229- TASKSTATS_CMD_NEW = C.TASKSTATS_CMD_NEW
20230- TASKSTATS_TYPE_UNSPEC = C.TASKSTATS_TYPE_UNSPEC
20231- TASKSTATS_TYPE_PID = C.TASKSTATS_TYPE_PID
20232- TASKSTATS_TYPE_TGID = C.TASKSTATS_TYPE_TGID
20233- TASKSTATS_TYPE_STATS = C.TASKSTATS_TYPE_STATS
20234- TASKSTATS_TYPE_AGGR_PID = C.TASKSTATS_TYPE_AGGR_PID
20235- TASKSTATS_TYPE_AGGR_TGID = C.TASKSTATS_TYPE_AGGR_TGID
20236- TASKSTATS_TYPE_NULL = C.TASKSTATS_TYPE_NULL
20237- TASKSTATS_CMD_ATTR_UNSPEC = C.TASKSTATS_CMD_ATTR_UNSPEC
20238- TASKSTATS_CMD_ATTR_PID = C.TASKSTATS_CMD_ATTR_PID
20239- TASKSTATS_CMD_ATTR_TGID = C.TASKSTATS_CMD_ATTR_TGID
20240- TASKSTATS_CMD_ATTR_REGISTER_CPUMASK = C.TASKSTATS_CMD_ATTR_REGISTER_CPUMASK
20241- TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK = C.TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK
20242- )
20243-
20244- type CGroupStats C.struct_cgroupstats
20245-
20246- const (
20247- CGROUPSTATS_CMD_UNSPEC = C.__TASKSTATS_CMD_MAX
20248- CGROUPSTATS_CMD_GET = C.CGROUPSTATS_CMD_GET
20249- CGROUPSTATS_CMD_NEW = C.CGROUPSTATS_CMD_NEW
20250- CGROUPSTATS_TYPE_UNSPEC = C.CGROUPSTATS_TYPE_UNSPEC
20251- CGROUPSTATS_TYPE_CGROUP_STATS = C.CGROUPSTATS_TYPE_CGROUP_STATS
20252- CGROUPSTATS_CMD_ATTR_UNSPEC = C.CGROUPSTATS_CMD_ATTR_UNSPEC
20253- CGROUPSTATS_CMD_ATTR_FD = C.CGROUPSTATS_CMD_ATTR_FD
20254- )
20255-
20256- // Generic netlink
20257-
20258- type Genlmsghdr C.struct_genlmsghdr
20259-
20260- const (
20261- CTRL_CMD_UNSPEC = C.CTRL_CMD_UNSPEC
20262- CTRL_CMD_NEWFAMILY = C.CTRL_CMD_NEWFAMILY
20263- CTRL_CMD_DELFAMILY = C.CTRL_CMD_DELFAMILY
20264- CTRL_CMD_GETFAMILY = C.CTRL_CMD_GETFAMILY
20265- CTRL_CMD_NEWOPS = C.CTRL_CMD_NEWOPS
20266- CTRL_CMD_DELOPS = C.CTRL_CMD_DELOPS
20267- CTRL_CMD_GETOPS = C.CTRL_CMD_GETOPS
20268- CTRL_CMD_NEWMCAST_GRP = C.CTRL_CMD_NEWMCAST_GRP
20269- CTRL_CMD_DELMCAST_GRP = C.CTRL_CMD_DELMCAST_GRP
20270- CTRL_CMD_GETMCAST_GRP = C.CTRL_CMD_GETMCAST_GRP
20271- CTRL_ATTR_UNSPEC = C.CTRL_ATTR_UNSPEC
20272- CTRL_ATTR_FAMILY_ID = C.CTRL_ATTR_FAMILY_ID
20273- CTRL_ATTR_FAMILY_NAME = C.CTRL_ATTR_FAMILY_NAME
20274- CTRL_ATTR_VERSION = C.CTRL_ATTR_VERSION
20275- CTRL_ATTR_HDRSIZE = C.CTRL_ATTR_HDRSIZE
20276- CTRL_ATTR_MAXATTR = C.CTRL_ATTR_MAXATTR
20277- CTRL_ATTR_OPS = C.CTRL_ATTR_OPS
20278- CTRL_ATTR_MCAST_GROUPS = C.CTRL_ATTR_MCAST_GROUPS
20279- CTRL_ATTR_OP_UNSPEC = C.CTRL_ATTR_OP_UNSPEC
20280- CTRL_ATTR_OP_ID = C.CTRL_ATTR_OP_ID
20281- CTRL_ATTR_OP_FLAGS = C.CTRL_ATTR_OP_FLAGS
20282- CTRL_ATTR_MCAST_GRP_UNSPEC = C.CTRL_ATTR_MCAST_GRP_UNSPEC
20283- CTRL_ATTR_MCAST_GRP_NAME = C.CTRL_ATTR_MCAST_GRP_NAME
20284- CTRL_ATTR_MCAST_GRP_ID = C.CTRL_ATTR_MCAST_GRP_ID
20285- )
20286-
20287- // CPU affinity
20288-
20289- type cpuMask C.__cpu_mask
20290-
20291- const (
20292- _CPU_SETSIZE = C.__CPU_SETSIZE
20293- _NCPUBITS = C.__NCPUBITS
20294- )
20295 diff --git a/vendor/golang.org/x/sys/windows/asm_windows_386.s b/vendor/golang.org/x/sys/windows/asm_windows_386.s
20296deleted file mode 100644
20297index 1c20dd2..0000000
20298--- a/vendor/golang.org/x/sys/windows/asm_windows_386.s
20299+++ /dev/null
20300 @@ -1,13 +0,0 @@
20301- // Copyright 2009 The Go Authors. All rights reserved.
20302- // Use of this source code is governed by a BSD-style
20303- // license that can be found in the LICENSE file.
20304-
20305- //
20306- // System calls for 386, Windows are implemented in runtime/syscall_windows.goc
20307- //
20308-
20309- TEXT ·getprocaddress(SB), 7, $0-8
20310- JMP syscall·getprocaddress(SB)
20311-
20312- TEXT ·loadlibrary(SB), 7, $0-4
20313- JMP syscall·loadlibrary(SB)
20314 diff --git a/vendor/golang.org/x/sys/windows/asm_windows_amd64.s b/vendor/golang.org/x/sys/windows/asm_windows_amd64.s
20315deleted file mode 100644
20316index 4d025ab..0000000
20317--- a/vendor/golang.org/x/sys/windows/asm_windows_amd64.s
20318+++ /dev/null
20319 @@ -1,13 +0,0 @@
20320- // Copyright 2009 The Go Authors. All rights reserved.
20321- // Use of this source code is governed by a BSD-style
20322- // license that can be found in the LICENSE file.
20323-
20324- //
20325- // System calls for amd64, Windows are implemented in runtime/syscall_windows.goc
20326- //
20327-
20328- TEXT ·getprocaddress(SB), 7, $0-32
20329- JMP syscall·getprocaddress(SB)
20330-
20331- TEXT ·loadlibrary(SB), 7, $0-8
20332- JMP syscall·loadlibrary(SB)
20333 diff --git a/vendor/golang.org/x/sys/windows/dll_windows.go b/vendor/golang.org/x/sys/windows/dll_windows.go
20334deleted file mode 100644
20335index e92c05b..0000000
20336--- a/vendor/golang.org/x/sys/windows/dll_windows.go
20337+++ /dev/null
20338 @@ -1,378 +0,0 @@
20339- // Copyright 2011 The Go Authors. All rights reserved.
20340- // Use of this source code is governed by a BSD-style
20341- // license that can be found in the LICENSE file.
20342-
20343- package windows
20344-
20345- import (
20346- "sync"
20347- "sync/atomic"
20348- "syscall"
20349- "unsafe"
20350- )
20351-
20352- // DLLError describes reasons for DLL load failures.
20353- type DLLError struct {
20354- Err error
20355- ObjName string
20356- Msg string
20357- }
20358-
20359- func (e *DLLError) Error() string { return e.Msg }
20360-
20361- // Implemented in runtime/syscall_windows.goc; we provide jumps to them in our assembly file.
20362- func loadlibrary(filename *uint16) (handle uintptr, err syscall.Errno)
20363- func getprocaddress(handle uintptr, procname *uint8) (proc uintptr, err syscall.Errno)
20364-
20365- // A DLL implements access to a single DLL.
20366- type DLL struct {
20367- Name string
20368- Handle Handle
20369- }
20370-
20371- // LoadDLL loads DLL file into memory.
20372- //
20373- // Warning: using LoadDLL without an absolute path name is subject to
20374- // DLL preloading attacks. To safely load a system DLL, use LazyDLL
20375- // with System set to true, or use LoadLibraryEx directly.
20376- func LoadDLL(name string) (dll *DLL, err error) {
20377- namep, err := UTF16PtrFromString(name)
20378- if err != nil {
20379- return nil, err
20380- }
20381- h, e := loadlibrary(namep)
20382- if e != 0 {
20383- return nil, &DLLError{
20384- Err: e,
20385- ObjName: name,
20386- Msg: "Failed to load " + name + ": " + e.Error(),
20387- }
20388- }
20389- d := &DLL{
20390- Name: name,
20391- Handle: Handle(h),
20392- }
20393- return d, nil
20394- }
20395-
20396- // MustLoadDLL is like LoadDLL but panics if load operation failes.
20397- func MustLoadDLL(name string) *DLL {
20398- d, e := LoadDLL(name)
20399- if e != nil {
20400- panic(e)
20401- }
20402- return d
20403- }
20404-
20405- // FindProc searches DLL d for procedure named name and returns *Proc
20406- // if found. It returns an error if search fails.
20407- func (d *DLL) FindProc(name string) (proc *Proc, err error) {
20408- namep, err := BytePtrFromString(name)
20409- if err != nil {
20410- return nil, err
20411- }
20412- a, e := getprocaddress(uintptr(d.Handle), namep)
20413- if e != 0 {
20414- return nil, &DLLError{
20415- Err: e,
20416- ObjName: name,
20417- Msg: "Failed to find " + name + " procedure in " + d.Name + ": " + e.Error(),
20418- }
20419- }
20420- p := &Proc{
20421- Dll: d,
20422- Name: name,
20423- addr: a,
20424- }
20425- return p, nil
20426- }
20427-
20428- // MustFindProc is like FindProc but panics if search fails.
20429- func (d *DLL) MustFindProc(name string) *Proc {
20430- p, e := d.FindProc(name)
20431- if e != nil {
20432- panic(e)
20433- }
20434- return p
20435- }
20436-
20437- // Release unloads DLL d from memory.
20438- func (d *DLL) Release() (err error) {
20439- return FreeLibrary(d.Handle)
20440- }
20441-
20442- // A Proc implements access to a procedure inside a DLL.
20443- type Proc struct {
20444- Dll *DLL
20445- Name string
20446- addr uintptr
20447- }
20448-
20449- // Addr returns the address of the procedure represented by p.
20450- // The return value can be passed to Syscall to run the procedure.
20451- func (p *Proc) Addr() uintptr {
20452- return p.addr
20453- }
20454-
20455- //go:uintptrescapes
20456-
20457- // Call executes procedure p with arguments a. It will panic, if more than 15 arguments
20458- // are supplied.
20459- //
20460- // The returned error is always non-nil, constructed from the result of GetLastError.
20461- // Callers must inspect the primary return value to decide whether an error occurred
20462- // (according to the semantics of the specific function being called) before consulting
20463- // the error. The error will be guaranteed to contain windows.Errno.
20464- func (p *Proc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
20465- switch len(a) {
20466- case 0:
20467- return syscall.Syscall(p.Addr(), uintptr(len(a)), 0, 0, 0)
20468- case 1:
20469- return syscall.Syscall(p.Addr(), uintptr(len(a)), a[0], 0, 0)
20470- case 2:
20471- return syscall.Syscall(p.Addr(), uintptr(len(a)), a[0], a[1], 0)
20472- case 3:
20473- return syscall.Syscall(p.Addr(), uintptr(len(a)), a[0], a[1], a[2])
20474- case 4:
20475- return syscall.Syscall6(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], 0, 0)
20476- case 5:
20477- return syscall.Syscall6(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], 0)
20478- case 6:
20479- return syscall.Syscall6(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5])
20480- case 7:
20481- return syscall.Syscall9(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], 0, 0)
20482- case 8:
20483- return syscall.Syscall9(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], 0)
20484- case 9:
20485- return syscall.Syscall9(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
20486- case 10:
20487- return syscall.Syscall12(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], 0, 0)
20488- case 11:
20489- return syscall.Syscall12(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], 0)
20490- case 12:
20491- return syscall.Syscall12(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11])
20492- case 13:
20493- return syscall.Syscall15(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], 0, 0)
20494- case 14:
20495- return syscall.Syscall15(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], 0)
20496- case 15:
20497- return syscall.Syscall15(p.Addr(), uintptr(len(a)), a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14])
20498- default:
20499- panic("Call " + p.Name + " with too many arguments " + itoa(len(a)) + ".")
20500- }
20501- }
20502-
20503- // A LazyDLL implements access to a single DLL.
20504- // It will delay the load of the DLL until the first
20505- // call to its Handle method or to one of its
20506- // LazyProc's Addr method.
20507- type LazyDLL struct {
20508- Name string
20509-
20510- // System determines whether the DLL must be loaded from the
20511- // Windows System directory, bypassing the normal DLL search
20512- // path.
20513- System bool
20514-
20515- mu sync.Mutex
20516- dll *DLL // non nil once DLL is loaded
20517- }
20518-
20519- // Load loads DLL file d.Name into memory. It returns an error if fails.
20520- // Load will not try to load DLL, if it is already loaded into memory.
20521- func (d *LazyDLL) Load() error {
20522- // Non-racy version of:
20523- // if d.dll != nil {
20524- if atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&d.dll))) != nil {
20525- return nil
20526- }
20527- d.mu.Lock()
20528- defer d.mu.Unlock()
20529- if d.dll != nil {
20530- return nil
20531- }
20532-
20533- // kernel32.dll is special, since it's where LoadLibraryEx comes from.
20534- // The kernel already special-cases its name, so it's always
20535- // loaded from system32.
20536- var dll *DLL
20537- var err error
20538- if d.Name == "kernel32.dll" {
20539- dll, err = LoadDLL(d.Name)
20540- } else {
20541- dll, err = loadLibraryEx(d.Name, d.System)
20542- }
20543- if err != nil {
20544- return err
20545- }
20546-
20547- // Non-racy version of:
20548- // d.dll = dll
20549- atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&d.dll)), unsafe.Pointer(dll))
20550- return nil
20551- }
20552-
20553- // mustLoad is like Load but panics if search fails.
20554- func (d *LazyDLL) mustLoad() {
20555- e := d.Load()
20556- if e != nil {
20557- panic(e)
20558- }
20559- }
20560-
20561- // Handle returns d's module handle.
20562- func (d *LazyDLL) Handle() uintptr {
20563- d.mustLoad()
20564- return uintptr(d.dll.Handle)
20565- }
20566-
20567- // NewProc returns a LazyProc for accessing the named procedure in the DLL d.
20568- func (d *LazyDLL) NewProc(name string) *LazyProc {
20569- return &LazyProc{l: d, Name: name}
20570- }
20571-
20572- // NewLazyDLL creates new LazyDLL associated with DLL file.
20573- func NewLazyDLL(name string) *LazyDLL {
20574- return &LazyDLL{Name: name}
20575- }
20576-
20577- // NewLazySystemDLL is like NewLazyDLL, but will only
20578- // search Windows System directory for the DLL if name is
20579- // a base name (like "advapi32.dll").
20580- func NewLazySystemDLL(name string) *LazyDLL {
20581- return &LazyDLL{Name: name, System: true}
20582- }
20583-
20584- // A LazyProc implements access to a procedure inside a LazyDLL.
20585- // It delays the lookup until the Addr method is called.
20586- type LazyProc struct {
20587- Name string
20588-
20589- mu sync.Mutex
20590- l *LazyDLL
20591- proc *Proc
20592- }
20593-
20594- // Find searches DLL for procedure named p.Name. It returns
20595- // an error if search fails. Find will not search procedure,
20596- // if it is already found and loaded into memory.
20597- func (p *LazyProc) Find() error {
20598- // Non-racy version of:
20599- // if p.proc == nil {
20600- if atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&p.proc))) == nil {
20601- p.mu.Lock()
20602- defer p.mu.Unlock()
20603- if p.proc == nil {
20604- e := p.l.Load()
20605- if e != nil {
20606- return e
20607- }
20608- proc, e := p.l.dll.FindProc(p.Name)
20609- if e != nil {
20610- return e
20611- }
20612- // Non-racy version of:
20613- // p.proc = proc
20614- atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.proc)), unsafe.Pointer(proc))
20615- }
20616- }
20617- return nil
20618- }
20619-
20620- // mustFind is like Find but panics if search fails.
20621- func (p *LazyProc) mustFind() {
20622- e := p.Find()
20623- if e != nil {
20624- panic(e)
20625- }
20626- }
20627-
20628- // Addr returns the address of the procedure represented by p.
20629- // The return value can be passed to Syscall to run the procedure.
20630- // It will panic if the procedure cannot be found.
20631- func (p *LazyProc) Addr() uintptr {
20632- p.mustFind()
20633- return p.proc.Addr()
20634- }
20635-
20636- //go:uintptrescapes
20637-
20638- // Call executes procedure p with arguments a. It will panic, if more than 15 arguments
20639- // are supplied. It will also panic if the procedure cannot be found.
20640- //
20641- // The returned error is always non-nil, constructed from the result of GetLastError.
20642- // Callers must inspect the primary return value to decide whether an error occurred
20643- // (according to the semantics of the specific function being called) before consulting
20644- // the error. The error will be guaranteed to contain windows.Errno.
20645- func (p *LazyProc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
20646- p.mustFind()
20647- return p.proc.Call(a...)
20648- }
20649-
20650- var canDoSearchSystem32Once struct {
20651- sync.Once
20652- v bool
20653- }
20654-
20655- func initCanDoSearchSystem32() {
20656- // https://msdn.microsoft.com/en-us/library/ms684179(v=vs.85).aspx says:
20657- // "Windows 7, Windows Server 2008 R2, Windows Vista, and Windows
20658- // Server 2008: The LOAD_LIBRARY_SEARCH_* flags are available on
20659- // systems that have KB2533623 installed. To determine whether the
20660- // flags are available, use GetProcAddress to get the address of the
20661- // AddDllDirectory, RemoveDllDirectory, or SetDefaultDllDirectories
20662- // function. If GetProcAddress succeeds, the LOAD_LIBRARY_SEARCH_*
20663- // flags can be used with LoadLibraryEx."
20664- canDoSearchSystem32Once.v = (modkernel32.NewProc("AddDllDirectory").Find() == nil)
20665- }
20666-
20667- func canDoSearchSystem32() bool {
20668- canDoSearchSystem32Once.Do(initCanDoSearchSystem32)
20669- return canDoSearchSystem32Once.v
20670- }
20671-
20672- func isBaseName(name string) bool {
20673- for _, c := range name {
20674- if c == ':' || c == '/' || c == '\\' {
20675- return false
20676- }
20677- }
20678- return true
20679- }
20680-
20681- // loadLibraryEx wraps the Windows LoadLibraryEx function.
20682- //
20683- // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx
20684- //
20685- // If name is not an absolute path, LoadLibraryEx searches for the DLL
20686- // in a variety of automatic locations unless constrained by flags.
20687- // See: https://msdn.microsoft.com/en-us/library/ff919712%28VS.85%29.aspx
20688- func loadLibraryEx(name string, system bool) (*DLL, error) {
20689- loadDLL := name
20690- var flags uintptr
20691- if system {
20692- if canDoSearchSystem32() {
20693- const LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800
20694- flags = LOAD_LIBRARY_SEARCH_SYSTEM32
20695- } else if isBaseName(name) {
20696- // WindowsXP or unpatched Windows machine
20697- // trying to load "foo.dll" out of the system
20698- // folder, but LoadLibraryEx doesn't support
20699- // that yet on their system, so emulate it.
20700- windir, _ := Getenv("WINDIR") // old var; apparently works on XP
20701- if windir == "" {
20702- return nil, errString("%WINDIR% not defined")
20703- }
20704- loadDLL = windir + "\\System32\\" + name
20705- }
20706- }
20707- h, err := LoadLibraryEx(loadDLL, 0, flags)
20708- if err != nil {
20709- return nil, err
20710- }
20711- return &DLL{Name: name, Handle: h}, nil
20712- }
20713-
20714- type errString string
20715-
20716- func (s errString) Error() string { return string(s) }
20717 diff --git a/vendor/golang.org/x/sys/windows/env_windows.go b/vendor/golang.org/x/sys/windows/env_windows.go
20718deleted file mode 100644
20719index bdc71e2..0000000
20720--- a/vendor/golang.org/x/sys/windows/env_windows.go
20721+++ /dev/null
20722 @@ -1,29 +0,0 @@
20723- // Copyright 2010 The Go Authors. All rights reserved.
20724- // Use of this source code is governed by a BSD-style
20725- // license that can be found in the LICENSE file.
20726-
20727- // Windows environment variables.
20728-
20729- package windows
20730-
20731- import "syscall"
20732-
20733- func Getenv(key string) (value string, found bool) {
20734- return syscall.Getenv(key)
20735- }
20736-
20737- func Setenv(key, value string) error {
20738- return syscall.Setenv(key, value)
20739- }
20740-
20741- func Clearenv() {
20742- syscall.Clearenv()
20743- }
20744-
20745- func Environ() []string {
20746- return syscall.Environ()
20747- }
20748-
20749- func Unsetenv(key string) error {
20750- return syscall.Unsetenv(key)
20751- }
20752 diff --git a/vendor/golang.org/x/sys/windows/eventlog.go b/vendor/golang.org/x/sys/windows/eventlog.go
20753deleted file mode 100644
20754index 40af946..0000000
20755--- a/vendor/golang.org/x/sys/windows/eventlog.go
20756+++ /dev/null
20757 @@ -1,20 +0,0 @@
20758- // Copyright 2012 The Go Authors. All rights reserved.
20759- // Use of this source code is governed by a BSD-style
20760- // license that can be found in the LICENSE file.
20761-
20762- // +build windows
20763-
20764- package windows
20765-
20766- const (
20767- EVENTLOG_SUCCESS = 0
20768- EVENTLOG_ERROR_TYPE = 1
20769- EVENTLOG_WARNING_TYPE = 2
20770- EVENTLOG_INFORMATION_TYPE = 4
20771- EVENTLOG_AUDIT_SUCCESS = 8
20772- EVENTLOG_AUDIT_FAILURE = 16
20773- )
20774-
20775- //sys RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) [failretval==0] = advapi32.RegisterEventSourceW
20776- //sys DeregisterEventSource(handle Handle) (err error) = advapi32.DeregisterEventSource
20777- //sys ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) = advapi32.ReportEventW
20778 diff --git a/vendor/golang.org/x/sys/windows/exec_windows.go b/vendor/golang.org/x/sys/windows/exec_windows.go
20779deleted file mode 100644
20780index 3606c3a..0000000
20781--- a/vendor/golang.org/x/sys/windows/exec_windows.go
20782+++ /dev/null
20783 @@ -1,97 +0,0 @@
20784- // Copyright 2009 The Go Authors. All rights reserved.
20785- // Use of this source code is governed by a BSD-style
20786- // license that can be found in the LICENSE file.
20787-
20788- // Fork, exec, wait, etc.
20789-
20790- package windows
20791-
20792- // EscapeArg rewrites command line argument s as prescribed
20793- // in http://msdn.microsoft.com/en-us/library/ms880421.
20794- // This function returns "" (2 double quotes) if s is empty.
20795- // Alternatively, these transformations are done:
20796- // - every back slash (\) is doubled, but only if immediately
20797- // followed by double quote (");
20798- // - every double quote (") is escaped by back slash (\);
20799- // - finally, s is wrapped with double quotes (arg -> "arg"),
20800- // but only if there is space or tab inside s.
20801- func EscapeArg(s string) string {
20802- if len(s) == 0 {
20803- return "\"\""
20804- }
20805- n := len(s)
20806- hasSpace := false
20807- for i := 0; i < len(s); i++ {
20808- switch s[i] {
20809- case '"', '\\':
20810- n++
20811- case ' ', '\t':
20812- hasSpace = true
20813- }
20814- }
20815- if hasSpace {
20816- n += 2
20817- }
20818- if n == len(s) {
20819- return s
20820- }
20821-
20822- qs := make([]byte, n)
20823- j := 0
20824- if hasSpace {
20825- qs[j] = '"'
20826- j++
20827- }
20828- slashes := 0
20829- for i := 0; i < len(s); i++ {
20830- switch s[i] {
20831- default:
20832- slashes = 0
20833- qs[j] = s[i]
20834- case '\\':
20835- slashes++
20836- qs[j] = s[i]
20837- case '"':
20838- for ; slashes > 0; slashes-- {
20839- qs[j] = '\\'
20840- j++
20841- }
20842- qs[j] = '\\'
20843- j++
20844- qs[j] = s[i]
20845- }
20846- j++
20847- }
20848- if hasSpace {
20849- for ; slashes > 0; slashes-- {
20850- qs[j] = '\\'
20851- j++
20852- }
20853- qs[j] = '"'
20854- j++
20855- }
20856- return string(qs[:j])
20857- }
20858-
20859- func CloseOnExec(fd Handle) {
20860- SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0)
20861- }
20862-
20863- // FullPath retrieves the full path of the specified file.
20864- func FullPath(name string) (path string, err error) {
20865- p, err := UTF16PtrFromString(name)
20866- if err != nil {
20867- return "", err
20868- }
20869- n := uint32(100)
20870- for {
20871- buf := make([]uint16, n)
20872- n, err = GetFullPathName(p, uint32(len(buf)), &buf[0], nil)
20873- if err != nil {
20874- return "", err
20875- }
20876- if n <= uint32(len(buf)) {
20877- return UTF16ToString(buf[:n]), nil
20878- }
20879- }
20880- }
20881 diff --git a/vendor/golang.org/x/sys/windows/memory_windows.go b/vendor/golang.org/x/sys/windows/memory_windows.go
20882deleted file mode 100644
20883index f80a420..0000000
20884--- a/vendor/golang.org/x/sys/windows/memory_windows.go
20885+++ /dev/null
20886 @@ -1,26 +0,0 @@
20887- // Copyright 2017 The Go Authors. All rights reserved.
20888- // Use of this source code is governed by a BSD-style
20889- // license that can be found in the LICENSE file.
20890-
20891- package windows
20892-
20893- const (
20894- MEM_COMMIT = 0x00001000
20895- MEM_RESERVE = 0x00002000
20896- MEM_DECOMMIT = 0x00004000
20897- MEM_RELEASE = 0x00008000
20898- MEM_RESET = 0x00080000
20899- MEM_TOP_DOWN = 0x00100000
20900- MEM_WRITE_WATCH = 0x00200000
20901- MEM_PHYSICAL = 0x00400000
20902- MEM_RESET_UNDO = 0x01000000
20903- MEM_LARGE_PAGES = 0x20000000
20904-
20905- PAGE_NOACCESS = 0x01
20906- PAGE_READONLY = 0x02
20907- PAGE_READWRITE = 0x04
20908- PAGE_WRITECOPY = 0x08
20909- PAGE_EXECUTE_READ = 0x20
20910- PAGE_EXECUTE_READWRITE = 0x40
20911- PAGE_EXECUTE_WRITECOPY = 0x80
20912- )
20913 diff --git a/vendor/golang.org/x/sys/windows/mksyscall.go b/vendor/golang.org/x/sys/windows/mksyscall.go
20914deleted file mode 100644
20915index fb7db0e..0000000
20916--- a/vendor/golang.org/x/sys/windows/mksyscall.go
20917+++ /dev/null
20918 @@ -1,7 +0,0 @@
20919- // Copyright 2009 The Go Authors. All rights reserved.
20920- // Use of this source code is governed by a BSD-style
20921- // license that can be found in the LICENSE file.
20922-
20923- package windows
20924-
20925- //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go eventlog.go service.go syscall_windows.go security_windows.go
20926 diff --git a/vendor/golang.org/x/sys/windows/race.go b/vendor/golang.org/x/sys/windows/race.go
20927deleted file mode 100644
20928index a74e3e2..0000000
20929--- a/vendor/golang.org/x/sys/windows/race.go
20930+++ /dev/null
20931 @@ -1,30 +0,0 @@
20932- // Copyright 2012 The Go Authors. All rights reserved.
20933- // Use of this source code is governed by a BSD-style
20934- // license that can be found in the LICENSE file.
20935-
20936- // +build windows,race
20937-
20938- package windows
20939-
20940- import (
20941- "runtime"
20942- "unsafe"
20943- )
20944-
20945- const raceenabled = true
20946-
20947- func raceAcquire(addr unsafe.Pointer) {
20948- runtime.RaceAcquire(addr)
20949- }
20950-
20951- func raceReleaseMerge(addr unsafe.Pointer) {
20952- runtime.RaceReleaseMerge(addr)
20953- }
20954-
20955- func raceReadRange(addr unsafe.Pointer, len int) {
20956- runtime.RaceReadRange(addr, len)
20957- }
20958-
20959- func raceWriteRange(addr unsafe.Pointer, len int) {
20960- runtime.RaceWriteRange(addr, len)
20961- }
20962 diff --git a/vendor/golang.org/x/sys/windows/race0.go b/vendor/golang.org/x/sys/windows/race0.go
20963deleted file mode 100644
20964index e44a3cb..0000000
20965--- a/vendor/golang.org/x/sys/windows/race0.go
20966+++ /dev/null
20967 @@ -1,25 +0,0 @@
20968- // Copyright 2012 The Go Authors. All rights reserved.
20969- // Use of this source code is governed by a BSD-style
20970- // license that can be found in the LICENSE file.
20971-
20972- // +build windows,!race
20973-
20974- package windows
20975-
20976- import (
20977- "unsafe"
20978- )
20979-
20980- const raceenabled = false
20981-
20982- func raceAcquire(addr unsafe.Pointer) {
20983- }
20984-
20985- func raceReleaseMerge(addr unsafe.Pointer) {
20986- }
20987-
20988- func raceReadRange(addr unsafe.Pointer, len int) {
20989- }
20990-
20991- func raceWriteRange(addr unsafe.Pointer, len int) {
20992- }
20993 diff --git a/vendor/golang.org/x/sys/windows/registry/export_test.go b/vendor/golang.org/x/sys/windows/registry/export_test.go
20994deleted file mode 100644
20995index 8badf6f..0000000
20996--- a/vendor/golang.org/x/sys/windows/registry/export_test.go
20997+++ /dev/null
20998 @@ -1,11 +0,0 @@
20999- // Copyright 2015 The Go Authors. All rights reserved.
21000- // Use of this source code is governed by a BSD-style
21001- // license that can be found in the LICENSE file.
21002-
21003- // +build windows
21004-
21005- package registry
21006-
21007- func (k Key) SetValue(name string, valtype uint32, data []byte) error {
21008- return k.setValue(name, valtype, data)
21009- }
21010 diff --git a/vendor/golang.org/x/sys/windows/registry/key.go b/vendor/golang.org/x/sys/windows/registry/key.go
21011deleted file mode 100644
21012index d0beb19..0000000
21013--- a/vendor/golang.org/x/sys/windows/registry/key.go
21014+++ /dev/null
21015 @@ -1,200 +0,0 @@
21016- // Copyright 2015 The Go Authors. All rights reserved.
21017- // Use of this source code is governed by a BSD-style
21018- // license that can be found in the LICENSE file.
21019-
21020- // +build windows
21021-
21022- // Package registry provides access to the Windows registry.
21023- //
21024- // Here is a simple example, opening a registry key and reading a string value from it.
21025- //
21026- // k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
21027- // if err != nil {
21028- // log.Fatal(err)
21029- // }
21030- // defer k.Close()
21031- //
21032- // s, _, err := k.GetStringValue("SystemRoot")
21033- // if err != nil {
21034- // log.Fatal(err)
21035- // }
21036- // fmt.Printf("Windows system root is %q\n", s)
21037- //
21038- package registry
21039-
21040- import (
21041- "io"
21042- "syscall"
21043- "time"
21044- )
21045-
21046- const (
21047- // Registry key security and access rights.
21048- // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724878.aspx
21049- // for details.
21050- ALL_ACCESS = 0xf003f
21051- CREATE_LINK = 0x00020
21052- CREATE_SUB_KEY = 0x00004
21053- ENUMERATE_SUB_KEYS = 0x00008
21054- EXECUTE = 0x20019
21055- NOTIFY = 0x00010
21056- QUERY_VALUE = 0x00001
21057- READ = 0x20019
21058- SET_VALUE = 0x00002
21059- WOW64_32KEY = 0x00200
21060- WOW64_64KEY = 0x00100
21061- WRITE = 0x20006
21062- )
21063-
21064- // Key is a handle to an open Windows registry key.
21065- // Keys can be obtained by calling OpenKey; there are
21066- // also some predefined root keys such as CURRENT_USER.
21067- // Keys can be used directly in the Windows API.
21068- type Key syscall.Handle
21069-
21070- const (
21071- // Windows defines some predefined root keys that are always open.
21072- // An application can use these keys as entry points to the registry.
21073- // Normally these keys are used in OpenKey to open new keys,
21074- // but they can also be used anywhere a Key is required.
21075- CLASSES_ROOT = Key(syscall.HKEY_CLASSES_ROOT)
21076- CURRENT_USER = Key(syscall.HKEY_CURRENT_USER)
21077- LOCAL_MACHINE = Key(syscall.HKEY_LOCAL_MACHINE)
21078- USERS = Key(syscall.HKEY_USERS)
21079- CURRENT_CONFIG = Key(syscall.HKEY_CURRENT_CONFIG)
21080- PERFORMANCE_DATA = Key(syscall.HKEY_PERFORMANCE_DATA)
21081- )
21082-
21083- // Close closes open key k.
21084- func (k Key) Close() error {
21085- return syscall.RegCloseKey(syscall.Handle(k))
21086- }
21087-
21088- // OpenKey opens a new key with path name relative to key k.
21089- // It accepts any open key, including CURRENT_USER and others,
21090- // and returns the new key and an error.
21091- // The access parameter specifies desired access rights to the
21092- // key to be opened.
21093- func OpenKey(k Key, path string, access uint32) (Key, error) {
21094- p, err := syscall.UTF16PtrFromString(path)
21095- if err != nil {
21096- return 0, err
21097- }
21098- var subkey syscall.Handle
21099- err = syscall.RegOpenKeyEx(syscall.Handle(k), p, 0, access, &subkey)
21100- if err != nil {
21101- return 0, err
21102- }
21103- return Key(subkey), nil
21104- }
21105-
21106- // OpenRemoteKey opens a predefined registry key on another
21107- // computer pcname. The key to be opened is specified by k, but
21108- // can only be one of LOCAL_MACHINE, PERFORMANCE_DATA or USERS.
21109- // If pcname is "", OpenRemoteKey returns local computer key.
21110- func OpenRemoteKey(pcname string, k Key) (Key, error) {
21111- var err error
21112- var p *uint16
21113- if pcname != "" {
21114- p, err = syscall.UTF16PtrFromString(`\\` + pcname)
21115- if err != nil {
21116- return 0, err
21117- }
21118- }
21119- var remoteKey syscall.Handle
21120- err = regConnectRegistry(p, syscall.Handle(k), &remoteKey)
21121- if err != nil {
21122- return 0, err
21123- }
21124- return Key(remoteKey), nil
21125- }
21126-
21127- // ReadSubKeyNames returns the names of subkeys of key k.
21128- // The parameter n controls the number of returned names,
21129- // analogous to the way os.File.Readdirnames works.
21130- func (k Key) ReadSubKeyNames(n int) ([]string, error) {
21131- ki, err := k.Stat()
21132- if err != nil {
21133- return nil, err
21134- }
21135- names := make([]string, 0, ki.SubKeyCount)
21136- buf := make([]uint16, ki.MaxSubKeyLen+1) // extra room for terminating zero byte
21137- loopItems:
21138- for i := uint32(0); ; i++ {
21139- if n > 0 {
21140- if len(names) == n {
21141- return names, nil
21142- }
21143- }
21144- l := uint32(len(buf))
21145- for {
21146- err := syscall.RegEnumKeyEx(syscall.Handle(k), i, &buf[0], &l, nil, nil, nil, nil)
21147- if err == nil {
21148- break
21149- }
21150- if err == syscall.ERROR_MORE_DATA {
21151- // Double buffer size and try again.
21152- l = uint32(2 * len(buf))
21153- buf = make([]uint16, l)
21154- continue
21155- }
21156- if err == _ERROR_NO_MORE_ITEMS {
21157- break loopItems
21158- }
21159- return names, err
21160- }
21161- names = append(names, syscall.UTF16ToString(buf[:l]))
21162- }
21163- if n > len(names) {
21164- return names, io.EOF
21165- }
21166- return names, nil
21167- }
21168-
21169- // CreateKey creates a key named path under open key k.
21170- // CreateKey returns the new key and a boolean flag that reports
21171- // whether the key already existed.
21172- // The access parameter specifies the access rights for the key
21173- // to be created.
21174- func CreateKey(k Key, path string, access uint32) (newk Key, openedExisting bool, err error) {
21175- var h syscall.Handle
21176- var d uint32
21177- err = regCreateKeyEx(syscall.Handle(k), syscall.StringToUTF16Ptr(path),
21178- 0, nil, _REG_OPTION_NON_VOLATILE, access, nil, &h, &d)
21179- if err != nil {
21180- return 0, false, err
21181- }
21182- return Key(h), d == _REG_OPENED_EXISTING_KEY, nil
21183- }
21184-
21185- // DeleteKey deletes the subkey path of key k and its values.
21186- func DeleteKey(k Key, path string) error {
21187- return regDeleteKey(syscall.Handle(k), syscall.StringToUTF16Ptr(path))
21188- }
21189-
21190- // A KeyInfo describes the statistics of a key. It is returned by Stat.
21191- type KeyInfo struct {
21192- SubKeyCount uint32
21193- MaxSubKeyLen uint32 // size of the key's subkey with the longest name, in Unicode characters, not including the terminating zero byte
21194- ValueCount uint32
21195- MaxValueNameLen uint32 // size of the key's longest value name, in Unicode characters, not including the terminating zero byte
21196- MaxValueLen uint32 // longest data component among the key's values, in bytes
21197- lastWriteTime syscall.Filetime
21198- }
21199-
21200- // ModTime returns the key's last write time.
21201- func (ki *KeyInfo) ModTime() time.Time {
21202- return time.Unix(0, ki.lastWriteTime.Nanoseconds())
21203- }
21204-
21205- // Stat retrieves information about the open key k.
21206- func (k Key) Stat() (*KeyInfo, error) {
21207- var ki KeyInfo
21208- err := syscall.RegQueryInfoKey(syscall.Handle(k), nil, nil, nil,
21209- &ki.SubKeyCount, &ki.MaxSubKeyLen, nil, &ki.ValueCount,
21210- &ki.MaxValueNameLen, &ki.MaxValueLen, nil, &ki.lastWriteTime)
21211- if err != nil {
21212- return nil, err
21213- }
21214- return &ki, nil
21215- }
21216 diff --git a/vendor/golang.org/x/sys/windows/registry/mksyscall.go b/vendor/golang.org/x/sys/windows/registry/mksyscall.go
21217deleted file mode 100644
21218index 0ac95ff..0000000
21219--- a/vendor/golang.org/x/sys/windows/registry/mksyscall.go
21220+++ /dev/null
21221 @@ -1,7 +0,0 @@
21222- // Copyright 2015 The Go Authors. All rights reserved.
21223- // Use of this source code is governed by a BSD-style
21224- // license that can be found in the LICENSE file.
21225-
21226- package registry
21227-
21228- //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go
21229 diff --git a/vendor/golang.org/x/sys/windows/registry/registry_test.go b/vendor/golang.org/x/sys/windows/registry/registry_test.go
21230deleted file mode 100644
21231index 3cb9771..0000000
21232--- a/vendor/golang.org/x/sys/windows/registry/registry_test.go
21233+++ /dev/null
21234 @@ -1,756 +0,0 @@
21235- // Copyright 2015 The Go Authors. All rights reserved.
21236- // Use of this source code is governed by a BSD-style
21237- // license that can be found in the LICENSE file.
21238-
21239- // +build windows
21240-
21241- package registry_test
21242-
21243- import (
21244- "bytes"
21245- "crypto/rand"
21246- "os"
21247- "syscall"
21248- "testing"
21249- "time"
21250- "unsafe"
21251-
21252- "golang.org/x/sys/windows/registry"
21253- )
21254-
21255- func randKeyName(prefix string) string {
21256- const numbers = "0123456789"
21257- buf := make([]byte, 10)
21258- rand.Read(buf)
21259- for i, b := range buf {
21260- buf[i] = numbers[b%byte(len(numbers))]
21261- }
21262- return prefix + string(buf)
21263- }
21264-
21265- func TestReadSubKeyNames(t *testing.T) {
21266- k, err := registry.OpenKey(registry.CLASSES_ROOT, "TypeLib", registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE)
21267- if err != nil {
21268- t.Fatal(err)
21269- }
21270- defer k.Close()
21271-
21272- names, err := k.ReadSubKeyNames(-1)
21273- if err != nil {
21274- t.Fatal(err)
21275- }
21276- var foundStdOle bool
21277- for _, name := range names {
21278- // Every PC has "stdole 2.0 OLE Automation" library installed.
21279- if name == "{00020430-0000-0000-C000-000000000046}" {
21280- foundStdOle = true
21281- }
21282- }
21283- if !foundStdOle {
21284- t.Fatal("could not find stdole 2.0 OLE Automation")
21285- }
21286- }
21287-
21288- func TestCreateOpenDeleteKey(t *testing.T) {
21289- k, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
21290- if err != nil {
21291- t.Fatal(err)
21292- }
21293- defer k.Close()
21294-
21295- testKName := randKeyName("TestCreateOpenDeleteKey_")
21296-
21297- testK, exist, err := registry.CreateKey(k, testKName, registry.CREATE_SUB_KEY)
21298- if err != nil {
21299- t.Fatal(err)
21300- }
21301- defer testK.Close()
21302-
21303- if exist {
21304- t.Fatalf("key %q already exists", testKName)
21305- }
21306-
21307- testKAgain, exist, err := registry.CreateKey(k, testKName, registry.CREATE_SUB_KEY)
21308- if err != nil {
21309- t.Fatal(err)
21310- }
21311- defer testKAgain.Close()
21312-
21313- if !exist {
21314- t.Fatalf("key %q should already exist", testKName)
21315- }
21316-
21317- testKOpened, err := registry.OpenKey(k, testKName, registry.ENUMERATE_SUB_KEYS)
21318- if err != nil {
21319- t.Fatal(err)
21320- }
21321- defer testKOpened.Close()
21322-
21323- err = registry.DeleteKey(k, testKName)
21324- if err != nil {
21325- t.Fatal(err)
21326- }
21327-
21328- testKOpenedAgain, err := registry.OpenKey(k, testKName, registry.ENUMERATE_SUB_KEYS)
21329- if err == nil {
21330- defer testKOpenedAgain.Close()
21331- t.Fatalf("key %q should already been deleted", testKName)
21332- }
21333- if err != registry.ErrNotExist {
21334- t.Fatalf(`unexpected error ("not exist" expected): %v`, err)
21335- }
21336- }
21337-
21338- func equalStringSlice(a, b []string) bool {
21339- if len(a) != len(b) {
21340- return false
21341- }
21342- if a == nil {
21343- return true
21344- }
21345- for i := range a {
21346- if a[i] != b[i] {
21347- return false
21348- }
21349- }
21350- return true
21351- }
21352-
21353- type ValueTest struct {
21354- Type uint32
21355- Name string
21356- Value interface{}
21357- WillFail bool
21358- }
21359-
21360- var ValueTests = []ValueTest{
21361- {Type: registry.SZ, Name: "String1", Value: ""},
21362- {Type: registry.SZ, Name: "String2", Value: "\000", WillFail: true},
21363- {Type: registry.SZ, Name: "String3", Value: "Hello World"},
21364- {Type: registry.SZ, Name: "String4", Value: "Hello World\000", WillFail: true},
21365- {Type: registry.EXPAND_SZ, Name: "ExpString1", Value: ""},
21366- {Type: registry.EXPAND_SZ, Name: "ExpString2", Value: "\000", WillFail: true},
21367- {Type: registry.EXPAND_SZ, Name: "ExpString3", Value: "Hello World"},
21368- {Type: registry.EXPAND_SZ, Name: "ExpString4", Value: "Hello\000World", WillFail: true},
21369- {Type: registry.EXPAND_SZ, Name: "ExpString5", Value: "%PATH%"},
21370- {Type: registry.EXPAND_SZ, Name: "ExpString6", Value: "%NO_SUCH_VARIABLE%"},
21371- {Type: registry.EXPAND_SZ, Name: "ExpString7", Value: "%PATH%;."},
21372- {Type: registry.BINARY, Name: "Binary1", Value: []byte{}},
21373- {Type: registry.BINARY, Name: "Binary2", Value: []byte{1, 2, 3}},
21374- {Type: registry.BINARY, Name: "Binary3", Value: []byte{3, 2, 1, 0, 1, 2, 3}},
21375- {Type: registry.DWORD, Name: "Dword1", Value: uint64(0)},
21376- {Type: registry.DWORD, Name: "Dword2", Value: uint64(1)},
21377- {Type: registry.DWORD, Name: "Dword3", Value: uint64(0xff)},
21378- {Type: registry.DWORD, Name: "Dword4", Value: uint64(0xffff)},
21379- {Type: registry.QWORD, Name: "Qword1", Value: uint64(0)},
21380- {Type: registry.QWORD, Name: "Qword2", Value: uint64(1)},
21381- {Type: registry.QWORD, Name: "Qword3", Value: uint64(0xff)},
21382- {Type: registry.QWORD, Name: "Qword4", Value: uint64(0xffff)},
21383- {Type: registry.QWORD, Name: "Qword5", Value: uint64(0xffffff)},
21384- {Type: registry.QWORD, Name: "Qword6", Value: uint64(0xffffffff)},
21385- {Type: registry.MULTI_SZ, Name: "MultiString1", Value: []string{"a", "b", "c"}},
21386- {Type: registry.MULTI_SZ, Name: "MultiString2", Value: []string{"abc", "", "cba"}},
21387- {Type: registry.MULTI_SZ, Name: "MultiString3", Value: []string{""}},
21388- {Type: registry.MULTI_SZ, Name: "MultiString4", Value: []string{"abcdef"}},
21389- {Type: registry.MULTI_SZ, Name: "MultiString5", Value: []string{"\000"}, WillFail: true},
21390- {Type: registry.MULTI_SZ, Name: "MultiString6", Value: []string{"a\000b"}, WillFail: true},
21391- {Type: registry.MULTI_SZ, Name: "MultiString7", Value: []string{"ab", "\000", "cd"}, WillFail: true},
21392- {Type: registry.MULTI_SZ, Name: "MultiString8", Value: []string{"\000", "cd"}, WillFail: true},
21393- {Type: registry.MULTI_SZ, Name: "MultiString9", Value: []string{"ab", "\000"}, WillFail: true},
21394- }
21395-
21396- func setValues(t *testing.T, k registry.Key) {
21397- for _, test := range ValueTests {
21398- var err error
21399- switch test.Type {
21400- case registry.SZ:
21401- err = k.SetStringValue(test.Name, test.Value.(string))
21402- case registry.EXPAND_SZ:
21403- err = k.SetExpandStringValue(test.Name, test.Value.(string))
21404- case registry.MULTI_SZ:
21405- err = k.SetStringsValue(test.Name, test.Value.([]string))
21406- case registry.BINARY:
21407- err = k.SetBinaryValue(test.Name, test.Value.([]byte))
21408- case registry.DWORD:
21409- err = k.SetDWordValue(test.Name, uint32(test.Value.(uint64)))
21410- case registry.QWORD:
21411- err = k.SetQWordValue(test.Name, test.Value.(uint64))
21412- default:
21413- t.Fatalf("unsupported type %d for %s value", test.Type, test.Name)
21414- }
21415- if test.WillFail {
21416- if err == nil {
21417- t.Fatalf("setting %s value %q should fail, but succeeded", test.Name, test.Value)
21418- }
21419- } else {
21420- if err != nil {
21421- t.Fatal(err)
21422- }
21423- }
21424- }
21425- }
21426-
21427- func enumerateValues(t *testing.T, k registry.Key) {
21428- names, err := k.ReadValueNames(-1)
21429- if err != nil {
21430- t.Error(err)
21431- return
21432- }
21433- haveNames := make(map[string]bool)
21434- for _, n := range names {
21435- haveNames[n] = false
21436- }
21437- for _, test := range ValueTests {
21438- wantFound := !test.WillFail
21439- _, haveFound := haveNames[test.Name]
21440- if wantFound && !haveFound {
21441- t.Errorf("value %s is not found while enumerating", test.Name)
21442- }
21443- if haveFound && !wantFound {
21444- t.Errorf("value %s is found while enumerating, but expected to fail", test.Name)
21445- }
21446- if haveFound {
21447- delete(haveNames, test.Name)
21448- }
21449- }
21450- for n, v := range haveNames {
21451- t.Errorf("value %s (%v) is found while enumerating, but has not been cretaed", n, v)
21452- }
21453- }
21454-
21455- func testErrNotExist(t *testing.T, name string, err error) {
21456- if err == nil {
21457- t.Errorf("%s value should not exist", name)
21458- return
21459- }
21460- if err != registry.ErrNotExist {
21461- t.Errorf("reading %s value should return 'not exist' error, but got: %s", name, err)
21462- return
21463- }
21464- }
21465-
21466- func testErrUnexpectedType(t *testing.T, test ValueTest, gottype uint32, err error) {
21467- if err == nil {
21468- t.Errorf("GetXValue(%q) should not succeed", test.Name)
21469- return
21470- }
21471- if err != registry.ErrUnexpectedType {
21472- t.Errorf("reading %s value should return 'unexpected key value type' error, but got: %s", test.Name, err)
21473- return
21474- }
21475- if gottype != test.Type {
21476- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21477- return
21478- }
21479- }
21480-
21481- func testGetStringValue(t *testing.T, k registry.Key, test ValueTest) {
21482- got, gottype, err := k.GetStringValue(test.Name)
21483- if err != nil {
21484- t.Errorf("GetStringValue(%s) failed: %v", test.Name, err)
21485- return
21486- }
21487- if got != test.Value {
21488- t.Errorf("want %s value %q, got %q", test.Name, test.Value, got)
21489- return
21490- }
21491- if gottype != test.Type {
21492- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21493- return
21494- }
21495- if gottype == registry.EXPAND_SZ {
21496- _, err = registry.ExpandString(got)
21497- if err != nil {
21498- t.Errorf("ExpandString(%s) failed: %v", got, err)
21499- return
21500- }
21501- }
21502- }
21503-
21504- func testGetIntegerValue(t *testing.T, k registry.Key, test ValueTest) {
21505- got, gottype, err := k.GetIntegerValue(test.Name)
21506- if err != nil {
21507- t.Errorf("GetIntegerValue(%s) failed: %v", test.Name, err)
21508- return
21509- }
21510- if got != test.Value.(uint64) {
21511- t.Errorf("want %s value %v, got %v", test.Name, test.Value, got)
21512- return
21513- }
21514- if gottype != test.Type {
21515- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21516- return
21517- }
21518- }
21519-
21520- func testGetBinaryValue(t *testing.T, k registry.Key, test ValueTest) {
21521- got, gottype, err := k.GetBinaryValue(test.Name)
21522- if err != nil {
21523- t.Errorf("GetBinaryValue(%s) failed: %v", test.Name, err)
21524- return
21525- }
21526- if !bytes.Equal(got, test.Value.([]byte)) {
21527- t.Errorf("want %s value %v, got %v", test.Name, test.Value, got)
21528- return
21529- }
21530- if gottype != test.Type {
21531- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21532- return
21533- }
21534- }
21535-
21536- func testGetStringsValue(t *testing.T, k registry.Key, test ValueTest) {
21537- got, gottype, err := k.GetStringsValue(test.Name)
21538- if err != nil {
21539- t.Errorf("GetStringsValue(%s) failed: %v", test.Name, err)
21540- return
21541- }
21542- if !equalStringSlice(got, test.Value.([]string)) {
21543- t.Errorf("want %s value %#v, got %#v", test.Name, test.Value, got)
21544- return
21545- }
21546- if gottype != test.Type {
21547- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21548- return
21549- }
21550- }
21551-
21552- func testGetValue(t *testing.T, k registry.Key, test ValueTest, size int) {
21553- if size <= 0 {
21554- return
21555- }
21556- // read data with no buffer
21557- gotsize, gottype, err := k.GetValue(test.Name, nil)
21558- if err != nil {
21559- t.Errorf("GetValue(%s, [%d]byte) failed: %v", test.Name, size, err)
21560- return
21561- }
21562- if gotsize != size {
21563- t.Errorf("want %s value size of %d, got %v", test.Name, size, gotsize)
21564- return
21565- }
21566- if gottype != test.Type {
21567- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21568- return
21569- }
21570- // read data with short buffer
21571- gotsize, gottype, err = k.GetValue(test.Name, make([]byte, size-1))
21572- if err == nil {
21573- t.Errorf("GetValue(%s, [%d]byte) should fail, but succeeded", test.Name, size-1)
21574- return
21575- }
21576- if err != registry.ErrShortBuffer {
21577- t.Errorf("reading %s value should return 'short buffer' error, but got: %s", test.Name, err)
21578- return
21579- }
21580- if gotsize != size {
21581- t.Errorf("want %s value size of %d, got %v", test.Name, size, gotsize)
21582- return
21583- }
21584- if gottype != test.Type {
21585- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21586- return
21587- }
21588- // read full data
21589- gotsize, gottype, err = k.GetValue(test.Name, make([]byte, size))
21590- if err != nil {
21591- t.Errorf("GetValue(%s, [%d]byte) failed: %v", test.Name, size, err)
21592- return
21593- }
21594- if gotsize != size {
21595- t.Errorf("want %s value size of %d, got %v", test.Name, size, gotsize)
21596- return
21597- }
21598- if gottype != test.Type {
21599- t.Errorf("want %s value type %v, got %v", test.Name, test.Type, gottype)
21600- return
21601- }
21602- // check GetValue returns ErrNotExist as required
21603- _, _, err = k.GetValue(test.Name+"_not_there", make([]byte, size))
21604- if err == nil {
21605- t.Errorf("GetValue(%q) should not succeed", test.Name)
21606- return
21607- }
21608- if err != registry.ErrNotExist {
21609- t.Errorf("GetValue(%q) should return 'not exist' error, but got: %s", test.Name, err)
21610- return
21611- }
21612- }
21613-
21614- func testValues(t *testing.T, k registry.Key) {
21615- for _, test := range ValueTests {
21616- switch test.Type {
21617- case registry.SZ, registry.EXPAND_SZ:
21618- if test.WillFail {
21619- _, _, err := k.GetStringValue(test.Name)
21620- testErrNotExist(t, test.Name, err)
21621- } else {
21622- testGetStringValue(t, k, test)
21623- _, gottype, err := k.GetIntegerValue(test.Name)
21624- testErrUnexpectedType(t, test, gottype, err)
21625- // Size of utf16 string in bytes is not perfect,
21626- // but correct for current test values.
21627- // Size also includes terminating 0.
21628- testGetValue(t, k, test, (len(test.Value.(string))+1)*2)
21629- }
21630- _, _, err := k.GetStringValue(test.Name + "_string_not_created")
21631- testErrNotExist(t, test.Name+"_string_not_created", err)
21632- case registry.DWORD, registry.QWORD:
21633- testGetIntegerValue(t, k, test)
21634- _, gottype, err := k.GetBinaryValue(test.Name)
21635- testErrUnexpectedType(t, test, gottype, err)
21636- _, _, err = k.GetIntegerValue(test.Name + "_int_not_created")
21637- testErrNotExist(t, test.Name+"_int_not_created", err)
21638- size := 8
21639- if test.Type == registry.DWORD {
21640- size = 4
21641- }
21642- testGetValue(t, k, test, size)
21643- case registry.BINARY:
21644- testGetBinaryValue(t, k, test)
21645- _, gottype, err := k.GetStringsValue(test.Name)
21646- testErrUnexpectedType(t, test, gottype, err)
21647- _, _, err = k.GetBinaryValue(test.Name + "_byte_not_created")
21648- testErrNotExist(t, test.Name+"_byte_not_created", err)
21649- testGetValue(t, k, test, len(test.Value.([]byte)))
21650- case registry.MULTI_SZ:
21651- if test.WillFail {
21652- _, _, err := k.GetStringsValue(test.Name)
21653- testErrNotExist(t, test.Name, err)
21654- } else {
21655- testGetStringsValue(t, k, test)
21656- _, gottype, err := k.GetStringValue(test.Name)
21657- testErrUnexpectedType(t, test, gottype, err)
21658- size := 0
21659- for _, s := range test.Value.([]string) {
21660- size += len(s) + 1 // nil terminated
21661- }
21662- size += 1 // extra nil at the end
21663- size *= 2 // count bytes, not uint16
21664- testGetValue(t, k, test, size)
21665- }
21666- _, _, err := k.GetStringsValue(test.Name + "_strings_not_created")
21667- testErrNotExist(t, test.Name+"_strings_not_created", err)
21668- default:
21669- t.Errorf("unsupported type %d for %s value", test.Type, test.Name)
21670- continue
21671- }
21672- }
21673- }
21674-
21675- func testStat(t *testing.T, k registry.Key) {
21676- subk, _, err := registry.CreateKey(k, "subkey", registry.CREATE_SUB_KEY)
21677- if err != nil {
21678- t.Error(err)
21679- return
21680- }
21681- defer subk.Close()
21682-
21683- defer registry.DeleteKey(k, "subkey")
21684-
21685- ki, err := k.Stat()
21686- if err != nil {
21687- t.Error(err)
21688- return
21689- }
21690- if ki.SubKeyCount != 1 {
21691- t.Error("key must have 1 subkey")
21692- }
21693- if ki.MaxSubKeyLen != 6 {
21694- t.Error("key max subkey name length must be 6")
21695- }
21696- if ki.ValueCount != 24 {
21697- t.Errorf("key must have 24 values, but is %d", ki.ValueCount)
21698- }
21699- if ki.MaxValueNameLen != 12 {
21700- t.Errorf("key max value name length must be 10, but is %d", ki.MaxValueNameLen)
21701- }
21702- if ki.MaxValueLen != 38 {
21703- t.Errorf("key max value length must be 38, but is %d", ki.MaxValueLen)
21704- }
21705- if mt, ct := ki.ModTime(), time.Now(); ct.Sub(mt) > 100*time.Millisecond {
21706- t.Errorf("key mod time is not close to current time: mtime=%v current=%v delta=%v", mt, ct, ct.Sub(mt))
21707- }
21708- }
21709-
21710- func deleteValues(t *testing.T, k registry.Key) {
21711- for _, test := range ValueTests {
21712- if test.WillFail {
21713- continue
21714- }
21715- err := k.DeleteValue(test.Name)
21716- if err != nil {
21717- t.Error(err)
21718- continue
21719- }
21720- }
21721- names, err := k.ReadValueNames(-1)
21722- if err != nil {
21723- t.Error(err)
21724- return
21725- }
21726- if len(names) != 0 {
21727- t.Errorf("some values remain after deletion: %v", names)
21728- }
21729- }
21730-
21731- func TestValues(t *testing.T) {
21732- softwareK, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
21733- if err != nil {
21734- t.Fatal(err)
21735- }
21736- defer softwareK.Close()
21737-
21738- testKName := randKeyName("TestValues_")
21739-
21740- k, exist, err := registry.CreateKey(softwareK, testKName, registry.CREATE_SUB_KEY|registry.QUERY_VALUE|registry.SET_VALUE)
21741- if err != nil {
21742- t.Fatal(err)
21743- }
21744- defer k.Close()
21745-
21746- if exist {
21747- t.Fatalf("key %q already exists", testKName)
21748- }
21749-
21750- defer registry.DeleteKey(softwareK, testKName)
21751-
21752- setValues(t, k)
21753-
21754- enumerateValues(t, k)
21755-
21756- testValues(t, k)
21757-
21758- testStat(t, k)
21759-
21760- deleteValues(t, k)
21761- }
21762-
21763- func walkKey(t *testing.T, k registry.Key, kname string) {
21764- names, err := k.ReadValueNames(-1)
21765- if err != nil {
21766- t.Fatalf("reading value names of %s failed: %v", kname, err)
21767- }
21768- for _, name := range names {
21769- _, valtype, err := k.GetValue(name, nil)
21770- if err != nil {
21771- t.Fatalf("reading value type of %s of %s failed: %v", name, kname, err)
21772- }
21773- switch valtype {
21774- case registry.NONE:
21775- case registry.SZ:
21776- _, _, err := k.GetStringValue(name)
21777- if err != nil {
21778- t.Error(err)
21779- }
21780- case registry.EXPAND_SZ:
21781- s, _, err := k.GetStringValue(name)
21782- if err != nil {
21783- t.Error(err)
21784- }
21785- _, err = registry.ExpandString(s)
21786- if err != nil {
21787- t.Error(err)
21788- }
21789- case registry.DWORD, registry.QWORD:
21790- _, _, err := k.GetIntegerValue(name)
21791- if err != nil {
21792- t.Error(err)
21793- }
21794- case registry.BINARY:
21795- _, _, err := k.GetBinaryValue(name)
21796- if err != nil {
21797- t.Error(err)
21798- }
21799- case registry.MULTI_SZ:
21800- _, _, err := k.GetStringsValue(name)
21801- if err != nil {
21802- t.Error(err)
21803- }
21804- case registry.FULL_RESOURCE_DESCRIPTOR, registry.RESOURCE_LIST, registry.RESOURCE_REQUIREMENTS_LIST:
21805- // TODO: not implemented
21806- default:
21807- t.Fatalf("value type %d of %s of %s failed: %v", valtype, name, kname, err)
21808- }
21809- }
21810-
21811- names, err = k.ReadSubKeyNames(-1)
21812- if err != nil {
21813- t.Fatalf("reading sub-keys of %s failed: %v", kname, err)
21814- }
21815- for _, name := range names {
21816- func() {
21817- subk, err := registry.OpenKey(k, name, registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE)
21818- if err != nil {
21819- if err == syscall.ERROR_ACCESS_DENIED {
21820- // ignore error, if we are not allowed to access this key
21821- return
21822- }
21823- t.Fatalf("opening sub-keys %s of %s failed: %v", name, kname, err)
21824- }
21825- defer subk.Close()
21826-
21827- walkKey(t, subk, kname+`\`+name)
21828- }()
21829- }
21830- }
21831-
21832- func TestWalkFullRegistry(t *testing.T) {
21833- if testing.Short() {
21834- t.Skip("skipping long running test in short mode")
21835- }
21836- walkKey(t, registry.CLASSES_ROOT, "CLASSES_ROOT")
21837- walkKey(t, registry.CURRENT_USER, "CURRENT_USER")
21838- walkKey(t, registry.LOCAL_MACHINE, "LOCAL_MACHINE")
21839- walkKey(t, registry.USERS, "USERS")
21840- walkKey(t, registry.CURRENT_CONFIG, "CURRENT_CONFIG")
21841- }
21842-
21843- func TestExpandString(t *testing.T) {
21844- got, err := registry.ExpandString("%PATH%")
21845- if err != nil {
21846- t.Fatal(err)
21847- }
21848- want := os.Getenv("PATH")
21849- if got != want {
21850- t.Errorf("want %q string expanded, got %q", want, got)
21851- }
21852- }
21853-
21854- func TestInvalidValues(t *testing.T) {
21855- softwareK, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
21856- if err != nil {
21857- t.Fatal(err)
21858- }
21859- defer softwareK.Close()
21860-
21861- testKName := randKeyName("TestInvalidValues_")
21862-
21863- k, exist, err := registry.CreateKey(softwareK, testKName, registry.CREATE_SUB_KEY|registry.QUERY_VALUE|registry.SET_VALUE)
21864- if err != nil {
21865- t.Fatal(err)
21866- }
21867- defer k.Close()
21868-
21869- if exist {
21870- t.Fatalf("key %q already exists", testKName)
21871- }
21872-
21873- defer registry.DeleteKey(softwareK, testKName)
21874-
21875- var tests = []struct {
21876- Type uint32
21877- Name string
21878- Data []byte
21879- }{
21880- {registry.DWORD, "Dword1", nil},
21881- {registry.DWORD, "Dword2", []byte{1, 2, 3}},
21882- {registry.QWORD, "Qword1", nil},
21883- {registry.QWORD, "Qword2", []byte{1, 2, 3}},
21884- {registry.QWORD, "Qword3", []byte{1, 2, 3, 4, 5, 6, 7}},
21885- {registry.MULTI_SZ, "MultiString1", nil},
21886- {registry.MULTI_SZ, "MultiString2", []byte{0}},
21887- {registry.MULTI_SZ, "MultiString3", []byte{'a', 'b', 0}},
21888- {registry.MULTI_SZ, "MultiString4", []byte{'a', 0, 0, 'b', 0}},
21889- {registry.MULTI_SZ, "MultiString5", []byte{'a', 0, 0}},
21890- }
21891-
21892- for _, test := range tests {
21893- err := k.SetValue(test.Name, test.Type, test.Data)
21894- if err != nil {
21895- t.Fatalf("SetValue for %q failed: %v", test.Name, err)
21896- }
21897- }
21898-
21899- for _, test := range tests {
21900- switch test.Type {
21901- case registry.DWORD, registry.QWORD:
21902- value, valType, err := k.GetIntegerValue(test.Name)
21903- if err == nil {
21904- t.Errorf("GetIntegerValue(%q) succeeded. Returns type=%d value=%v", test.Name, valType, value)
21905- }
21906- case registry.MULTI_SZ:
21907- value, valType, err := k.GetStringsValue(test.Name)
21908- if err == nil {
21909- if len(value) != 0 {
21910- t.Errorf("GetStringsValue(%q) succeeded. Returns type=%d value=%v", test.Name, valType, value)
21911- }
21912- }
21913- default:
21914- t.Errorf("unsupported type %d for %s value", test.Type, test.Name)
21915- }
21916- }
21917- }
21918-
21919- func TestGetMUIStringValue(t *testing.T) {
21920- if err := registry.LoadRegLoadMUIString(); err != nil {
21921- t.Skip("regLoadMUIString not supported; skipping")
21922- }
21923- if err := procGetDynamicTimeZoneInformation.Find(); err != nil {
21924- t.Skipf("%s not supported; skipping", procGetDynamicTimeZoneInformation.Name)
21925- }
21926- var dtzi DynamicTimezoneinformation
21927- if _, err := GetDynamicTimeZoneInformation(&dtzi); err != nil {
21928- t.Fatal(err)
21929- }
21930- tzKeyName := syscall.UTF16ToString(dtzi.TimeZoneKeyName[:])
21931- timezoneK, err := registry.OpenKey(registry.LOCAL_MACHINE,
21932- `SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\`+tzKeyName, registry.READ)
21933- if err != nil {
21934- t.Fatal(err)
21935- }
21936- defer timezoneK.Close()
21937-
21938- type testType struct {
21939- name string
21940- want string
21941- }
21942- var tests = []testType{
21943- {"MUI_Std", syscall.UTF16ToString(dtzi.StandardName[:])},
21944- }
21945- if dtzi.DynamicDaylightTimeDisabled == 0 {
21946- tests = append(tests, testType{"MUI_Dlt", syscall.UTF16ToString(dtzi.DaylightName[:])})
21947- }
21948-
21949- for _, test := range tests {
21950- got, err := timezoneK.GetMUIStringValue(test.name)
21951- if err != nil {
21952- t.Error("GetMUIStringValue:", err)
21953- }
21954-
21955- if got != test.want {
21956- t.Errorf("GetMUIStringValue: %s: Got %q, want %q", test.name, got, test.want)
21957- }
21958- }
21959- }
21960-
21961- type DynamicTimezoneinformation struct {
21962- Bias int32
21963- StandardName [32]uint16
21964- StandardDate syscall.Systemtime
21965- StandardBias int32
21966- DaylightName [32]uint16
21967- DaylightDate syscall.Systemtime
21968- DaylightBias int32
21969- TimeZoneKeyName [128]uint16
21970- DynamicDaylightTimeDisabled uint8
21971- }
21972-
21973- var (
21974- kernel32DLL = syscall.NewLazyDLL("kernel32")
21975-
21976- procGetDynamicTimeZoneInformation = kernel32DLL.NewProc("GetDynamicTimeZoneInformation")
21977- )
21978-
21979- func GetDynamicTimeZoneInformation(dtzi *DynamicTimezoneinformation) (rc uint32, err error) {
21980- r0, _, e1 := syscall.Syscall(procGetDynamicTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(dtzi)), 0, 0)
21981- rc = uint32(r0)
21982- if rc == 0xffffffff {
21983- if e1 != 0 {
21984- err = error(e1)
21985- } else {
21986- err = syscall.EINVAL
21987- }
21988- }
21989- return
21990- }
21991 diff --git a/vendor/golang.org/x/sys/windows/registry/syscall.go b/vendor/golang.org/x/sys/windows/registry/syscall.go
21992deleted file mode 100644
21993index e66643c..0000000
21994--- a/vendor/golang.org/x/sys/windows/registry/syscall.go
21995+++ /dev/null
21996 @@ -1,32 +0,0 @@
21997- // Copyright 2015 The Go Authors. All rights reserved.
21998- // Use of this source code is governed by a BSD-style
21999- // license that can be found in the LICENSE file.
22000-
22001- // +build windows
22002-
22003- package registry
22004-
22005- import "syscall"
22006-
22007- const (
22008- _REG_OPTION_NON_VOLATILE = 0
22009-
22010- _REG_CREATED_NEW_KEY = 1
22011- _REG_OPENED_EXISTING_KEY = 2
22012-
22013- _ERROR_NO_MORE_ITEMS syscall.Errno = 259
22014- )
22015-
22016- func LoadRegLoadMUIString() error {
22017- return procRegLoadMUIStringW.Find()
22018- }
22019-
22020- //sys regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) = advapi32.RegCreateKeyExW
22021- //sys regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) = advapi32.RegDeleteKeyW
22022- //sys regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) = advapi32.RegSetValueExW
22023- //sys regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegEnumValueW
22024- //sys regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) = advapi32.RegDeleteValueW
22025- //sys regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) = advapi32.RegLoadMUIStringW
22026- //sys regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) = advapi32.RegConnectRegistryW
22027-
22028- //sys expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) = kernel32.ExpandEnvironmentStringsW
22029 diff --git a/vendor/golang.org/x/sys/windows/registry/value.go b/vendor/golang.org/x/sys/windows/registry/value.go
22030deleted file mode 100644
22031index 71d4e15..0000000
22032--- a/vendor/golang.org/x/sys/windows/registry/value.go
22033+++ /dev/null
22034 @@ -1,384 +0,0 @@
22035- // Copyright 2015 The Go Authors. All rights reserved.
22036- // Use of this source code is governed by a BSD-style
22037- // license that can be found in the LICENSE file.
22038-
22039- // +build windows
22040-
22041- package registry
22042-
22043- import (
22044- "errors"
22045- "io"
22046- "syscall"
22047- "unicode/utf16"
22048- "unsafe"
22049- )
22050-
22051- const (
22052- // Registry value types.
22053- NONE = 0
22054- SZ = 1
22055- EXPAND_SZ = 2
22056- BINARY = 3
22057- DWORD = 4
22058- DWORD_BIG_ENDIAN = 5
22059- LINK = 6
22060- MULTI_SZ = 7
22061- RESOURCE_LIST = 8
22062- FULL_RESOURCE_DESCRIPTOR = 9
22063- RESOURCE_REQUIREMENTS_LIST = 10
22064- QWORD = 11
22065- )
22066-
22067- var (
22068- // ErrShortBuffer is returned when the buffer was too short for the operation.
22069- ErrShortBuffer = syscall.ERROR_MORE_DATA
22070-
22071- // ErrNotExist is returned when a registry key or value does not exist.
22072- ErrNotExist = syscall.ERROR_FILE_NOT_FOUND
22073-
22074- // ErrUnexpectedType is returned by Get*Value when the value's type was unexpected.
22075- ErrUnexpectedType = errors.New("unexpected key value type")
22076- )
22077-
22078- // GetValue retrieves the type and data for the specified value associated
22079- // with an open key k. It fills up buffer buf and returns the retrieved
22080- // byte count n. If buf is too small to fit the stored value it returns
22081- // ErrShortBuffer error along with the required buffer size n.
22082- // If no buffer is provided, it returns true and actual buffer size n.
22083- // If no buffer is provided, GetValue returns the value's type only.
22084- // If the value does not exist, the error returned is ErrNotExist.
22085- //
22086- // GetValue is a low level function. If value's type is known, use the appropriate
22087- // Get*Value function instead.
22088- func (k Key) GetValue(name string, buf []byte) (n int, valtype uint32, err error) {
22089- pname, err := syscall.UTF16PtrFromString(name)
22090- if err != nil {
22091- return 0, 0, err
22092- }
22093- var pbuf *byte
22094- if len(buf) > 0 {
22095- pbuf = (*byte)(unsafe.Pointer(&buf[0]))
22096- }
22097- l := uint32(len(buf))
22098- err = syscall.RegQueryValueEx(syscall.Handle(k), pname, nil, &valtype, pbuf, &l)
22099- if err != nil {
22100- return int(l), valtype, err
22101- }
22102- return int(l), valtype, nil
22103- }
22104-
22105- func (k Key) getValue(name string, buf []byte) (date []byte, valtype uint32, err error) {
22106- p, err := syscall.UTF16PtrFromString(name)
22107- if err != nil {
22108- return nil, 0, err
22109- }
22110- var t uint32
22111- n := uint32(len(buf))
22112- for {
22113- err = syscall.RegQueryValueEx(syscall.Handle(k), p, nil, &t, (*byte)(unsafe.Pointer(&buf[0])), &n)
22114- if err == nil {
22115- return buf[:n], t, nil
22116- }
22117- if err != syscall.ERROR_MORE_DATA {
22118- return nil, 0, err
22119- }
22120- if n <= uint32(len(buf)) {
22121- return nil, 0, err
22122- }
22123- buf = make([]byte, n)
22124- }
22125- }
22126-
22127- // GetStringValue retrieves the string value for the specified
22128- // value name associated with an open key k. It also returns the value's type.
22129- // If value does not exist, GetStringValue returns ErrNotExist.
22130- // If value is not SZ or EXPAND_SZ, it will return the correct value
22131- // type and ErrUnexpectedType.
22132- func (k Key) GetStringValue(name string) (val string, valtype uint32, err error) {
22133- data, typ, err2 := k.getValue(name, make([]byte, 64))
22134- if err2 != nil {
22135- return "", typ, err2
22136- }
22137- switch typ {
22138- case SZ, EXPAND_SZ:
22139- default:
22140- return "", typ, ErrUnexpectedType
22141- }
22142- if len(data) == 0 {
22143- return "", typ, nil
22144- }
22145- u := (*[1 << 29]uint16)(unsafe.Pointer(&data[0]))[:]
22146- return syscall.UTF16ToString(u), typ, nil
22147- }
22148-
22149- // GetMUIStringValue retrieves the localized string value for
22150- // the specified value name associated with an open key k.
22151- // If the value name doesn't exist or the localized string value
22152- // can't be resolved, GetMUIStringValue returns ErrNotExist.
22153- // GetMUIStringValue panics if the system doesn't support
22154- // regLoadMUIString; use LoadRegLoadMUIString to check if
22155- // regLoadMUIString is supported before calling this function.
22156- func (k Key) GetMUIStringValue(name string) (string, error) {
22157- pname, err := syscall.UTF16PtrFromString(name)
22158- if err != nil {
22159- return "", err
22160- }
22161-
22162- buf := make([]uint16, 1024)
22163- var buflen uint32
22164- var pdir *uint16
22165-
22166- err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir)
22167- if err == syscall.ERROR_FILE_NOT_FOUND { // Try fallback path
22168-
22169- // Try to resolve the string value using the system directory as
22170- // a DLL search path; this assumes the string value is of the form
22171- // @[path]\dllname,-strID but with no path given, e.g. @tzres.dll,-320.
22172-
22173- // This approach works with tzres.dll but may have to be revised
22174- // in the future to allow callers to provide custom search paths.
22175-
22176- var s string
22177- s, err = ExpandString("%SystemRoot%\\system32\\")
22178- if err != nil {
22179- return "", err
22180- }
22181- pdir, err = syscall.UTF16PtrFromString(s)
22182- if err != nil {
22183- return "", err
22184- }
22185-
22186- err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir)
22187- }
22188-
22189- for err == syscall.ERROR_MORE_DATA { // Grow buffer if needed
22190- if buflen <= uint32(len(buf)) {
22191- break // Buffer not growing, assume race; break
22192- }
22193- buf = make([]uint16, buflen)
22194- err = regLoadMUIString(syscall.Handle(k), pname, &buf[0], uint32(len(buf)), &buflen, 0, pdir)
22195- }
22196-
22197- if err != nil {
22198- return "", err
22199- }
22200-
22201- return syscall.UTF16ToString(buf), nil
22202- }
22203-
22204- // ExpandString expands environment-variable strings and replaces
22205- // them with the values defined for the current user.
22206- // Use ExpandString to expand EXPAND_SZ strings.
22207- func ExpandString(value string) (string, error) {
22208- if value == "" {
22209- return "", nil
22210- }
22211- p, err := syscall.UTF16PtrFromString(value)
22212- if err != nil {
22213- return "", err
22214- }
22215- r := make([]uint16, 100)
22216- for {
22217- n, err := expandEnvironmentStrings(p, &r[0], uint32(len(r)))
22218- if err != nil {
22219- return "", err
22220- }
22221- if n <= uint32(len(r)) {
22222- u := (*[1 << 29]uint16)(unsafe.Pointer(&r[0]))[:]
22223- return syscall.UTF16ToString(u), nil
22224- }
22225- r = make([]uint16, n)
22226- }
22227- }
22228-
22229- // GetStringsValue retrieves the []string value for the specified
22230- // value name associated with an open key k. It also returns the value's type.
22231- // If value does not exist, GetStringsValue returns ErrNotExist.
22232- // If value is not MULTI_SZ, it will return the correct value
22233- // type and ErrUnexpectedType.
22234- func (k Key) GetStringsValue(name string) (val []string, valtype uint32, err error) {
22235- data, typ, err2 := k.getValue(name, make([]byte, 64))
22236- if err2 != nil {
22237- return nil, typ, err2
22238- }
22239- if typ != MULTI_SZ {
22240- return nil, typ, ErrUnexpectedType
22241- }
22242- if len(data) == 0 {
22243- return nil, typ, nil
22244- }
22245- p := (*[1 << 29]uint16)(unsafe.Pointer(&data[0]))[:len(data)/2]
22246- if len(p) == 0 {
22247- return nil, typ, nil
22248- }
22249- if p[len(p)-1] == 0 {
22250- p = p[:len(p)-1] // remove terminating null
22251- }
22252- val = make([]string, 0, 5)
22253- from := 0
22254- for i, c := range p {
22255- if c == 0 {
22256- val = append(val, string(utf16.Decode(p[from:i])))
22257- from = i + 1
22258- }
22259- }
22260- return val, typ, nil
22261- }
22262-
22263- // GetIntegerValue retrieves the integer value for the specified
22264- // value name associated with an open key k. It also returns the value's type.
22265- // If value does not exist, GetIntegerValue returns ErrNotExist.
22266- // If value is not DWORD or QWORD, it will return the correct value
22267- // type and ErrUnexpectedType.
22268- func (k Key) GetIntegerValue(name string) (val uint64, valtype uint32, err error) {
22269- data, typ, err2 := k.getValue(name, make([]byte, 8))
22270- if err2 != nil {
22271- return 0, typ, err2
22272- }
22273- switch typ {
22274- case DWORD:
22275- if len(data) != 4 {
22276- return 0, typ, errors.New("DWORD value is not 4 bytes long")
22277- }
22278- return uint64(*(*uint32)(unsafe.Pointer(&data[0]))), DWORD, nil
22279- case QWORD:
22280- if len(data) != 8 {
22281- return 0, typ, errors.New("QWORD value is not 8 bytes long")
22282- }
22283- return uint64(*(*uint64)(unsafe.Pointer(&data[0]))), QWORD, nil
22284- default:
22285- return 0, typ, ErrUnexpectedType
22286- }
22287- }
22288-
22289- // GetBinaryValue retrieves the binary value for the specified
22290- // value name associated with an open key k. It also returns the value's type.
22291- // If value does not exist, GetBinaryValue returns ErrNotExist.
22292- // If value is not BINARY, it will return the correct value
22293- // type and ErrUnexpectedType.
22294- func (k Key) GetBinaryValue(name string) (val []byte, valtype uint32, err error) {
22295- data, typ, err2 := k.getValue(name, make([]byte, 64))
22296- if err2 != nil {
22297- return nil, typ, err2
22298- }
22299- if typ != BINARY {
22300- return nil, typ, ErrUnexpectedType
22301- }
22302- return data, typ, nil
22303- }
22304-
22305- func (k Key) setValue(name string, valtype uint32, data []byte) error {
22306- p, err := syscall.UTF16PtrFromString(name)
22307- if err != nil {
22308- return err
22309- }
22310- if len(data) == 0 {
22311- return regSetValueEx(syscall.Handle(k), p, 0, valtype, nil, 0)
22312- }
22313- return regSetValueEx(syscall.Handle(k), p, 0, valtype, &data[0], uint32(len(data)))
22314- }
22315-
22316- // SetDWordValue sets the data and type of a name value
22317- // under key k to value and DWORD.
22318- func (k Key) SetDWordValue(name string, value uint32) error {
22319- return k.setValue(name, DWORD, (*[4]byte)(unsafe.Pointer(&value))[:])
22320- }
22321-
22322- // SetQWordValue sets the data and type of a name value
22323- // under key k to value and QWORD.
22324- func (k Key) SetQWordValue(name string, value uint64) error {
22325- return k.setValue(name, QWORD, (*[8]byte)(unsafe.Pointer(&value))[:])
22326- }
22327-
22328- func (k Key) setStringValue(name string, valtype uint32, value string) error {
22329- v, err := syscall.UTF16FromString(value)
22330- if err != nil {
22331- return err
22332- }
22333- buf := (*[1 << 29]byte)(unsafe.Pointer(&v[0]))[:len(v)*2]
22334- return k.setValue(name, valtype, buf)
22335- }
22336-
22337- // SetStringValue sets the data and type of a name value
22338- // under key k to value and SZ. The value must not contain a zero byte.
22339- func (k Key) SetStringValue(name, value string) error {
22340- return k.setStringValue(name, SZ, value)
22341- }
22342-
22343- // SetExpandStringValue sets the data and type of a name value
22344- // under key k to value and EXPAND_SZ. The value must not contain a zero byte.
22345- func (k Key) SetExpandStringValue(name, value string) error {
22346- return k.setStringValue(name, EXPAND_SZ, value)
22347- }
22348-
22349- // SetStringsValue sets the data and type of a name value
22350- // under key k to value and MULTI_SZ. The value strings
22351- // must not contain a zero byte.
22352- func (k Key) SetStringsValue(name string, value []string) error {
22353- ss := ""
22354- for _, s := range value {
22355- for i := 0; i < len(s); i++ {
22356- if s[i] == 0 {
22357- return errors.New("string cannot have 0 inside")
22358- }
22359- }
22360- ss += s + "\x00"
22361- }
22362- v := utf16.Encode([]rune(ss + "\x00"))
22363- buf := (*[1 << 29]byte)(unsafe.Pointer(&v[0]))[:len(v)*2]
22364- return k.setValue(name, MULTI_SZ, buf)
22365- }
22366-
22367- // SetBinaryValue sets the data and type of a name value
22368- // under key k to value and BINARY.
22369- func (k Key) SetBinaryValue(name string, value []byte) error {
22370- return k.setValue(name, BINARY, value)
22371- }
22372-
22373- // DeleteValue removes a named value from the key k.
22374- func (k Key) DeleteValue(name string) error {
22375- return regDeleteValue(syscall.Handle(k), syscall.StringToUTF16Ptr(name))
22376- }
22377-
22378- // ReadValueNames returns the value names of key k.
22379- // The parameter n controls the number of returned names,
22380- // analogous to the way os.File.Readdirnames works.
22381- func (k Key) ReadValueNames(n int) ([]string, error) {
22382- ki, err := k.Stat()
22383- if err != nil {
22384- return nil, err
22385- }
22386- names := make([]string, 0, ki.ValueCount)
22387- buf := make([]uint16, ki.MaxValueNameLen+1) // extra room for terminating null character
22388- loopItems:
22389- for i := uint32(0); ; i++ {
22390- if n > 0 {
22391- if len(names) == n {
22392- return names, nil
22393- }
22394- }
22395- l := uint32(len(buf))
22396- for {
22397- err := regEnumValue(syscall.Handle(k), i, &buf[0], &l, nil, nil, nil, nil)
22398- if err == nil {
22399- break
22400- }
22401- if err == syscall.ERROR_MORE_DATA {
22402- // Double buffer size and try again.
22403- l = uint32(2 * len(buf))
22404- buf = make([]uint16, l)
22405- continue
22406- }
22407- if err == _ERROR_NO_MORE_ITEMS {
22408- break loopItems
22409- }
22410- return names, err
22411- }
22412- names = append(names, syscall.UTF16ToString(buf[:l]))
22413- }
22414- if n > len(names) {
22415- return names, io.EOF
22416- }
22417- return names, nil
22418- }
22419 diff --git a/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go
22420deleted file mode 100644
22421index ceebdd7..0000000
22422--- a/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go
22423+++ /dev/null
22424 @@ -1,120 +0,0 @@
22425- // MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
22426-
22427- package registry
22428-
22429- import (
22430- "syscall"
22431- "unsafe"
22432-
22433- "golang.org/x/sys/windows"
22434- )
22435-
22436- var _ unsafe.Pointer
22437-
22438- // Do the interface allocations only once for common
22439- // Errno values.
22440- const (
22441- errnoERROR_IO_PENDING = 997
22442- )
22443-
22444- var (
22445- errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
22446- )
22447-
22448- // errnoErr returns common boxed Errno values, to prevent
22449- // allocations at runtime.
22450- func errnoErr(e syscall.Errno) error {
22451- switch e {
22452- case 0:
22453- return nil
22454- case errnoERROR_IO_PENDING:
22455- return errERROR_IO_PENDING
22456- }
22457- // TODO: add more here, after collecting data on the common
22458- // error values see on Windows. (perhaps when running
22459- // all.bat?)
22460- return e
22461- }
22462-
22463- var (
22464- modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
22465- modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
22466-
22467- procRegCreateKeyExW = modadvapi32.NewProc("RegCreateKeyExW")
22468- procRegDeleteKeyW = modadvapi32.NewProc("RegDeleteKeyW")
22469- procRegSetValueExW = modadvapi32.NewProc("RegSetValueExW")
22470- procRegEnumValueW = modadvapi32.NewProc("RegEnumValueW")
22471- procRegDeleteValueW = modadvapi32.NewProc("RegDeleteValueW")
22472- procRegLoadMUIStringW = modadvapi32.NewProc("RegLoadMUIStringW")
22473- procRegConnectRegistryW = modadvapi32.NewProc("RegConnectRegistryW")
22474- procExpandEnvironmentStringsW = modkernel32.NewProc("ExpandEnvironmentStringsW")
22475- )
22476-
22477- func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) {
22478- r0, _, _ := syscall.Syscall9(procRegCreateKeyExW.Addr(), 9, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition)))
22479- if r0 != 0 {
22480- regerrno = syscall.Errno(r0)
22481- }
22482- return
22483- }
22484-
22485- func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) {
22486- r0, _, _ := syscall.Syscall(procRegDeleteKeyW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(subkey)), 0)
22487- if r0 != 0 {
22488- regerrno = syscall.Errno(r0)
22489- }
22490- return
22491- }
22492-
22493- func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) {
22494- r0, _, _ := syscall.Syscall6(procRegSetValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize))
22495- if r0 != 0 {
22496- regerrno = syscall.Errno(r0)
22497- }
22498- return
22499- }
22500-
22501- func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
22502- r0, _, _ := syscall.Syscall9(procRegEnumValueW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)), 0)
22503- if r0 != 0 {
22504- regerrno = syscall.Errno(r0)
22505- }
22506- return
22507- }
22508-
22509- func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) {
22510- r0, _, _ := syscall.Syscall(procRegDeleteValueW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(name)), 0)
22511- if r0 != 0 {
22512- regerrno = syscall.Errno(r0)
22513- }
22514- return
22515- }
22516-
22517- func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) {
22518- r0, _, _ := syscall.Syscall9(procRegLoadMUIStringW.Addr(), 7, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir)), 0, 0)
22519- if r0 != 0 {
22520- regerrno = syscall.Errno(r0)
22521- }
22522- return
22523- }
22524-
22525- func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) {
22526- r0, _, _ := syscall.Syscall(procRegConnectRegistryW.Addr(), 3, uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result)))
22527- if r0 != 0 {
22528- regerrno = syscall.Errno(r0)
22529- }
22530- return
22531- }
22532-
22533- func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) {
22534- r0, _, e1 := syscall.Syscall(procExpandEnvironmentStringsW.Addr(), 3, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size))
22535- n = uint32(r0)
22536- if n == 0 {
22537- if e1 != 0 {
22538- err = errnoErr(e1)
22539- } else {
22540- err = syscall.EINVAL
22541- }
22542- }
22543- return
22544- }
22545 diff --git a/vendor/golang.org/x/sys/windows/security_windows.go b/vendor/golang.org/x/sys/windows/security_windows.go
22546deleted file mode 100644
22547index f1ec5dc..0000000
22548--- a/vendor/golang.org/x/sys/windows/security_windows.go
22549+++ /dev/null
22550 @@ -1,476 +0,0 @@
22551- // Copyright 2012 The Go Authors. All rights reserved.
22552- // Use of this source code is governed by a BSD-style
22553- // license that can be found in the LICENSE file.
22554-
22555- package windows
22556-
22557- import (
22558- "syscall"
22559- "unsafe"
22560- )
22561-
22562- const (
22563- STANDARD_RIGHTS_REQUIRED = 0xf0000
22564- STANDARD_RIGHTS_READ = 0x20000
22565- STANDARD_RIGHTS_WRITE = 0x20000
22566- STANDARD_RIGHTS_EXECUTE = 0x20000
22567- STANDARD_RIGHTS_ALL = 0x1F0000
22568- )
22569-
22570- const (
22571- NameUnknown = 0
22572- NameFullyQualifiedDN = 1
22573- NameSamCompatible = 2
22574- NameDisplay = 3
22575- NameUniqueId = 6
22576- NameCanonical = 7
22577- NameUserPrincipal = 8
22578- NameCanonicalEx = 9
22579- NameServicePrincipal = 10
22580- NameDnsDomain = 12
22581- )
22582-
22583- // This function returns 1 byte BOOLEAN rather than the 4 byte BOOL.
22584- // http://blogs.msdn.com/b/drnick/archive/2007/12/19/windows-and-upn-format-credentials.aspx
22585- //sys TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) [failretval&0xff==0] = secur32.TranslateNameW
22586- //sys GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) [failretval&0xff==0] = secur32.GetUserNameExW
22587-
22588- // TranslateAccountName converts a directory service
22589- // object name from one format to another.
22590- func TranslateAccountName(username string, from, to uint32, initSize int) (string, error) {
22591- u, e := UTF16PtrFromString(username)
22592- if e != nil {
22593- return "", e
22594- }
22595- n := uint32(50)
22596- for {
22597- b := make([]uint16, n)
22598- e = TranslateName(u, from, to, &b[0], &n)
22599- if e == nil {
22600- return UTF16ToString(b[:n]), nil
22601- }
22602- if e != ERROR_INSUFFICIENT_BUFFER {
22603- return "", e
22604- }
22605- if n <= uint32(len(b)) {
22606- return "", e
22607- }
22608- }
22609- }
22610-
22611- const (
22612- // do not reorder
22613- NetSetupUnknownStatus = iota
22614- NetSetupUnjoined
22615- NetSetupWorkgroupName
22616- NetSetupDomainName
22617- )
22618-
22619- type UserInfo10 struct {
22620- Name *uint16
22621- Comment *uint16
22622- UsrComment *uint16
22623- FullName *uint16
22624- }
22625-
22626- //sys NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) = netapi32.NetUserGetInfo
22627- //sys NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) = netapi32.NetGetJoinInformation
22628- //sys NetApiBufferFree(buf *byte) (neterr error) = netapi32.NetApiBufferFree
22629-
22630- const (
22631- // do not reorder
22632- SidTypeUser = 1 + iota
22633- SidTypeGroup
22634- SidTypeDomain
22635- SidTypeAlias
22636- SidTypeWellKnownGroup
22637- SidTypeDeletedAccount
22638- SidTypeInvalid
22639- SidTypeUnknown
22640- SidTypeComputer
22641- SidTypeLabel
22642- )
22643-
22644- type SidIdentifierAuthority struct {
22645- Value [6]byte
22646- }
22647-
22648- var (
22649- SECURITY_NULL_SID_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 0}}
22650- SECURITY_WORLD_SID_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 1}}
22651- SECURITY_LOCAL_SID_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 2}}
22652- SECURITY_CREATOR_SID_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 3}}
22653- SECURITY_NON_UNIQUE_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 4}}
22654- SECURITY_NT_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 5}}
22655- SECURITY_MANDATORY_LABEL_AUTHORITY = SidIdentifierAuthority{[6]byte{0, 0, 0, 0, 0, 16}}
22656- )
22657-
22658- const (
22659- SECURITY_NULL_RID = 0
22660- SECURITY_WORLD_RID = 0
22661- SECURITY_LOCAL_RID = 0
22662- SECURITY_CREATOR_OWNER_RID = 0
22663- SECURITY_CREATOR_GROUP_RID = 1
22664- SECURITY_DIALUP_RID = 1
22665- SECURITY_NETWORK_RID = 2
22666- SECURITY_BATCH_RID = 3
22667- SECURITY_INTERACTIVE_RID = 4
22668- SECURITY_LOGON_IDS_RID = 5
22669- SECURITY_SERVICE_RID = 6
22670- SECURITY_LOCAL_SYSTEM_RID = 18
22671- SECURITY_BUILTIN_DOMAIN_RID = 32
22672- SECURITY_PRINCIPAL_SELF_RID = 10
22673- SECURITY_CREATOR_OWNER_SERVER_RID = 0x2
22674- SECURITY_CREATOR_GROUP_SERVER_RID = 0x3
22675- SECURITY_LOGON_IDS_RID_COUNT = 0x3
22676- SECURITY_ANONYMOUS_LOGON_RID = 0x7
22677- SECURITY_PROXY_RID = 0x8
22678- SECURITY_ENTERPRISE_CONTROLLERS_RID = 0x9
22679- SECURITY_SERVER_LOGON_RID = SECURITY_ENTERPRISE_CONTROLLERS_RID
22680- SECURITY_AUTHENTICATED_USER_RID = 0xb
22681- SECURITY_RESTRICTED_CODE_RID = 0xc
22682- SECURITY_NT_NON_UNIQUE_RID = 0x15
22683- )
22684-
22685- // Predefined domain-relative RIDs for local groups.
22686- // See https://msdn.microsoft.com/en-us/library/windows/desktop/aa379649(v=vs.85).aspx
22687- const (
22688- DOMAIN_ALIAS_RID_ADMINS = 0x220
22689- DOMAIN_ALIAS_RID_USERS = 0x221
22690- DOMAIN_ALIAS_RID_GUESTS = 0x222
22691- DOMAIN_ALIAS_RID_POWER_USERS = 0x223
22692- DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224
22693- DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225
22694- DOMAIN_ALIAS_RID_PRINT_OPS = 0x226
22695- DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227
22696- DOMAIN_ALIAS_RID_REPLICATOR = 0x228
22697- DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229
22698- DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a
22699- DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS = 0x22b
22700- DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS = 0x22c
22701- DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS = 0x22d
22702- DOMAIN_ALIAS_RID_MONITORING_USERS = 0X22e
22703- DOMAIN_ALIAS_RID_LOGGING_USERS = 0x22f
22704- DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS = 0x230
22705- DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS = 0x231
22706- DOMAIN_ALIAS_RID_DCOM_USERS = 0x232
22707- DOMAIN_ALIAS_RID_IUSERS = 0x238
22708- DOMAIN_ALIAS_RID_CRYPTO_OPERATORS = 0x239
22709- DOMAIN_ALIAS_RID_CACHEABLE_PRINCIPALS_GROUP = 0x23b
22710- DOMAIN_ALIAS_RID_NON_CACHEABLE_PRINCIPALS_GROUP = 0x23c
22711- DOMAIN_ALIAS_RID_EVENT_LOG_READERS_GROUP = 0x23d
22712- DOMAIN_ALIAS_RID_CERTSVC_DCOM_ACCESS_GROUP = 0x23e
22713- )
22714-
22715- //sys LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) = advapi32.LookupAccountSidW
22716- //sys LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) = advapi32.LookupAccountNameW
22717- //sys ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) = advapi32.ConvertSidToStringSidW
22718- //sys ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) = advapi32.ConvertStringSidToSidW
22719- //sys GetLengthSid(sid *SID) (len uint32) = advapi32.GetLengthSid
22720- //sys CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) = advapi32.CopySid
22721- //sys AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, subAuth0 uint32, subAuth1 uint32, subAuth2 uint32, subAuth3 uint32, subAuth4 uint32, subAuth5 uint32, subAuth6 uint32, subAuth7 uint32, sid **SID) (err error) = advapi32.AllocateAndInitializeSid
22722- //sys FreeSid(sid *SID) (err error) [failretval!=0] = advapi32.FreeSid
22723- //sys EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) = advapi32.EqualSid
22724-
22725- // The security identifier (SID) structure is a variable-length
22726- // structure used to uniquely identify users or groups.
22727- type SID struct{}
22728-
22729- // StringToSid converts a string-format security identifier
22730- // sid into a valid, functional sid.
22731- func StringToSid(s string) (*SID, error) {
22732- var sid *SID
22733- p, e := UTF16PtrFromString(s)
22734- if e != nil {
22735- return nil, e
22736- }
22737- e = ConvertStringSidToSid(p, &sid)
22738- if e != nil {
22739- return nil, e
22740- }
22741- defer LocalFree((Handle)(unsafe.Pointer(sid)))
22742- return sid.Copy()
22743- }
22744-
22745- // LookupSID retrieves a security identifier sid for the account
22746- // and the name of the domain on which the account was found.
22747- // System specify target computer to search.
22748- func LookupSID(system, account string) (sid *SID, domain string, accType uint32, err error) {
22749- if len(account) == 0 {
22750- return nil, "", 0, syscall.EINVAL
22751- }
22752- acc, e := UTF16PtrFromString(account)
22753- if e != nil {
22754- return nil, "", 0, e
22755- }
22756- var sys *uint16
22757- if len(system) > 0 {
22758- sys, e = UTF16PtrFromString(system)
22759- if e != nil {
22760- return nil, "", 0, e
22761- }
22762- }
22763- n := uint32(50)
22764- dn := uint32(50)
22765- for {
22766- b := make([]byte, n)
22767- db := make([]uint16, dn)
22768- sid = (*SID)(unsafe.Pointer(&b[0]))
22769- e = LookupAccountName(sys, acc, sid, &n, &db[0], &dn, &accType)
22770- if e == nil {
22771- return sid, UTF16ToString(db), accType, nil
22772- }
22773- if e != ERROR_INSUFFICIENT_BUFFER {
22774- return nil, "", 0, e
22775- }
22776- if n <= uint32(len(b)) {
22777- return nil, "", 0, e
22778- }
22779- }
22780- }
22781-
22782- // String converts sid to a string format
22783- // suitable for display, storage, or transmission.
22784- func (sid *SID) String() (string, error) {
22785- var s *uint16
22786- e := ConvertSidToStringSid(sid, &s)
22787- if e != nil {
22788- return "", e
22789- }
22790- defer LocalFree((Handle)(unsafe.Pointer(s)))
22791- return UTF16ToString((*[256]uint16)(unsafe.Pointer(s))[:]), nil
22792- }
22793-
22794- // Len returns the length, in bytes, of a valid security identifier sid.
22795- func (sid *SID) Len() int {
22796- return int(GetLengthSid(sid))
22797- }
22798-
22799- // Copy creates a duplicate of security identifier sid.
22800- func (sid *SID) Copy() (*SID, error) {
22801- b := make([]byte, sid.Len())
22802- sid2 := (*SID)(unsafe.Pointer(&b[0]))
22803- e := CopySid(uint32(len(b)), sid2, sid)
22804- if e != nil {
22805- return nil, e
22806- }
22807- return sid2, nil
22808- }
22809-
22810- // LookupAccount retrieves the name of the account for this sid
22811- // and the name of the first domain on which this sid is found.
22812- // System specify target computer to search for.
22813- func (sid *SID) LookupAccount(system string) (account, domain string, accType uint32, err error) {
22814- var sys *uint16
22815- if len(system) > 0 {
22816- sys, err = UTF16PtrFromString(system)
22817- if err != nil {
22818- return "", "", 0, err
22819- }
22820- }
22821- n := uint32(50)
22822- dn := uint32(50)
22823- for {
22824- b := make([]uint16, n)
22825- db := make([]uint16, dn)
22826- e := LookupAccountSid(sys, sid, &b[0], &n, &db[0], &dn, &accType)
22827- if e == nil {
22828- return UTF16ToString(b), UTF16ToString(db), accType, nil
22829- }
22830- if e != ERROR_INSUFFICIENT_BUFFER {
22831- return "", "", 0, e
22832- }
22833- if n <= uint32(len(b)) {
22834- return "", "", 0, e
22835- }
22836- }
22837- }
22838-
22839- const (
22840- // do not reorder
22841- TOKEN_ASSIGN_PRIMARY = 1 << iota
22842- TOKEN_DUPLICATE
22843- TOKEN_IMPERSONATE
22844- TOKEN_QUERY
22845- TOKEN_QUERY_SOURCE
22846- TOKEN_ADJUST_PRIVILEGES
22847- TOKEN_ADJUST_GROUPS
22848- TOKEN_ADJUST_DEFAULT
22849-
22850- TOKEN_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED |
22851- TOKEN_ASSIGN_PRIMARY |
22852- TOKEN_DUPLICATE |
22853- TOKEN_IMPERSONATE |
22854- TOKEN_QUERY |
22855- TOKEN_QUERY_SOURCE |
22856- TOKEN_ADJUST_PRIVILEGES |
22857- TOKEN_ADJUST_GROUPS |
22858- TOKEN_ADJUST_DEFAULT
22859- TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY
22860- TOKEN_WRITE = STANDARD_RIGHTS_WRITE |
22861- TOKEN_ADJUST_PRIVILEGES |
22862- TOKEN_ADJUST_GROUPS |
22863- TOKEN_ADJUST_DEFAULT
22864- TOKEN_EXECUTE = STANDARD_RIGHTS_EXECUTE
22865- )
22866-
22867- const (
22868- // do not reorder
22869- TokenUser = 1 + iota
22870- TokenGroups
22871- TokenPrivileges
22872- TokenOwner
22873- TokenPrimaryGroup
22874- TokenDefaultDacl
22875- TokenSource
22876- TokenType
22877- TokenImpersonationLevel
22878- TokenStatistics
22879- TokenRestrictedSids
22880- TokenSessionId
22881- TokenGroupsAndPrivileges
22882- TokenSessionReference
22883- TokenSandBoxInert
22884- TokenAuditPolicy
22885- TokenOrigin
22886- TokenElevationType
22887- TokenLinkedToken
22888- TokenElevation
22889- TokenHasRestrictions
22890- TokenAccessInformation
22891- TokenVirtualizationAllowed
22892- TokenVirtualizationEnabled
22893- TokenIntegrityLevel
22894- TokenUIAccess
22895- TokenMandatoryPolicy
22896- TokenLogonSid
22897- MaxTokenInfoClass
22898- )
22899-
22900- type SIDAndAttributes struct {
22901- Sid *SID
22902- Attributes uint32
22903- }
22904-
22905- type Tokenuser struct {
22906- User SIDAndAttributes
22907- }
22908-
22909- type Tokenprimarygroup struct {
22910- PrimaryGroup *SID
22911- }
22912-
22913- type Tokengroups struct {
22914- GroupCount uint32
22915- Groups [1]SIDAndAttributes
22916- }
22917-
22918- // Authorization Functions
22919- //sys checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) = advapi32.CheckTokenMembership
22920- //sys OpenProcessToken(h Handle, access uint32, token *Token) (err error) = advapi32.OpenProcessToken
22921- //sys GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) = advapi32.GetTokenInformation
22922- //sys GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) = userenv.GetUserProfileDirectoryW
22923-
22924- // An access token contains the security information for a logon session.
22925- // The system creates an access token when a user logs on, and every
22926- // process executed on behalf of the user has a copy of the token.
22927- // The token identifies the user, the user's groups, and the user's
22928- // privileges. The system uses the token to control access to securable
22929- // objects and to control the ability of the user to perform various
22930- // system-related operations on the local computer.
22931- type Token Handle
22932-
22933- // OpenCurrentProcessToken opens the access token
22934- // associated with current process.
22935- func OpenCurrentProcessToken() (Token, error) {
22936- p, e := GetCurrentProcess()
22937- if e != nil {
22938- return 0, e
22939- }
22940- var t Token
22941- e = OpenProcessToken(p, TOKEN_QUERY, &t)
22942- if e != nil {
22943- return 0, e
22944- }
22945- return t, nil
22946- }
22947-
22948- // Close releases access to access token.
22949- func (t Token) Close() error {
22950- return CloseHandle(Handle(t))
22951- }
22952-
22953- // getInfo retrieves a specified type of information about an access token.
22954- func (t Token) getInfo(class uint32, initSize int) (unsafe.Pointer, error) {
22955- n := uint32(initSize)
22956- for {
22957- b := make([]byte, n)
22958- e := GetTokenInformation(t, class, &b[0], uint32(len(b)), &n)
22959- if e == nil {
22960- return unsafe.Pointer(&b[0]), nil
22961- }
22962- if e != ERROR_INSUFFICIENT_BUFFER {
22963- return nil, e
22964- }
22965- if n <= uint32(len(b)) {
22966- return nil, e
22967- }
22968- }
22969- }
22970-
22971- // GetTokenUser retrieves access token t user account information.
22972- func (t Token) GetTokenUser() (*Tokenuser, error) {
22973- i, e := t.getInfo(TokenUser, 50)
22974- if e != nil {
22975- return nil, e
22976- }
22977- return (*Tokenuser)(i), nil
22978- }
22979-
22980- // GetTokenGroups retrieves group accounts associated with access token t.
22981- func (t Token) GetTokenGroups() (*Tokengroups, error) {
22982- i, e := t.getInfo(TokenGroups, 50)
22983- if e != nil {
22984- return nil, e
22985- }
22986- return (*Tokengroups)(i), nil
22987- }
22988-
22989- // GetTokenPrimaryGroup retrieves access token t primary group information.
22990- // A pointer to a SID structure representing a group that will become
22991- // the primary group of any objects created by a process using this access token.
22992- func (t Token) GetTokenPrimaryGroup() (*Tokenprimarygroup, error) {
22993- i, e := t.getInfo(TokenPrimaryGroup, 50)
22994- if e != nil {
22995- return nil, e
22996- }
22997- return (*Tokenprimarygroup)(i), nil
22998- }
22999-
23000- // GetUserProfileDirectory retrieves path to the
23001- // root directory of the access token t user's profile.
23002- func (t Token) GetUserProfileDirectory() (string, error) {
23003- n := uint32(100)
23004- for {
23005- b := make([]uint16, n)
23006- e := GetUserProfileDirectory(t, &b[0], &n)
23007- if e == nil {
23008- return UTF16ToString(b), nil
23009- }
23010- if e != ERROR_INSUFFICIENT_BUFFER {
23011- return "", e
23012- }
23013- if n <= uint32(len(b)) {
23014- return "", e
23015- }
23016- }
23017- }
23018-
23019- // IsMember reports whether the access token t is a member of the provided SID.
23020- func (t Token) IsMember(sid *SID) (bool, error) {
23021- var b int32
23022- if e := checkTokenMembership(t, sid, &b); e != nil {
23023- return false, e
23024- }
23025- return b != 0, nil
23026- }
23027 diff --git a/vendor/golang.org/x/sys/windows/service.go b/vendor/golang.org/x/sys/windows/service.go
23028deleted file mode 100644
23029index a500dd7..0000000
23030--- a/vendor/golang.org/x/sys/windows/service.go
23031+++ /dev/null
23032 @@ -1,164 +0,0 @@
23033- // Copyright 2012 The Go Authors. All rights reserved.
23034- // Use of this source code is governed by a BSD-style
23035- // license that can be found in the LICENSE file.
23036-
23037- // +build windows
23038-
23039- package windows
23040-
23041- const (
23042- SC_MANAGER_CONNECT = 1
23043- SC_MANAGER_CREATE_SERVICE = 2
23044- SC_MANAGER_ENUMERATE_SERVICE = 4
23045- SC_MANAGER_LOCK = 8
23046- SC_MANAGER_QUERY_LOCK_STATUS = 16
23047- SC_MANAGER_MODIFY_BOOT_CONFIG = 32
23048- SC_MANAGER_ALL_ACCESS = 0xf003f
23049- )
23050-
23051- //sys OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenSCManagerW
23052-
23053- const (
23054- SERVICE_KERNEL_DRIVER = 1
23055- SERVICE_FILE_SYSTEM_DRIVER = 2
23056- SERVICE_ADAPTER = 4
23057- SERVICE_RECOGNIZER_DRIVER = 8
23058- SERVICE_WIN32_OWN_PROCESS = 16
23059- SERVICE_WIN32_SHARE_PROCESS = 32
23060- SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS
23061- SERVICE_INTERACTIVE_PROCESS = 256
23062- SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_RECOGNIZER_DRIVER
23063- SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS
23064-
23065- SERVICE_BOOT_START = 0
23066- SERVICE_SYSTEM_START = 1
23067- SERVICE_AUTO_START = 2
23068- SERVICE_DEMAND_START = 3
23069- SERVICE_DISABLED = 4
23070-
23071- SERVICE_ERROR_IGNORE = 0
23072- SERVICE_ERROR_NORMAL = 1
23073- SERVICE_ERROR_SEVERE = 2
23074- SERVICE_ERROR_CRITICAL = 3
23075-
23076- SC_STATUS_PROCESS_INFO = 0
23077-
23078- SERVICE_STOPPED = 1
23079- SERVICE_START_PENDING = 2
23080- SERVICE_STOP_PENDING = 3
23081- SERVICE_RUNNING = 4
23082- SERVICE_CONTINUE_PENDING = 5
23083- SERVICE_PAUSE_PENDING = 6
23084- SERVICE_PAUSED = 7
23085- SERVICE_NO_CHANGE = 0xffffffff
23086-
23087- SERVICE_ACCEPT_STOP = 1
23088- SERVICE_ACCEPT_PAUSE_CONTINUE = 2
23089- SERVICE_ACCEPT_SHUTDOWN = 4
23090- SERVICE_ACCEPT_PARAMCHANGE = 8
23091- SERVICE_ACCEPT_NETBINDCHANGE = 16
23092- SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 32
23093- SERVICE_ACCEPT_POWEREVENT = 64
23094- SERVICE_ACCEPT_SESSIONCHANGE = 128
23095-
23096- SERVICE_CONTROL_STOP = 1
23097- SERVICE_CONTROL_PAUSE = 2
23098- SERVICE_CONTROL_CONTINUE = 3
23099- SERVICE_CONTROL_INTERROGATE = 4
23100- SERVICE_CONTROL_SHUTDOWN = 5
23101- SERVICE_CONTROL_PARAMCHANGE = 6
23102- SERVICE_CONTROL_NETBINDADD = 7
23103- SERVICE_CONTROL_NETBINDREMOVE = 8
23104- SERVICE_CONTROL_NETBINDENABLE = 9
23105- SERVICE_CONTROL_NETBINDDISABLE = 10
23106- SERVICE_CONTROL_DEVICEEVENT = 11
23107- SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12
23108- SERVICE_CONTROL_POWEREVENT = 13
23109- SERVICE_CONTROL_SESSIONCHANGE = 14
23110-
23111- SERVICE_ACTIVE = 1
23112- SERVICE_INACTIVE = 2
23113- SERVICE_STATE_ALL = 3
23114-
23115- SERVICE_QUERY_CONFIG = 1
23116- SERVICE_CHANGE_CONFIG = 2
23117- SERVICE_QUERY_STATUS = 4
23118- SERVICE_ENUMERATE_DEPENDENTS = 8
23119- SERVICE_START = 16
23120- SERVICE_STOP = 32
23121- SERVICE_PAUSE_CONTINUE = 64
23122- SERVICE_INTERROGATE = 128
23123- SERVICE_USER_DEFINED_CONTROL = 256
23124- SERVICE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_INTERROGATE | SERVICE_USER_DEFINED_CONTROL
23125- SERVICE_RUNS_IN_SYSTEM_PROCESS = 1
23126- SERVICE_CONFIG_DESCRIPTION = 1
23127- SERVICE_CONFIG_FAILURE_ACTIONS = 2
23128-
23129- NO_ERROR = 0
23130-
23131- SC_ENUM_PROCESS_INFO = 0
23132- )
23133-
23134- type SERVICE_STATUS struct {
23135- ServiceType uint32
23136- CurrentState uint32
23137- ControlsAccepted uint32
23138- Win32ExitCode uint32
23139- ServiceSpecificExitCode uint32
23140- CheckPoint uint32
23141- WaitHint uint32
23142- }
23143-
23144- type SERVICE_TABLE_ENTRY struct {
23145- ServiceName *uint16
23146- ServiceProc uintptr
23147- }
23148-
23149- type QUERY_SERVICE_CONFIG struct {
23150- ServiceType uint32
23151- StartType uint32
23152- ErrorControl uint32
23153- BinaryPathName *uint16
23154- LoadOrderGroup *uint16
23155- TagId uint32
23156- Dependencies *uint16
23157- ServiceStartName *uint16
23158- DisplayName *uint16
23159- }
23160-
23161- type SERVICE_DESCRIPTION struct {
23162- Description *uint16
23163- }
23164-
23165- type SERVICE_STATUS_PROCESS struct {
23166- ServiceType uint32
23167- CurrentState uint32
23168- ControlsAccepted uint32
23169- Win32ExitCode uint32
23170- ServiceSpecificExitCode uint32
23171- CheckPoint uint32
23172- WaitHint uint32
23173- ProcessId uint32
23174- ServiceFlags uint32
23175- }
23176-
23177- type ENUM_SERVICE_STATUS_PROCESS struct {
23178- ServiceName *uint16
23179- DisplayName *uint16
23180- ServiceStatusProcess SERVICE_STATUS_PROCESS
23181- }
23182-
23183- //sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle
23184- //sys CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) [failretval==0] = advapi32.CreateServiceW
23185- //sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW
23186- //sys DeleteService(service Handle) (err error) = advapi32.DeleteService
23187- //sys StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) = advapi32.StartServiceW
23188- //sys QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) = advapi32.QueryServiceStatus
23189- //sys ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) = advapi32.ControlService
23190- //sys StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) = advapi32.StartServiceCtrlDispatcherW
23191- //sys SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) = advapi32.SetServiceStatus
23192- //sys ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) = advapi32.ChangeServiceConfigW
23193- //sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW
23194- //sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W
23195- //sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W
23196- //sys EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) = advapi32.EnumServicesStatusExW
23197 diff --git a/vendor/golang.org/x/sys/windows/str.go b/vendor/golang.org/x/sys/windows/str.go
23198deleted file mode 100644
23199index 917cc2a..0000000
23200--- a/vendor/golang.org/x/sys/windows/str.go
23201+++ /dev/null
23202 @@ -1,22 +0,0 @@
23203- // Copyright 2009 The Go Authors. All rights reserved.
23204- // Use of this source code is governed by a BSD-style
23205- // license that can be found in the LICENSE file.
23206-
23207- // +build windows
23208-
23209- package windows
23210-
23211- func itoa(val int) string { // do it here rather than with fmt to avoid dependency
23212- if val < 0 {
23213- return "-" + itoa(-val)
23214- }
23215- var buf [32]byte // big enough for int64
23216- i := len(buf) - 1
23217- for val >= 10 {
23218- buf[i] = byte(val%10 + '0')
23219- i--
23220- val /= 10
23221- }
23222- buf[i] = byte(val + '0')
23223- return string(buf[i:])
23224- }
23225 diff --git a/vendor/golang.org/x/sys/windows/svc/debug/log.go b/vendor/golang.org/x/sys/windows/svc/debug/log.go
23226deleted file mode 100644
23227index e51ab42..0000000
23228--- a/vendor/golang.org/x/sys/windows/svc/debug/log.go
23229+++ /dev/null
23230 @@ -1,56 +0,0 @@
23231- // Copyright 2012 The Go Authors. All rights reserved.
23232- // Use of this source code is governed by a BSD-style
23233- // license that can be found in the LICENSE file.
23234-
23235- // +build windows
23236-
23237- package debug
23238-
23239- import (
23240- "os"
23241- "strconv"
23242- )
23243-
23244- // Log interface allows different log implementations to be used.
23245- type Log interface {
23246- Close() error
23247- Info(eid uint32, msg string) error
23248- Warning(eid uint32, msg string) error
23249- Error(eid uint32, msg string) error
23250- }
23251-
23252- // ConsoleLog provides access to the console.
23253- type ConsoleLog struct {
23254- Name string
23255- }
23256-
23257- // New creates new ConsoleLog.
23258- func New(source string) *ConsoleLog {
23259- return &ConsoleLog{Name: source}
23260- }
23261-
23262- // Close closes console log l.
23263- func (l *ConsoleLog) Close() error {
23264- return nil
23265- }
23266-
23267- func (l *ConsoleLog) report(kind string, eid uint32, msg string) error {
23268- s := l.Name + "." + kind + "(" + strconv.Itoa(int(eid)) + "): " + msg + "\n"
23269- _, err := os.Stdout.Write([]byte(s))
23270- return err
23271- }
23272-
23273- // Info writes an information event msg with event id eid to the console l.
23274- func (l *ConsoleLog) Info(eid uint32, msg string) error {
23275- return l.report("info", eid, msg)
23276- }
23277-
23278- // Warning writes an warning event msg with event id eid to the console l.
23279- func (l *ConsoleLog) Warning(eid uint32, msg string) error {
23280- return l.report("warn", eid, msg)
23281- }
23282-
23283- // Error writes an error event msg with event id eid to the console l.
23284- func (l *ConsoleLog) Error(eid uint32, msg string) error {
23285- return l.report("error", eid, msg)
23286- }
23287 diff --git a/vendor/golang.org/x/sys/windows/svc/debug/service.go b/vendor/golang.org/x/sys/windows/svc/debug/service.go
23288deleted file mode 100644
23289index 123df98..0000000
23290--- a/vendor/golang.org/x/sys/windows/svc/debug/service.go
23291+++ /dev/null
23292 @@ -1,45 +0,0 @@
23293- // Copyright 2012 The Go Authors. All rights reserved.
23294- // Use of this source code is governed by a BSD-style
23295- // license that can be found in the LICENSE file.
23296-
23297- // +build windows
23298-
23299- // Package debug provides facilities to execute svc.Handler on console.
23300- //
23301- package debug
23302-
23303- import (
23304- "os"
23305- "os/signal"
23306- "syscall"
23307-
23308- "golang.org/x/sys/windows/svc"
23309- )
23310-
23311- // Run executes service name by calling appropriate handler function.
23312- // The process is running on console, unlike real service. Use Ctrl+C to
23313- // send "Stop" command to your service.
23314- func Run(name string, handler svc.Handler) error {
23315- cmds := make(chan svc.ChangeRequest)
23316- changes := make(chan svc.Status)
23317-
23318- sig := make(chan os.Signal)
23319- signal.Notify(sig)
23320-
23321- go func() {
23322- status := svc.Status{State: svc.Stopped}
23323- for {
23324- select {
23325- case <-sig:
23326- cmds <- svc.ChangeRequest{svc.Stop, 0, 0, status}
23327- case status = <-changes:
23328- }
23329- }
23330- }()
23331-
23332- _, errno := handler.Execute([]string{name}, cmds, changes)
23333- if errno != 0 {
23334- return syscall.Errno(errno)
23335- }
23336- return nil
23337- }
23338 diff --git a/vendor/golang.org/x/sys/windows/svc/event.go b/vendor/golang.org/x/sys/windows/svc/event.go
23339deleted file mode 100644
23340index 0508e22..0000000
23341--- a/vendor/golang.org/x/sys/windows/svc/event.go
23342+++ /dev/null
23343 @@ -1,48 +0,0 @@
23344- // Copyright 2012 The Go Authors. All rights reserved.
23345- // Use of this source code is governed by a BSD-style
23346- // license that can be found in the LICENSE file.
23347-
23348- // +build windows
23349-
23350- package svc
23351-
23352- import (
23353- "errors"
23354-
23355- "golang.org/x/sys/windows"
23356- )
23357-
23358- // event represents auto-reset, initially non-signaled Windows event.
23359- // It is used to communicate between go and asm parts of this package.
23360- type event struct {
23361- h windows.Handle
23362- }
23363-
23364- func newEvent() (*event, error) {
23365- h, err := windows.CreateEvent(nil, 0, 0, nil)
23366- if err != nil {
23367- return nil, err
23368- }
23369- return &event{h: h}, nil
23370- }
23371-
23372- func (e *event) Close() error {
23373- return windows.CloseHandle(e.h)
23374- }
23375-
23376- func (e *event) Set() error {
23377- return windows.SetEvent(e.h)
23378- }
23379-
23380- func (e *event) Wait() error {
23381- s, err := windows.WaitForSingleObject(e.h, windows.INFINITE)
23382- switch s {
23383- case windows.WAIT_OBJECT_0:
23384- break
23385- case windows.WAIT_FAILED:
23386- return err
23387- default:
23388- return errors.New("unexpected result from WaitForSingleObject")
23389- }
23390- return nil
23391- }
23392 diff --git a/vendor/golang.org/x/sys/windows/svc/eventlog/install.go b/vendor/golang.org/x/sys/windows/svc/eventlog/install.go
23393deleted file mode 100644
23394index c76a376..0000000
23395--- a/vendor/golang.org/x/sys/windows/svc/eventlog/install.go
23396+++ /dev/null
23397 @@ -1,80 +0,0 @@
23398- // Copyright 2012 The Go Authors. All rights reserved.
23399- // Use of this source code is governed by a BSD-style
23400- // license that can be found in the LICENSE file.
23401-
23402- // +build windows
23403-
23404- package eventlog
23405-
23406- import (
23407- "errors"
23408-
23409- "golang.org/x/sys/windows"
23410- "golang.org/x/sys/windows/registry"
23411- )
23412-
23413- const (
23414- // Log levels.
23415- Info = windows.EVENTLOG_INFORMATION_TYPE
23416- Warning = windows.EVENTLOG_WARNING_TYPE
23417- Error = windows.EVENTLOG_ERROR_TYPE
23418- )
23419-
23420- const addKeyName = `SYSTEM\CurrentControlSet\Services\EventLog\Application`
23421-
23422- // Install modifies PC registry to allow logging with an event source src.
23423- // It adds all required keys and values to the event log registry key.
23424- // Install uses msgFile as the event message file. If useExpandKey is true,
23425- // the event message file is installed as REG_EXPAND_SZ value,
23426- // otherwise as REG_SZ. Use bitwise of log.Error, log.Warning and
23427- // log.Info to specify events supported by the new event source.
23428- func Install(src, msgFile string, useExpandKey bool, eventsSupported uint32) error {
23429- appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.CREATE_SUB_KEY)
23430- if err != nil {
23431- return err
23432- }
23433- defer appkey.Close()
23434-
23435- sk, alreadyExist, err := registry.CreateKey(appkey, src, registry.SET_VALUE)
23436- if err != nil {
23437- return err
23438- }
23439- defer sk.Close()
23440- if alreadyExist {
23441- return errors.New(addKeyName + `\` + src + " registry key already exists")
23442- }
23443-
23444- err = sk.SetDWordValue("CustomSource", 1)
23445- if err != nil {
23446- return err
23447- }
23448- if useExpandKey {
23449- err = sk.SetExpandStringValue("EventMessageFile", msgFile)
23450- } else {
23451- err = sk.SetStringValue("EventMessageFile", msgFile)
23452- }
23453- if err != nil {
23454- return err
23455- }
23456- err = sk.SetDWordValue("TypesSupported", eventsSupported)
23457- if err != nil {
23458- return err
23459- }
23460- return nil
23461- }
23462-
23463- // InstallAsEventCreate is the same as Install, but uses
23464- // %SystemRoot%\System32\EventCreate.exe as the event message file.
23465- func InstallAsEventCreate(src string, eventsSupported uint32) error {
23466- return Install(src, "%SystemRoot%\\System32\\EventCreate.exe", true, eventsSupported)
23467- }
23468-
23469- // Remove deletes all registry elements installed by the correspondent Install.
23470- func Remove(src string) error {
23471- appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.SET_VALUE)
23472- if err != nil {
23473- return err
23474- }
23475- defer appkey.Close()
23476- return registry.DeleteKey(appkey, src)
23477- }
23478 diff --git a/vendor/golang.org/x/sys/windows/svc/eventlog/log.go b/vendor/golang.org/x/sys/windows/svc/eventlog/log.go
23479deleted file mode 100644
23480index 46e5153..0000000
23481--- a/vendor/golang.org/x/sys/windows/svc/eventlog/log.go
23482+++ /dev/null
23483 @@ -1,70 +0,0 @@
23484- // Copyright 2012 The Go Authors. All rights reserved.
23485- // Use of this source code is governed by a BSD-style
23486- // license that can be found in the LICENSE file.
23487-
23488- // +build windows
23489-
23490- // Package eventlog implements access to Windows event log.
23491- //
23492- package eventlog
23493-
23494- import (
23495- "errors"
23496- "syscall"
23497-
23498- "golang.org/x/sys/windows"
23499- )
23500-
23501- // Log provides access to the system log.
23502- type Log struct {
23503- Handle windows.Handle
23504- }
23505-
23506- // Open retrieves a handle to the specified event log.
23507- func Open(source string) (*Log, error) {
23508- return OpenRemote("", source)
23509- }
23510-
23511- // OpenRemote does the same as Open, but on different computer host.
23512- func OpenRemote(host, source string) (*Log, error) {
23513- if source == "" {
23514- return nil, errors.New("Specify event log source")
23515- }
23516- var s *uint16
23517- if host != "" {
23518- s = syscall.StringToUTF16Ptr(host)
23519- }
23520- h, err := windows.RegisterEventSource(s, syscall.StringToUTF16Ptr(source))
23521- if err != nil {
23522- return nil, err
23523- }
23524- return &Log{Handle: h}, nil
23525- }
23526-
23527- // Close closes event log l.
23528- func (l *Log) Close() error {
23529- return windows.DeregisterEventSource(l.Handle)
23530- }
23531-
23532- func (l *Log) report(etype uint16, eid uint32, msg string) error {
23533- ss := []*uint16{syscall.StringToUTF16Ptr(msg)}
23534- return windows.ReportEvent(l.Handle, etype, 0, eid, 0, 1, 0, &ss[0], nil)
23535- }
23536-
23537- // Info writes an information event msg with event id eid to the end of event log l.
23538- // When EventCreate.exe is used, eid must be between 1 and 1000.
23539- func (l *Log) Info(eid uint32, msg string) error {
23540- return l.report(windows.EVENTLOG_INFORMATION_TYPE, eid, msg)
23541- }
23542-
23543- // Warning writes an warning event msg with event id eid to the end of event log l.
23544- // When EventCreate.exe is used, eid must be between 1 and 1000.
23545- func (l *Log) Warning(eid uint32, msg string) error {
23546- return l.report(windows.EVENTLOG_WARNING_TYPE, eid, msg)
23547- }
23548-
23549- // Error writes an error event msg with event id eid to the end of event log l.
23550- // When EventCreate.exe is used, eid must be between 1 and 1000.
23551- func (l *Log) Error(eid uint32, msg string) error {
23552- return l.report(windows.EVENTLOG_ERROR_TYPE, eid, msg)
23553- }
23554 diff --git a/vendor/golang.org/x/sys/windows/svc/eventlog/log_test.go b/vendor/golang.org/x/sys/windows/svc/eventlog/log_test.go
23555deleted file mode 100644
23556index 6fbbd4a..0000000
23557--- a/vendor/golang.org/x/sys/windows/svc/eventlog/log_test.go
23558+++ /dev/null
23559 @@ -1,51 +0,0 @@
23560- // Copyright 2012 The Go Authors. All rights reserved.
23561- // Use of this source code is governed by a BSD-style
23562- // license that can be found in the LICENSE file.
23563-
23564- // +build windows
23565-
23566- package eventlog_test
23567-
23568- import (
23569- "testing"
23570-
23571- "golang.org/x/sys/windows/svc/eventlog"
23572- )
23573-
23574- func TestLog(t *testing.T) {
23575- if testing.Short() {
23576- t.Skip("skipping test in short mode - it modifies system logs")
23577- }
23578-
23579- const name = "mylog"
23580- const supports = eventlog.Error | eventlog.Warning | eventlog.Info
23581- err := eventlog.InstallAsEventCreate(name, supports)
23582- if err != nil {
23583- t.Fatalf("Install failed: %s", err)
23584- }
23585- defer func() {
23586- err = eventlog.Remove(name)
23587- if err != nil {
23588- t.Fatalf("Remove failed: %s", err)
23589- }
23590- }()
23591-
23592- l, err := eventlog.Open(name)
23593- if err != nil {
23594- t.Fatalf("Open failed: %s", err)
23595- }
23596- defer l.Close()
23597-
23598- err = l.Info(1, "info")
23599- if err != nil {
23600- t.Fatalf("Info failed: %s", err)
23601- }
23602- err = l.Warning(2, "warning")
23603- if err != nil {
23604- t.Fatalf("Warning failed: %s", err)
23605- }
23606- err = l.Error(3, "error")
23607- if err != nil {
23608- t.Fatalf("Error failed: %s", err)
23609- }
23610- }
23611 diff --git a/vendor/golang.org/x/sys/windows/svc/example/beep.go b/vendor/golang.org/x/sys/windows/svc/example/beep.go
23612deleted file mode 100644
23613index dcf2340..0000000
23614--- a/vendor/golang.org/x/sys/windows/svc/example/beep.go
23615+++ /dev/null
23616 @@ -1,22 +0,0 @@
23617- // Copyright 2012 The Go Authors. All rights reserved.
23618- // Use of this source code is governed by a BSD-style
23619- // license that can be found in the LICENSE file.
23620-
23621- // +build windows
23622-
23623- package main
23624-
23625- import (
23626- "syscall"
23627- )
23628-
23629- // BUG(brainman): MessageBeep Windows api is broken on Windows 7,
23630- // so this example does not beep when runs as service on Windows 7.
23631-
23632- var (
23633- beepFunc = syscall.MustLoadDLL("user32.dll").MustFindProc("MessageBeep")
23634- )
23635-
23636- func beep() {
23637- beepFunc.Call(0xffffffff)
23638- }
23639 diff --git a/vendor/golang.org/x/sys/windows/svc/example/install.go b/vendor/golang.org/x/sys/windows/svc/example/install.go
23640deleted file mode 100644
23641index 39cb00d..0000000
23642--- a/vendor/golang.org/x/sys/windows/svc/example/install.go
23643+++ /dev/null
23644 @@ -1,92 +0,0 @@
23645- // Copyright 2012 The Go Authors. All rights reserved.
23646- // Use of this source code is governed by a BSD-style
23647- // license that can be found in the LICENSE file.
23648-
23649- // +build windows
23650-
23651- package main
23652-
23653- import (
23654- "fmt"
23655- "os"
23656- "path/filepath"
23657-
23658- "golang.org/x/sys/windows/svc/eventlog"
23659- "golang.org/x/sys/windows/svc/mgr"
23660- )
23661-
23662- func exePath() (string, error) {
23663- prog := os.Args[0]
23664- p, err := filepath.Abs(prog)
23665- if err != nil {
23666- return "", err
23667- }
23668- fi, err := os.Stat(p)
23669- if err == nil {
23670- if !fi.Mode().IsDir() {
23671- return p, nil
23672- }
23673- err = fmt.Errorf("%s is directory", p)
23674- }
23675- if filepath.Ext(p) == "" {
23676- p += ".exe"
23677- fi, err := os.Stat(p)
23678- if err == nil {
23679- if !fi.Mode().IsDir() {
23680- return p, nil
23681- }
23682- err = fmt.Errorf("%s is directory", p)
23683- }
23684- }
23685- return "", err
23686- }
23687-
23688- func installService(name, desc string) error {
23689- exepath, err := exePath()
23690- if err != nil {
23691- return err
23692- }
23693- m, err := mgr.Connect()
23694- if err != nil {
23695- return err
23696- }
23697- defer m.Disconnect()
23698- s, err := m.OpenService(name)
23699- if err == nil {
23700- s.Close()
23701- return fmt.Errorf("service %s already exists", name)
23702- }
23703- s, err = m.CreateService(name, exepath, mgr.Config{DisplayName: desc}, "is", "auto-started")
23704- if err != nil {
23705- return err
23706- }
23707- defer s.Close()
23708- err = eventlog.InstallAsEventCreate(name, eventlog.Error|eventlog.Warning|eventlog.Info)
23709- if err != nil {
23710- s.Delete()
23711- return fmt.Errorf("SetupEventLogSource() failed: %s", err)
23712- }
23713- return nil
23714- }
23715-
23716- func removeService(name string) error {
23717- m, err := mgr.Connect()
23718- if err != nil {
23719- return err
23720- }
23721- defer m.Disconnect()
23722- s, err := m.OpenService(name)
23723- if err != nil {
23724- return fmt.Errorf("service %s is not installed", name)
23725- }
23726- defer s.Close()
23727- err = s.Delete()
23728- if err != nil {
23729- return err
23730- }
23731- err = eventlog.Remove(name)
23732- if err != nil {
23733- return fmt.Errorf("RemoveEventLogSource() failed: %s", err)
23734- }
23735- return nil
23736- }
23737 diff --git a/vendor/golang.org/x/sys/windows/svc/example/main.go b/vendor/golang.org/x/sys/windows/svc/example/main.go
23738deleted file mode 100644
23739index dc96c08..0000000
23740--- a/vendor/golang.org/x/sys/windows/svc/example/main.go
23741+++ /dev/null
23742 @@ -1,76 +0,0 @@
23743- // Copyright 2012 The Go Authors. All rights reserved.
23744- // Use of this source code is governed by a BSD-style
23745- // license that can be found in the LICENSE file.
23746-
23747- // +build windows
23748-
23749- // Example service program that beeps.
23750- //
23751- // The program demonstrates how to create Windows service and
23752- // install / remove it on a computer. It also shows how to
23753- // stop / start / pause / continue any service, and how to
23754- // write to event log. It also shows how to use debug
23755- // facilities available in debug package.
23756- //
23757- package main
23758-
23759- import (
23760- "fmt"
23761- "log"
23762- "os"
23763- "strings"
23764-
23765- "golang.org/x/sys/windows/svc"
23766- )
23767-
23768- func usage(errmsg string) {
23769- fmt.Fprintf(os.Stderr,
23770- "%s\n\n"+
23771- "usage: %s <command>\n"+
23772- " where <command> is one of\n"+
23773- " install, remove, debug, start, stop, pause or continue.\n",
23774- errmsg, os.Args[0])
23775- os.Exit(2)
23776- }
23777-
23778- func main() {
23779- const svcName = "myservice"
23780-
23781- isIntSess, err := svc.IsAnInteractiveSession()
23782- if err != nil {
23783- log.Fatalf("failed to determine if we are running in an interactive session: %v", err)
23784- }
23785- if !isIntSess {
23786- runService(svcName, false)
23787- return
23788- }
23789-
23790- if len(os.Args) < 2 {
23791- usage("no command specified")
23792- }
23793-
23794- cmd := strings.ToLower(os.Args[1])
23795- switch cmd {
23796- case "debug":
23797- runService(svcName, true)
23798- return
23799- case "install":
23800- err = installService(svcName, "my service")
23801- case "remove":
23802- err = removeService(svcName)
23803- case "start":
23804- err = startService(svcName)
23805- case "stop":
23806- err = controlService(svcName, svc.Stop, svc.Stopped)
23807- case "pause":
23808- err = controlService(svcName, svc.Pause, svc.Paused)
23809- case "continue":
23810- err = controlService(svcName, svc.Continue, svc.Running)
23811- default:
23812- usage(fmt.Sprintf("invalid command %s", cmd))
23813- }
23814- if err != nil {
23815- log.Fatalf("failed to %s %s: %v", cmd, svcName, err)
23816- }
23817- return
23818- }
23819 diff --git a/vendor/golang.org/x/sys/windows/svc/example/manage.go b/vendor/golang.org/x/sys/windows/svc/example/manage.go
23820deleted file mode 100644
23821index 782dbd9..0000000
23822--- a/vendor/golang.org/x/sys/windows/svc/example/manage.go
23823+++ /dev/null
23824 @@ -1,62 +0,0 @@
23825- // Copyright 2012 The Go Authors. All rights reserved.
23826- // Use of this source code is governed by a BSD-style
23827- // license that can be found in the LICENSE file.
23828-
23829- // +build windows
23830-
23831- package main
23832-
23833- import (
23834- "fmt"
23835- "time"
23836-
23837- "golang.org/x/sys/windows/svc"
23838- "golang.org/x/sys/windows/svc/mgr"
23839- )
23840-
23841- func startService(name string) error {
23842- m, err := mgr.Connect()
23843- if err != nil {
23844- return err
23845- }
23846- defer m.Disconnect()
23847- s, err := m.OpenService(name)
23848- if err != nil {
23849- return fmt.Errorf("could not access service: %v", err)
23850- }
23851- defer s.Close()
23852- err = s.Start("is", "manual-started")
23853- if err != nil {
23854- return fmt.Errorf("could not start service: %v", err)
23855- }
23856- return nil
23857- }
23858-
23859- func controlService(name string, c svc.Cmd, to svc.State) error {
23860- m, err := mgr.Connect()
23861- if err != nil {
23862- return err
23863- }
23864- defer m.Disconnect()
23865- s, err := m.OpenService(name)
23866- if err != nil {
23867- return fmt.Errorf("could not access service: %v", err)
23868- }
23869- defer s.Close()
23870- status, err := s.Control(c)
23871- if err != nil {
23872- return fmt.Errorf("could not send control=%d: %v", c, err)
23873- }
23874- timeout := time.Now().Add(10 * time.Second)
23875- for status.State != to {
23876- if timeout.Before(time.Now()) {
23877- return fmt.Errorf("timeout waiting for service to go to state=%d", to)
23878- }
23879- time.Sleep(300 * time.Millisecond)
23880- status, err = s.Query()
23881- if err != nil {
23882- return fmt.Errorf("could not retrieve service status: %v", err)
23883- }
23884- }
23885- return nil
23886- }
23887 diff --git a/vendor/golang.org/x/sys/windows/svc/example/service.go b/vendor/golang.org/x/sys/windows/svc/example/service.go
23888deleted file mode 100644
23889index 237e809..0000000
23890--- a/vendor/golang.org/x/sys/windows/svc/example/service.go
23891+++ /dev/null
23892 @@ -1,82 +0,0 @@
23893- // Copyright 2012 The Go Authors. All rights reserved.
23894- // Use of this source code is governed by a BSD-style
23895- // license that can be found in the LICENSE file.
23896-
23897- // +build windows
23898-
23899- package main
23900-
23901- import (
23902- "fmt"
23903- "time"
23904-
23905- "golang.org/x/sys/windows/svc"
23906- "golang.org/x/sys/windows/svc/debug"
23907- "golang.org/x/sys/windows/svc/eventlog"
23908- )
23909-
23910- var elog debug.Log
23911-
23912- type myservice struct{}
23913-
23914- func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
23915- const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
23916- changes <- svc.Status{State: svc.StartPending}
23917- fasttick := time.Tick(500 * time.Millisecond)
23918- slowtick := time.Tick(2 * time.Second)
23919- tick := fasttick
23920- changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
23921- loop:
23922- for {
23923- select {
23924- case <-tick:
23925- beep()
23926- elog.Info(1, "beep")
23927- case c := <-r:
23928- switch c.Cmd {
23929- case svc.Interrogate:
23930- changes <- c.CurrentStatus
23931- // Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
23932- time.Sleep(100 * time.Millisecond)
23933- changes <- c.CurrentStatus
23934- case svc.Stop, svc.Shutdown:
23935- break loop
23936- case svc.Pause:
23937- changes <- svc.Status{State: svc.Paused, Accepts: cmdsAccepted}
23938- tick = slowtick
23939- case svc.Continue:
23940- changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
23941- tick = fasttick
23942- default:
23943- elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
23944- }
23945- }
23946- }
23947- changes <- svc.Status{State: svc.StopPending}
23948- return
23949- }
23950-
23951- func runService(name string, isDebug bool) {
23952- var err error
23953- if isDebug {
23954- elog = debug.New(name)
23955- } else {
23956- elog, err = eventlog.Open(name)
23957- if err != nil {
23958- return
23959- }
23960- }
23961- defer elog.Close()
23962-
23963- elog.Info(1, fmt.Sprintf("starting %s service", name))
23964- run := svc.Run
23965- if isDebug {
23966- run = debug.Run
23967- }
23968- err = run(name, &myservice{})
23969- if err != nil {
23970- elog.Error(1, fmt.Sprintf("%s service failed: %v", name, err))
23971- return
23972- }
23973- elog.Info(1, fmt.Sprintf("%s service stopped", name))
23974- }
23975 diff --git a/vendor/golang.org/x/sys/windows/svc/go12.c b/vendor/golang.org/x/sys/windows/svc/go12.c
23976deleted file mode 100644
23977index 6f1be1f..0000000
23978--- a/vendor/golang.org/x/sys/windows/svc/go12.c
23979+++ /dev/null
23980 @@ -1,24 +0,0 @@
23981- // Copyright 2012 The Go Authors. All rights reserved.
23982- // Use of this source code is governed by a BSD-style
23983- // license that can be found in the LICENSE file.
23984-
23985- // +build windows
23986- // +build !go1.3
23987-
23988- // copied from pkg/runtime
23989- typedef unsigned int uint32;
23990- typedef unsigned long long int uint64;
23991- #ifdef _64BIT
23992- typedef uint64 uintptr;
23993- #else
23994- typedef uint32 uintptr;
23995- #endif
23996-
23997- // from sys_386.s or sys_amd64.s
23998- void ·servicemain(void);
23999-
24000- void
24001- ·getServiceMain(uintptr *r)
24002- {
24003- *r = (uintptr)·servicemain;
24004- }
24005 diff --git a/vendor/golang.org/x/sys/windows/svc/go12.go b/vendor/golang.org/x/sys/windows/svc/go12.go
24006deleted file mode 100644
24007index cd8b913..0000000
24008--- a/vendor/golang.org/x/sys/windows/svc/go12.go
24009+++ /dev/null
24010 @@ -1,11 +0,0 @@
24011- // Copyright 2014 The Go Authors. All rights reserved.
24012- // Use of this source code is governed by a BSD-style
24013- // license that can be found in the LICENSE file.
24014-
24015- // +build windows
24016- // +build !go1.3
24017-
24018- package svc
24019-
24020- // from go12.c
24021- func getServiceMain(r *uintptr)
24022 diff --git a/vendor/golang.org/x/sys/windows/svc/go13.go b/vendor/golang.org/x/sys/windows/svc/go13.go
24023deleted file mode 100644
24024index 9d7f3ce..0000000
24025--- a/vendor/golang.org/x/sys/windows/svc/go13.go
24026+++ /dev/null
24027 @@ -1,31 +0,0 @@
24028- // Copyright 2014 The Go Authors. All rights reserved.
24029- // Use of this source code is governed by a BSD-style
24030- // license that can be found in the LICENSE file.
24031-
24032- // +build windows
24033- // +build go1.3
24034-
24035- package svc
24036-
24037- import "unsafe"
24038-
24039- const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
24040-
24041- // Should be a built-in for unsafe.Pointer?
24042- func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
24043- return unsafe.Pointer(uintptr(p) + x)
24044- }
24045-
24046- // funcPC returns the entry PC of the function f.
24047- // It assumes that f is a func value. Otherwise the behavior is undefined.
24048- func funcPC(f interface{}) uintptr {
24049- return **(**uintptr)(add(unsafe.Pointer(&f), ptrSize))
24050- }
24051-
24052- // from sys_386.s and sys_amd64.s
24053- func servicectlhandler(ctl uint32) uintptr
24054- func servicemain(argc uint32, argv **uint16)
24055-
24056- func getServiceMain(r *uintptr) {
24057- *r = funcPC(servicemain)
24058- }
24059 diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/config.go b/vendor/golang.org/x/sys/windows/svc/mgr/config.go
24060deleted file mode 100644
24061index 0a6edba..0000000
24062--- a/vendor/golang.org/x/sys/windows/svc/mgr/config.go
24063+++ /dev/null
24064 @@ -1,139 +0,0 @@
24065- // Copyright 2012 The Go Authors. All rights reserved.
24066- // Use of this source code is governed by a BSD-style
24067- // license that can be found in the LICENSE file.
24068-
24069- // +build windows
24070-
24071- package mgr
24072-
24073- import (
24074- "syscall"
24075- "unicode/utf16"
24076- "unsafe"
24077-
24078- "golang.org/x/sys/windows"
24079- )
24080-
24081- const (
24082- // Service start types.
24083- StartManual = windows.SERVICE_DEMAND_START // the service must be started manually
24084- StartAutomatic = windows.SERVICE_AUTO_START // the service will start by itself whenever the computer reboots
24085- StartDisabled = windows.SERVICE_DISABLED // the service cannot be started
24086-
24087- // The severity of the error, and action taken,
24088- // if this service fails to start.
24089- ErrorCritical = windows.SERVICE_ERROR_CRITICAL
24090- ErrorIgnore = windows.SERVICE_ERROR_IGNORE
24091- ErrorNormal = windows.SERVICE_ERROR_NORMAL
24092- ErrorSevere = windows.SERVICE_ERROR_SEVERE
24093- )
24094-
24095- // TODO(brainman): Password is not returned by windows.QueryServiceConfig, not sure how to get it.
24096-
24097- type Config struct {
24098- ServiceType uint32
24099- StartType uint32
24100- ErrorControl uint32
24101- BinaryPathName string // fully qualified path to the service binary file, can also include arguments for an auto-start service
24102- LoadOrderGroup string
24103- TagId uint32
24104- Dependencies []string
24105- ServiceStartName string // name of the account under which the service should run
24106- DisplayName string
24107- Password string
24108- Description string
24109- }
24110-
24111- func toString(p *uint16) string {
24112- if p == nil {
24113- return ""
24114- }
24115- return syscall.UTF16ToString((*[4096]uint16)(unsafe.Pointer(p))[:])
24116- }
24117-
24118- func toStringSlice(ps *uint16) []string {
24119- if ps == nil {
24120- return nil
24121- }
24122- r := make([]string, 0)
24123- for from, i, p := 0, 0, (*[1 << 24]uint16)(unsafe.Pointer(ps)); true; i++ {
24124- if p[i] == 0 {
24125- // empty string marks the end
24126- if i <= from {
24127- break
24128- }
24129- r = append(r, string(utf16.Decode(p[from:i])))
24130- from = i + 1
24131- }
24132- }
24133- return r
24134- }
24135-
24136- // Config retrieves service s configuration paramteres.
24137- func (s *Service) Config() (Config, error) {
24138- var p *windows.QUERY_SERVICE_CONFIG
24139- n := uint32(1024)
24140- for {
24141- b := make([]byte, n)
24142- p = (*windows.QUERY_SERVICE_CONFIG)(unsafe.Pointer(&b[0]))
24143- err := windows.QueryServiceConfig(s.Handle, p, n, &n)
24144- if err == nil {
24145- break
24146- }
24147- if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
24148- return Config{}, err
24149- }
24150- if n <= uint32(len(b)) {
24151- return Config{}, err
24152- }
24153- }
24154-
24155- var p2 *windows.SERVICE_DESCRIPTION
24156- n = uint32(1024)
24157- for {
24158- b := make([]byte, n)
24159- p2 = (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
24160- err := windows.QueryServiceConfig2(s.Handle,
24161- windows.SERVICE_CONFIG_DESCRIPTION, &b[0], n, &n)
24162- if err == nil {
24163- break
24164- }
24165- if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER {
24166- return Config{}, err
24167- }
24168- if n <= uint32(len(b)) {
24169- return Config{}, err
24170- }
24171- }
24172-
24173- return Config{
24174- ServiceType: p.ServiceType,
24175- StartType: p.StartType,
24176- ErrorControl: p.ErrorControl,
24177- BinaryPathName: toString(p.BinaryPathName),
24178- LoadOrderGroup: toString(p.LoadOrderGroup),
24179- TagId: p.TagId,
24180- Dependencies: toStringSlice(p.Dependencies),
24181- ServiceStartName: toString(p.ServiceStartName),
24182- DisplayName: toString(p.DisplayName),
24183- Description: toString(p2.Description),
24184- }, nil
24185- }
24186-
24187- func updateDescription(handle windows.Handle, desc string) error {
24188- d := windows.SERVICE_DESCRIPTION{toPtr(desc)}
24189- return windows.ChangeServiceConfig2(handle,
24190- windows.SERVICE_CONFIG_DESCRIPTION, (*byte)(unsafe.Pointer(&d)))
24191- }
24192-
24193- // UpdateConfig updates service s configuration parameters.
24194- func (s *Service) UpdateConfig(c Config) error {
24195- err := windows.ChangeServiceConfig(s.Handle, c.ServiceType, c.StartType,
24196- c.ErrorControl, toPtr(c.BinaryPathName), toPtr(c.LoadOrderGroup),
24197- nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName),
24198- toPtr(c.Password), toPtr(c.DisplayName))
24199- if err != nil {
24200- return err
24201- }
24202- return updateDescription(s.Handle, c.Description)
24203- }
24204 diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go b/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
24205deleted file mode 100644
24206index 76965b5..0000000
24207--- a/vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
24208+++ /dev/null
24209 @@ -1,162 +0,0 @@
24210- // Copyright 2012 The Go Authors. All rights reserved.
24211- // Use of this source code is governed by a BSD-style
24212- // license that can be found in the LICENSE file.
24213-
24214- // +build windows
24215-
24216- // Package mgr can be used to manage Windows service programs.
24217- // It can be used to install and remove them. It can also start,
24218- // stop and pause them. The package can query / change current
24219- // service state and config parameters.
24220- //
24221- package mgr
24222-
24223- import (
24224- "syscall"
24225- "unicode/utf16"
24226- "unsafe"
24227-
24228- "golang.org/x/sys/windows"
24229- )
24230-
24231- // Mgr is used to manage Windows service.
24232- type Mgr struct {
24233- Handle windows.Handle
24234- }
24235-
24236- // Connect establishes a connection to the service control manager.
24237- func Connect() (*Mgr, error) {
24238- return ConnectRemote("")
24239- }
24240-
24241- // ConnectRemote establishes a connection to the
24242- // service control manager on computer named host.
24243- func ConnectRemote(host string) (*Mgr, error) {
24244- var s *uint16
24245- if host != "" {
24246- s = syscall.StringToUTF16Ptr(host)
24247- }
24248- h, err := windows.OpenSCManager(s, nil, windows.SC_MANAGER_ALL_ACCESS)
24249- if err != nil {
24250- return nil, err
24251- }
24252- return &Mgr{Handle: h}, nil
24253- }
24254-
24255- // Disconnect closes connection to the service control manager m.
24256- func (m *Mgr) Disconnect() error {
24257- return windows.CloseServiceHandle(m.Handle)
24258- }
24259-
24260- func toPtr(s string) *uint16 {
24261- if len(s) == 0 {
24262- return nil
24263- }
24264- return syscall.StringToUTF16Ptr(s)
24265- }
24266-
24267- // toStringBlock terminates strings in ss with 0, and then
24268- // concatenates them together. It also adds extra 0 at the end.
24269- func toStringBlock(ss []string) *uint16 {
24270- if len(ss) == 0 {
24271- return nil
24272- }
24273- t := ""
24274- for _, s := range ss {
24275- if s != "" {
24276- t += s + "\x00"
24277- }
24278- }
24279- if t == "" {
24280- return nil
24281- }
24282- t += "\x00"
24283- return &utf16.Encode([]rune(t))[0]
24284- }
24285-
24286- // CreateService installs new service name on the system.
24287- // The service will be executed by running exepath binary.
24288- // Use config c to specify service parameters.
24289- // Any args will be passed as command-line arguments when
24290- // the service is started; these arguments are distinct from
24291- // the arguments passed to Service.Start or via the "Start
24292- // parameters" field in the service's Properties dialog box.
24293- func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Service, error) {
24294- if c.StartType == 0 {
24295- c.StartType = StartManual
24296- }
24297- if c.ErrorControl == 0 {
24298- c.ErrorControl = ErrorNormal
24299- }
24300- if c.ServiceType == 0 {
24301- c.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
24302- }
24303- s := syscall.EscapeArg(exepath)
24304- for _, v := range args {
24305- s += " " + syscall.EscapeArg(v)
24306- }
24307- h, err := windows.CreateService(m.Handle, toPtr(name), toPtr(c.DisplayName),
24308- windows.SERVICE_ALL_ACCESS, c.ServiceType,
24309- c.StartType, c.ErrorControl, toPtr(s), toPtr(c.LoadOrderGroup),
24310- nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), toPtr(c.Password))
24311- if err != nil {
24312- return nil, err
24313- }
24314- if c.Description != "" {
24315- err = updateDescription(h, c.Description)
24316- if err != nil {
24317- return nil, err
24318- }
24319- }
24320- return &Service{Name: name, Handle: h}, nil
24321- }
24322-
24323- // OpenService retrieves access to service name, so it can
24324- // be interrogated and controlled.
24325- func (m *Mgr) OpenService(name string) (*Service, error) {
24326- h, err := windows.OpenService(m.Handle, syscall.StringToUTF16Ptr(name), windows.SERVICE_ALL_ACCESS)
24327- if err != nil {
24328- return nil, err
24329- }
24330- return &Service{Name: name, Handle: h}, nil
24331- }
24332-
24333- // ListServices enumerates services in the specified
24334- // service control manager database m.
24335- // If the caller does not have the SERVICE_QUERY_STATUS
24336- // access right to a service, the service is silently
24337- // omitted from the list of services returned.
24338- func (m *Mgr) ListServices() ([]string, error) {
24339- var err error
24340- var bytesNeeded, servicesReturned uint32
24341- var buf []byte
24342- for {
24343- var p *byte
24344- if len(buf) > 0 {
24345- p = &buf[0]
24346- }
24347- err = windows.EnumServicesStatusEx(m.Handle, windows.SC_ENUM_PROCESS_INFO,
24348- windows.SERVICE_WIN32, windows.SERVICE_STATE_ALL,
24349- p, uint32(len(buf)), &bytesNeeded, &servicesReturned, nil, nil)
24350- if err == nil {
24351- break
24352- }
24353- if err != syscall.ERROR_MORE_DATA {
24354- return nil, err
24355- }
24356- if bytesNeeded <= uint32(len(buf)) {
24357- return nil, err
24358- }
24359- buf = make([]byte, bytesNeeded)
24360- }
24361- if servicesReturned == 0 {
24362- return nil, nil
24363- }
24364- services := (*[1 << 20]windows.ENUM_SERVICE_STATUS_PROCESS)(unsafe.Pointer(&buf[0]))[:servicesReturned]
24365- var names []string
24366- for _, s := range services {
24367- name := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(s.ServiceName))[:])
24368- names = append(names, name)
24369- }
24370- return names, nil
24371- }
24372 diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go b/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go
24373deleted file mode 100644
24374index 1569a22..0000000
24375--- a/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go
24376+++ /dev/null
24377 @@ -1,169 +0,0 @@
24378- // Copyright 2012 The Go Authors. All rights reserved.
24379- // Use of this source code is governed by a BSD-style
24380- // license that can be found in the LICENSE file.
24381-
24382- // +build windows
24383-
24384- package mgr_test
24385-
24386- import (
24387- "os"
24388- "path/filepath"
24389- "sort"
24390- "strings"
24391- "syscall"
24392- "testing"
24393- "time"
24394-
24395- "golang.org/x/sys/windows/svc/mgr"
24396- )
24397-
24398- func TestOpenLanManServer(t *testing.T) {
24399- m, err := mgr.Connect()
24400- if err != nil {
24401- if errno, ok := err.(syscall.Errno); ok && errno == syscall.ERROR_ACCESS_DENIED {
24402- t.Skip("Skipping test: we don't have rights to manage services.")
24403- }
24404- t.Fatalf("SCM connection failed: %s", err)
24405- }
24406- defer m.Disconnect()
24407-
24408- s, err := m.OpenService("LanmanServer")
24409- if err != nil {
24410- t.Fatalf("OpenService(lanmanserver) failed: %s", err)
24411- }
24412- defer s.Close()
24413-
24414- _, err = s.Config()
24415- if err != nil {
24416- t.Fatalf("Config failed: %s", err)
24417- }
24418- }
24419-
24420- func install(t *testing.T, m *mgr.Mgr, name, exepath string, c mgr.Config) {
24421- // Sometimes it takes a while for the service to get
24422- // removed after previous test run.
24423- for i := 0; ; i++ {
24424- s, err := m.OpenService(name)
24425- if err != nil {
24426- break
24427- }
24428- s.Close()
24429-
24430- if i > 10 {
24431- t.Fatalf("service %s already exists", name)
24432- }
24433- time.Sleep(300 * time.Millisecond)
24434- }
24435-
24436- s, err := m.CreateService(name, exepath, c)
24437- if err != nil {
24438- t.Fatalf("CreateService(%s) failed: %v", name, err)
24439- }
24440- defer s.Close()
24441- }
24442-
24443- func depString(d []string) string {
24444- if len(d) == 0 {
24445- return ""
24446- }
24447- for i := range d {
24448- d[i] = strings.ToLower(d[i])
24449- }
24450- ss := sort.StringSlice(d)
24451- ss.Sort()
24452- return strings.Join([]string(ss), " ")
24453- }
24454-
24455- func testConfig(t *testing.T, s *mgr.Service, should mgr.Config) mgr.Config {
24456- is, err := s.Config()
24457- if err != nil {
24458- t.Fatalf("Config failed: %s", err)
24459- }
24460- if should.DisplayName != is.DisplayName {
24461- t.Fatalf("config mismatch: DisplayName is %q, but should have %q", is.DisplayName, should.DisplayName)
24462- }
24463- if should.StartType != is.StartType {
24464- t.Fatalf("config mismatch: StartType is %v, but should have %v", is.StartType, should.StartType)
24465- }
24466- if should.Description != is.Description {
24467- t.Fatalf("config mismatch: Description is %q, but should have %q", is.Description, should.Description)
24468- }
24469- if depString(should.Dependencies) != depString(is.Dependencies) {
24470- t.Fatalf("config mismatch: Dependencies is %v, but should have %v", is.Dependencies, should.Dependencies)
24471- }
24472- return is
24473- }
24474-
24475- func remove(t *testing.T, s *mgr.Service) {
24476- err := s.Delete()
24477- if err != nil {
24478- t.Fatalf("Delete failed: %s", err)
24479- }
24480- }
24481-
24482- func TestMyService(t *testing.T) {
24483- if testing.Short() {
24484- t.Skip("skipping test in short mode - it modifies system services")
24485- }
24486-
24487- const name = "myservice"
24488-
24489- m, err := mgr.Connect()
24490- if err != nil {
24491- if errno, ok := err.(syscall.Errno); ok && errno == syscall.ERROR_ACCESS_DENIED {
24492- t.Skip("Skipping test: we don't have rights to manage services.")
24493- }
24494- t.Fatalf("SCM connection failed: %s", err)
24495- }
24496- defer m.Disconnect()
24497-
24498- c := mgr.Config{
24499- StartType: mgr.StartDisabled,
24500- DisplayName: "my service",
24501- Description: "my service is just a test",
24502- Dependencies: []string{"LanmanServer", "W32Time"},
24503- }
24504-
24505- exename := os.Args[0]
24506- exepath, err := filepath.Abs(exename)
24507- if err != nil {
24508- t.Fatalf("filepath.Abs(%s) failed: %s", exename, err)
24509- }
24510-
24511- install(t, m, name, exepath, c)
24512-
24513- s, err := m.OpenService(name)
24514- if err != nil {
24515- t.Fatalf("service %s is not installed", name)
24516- }
24517- defer s.Close()
24518-
24519- c.BinaryPathName = exepath
24520- c = testConfig(t, s, c)
24521-
24522- c.StartType = mgr.StartManual
24523- err = s.UpdateConfig(c)
24524- if err != nil {
24525- t.Fatalf("UpdateConfig failed: %v", err)
24526- }
24527-
24528- testConfig(t, s, c)
24529-
24530- svcnames, err := m.ListServices()
24531- if err != nil {
24532- t.Fatalf("ListServices failed: %v", err)
24533- }
24534- var myserviceIsInstalled bool
24535- for _, sn := range svcnames {
24536- if sn == name {
24537- myserviceIsInstalled = true
24538- break
24539- }
24540- }
24541- if !myserviceIsInstalled {
24542- t.Errorf("ListServices failed to find %q service", name)
24543- }
24544-
24545- remove(t, s)
24546- }
24547 diff --git a/vendor/golang.org/x/sys/windows/svc/mgr/service.go b/vendor/golang.org/x/sys/windows/svc/mgr/service.go
24548deleted file mode 100644
24549index fdc46af..0000000
24550--- a/vendor/golang.org/x/sys/windows/svc/mgr/service.go
24551+++ /dev/null
24552 @@ -1,72 +0,0 @@
24553- // Copyright 2012 The Go Authors. All rights reserved.
24554- // Use of this source code is governed by a BSD-style
24555- // license that can be found in the LICENSE file.
24556-
24557- // +build windows
24558-
24559- package mgr
24560-
24561- import (
24562- "syscall"
24563-
24564- "golang.org/x/sys/windows"
24565- "golang.org/x/sys/windows/svc"
24566- )
24567-
24568- // TODO(brainman): Use EnumDependentServices to enumerate dependent services.
24569-
24570- // Service is used to access Windows service.
24571- type Service struct {
24572- Name string
24573- Handle windows.Handle
24574- }
24575-
24576- // Delete marks service s for deletion from the service control manager database.
24577- func (s *Service) Delete() error {
24578- return windows.DeleteService(s.Handle)
24579- }
24580-
24581- // Close relinquish access to the service s.
24582- func (s *Service) Close() error {
24583- return windows.CloseServiceHandle(s.Handle)
24584- }
24585-
24586- // Start starts service s.
24587- // args will be passed to svc.Handler.Execute.
24588- func (s *Service) Start(args ...string) error {
24589- var p **uint16
24590- if len(args) > 0 {
24591- vs := make([]*uint16, len(args))
24592- for i := range vs {
24593- vs[i] = syscall.StringToUTF16Ptr(args[i])
24594- }
24595- p = &vs[0]
24596- }
24597- return windows.StartService(s.Handle, uint32(len(args)), p)
24598- }
24599-
24600- // Control sends state change request c to the servce s.
24601- func (s *Service) Control(c svc.Cmd) (svc.Status, error) {
24602- var t windows.SERVICE_STATUS
24603- err := windows.ControlService(s.Handle, uint32(c), &t)
24604- if err != nil {
24605- return svc.Status{}, err
24606- }
24607- return svc.Status{
24608- State: svc.State(t.CurrentState),
24609- Accepts: svc.Accepted(t.ControlsAccepted),
24610- }, nil
24611- }
24612-
24613- // Query returns current status of service s.
24614- func (s *Service) Query() (svc.Status, error) {
24615- var t windows.SERVICE_STATUS
24616- err := windows.QueryServiceStatus(s.Handle, &t)
24617- if err != nil {
24618- return svc.Status{}, err
24619- }
24620- return svc.Status{
24621- State: svc.State(t.CurrentState),
24622- Accepts: svc.Accepted(t.ControlsAccepted),
24623- }, nil
24624- }
24625 diff --git a/vendor/golang.org/x/sys/windows/svc/security.go b/vendor/golang.org/x/sys/windows/svc/security.go
24626deleted file mode 100644
24627index 6fbc923..0000000
24628--- a/vendor/golang.org/x/sys/windows/svc/security.go
24629+++ /dev/null
24630 @@ -1,62 +0,0 @@
24631- // Copyright 2012 The Go Authors. All rights reserved.
24632- // Use of this source code is governed by a BSD-style
24633- // license that can be found in the LICENSE file.
24634-
24635- // +build windows
24636-
24637- package svc
24638-
24639- import (
24640- "unsafe"
24641-
24642- "golang.org/x/sys/windows"
24643- )
24644-
24645- func allocSid(subAuth0 uint32) (*windows.SID, error) {
24646- var sid *windows.SID
24647- err := windows.AllocateAndInitializeSid(&windows.SECURITY_NT_AUTHORITY,
24648- 1, subAuth0, 0, 0, 0, 0, 0, 0, 0, &sid)
24649- if err != nil {
24650- return nil, err
24651- }
24652- return sid, nil
24653- }
24654-
24655- // IsAnInteractiveSession determines if calling process is running interactively.
24656- // It queries the process token for membership in the Interactive group.
24657- // http://stackoverflow.com/questions/2668851/how-do-i-detect-that-my-application-is-running-as-service-or-in-an-interactive-s
24658- func IsAnInteractiveSession() (bool, error) {
24659- interSid, err := allocSid(windows.SECURITY_INTERACTIVE_RID)
24660- if err != nil {
24661- return false, err
24662- }
24663- defer windows.FreeSid(interSid)
24664-
24665- serviceSid, err := allocSid(windows.SECURITY_SERVICE_RID)
24666- if err != nil {
24667- return false, err
24668- }
24669- defer windows.FreeSid(serviceSid)
24670-
24671- t, err := windows.OpenCurrentProcessToken()
24672- if err != nil {
24673- return false, err
24674- }
24675- defer t.Close()
24676-
24677- gs, err := t.GetTokenGroups()
24678- if err != nil {
24679- return false, err
24680- }
24681- p := unsafe.Pointer(&gs.Groups[0])
24682- groups := (*[2 << 20]windows.SIDAndAttributes)(p)[:gs.GroupCount]
24683- for _, g := range groups {
24684- if windows.EqualSid(g.Sid, interSid) {
24685- return true, nil
24686- }
24687- if windows.EqualSid(g.Sid, serviceSid) {
24688- return false, nil
24689- }
24690- }
24691- return false, nil
24692- }
24693 diff --git a/vendor/golang.org/x/sys/windows/svc/service.go b/vendor/golang.org/x/sys/windows/svc/service.go
24694deleted file mode 100644
24695index 903cba3..0000000
24696--- a/vendor/golang.org/x/sys/windows/svc/service.go
24697+++ /dev/null
24698 @@ -1,363 +0,0 @@
24699- // Copyright 2012 The Go Authors. All rights reserved.
24700- // Use of this source code is governed by a BSD-style
24701- // license that can be found in the LICENSE file.
24702-
24703- // +build windows
24704-
24705- // Package svc provides everything required to build Windows service.
24706- //
24707- package svc
24708-
24709- import (
24710- "errors"
24711- "runtime"
24712- "syscall"
24713- "unsafe"
24714-
24715- "golang.org/x/sys/windows"
24716- )
24717-
24718- // State describes service execution state (Stopped, Running and so on).
24719- type State uint32
24720-
24721- const (
24722- Stopped = State(windows.SERVICE_STOPPED)
24723- StartPending = State(windows.SERVICE_START_PENDING)
24724- StopPending = State(windows.SERVICE_STOP_PENDING)
24725- Running = State(windows.SERVICE_RUNNING)
24726- ContinuePending = State(windows.SERVICE_CONTINUE_PENDING)
24727- PausePending = State(windows.SERVICE_PAUSE_PENDING)
24728- Paused = State(windows.SERVICE_PAUSED)
24729- )
24730-
24731- // Cmd represents service state change request. It is sent to a service
24732- // by the service manager, and should be actioned upon by the service.
24733- type Cmd uint32
24734-
24735- const (
24736- Stop = Cmd(windows.SERVICE_CONTROL_STOP)
24737- Pause = Cmd(windows.SERVICE_CONTROL_PAUSE)
24738- Continue = Cmd(windows.SERVICE_CONTROL_CONTINUE)
24739- Interrogate = Cmd(windows.SERVICE_CONTROL_INTERROGATE)
24740- Shutdown = Cmd(windows.SERVICE_CONTROL_SHUTDOWN)
24741- ParamChange = Cmd(windows.SERVICE_CONTROL_PARAMCHANGE)
24742- NetBindAdd = Cmd(windows.SERVICE_CONTROL_NETBINDADD)
24743- NetBindRemove = Cmd(windows.SERVICE_CONTROL_NETBINDREMOVE)
24744- NetBindEnable = Cmd(windows.SERVICE_CONTROL_NETBINDENABLE)
24745- NetBindDisable = Cmd(windows.SERVICE_CONTROL_NETBINDDISABLE)
24746- DeviceEvent = Cmd(windows.SERVICE_CONTROL_DEVICEEVENT)
24747- HardwareProfileChange = Cmd(windows.SERVICE_CONTROL_HARDWAREPROFILECHANGE)
24748- PowerEvent = Cmd(windows.SERVICE_CONTROL_POWEREVENT)
24749- SessionChange = Cmd(windows.SERVICE_CONTROL_SESSIONCHANGE)
24750- )
24751-
24752- // Accepted is used to describe commands accepted by the service.
24753- // Note that Interrogate is always accepted.
24754- type Accepted uint32
24755-
24756- const (
24757- AcceptStop = Accepted(windows.SERVICE_ACCEPT_STOP)
24758- AcceptShutdown = Accepted(windows.SERVICE_ACCEPT_SHUTDOWN)
24759- AcceptPauseAndContinue = Accepted(windows.SERVICE_ACCEPT_PAUSE_CONTINUE)
24760- AcceptParamChange = Accepted(windows.SERVICE_ACCEPT_PARAMCHANGE)
24761- AcceptNetBindChange = Accepted(windows.SERVICE_ACCEPT_NETBINDCHANGE)
24762- AcceptHardwareProfileChange = Accepted(windows.SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
24763- AcceptPowerEvent = Accepted(windows.SERVICE_ACCEPT_POWEREVENT)
24764- AcceptSessionChange = Accepted(windows.SERVICE_ACCEPT_SESSIONCHANGE)
24765- )
24766-
24767- // Status combines State and Accepted commands to fully describe running service.
24768- type Status struct {
24769- State State
24770- Accepts Accepted
24771- CheckPoint uint32 // used to report progress during a lengthy operation
24772- WaitHint uint32 // estimated time required for a pending operation, in milliseconds
24773- }
24774-
24775- // ChangeRequest is sent to the service Handler to request service status change.
24776- type ChangeRequest struct {
24777- Cmd Cmd
24778- EventType uint32
24779- EventData uintptr
24780- CurrentStatus Status
24781- }
24782-
24783- // Handler is the interface that must be implemented to build Windows service.
24784- type Handler interface {
24785-
24786- // Execute will be called by the package code at the start of
24787- // the service, and the service will exit once Execute completes.
24788- // Inside Execute you must read service change requests from r and
24789- // act accordingly. You must keep service control manager up to date
24790- // about state of your service by writing into s as required.
24791- // args contains service name followed by argument strings passed
24792- // to the service.
24793- // You can provide service exit code in exitCode return parameter,
24794- // with 0 being "no error". You can also indicate if exit code,
24795- // if any, is service specific or not by using svcSpecificEC
24796- // parameter.
24797- Execute(args []string, r <-chan ChangeRequest, s chan<- Status) (svcSpecificEC bool, exitCode uint32)
24798- }
24799-
24800- var (
24801- // These are used by asm code.
24802- goWaitsH uintptr
24803- cWaitsH uintptr
24804- ssHandle uintptr
24805- sName *uint16
24806- sArgc uintptr
24807- sArgv **uint16
24808- ctlHandlerExProc uintptr
24809- cSetEvent uintptr
24810- cWaitForSingleObject uintptr
24811- cRegisterServiceCtrlHandlerExW uintptr
24812- )
24813-
24814- func init() {
24815- k := syscall.MustLoadDLL("kernel32.dll")
24816- cSetEvent = k.MustFindProc("SetEvent").Addr()
24817- cWaitForSingleObject = k.MustFindProc("WaitForSingleObject").Addr()
24818- a := syscall.MustLoadDLL("advapi32.dll")
24819- cRegisterServiceCtrlHandlerExW = a.MustFindProc("RegisterServiceCtrlHandlerExW").Addr()
24820- }
24821-
24822- // The HandlerEx prototype also has a context pointer but since we don't use
24823- // it at start-up time we don't have to pass it over either.
24824- type ctlEvent struct {
24825- cmd Cmd
24826- eventType uint32
24827- eventData uintptr
24828- errno uint32
24829- }
24830-
24831- // service provides access to windows service api.
24832- type service struct {
24833- name string
24834- h windows.Handle
24835- cWaits *event
24836- goWaits *event
24837- c chan ctlEvent
24838- handler Handler
24839- }
24840-
24841- func newService(name string, handler Handler) (*service, error) {
24842- var s service
24843- var err error
24844- s.name = name
24845- s.c = make(chan ctlEvent)
24846- s.handler = handler
24847- s.cWaits, err = newEvent()
24848- if err != nil {
24849- return nil, err
24850- }
24851- s.goWaits, err = newEvent()
24852- if err != nil {
24853- s.cWaits.Close()
24854- return nil, err
24855- }
24856- return &s, nil
24857- }
24858-
24859- func (s *service) close() error {
24860- s.cWaits.Close()
24861- s.goWaits.Close()
24862- return nil
24863- }
24864-
24865- type exitCode struct {
24866- isSvcSpecific bool
24867- errno uint32
24868- }
24869-
24870- func (s *service) updateStatus(status *Status, ec *exitCode) error {
24871- if s.h == 0 {
24872- return errors.New("updateStatus with no service status handle")
24873- }
24874- var t windows.SERVICE_STATUS
24875- t.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
24876- t.CurrentState = uint32(status.State)
24877- if status.Accepts&AcceptStop != 0 {
24878- t.ControlsAccepted |= windows.SERVICE_ACCEPT_STOP
24879- }
24880- if status.Accepts&AcceptShutdown != 0 {
24881- t.ControlsAccepted |= windows.SERVICE_ACCEPT_SHUTDOWN
24882- }
24883- if status.Accepts&AcceptPauseAndContinue != 0 {
24884- t.ControlsAccepted |= windows.SERVICE_ACCEPT_PAUSE_CONTINUE
24885- }
24886- if status.Accepts&AcceptParamChange != 0 {
24887- t.ControlsAccepted |= windows.SERVICE_ACCEPT_PARAMCHANGE
24888- }
24889- if status.Accepts&AcceptNetBindChange != 0 {
24890- t.ControlsAccepted |= windows.SERVICE_ACCEPT_NETBINDCHANGE
24891- }
24892- if status.Accepts&AcceptHardwareProfileChange != 0 {
24893- t.ControlsAccepted |= windows.SERVICE_ACCEPT_HARDWAREPROFILECHANGE
24894- }
24895- if status.Accepts&AcceptPowerEvent != 0 {
24896- t.ControlsAccepted |= windows.SERVICE_ACCEPT_POWEREVENT
24897- }
24898- if status.Accepts&AcceptSessionChange != 0 {
24899- t.ControlsAccepted |= windows.SERVICE_ACCEPT_SESSIONCHANGE
24900- }
24901- if ec.errno == 0 {
24902- t.Win32ExitCode = windows.NO_ERROR
24903- t.ServiceSpecificExitCode = windows.NO_ERROR
24904- } else if ec.isSvcSpecific {
24905- t.Win32ExitCode = uint32(windows.ERROR_SERVICE_SPECIFIC_ERROR)
24906- t.ServiceSpecificExitCode = ec.errno
24907- } else {
24908- t.Win32ExitCode = ec.errno
24909- t.ServiceSpecificExitCode = windows.NO_ERROR
24910- }
24911- t.CheckPoint = status.CheckPoint
24912- t.WaitHint = status.WaitHint
24913- return windows.SetServiceStatus(s.h, &t)
24914- }
24915-
24916- const (
24917- sysErrSetServiceStatusFailed = uint32(syscall.APPLICATION_ERROR) + iota
24918- sysErrNewThreadInCallback
24919- )
24920-
24921- func (s *service) run() {
24922- s.goWaits.Wait()
24923- s.h = windows.Handle(ssHandle)
24924- argv := (*[100]*int16)(unsafe.Pointer(sArgv))[:sArgc]
24925- args := make([]string, len(argv))
24926- for i, a := range argv {
24927- args[i] = syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(a))[:])
24928- }
24929-
24930- cmdsToHandler := make(chan ChangeRequest)
24931- changesFromHandler := make(chan Status)
24932- exitFromHandler := make(chan exitCode)
24933-
24934- go func() {
24935- ss, errno := s.handler.Execute(args, cmdsToHandler, changesFromHandler)
24936- exitFromHandler <- exitCode{ss, errno}
24937- }()
24938-
24939- status := Status{State: Stopped}
24940- ec := exitCode{isSvcSpecific: true, errno: 0}
24941- var outch chan ChangeRequest
24942- inch := s.c
24943- var cmd Cmd
24944- var evtype uint32
24945- var evdata uintptr
24946- loop:
24947- for {
24948- select {
24949- case r := <-inch:
24950- if r.errno != 0 {
24951- ec.errno = r.errno
24952- break loop
24953- }
24954- inch = nil
24955- outch = cmdsToHandler
24956- cmd = r.cmd
24957- evtype = r.eventType
24958- evdata = r.eventData
24959- case outch <- ChangeRequest{cmd, evtype, evdata, status}:
24960- inch = s.c
24961- outch = nil
24962- case c := <-changesFromHandler:
24963- err := s.updateStatus(&c, &ec)
24964- if err != nil {
24965- // best suitable error number
24966- ec.errno = sysErrSetServiceStatusFailed
24967- if err2, ok := err.(syscall.Errno); ok {
24968- ec.errno = uint32(err2)
24969- }
24970- break loop
24971- }
24972- status = c
24973- case ec = <-exitFromHandler:
24974- break loop
24975- }
24976- }
24977-
24978- s.updateStatus(&Status{State: Stopped}, &ec)
24979- s.cWaits.Set()
24980- }
24981-
24982- func newCallback(fn interface{}) (cb uintptr, err error) {
24983- defer func() {
24984- r := recover()
24985- if r == nil {
24986- return
24987- }
24988- cb = 0
24989- switch v := r.(type) {
24990- case string:
24991- err = errors.New(v)
24992- case error:
24993- err = v
24994- default:
24995- err = errors.New("unexpected panic in syscall.NewCallback")
24996- }
24997- }()
24998- return syscall.NewCallback(fn), nil
24999- }
25000-
25001- // BUG(brainman): There is no mechanism to run multiple services
25002- // inside one single executable. Perhaps, it can be overcome by
25003- // using RegisterServiceCtrlHandlerEx Windows api.
25004-
25005- // Run executes service name by calling appropriate handler function.
25006- func Run(name string, handler Handler) error {
25007- runtime.LockOSThread()
25008-
25009- tid := windows.GetCurrentThreadId()
25010-
25011- s, err := newService(name, handler)
25012- if err != nil {
25013- return err
25014- }
25015-
25016- ctlHandler := func(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr {
25017- e := ctlEvent{cmd: Cmd(ctl), eventType: evtype, eventData: evdata}
25018- // We assume that this callback function is running on
25019- // the same thread as Run. Nowhere in MS documentation
25020- // I could find statement to guarantee that. So putting
25021- // check here to verify, otherwise things will go bad
25022- // quickly, if ignored.
25023- i := windows.GetCurrentThreadId()
25024- if i != tid {
25025- e.errno = sysErrNewThreadInCallback
25026- }
25027- s.c <- e
25028- // Always return NO_ERROR (0) for now.
25029- return 0
25030- }
25031-
25032- var svcmain uintptr
25033- getServiceMain(&svcmain)
25034- t := []windows.SERVICE_TABLE_ENTRY{
25035- {syscall.StringToUTF16Ptr(s.name), svcmain},
25036- {nil, 0},
25037- }
25038-
25039- goWaitsH = uintptr(s.goWaits.h)
25040- cWaitsH = uintptr(s.cWaits.h)
25041- sName = t[0].ServiceName
25042- ctlHandlerExProc, err = newCallback(ctlHandler)
25043- if err != nil {
25044- return err
25045- }
25046-
25047- go s.run()
25048-
25049- err = windows.StartServiceCtrlDispatcher(&t[0])
25050- if err != nil {
25051- return err
25052- }
25053- return nil
25054- }
25055-
25056- // StatusHandle returns service status handle. It is safe to call this function
25057- // from inside the Handler.Execute because then it is guaranteed to be set.
25058- // This code will have to change once multiple services are possible per process.
25059- func StatusHandle() windows.Handle {
25060- return windows.Handle(ssHandle)
25061- }
25062 diff --git a/vendor/golang.org/x/sys/windows/svc/svc_test.go b/vendor/golang.org/x/sys/windows/svc/svc_test.go
25063deleted file mode 100644
25064index da7ec66..0000000
25065--- a/vendor/golang.org/x/sys/windows/svc/svc_test.go
25066+++ /dev/null
25067 @@ -1,118 +0,0 @@
25068- // Copyright 2012 The Go Authors. All rights reserved.
25069- // Use of this source code is governed by a BSD-style
25070- // license that can be found in the LICENSE file.
25071-
25072- // +build windows
25073-
25074- package svc_test
25075-
25076- import (
25077- "io/ioutil"
25078- "os"
25079- "os/exec"
25080- "path/filepath"
25081- "testing"
25082- "time"
25083-
25084- "golang.org/x/sys/windows/svc"
25085- "golang.org/x/sys/windows/svc/mgr"
25086- )
25087-
25088- func getState(t *testing.T, s *mgr.Service) svc.State {
25089- status, err := s.Query()
25090- if err != nil {
25091- t.Fatalf("Query(%s) failed: %s", s.Name, err)
25092- }
25093- return status.State
25094- }
25095-
25096- func testState(t *testing.T, s *mgr.Service, want svc.State) {
25097- have := getState(t, s)
25098- if have != want {
25099- t.Fatalf("%s state is=%d want=%d", s.Name, have, want)
25100- }
25101- }
25102-
25103- func waitState(t *testing.T, s *mgr.Service, want svc.State) {
25104- for i := 0; ; i++ {
25105- have := getState(t, s)
25106- if have == want {
25107- return
25108- }
25109- if i > 10 {
25110- t.Fatalf("%s state is=%d, waiting timeout", s.Name, have)
25111- }
25112- time.Sleep(300 * time.Millisecond)
25113- }
25114- }
25115-
25116- func TestExample(t *testing.T) {
25117- if testing.Short() {
25118- t.Skip("skipping test in short mode - it modifies system services")
25119- }
25120-
25121- const name = "myservice"
25122-
25123- m, err := mgr.Connect()
25124- if err != nil {
25125- t.Fatalf("SCM connection failed: %s", err)
25126- }
25127- defer m.Disconnect()
25128-
25129- dir, err := ioutil.TempDir("", "svc")
25130- if err != nil {
25131- t.Fatalf("failed to create temp directory: %v", err)
25132- }
25133- defer os.RemoveAll(dir)
25134-
25135- exepath := filepath.Join(dir, "a.exe")
25136- o, err := exec.Command("go", "build", "-o", exepath, "golang.org/x/sys/windows/svc/example").CombinedOutput()
25137- if err != nil {
25138- t.Fatalf("failed to build service program: %v\n%v", err, string(o))
25139- }
25140-
25141- s, err := m.OpenService(name)
25142- if err == nil {
25143- err = s.Delete()
25144- if err != nil {
25145- s.Close()
25146- t.Fatalf("Delete failed: %s", err)
25147- }
25148- s.Close()
25149- }
25150- s, err = m.CreateService(name, exepath, mgr.Config{DisplayName: "my service"}, "is", "auto-started")
25151- if err != nil {
25152- t.Fatalf("CreateService(%s) failed: %v", name, err)
25153- }
25154- defer s.Close()
25155-
25156- testState(t, s, svc.Stopped)
25157- err = s.Start("is", "manual-started")
25158- if err != nil {
25159- t.Fatalf("Start(%s) failed: %s", s.Name, err)
25160- }
25161- waitState(t, s, svc.Running)
25162- time.Sleep(1 * time.Second)
25163-
25164- // testing deadlock from issues 4.
25165- _, err = s.Control(svc.Interrogate)
25166- if err != nil {
25167- t.Fatalf("Control(%s) failed: %s", s.Name, err)
25168- }
25169- _, err = s.Control(svc.Interrogate)
25170- if err != nil {
25171- t.Fatalf("Control(%s) failed: %s", s.Name, err)
25172- }
25173- time.Sleep(1 * time.Second)
25174-
25175- _, err = s.Control(svc.Stop)
25176- if err != nil {
25177- t.Fatalf("Control(%s) failed: %s", s.Name, err)
25178- }
25179- waitState(t, s, svc.Stopped)
25180-
25181- err = s.Delete()
25182- if err != nil {
25183- t.Fatalf("Delete failed: %s", err)
25184- }
25185- }
25186 diff --git a/vendor/golang.org/x/sys/windows/svc/sys_386.s b/vendor/golang.org/x/sys/windows/svc/sys_386.s
25187deleted file mode 100644
25188index 2c82a9d..0000000
25189--- a/vendor/golang.org/x/sys/windows/svc/sys_386.s
25190+++ /dev/null
25191 @@ -1,68 +0,0 @@
25192- // Copyright 2012 The Go Authors. All rights reserved.
25193- // Use of this source code is governed by a BSD-style
25194- // license that can be found in the LICENSE file.
25195-
25196- // +build windows
25197-
25198- // func servicemain(argc uint32, argv **uint16)
25199- TEXT ·servicemain(SB),7,$0
25200- MOVL argc+0(FP), AX
25201- MOVL AX, ·sArgc(SB)
25202- MOVL argv+4(FP), AX
25203- MOVL AX, ·sArgv(SB)
25204-
25205- PUSHL BP
25206- PUSHL BX
25207- PUSHL SI
25208- PUSHL DI
25209-
25210- SUBL $12, SP
25211-
25212- MOVL ·sName(SB), AX
25213- MOVL AX, (SP)
25214- MOVL $·servicectlhandler(SB), AX
25215- MOVL AX, 4(SP)
25216- MOVL $0, 8(SP)
25217- MOVL ·cRegisterServiceCtrlHandlerExW(SB), AX
25218- MOVL SP, BP
25219- CALL AX
25220- MOVL BP, SP
25221- CMPL AX, $0
25222- JE exit
25223- MOVL AX, ·ssHandle(SB)
25224-
25225- MOVL ·goWaitsH(SB), AX
25226- MOVL AX, (SP)
25227- MOVL ·cSetEvent(SB), AX
25228- MOVL SP, BP
25229- CALL AX
25230- MOVL BP, SP
25231-
25232- MOVL ·cWaitsH(SB), AX
25233- MOVL AX, (SP)
25234- MOVL $-1, AX
25235- MOVL AX, 4(SP)
25236- MOVL ·cWaitForSingleObject(SB), AX
25237- MOVL SP, BP
25238- CALL AX
25239- MOVL BP, SP
25240-
25241- exit:
25242- ADDL $12, SP
25243-
25244- POPL DI
25245- POPL SI
25246- POPL BX
25247- POPL BP
25248-
25249- MOVL 0(SP), CX
25250- ADDL $12, SP
25251- JMP CX
25252-
25253- // I do not know why, but this seems to be the only way to call
25254- // ctlHandlerProc on Windows 7.
25255-
25256- // func servicectlhandler(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr {
25257- TEXT ·servicectlhandler(SB),7,$0
25258- MOVL ·ctlHandlerExProc(SB), CX
25259- JMP CX
25260 diff --git a/vendor/golang.org/x/sys/windows/svc/sys_amd64.s b/vendor/golang.org/x/sys/windows/svc/sys_amd64.s
25261deleted file mode 100644
25262index 06b4259..0000000
25263--- a/vendor/golang.org/x/sys/windows/svc/sys_amd64.s
25264+++ /dev/null
25265 @@ -1,42 +0,0 @@
25266- // Copyright 2012 The Go Authors. All rights reserved.
25267- // Use of this source code is governed by a BSD-style
25268- // license that can be found in the LICENSE file.
25269-
25270- // +build windows
25271-
25272- // func servicemain(argc uint32, argv **uint16)
25273- TEXT ·servicemain(SB),7,$0
25274- MOVL CX, ·sArgc(SB)
25275- MOVL DX, ·sArgv(SB)
25276-
25277- SUBQ $32, SP // stack for the first 4 syscall params
25278-
25279- MOVQ ·sName(SB), CX
25280- MOVQ $·servicectlhandler(SB), DX
25281- // BUG(pastarmovj): Figure out a way to pass in context in R8.
25282- MOVQ ·cRegisterServiceCtrlHandlerExW(SB), AX
25283- CALL AX
25284- CMPQ AX, $0
25285- JE exit
25286- MOVQ AX, ·ssHandle(SB)
25287-
25288- MOVQ ·goWaitsH(SB), CX
25289- MOVQ ·cSetEvent(SB), AX
25290- CALL AX
25291-
25292- MOVQ ·cWaitsH(SB), CX
25293- MOVQ $4294967295, DX
25294- MOVQ ·cWaitForSingleObject(SB), AX
25295- CALL AX
25296-
25297- exit:
25298- ADDQ $32, SP
25299- RET
25300-
25301- // I do not know why, but this seems to be the only way to call
25302- // ctlHandlerProc on Windows 7.
25303-
25304- // func ·servicectlhandler(ctl uint32, evtype uint32, evdata uintptr, context uintptr) uintptr {
25305- TEXT ·servicectlhandler(SB),7,$0
25306- MOVQ ·ctlHandlerExProc(SB), AX
25307- JMP AX
25308 diff --git a/vendor/golang.org/x/sys/windows/syscall.go b/vendor/golang.org/x/sys/windows/syscall.go
25309deleted file mode 100644
25310index b07bc23..0000000
25311--- a/vendor/golang.org/x/sys/windows/syscall.go
25312+++ /dev/null
25313 @@ -1,71 +0,0 @@
25314- // Copyright 2009 The Go Authors. All rights reserved.
25315- // Use of this source code is governed by a BSD-style
25316- // license that can be found in the LICENSE file.
25317-
25318- // +build windows
25319-
25320- // Package windows contains an interface to the low-level operating system
25321- // primitives. OS details vary depending on the underlying system, and
25322- // by default, godoc will display the OS-specific documentation for the current
25323- // system. If you want godoc to display syscall documentation for another
25324- // system, set $GOOS and $GOARCH to the desired system. For example, if
25325- // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS
25326- // to freebsd and $GOARCH to arm.
25327- // The primary use of this package is inside other packages that provide a more
25328- // portable interface to the system, such as "os", "time" and "net". Use
25329- // those packages rather than this one if you can.
25330- // For details of the functions and data types in this package consult
25331- // the manuals for the appropriate operating system.
25332- // These calls return err == nil to indicate success; otherwise
25333- // err represents an operating system error describing the failure and
25334- // holds a value of type syscall.Errno.
25335- package windows // import "golang.org/x/sys/windows"
25336-
25337- import (
25338- "syscall"
25339- )
25340-
25341- // ByteSliceFromString returns a NUL-terminated slice of bytes
25342- // containing the text of s. If s contains a NUL byte at any
25343- // location, it returns (nil, syscall.EINVAL).
25344- func ByteSliceFromString(s string) ([]byte, error) {
25345- for i := 0; i < len(s); i++ {
25346- if s[i] == 0 {
25347- return nil, syscall.EINVAL
25348- }
25349- }
25350- a := make([]byte, len(s)+1)
25351- copy(a, s)
25352- return a, nil
25353- }
25354-
25355- // BytePtrFromString returns a pointer to a NUL-terminated array of
25356- // bytes containing the text of s. If s contains a NUL byte at any
25357- // location, it returns (nil, syscall.EINVAL).
25358- func BytePtrFromString(s string) (*byte, error) {
25359- a, err := ByteSliceFromString(s)
25360- if err != nil {
25361- return nil, err
25362- }
25363- return &a[0], nil
25364- }
25365-
25366- // Single-word zero for use when we need a valid pointer to 0 bytes.
25367- // See mksyscall.pl.
25368- var _zero uintptr
25369-
25370- func (ts *Timespec) Unix() (sec int64, nsec int64) {
25371- return int64(ts.Sec), int64(ts.Nsec)
25372- }
25373-
25374- func (tv *Timeval) Unix() (sec int64, nsec int64) {
25375- return int64(tv.Sec), int64(tv.Usec) * 1000
25376- }
25377-
25378- func (ts *Timespec) Nano() int64 {
25379- return int64(ts.Sec)*1e9 + int64(ts.Nsec)
25380- }
25381-
25382- func (tv *Timeval) Nano() int64 {
25383- return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
25384- }
25385 diff --git a/vendor/golang.org/x/sys/windows/syscall_test.go b/vendor/golang.org/x/sys/windows/syscall_test.go
25386deleted file mode 100644
25387index d7009e4..0000000
25388--- a/vendor/golang.org/x/sys/windows/syscall_test.go
25389+++ /dev/null
25390 @@ -1,53 +0,0 @@
25391- // Copyright 2013 The Go Authors. All rights reserved.
25392- // Use of this source code is governed by a BSD-style
25393- // license that can be found in the LICENSE file.
25394-
25395- // +build windows
25396-
25397- package windows_test
25398-
25399- import (
25400- "syscall"
25401- "testing"
25402-
25403- "golang.org/x/sys/windows"
25404- )
25405-
25406- func testSetGetenv(t *testing.T, key, value string) {
25407- err := windows.Setenv(key, value)
25408- if err != nil {
25409- t.Fatalf("Setenv failed to set %q: %v", value, err)
25410- }
25411- newvalue, found := windows.Getenv(key)
25412- if !found {
25413- t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
25414- }
25415- if newvalue != value {
25416- t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
25417- }
25418- }
25419-
25420- func TestEnv(t *testing.T) {
25421- testSetGetenv(t, "TESTENV", "AVALUE")
25422- // make sure TESTENV gets set to "", not deleted
25423- testSetGetenv(t, "TESTENV", "")
25424- }
25425-
25426- func TestGetProcAddressByOrdinal(t *testing.T) {
25427- // Attempt calling shlwapi.dll:IsOS, resolving it by ordinal, as
25428- // suggested in
25429- // https://msdn.microsoft.com/en-us/library/windows/desktop/bb773795.aspx
25430- h, err := windows.LoadLibrary("shlwapi.dll")
25431- if err != nil {
25432- t.Fatalf("Failed to load shlwapi.dll: %s", err)
25433- }
25434- procIsOS, err := windows.GetProcAddressByOrdinal(h, 437)
25435- if err != nil {
25436- t.Fatalf("Could not find shlwapi.dll:IsOS by ordinal: %s", err)
25437- }
25438- const OS_NT = 1
25439- r, _, _ := syscall.Syscall(procIsOS, 1, OS_NT, 0, 0)
25440- if r == 0 {
25441- t.Error("shlwapi.dll:IsOS(OS_NT) returned 0, expected non-zero value")
25442- }
25443- }
25444 diff --git a/vendor/golang.org/x/sys/windows/syscall_windows.go b/vendor/golang.org/x/sys/windows/syscall_windows.go
25445deleted file mode 100644
25446index 1e9f4bb..0000000
25447--- a/vendor/golang.org/x/sys/windows/syscall_windows.go
25448+++ /dev/null
25449 @@ -1,1153 +0,0 @@
25450- // Copyright 2009 The Go Authors. All rights reserved.
25451- // Use of this source code is governed by a BSD-style
25452- // license that can be found in the LICENSE file.
25453-
25454- // Windows system calls.
25455-
25456- package windows
25457-
25458- import (
25459- errorspkg "errors"
25460- "sync"
25461- "syscall"
25462- "unicode/utf16"
25463- "unsafe"
25464- )
25465-
25466- type Handle uintptr
25467-
25468- const (
25469- InvalidHandle = ^Handle(0)
25470-
25471- // Flags for DefineDosDevice.
25472- DDD_EXACT_MATCH_ON_REMOVE = 0x00000004
25473- DDD_NO_BROADCAST_SYSTEM = 0x00000008
25474- DDD_RAW_TARGET_PATH = 0x00000001
25475- DDD_REMOVE_DEFINITION = 0x00000002
25476-
25477- // Return values for GetDriveType.
25478- DRIVE_UNKNOWN = 0
25479- DRIVE_NO_ROOT_DIR = 1
25480- DRIVE_REMOVABLE = 2
25481- DRIVE_FIXED = 3
25482- DRIVE_REMOTE = 4
25483- DRIVE_CDROM = 5
25484- DRIVE_RAMDISK = 6
25485-
25486- // File system flags from GetVolumeInformation and GetVolumeInformationByHandle.
25487- FILE_CASE_SENSITIVE_SEARCH = 0x00000001
25488- FILE_CASE_PRESERVED_NAMES = 0x00000002
25489- FILE_FILE_COMPRESSION = 0x00000010
25490- FILE_DAX_VOLUME = 0x20000000
25491- FILE_NAMED_STREAMS = 0x00040000
25492- FILE_PERSISTENT_ACLS = 0x00000008
25493- FILE_READ_ONLY_VOLUME = 0x00080000
25494- FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000
25495- FILE_SUPPORTS_ENCRYPTION = 0x00020000
25496- FILE_SUPPORTS_EXTENDED_ATTRIBUTES = 0x00800000
25497- FILE_SUPPORTS_HARD_LINKS = 0x00400000
25498- FILE_SUPPORTS_OBJECT_IDS = 0x00010000
25499- FILE_SUPPORTS_OPEN_BY_FILE_ID = 0x01000000
25500- FILE_SUPPORTS_REPARSE_POINTS = 0x00000080
25501- FILE_SUPPORTS_SPARSE_FILES = 0x00000040
25502- FILE_SUPPORTS_TRANSACTIONS = 0x00200000
25503- FILE_SUPPORTS_USN_JOURNAL = 0x02000000
25504- FILE_UNICODE_ON_DISK = 0x00000004
25505- FILE_VOLUME_IS_COMPRESSED = 0x00008000
25506- FILE_VOLUME_QUOTAS = 0x00000020
25507- )
25508-
25509- // StringToUTF16 is deprecated. Use UTF16FromString instead.
25510- // If s contains a NUL byte this function panics instead of
25511- // returning an error.
25512- func StringToUTF16(s string) []uint16 {
25513- a, err := UTF16FromString(s)
25514- if err != nil {
25515- panic("windows: string with NUL passed to StringToUTF16")
25516- }
25517- return a
25518- }
25519-
25520- // UTF16FromString returns the UTF-16 encoding of the UTF-8 string
25521- // s, with a terminating NUL added. If s contains a NUL byte at any
25522- // location, it returns (nil, syscall.EINVAL).
25523- func UTF16FromString(s string) ([]uint16, error) {
25524- for i := 0; i < len(s); i++ {
25525- if s[i] == 0 {
25526- return nil, syscall.EINVAL
25527- }
25528- }
25529- return utf16.Encode([]rune(s + "\x00")), nil
25530- }
25531-
25532- // UTF16ToString returns the UTF-8 encoding of the UTF-16 sequence s,
25533- // with a terminating NUL removed.
25534- func UTF16ToString(s []uint16) string {
25535- for i, v := range s {
25536- if v == 0 {
25537- s = s[0:i]
25538- break
25539- }
25540- }
25541- return string(utf16.Decode(s))
25542- }
25543-
25544- // StringToUTF16Ptr is deprecated. Use UTF16PtrFromString instead.
25545- // If s contains a NUL byte this function panics instead of
25546- // returning an error.
25547- func StringToUTF16Ptr(s string) *uint16 { return &StringToUTF16(s)[0] }
25548-
25549- // UTF16PtrFromString returns pointer to the UTF-16 encoding of
25550- // the UTF-8 string s, with a terminating NUL added. If s
25551- // contains a NUL byte at any location, it returns (nil, syscall.EINVAL).
25552- func UTF16PtrFromString(s string) (*uint16, error) {
25553- a, err := UTF16FromString(s)
25554- if err != nil {
25555- return nil, err
25556- }
25557- return &a[0], nil
25558- }
25559-
25560- func Getpagesize() int { return 4096 }
25561-
25562- // NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention.
25563- // This is useful when interoperating with Windows code requiring callbacks.
25564- func NewCallback(fn interface{}) uintptr {
25565- return syscall.NewCallback(fn)
25566- }
25567-
25568- // NewCallbackCDecl converts a Go function to a function pointer conforming to the cdecl calling convention.
25569- // This is useful when interoperating with Windows code requiring callbacks.
25570- func NewCallbackCDecl(fn interface{}) uintptr {
25571- return syscall.NewCallbackCDecl(fn)
25572- }
25573-
25574- // windows api calls
25575-
25576- //sys GetLastError() (lasterr error)
25577- //sys LoadLibrary(libname string) (handle Handle, err error) = LoadLibraryW
25578- //sys LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, err error) = LoadLibraryExW
25579- //sys FreeLibrary(handle Handle) (err error)
25580- //sys GetProcAddress(module Handle, procname string) (proc uintptr, err error)
25581- //sys GetVersion() (ver uint32, err error)
25582- //sys FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW
25583- //sys ExitProcess(exitcode uint32)
25584- //sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW
25585- //sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
25586- //sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
25587- //sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff]
25588- //sys CloseHandle(handle Handle) (err error)
25589- //sys GetStdHandle(stdhandle uint32) (handle Handle, err error) [failretval==InvalidHandle]
25590- //sys SetStdHandle(stdhandle uint32, handle Handle) (err error)
25591- //sys findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstFileW
25592- //sys findNextFile1(handle Handle, data *win32finddata1) (err error) = FindNextFileW
25593- //sys FindClose(handle Handle) (err error)
25594- //sys GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error)
25595- //sys GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) = GetCurrentDirectoryW
25596- //sys SetCurrentDirectory(path *uint16) (err error) = SetCurrentDirectoryW
25597- //sys CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) = CreateDirectoryW
25598- //sys RemoveDirectory(path *uint16) (err error) = RemoveDirectoryW
25599- //sys DeleteFile(path *uint16) (err error) = DeleteFileW
25600- //sys MoveFile(from *uint16, to *uint16) (err error) = MoveFileW
25601- //sys MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
25602- //sys GetComputerName(buf *uint16, n *uint32) (err error) = GetComputerNameW
25603- //sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
25604- //sys SetEndOfFile(handle Handle) (err error)
25605- //sys GetSystemTimeAsFileTime(time *Filetime)
25606- //sys GetSystemTimePreciseAsFileTime(time *Filetime)
25607- //sys GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) [failretval==0xffffffff]
25608- //sys CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error)
25609- //sys GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error)
25610- //sys PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error)
25611- //sys CancelIo(s Handle) (err error)
25612- //sys CancelIoEx(s Handle, o *Overlapped) (err error)
25613- //sys CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessW
25614- //sys OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error)
25615- //sys TerminateProcess(handle Handle, exitcode uint32) (err error)
25616- //sys GetExitCodeProcess(handle Handle, exitcode *uint32) (err error)
25617- //sys GetStartupInfo(startupInfo *StartupInfo) (err error) = GetStartupInfoW
25618- //sys GetCurrentProcess() (pseudoHandle Handle, err error)
25619- //sys GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error)
25620- //sys DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error)
25621- //sys WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) [failretval==0xffffffff]
25622- //sys GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) = GetTempPathW
25623- //sys CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error)
25624- //sys GetFileType(filehandle Handle) (n uint32, err error)
25625- //sys CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) = advapi32.CryptAcquireContextW
25626- //sys CryptReleaseContext(provhandle Handle, flags uint32) (err error) = advapi32.CryptReleaseContext
25627- //sys CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) = advapi32.CryptGenRandom
25628- //sys GetEnvironmentStrings() (envs *uint16, err error) [failretval==nil] = kernel32.GetEnvironmentStringsW
25629- //sys FreeEnvironmentStrings(envs *uint16) (err error) = kernel32.FreeEnvironmentStringsW
25630- //sys GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) = kernel32.GetEnvironmentVariableW
25631- //sys SetEnvironmentVariable(name *uint16, value *uint16) (err error) = kernel32.SetEnvironmentVariableW
25632- //sys SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error)
25633- //sys GetFileAttributes(name *uint16) (attrs uint32, err error) [failretval==INVALID_FILE_ATTRIBUTES] = kernel32.GetFileAttributesW
25634- //sys SetFileAttributes(name *uint16, attrs uint32) (err error) = kernel32.SetFileAttributesW
25635- //sys GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) = kernel32.GetFileAttributesExW
25636- //sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW
25637- //sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) [failretval==nil] = shell32.CommandLineToArgvW
25638- //sys LocalFree(hmem Handle) (handle Handle, err error) [failretval!=0]
25639- //sys SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error)
25640- //sys FlushFileBuffers(handle Handle) (err error)
25641- //sys GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) = kernel32.GetFullPathNameW
25642- //sys GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) = kernel32.GetLongPathNameW
25643- //sys GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) = kernel32.GetShortPathNameW
25644- //sys CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) = kernel32.CreateFileMappingW
25645- //sys MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error)
25646- //sys UnmapViewOfFile(addr uintptr) (err error)
25647- //sys FlushViewOfFile(addr uintptr, length uintptr) (err error)
25648- //sys VirtualLock(addr uintptr, length uintptr) (err error)
25649- //sys VirtualUnlock(addr uintptr, length uintptr) (err error)
25650- //sys VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) = kernel32.VirtualAlloc
25651- //sys VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) = kernel32.VirtualFree
25652- //sys VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) = kernel32.VirtualProtect
25653- //sys TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) = mswsock.TransmitFile
25654- //sys ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) = kernel32.ReadDirectoryChangesW
25655- //sys CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) = crypt32.CertOpenSystemStoreW
25656- //sys CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) [failretval==InvalidHandle] = crypt32.CertOpenStore
25657- //sys CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) [failretval==nil] = crypt32.CertEnumCertificatesInStore
25658- //sys CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) = crypt32.CertAddCertificateContextToStore
25659- //sys CertCloseStore(store Handle, flags uint32) (err error) = crypt32.CertCloseStore
25660- //sys CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) = crypt32.CertGetCertificateChain
25661- //sys CertFreeCertificateChain(ctx *CertChainContext) = crypt32.CertFreeCertificateChain
25662- //sys CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) [failretval==nil] = crypt32.CertCreateCertificateContext
25663- //sys CertFreeCertificateContext(ctx *CertContext) (err error) = crypt32.CertFreeCertificateContext
25664- //sys CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) = crypt32.CertVerifyCertificateChainPolicy
25665- //sys RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) = advapi32.RegOpenKeyExW
25666- //sys RegCloseKey(key Handle) (regerrno error) = advapi32.RegCloseKey
25667- //sys RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegQueryInfoKeyW
25668- //sys RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) = advapi32.RegEnumKeyExW
25669- //sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegQueryValueExW
25670- //sys getCurrentProcessId() (pid uint32) = kernel32.GetCurrentProcessId
25671- //sys GetConsoleMode(console Handle, mode *uint32) (err error) = kernel32.GetConsoleMode
25672- //sys SetConsoleMode(console Handle, mode uint32) (err error) = kernel32.SetConsoleMode
25673- //sys GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) = kernel32.GetConsoleScreenBufferInfo
25674- //sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW
25675- //sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW
25676- //sys CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.CreateToolhelp32Snapshot
25677- //sys Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) = kernel32.Process32FirstW
25678- //sys Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) = kernel32.Process32NextW
25679- //sys DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error)
25680- // This function returns 1 byte BOOLEAN rather than the 4 byte BOOL.
25681- //sys CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) [failretval&0xff==0] = CreateSymbolicLinkW
25682- //sys CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) [failretval&0xff==0] = CreateHardLinkW
25683- //sys GetCurrentThreadId() (id uint32)
25684- //sys CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) = kernel32.CreateEventW
25685- //sys CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) = kernel32.CreateEventExW
25686- //sys OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) = kernel32.OpenEventW
25687- //sys SetEvent(event Handle) (err error) = kernel32.SetEvent
25688- //sys ResetEvent(event Handle) (err error) = kernel32.ResetEvent
25689- //sys PulseEvent(event Handle) (err error) = kernel32.PulseEvent
25690-
25691- // Volume Management Functions
25692- //sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW
25693- //sys DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) = DeleteVolumeMountPointW
25694- //sys FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstVolumeW
25695- //sys FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstVolumeMountPointW
25696- //sys FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) = FindNextVolumeW
25697- //sys FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) = FindNextVolumeMountPointW
25698- //sys FindVolumeClose(findVolume Handle) (err error)
25699- //sys FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error)
25700- //sys GetDriveType(rootPathName *uint16) (driveType uint32) = GetDriveTypeW
25701- //sys GetLogicalDrives() (drivesBitMask uint32, err error) [failretval==0]
25702- //sys GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) [failretval==0] = GetLogicalDriveStringsW
25703- //sys GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) = GetVolumeInformationW
25704- //sys GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) = GetVolumeInformationByHandleW
25705- //sys GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) = GetVolumeNameForVolumeMountPointW
25706- //sys GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) = GetVolumePathNameW
25707- //sys GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) = GetVolumePathNamesForVolumeNameW
25708- //sys QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) [failretval==0] = QueryDosDeviceW
25709- //sys SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) = SetVolumeLabelW
25710- //sys SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) = SetVolumeMountPointW
25711-
25712- // syscall interface implementation for other packages
25713-
25714- // GetProcAddressByOrdinal retrieves the address of the exported
25715- // function from module by ordinal.
25716- func GetProcAddressByOrdinal(module Handle, ordinal uintptr) (proc uintptr, err error) {
25717- r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), ordinal, 0)
25718- proc = uintptr(r0)
25719- if proc == 0 {
25720- if e1 != 0 {
25721- err = errnoErr(e1)
25722- } else {
25723- err = syscall.EINVAL
25724- }
25725- }
25726- return
25727- }
25728-
25729- func Exit(code int) { ExitProcess(uint32(code)) }
25730-
25731- func makeInheritSa() *SecurityAttributes {
25732- var sa SecurityAttributes
25733- sa.Length = uint32(unsafe.Sizeof(sa))
25734- sa.InheritHandle = 1
25735- return &sa
25736- }
25737-
25738- func Open(path string, mode int, perm uint32) (fd Handle, err error) {
25739- if len(path) == 0 {
25740- return InvalidHandle, ERROR_FILE_NOT_FOUND
25741- }
25742- pathp, err := UTF16PtrFromString(path)
25743- if err != nil {
25744- return InvalidHandle, err
25745- }
25746- var access uint32
25747- switch mode & (O_RDONLY | O_WRONLY | O_RDWR) {
25748- case O_RDONLY:
25749- access = GENERIC_READ
25750- case O_WRONLY:
25751- access = GENERIC_WRITE
25752- case O_RDWR:
25753- access = GENERIC_READ | GENERIC_WRITE
25754- }
25755- if mode&O_CREAT != 0 {
25756- access |= GENERIC_WRITE
25757- }
25758- if mode&O_APPEND != 0 {
25759- access &^= GENERIC_WRITE
25760- access |= FILE_APPEND_DATA
25761- }
25762- sharemode := uint32(FILE_SHARE_READ | FILE_SHARE_WRITE)
25763- var sa *SecurityAttributes
25764- if mode&O_CLOEXEC == 0 {
25765- sa = makeInheritSa()
25766- }
25767- var createmode uint32
25768- switch {
25769- case mode&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL):
25770- createmode = CREATE_NEW
25771- case mode&(O_CREAT|O_TRUNC) == (O_CREAT | O_TRUNC):
25772- createmode = CREATE_ALWAYS
25773- case mode&O_CREAT == O_CREAT:
25774- createmode = OPEN_ALWAYS
25775- case mode&O_TRUNC == O_TRUNC:
25776- createmode = TRUNCATE_EXISTING
25777- default:
25778- createmode = OPEN_EXISTING
25779- }
25780- h, e := CreateFile(pathp, access, sharemode, sa, createmode, FILE_ATTRIBUTE_NORMAL, 0)
25781- return h, e
25782- }
25783-
25784- func Read(fd Handle, p []byte) (n int, err error) {
25785- var done uint32
25786- e := ReadFile(fd, p, &done, nil)
25787- if e != nil {
25788- if e == ERROR_BROKEN_PIPE {
25789- // NOTE(brainman): work around ERROR_BROKEN_PIPE is returned on reading EOF from stdin
25790- return 0, nil
25791- }
25792- return 0, e
25793- }
25794- if raceenabled {
25795- if done > 0 {
25796- raceWriteRange(unsafe.Pointer(&p[0]), int(done))
25797- }
25798- raceAcquire(unsafe.Pointer(&ioSync))
25799- }
25800- return int(done), nil
25801- }
25802-
25803- func Write(fd Handle, p []byte) (n int, err error) {
25804- if raceenabled {
25805- raceReleaseMerge(unsafe.Pointer(&ioSync))
25806- }
25807- var done uint32
25808- e := WriteFile(fd, p, &done, nil)
25809- if e != nil {
25810- return 0, e
25811- }
25812- if raceenabled && done > 0 {
25813- raceReadRange(unsafe.Pointer(&p[0]), int(done))
25814- }
25815- return int(done), nil
25816- }
25817-
25818- var ioSync int64
25819-
25820- func Seek(fd Handle, offset int64, whence int) (newoffset int64, err error) {
25821- var w uint32
25822- switch whence {
25823- case 0:
25824- w = FILE_BEGIN
25825- case 1:
25826- w = FILE_CURRENT
25827- case 2:
25828- w = FILE_END
25829- }
25830- hi := int32(offset >> 32)
25831- lo := int32(offset)
25832- // use GetFileType to check pipe, pipe can't do seek
25833- ft, _ := GetFileType(fd)
25834- if ft == FILE_TYPE_PIPE {
25835- return 0, syscall.EPIPE
25836- }
25837- rlo, e := SetFilePointer(fd, lo, &hi, w)
25838- if e != nil {
25839- return 0, e
25840- }
25841- return int64(hi)<<32 + int64(rlo), nil
25842- }
25843-
25844- func Close(fd Handle) (err error) {
25845- return CloseHandle(fd)
25846- }
25847-
25848- var (
25849- Stdin = getStdHandle(STD_INPUT_HANDLE)
25850- Stdout = getStdHandle(STD_OUTPUT_HANDLE)
25851- Stderr = getStdHandle(STD_ERROR_HANDLE)
25852- )
25853-
25854- func getStdHandle(stdhandle uint32) (fd Handle) {
25855- r, _ := GetStdHandle(stdhandle)
25856- CloseOnExec(r)
25857- return r
25858- }
25859-
25860- const ImplementsGetwd = true
25861-
25862- func Getwd() (wd string, err error) {
25863- b := make([]uint16, 300)
25864- n, e := GetCurrentDirectory(uint32(len(b)), &b[0])
25865- if e != nil {
25866- return "", e
25867- }
25868- return string(utf16.Decode(b[0:n])), nil
25869- }
25870-
25871- func Chdir(path string) (err error) {
25872- pathp, err := UTF16PtrFromString(path)
25873- if err != nil {
25874- return err
25875- }
25876- return SetCurrentDirectory(pathp)
25877- }
25878-
25879- func Mkdir(path string, mode uint32) (err error) {
25880- pathp, err := UTF16PtrFromString(path)
25881- if err != nil {
25882- return err
25883- }
25884- return CreateDirectory(pathp, nil)
25885- }
25886-
25887- func Rmdir(path string) (err error) {
25888- pathp, err := UTF16PtrFromString(path)
25889- if err != nil {
25890- return err
25891- }
25892- return RemoveDirectory(pathp)
25893- }
25894-
25895- func Unlink(path string) (err error) {
25896- pathp, err := UTF16PtrFromString(path)
25897- if err != nil {
25898- return err
25899- }
25900- return DeleteFile(pathp)
25901- }
25902-
25903- func Rename(oldpath, newpath string) (err error) {
25904- from, err := UTF16PtrFromString(oldpath)
25905- if err != nil {
25906- return err
25907- }
25908- to, err := UTF16PtrFromString(newpath)
25909- if err != nil {
25910- return err
25911- }
25912- return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
25913- }
25914-
25915- func ComputerName() (name string, err error) {
25916- var n uint32 = MAX_COMPUTERNAME_LENGTH + 1
25917- b := make([]uint16, n)
25918- e := GetComputerName(&b[0], &n)
25919- if e != nil {
25920- return "", e
25921- }
25922- return string(utf16.Decode(b[0:n])), nil
25923- }
25924-
25925- func Ftruncate(fd Handle, length int64) (err error) {
25926- curoffset, e := Seek(fd, 0, 1)
25927- if e != nil {
25928- return e
25929- }
25930- defer Seek(fd, curoffset, 0)
25931- _, e = Seek(fd, length, 0)
25932- if e != nil {
25933- return e
25934- }
25935- e = SetEndOfFile(fd)
25936- if e != nil {
25937- return e
25938- }
25939- return nil
25940- }
25941-
25942- func Gettimeofday(tv *Timeval) (err error) {
25943- var ft Filetime
25944- GetSystemTimeAsFileTime(&ft)
25945- *tv = NsecToTimeval(ft.Nanoseconds())
25946- return nil
25947- }
25948-
25949- func Pipe(p []Handle) (err error) {
25950- if len(p) != 2 {
25951- return syscall.EINVAL
25952- }
25953- var r, w Handle
25954- e := CreatePipe(&r, &w, makeInheritSa(), 0)
25955- if e != nil {
25956- return e
25957- }
25958- p[0] = r
25959- p[1] = w
25960- return nil
25961- }
25962-
25963- func Utimes(path string, tv []Timeval) (err error) {
25964- if len(tv) != 2 {
25965- return syscall.EINVAL
25966- }
25967- pathp, e := UTF16PtrFromString(path)
25968- if e != nil {
25969- return e
25970- }
25971- h, e := CreateFile(pathp,
25972- FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, nil,
25973- OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
25974- if e != nil {
25975- return e
25976- }
25977- defer Close(h)
25978- a := NsecToFiletime(tv[0].Nanoseconds())
25979- w := NsecToFiletime(tv[1].Nanoseconds())
25980- return SetFileTime(h, nil, &a, &w)
25981- }
25982-
25983- func UtimesNano(path string, ts []Timespec) (err error) {
25984- if len(ts) != 2 {
25985- return syscall.EINVAL
25986- }
25987- pathp, e := UTF16PtrFromString(path)
25988- if e != nil {
25989- return e
25990- }
25991- h, e := CreateFile(pathp,
25992- FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, nil,
25993- OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
25994- if e != nil {
25995- return e
25996- }
25997- defer Close(h)
25998- a := NsecToFiletime(TimespecToNsec(ts[0]))
25999- w := NsecToFiletime(TimespecToNsec(ts[1]))
26000- return SetFileTime(h, nil, &a, &w)
26001- }
26002-
26003- func Fsync(fd Handle) (err error) {
26004- return FlushFileBuffers(fd)
26005- }
26006-
26007- func Chmod(path string, mode uint32) (err error) {
26008- if mode == 0 {
26009- return syscall.EINVAL
26010- }
26011- p, e := UTF16PtrFromString(path)
26012- if e != nil {
26013- return e
26014- }
26015- attrs, e := GetFileAttributes(p)
26016- if e != nil {
26017- return e
26018- }
26019- if mode&S_IWRITE != 0 {
26020- attrs &^= FILE_ATTRIBUTE_READONLY
26021- } else {
26022- attrs |= FILE_ATTRIBUTE_READONLY
26023- }
26024- return SetFileAttributes(p, attrs)
26025- }
26026-
26027- func LoadGetSystemTimePreciseAsFileTime() error {
26028- return procGetSystemTimePreciseAsFileTime.Find()
26029- }
26030-
26031- func LoadCancelIoEx() error {
26032- return procCancelIoEx.Find()
26033- }
26034-
26035- func LoadSetFileCompletionNotificationModes() error {
26036- return procSetFileCompletionNotificationModes.Find()
26037- }
26038-
26039- // net api calls
26040-
26041- const socket_error = uintptr(^uint32(0))
26042-
26043- //sys WSAStartup(verreq uint32, data *WSAData) (sockerr error) = ws2_32.WSAStartup
26044- //sys WSACleanup() (err error) [failretval==socket_error] = ws2_32.WSACleanup
26045- //sys WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) [failretval==socket_error] = ws2_32.WSAIoctl
26046- //sys socket(af int32, typ int32, protocol int32) (handle Handle, err error) [failretval==InvalidHandle] = ws2_32.socket
26047- //sys Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) [failretval==socket_error] = ws2_32.setsockopt
26048- //sys Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) [failretval==socket_error] = ws2_32.getsockopt
26049- //sys bind(s Handle, name unsafe.Pointer, namelen int32) (err error) [failretval==socket_error] = ws2_32.bind
26050- //sys connect(s Handle, name unsafe.Pointer, namelen int32) (err error) [failretval==socket_error] = ws2_32.connect
26051- //sys getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) [failretval==socket_error] = ws2_32.getsockname
26052- //sys getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) [failretval==socket_error] = ws2_32.getpeername
26053- //sys listen(s Handle, backlog int32) (err error) [failretval==socket_error] = ws2_32.listen
26054- //sys shutdown(s Handle, how int32) (err error) [failretval==socket_error] = ws2_32.shutdown
26055- //sys Closesocket(s Handle) (err error) [failretval==socket_error] = ws2_32.closesocket
26056- //sys AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) = mswsock.AcceptEx
26057- //sys GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) = mswsock.GetAcceptExSockaddrs
26058- //sys WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSARecv
26059- //sys WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSASend
26060- //sys WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSARecvFrom
26061- //sys WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) [failretval==socket_error] = ws2_32.WSASendTo
26062- //sys GetHostByName(name string) (h *Hostent, err error) [failretval==nil] = ws2_32.gethostbyname
26063- //sys GetServByName(name string, proto string) (s *Servent, err error) [failretval==nil] = ws2_32.getservbyname
26064- //sys Ntohs(netshort uint16) (u uint16) = ws2_32.ntohs
26065- //sys GetProtoByName(name string) (p *Protoent, err error) [failretval==nil] = ws2_32.getprotobyname
26066- //sys DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) = dnsapi.DnsQuery_W
26067- //sys DnsRecordListFree(rl *DNSRecord, freetype uint32) = dnsapi.DnsRecordListFree
26068- //sys DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) = dnsapi.DnsNameCompare_W
26069- //sys GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) = ws2_32.GetAddrInfoW
26070- //sys FreeAddrInfoW(addrinfo *AddrinfoW) = ws2_32.FreeAddrInfoW
26071- //sys GetIfEntry(pIfRow *MibIfRow) (errcode error) = iphlpapi.GetIfEntry
26072- //sys GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) = iphlpapi.GetAdaptersInfo
26073- //sys SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) = kernel32.SetFileCompletionNotificationModes
26074- //sys WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) [failretval==-1] = ws2_32.WSAEnumProtocolsW
26075- //sys GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) = iphlpapi.GetAdaptersAddresses
26076- //sys GetACP() (acp uint32) = kernel32.GetACP
26077- //sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
26078-
26079- // For testing: clients can set this flag to force
26080- // creation of IPv6 sockets to return EAFNOSUPPORT.
26081- var SocketDisableIPv6 bool
26082-
26083- type RawSockaddrInet4 struct {
26084- Family uint16
26085- Port uint16
26086- Addr [4]byte /* in_addr */
26087- Zero [8]uint8
26088- }
26089-
26090- type RawSockaddrInet6 struct {
26091- Family uint16
26092- Port uint16
26093- Flowinfo uint32
26094- Addr [16]byte /* in6_addr */
26095- Scope_id uint32
26096- }
26097-
26098- type RawSockaddr struct {
26099- Family uint16
26100- Data [14]int8
26101- }
26102-
26103- type RawSockaddrAny struct {
26104- Addr RawSockaddr
26105- Pad [96]int8
26106- }
26107-
26108- type Sockaddr interface {
26109- sockaddr() (ptr unsafe.Pointer, len int32, err error) // lowercase; only we can define Sockaddrs
26110- }
26111-
26112- type SockaddrInet4 struct {
26113- Port int
26114- Addr [4]byte
26115- raw RawSockaddrInet4
26116- }
26117-
26118- func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, int32, error) {
26119- if sa.Port < 0 || sa.Port > 0xFFFF {
26120- return nil, 0, syscall.EINVAL
26121- }
26122- sa.raw.Family = AF_INET
26123- p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
26124- p[0] = byte(sa.Port >> 8)
26125- p[1] = byte(sa.Port)
26126- for i := 0; i < len(sa.Addr); i++ {
26127- sa.raw.Addr[i] = sa.Addr[i]
26128- }
26129- return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil
26130- }
26131-
26132- type SockaddrInet6 struct {
26133- Port int
26134- ZoneId uint32
26135- Addr [16]byte
26136- raw RawSockaddrInet6
26137- }
26138-
26139- func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, int32, error) {
26140- if sa.Port < 0 || sa.Port > 0xFFFF {
26141- return nil, 0, syscall.EINVAL
26142- }
26143- sa.raw.Family = AF_INET6
26144- p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
26145- p[0] = byte(sa.Port >> 8)
26146- p[1] = byte(sa.Port)
26147- sa.raw.Scope_id = sa.ZoneId
26148- for i := 0; i < len(sa.Addr); i++ {
26149- sa.raw.Addr[i] = sa.Addr[i]
26150- }
26151- return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil
26152- }
26153-
26154- type SockaddrUnix struct {
26155- Name string
26156- }
26157-
26158- func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) {
26159- // TODO(brainman): implement SockaddrUnix.sockaddr()
26160- return nil, 0, syscall.EWINDOWS
26161- }
26162-
26163- func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) {
26164- switch rsa.Addr.Family {
26165- case AF_UNIX:
26166- return nil, syscall.EWINDOWS
26167-
26168- case AF_INET:
26169- pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
26170- sa := new(SockaddrInet4)
26171- p := (*[2]byte)(unsafe.Pointer(&pp.Port))
26172- sa.Port = int(p[0])<<8 + int(p[1])
26173- for i := 0; i < len(sa.Addr); i++ {
26174- sa.Addr[i] = pp.Addr[i]
26175- }
26176- return sa, nil
26177-
26178- case AF_INET6:
26179- pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa))
26180- sa := new(SockaddrInet6)
26181- p := (*[2]byte)(unsafe.Pointer(&pp.Port))
26182- sa.Port = int(p[0])<<8 + int(p[1])
26183- sa.ZoneId = pp.Scope_id
26184- for i := 0; i < len(sa.Addr); i++ {
26185- sa.Addr[i] = pp.Addr[i]
26186- }
26187- return sa, nil
26188- }
26189- return nil, syscall.EAFNOSUPPORT
26190- }
26191-
26192- func Socket(domain, typ, proto int) (fd Handle, err error) {
26193- if domain == AF_INET6 && SocketDisableIPv6 {
26194- return InvalidHandle, syscall.EAFNOSUPPORT
26195- }
26196- return socket(int32(domain), int32(typ), int32(proto))
26197- }
26198-
26199- func SetsockoptInt(fd Handle, level, opt int, value int) (err error) {
26200- v := int32(value)
26201- return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(&v)), int32(unsafe.Sizeof(v)))
26202- }
26203-
26204- func Bind(fd Handle, sa Sockaddr) (err error) {
26205- ptr, n, err := sa.sockaddr()
26206- if err != nil {
26207- return err
26208- }
26209- return bind(fd, ptr, n)
26210- }
26211-
26212- func Connect(fd Handle, sa Sockaddr) (err error) {
26213- ptr, n, err := sa.sockaddr()
26214- if err != nil {
26215- return err
26216- }
26217- return connect(fd, ptr, n)
26218- }
26219-
26220- func Getsockname(fd Handle) (sa Sockaddr, err error) {
26221- var rsa RawSockaddrAny
26222- l := int32(unsafe.Sizeof(rsa))
26223- if err = getsockname(fd, &rsa, &l); err != nil {
26224- return
26225- }
26226- return rsa.Sockaddr()
26227- }
26228-
26229- func Getpeername(fd Handle) (sa Sockaddr, err error) {
26230- var rsa RawSockaddrAny
26231- l := int32(unsafe.Sizeof(rsa))
26232- if err = getpeername(fd, &rsa, &l); err != nil {
26233- return
26234- }
26235- return rsa.Sockaddr()
26236- }
26237-
26238- func Listen(s Handle, n int) (err error) {
26239- return listen(s, int32(n))
26240- }
26241-
26242- func Shutdown(fd Handle, how int) (err error) {
26243- return shutdown(fd, int32(how))
26244- }
26245-
26246- func WSASendto(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to Sockaddr, overlapped *Overlapped, croutine *byte) (err error) {
26247- rsa, l, err := to.sockaddr()
26248- if err != nil {
26249- return err
26250- }
26251- return WSASendTo(s, bufs, bufcnt, sent, flags, (*RawSockaddrAny)(unsafe.Pointer(rsa)), l, overlapped, croutine)
26252- }
26253-
26254- func LoadGetAddrInfo() error {
26255- return procGetAddrInfoW.Find()
26256- }
26257-
26258- var connectExFunc struct {
26259- once sync.Once
26260- addr uintptr
26261- err error
26262- }
26263-
26264- func LoadConnectEx() error {
26265- connectExFunc.once.Do(func() {
26266- var s Handle
26267- s, connectExFunc.err = Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
26268- if connectExFunc.err != nil {
26269- return
26270- }
26271- defer CloseHandle(s)
26272- var n uint32
26273- connectExFunc.err = WSAIoctl(s,
26274- SIO_GET_EXTENSION_FUNCTION_POINTER,
26275- (*byte)(unsafe.Pointer(&WSAID_CONNECTEX)),
26276- uint32(unsafe.Sizeof(WSAID_CONNECTEX)),
26277- (*byte)(unsafe.Pointer(&connectExFunc.addr)),
26278- uint32(unsafe.Sizeof(connectExFunc.addr)),
26279- &n, nil, 0)
26280- })
26281- return connectExFunc.err
26282- }
26283-
26284- func connectEx(s Handle, name unsafe.Pointer, namelen int32, sendBuf *byte, sendDataLen uint32, bytesSent *uint32, overlapped *Overlapped) (err error) {
26285- r1, _, e1 := syscall.Syscall9(connectExFunc.addr, 7, uintptr(s), uintptr(name), uintptr(namelen), uintptr(unsafe.Pointer(sendBuf)), uintptr(sendDataLen), uintptr(unsafe.Pointer(bytesSent)), uintptr(unsafe.Pointer(overlapped)), 0, 0)
26286- if r1 == 0 {
26287- if e1 != 0 {
26288- err = error(e1)
26289- } else {
26290- err = syscall.EINVAL
26291- }
26292- }
26293- return
26294- }
26295-
26296- func ConnectEx(fd Handle, sa Sockaddr, sendBuf *byte, sendDataLen uint32, bytesSent *uint32, overlapped *Overlapped) error {
26297- err := LoadConnectEx()
26298- if err != nil {
26299- return errorspkg.New("failed to find ConnectEx: " + err.Error())
26300- }
26301- ptr, n, err := sa.sockaddr()
26302- if err != nil {
26303- return err
26304- }
26305- return connectEx(fd, ptr, n, sendBuf, sendDataLen, bytesSent, overlapped)
26306- }
26307-
26308- var sendRecvMsgFunc struct {
26309- once sync.Once
26310- sendAddr uintptr
26311- recvAddr uintptr
26312- err error
26313- }
26314-
26315- func loadWSASendRecvMsg() error {
26316- sendRecvMsgFunc.once.Do(func() {
26317- var s Handle
26318- s, sendRecvMsgFunc.err = Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
26319- if sendRecvMsgFunc.err != nil {
26320- return
26321- }
26322- defer CloseHandle(s)
26323- var n uint32
26324- sendRecvMsgFunc.err = WSAIoctl(s,
26325- SIO_GET_EXTENSION_FUNCTION_POINTER,
26326- (*byte)(unsafe.Pointer(&WSAID_WSARECVMSG)),
26327- uint32(unsafe.Sizeof(WSAID_WSARECVMSG)),
26328- (*byte)(unsafe.Pointer(&sendRecvMsgFunc.recvAddr)),
26329- uint32(unsafe.Sizeof(sendRecvMsgFunc.recvAddr)),
26330- &n, nil, 0)
26331- if sendRecvMsgFunc.err != nil {
26332- return
26333- }
26334- sendRecvMsgFunc.err = WSAIoctl(s,
26335- SIO_GET_EXTENSION_FUNCTION_POINTER,
26336- (*byte)(unsafe.Pointer(&WSAID_WSASENDMSG)),
26337- uint32(unsafe.Sizeof(WSAID_WSASENDMSG)),
26338- (*byte)(unsafe.Pointer(&sendRecvMsgFunc.sendAddr)),
26339- uint32(unsafe.Sizeof(sendRecvMsgFunc.sendAddr)),
26340- &n, nil, 0)
26341- })
26342- return sendRecvMsgFunc.err
26343- }
26344-
26345- func WSASendMsg(fd Handle, msg *WSAMsg, flags uint32, bytesSent *uint32, overlapped *Overlapped, croutine *byte) error {
26346- err := loadWSASendRecvMsg()
26347- if err != nil {
26348- return err
26349- }
26350- r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.sendAddr, 6, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(flags), uintptr(unsafe.Pointer(bytesSent)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
26351- if r1 == socket_error {
26352- if e1 != 0 {
26353- err = errnoErr(e1)
26354- } else {
26355- err = syscall.EINVAL
26356- }
26357- }
26358- return err
26359- }
26360-
26361- func WSARecvMsg(fd Handle, msg *WSAMsg, bytesReceived *uint32, overlapped *Overlapped, croutine *byte) error {
26362- err := loadWSASendRecvMsg()
26363- if err != nil {
26364- return err
26365- }
26366- r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.recvAddr, 5, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(bytesReceived)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0)
26367- if r1 == socket_error {
26368- if e1 != 0 {
26369- err = errnoErr(e1)
26370- } else {
26371- err = syscall.EINVAL
26372- }
26373- }
26374- return err
26375- }
26376-
26377- // Invented structures to support what package os expects.
26378- type Rusage struct {
26379- CreationTime Filetime
26380- ExitTime Filetime
26381- KernelTime Filetime
26382- UserTime Filetime
26383- }
26384-
26385- type WaitStatus struct {
26386- ExitCode uint32
26387- }
26388-
26389- func (w WaitStatus) Exited() bool { return true }
26390-
26391- func (w WaitStatus) ExitStatus() int { return int(w.ExitCode) }
26392-
26393- func (w WaitStatus) Signal() Signal { return -1 }
26394-
26395- func (w WaitStatus) CoreDump() bool { return false }
26396-
26397- func (w WaitStatus) Stopped() bool { return false }
26398-
26399- func (w WaitStatus) Continued() bool { return false }
26400-
26401- func (w WaitStatus) StopSignal() Signal { return -1 }
26402-
26403- func (w WaitStatus) Signaled() bool { return false }
26404-
26405- func (w WaitStatus) TrapCause() int { return -1 }
26406-
26407- // Timespec is an invented structure on Windows, but here for
26408- // consistency with the corresponding package for other operating systems.
26409- type Timespec struct {
26410- Sec int64
26411- Nsec int64
26412- }
26413-
26414- func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
26415-
26416- func NsecToTimespec(nsec int64) (ts Timespec) {
26417- ts.Sec = nsec / 1e9
26418- ts.Nsec = nsec % 1e9
26419- return
26420- }
26421-
26422- // TODO(brainman): fix all needed for net
26423-
26424- func Accept(fd Handle) (nfd Handle, sa Sockaddr, err error) { return 0, nil, syscall.EWINDOWS }
26425- func Recvfrom(fd Handle, p []byte, flags int) (n int, from Sockaddr, err error) {
26426- return 0, nil, syscall.EWINDOWS
26427- }
26428- func Sendto(fd Handle, p []byte, flags int, to Sockaddr) (err error) { return syscall.EWINDOWS }
26429- func SetsockoptTimeval(fd Handle, level, opt int, tv *Timeval) (err error) { return syscall.EWINDOWS }
26430-
26431- // The Linger struct is wrong but we only noticed after Go 1.
26432- // sysLinger is the real system call structure.
26433-
26434- // BUG(brainman): The definition of Linger is not appropriate for direct use
26435- // with Setsockopt and Getsockopt.
26436- // Use SetsockoptLinger instead.
26437-
26438- type Linger struct {
26439- Onoff int32
26440- Linger int32
26441- }
26442-
26443- type sysLinger struct {
26444- Onoff uint16
26445- Linger uint16
26446- }
26447-
26448- type IPMreq struct {
26449- Multiaddr [4]byte /* in_addr */
26450- Interface [4]byte /* in_addr */
26451- }
26452-
26453- type IPv6Mreq struct {
26454- Multiaddr [16]byte /* in6_addr */
26455- Interface uint32
26456- }
26457-
26458- func GetsockoptInt(fd Handle, level, opt int) (int, error) { return -1, syscall.EWINDOWS }
26459-
26460- func SetsockoptLinger(fd Handle, level, opt int, l *Linger) (err error) {
26461- sys := sysLinger{Onoff: uint16(l.Onoff), Linger: uint16(l.Linger)}
26462- return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(&sys)), int32(unsafe.Sizeof(sys)))
26463- }
26464-
26465- func SetsockoptInet4Addr(fd Handle, level, opt int, value [4]byte) (err error) {
26466- return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(&value[0])), 4)
26467- }
26468- func SetsockoptIPMreq(fd Handle, level, opt int, mreq *IPMreq) (err error) {
26469- return Setsockopt(fd, int32(level), int32(opt), (*byte)(unsafe.Pointer(mreq)), int32(unsafe.Sizeof(*mreq)))
26470- }
26471- func SetsockoptIPv6Mreq(fd Handle, level, opt int, mreq *IPv6Mreq) (err error) {
26472- return syscall.EWINDOWS
26473- }
26474-
26475- func Getpid() (pid int) { return int(getCurrentProcessId()) }
26476-
26477- func FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, err error) {
26478- // NOTE(rsc): The Win32finddata struct is wrong for the system call:
26479- // the two paths are each one uint16 short. Use the correct struct,
26480- // a win32finddata1, and then copy the results out.
26481- // There is no loss of expressivity here, because the final
26482- // uint16, if it is used, is supposed to be a NUL, and Go doesn't need that.
26483- // For Go 1.1, we might avoid the allocation of win32finddata1 here
26484- // by adding a final Bug [2]uint16 field to the struct and then
26485- // adjusting the fields in the result directly.
26486- var data1 win32finddata1
26487- handle, err = findFirstFile1(name, &data1)
26488- if err == nil {
26489- copyFindData(data, &data1)
26490- }
26491- return
26492- }
26493-
26494- func FindNextFile(handle Handle, data *Win32finddata) (err error) {
26495- var data1 win32finddata1
26496- err = findNextFile1(handle, &data1)
26497- if err == nil {
26498- copyFindData(data, &data1)
26499- }
26500- return
26501- }
26502-
26503- func getProcessEntry(pid int) (*ProcessEntry32, error) {
26504- snapshot, err := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
26505- if err != nil {
26506- return nil, err
26507- }
26508- defer CloseHandle(snapshot)
26509- var procEntry ProcessEntry32
26510- procEntry.Size = uint32(unsafe.Sizeof(procEntry))
26511- if err = Process32First(snapshot, &procEntry); err != nil {
26512- return nil, err
26513- }
26514- for {
26515- if procEntry.ProcessID == uint32(pid) {
26516- return &procEntry, nil
26517- }
26518- err = Process32Next(snapshot, &procEntry)
26519- if err != nil {
26520- return nil, err
26521- }
26522- }
26523- }
26524-
26525- func Getppid() (ppid int) {
26526- pe, err := getProcessEntry(Getpid())
26527- if err != nil {
26528- return -1
26529- }
26530- return int(pe.ParentProcessID)
26531- }
26532-
26533- // TODO(brainman): fix all needed for os
26534- func Fchdir(fd Handle) (err error) { return syscall.EWINDOWS }
26535- func Link(oldpath, newpath string) (err error) { return syscall.EWINDOWS }
26536- func Symlink(path, link string) (err error) { return syscall.EWINDOWS }
26537-
26538- func Fchmod(fd Handle, mode uint32) (err error) { return syscall.EWINDOWS }
26539- func Chown(path string, uid int, gid int) (err error) { return syscall.EWINDOWS }
26540- func Lchown(path string, uid int, gid int) (err error) { return syscall.EWINDOWS }
26541- func Fchown(fd Handle, uid int, gid int) (err error) { return syscall.EWINDOWS }
26542-
26543- func Getuid() (uid int) { return -1 }
26544- func Geteuid() (euid int) { return -1 }
26545- func Getgid() (gid int) { return -1 }
26546- func Getegid() (egid int) { return -1 }
26547- func Getgroups() (gids []int, err error) { return nil, syscall.EWINDOWS }
26548-
26549- type Signal int
26550-
26551- func (s Signal) Signal() {}
26552-
26553- func (s Signal) String() string {
26554- if 0 <= s && int(s) < len(signals) {
26555- str := signals[s]
26556- if str != "" {
26557- return str
26558- }
26559- }
26560- return "signal " + itoa(int(s))
26561- }
26562-
26563- func LoadCreateSymbolicLink() error {
26564- return procCreateSymbolicLinkW.Find()
26565- }
26566-
26567- // Readlink returns the destination of the named symbolic link.
26568- func Readlink(path string, buf []byte) (n int, err error) {
26569- fd, err := CreateFile(StringToUTF16Ptr(path), GENERIC_READ, 0, nil, OPEN_EXISTING,
26570- FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, 0)
26571- if err != nil {
26572- return -1, err
26573- }
26574- defer CloseHandle(fd)
26575-
26576- rdbbuf := make([]byte, MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
26577- var bytesReturned uint32
26578- err = DeviceIoControl(fd, FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil)
26579- if err != nil {
26580- return -1, err
26581- }
26582-
26583- rdb := (*reparseDataBuffer)(unsafe.Pointer(&rdbbuf[0]))
26584- var s string
26585- switch rdb.ReparseTag {
26586- case IO_REPARSE_TAG_SYMLINK:
26587- data := (*symbolicLinkReparseBuffer)(unsafe.Pointer(&rdb.reparseBuffer))
26588- p := (*[0xffff]uint16)(unsafe.Pointer(&data.PathBuffer[0]))
26589- s = UTF16ToString(p[data.PrintNameOffset/2 : (data.PrintNameLength-data.PrintNameOffset)/2])
26590- case IO_REPARSE_TAG_MOUNT_POINT:
26591- data := (*mountPointReparseBuffer)(unsafe.Pointer(&rdb.reparseBuffer))
26592- p := (*[0xffff]uint16)(unsafe.Pointer(&data.PathBuffer[0]))
26593- s = UTF16ToString(p[data.PrintNameOffset/2 : (data.PrintNameLength-data.PrintNameOffset)/2])
26594- default:
26595- // the path is not a symlink or junction but another type of reparse
26596- // point
26597- return -1, syscall.ENOENT
26598- }
26599- n = copy(buf, []byte(s))
26600-
26601- return n, nil
26602- }
26603 diff --git a/vendor/golang.org/x/sys/windows/syscall_windows_test.go b/vendor/golang.org/x/sys/windows/syscall_windows_test.go
26604deleted file mode 100644
26605index 9c7133c..0000000
26606--- a/vendor/golang.org/x/sys/windows/syscall_windows_test.go
26607+++ /dev/null
26608 @@ -1,107 +0,0 @@
26609- // Copyright 2012 The Go Authors. All rights reserved.
26610- // Use of this source code is governed by a BSD-style
26611- // license that can be found in the LICENSE file.
26612-
26613- package windows_test
26614-
26615- import (
26616- "io/ioutil"
26617- "os"
26618- "path/filepath"
26619- "syscall"
26620- "testing"
26621- "unsafe"
26622-
26623- "golang.org/x/sys/windows"
26624- )
26625-
26626- func TestWin32finddata(t *testing.T) {
26627- dir, err := ioutil.TempDir("", "go-build")
26628- if err != nil {
26629- t.Fatalf("failed to create temp directory: %v", err)
26630- }
26631- defer os.RemoveAll(dir)
26632-
26633- path := filepath.Join(dir, "long_name.and_extension")
26634- f, err := os.Create(path)
26635- if err != nil {
26636- t.Fatalf("failed to create %v: %v", path, err)
26637- }
26638- f.Close()
26639-
26640- type X struct {
26641- fd windows.Win32finddata
26642- got byte
26643- pad [10]byte // to protect ourselves
26644-
26645- }
26646- var want byte = 2 // it is unlikely to have this character in the filename
26647- x := X{got: want}
26648-
26649- pathp, _ := windows.UTF16PtrFromString(path)
26650- h, err := windows.FindFirstFile(pathp, &(x.fd))
26651- if err != nil {
26652- t.Fatalf("FindFirstFile failed: %v", err)
26653- }
26654- err = windows.FindClose(h)
26655- if err != nil {
26656- t.Fatalf("FindClose failed: %v", err)
26657- }
26658-
26659- if x.got != want {
26660- t.Fatalf("memory corruption: want=%d got=%d", want, x.got)
26661- }
26662- }
26663-
26664- func TestFormatMessage(t *testing.T) {
26665- dll := windows.MustLoadDLL("pdh.dll")
26666-
26667- pdhOpenQuery := func(datasrc *uint16, userdata uint32, query *windows.Handle) (errno uintptr) {
26668- r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhOpenQueryW").Addr(), 3, uintptr(unsafe.Pointer(datasrc)), uintptr(userdata), uintptr(unsafe.Pointer(query)))
26669- return r0
26670- }
26671-
26672- pdhCloseQuery := func(query windows.Handle) (errno uintptr) {
26673- r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhCloseQuery").Addr(), 1, uintptr(query), 0, 0)
26674- return r0
26675- }
26676-
26677- var q windows.Handle
26678- name, err := windows.UTF16PtrFromString("no_such_source")
26679- if err != nil {
26680- t.Fatal(err)
26681- }
26682- errno := pdhOpenQuery(name, 0, &q)
26683- if errno == 0 {
26684- pdhCloseQuery(q)
26685- t.Fatal("PdhOpenQuery succeeded, but expected to fail.")
26686- }
26687-
26688- const flags uint32 = syscall.FORMAT_MESSAGE_FROM_HMODULE | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
26689- buf := make([]uint16, 300)
26690- _, err = windows.FormatMessage(flags, uintptr(dll.Handle), uint32(errno), 0, buf, nil)
26691- if err != nil {
26692- t.Fatalf("FormatMessage for handle=%x and errno=%x failed: %v", dll.Handle, errno, err)
26693- }
26694- }
26695-
26696- func abort(funcname string, err error) {
26697- panic(funcname + " failed: " + err.Error())
26698- }
26699-
26700- func ExampleLoadLibrary() {
26701- h, err := windows.LoadLibrary("kernel32.dll")
26702- if err != nil {
26703- abort("LoadLibrary", err)
26704- }
26705- defer windows.FreeLibrary(h)
26706- proc, err := windows.GetProcAddress(h, "GetVersion")
26707- if err != nil {
26708- abort("GetProcAddress", err)
26709- }
26710- r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
26711- major := byte(r)
26712- minor := uint8(r >> 8)
26713- build := uint16(r >> 16)
26714- print("windows version ", major, ".", minor, " (Build ", build, ")\n")
26715- }
26716 diff --git a/vendor/golang.org/x/sys/windows/types_windows.go b/vendor/golang.org/x/sys/windows/types_windows.go
26717deleted file mode 100644
26718index 52c2037..0000000
26719--- a/vendor/golang.org/x/sys/windows/types_windows.go
26720+++ /dev/null
26721 @@ -1,1333 +0,0 @@
26722- // Copyright 2011 The Go Authors. All rights reserved.
26723- // Use of this source code is governed by a BSD-style
26724- // license that can be found in the LICENSE file.
26725-
26726- package windows
26727-
26728- import "syscall"
26729-
26730- const (
26731- // Windows errors.
26732- ERROR_FILE_NOT_FOUND syscall.Errno = 2
26733- ERROR_PATH_NOT_FOUND syscall.Errno = 3
26734- ERROR_ACCESS_DENIED syscall.Errno = 5
26735- ERROR_NO_MORE_FILES syscall.Errno = 18
26736- ERROR_HANDLE_EOF syscall.Errno = 38
26737- ERROR_NETNAME_DELETED syscall.Errno = 64
26738- ERROR_FILE_EXISTS syscall.Errno = 80
26739- ERROR_BROKEN_PIPE syscall.Errno = 109
26740- ERROR_BUFFER_OVERFLOW syscall.Errno = 111
26741- ERROR_INSUFFICIENT_BUFFER syscall.Errno = 122
26742- ERROR_MOD_NOT_FOUND syscall.Errno = 126
26743- ERROR_PROC_NOT_FOUND syscall.Errno = 127
26744- ERROR_ALREADY_EXISTS syscall.Errno = 183
26745- ERROR_ENVVAR_NOT_FOUND syscall.Errno = 203
26746- ERROR_MORE_DATA syscall.Errno = 234
26747- ERROR_OPERATION_ABORTED syscall.Errno = 995
26748- ERROR_IO_PENDING syscall.Errno = 997
26749- ERROR_SERVICE_SPECIFIC_ERROR syscall.Errno = 1066
26750- ERROR_NOT_FOUND syscall.Errno = 1168
26751- ERROR_PRIVILEGE_NOT_HELD syscall.Errno = 1314
26752- WSAEACCES syscall.Errno = 10013
26753- WSAEMSGSIZE syscall.Errno = 10040
26754- WSAECONNRESET syscall.Errno = 10054
26755- )
26756-
26757- const (
26758- // Invented values to support what package os expects.
26759- O_RDONLY = 0x00000
26760- O_WRONLY = 0x00001
26761- O_RDWR = 0x00002
26762- O_CREAT = 0x00040
26763- O_EXCL = 0x00080
26764- O_NOCTTY = 0x00100
26765- O_TRUNC = 0x00200
26766- O_NONBLOCK = 0x00800
26767- O_APPEND = 0x00400
26768- O_SYNC = 0x01000
26769- O_ASYNC = 0x02000
26770- O_CLOEXEC = 0x80000
26771- )
26772-
26773- const (
26774- // More invented values for signals
26775- SIGHUP = Signal(0x1)
26776- SIGINT = Signal(0x2)
26777- SIGQUIT = Signal(0x3)
26778- SIGILL = Signal(0x4)
26779- SIGTRAP = Signal(0x5)
26780- SIGABRT = Signal(0x6)
26781- SIGBUS = Signal(0x7)
26782- SIGFPE = Signal(0x8)
26783- SIGKILL = Signal(0x9)
26784- SIGSEGV = Signal(0xb)
26785- SIGPIPE = Signal(0xd)
26786- SIGALRM = Signal(0xe)
26787- SIGTERM = Signal(0xf)
26788- )
26789-
26790- var signals = [...]string{
26791- 1: "hangup",
26792- 2: "interrupt",
26793- 3: "quit",
26794- 4: "illegal instruction",
26795- 5: "trace/breakpoint trap",
26796- 6: "aborted",
26797- 7: "bus error",
26798- 8: "floating point exception",
26799- 9: "killed",
26800- 10: "user defined signal 1",
26801- 11: "segmentation fault",
26802- 12: "user defined signal 2",
26803- 13: "broken pipe",
26804- 14: "alarm clock",
26805- 15: "terminated",
26806- }
26807-
26808- const (
26809- GENERIC_READ = 0x80000000
26810- GENERIC_WRITE = 0x40000000
26811- GENERIC_EXECUTE = 0x20000000
26812- GENERIC_ALL = 0x10000000
26813-
26814- FILE_LIST_DIRECTORY = 0x00000001
26815- FILE_APPEND_DATA = 0x00000004
26816- FILE_WRITE_ATTRIBUTES = 0x00000100
26817-
26818- FILE_SHARE_READ = 0x00000001
26819- FILE_SHARE_WRITE = 0x00000002
26820- FILE_SHARE_DELETE = 0x00000004
26821- FILE_ATTRIBUTE_READONLY = 0x00000001
26822- FILE_ATTRIBUTE_HIDDEN = 0x00000002
26823- FILE_ATTRIBUTE_SYSTEM = 0x00000004
26824- FILE_ATTRIBUTE_DIRECTORY = 0x00000010
26825- FILE_ATTRIBUTE_ARCHIVE = 0x00000020
26826- FILE_ATTRIBUTE_NORMAL = 0x00000080
26827- FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
26828-
26829- INVALID_FILE_ATTRIBUTES = 0xffffffff
26830-
26831- CREATE_NEW = 1
26832- CREATE_ALWAYS = 2
26833- OPEN_EXISTING = 3
26834- OPEN_ALWAYS = 4
26835- TRUNCATE_EXISTING = 5
26836-
26837- FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
26838- FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
26839- FILE_FLAG_OVERLAPPED = 0x40000000
26840-
26841- HANDLE_FLAG_INHERIT = 0x00000001
26842- STARTF_USESTDHANDLES = 0x00000100
26843- STARTF_USESHOWWINDOW = 0x00000001
26844- DUPLICATE_CLOSE_SOURCE = 0x00000001
26845- DUPLICATE_SAME_ACCESS = 0x00000002
26846-
26847- STD_INPUT_HANDLE = -10 & (1<<32 - 1)
26848- STD_OUTPUT_HANDLE = -11 & (1<<32 - 1)
26849- STD_ERROR_HANDLE = -12 & (1<<32 - 1)
26850-
26851- FILE_BEGIN = 0
26852- FILE_CURRENT = 1
26853- FILE_END = 2
26854-
26855- LANG_ENGLISH = 0x09
26856- SUBLANG_ENGLISH_US = 0x01
26857-
26858- FORMAT_MESSAGE_ALLOCATE_BUFFER = 256
26859- FORMAT_MESSAGE_IGNORE_INSERTS = 512
26860- FORMAT_MESSAGE_FROM_STRING = 1024
26861- FORMAT_MESSAGE_FROM_HMODULE = 2048
26862- FORMAT_MESSAGE_FROM_SYSTEM = 4096
26863- FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192
26864- FORMAT_MESSAGE_MAX_WIDTH_MASK = 255
26865-
26866- MAX_PATH = 260
26867- MAX_LONG_PATH = 32768
26868-
26869- MAX_COMPUTERNAME_LENGTH = 15
26870-
26871- TIME_ZONE_ID_UNKNOWN = 0
26872- TIME_ZONE_ID_STANDARD = 1
26873-
26874- TIME_ZONE_ID_DAYLIGHT = 2
26875- IGNORE = 0
26876- INFINITE = 0xffffffff
26877-
26878- WAIT_TIMEOUT = 258
26879- WAIT_ABANDONED = 0x00000080
26880- WAIT_OBJECT_0 = 0x00000000
26881- WAIT_FAILED = 0xFFFFFFFF
26882-
26883- PROCESS_TERMINATE = 1
26884- PROCESS_QUERY_INFORMATION = 0x00000400
26885- SYNCHRONIZE = 0x00100000
26886-
26887- FILE_MAP_COPY = 0x01
26888- FILE_MAP_WRITE = 0x02
26889- FILE_MAP_READ = 0x04
26890- FILE_MAP_EXECUTE = 0x20
26891-
26892- CTRL_C_EVENT = 0
26893- CTRL_BREAK_EVENT = 1
26894-
26895- // Windows reserves errors >= 1<<29 for application use.
26896- APPLICATION_ERROR = 1 << 29
26897- )
26898-
26899- const (
26900- // Process creation flags.
26901- CREATE_BREAKAWAY_FROM_JOB = 0x01000000
26902- CREATE_DEFAULT_ERROR_MODE = 0x04000000
26903- CREATE_NEW_CONSOLE = 0x00000010
26904- CREATE_NEW_PROCESS_GROUP = 0x00000200
26905- CREATE_NO_WINDOW = 0x08000000
26906- CREATE_PROTECTED_PROCESS = 0x00040000
26907- CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
26908- CREATE_SEPARATE_WOW_VDM = 0x00000800
26909- CREATE_SHARED_WOW_VDM = 0x00001000
26910- CREATE_SUSPENDED = 0x00000004
26911- CREATE_UNICODE_ENVIRONMENT = 0x00000400
26912- DEBUG_ONLY_THIS_PROCESS = 0x00000002
26913- DEBUG_PROCESS = 0x00000001
26914- DETACHED_PROCESS = 0x00000008
26915- EXTENDED_STARTUPINFO_PRESENT = 0x00080000
26916- INHERIT_PARENT_AFFINITY = 0x00010000
26917- )
26918-
26919- const (
26920- // flags for CreateToolhelp32Snapshot
26921- TH32CS_SNAPHEAPLIST = 0x01
26922- TH32CS_SNAPPROCESS = 0x02
26923- TH32CS_SNAPTHREAD = 0x04
26924- TH32CS_SNAPMODULE = 0x08
26925- TH32CS_SNAPMODULE32 = 0x10
26926- TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
26927- TH32CS_INHERIT = 0x80000000
26928- )
26929-
26930- const (
26931- // filters for ReadDirectoryChangesW
26932- FILE_NOTIFY_CHANGE_FILE_NAME = 0x001
26933- FILE_NOTIFY_CHANGE_DIR_NAME = 0x002
26934- FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x004
26935- FILE_NOTIFY_CHANGE_SIZE = 0x008
26936- FILE_NOTIFY_CHANGE_LAST_WRITE = 0x010
26937- FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020
26938- FILE_NOTIFY_CHANGE_CREATION = 0x040
26939- FILE_NOTIFY_CHANGE_SECURITY = 0x100
26940- )
26941-
26942- const (
26943- // do not reorder
26944- FILE_ACTION_ADDED = iota + 1
26945- FILE_ACTION_REMOVED
26946- FILE_ACTION_MODIFIED
26947- FILE_ACTION_RENAMED_OLD_NAME
26948- FILE_ACTION_RENAMED_NEW_NAME
26949- )
26950-
26951- const (
26952- // wincrypt.h
26953- PROV_RSA_FULL = 1
26954- PROV_RSA_SIG = 2
26955- PROV_DSS = 3
26956- PROV_FORTEZZA = 4
26957- PROV_MS_EXCHANGE = 5
26958- PROV_SSL = 6
26959- PROV_RSA_SCHANNEL = 12
26960- PROV_DSS_DH = 13
26961- PROV_EC_ECDSA_SIG = 14
26962- PROV_EC_ECNRA_SIG = 15
26963- PROV_EC_ECDSA_FULL = 16
26964- PROV_EC_ECNRA_FULL = 17
26965- PROV_DH_SCHANNEL = 18
26966- PROV_SPYRUS_LYNKS = 20
26967- PROV_RNG = 21
26968- PROV_INTEL_SEC = 22
26969- PROV_REPLACE_OWF = 23
26970- PROV_RSA_AES = 24
26971- CRYPT_VERIFYCONTEXT = 0xF0000000
26972- CRYPT_NEWKEYSET = 0x00000008
26973- CRYPT_DELETEKEYSET = 0x00000010
26974- CRYPT_MACHINE_KEYSET = 0x00000020
26975- CRYPT_SILENT = 0x00000040
26976- CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x00000080
26977-
26978- USAGE_MATCH_TYPE_AND = 0
26979- USAGE_MATCH_TYPE_OR = 1
26980-
26981- X509_ASN_ENCODING = 0x00000001
26982- PKCS_7_ASN_ENCODING = 0x00010000
26983-
26984- CERT_STORE_PROV_MEMORY = 2
26985-
26986- CERT_STORE_ADD_ALWAYS = 4
26987-
26988- CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004
26989-
26990- CERT_TRUST_NO_ERROR = 0x00000000
26991- CERT_TRUST_IS_NOT_TIME_VALID = 0x00000001
26992- CERT_TRUST_IS_REVOKED = 0x00000004
26993- CERT_TRUST_IS_NOT_SIGNATURE_VALID = 0x00000008
26994- CERT_TRUST_IS_NOT_VALID_FOR_USAGE = 0x00000010
26995- CERT_TRUST_IS_UNTRUSTED_ROOT = 0x00000020
26996- CERT_TRUST_REVOCATION_STATUS_UNKNOWN = 0x00000040
26997- CERT_TRUST_IS_CYCLIC = 0x00000080
26998- CERT_TRUST_INVALID_EXTENSION = 0x00000100
26999- CERT_TRUST_INVALID_POLICY_CONSTRAINTS = 0x00000200
27000- CERT_TRUST_INVALID_BASIC_CONSTRAINTS = 0x00000400
27001- CERT_TRUST_INVALID_NAME_CONSTRAINTS = 0x00000800
27002- CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 0x00001000
27003- CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT = 0x00002000
27004- CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000
27005- CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT = 0x00008000
27006- CERT_TRUST_IS_OFFLINE_REVOCATION = 0x01000000
27007- CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY = 0x02000000
27008- CERT_TRUST_IS_EXPLICIT_DISTRUST = 0x04000000
27009- CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT = 0x08000000
27010-
27011- CERT_CHAIN_POLICY_BASE = 1
27012- CERT_CHAIN_POLICY_AUTHENTICODE = 2
27013- CERT_CHAIN_POLICY_AUTHENTICODE_TS = 3
27014- CERT_CHAIN_POLICY_SSL = 4
27015- CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5
27016- CERT_CHAIN_POLICY_NT_AUTH = 6
27017- CERT_CHAIN_POLICY_MICROSOFT_ROOT = 7
27018- CERT_CHAIN_POLICY_EV = 8
27019-
27020- CERT_E_EXPIRED = 0x800B0101
27021- CERT_E_ROLE = 0x800B0103
27022- CERT_E_PURPOSE = 0x800B0106
27023- CERT_E_UNTRUSTEDROOT = 0x800B0109
27024- CERT_E_CN_NO_MATCH = 0x800B010F
27025-
27026- AUTHTYPE_CLIENT = 1
27027- AUTHTYPE_SERVER = 2
27028- )
27029-
27030- var (
27031- OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00")
27032- OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00")
27033- OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00")
27034- )
27035-
27036- // Invented values to support what package os expects.
27037- type Timeval struct {
27038- Sec int32
27039- Usec int32
27040- }
27041-
27042- func (tv *Timeval) Nanoseconds() int64 {
27043- return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3
27044- }
27045-
27046- func NsecToTimeval(nsec int64) (tv Timeval) {
27047- tv.Sec = int32(nsec / 1e9)
27048- tv.Usec = int32(nsec % 1e9 / 1e3)
27049- return
27050- }
27051-
27052- type SecurityAttributes struct {
27053- Length uint32
27054- SecurityDescriptor uintptr
27055- InheritHandle uint32
27056- }
27057-
27058- type Overlapped struct {
27059- Internal uintptr
27060- InternalHigh uintptr
27061- Offset uint32
27062- OffsetHigh uint32
27063- HEvent Handle
27064- }
27065-
27066- type FileNotifyInformation struct {
27067- NextEntryOffset uint32
27068- Action uint32
27069- FileNameLength uint32
27070- FileName uint16
27071- }
27072-
27073- type Filetime struct {
27074- LowDateTime uint32
27075- HighDateTime uint32
27076- }
27077-
27078- // Nanoseconds returns Filetime ft in nanoseconds
27079- // since Epoch (00:00:00 UTC, January 1, 1970).
27080- func (ft *Filetime) Nanoseconds() int64 {
27081- // 100-nanosecond intervals since January 1, 1601
27082- nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
27083- // change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
27084- nsec -= 116444736000000000
27085- // convert into nanoseconds
27086- nsec *= 100
27087- return nsec
27088- }
27089-
27090- func NsecToFiletime(nsec int64) (ft Filetime) {
27091- // convert into 100-nanosecond
27092- nsec /= 100
27093- // change starting time to January 1, 1601
27094- nsec += 116444736000000000
27095- // split into high / low
27096- ft.LowDateTime = uint32(nsec & 0xffffffff)
27097- ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff)
27098- return ft
27099- }
27100-
27101- type Win32finddata struct {
27102- FileAttributes uint32
27103- CreationTime Filetime
27104- LastAccessTime Filetime
27105- LastWriteTime Filetime
27106- FileSizeHigh uint32
27107- FileSizeLow uint32
27108- Reserved0 uint32
27109- Reserved1 uint32
27110- FileName [MAX_PATH - 1]uint16
27111- AlternateFileName [13]uint16
27112- }
27113-
27114- // This is the actual system call structure.
27115- // Win32finddata is what we committed to in Go 1.
27116- type win32finddata1 struct {
27117- FileAttributes uint32
27118- CreationTime Filetime
27119- LastAccessTime Filetime
27120- LastWriteTime Filetime
27121- FileSizeHigh uint32
27122- FileSizeLow uint32
27123- Reserved0 uint32
27124- Reserved1 uint32
27125- FileName [MAX_PATH]uint16
27126- AlternateFileName [14]uint16
27127- }
27128-
27129- func copyFindData(dst *Win32finddata, src *win32finddata1) {
27130- dst.FileAttributes = src.FileAttributes
27131- dst.CreationTime = src.CreationTime
27132- dst.LastAccessTime = src.LastAccessTime
27133- dst.LastWriteTime = src.LastWriteTime
27134- dst.FileSizeHigh = src.FileSizeHigh
27135- dst.FileSizeLow = src.FileSizeLow
27136- dst.Reserved0 = src.Reserved0
27137- dst.Reserved1 = src.Reserved1
27138-
27139- // The src is 1 element bigger than dst, but it must be NUL.
27140- copy(dst.FileName[:], src.FileName[:])
27141- copy(dst.AlternateFileName[:], src.AlternateFileName[:])
27142- }
27143-
27144- type ByHandleFileInformation struct {
27145- FileAttributes uint32
27146- CreationTime Filetime
27147- LastAccessTime Filetime
27148- LastWriteTime Filetime
27149- VolumeSerialNumber uint32
27150- FileSizeHigh uint32
27151- FileSizeLow uint32
27152- NumberOfLinks uint32
27153- FileIndexHigh uint32
27154- FileIndexLow uint32
27155- }
27156-
27157- const (
27158- GetFileExInfoStandard = 0
27159- GetFileExMaxInfoLevel = 1
27160- )
27161-
27162- type Win32FileAttributeData struct {
27163- FileAttributes uint32
27164- CreationTime Filetime
27165- LastAccessTime Filetime
27166- LastWriteTime Filetime
27167- FileSizeHigh uint32
27168- FileSizeLow uint32
27169- }
27170-
27171- // ShowWindow constants
27172- const (
27173- // winuser.h
27174- SW_HIDE = 0
27175- SW_NORMAL = 1
27176- SW_SHOWNORMAL = 1
27177- SW_SHOWMINIMIZED = 2
27178- SW_SHOWMAXIMIZED = 3
27179- SW_MAXIMIZE = 3
27180- SW_SHOWNOACTIVATE = 4
27181- SW_SHOW = 5
27182- SW_MINIMIZE = 6
27183- SW_SHOWMINNOACTIVE = 7
27184- SW_SHOWNA = 8
27185- SW_RESTORE = 9
27186- SW_SHOWDEFAULT = 10
27187- SW_FORCEMINIMIZE = 11
27188- )
27189-
27190- type StartupInfo struct {
27191- Cb uint32
27192- _ *uint16
27193- Desktop *uint16
27194- Title *uint16
27195- X uint32
27196- Y uint32
27197- XSize uint32
27198- YSize uint32
27199- XCountChars uint32
27200- YCountChars uint32
27201- FillAttribute uint32
27202- Flags uint32
27203- ShowWindow uint16
27204- _ uint16
27205- _ *byte
27206- StdInput Handle
27207- StdOutput Handle
27208- StdErr Handle
27209- }
27210-
27211- type ProcessInformation struct {
27212- Process Handle
27213- Thread Handle
27214- ProcessId uint32
27215- ThreadId uint32
27216- }
27217-
27218- type ProcessEntry32 struct {
27219- Size uint32
27220- Usage uint32
27221- ProcessID uint32
27222- DefaultHeapID uintptr
27223- ModuleID uint32
27224- Threads uint32
27225- ParentProcessID uint32
27226- PriClassBase int32
27227- Flags uint32
27228- ExeFile [MAX_PATH]uint16
27229- }
27230-
27231- type Systemtime struct {
27232- Year uint16
27233- Month uint16
27234- DayOfWeek uint16
27235- Day uint16
27236- Hour uint16
27237- Minute uint16
27238- Second uint16
27239- Milliseconds uint16
27240- }
27241-
27242- type Timezoneinformation struct {
27243- Bias int32
27244- StandardName [32]uint16
27245- StandardDate Systemtime
27246- StandardBias int32
27247- DaylightName [32]uint16
27248- DaylightDate Systemtime
27249- DaylightBias int32
27250- }
27251-
27252- // Socket related.
27253-
27254- const (
27255- AF_UNSPEC = 0
27256- AF_UNIX = 1
27257- AF_INET = 2
27258- AF_INET6 = 23
27259- AF_NETBIOS = 17
27260-
27261- SOCK_STREAM = 1
27262- SOCK_DGRAM = 2
27263- SOCK_RAW = 3
27264- SOCK_SEQPACKET = 5
27265-
27266- IPPROTO_IP = 0
27267- IPPROTO_IPV6 = 0x29
27268- IPPROTO_TCP = 6
27269- IPPROTO_UDP = 17
27270-
27271- SOL_SOCKET = 0xffff
27272- SO_REUSEADDR = 4
27273- SO_KEEPALIVE = 8
27274- SO_DONTROUTE = 16
27275- SO_BROADCAST = 32
27276- SO_LINGER = 128
27277- SO_RCVBUF = 0x1002
27278- SO_SNDBUF = 0x1001
27279- SO_UPDATE_ACCEPT_CONTEXT = 0x700b
27280- SO_UPDATE_CONNECT_CONTEXT = 0x7010
27281-
27282- IOC_OUT = 0x40000000
27283- IOC_IN = 0x80000000
27284- IOC_VENDOR = 0x18000000
27285- IOC_INOUT = IOC_IN | IOC_OUT
27286- IOC_WS2 = 0x08000000
27287- SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
27288- SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4
27289- SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12
27290-
27291- // cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
27292-
27293- IP_TOS = 0x3
27294- IP_TTL = 0x4
27295- IP_MULTICAST_IF = 0x9
27296- IP_MULTICAST_TTL = 0xa
27297- IP_MULTICAST_LOOP = 0xb
27298- IP_ADD_MEMBERSHIP = 0xc
27299- IP_DROP_MEMBERSHIP = 0xd
27300-
27301- IPV6_V6ONLY = 0x1b
27302- IPV6_UNICAST_HOPS = 0x4
27303- IPV6_MULTICAST_IF = 0x9
27304- IPV6_MULTICAST_HOPS = 0xa
27305- IPV6_MULTICAST_LOOP = 0xb
27306- IPV6_JOIN_GROUP = 0xc
27307- IPV6_LEAVE_GROUP = 0xd
27308-
27309- MSG_OOB = 0x1
27310- MSG_PEEK = 0x2
27311- MSG_DONTROUTE = 0x4
27312- MSG_WAITALL = 0x8
27313-
27314- MSG_TRUNC = 0x0100
27315- MSG_CTRUNC = 0x0200
27316- MSG_BCAST = 0x0400
27317- MSG_MCAST = 0x0800
27318-
27319- SOMAXCONN = 0x7fffffff
27320-
27321- TCP_NODELAY = 1
27322-
27323- SHUT_RD = 0
27324- SHUT_WR = 1
27325- SHUT_RDWR = 2
27326-
27327- WSADESCRIPTION_LEN = 256
27328- WSASYS_STATUS_LEN = 128
27329- )
27330-
27331- type WSABuf struct {
27332- Len uint32
27333- Buf *byte
27334- }
27335-
27336- type WSAMsg struct {
27337- Name *syscall.RawSockaddrAny
27338- Namelen int32
27339- Buffers *WSABuf
27340- BufferCount uint32
27341- Control WSABuf
27342- Flags uint32
27343- }
27344-
27345- // Invented values to support what package os expects.
27346- const (
27347- S_IFMT = 0x1f000
27348- S_IFIFO = 0x1000
27349- S_IFCHR = 0x2000
27350- S_IFDIR = 0x4000
27351- S_IFBLK = 0x6000
27352- S_IFREG = 0x8000
27353- S_IFLNK = 0xa000
27354- S_IFSOCK = 0xc000
27355- S_ISUID = 0x800
27356- S_ISGID = 0x400
27357- S_ISVTX = 0x200
27358- S_IRUSR = 0x100
27359- S_IWRITE = 0x80
27360- S_IWUSR = 0x80
27361- S_IXUSR = 0x40
27362- )
27363-
27364- const (
27365- FILE_TYPE_CHAR = 0x0002
27366- FILE_TYPE_DISK = 0x0001
27367- FILE_TYPE_PIPE = 0x0003
27368- FILE_TYPE_REMOTE = 0x8000
27369- FILE_TYPE_UNKNOWN = 0x0000
27370- )
27371-
27372- type Hostent struct {
27373- Name *byte
27374- Aliases **byte
27375- AddrType uint16
27376- Length uint16
27377- AddrList **byte
27378- }
27379-
27380- type Protoent struct {
27381- Name *byte
27382- Aliases **byte
27383- Proto uint16
27384- }
27385-
27386- const (
27387- DNS_TYPE_A = 0x0001
27388- DNS_TYPE_NS = 0x0002
27389- DNS_TYPE_MD = 0x0003
27390- DNS_TYPE_MF = 0x0004
27391- DNS_TYPE_CNAME = 0x0005
27392- DNS_TYPE_SOA = 0x0006
27393- DNS_TYPE_MB = 0x0007
27394- DNS_TYPE_MG = 0x0008
27395- DNS_TYPE_MR = 0x0009
27396- DNS_TYPE_NULL = 0x000a
27397- DNS_TYPE_WKS = 0x000b
27398- DNS_TYPE_PTR = 0x000c
27399- DNS_TYPE_HINFO = 0x000d
27400- DNS_TYPE_MINFO = 0x000e
27401- DNS_TYPE_MX = 0x000f
27402- DNS_TYPE_TEXT = 0x0010
27403- DNS_TYPE_RP = 0x0011
27404- DNS_TYPE_AFSDB = 0x0012
27405- DNS_TYPE_X25 = 0x0013
27406- DNS_TYPE_ISDN = 0x0014
27407- DNS_TYPE_RT = 0x0015
27408- DNS_TYPE_NSAP = 0x0016
27409- DNS_TYPE_NSAPPTR = 0x0017
27410- DNS_TYPE_SIG = 0x0018
27411- DNS_TYPE_KEY = 0x0019
27412- DNS_TYPE_PX = 0x001a
27413- DNS_TYPE_GPOS = 0x001b
27414- DNS_TYPE_AAAA = 0x001c
27415- DNS_TYPE_LOC = 0x001d
27416- DNS_TYPE_NXT = 0x001e
27417- DNS_TYPE_EID = 0x001f
27418- DNS_TYPE_NIMLOC = 0x0020
27419- DNS_TYPE_SRV = 0x0021
27420- DNS_TYPE_ATMA = 0x0022
27421- DNS_TYPE_NAPTR = 0x0023
27422- DNS_TYPE_KX = 0x0024
27423- DNS_TYPE_CERT = 0x0025
27424- DNS_TYPE_A6 = 0x0026
27425- DNS_TYPE_DNAME = 0x0027
27426- DNS_TYPE_SINK = 0x0028
27427- DNS_TYPE_OPT = 0x0029
27428- DNS_TYPE_DS = 0x002B
27429- DNS_TYPE_RRSIG = 0x002E
27430- DNS_TYPE_NSEC = 0x002F
27431- DNS_TYPE_DNSKEY = 0x0030
27432- DNS_TYPE_DHCID = 0x0031
27433- DNS_TYPE_UINFO = 0x0064
27434- DNS_TYPE_UID = 0x0065
27435- DNS_TYPE_GID = 0x0066
27436- DNS_TYPE_UNSPEC = 0x0067
27437- DNS_TYPE_ADDRS = 0x00f8
27438- DNS_TYPE_TKEY = 0x00f9
27439- DNS_TYPE_TSIG = 0x00fa
27440- DNS_TYPE_IXFR = 0x00fb
27441- DNS_TYPE_AXFR = 0x00fc
27442- DNS_TYPE_MAILB = 0x00fd
27443- DNS_TYPE_MAILA = 0x00fe
27444- DNS_TYPE_ALL = 0x00ff
27445- DNS_TYPE_ANY = 0x00ff
27446- DNS_TYPE_WINS = 0xff01
27447- DNS_TYPE_WINSR = 0xff02
27448- DNS_TYPE_NBSTAT = 0xff01
27449- )
27450-
27451- const (
27452- DNS_INFO_NO_RECORDS = 0x251D
27453- )
27454-
27455- const (
27456- // flags inside DNSRecord.Dw
27457- DnsSectionQuestion = 0x0000
27458- DnsSectionAnswer = 0x0001
27459- DnsSectionAuthority = 0x0002
27460- DnsSectionAdditional = 0x0003
27461- )
27462-
27463- type DNSSRVData struct {
27464- Target *uint16
27465- Priority uint16
27466- Weight uint16
27467- Port uint16
27468- Pad uint16
27469- }
27470-
27471- type DNSPTRData struct {
27472- Host *uint16
27473- }
27474-
27475- type DNSMXData struct {
27476- NameExchange *uint16
27477- Preference uint16
27478- Pad uint16
27479- }
27480-
27481- type DNSTXTData struct {
27482- StringCount uint16
27483- StringArray [1]*uint16
27484- }
27485-
27486- type DNSRecord struct {
27487- Next *DNSRecord
27488- Name *uint16
27489- Type uint16
27490- Length uint16
27491- Dw uint32
27492- Ttl uint32
27493- Reserved uint32
27494- Data [40]byte
27495- }
27496-
27497- const (
27498- TF_DISCONNECT = 1
27499- TF_REUSE_SOCKET = 2
27500- TF_WRITE_BEHIND = 4
27501- TF_USE_DEFAULT_WORKER = 0
27502- TF_USE_SYSTEM_THREAD = 16
27503- TF_USE_KERNEL_APC = 32
27504- )
27505-
27506- type TransmitFileBuffers struct {
27507- Head uintptr
27508- HeadLength uint32
27509- Tail uintptr
27510- TailLength uint32
27511- }
27512-
27513- const (
27514- IFF_UP = 1
27515- IFF_BROADCAST = 2
27516- IFF_LOOPBACK = 4
27517- IFF_POINTTOPOINT = 8
27518- IFF_MULTICAST = 16
27519- )
27520-
27521- const SIO_GET_INTERFACE_LIST = 0x4004747F
27522-
27523- // TODO(mattn): SockaddrGen is union of sockaddr/sockaddr_in/sockaddr_in6_old.
27524- // will be fixed to change variable type as suitable.
27525-
27526- type SockaddrGen [24]byte
27527-
27528- type InterfaceInfo struct {
27529- Flags uint32
27530- Address SockaddrGen
27531- BroadcastAddress SockaddrGen
27532- Netmask SockaddrGen
27533- }
27534-
27535- type IpAddressString struct {
27536- String [16]byte
27537- }
27538-
27539- type IpMaskString IpAddressString
27540-
27541- type IpAddrString struct {
27542- Next *IpAddrString
27543- IpAddress IpAddressString
27544- IpMask IpMaskString
27545- Context uint32
27546- }
27547-
27548- const MAX_ADAPTER_NAME_LENGTH = 256
27549- const MAX_ADAPTER_DESCRIPTION_LENGTH = 128
27550- const MAX_ADAPTER_ADDRESS_LENGTH = 8
27551-
27552- type IpAdapterInfo struct {
27553- Next *IpAdapterInfo
27554- ComboIndex uint32
27555- AdapterName [MAX_ADAPTER_NAME_LENGTH + 4]byte
27556- Description [MAX_ADAPTER_DESCRIPTION_LENGTH + 4]byte
27557- AddressLength uint32
27558- Address [MAX_ADAPTER_ADDRESS_LENGTH]byte
27559- Index uint32
27560- Type uint32
27561- DhcpEnabled uint32
27562- CurrentIpAddress *IpAddrString
27563- IpAddressList IpAddrString
27564- GatewayList IpAddrString
27565- DhcpServer IpAddrString
27566- HaveWins bool
27567- PrimaryWinsServer IpAddrString
27568- SecondaryWinsServer IpAddrString
27569- LeaseObtained int64
27570- LeaseExpires int64
27571- }
27572-
27573- const MAXLEN_PHYSADDR = 8
27574- const MAX_INTERFACE_NAME_LEN = 256
27575- const MAXLEN_IFDESCR = 256
27576-
27577- type MibIfRow struct {
27578- Name [MAX_INTERFACE_NAME_LEN]uint16
27579- Index uint32
27580- Type uint32
27581- Mtu uint32
27582- Speed uint32
27583- PhysAddrLen uint32
27584- PhysAddr [MAXLEN_PHYSADDR]byte
27585- AdminStatus uint32
27586- OperStatus uint32
27587- LastChange uint32
27588- InOctets uint32
27589- InUcastPkts uint32
27590- InNUcastPkts uint32
27591- InDiscards uint32
27592- InErrors uint32
27593- InUnknownProtos uint32
27594- OutOctets uint32
27595- OutUcastPkts uint32
27596- OutNUcastPkts uint32
27597- OutDiscards uint32
27598- OutErrors uint32
27599- OutQLen uint32
27600- DescrLen uint32
27601- Descr [MAXLEN_IFDESCR]byte
27602- }
27603-
27604- type CertContext struct {
27605- EncodingType uint32
27606- EncodedCert *byte
27607- Length uint32
27608- CertInfo uintptr
27609- Store Handle
27610- }
27611-
27612- type CertChainContext struct {
27613- Size uint32
27614- TrustStatus CertTrustStatus
27615- ChainCount uint32
27616- Chains **CertSimpleChain
27617- LowerQualityChainCount uint32
27618- LowerQualityChains **CertChainContext
27619- HasRevocationFreshnessTime uint32
27620- RevocationFreshnessTime uint32
27621- }
27622-
27623- type CertSimpleChain struct {
27624- Size uint32
27625- TrustStatus CertTrustStatus
27626- NumElements uint32
27627- Elements **CertChainElement
27628- TrustListInfo uintptr
27629- HasRevocationFreshnessTime uint32
27630- RevocationFreshnessTime uint32
27631- }
27632-
27633- type CertChainElement struct {
27634- Size uint32
27635- CertContext *CertContext
27636- TrustStatus CertTrustStatus
27637- RevocationInfo *CertRevocationInfo
27638- IssuanceUsage *CertEnhKeyUsage
27639- ApplicationUsage *CertEnhKeyUsage
27640- ExtendedErrorInfo *uint16
27641- }
27642-
27643- type CertRevocationInfo struct {
27644- Size uint32
27645- RevocationResult uint32
27646- RevocationOid *byte
27647- OidSpecificInfo uintptr
27648- HasFreshnessTime uint32
27649- FreshnessTime uint32
27650- CrlInfo uintptr // *CertRevocationCrlInfo
27651- }
27652-
27653- type CertTrustStatus struct {
27654- ErrorStatus uint32
27655- InfoStatus uint32
27656- }
27657-
27658- type CertUsageMatch struct {
27659- Type uint32
27660- Usage CertEnhKeyUsage
27661- }
27662-
27663- type CertEnhKeyUsage struct {
27664- Length uint32
27665- UsageIdentifiers **byte
27666- }
27667-
27668- type CertChainPara struct {
27669- Size uint32
27670- RequestedUsage CertUsageMatch
27671- RequstedIssuancePolicy CertUsageMatch
27672- URLRetrievalTimeout uint32
27673- CheckRevocationFreshnessTime uint32
27674- RevocationFreshnessTime uint32
27675- CacheResync *Filetime
27676- }
27677-
27678- type CertChainPolicyPara struct {
27679- Size uint32
27680- Flags uint32
27681- ExtraPolicyPara uintptr
27682- }
27683-
27684- type SSLExtraCertChainPolicyPara struct {
27685- Size uint32
27686- AuthType uint32
27687- Checks uint32
27688- ServerName *uint16
27689- }
27690-
27691- type CertChainPolicyStatus struct {
27692- Size uint32
27693- Error uint32
27694- ChainIndex uint32
27695- ElementIndex uint32
27696- ExtraPolicyStatus uintptr
27697- }
27698-
27699- const (
27700- // do not reorder
27701- HKEY_CLASSES_ROOT = 0x80000000 + iota
27702- HKEY_CURRENT_USER
27703- HKEY_LOCAL_MACHINE
27704- HKEY_USERS
27705- HKEY_PERFORMANCE_DATA
27706- HKEY_CURRENT_CONFIG
27707- HKEY_DYN_DATA
27708-
27709- KEY_QUERY_VALUE = 1
27710- KEY_SET_VALUE = 2
27711- KEY_CREATE_SUB_KEY = 4
27712- KEY_ENUMERATE_SUB_KEYS = 8
27713- KEY_NOTIFY = 16
27714- KEY_CREATE_LINK = 32
27715- KEY_WRITE = 0x20006
27716- KEY_EXECUTE = 0x20019
27717- KEY_READ = 0x20019
27718- KEY_WOW64_64KEY = 0x0100
27719- KEY_WOW64_32KEY = 0x0200
27720- KEY_ALL_ACCESS = 0xf003f
27721- )
27722-
27723- const (
27724- // do not reorder
27725- REG_NONE = iota
27726- REG_SZ
27727- REG_EXPAND_SZ
27728- REG_BINARY
27729- REG_DWORD_LITTLE_ENDIAN
27730- REG_DWORD_BIG_ENDIAN
27731- REG_LINK
27732- REG_MULTI_SZ
27733- REG_RESOURCE_LIST
27734- REG_FULL_RESOURCE_DESCRIPTOR
27735- REG_RESOURCE_REQUIREMENTS_LIST
27736- REG_QWORD_LITTLE_ENDIAN
27737- REG_DWORD = REG_DWORD_LITTLE_ENDIAN
27738- REG_QWORD = REG_QWORD_LITTLE_ENDIAN
27739- )
27740-
27741- type AddrinfoW struct {
27742- Flags int32
27743- Family int32
27744- Socktype int32
27745- Protocol int32
27746- Addrlen uintptr
27747- Canonname *uint16
27748- Addr uintptr
27749- Next *AddrinfoW
27750- }
27751-
27752- const (
27753- AI_PASSIVE = 1
27754- AI_CANONNAME = 2
27755- AI_NUMERICHOST = 4
27756- )
27757-
27758- type GUID struct {
27759- Data1 uint32
27760- Data2 uint16
27761- Data3 uint16
27762- Data4 [8]byte
27763- }
27764-
27765- var WSAID_CONNECTEX = GUID{
27766- 0x25a207b9,
27767- 0xddf3,
27768- 0x4660,
27769- [8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
27770- }
27771-
27772- var WSAID_WSASENDMSG = GUID{
27773- 0xa441e712,
27774- 0x754f,
27775- 0x43ca,
27776- [8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d},
27777- }
27778-
27779- var WSAID_WSARECVMSG = GUID{
27780- 0xf689d7c8,
27781- 0x6f1f,
27782- 0x436b,
27783- [8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22},
27784- }
27785-
27786- const (
27787- FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1
27788- FILE_SKIP_SET_EVENT_ON_HANDLE = 2
27789- )
27790-
27791- const (
27792- WSAPROTOCOL_LEN = 255
27793- MAX_PROTOCOL_CHAIN = 7
27794- BASE_PROTOCOL = 1
27795- LAYERED_PROTOCOL = 0
27796-
27797- XP1_CONNECTIONLESS = 0x00000001
27798- XP1_GUARANTEED_DELIVERY = 0x00000002
27799- XP1_GUARANTEED_ORDER = 0x00000004
27800- XP1_MESSAGE_ORIENTED = 0x00000008
27801- XP1_PSEUDO_STREAM = 0x00000010
27802- XP1_GRACEFUL_CLOSE = 0x00000020
27803- XP1_EXPEDITED_DATA = 0x00000040
27804- XP1_CONNECT_DATA = 0x00000080
27805- XP1_DISCONNECT_DATA = 0x00000100
27806- XP1_SUPPORT_BROADCAST = 0x00000200
27807- XP1_SUPPORT_MULTIPOINT = 0x00000400
27808- XP1_MULTIPOINT_CONTROL_PLANE = 0x00000800
27809- XP1_MULTIPOINT_DATA_PLANE = 0x00001000
27810- XP1_QOS_SUPPORTED = 0x00002000
27811- XP1_UNI_SEND = 0x00008000
27812- XP1_UNI_RECV = 0x00010000
27813- XP1_IFS_HANDLES = 0x00020000
27814- XP1_PARTIAL_MESSAGE = 0x00040000
27815- XP1_SAN_SUPPORT_SDP = 0x00080000
27816-
27817- PFL_MULTIPLE_PROTO_ENTRIES = 0x00000001
27818- PFL_RECOMMENDED_PROTO_ENTRY = 0x00000002
27819- PFL_HIDDEN = 0x00000004
27820- PFL_MATCHES_PROTOCOL_ZERO = 0x00000008
27821- PFL_NETWORKDIRECT_PROVIDER = 0x00000010
27822- )
27823-
27824- type WSAProtocolInfo struct {
27825- ServiceFlags1 uint32
27826- ServiceFlags2 uint32
27827- ServiceFlags3 uint32
27828- ServiceFlags4 uint32
27829- ProviderFlags uint32
27830- ProviderId GUID
27831- CatalogEntryId uint32
27832- ProtocolChain WSAProtocolChain
27833- Version int32
27834- AddressFamily int32
27835- MaxSockAddr int32
27836- MinSockAddr int32
27837- SocketType int32
27838- Protocol int32
27839- ProtocolMaxOffset int32
27840- NetworkByteOrder int32
27841- SecurityScheme int32
27842- MessageSize uint32
27843- ProviderReserved uint32
27844- ProtocolName [WSAPROTOCOL_LEN + 1]uint16
27845- }
27846-
27847- type WSAProtocolChain struct {
27848- ChainLen int32
27849- ChainEntries [MAX_PROTOCOL_CHAIN]uint32
27850- }
27851-
27852- type TCPKeepalive struct {
27853- OnOff uint32
27854- Time uint32
27855- Interval uint32
27856- }
27857-
27858- type symbolicLinkReparseBuffer struct {
27859- SubstituteNameOffset uint16
27860- SubstituteNameLength uint16
27861- PrintNameOffset uint16
27862- PrintNameLength uint16
27863- Flags uint32
27864- PathBuffer [1]uint16
27865- }
27866-
27867- type mountPointReparseBuffer struct {
27868- SubstituteNameOffset uint16
27869- SubstituteNameLength uint16
27870- PrintNameOffset uint16
27871- PrintNameLength uint16
27872- PathBuffer [1]uint16
27873- }
27874-
27875- type reparseDataBuffer struct {
27876- ReparseTag uint32
27877- ReparseDataLength uint16
27878- Reserved uint16
27879-
27880- // GenericReparseBuffer
27881- reparseBuffer byte
27882- }
27883-
27884- const (
27885- FSCTL_GET_REPARSE_POINT = 0x900A8
27886- MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024
27887- IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003
27888- IO_REPARSE_TAG_SYMLINK = 0xA000000C
27889- SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
27890- )
27891-
27892- const (
27893- ComputerNameNetBIOS = 0
27894- ComputerNameDnsHostname = 1
27895- ComputerNameDnsDomain = 2
27896- ComputerNameDnsFullyQualified = 3
27897- ComputerNamePhysicalNetBIOS = 4
27898- ComputerNamePhysicalDnsHostname = 5
27899- ComputerNamePhysicalDnsDomain = 6
27900- ComputerNamePhysicalDnsFullyQualified = 7
27901- ComputerNameMax = 8
27902- )
27903-
27904- const (
27905- MOVEFILE_REPLACE_EXISTING = 0x1
27906- MOVEFILE_COPY_ALLOWED = 0x2
27907- MOVEFILE_DELAY_UNTIL_REBOOT = 0x4
27908- MOVEFILE_WRITE_THROUGH = 0x8
27909- MOVEFILE_CREATE_HARDLINK = 0x10
27910- MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
27911- )
27912-
27913- const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
27914-
27915- const (
27916- IF_TYPE_OTHER = 1
27917- IF_TYPE_ETHERNET_CSMACD = 6
27918- IF_TYPE_ISO88025_TOKENRING = 9
27919- IF_TYPE_PPP = 23
27920- IF_TYPE_SOFTWARE_LOOPBACK = 24
27921- IF_TYPE_ATM = 37
27922- IF_TYPE_IEEE80211 = 71
27923- IF_TYPE_TUNNEL = 131
27924- IF_TYPE_IEEE1394 = 144
27925- )
27926-
27927- type SocketAddress struct {
27928- Sockaddr *syscall.RawSockaddrAny
27929- SockaddrLength int32
27930- }
27931-
27932- type IpAdapterUnicastAddress struct {
27933- Length uint32
27934- Flags uint32
27935- Next *IpAdapterUnicastAddress
27936- Address SocketAddress
27937- PrefixOrigin int32
27938- SuffixOrigin int32
27939- DadState int32
27940- ValidLifetime uint32
27941- PreferredLifetime uint32
27942- LeaseLifetime uint32
27943- OnLinkPrefixLength uint8
27944- }
27945-
27946- type IpAdapterAnycastAddress struct {
27947- Length uint32
27948- Flags uint32
27949- Next *IpAdapterAnycastAddress
27950- Address SocketAddress
27951- }
27952-
27953- type IpAdapterMulticastAddress struct {
27954- Length uint32
27955- Flags uint32
27956- Next *IpAdapterMulticastAddress
27957- Address SocketAddress
27958- }
27959-
27960- type IpAdapterDnsServerAdapter struct {
27961- Length uint32
27962- Reserved uint32
27963- Next *IpAdapterDnsServerAdapter
27964- Address SocketAddress
27965- }
27966-
27967- type IpAdapterPrefix struct {
27968- Length uint32
27969- Flags uint32
27970- Next *IpAdapterPrefix
27971- Address SocketAddress
27972- PrefixLength uint32
27973- }
27974-
27975- type IpAdapterAddresses struct {
27976- Length uint32
27977- IfIndex uint32
27978- Next *IpAdapterAddresses
27979- AdapterName *byte
27980- FirstUnicastAddress *IpAdapterUnicastAddress
27981- FirstAnycastAddress *IpAdapterAnycastAddress
27982- FirstMulticastAddress *IpAdapterMulticastAddress
27983- FirstDnsServerAddress *IpAdapterDnsServerAdapter
27984- DnsSuffix *uint16
27985- Description *uint16
27986- FriendlyName *uint16
27987- PhysicalAddress [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
27988- PhysicalAddressLength uint32
27989- Flags uint32
27990- Mtu uint32
27991- IfType uint32
27992- OperStatus uint32
27993- Ipv6IfIndex uint32
27994- ZoneIndices [16]uint32
27995- FirstPrefix *IpAdapterPrefix
27996- /* more fields might be present here. */
27997- }
27998-
27999- const (
28000- IfOperStatusUp = 1
28001- IfOperStatusDown = 2
28002- IfOperStatusTesting = 3
28003- IfOperStatusUnknown = 4
28004- IfOperStatusDormant = 5
28005- IfOperStatusNotPresent = 6
28006- IfOperStatusLowerLayerDown = 7
28007- )
28008-
28009- // Console related constants used for the mode parameter to SetConsoleMode. See
28010- // https://docs.microsoft.com/en-us/windows/console/setconsolemode for details.
28011-
28012- const (
28013- ENABLE_PROCESSED_INPUT = 0x1
28014- ENABLE_LINE_INPUT = 0x2
28015- ENABLE_ECHO_INPUT = 0x4
28016- ENABLE_WINDOW_INPUT = 0x8
28017- ENABLE_MOUSE_INPUT = 0x10
28018- ENABLE_INSERT_MODE = 0x20
28019- ENABLE_QUICK_EDIT_MODE = 0x40
28020- ENABLE_EXTENDED_FLAGS = 0x80
28021- ENABLE_AUTO_POSITION = 0x100
28022- ENABLE_VIRTUAL_TERMINAL_INPUT = 0x200
28023-
28024- ENABLE_PROCESSED_OUTPUT = 0x1
28025- ENABLE_WRAP_AT_EOL_OUTPUT = 0x2
28026- ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
28027- DISABLE_NEWLINE_AUTO_RETURN = 0x8
28028- ENABLE_LVB_GRID_WORLDWIDE = 0x10
28029- )
28030-
28031- type Coord struct {
28032- X int16
28033- Y int16
28034- }
28035-
28036- type SmallRect struct {
28037- Left int16
28038- Top int16
28039- Right int16
28040- Bottom int16
28041- }
28042-
28043- // Used with GetConsoleScreenBuffer to retreive information about a console
28044- // screen buffer. See
28045- // https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str
28046- // for details.
28047-
28048- type ConsoleScreenBufferInfo struct {
28049- Size Coord
28050- CursorPosition Coord
28051- Attributes uint16
28052- Window SmallRect
28053- MaximumWindowSize Coord
28054- }
28055 diff --git a/vendor/golang.org/x/sys/windows/types_windows_386.go b/vendor/golang.org/x/sys/windows/types_windows_386.go
28056deleted file mode 100644
28057index fe0ddd0..0000000
28058--- a/vendor/golang.org/x/sys/windows/types_windows_386.go
28059+++ /dev/null
28060 @@ -1,22 +0,0 @@
28061- // Copyright 2011 The Go Authors. All rights reserved.
28062- // Use of this source code is governed by a BSD-style
28063- // license that can be found in the LICENSE file.
28064-
28065- package windows
28066-
28067- type WSAData struct {
28068- Version uint16
28069- HighVersion uint16
28070- Description [WSADESCRIPTION_LEN + 1]byte
28071- SystemStatus [WSASYS_STATUS_LEN + 1]byte
28072- MaxSockets uint16
28073- MaxUdpDg uint16
28074- VendorInfo *byte
28075- }
28076-
28077- type Servent struct {
28078- Name *byte
28079- Aliases **byte
28080- Port uint16
28081- Proto *byte
28082- }
28083 diff --git a/vendor/golang.org/x/sys/windows/types_windows_amd64.go b/vendor/golang.org/x/sys/windows/types_windows_amd64.go
28084deleted file mode 100644
28085index 7e154c2..0000000
28086--- a/vendor/golang.org/x/sys/windows/types_windows_amd64.go
28087+++ /dev/null
28088 @@ -1,22 +0,0 @@
28089- // Copyright 2011 The Go Authors. All rights reserved.
28090- // Use of this source code is governed by a BSD-style
28091- // license that can be found in the LICENSE file.
28092-
28093- package windows
28094-
28095- type WSAData struct {
28096- Version uint16
28097- HighVersion uint16
28098- MaxSockets uint16
28099- MaxUdpDg uint16
28100- VendorInfo *byte
28101- Description [WSADESCRIPTION_LEN + 1]byte
28102- SystemStatus [WSASYS_STATUS_LEN + 1]byte
28103- }
28104-
28105- type Servent struct {
28106- Name *byte
28107- Aliases **byte
28108- Proto *byte
28109- Port uint16
28110- }
28111 diff --git a/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/zsyscall_windows.go
28112deleted file mode 100644
28113index c7b3b15..0000000
28114--- a/vendor/golang.org/x/sys/windows/zsyscall_windows.go
28115+++ /dev/null
28116 @@ -1,2687 +0,0 @@
28117- // MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
28118-
28119- package windows
28120-
28121- import (
28122- "syscall"
28123- "unsafe"
28124- )
28125-
28126- var _ unsafe.Pointer
28127-
28128- // Do the interface allocations only once for common
28129- // Errno values.
28130- const (
28131- errnoERROR_IO_PENDING = 997
28132- )
28133-
28134- var (
28135- errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
28136- )
28137-
28138- // errnoErr returns common boxed Errno values, to prevent
28139- // allocations at runtime.
28140- func errnoErr(e syscall.Errno) error {
28141- switch e {
28142- case 0:
28143- return nil
28144- case errnoERROR_IO_PENDING:
28145- return errERROR_IO_PENDING
28146- }
28147- // TODO: add more here, after collecting data on the common
28148- // error values see on Windows. (perhaps when running
28149- // all.bat?)
28150- return e
28151- }
28152-
28153- var (
28154- modadvapi32 = NewLazySystemDLL("advapi32.dll")
28155- modkernel32 = NewLazySystemDLL("kernel32.dll")
28156- modshell32 = NewLazySystemDLL("shell32.dll")
28157- modmswsock = NewLazySystemDLL("mswsock.dll")
28158- modcrypt32 = NewLazySystemDLL("crypt32.dll")
28159- modws2_32 = NewLazySystemDLL("ws2_32.dll")
28160- moddnsapi = NewLazySystemDLL("dnsapi.dll")
28161- modiphlpapi = NewLazySystemDLL("iphlpapi.dll")
28162- modsecur32 = NewLazySystemDLL("secur32.dll")
28163- modnetapi32 = NewLazySystemDLL("netapi32.dll")
28164- moduserenv = NewLazySystemDLL("userenv.dll")
28165-
28166- procRegisterEventSourceW = modadvapi32.NewProc("RegisterEventSourceW")
28167- procDeregisterEventSource = modadvapi32.NewProc("DeregisterEventSource")
28168- procReportEventW = modadvapi32.NewProc("ReportEventW")
28169- procOpenSCManagerW = modadvapi32.NewProc("OpenSCManagerW")
28170- procCloseServiceHandle = modadvapi32.NewProc("CloseServiceHandle")
28171- procCreateServiceW = modadvapi32.NewProc("CreateServiceW")
28172- procOpenServiceW = modadvapi32.NewProc("OpenServiceW")
28173- procDeleteService = modadvapi32.NewProc("DeleteService")
28174- procStartServiceW = modadvapi32.NewProc("StartServiceW")
28175- procQueryServiceStatus = modadvapi32.NewProc("QueryServiceStatus")
28176- procControlService = modadvapi32.NewProc("ControlService")
28177- procStartServiceCtrlDispatcherW = modadvapi32.NewProc("StartServiceCtrlDispatcherW")
28178- procSetServiceStatus = modadvapi32.NewProc("SetServiceStatus")
28179- procChangeServiceConfigW = modadvapi32.NewProc("ChangeServiceConfigW")
28180- procQueryServiceConfigW = modadvapi32.NewProc("QueryServiceConfigW")
28181- procChangeServiceConfig2W = modadvapi32.NewProc("ChangeServiceConfig2W")
28182- procQueryServiceConfig2W = modadvapi32.NewProc("QueryServiceConfig2W")
28183- procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW")
28184- procGetLastError = modkernel32.NewProc("GetLastError")
28185- procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
28186- procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW")
28187- procFreeLibrary = modkernel32.NewProc("FreeLibrary")
28188- procGetProcAddress = modkernel32.NewProc("GetProcAddress")
28189- procGetVersion = modkernel32.NewProc("GetVersion")
28190- procFormatMessageW = modkernel32.NewProc("FormatMessageW")
28191- procExitProcess = modkernel32.NewProc("ExitProcess")
28192- procCreateFileW = modkernel32.NewProc("CreateFileW")
28193- procReadFile = modkernel32.NewProc("ReadFile")
28194- procWriteFile = modkernel32.NewProc("WriteFile")
28195- procSetFilePointer = modkernel32.NewProc("SetFilePointer")
28196- procCloseHandle = modkernel32.NewProc("CloseHandle")
28197- procGetStdHandle = modkernel32.NewProc("GetStdHandle")
28198- procSetStdHandle = modkernel32.NewProc("SetStdHandle")
28199- procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
28200- procFindNextFileW = modkernel32.NewProc("FindNextFileW")
28201- procFindClose = modkernel32.NewProc("FindClose")
28202- procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
28203- procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW")
28204- procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
28205- procCreateDirectoryW = modkernel32.NewProc("CreateDirectoryW")
28206- procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
28207- procDeleteFileW = modkernel32.NewProc("DeleteFileW")
28208- procMoveFileW = modkernel32.NewProc("MoveFileW")
28209- procMoveFileExW = modkernel32.NewProc("MoveFileExW")
28210- procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
28211- procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
28212- procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
28213- procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
28214- procGetSystemTimePreciseAsFileTime = modkernel32.NewProc("GetSystemTimePreciseAsFileTime")
28215- procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
28216- procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
28217- procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
28218- procPostQueuedCompletionStatus = modkernel32.NewProc("PostQueuedCompletionStatus")
28219- procCancelIo = modkernel32.NewProc("CancelIo")
28220- procCancelIoEx = modkernel32.NewProc("CancelIoEx")
28221- procCreateProcessW = modkernel32.NewProc("CreateProcessW")
28222- procOpenProcess = modkernel32.NewProc("OpenProcess")
28223- procTerminateProcess = modkernel32.NewProc("TerminateProcess")
28224- procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
28225- procGetStartupInfoW = modkernel32.NewProc("GetStartupInfoW")
28226- procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
28227- procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
28228- procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
28229- procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
28230- procGetTempPathW = modkernel32.NewProc("GetTempPathW")
28231- procCreatePipe = modkernel32.NewProc("CreatePipe")
28232- procGetFileType = modkernel32.NewProc("GetFileType")
28233- procCryptAcquireContextW = modadvapi32.NewProc("CryptAcquireContextW")
28234- procCryptReleaseContext = modadvapi32.NewProc("CryptReleaseContext")
28235- procCryptGenRandom = modadvapi32.NewProc("CryptGenRandom")
28236- procGetEnvironmentStringsW = modkernel32.NewProc("GetEnvironmentStringsW")
28237- procFreeEnvironmentStringsW = modkernel32.NewProc("FreeEnvironmentStringsW")
28238- procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
28239- procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW")
28240- procSetFileTime = modkernel32.NewProc("SetFileTime")
28241- procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
28242- procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
28243- procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
28244- procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
28245- procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
28246- procLocalFree = modkernel32.NewProc("LocalFree")
28247- procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
28248- procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
28249- procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
28250- procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
28251- procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
28252- procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
28253- procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
28254- procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
28255- procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
28256- procVirtualLock = modkernel32.NewProc("VirtualLock")
28257- procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
28258- procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
28259- procVirtualFree = modkernel32.NewProc("VirtualFree")
28260- procVirtualProtect = modkernel32.NewProc("VirtualProtect")
28261- procTransmitFile = modmswsock.NewProc("TransmitFile")
28262- procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
28263- procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
28264- procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
28265- procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
28266- procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
28267- procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
28268- procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
28269- procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
28270- procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
28271- procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
28272- procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
28273- procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
28274- procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
28275- procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
28276- procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
28277- procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
28278- procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
28279- procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
28280- procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
28281- procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
28282- procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
28283- procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
28284- procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
28285- procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
28286- procProcess32NextW = modkernel32.NewProc("Process32NextW")
28287- procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
28288- procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
28289- procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
28290- procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
28291- procCreateEventW = modkernel32.NewProc("CreateEventW")
28292- procCreateEventExW = modkernel32.NewProc("CreateEventExW")
28293- procOpenEventW = modkernel32.NewProc("OpenEventW")
28294- procSetEvent = modkernel32.NewProc("SetEvent")
28295- procResetEvent = modkernel32.NewProc("ResetEvent")
28296- procPulseEvent = modkernel32.NewProc("PulseEvent")
28297- procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW")
28298- procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW")
28299- procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW")
28300- procFindFirstVolumeMountPointW = modkernel32.NewProc("FindFirstVolumeMountPointW")
28301- procFindNextVolumeW = modkernel32.NewProc("FindNextVolumeW")
28302- procFindNextVolumeMountPointW = modkernel32.NewProc("FindNextVolumeMountPointW")
28303- procFindVolumeClose = modkernel32.NewProc("FindVolumeClose")
28304- procFindVolumeMountPointClose = modkernel32.NewProc("FindVolumeMountPointClose")
28305- procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW")
28306- procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives")
28307- procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW")
28308- procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
28309- procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW")
28310- procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
28311- procGetVolumePathNameW = modkernel32.NewProc("GetVolumePathNameW")
28312- procGetVolumePathNamesForVolumeNameW = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW")
28313- procQueryDosDeviceW = modkernel32.NewProc("QueryDosDeviceW")
28314- procSetVolumeLabelW = modkernel32.NewProc("SetVolumeLabelW")
28315- procSetVolumeMountPointW = modkernel32.NewProc("SetVolumeMountPointW")
28316- procWSAStartup = modws2_32.NewProc("WSAStartup")
28317- procWSACleanup = modws2_32.NewProc("WSACleanup")
28318- procWSAIoctl = modws2_32.NewProc("WSAIoctl")
28319- procsocket = modws2_32.NewProc("socket")
28320- procsetsockopt = modws2_32.NewProc("setsockopt")
28321- procgetsockopt = modws2_32.NewProc("getsockopt")
28322- procbind = modws2_32.NewProc("bind")
28323- procconnect = modws2_32.NewProc("connect")
28324- procgetsockname = modws2_32.NewProc("getsockname")
28325- procgetpeername = modws2_32.NewProc("getpeername")
28326- proclisten = modws2_32.NewProc("listen")
28327- procshutdown = modws2_32.NewProc("shutdown")
28328- procclosesocket = modws2_32.NewProc("closesocket")
28329- procAcceptEx = modmswsock.NewProc("AcceptEx")
28330- procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
28331- procWSARecv = modws2_32.NewProc("WSARecv")
28332- procWSASend = modws2_32.NewProc("WSASend")
28333- procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
28334- procWSASendTo = modws2_32.NewProc("WSASendTo")
28335- procgethostbyname = modws2_32.NewProc("gethostbyname")
28336- procgetservbyname = modws2_32.NewProc("getservbyname")
28337- procntohs = modws2_32.NewProc("ntohs")
28338- procgetprotobyname = modws2_32.NewProc("getprotobyname")
28339- procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
28340- procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
28341- procDnsNameCompare_W = moddnsapi.NewProc("DnsNameCompare_W")
28342- procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
28343- procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
28344- procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
28345- procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
28346- procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
28347- procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
28348- procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
28349- procGetACP = modkernel32.NewProc("GetACP")
28350- procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
28351- procTranslateNameW = modsecur32.NewProc("TranslateNameW")
28352- procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
28353- procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
28354- procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
28355- procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
28356- procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
28357- procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
28358- procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
28359- procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
28360- procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
28361- procCopySid = modadvapi32.NewProc("CopySid")
28362- procAllocateAndInitializeSid = modadvapi32.NewProc("AllocateAndInitializeSid")
28363- procFreeSid = modadvapi32.NewProc("FreeSid")
28364- procEqualSid = modadvapi32.NewProc("EqualSid")
28365- procCheckTokenMembership = modadvapi32.NewProc("CheckTokenMembership")
28366- procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
28367- procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
28368- procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
28369- )
28370-
28371- func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
28372- r0, _, e1 := syscall.Syscall(procRegisterEventSourceW.Addr(), 2, uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName)), 0)
28373- handle = Handle(r0)
28374- if handle == 0 {
28375- if e1 != 0 {
28376- err = errnoErr(e1)
28377- } else {
28378- err = syscall.EINVAL
28379- }
28380- }
28381- return
28382- }
28383-
28384- func DeregisterEventSource(handle Handle) (err error) {
28385- r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0)
28386- if r1 == 0 {
28387- if e1 != 0 {
28388- err = errnoErr(e1)
28389- } else {
28390- err = syscall.EINVAL
28391- }
28392- }
28393- return
28394- }
28395-
28396- func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) {
28397- r1, _, e1 := syscall.Syscall9(procReportEventW.Addr(), 9, uintptr(log), uintptr(etype), uintptr(category), uintptr(eventId), uintptr(usrSId), uintptr(numStrings), uintptr(dataSize), uintptr(unsafe.Pointer(strings)), uintptr(unsafe.Pointer(rawData)))
28398- if r1 == 0 {
28399- if e1 != 0 {
28400- err = errnoErr(e1)
28401- } else {
28402- err = syscall.EINVAL
28403- }
28404- }
28405- return
28406- }
28407-
28408- func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) {
28409- r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
28410- handle = Handle(r0)
28411- if handle == 0 {
28412- if e1 != 0 {
28413- err = errnoErr(e1)
28414- } else {
28415- err = syscall.EINVAL
28416- }
28417- }
28418- return
28419- }
28420-
28421- func CloseServiceHandle(handle Handle) (err error) {
28422- r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0)
28423- if r1 == 0 {
28424- if e1 != 0 {
28425- err = errnoErr(e1)
28426- } else {
28427- err = syscall.EINVAL
28428- }
28429- }
28430- return
28431- }
28432-
28433- func CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) {
28434- r0, _, e1 := syscall.Syscall15(procCreateServiceW.Addr(), 13, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(unsafe.Pointer(displayName)), uintptr(access), uintptr(srvType), uintptr(startType), uintptr(errCtl), uintptr(unsafe.Pointer(pathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), 0, 0)
28435- handle = Handle(r0)
28436- if handle == 0 {
28437- if e1 != 0 {
28438- err = errnoErr(e1)
28439- } else {
28440- err = syscall.EINVAL
28441- }
28442- }
28443- return
28444- }
28445-
28446- func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) {
28447- r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
28448- handle = Handle(r0)
28449- if handle == 0 {
28450- if e1 != 0 {
28451- err = errnoErr(e1)
28452- } else {
28453- err = syscall.EINVAL
28454- }
28455- }
28456- return
28457- }
28458-
28459- func DeleteService(service Handle) (err error) {
28460- r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0)
28461- if r1 == 0 {
28462- if e1 != 0 {
28463- err = errnoErr(e1)
28464- } else {
28465- err = syscall.EINVAL
28466- }
28467- }
28468- return
28469- }
28470-
28471- func StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) {
28472- r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors)))
28473- if r1 == 0 {
28474- if e1 != 0 {
28475- err = errnoErr(e1)
28476- } else {
28477- err = syscall.EINVAL
28478- }
28479- }
28480- return
28481- }
28482-
28483- func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) {
28484- r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0)
28485- if r1 == 0 {
28486- if e1 != 0 {
28487- err = errnoErr(e1)
28488- } else {
28489- err = syscall.EINVAL
28490- }
28491- }
28492- return
28493- }
28494-
28495- func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) {
28496- r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status)))
28497- if r1 == 0 {
28498- if e1 != 0 {
28499- err = errnoErr(e1)
28500- } else {
28501- err = syscall.EINVAL
28502- }
28503- }
28504- return
28505- }
28506-
28507- func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) {
28508- r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0)
28509- if r1 == 0 {
28510- if e1 != 0 {
28511- err = errnoErr(e1)
28512- } else {
28513- err = syscall.EINVAL
28514- }
28515- }
28516- return
28517- }
28518-
28519- func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) {
28520- r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0)
28521- if r1 == 0 {
28522- if e1 != 0 {
28523- err = errnoErr(e1)
28524- } else {
28525- err = syscall.EINVAL
28526- }
28527- }
28528- return
28529- }
28530-
28531- func ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) {
28532- r1, _, e1 := syscall.Syscall12(procChangeServiceConfigW.Addr(), 11, uintptr(service), uintptr(serviceType), uintptr(startType), uintptr(errorControl), uintptr(unsafe.Pointer(binaryPathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), uintptr(unsafe.Pointer(displayName)), 0)
28533- if r1 == 0 {
28534- if e1 != 0 {
28535- err = errnoErr(e1)
28536- } else {
28537- err = syscall.EINVAL
28538- }
28539- }
28540- return
28541- }
28542-
28543- func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) {
28544- r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0)
28545- if r1 == 0 {
28546- if e1 != 0 {
28547- err = errnoErr(e1)
28548- } else {
28549- err = syscall.EINVAL
28550- }
28551- }
28552- return
28553- }
28554-
28555- func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) {
28556- r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info)))
28557- if r1 == 0 {
28558- if e1 != 0 {
28559- err = errnoErr(e1)
28560- } else {
28561- err = syscall.EINVAL
28562- }
28563- }
28564- return
28565- }
28566-
28567- func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
28568- r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
28569- if r1 == 0 {
28570- if e1 != 0 {
28571- err = errnoErr(e1)
28572- } else {
28573- err = syscall.EINVAL
28574- }
28575- }
28576- return
28577- }
28578-
28579- func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) {
28580- r1, _, e1 := syscall.Syscall12(procEnumServicesStatusExW.Addr(), 10, uintptr(mgr), uintptr(infoLevel), uintptr(serviceType), uintptr(serviceState), uintptr(unsafe.Pointer(services)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned)), uintptr(unsafe.Pointer(resumeHandle)), uintptr(unsafe.Pointer(groupName)), 0, 0)
28581- if r1 == 0 {
28582- if e1 != 0 {
28583- err = errnoErr(e1)
28584- } else {
28585- err = syscall.EINVAL
28586- }
28587- }
28588- return
28589- }
28590-
28591- func GetLastError() (lasterr error) {
28592- r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
28593- if r0 != 0 {
28594- lasterr = syscall.Errno(r0)
28595- }
28596- return
28597- }
28598-
28599- func LoadLibrary(libname string) (handle Handle, err error) {
28600- var _p0 *uint16
28601- _p0, err = syscall.UTF16PtrFromString(libname)
28602- if err != nil {
28603- return
28604- }
28605- return _LoadLibrary(_p0)
28606- }
28607-
28608- func _LoadLibrary(libname *uint16) (handle Handle, err error) {
28609- r0, _, e1 := syscall.Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0)
28610- handle = Handle(r0)
28611- if handle == 0 {
28612- if e1 != 0 {
28613- err = errnoErr(e1)
28614- } else {
28615- err = syscall.EINVAL
28616- }
28617- }
28618- return
28619- }
28620-
28621- func LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, err error) {
28622- var _p0 *uint16
28623- _p0, err = syscall.UTF16PtrFromString(libname)
28624- if err != nil {
28625- return
28626- }
28627- return _LoadLibraryEx(_p0, zero, flags)
28628- }
28629-
28630- func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, err error) {
28631- r0, _, e1 := syscall.Syscall(procLoadLibraryExW.Addr(), 3, uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags))
28632- handle = Handle(r0)
28633- if handle == 0 {
28634- if e1 != 0 {
28635- err = errnoErr(e1)
28636- } else {
28637- err = syscall.EINVAL
28638- }
28639- }
28640- return
28641- }
28642-
28643- func FreeLibrary(handle Handle) (err error) {
28644- r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
28645- if r1 == 0 {
28646- if e1 != 0 {
28647- err = errnoErr(e1)
28648- } else {
28649- err = syscall.EINVAL
28650- }
28651- }
28652- return
28653- }
28654-
28655- func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
28656- var _p0 *byte
28657- _p0, err = syscall.BytePtrFromString(procname)
28658- if err != nil {
28659- return
28660- }
28661- return _GetProcAddress(module, _p0)
28662- }
28663-
28664- func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
28665- r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0)
28666- proc = uintptr(r0)
28667- if proc == 0 {
28668- if e1 != 0 {
28669- err = errnoErr(e1)
28670- } else {
28671- err = syscall.EINVAL
28672- }
28673- }
28674- return
28675- }
28676-
28677- func GetVersion() (ver uint32, err error) {
28678- r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
28679- ver = uint32(r0)
28680- if ver == 0 {
28681- if e1 != 0 {
28682- err = errnoErr(e1)
28683- } else {
28684- err = syscall.EINVAL
28685- }
28686- }
28687- return
28688- }
28689-
28690- func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
28691- var _p0 *uint16
28692- if len(buf) > 0 {
28693- _p0 = &buf[0]
28694- }
28695- r0, _, e1 := syscall.Syscall9(procFormatMessageW.Addr(), 7, uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args)), 0, 0)
28696- n = uint32(r0)
28697- if n == 0 {
28698- if e1 != 0 {
28699- err = errnoErr(e1)
28700- } else {
28701- err = syscall.EINVAL
28702- }
28703- }
28704- return
28705- }
28706-
28707- func ExitProcess(exitcode uint32) {
28708- syscall.Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
28709- return
28710- }
28711-
28712- func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) {
28713- r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
28714- handle = Handle(r0)
28715- if handle == InvalidHandle {
28716- if e1 != 0 {
28717- err = errnoErr(e1)
28718- } else {
28719- err = syscall.EINVAL
28720- }
28721- }
28722- return
28723- }
28724-
28725- func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
28726- var _p0 *byte
28727- if len(buf) > 0 {
28728- _p0 = &buf[0]
28729- }
28730- r1, _, e1 := syscall.Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
28731- if r1 == 0 {
28732- if e1 != 0 {
28733- err = errnoErr(e1)
28734- } else {
28735- err = syscall.EINVAL
28736- }
28737- }
28738- return
28739- }
28740-
28741- func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
28742- var _p0 *byte
28743- if len(buf) > 0 {
28744- _p0 = &buf[0]
28745- }
28746- r1, _, e1 := syscall.Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
28747- if r1 == 0 {
28748- if e1 != 0 {
28749- err = errnoErr(e1)
28750- } else {
28751- err = syscall.EINVAL
28752- }
28753- }
28754- return
28755- }
28756-
28757- func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
28758- r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
28759- newlowoffset = uint32(r0)
28760- if newlowoffset == 0xffffffff {
28761- if e1 != 0 {
28762- err = errnoErr(e1)
28763- } else {
28764- err = syscall.EINVAL
28765- }
28766- }
28767- return
28768- }
28769-
28770- func CloseHandle(handle Handle) (err error) {
28771- r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
28772- if r1 == 0 {
28773- if e1 != 0 {
28774- err = errnoErr(e1)
28775- } else {
28776- err = syscall.EINVAL
28777- }
28778- }
28779- return
28780- }
28781-
28782- func GetStdHandle(stdhandle uint32) (handle Handle, err error) {
28783- r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
28784- handle = Handle(r0)
28785- if handle == InvalidHandle {
28786- if e1 != 0 {
28787- err = errnoErr(e1)
28788- } else {
28789- err = syscall.EINVAL
28790- }
28791- }
28792- return
28793- }
28794-
28795- func SetStdHandle(stdhandle uint32, handle Handle) (err error) {
28796- r1, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
28797- if r1 == 0 {
28798- if e1 != 0 {
28799- err = errnoErr(e1)
28800- } else {
28801- err = syscall.EINVAL
28802- }
28803- }
28804- return
28805- }
28806-
28807- func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
28808- r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
28809- handle = Handle(r0)
28810- if handle == InvalidHandle {
28811- if e1 != 0 {
28812- err = errnoErr(e1)
28813- } else {
28814- err = syscall.EINVAL
28815- }
28816- }
28817- return
28818- }
28819-
28820- func findNextFile1(handle Handle, data *win32finddata1) (err error) {
28821- r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
28822- if r1 == 0 {
28823- if e1 != 0 {
28824- err = errnoErr(e1)
28825- } else {
28826- err = syscall.EINVAL
28827- }
28828- }
28829- return
28830- }
28831-
28832- func FindClose(handle Handle) (err error) {
28833- r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
28834- if r1 == 0 {
28835- if e1 != 0 {
28836- err = errnoErr(e1)
28837- } else {
28838- err = syscall.EINVAL
28839- }
28840- }
28841- return
28842- }
28843-
28844- func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
28845- r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
28846- if r1 == 0 {
28847- if e1 != 0 {
28848- err = errnoErr(e1)
28849- } else {
28850- err = syscall.EINVAL
28851- }
28852- }
28853- return
28854- }
28855-
28856- func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
28857- r0, _, e1 := syscall.Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
28858- n = uint32(r0)
28859- if n == 0 {
28860- if e1 != 0 {
28861- err = errnoErr(e1)
28862- } else {
28863- err = syscall.EINVAL
28864- }
28865- }
28866- return
28867- }
28868-
28869- func SetCurrentDirectory(path *uint16) (err error) {
28870- r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
28871- if r1 == 0 {
28872- if e1 != 0 {
28873- err = errnoErr(e1)
28874- } else {
28875- err = syscall.EINVAL
28876- }
28877- }
28878- return
28879- }
28880-
28881- func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
28882- r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
28883- if r1 == 0 {
28884- if e1 != 0 {
28885- err = errnoErr(e1)
28886- } else {
28887- err = syscall.EINVAL
28888- }
28889- }
28890- return
28891- }
28892-
28893- func RemoveDirectory(path *uint16) (err error) {
28894- r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
28895- if r1 == 0 {
28896- if e1 != 0 {
28897- err = errnoErr(e1)
28898- } else {
28899- err = syscall.EINVAL
28900- }
28901- }
28902- return
28903- }
28904-
28905- func DeleteFile(path *uint16) (err error) {
28906- r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
28907- if r1 == 0 {
28908- if e1 != 0 {
28909- err = errnoErr(e1)
28910- } else {
28911- err = syscall.EINVAL
28912- }
28913- }
28914- return
28915- }
28916-
28917- func MoveFile(from *uint16, to *uint16) (err error) {
28918- r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
28919- if r1 == 0 {
28920- if e1 != 0 {
28921- err = errnoErr(e1)
28922- } else {
28923- err = syscall.EINVAL
28924- }
28925- }
28926- return
28927- }
28928-
28929- func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
28930- r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
28931- if r1 == 0 {
28932- if e1 != 0 {
28933- err = errnoErr(e1)
28934- } else {
28935- err = syscall.EINVAL
28936- }
28937- }
28938- return
28939- }
28940-
28941- func GetComputerName(buf *uint16, n *uint32) (err error) {
28942- r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
28943- if r1 == 0 {
28944- if e1 != 0 {
28945- err = errnoErr(e1)
28946- } else {
28947- err = syscall.EINVAL
28948- }
28949- }
28950- return
28951- }
28952-
28953- func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) {
28954- r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
28955- if r1 == 0 {
28956- if e1 != 0 {
28957- err = errnoErr(e1)
28958- } else {
28959- err = syscall.EINVAL
28960- }
28961- }
28962- return
28963- }
28964-
28965- func SetEndOfFile(handle Handle) (err error) {
28966- r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
28967- if r1 == 0 {
28968- if e1 != 0 {
28969- err = errnoErr(e1)
28970- } else {
28971- err = syscall.EINVAL
28972- }
28973- }
28974- return
28975- }
28976-
28977- func GetSystemTimeAsFileTime(time *Filetime) {
28978- syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
28979- return
28980- }
28981-
28982- func GetSystemTimePreciseAsFileTime(time *Filetime) {
28983- syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
28984- return
28985- }
28986-
28987- func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
28988- r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
28989- rc = uint32(r0)
28990- if rc == 0xffffffff {
28991- if e1 != 0 {
28992- err = errnoErr(e1)
28993- } else {
28994- err = syscall.EINVAL
28995- }
28996- }
28997- return
28998- }
28999-
29000- func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
29001- r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
29002- handle = Handle(r0)
29003- if handle == 0 {
29004- if e1 != 0 {
29005- err = errnoErr(e1)
29006- } else {
29007- err = syscall.EINVAL
29008- }
29009- }
29010- return
29011- }
29012-
29013- func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
29014- r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
29015- if r1 == 0 {
29016- if e1 != 0 {
29017- err = errnoErr(e1)
29018- } else {
29019- err = syscall.EINVAL
29020- }
29021- }
29022- return
29023- }
29024-
29025- func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
29026- r1, _, e1 := syscall.Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
29027- if r1 == 0 {
29028- if e1 != 0 {
29029- err = errnoErr(e1)
29030- } else {
29031- err = syscall.EINVAL
29032- }
29033- }
29034- return
29035- }
29036-
29037- func CancelIo(s Handle) (err error) {
29038- r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
29039- if r1 == 0 {
29040- if e1 != 0 {
29041- err = errnoErr(e1)
29042- } else {
29043- err = syscall.EINVAL
29044- }
29045- }
29046- return
29047- }
29048-
29049- func CancelIoEx(s Handle, o *Overlapped) (err error) {
29050- r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
29051- if r1 == 0 {
29052- if e1 != 0 {
29053- err = errnoErr(e1)
29054- } else {
29055- err = syscall.EINVAL
29056- }
29057- }
29058- return
29059- }
29060-
29061- func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
29062- var _p0 uint32
29063- if inheritHandles {
29064- _p0 = 1
29065- } else {
29066- _p0 = 0
29067- }
29068- r1, _, e1 := syscall.Syscall12(procCreateProcessW.Addr(), 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0)
29069- if r1 == 0 {
29070- if e1 != 0 {
29071- err = errnoErr(e1)
29072- } else {
29073- err = syscall.EINVAL
29074- }
29075- }
29076- return
29077- }
29078-
29079- func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
29080- var _p0 uint32
29081- if inheritHandle {
29082- _p0 = 1
29083- } else {
29084- _p0 = 0
29085- }
29086- r0, _, e1 := syscall.Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
29087- handle = Handle(r0)
29088- if handle == 0 {
29089- if e1 != 0 {
29090- err = errnoErr(e1)
29091- } else {
29092- err = syscall.EINVAL
29093- }
29094- }
29095- return
29096- }
29097-
29098- func TerminateProcess(handle Handle, exitcode uint32) (err error) {
29099- r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
29100- if r1 == 0 {
29101- if e1 != 0 {
29102- err = errnoErr(e1)
29103- } else {
29104- err = syscall.EINVAL
29105- }
29106- }
29107- return
29108- }
29109-
29110- func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
29111- r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
29112- if r1 == 0 {
29113- if e1 != 0 {
29114- err = errnoErr(e1)
29115- } else {
29116- err = syscall.EINVAL
29117- }
29118- }
29119- return
29120- }
29121-
29122- func GetStartupInfo(startupInfo *StartupInfo) (err error) {
29123- r1, _, e1 := syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
29124- if r1 == 0 {
29125- if e1 != 0 {
29126- err = errnoErr(e1)
29127- } else {
29128- err = syscall.EINVAL
29129- }
29130- }
29131- return
29132- }
29133-
29134- func GetCurrentProcess() (pseudoHandle Handle, err error) {
29135- r0, _, e1 := syscall.Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
29136- pseudoHandle = Handle(r0)
29137- if pseudoHandle == 0 {
29138- if e1 != 0 {
29139- err = errnoErr(e1)
29140- } else {
29141- err = syscall.EINVAL
29142- }
29143- }
29144- return
29145- }
29146-
29147- func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
29148- r1, _, e1 := syscall.Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0)
29149- if r1 == 0 {
29150- if e1 != 0 {
29151- err = errnoErr(e1)
29152- } else {
29153- err = syscall.EINVAL
29154- }
29155- }
29156- return
29157- }
29158-
29159- func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
29160- var _p0 uint32
29161- if bInheritHandle {
29162- _p0 = 1
29163- } else {
29164- _p0 = 0
29165- }
29166- r1, _, e1 := syscall.Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
29167- if r1 == 0 {
29168- if e1 != 0 {
29169- err = errnoErr(e1)
29170- } else {
29171- err = syscall.EINVAL
29172- }
29173- }
29174- return
29175- }
29176-
29177- func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
29178- r0, _, e1 := syscall.Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
29179- event = uint32(r0)
29180- if event == 0xffffffff {
29181- if e1 != 0 {
29182- err = errnoErr(e1)
29183- } else {
29184- err = syscall.EINVAL
29185- }
29186- }
29187- return
29188- }
29189-
29190- func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
29191- r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
29192- n = uint32(r0)
29193- if n == 0 {
29194- if e1 != 0 {
29195- err = errnoErr(e1)
29196- } else {
29197- err = syscall.EINVAL
29198- }
29199- }
29200- return
29201- }
29202-
29203- func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
29204- r1, _, e1 := syscall.Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
29205- if r1 == 0 {
29206- if e1 != 0 {
29207- err = errnoErr(e1)
29208- } else {
29209- err = syscall.EINVAL
29210- }
29211- }
29212- return
29213- }
29214-
29215- func GetFileType(filehandle Handle) (n uint32, err error) {
29216- r0, _, e1 := syscall.Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
29217- n = uint32(r0)
29218- if n == 0 {
29219- if e1 != 0 {
29220- err = errnoErr(e1)
29221- } else {
29222- err = syscall.EINVAL
29223- }
29224- }
29225- return
29226- }
29227-
29228- func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
29229- r1, _, e1 := syscall.Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
29230- if r1 == 0 {
29231- if e1 != 0 {
29232- err = errnoErr(e1)
29233- } else {
29234- err = syscall.EINVAL
29235- }
29236- }
29237- return
29238- }
29239-
29240- func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
29241- r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
29242- if r1 == 0 {
29243- if e1 != 0 {
29244- err = errnoErr(e1)
29245- } else {
29246- err = syscall.EINVAL
29247- }
29248- }
29249- return
29250- }
29251-
29252- func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
29253- r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
29254- if r1 == 0 {
29255- if e1 != 0 {
29256- err = errnoErr(e1)
29257- } else {
29258- err = syscall.EINVAL
29259- }
29260- }
29261- return
29262- }
29263-
29264- func GetEnvironmentStrings() (envs *uint16, err error) {
29265- r0, _, e1 := syscall.Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
29266- envs = (*uint16)(unsafe.Pointer(r0))
29267- if envs == nil {
29268- if e1 != 0 {
29269- err = errnoErr(e1)
29270- } else {
29271- err = syscall.EINVAL
29272- }
29273- }
29274- return
29275- }
29276-
29277- func FreeEnvironmentStrings(envs *uint16) (err error) {
29278- r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
29279- if r1 == 0 {
29280- if e1 != 0 {
29281- err = errnoErr(e1)
29282- } else {
29283- err = syscall.EINVAL
29284- }
29285- }
29286- return
29287- }
29288-
29289- func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
29290- r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
29291- n = uint32(r0)
29292- if n == 0 {
29293- if e1 != 0 {
29294- err = errnoErr(e1)
29295- } else {
29296- err = syscall.EINVAL
29297- }
29298- }
29299- return
29300- }
29301-
29302- func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
29303- r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
29304- if r1 == 0 {
29305- if e1 != 0 {
29306- err = errnoErr(e1)
29307- } else {
29308- err = syscall.EINVAL
29309- }
29310- }
29311- return
29312- }
29313-
29314- func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
29315- r1, _, e1 := syscall.Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
29316- if r1 == 0 {
29317- if e1 != 0 {
29318- err = errnoErr(e1)
29319- } else {
29320- err = syscall.EINVAL
29321- }
29322- }
29323- return
29324- }
29325-
29326- func GetFileAttributes(name *uint16) (attrs uint32, err error) {
29327- r0, _, e1 := syscall.Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
29328- attrs = uint32(r0)
29329- if attrs == INVALID_FILE_ATTRIBUTES {
29330- if e1 != 0 {
29331- err = errnoErr(e1)
29332- } else {
29333- err = syscall.EINVAL
29334- }
29335- }
29336- return
29337- }
29338-
29339- func SetFileAttributes(name *uint16, attrs uint32) (err error) {
29340- r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
29341- if r1 == 0 {
29342- if e1 != 0 {
29343- err = errnoErr(e1)
29344- } else {
29345- err = syscall.EINVAL
29346- }
29347- }
29348- return
29349- }
29350-
29351- func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
29352- r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
29353- if r1 == 0 {
29354- if e1 != 0 {
29355- err = errnoErr(e1)
29356- } else {
29357- err = syscall.EINVAL
29358- }
29359- }
29360- return
29361- }
29362-
29363- func GetCommandLine() (cmd *uint16) {
29364- r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
29365- cmd = (*uint16)(unsafe.Pointer(r0))
29366- return
29367- }
29368-
29369- func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
29370- r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
29371- argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
29372- if argv == nil {
29373- if e1 != 0 {
29374- err = errnoErr(e1)
29375- } else {
29376- err = syscall.EINVAL
29377- }
29378- }
29379- return
29380- }
29381-
29382- func LocalFree(hmem Handle) (handle Handle, err error) {
29383- r0, _, e1 := syscall.Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
29384- handle = Handle(r0)
29385- if handle != 0 {
29386- if e1 != 0 {
29387- err = errnoErr(e1)
29388- } else {
29389- err = syscall.EINVAL
29390- }
29391- }
29392- return
29393- }
29394-
29395- func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
29396- r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
29397- if r1 == 0 {
29398- if e1 != 0 {
29399- err = errnoErr(e1)
29400- } else {
29401- err = syscall.EINVAL
29402- }
29403- }
29404- return
29405- }
29406-
29407- func FlushFileBuffers(handle Handle) (err error) {
29408- r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
29409- if r1 == 0 {
29410- if e1 != 0 {
29411- err = errnoErr(e1)
29412- } else {
29413- err = syscall.EINVAL
29414- }
29415- }
29416- return
29417- }
29418-
29419- func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
29420- r0, _, e1 := syscall.Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
29421- n = uint32(r0)
29422- if n == 0 {
29423- if e1 != 0 {
29424- err = errnoErr(e1)
29425- } else {
29426- err = syscall.EINVAL
29427- }
29428- }
29429- return
29430- }
29431-
29432- func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
29433- r0, _, e1 := syscall.Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
29434- n = uint32(r0)
29435- if n == 0 {
29436- if e1 != 0 {
29437- err = errnoErr(e1)
29438- } else {
29439- err = syscall.EINVAL
29440- }
29441- }
29442- return
29443- }
29444-
29445- func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
29446- r0, _, e1 := syscall.Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
29447- n = uint32(r0)
29448- if n == 0 {
29449- if e1 != 0 {
29450- err = errnoErr(e1)
29451- } else {
29452- err = syscall.EINVAL
29453- }
29454- }
29455- return
29456- }
29457-
29458- func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
29459- r0, _, e1 := syscall.Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
29460- handle = Handle(r0)
29461- if handle == 0 {
29462- if e1 != 0 {
29463- err = errnoErr(e1)
29464- } else {
29465- err = syscall.EINVAL
29466- }
29467- }
29468- return
29469- }
29470-
29471- func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
29472- r0, _, e1 := syscall.Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
29473- addr = uintptr(r0)
29474- if addr == 0 {
29475- if e1 != 0 {
29476- err = errnoErr(e1)
29477- } else {
29478- err = syscall.EINVAL
29479- }
29480- }
29481- return
29482- }
29483-
29484- func UnmapViewOfFile(addr uintptr) (err error) {
29485- r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
29486- if r1 == 0 {
29487- if e1 != 0 {
29488- err = errnoErr(e1)
29489- } else {
29490- err = syscall.EINVAL
29491- }
29492- }
29493- return
29494- }
29495-
29496- func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
29497- r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
29498- if r1 == 0 {
29499- if e1 != 0 {
29500- err = errnoErr(e1)
29501- } else {
29502- err = syscall.EINVAL
29503- }
29504- }
29505- return
29506- }
29507-
29508- func VirtualLock(addr uintptr, length uintptr) (err error) {
29509- r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
29510- if r1 == 0 {
29511- if e1 != 0 {
29512- err = errnoErr(e1)
29513- } else {
29514- err = syscall.EINVAL
29515- }
29516- }
29517- return
29518- }
29519-
29520- func VirtualUnlock(addr uintptr, length uintptr) (err error) {
29521- r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
29522- if r1 == 0 {
29523- if e1 != 0 {
29524- err = errnoErr(e1)
29525- } else {
29526- err = syscall.EINVAL
29527- }
29528- }
29529- return
29530- }
29531-
29532- func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) {
29533- r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0)
29534- value = uintptr(r0)
29535- if value == 0 {
29536- if e1 != 0 {
29537- err = errnoErr(e1)
29538- } else {
29539- err = syscall.EINVAL
29540- }
29541- }
29542- return
29543- }
29544-
29545- func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) {
29546- r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype))
29547- if r1 == 0 {
29548- if e1 != 0 {
29549- err = errnoErr(e1)
29550- } else {
29551- err = syscall.EINVAL
29552- }
29553- }
29554- return
29555- }
29556-
29557- func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) {
29558- r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0)
29559- if r1 == 0 {
29560- if e1 != 0 {
29561- err = errnoErr(e1)
29562- } else {
29563- err = syscall.EINVAL
29564- }
29565- }
29566- return
29567- }
29568-
29569- func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
29570- r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
29571- if r1 == 0 {
29572- if e1 != 0 {
29573- err = errnoErr(e1)
29574- } else {
29575- err = syscall.EINVAL
29576- }
29577- }
29578- return
29579- }
29580-
29581- func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
29582- var _p0 uint32
29583- if watchSubTree {
29584- _p0 = 1
29585- } else {
29586- _p0 = 0
29587- }
29588- r1, _, e1 := syscall.Syscall9(procReadDirectoryChangesW.Addr(), 8, uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine), 0)
29589- if r1 == 0 {
29590- if e1 != 0 {
29591- err = errnoErr(e1)
29592- } else {
29593- err = syscall.EINVAL
29594- }
29595- }
29596- return
29597- }
29598-
29599- func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
29600- r0, _, e1 := syscall.Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
29601- store = Handle(r0)
29602- if store == 0 {
29603- if e1 != 0 {
29604- err = errnoErr(e1)
29605- } else {
29606- err = syscall.EINVAL
29607- }
29608- }
29609- return
29610- }
29611-
29612- func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
29613- r0, _, e1 := syscall.Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
29614- handle = Handle(r0)
29615- if handle == InvalidHandle {
29616- if e1 != 0 {
29617- err = errnoErr(e1)
29618- } else {
29619- err = syscall.EINVAL
29620- }
29621- }
29622- return
29623- }
29624-
29625- func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
29626- r0, _, e1 := syscall.Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
29627- context = (*CertContext)(unsafe.Pointer(r0))
29628- if context == nil {
29629- if e1 != 0 {
29630- err = errnoErr(e1)
29631- } else {
29632- err = syscall.EINVAL
29633- }
29634- }
29635- return
29636- }
29637-
29638- func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
29639- r1, _, e1 := syscall.Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
29640- if r1 == 0 {
29641- if e1 != 0 {
29642- err = errnoErr(e1)
29643- } else {
29644- err = syscall.EINVAL
29645- }
29646- }
29647- return
29648- }
29649-
29650- func CertCloseStore(store Handle, flags uint32) (err error) {
29651- r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
29652- if r1 == 0 {
29653- if e1 != 0 {
29654- err = errnoErr(e1)
29655- } else {
29656- err = syscall.EINVAL
29657- }
29658- }
29659- return
29660- }
29661-
29662- func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
29663- r1, _, e1 := syscall.Syscall9(procCertGetCertificateChain.Addr(), 8, uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx)), 0)
29664- if r1 == 0 {
29665- if e1 != 0 {
29666- err = errnoErr(e1)
29667- } else {
29668- err = syscall.EINVAL
29669- }
29670- }
29671- return
29672- }
29673-
29674- func CertFreeCertificateChain(ctx *CertChainContext) {
29675- syscall.Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
29676- return
29677- }
29678-
29679- func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
29680- r0, _, e1 := syscall.Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
29681- context = (*CertContext)(unsafe.Pointer(r0))
29682- if context == nil {
29683- if e1 != 0 {
29684- err = errnoErr(e1)
29685- } else {
29686- err = syscall.EINVAL
29687- }
29688- }
29689- return
29690- }
29691-
29692- func CertFreeCertificateContext(ctx *CertContext) (err error) {
29693- r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
29694- if r1 == 0 {
29695- if e1 != 0 {
29696- err = errnoErr(e1)
29697- } else {
29698- err = syscall.EINVAL
29699- }
29700- }
29701- return
29702- }
29703-
29704- func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
29705- r1, _, e1 := syscall.Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
29706- if r1 == 0 {
29707- if e1 != 0 {
29708- err = errnoErr(e1)
29709- } else {
29710- err = syscall.EINVAL
29711- }
29712- }
29713- return
29714- }
29715-
29716- func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
29717- r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
29718- if r0 != 0 {
29719- regerrno = syscall.Errno(r0)
29720- }
29721- return
29722- }
29723-
29724- func RegCloseKey(key Handle) (regerrno error) {
29725- r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
29726- if r0 != 0 {
29727- regerrno = syscall.Errno(r0)
29728- }
29729- return
29730- }
29731-
29732- func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
29733- r0, _, _ := syscall.Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
29734- if r0 != 0 {
29735- regerrno = syscall.Errno(r0)
29736- }
29737- return
29738- }
29739-
29740- func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
29741- r0, _, _ := syscall.Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
29742- if r0 != 0 {
29743- regerrno = syscall.Errno(r0)
29744- }
29745- return
29746- }
29747-
29748- func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
29749- r0, _, _ := syscall.Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
29750- if r0 != 0 {
29751- regerrno = syscall.Errno(r0)
29752- }
29753- return
29754- }
29755-
29756- func getCurrentProcessId() (pid uint32) {
29757- r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
29758- pid = uint32(r0)
29759- return
29760- }
29761-
29762- func GetConsoleMode(console Handle, mode *uint32) (err error) {
29763- r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
29764- if r1 == 0 {
29765- if e1 != 0 {
29766- err = errnoErr(e1)
29767- } else {
29768- err = syscall.EINVAL
29769- }
29770- }
29771- return
29772- }
29773-
29774- func SetConsoleMode(console Handle, mode uint32) (err error) {
29775- r1, _, e1 := syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(console), uintptr(mode), 0)
29776- if r1 == 0 {
29777- if e1 != 0 {
29778- err = errnoErr(e1)
29779- } else {
29780- err = syscall.EINVAL
29781- }
29782- }
29783- return
29784- }
29785-
29786- func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) {
29787- r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0)
29788- if r1 == 0 {
29789- if e1 != 0 {
29790- err = errnoErr(e1)
29791- } else {
29792- err = syscall.EINVAL
29793- }
29794- }
29795- return
29796- }
29797-
29798- func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
29799- r1, _, e1 := syscall.Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
29800- if r1 == 0 {
29801- if e1 != 0 {
29802- err = errnoErr(e1)
29803- } else {
29804- err = syscall.EINVAL
29805- }
29806- }
29807- return
29808- }
29809-
29810- func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
29811- r1, _, e1 := syscall.Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
29812- if r1 == 0 {
29813- if e1 != 0 {
29814- err = errnoErr(e1)
29815- } else {
29816- err = syscall.EINVAL
29817- }
29818- }
29819- return
29820- }
29821-
29822- func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
29823- r0, _, e1 := syscall.Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
29824- handle = Handle(r0)
29825- if handle == InvalidHandle {
29826- if e1 != 0 {
29827- err = errnoErr(e1)
29828- } else {
29829- err = syscall.EINVAL
29830- }
29831- }
29832- return
29833- }
29834-
29835- func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
29836- r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
29837- if r1 == 0 {
29838- if e1 != 0 {
29839- err = errnoErr(e1)
29840- } else {
29841- err = syscall.EINVAL
29842- }
29843- }
29844- return
29845- }
29846-
29847- func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
29848- r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
29849- if r1 == 0 {
29850- if e1 != 0 {
29851- err = errnoErr(e1)
29852- } else {
29853- err = syscall.EINVAL
29854- }
29855- }
29856- return
29857- }
29858-
29859- func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
29860- r1, _, e1 := syscall.Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0)
29861- if r1 == 0 {
29862- if e1 != 0 {
29863- err = errnoErr(e1)
29864- } else {
29865- err = syscall.EINVAL
29866- }
29867- }
29868- return
29869- }
29870-
29871- func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
29872- r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
29873- if r1&0xff == 0 {
29874- if e1 != 0 {
29875- err = errnoErr(e1)
29876- } else {
29877- err = syscall.EINVAL
29878- }
29879- }
29880- return
29881- }
29882-
29883- func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
29884- r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
29885- if r1&0xff == 0 {
29886- if e1 != 0 {
29887- err = errnoErr(e1)
29888- } else {
29889- err = syscall.EINVAL
29890- }
29891- }
29892- return
29893- }
29894-
29895- func GetCurrentThreadId() (id uint32) {
29896- r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0)
29897- id = uint32(r0)
29898- return
29899- }
29900-
29901- func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) {
29902- r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0)
29903- handle = Handle(r0)
29904- if handle == 0 {
29905- if e1 != 0 {
29906- err = errnoErr(e1)
29907- } else {
29908- err = syscall.EINVAL
29909- }
29910- }
29911- return
29912- }
29913-
29914- func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) {
29915- r0, _, e1 := syscall.Syscall6(procCreateEventExW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0)
29916- handle = Handle(r0)
29917- if handle == 0 {
29918- if e1 != 0 {
29919- err = errnoErr(e1)
29920- } else {
29921- err = syscall.EINVAL
29922- }
29923- }
29924- return
29925- }
29926-
29927- func OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) {
29928- var _p0 uint32
29929- if inheritHandle {
29930- _p0 = 1
29931- } else {
29932- _p0 = 0
29933- }
29934- r0, _, e1 := syscall.Syscall(procOpenEventW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name)))
29935- handle = Handle(r0)
29936- if handle == 0 {
29937- if e1 != 0 {
29938- err = errnoErr(e1)
29939- } else {
29940- err = syscall.EINVAL
29941- }
29942- }
29943- return
29944- }
29945-
29946- func SetEvent(event Handle) (err error) {
29947- r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0)
29948- if r1 == 0 {
29949- if e1 != 0 {
29950- err = errnoErr(e1)
29951- } else {
29952- err = syscall.EINVAL
29953- }
29954- }
29955- return
29956- }
29957-
29958- func ResetEvent(event Handle) (err error) {
29959- r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(event), 0, 0)
29960- if r1 == 0 {
29961- if e1 != 0 {
29962- err = errnoErr(e1)
29963- } else {
29964- err = syscall.EINVAL
29965- }
29966- }
29967- return
29968- }
29969-
29970- func PulseEvent(event Handle) (err error) {
29971- r1, _, e1 := syscall.Syscall(procPulseEvent.Addr(), 1, uintptr(event), 0, 0)
29972- if r1 == 0 {
29973- if e1 != 0 {
29974- err = errnoErr(e1)
29975- } else {
29976- err = syscall.EINVAL
29977- }
29978- }
29979- return
29980- }
29981-
29982- func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) {
29983- r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)))
29984- if r1 == 0 {
29985- if e1 != 0 {
29986- err = errnoErr(e1)
29987- } else {
29988- err = syscall.EINVAL
29989- }
29990- }
29991- return
29992- }
29993-
29994- func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) {
29995- r1, _, e1 := syscall.Syscall(procDeleteVolumeMountPointW.Addr(), 1, uintptr(unsafe.Pointer(volumeMountPoint)), 0, 0)
29996- if r1 == 0 {
29997- if e1 != 0 {
29998- err = errnoErr(e1)
29999- } else {
30000- err = syscall.EINVAL
30001- }
30002- }
30003- return
30004- }
30005-
30006- func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) {
30007- r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0)
30008- handle = Handle(r0)
30009- if handle == InvalidHandle {
30010- if e1 != 0 {
30011- err = errnoErr(e1)
30012- } else {
30013- err = syscall.EINVAL
30014- }
30015- }
30016- return
30017- }
30018-
30019- func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) {
30020- r0, _, e1 := syscall.Syscall(procFindFirstVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
30021- handle = Handle(r0)
30022- if handle == InvalidHandle {
30023- if e1 != 0 {
30024- err = errnoErr(e1)
30025- } else {
30026- err = syscall.EINVAL
30027- }
30028- }
30029- return
30030- }
30031-
30032- func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) {
30033- r1, _, e1 := syscall.Syscall(procFindNextVolumeW.Addr(), 3, uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength))
30034- if r1 == 0 {
30035- if e1 != 0 {
30036- err = errnoErr(e1)
30037- } else {
30038- err = syscall.EINVAL
30039- }
30040- }
30041- return
30042- }
30043-
30044- func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) {
30045- r1, _, e1 := syscall.Syscall(procFindNextVolumeMountPointW.Addr(), 3, uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
30046- if r1 == 0 {
30047- if e1 != 0 {
30048- err = errnoErr(e1)
30049- } else {
30050- err = syscall.EINVAL
30051- }
30052- }
30053- return
30054- }
30055-
30056- func FindVolumeClose(findVolume Handle) (err error) {
30057- r1, _, e1 := syscall.Syscall(procFindVolumeClose.Addr(), 1, uintptr(findVolume), 0, 0)
30058- if r1 == 0 {
30059- if e1 != 0 {
30060- err = errnoErr(e1)
30061- } else {
30062- err = syscall.EINVAL
30063- }
30064- }
30065- return
30066- }
30067-
30068- func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) {
30069- r1, _, e1 := syscall.Syscall(procFindVolumeMountPointClose.Addr(), 1, uintptr(findVolumeMountPoint), 0, 0)
30070- if r1 == 0 {
30071- if e1 != 0 {
30072- err = errnoErr(e1)
30073- } else {
30074- err = syscall.EINVAL
30075- }
30076- }
30077- return
30078- }
30079-
30080- func GetDriveType(rootPathName *uint16) (driveType uint32) {
30081- r0, _, _ := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(rootPathName)), 0, 0)
30082- driveType = uint32(r0)
30083- return
30084- }
30085-
30086- func GetLogicalDrives() (drivesBitMask uint32, err error) {
30087- r0, _, e1 := syscall.Syscall(procGetLogicalDrives.Addr(), 0, 0, 0, 0)
30088- drivesBitMask = uint32(r0)
30089- if drivesBitMask == 0 {
30090- if e1 != 0 {
30091- err = errnoErr(e1)
30092- } else {
30093- err = syscall.EINVAL
30094- }
30095- }
30096- return
30097- }
30098-
30099- func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) {
30100- r0, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(bufferLength), uintptr(unsafe.Pointer(buffer)), 0)
30101- n = uint32(r0)
30102- if n == 0 {
30103- if e1 != 0 {
30104- err = errnoErr(e1)
30105- } else {
30106- err = syscall.EINVAL
30107- }
30108- }
30109- return
30110- }
30111-
30112- func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
30113- r1, _, e1 := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0)
30114- if r1 == 0 {
30115- if e1 != 0 {
30116- err = errnoErr(e1)
30117- } else {
30118- err = syscall.EINVAL
30119- }
30120- }
30121- return
30122- }
30123-
30124- func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
30125- r1, _, e1 := syscall.Syscall9(procGetVolumeInformationByHandleW.Addr(), 8, uintptr(file), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0)
30126- if r1 == 0 {
30127- if e1 != 0 {
30128- err = errnoErr(e1)
30129- } else {
30130- err = syscall.EINVAL
30131- }
30132- }
30133- return
30134- }
30135-
30136- func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) {
30137- r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength))
30138- if r1 == 0 {
30139- if e1 != 0 {
30140- err = errnoErr(e1)
30141- } else {
30142- err = syscall.EINVAL
30143- }
30144- }
30145- return
30146- }
30147-
30148- func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) {
30149- r1, _, e1 := syscall.Syscall(procGetVolumePathNameW.Addr(), 3, uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength))
30150- if r1 == 0 {
30151- if e1 != 0 {
30152- err = errnoErr(e1)
30153- } else {
30154- err = syscall.EINVAL
30155- }
30156- }
30157- return
30158- }
30159-
30160- func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) {
30161- r1, _, e1 := syscall.Syscall6(procGetVolumePathNamesForVolumeNameW.Addr(), 4, uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength)), 0, 0)
30162- if r1 == 0 {
30163- if e1 != 0 {
30164- err = errnoErr(e1)
30165- } else {
30166- err = syscall.EINVAL
30167- }
30168- }
30169- return
30170- }
30171-
30172- func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) {
30173- r0, _, e1 := syscall.Syscall(procQueryDosDeviceW.Addr(), 3, uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max))
30174- n = uint32(r0)
30175- if n == 0 {
30176- if e1 != 0 {
30177- err = errnoErr(e1)
30178- } else {
30179- err = syscall.EINVAL
30180- }
30181- }
30182- return
30183- }
30184-
30185- func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) {
30186- r1, _, e1 := syscall.Syscall(procSetVolumeLabelW.Addr(), 2, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName)), 0)
30187- if r1 == 0 {
30188- if e1 != 0 {
30189- err = errnoErr(e1)
30190- } else {
30191- err = syscall.EINVAL
30192- }
30193- }
30194- return
30195- }
30196-
30197- func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) {
30198- r1, _, e1 := syscall.Syscall(procSetVolumeMountPointW.Addr(), 2, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), 0)
30199- if r1 == 0 {
30200- if e1 != 0 {
30201- err = errnoErr(e1)
30202- } else {
30203- err = syscall.EINVAL
30204- }
30205- }
30206- return
30207- }
30208-
30209- func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
30210- r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
30211- if r0 != 0 {
30212- sockerr = syscall.Errno(r0)
30213- }
30214- return
30215- }
30216-
30217- func WSACleanup() (err error) {
30218- r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
30219- if r1 == socket_error {
30220- if e1 != 0 {
30221- err = errnoErr(e1)
30222- } else {
30223- err = syscall.EINVAL
30224- }
30225- }
30226- return
30227- }
30228-
30229- func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
30230- r1, _, e1 := syscall.Syscall9(procWSAIoctl.Addr(), 9, uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine))
30231- if r1 == socket_error {
30232- if e1 != 0 {
30233- err = errnoErr(e1)
30234- } else {
30235- err = syscall.EINVAL
30236- }
30237- }
30238- return
30239- }
30240-
30241- func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
30242- r0, _, e1 := syscall.Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
30243- handle = Handle(r0)
30244- if handle == InvalidHandle {
30245- if e1 != 0 {
30246- err = errnoErr(e1)
30247- } else {
30248- err = syscall.EINVAL
30249- }
30250- }
30251- return
30252- }
30253-
30254- func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
30255- r1, _, e1 := syscall.Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
30256- if r1 == socket_error {
30257- if e1 != 0 {
30258- err = errnoErr(e1)
30259- } else {
30260- err = syscall.EINVAL
30261- }
30262- }
30263- return
30264- }
30265-
30266- func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
30267- r1, _, e1 := syscall.Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
30268- if r1 == socket_error {
30269- if e1 != 0 {
30270- err = errnoErr(e1)
30271- } else {
30272- err = syscall.EINVAL
30273- }
30274- }
30275- return
30276- }
30277-
30278- func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
30279- r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
30280- if r1 == socket_error {
30281- if e1 != 0 {
30282- err = errnoErr(e1)
30283- } else {
30284- err = syscall.EINVAL
30285- }
30286- }
30287- return
30288- }
30289-
30290- func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
30291- r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
30292- if r1 == socket_error {
30293- if e1 != 0 {
30294- err = errnoErr(e1)
30295- } else {
30296- err = syscall.EINVAL
30297- }
30298- }
30299- return
30300- }
30301-
30302- func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
30303- r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
30304- if r1 == socket_error {
30305- if e1 != 0 {
30306- err = errnoErr(e1)
30307- } else {
30308- err = syscall.EINVAL
30309- }
30310- }
30311- return
30312- }
30313-
30314- func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
30315- r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
30316- if r1 == socket_error {
30317- if e1 != 0 {
30318- err = errnoErr(e1)
30319- } else {
30320- err = syscall.EINVAL
30321- }
30322- }
30323- return
30324- }
30325-
30326- func listen(s Handle, backlog int32) (err error) {
30327- r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
30328- if r1 == socket_error {
30329- if e1 != 0 {
30330- err = errnoErr(e1)
30331- } else {
30332- err = syscall.EINVAL
30333- }
30334- }
30335- return
30336- }
30337-
30338- func shutdown(s Handle, how int32) (err error) {
30339- r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
30340- if r1 == socket_error {
30341- if e1 != 0 {
30342- err = errnoErr(e1)
30343- } else {
30344- err = syscall.EINVAL
30345- }
30346- }
30347- return
30348- }
30349-
30350- func Closesocket(s Handle) (err error) {
30351- r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
30352- if r1 == socket_error {
30353- if e1 != 0 {
30354- err = errnoErr(e1)
30355- } else {
30356- err = syscall.EINVAL
30357- }
30358- }
30359- return
30360- }
30361-
30362- func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
30363- r1, _, e1 := syscall.Syscall9(procAcceptEx.Addr(), 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0)
30364- if r1 == 0 {
30365- if e1 != 0 {
30366- err = errnoErr(e1)
30367- } else {
30368- err = syscall.EINVAL
30369- }
30370- }
30371- return
30372- }
30373-
30374- func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
30375- syscall.Syscall9(procGetAcceptExSockaddrs.Addr(), 8, uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(lrsa)), uintptr(unsafe.Pointer(lrsalen)), uintptr(unsafe.Pointer(rrsa)), uintptr(unsafe.Pointer(rrsalen)), 0)
30376- return
30377- }
30378-
30379- func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
30380- r1, _, e1 := syscall.Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
30381- if r1 == socket_error {
30382- if e1 != 0 {
30383- err = errnoErr(e1)
30384- } else {
30385- err = syscall.EINVAL
30386- }
30387- }
30388- return
30389- }
30390-
30391- func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
30392- r1, _, e1 := syscall.Syscall9(procWSASend.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
30393- if r1 == socket_error {
30394- if e1 != 0 {
30395- err = errnoErr(e1)
30396- } else {
30397- err = syscall.EINVAL
30398- }
30399- }
30400- return
30401- }
30402-
30403- func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
30404- r1, _, e1 := syscall.Syscall9(procWSARecvFrom.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
30405- if r1 == socket_error {
30406- if e1 != 0 {
30407- err = errnoErr(e1)
30408- } else {
30409- err = syscall.EINVAL
30410- }
30411- }
30412- return
30413- }
30414-
30415- func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
30416- r1, _, e1 := syscall.Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
30417- if r1 == socket_error {
30418- if e1 != 0 {
30419- err = errnoErr(e1)
30420- } else {
30421- err = syscall.EINVAL
30422- }
30423- }
30424- return
30425- }
30426-
30427- func GetHostByName(name string) (h *Hostent, err error) {
30428- var _p0 *byte
30429- _p0, err = syscall.BytePtrFromString(name)
30430- if err != nil {
30431- return
30432- }
30433- return _GetHostByName(_p0)
30434- }
30435-
30436- func _GetHostByName(name *byte) (h *Hostent, err error) {
30437- r0, _, e1 := syscall.Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
30438- h = (*Hostent)(unsafe.Pointer(r0))
30439- if h == nil {
30440- if e1 != 0 {
30441- err = errnoErr(e1)
30442- } else {
30443- err = syscall.EINVAL
30444- }
30445- }
30446- return
30447- }
30448-
30449- func GetServByName(name string, proto string) (s *Servent, err error) {
30450- var _p0 *byte
30451- _p0, err = syscall.BytePtrFromString(name)
30452- if err != nil {
30453- return
30454- }
30455- var _p1 *byte
30456- _p1, err = syscall.BytePtrFromString(proto)
30457- if err != nil {
30458- return
30459- }
30460- return _GetServByName(_p0, _p1)
30461- }
30462-
30463- func _GetServByName(name *byte, proto *byte) (s *Servent, err error) {
30464- r0, _, e1 := syscall.Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0)
30465- s = (*Servent)(unsafe.Pointer(r0))
30466- if s == nil {
30467- if e1 != 0 {
30468- err = errnoErr(e1)
30469- } else {
30470- err = syscall.EINVAL
30471- }
30472- }
30473- return
30474- }
30475-
30476- func Ntohs(netshort uint16) (u uint16) {
30477- r0, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
30478- u = uint16(r0)
30479- return
30480- }
30481-
30482- func GetProtoByName(name string) (p *Protoent, err error) {
30483- var _p0 *byte
30484- _p0, err = syscall.BytePtrFromString(name)
30485- if err != nil {
30486- return
30487- }
30488- return _GetProtoByName(_p0)
30489- }
30490-
30491- func _GetProtoByName(name *byte) (p *Protoent, err error) {
30492- r0, _, e1 := syscall.Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
30493- p = (*Protoent)(unsafe.Pointer(r0))
30494- if p == nil {
30495- if e1 != 0 {
30496- err = errnoErr(e1)
30497- } else {
30498- err = syscall.EINVAL
30499- }
30500- }
30501- return
30502- }
30503-
30504- func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
30505- var _p0 *uint16
30506- _p0, status = syscall.UTF16PtrFromString(name)
30507- if status != nil {
30508- return
30509- }
30510- return _DnsQuery(_p0, qtype, options, extra, qrs, pr)
30511- }
30512-
30513- func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
30514- r0, _, _ := syscall.Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(name)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
30515- if r0 != 0 {
30516- status = syscall.Errno(r0)
30517- }
30518- return
30519- }
30520-
30521- func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
30522- syscall.Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
30523- return
30524- }
30525-
30526- func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
30527- r0, _, _ := syscall.Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
30528- same = r0 != 0
30529- return
30530- }
30531-
30532- func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
30533- r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
30534- if r0 != 0 {
30535- sockerr = syscall.Errno(r0)
30536- }
30537- return
30538- }
30539-
30540- func FreeAddrInfoW(addrinfo *AddrinfoW) {
30541- syscall.Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
30542- return
30543- }
30544-
30545- func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
30546- r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
30547- if r0 != 0 {
30548- errcode = syscall.Errno(r0)
30549- }
30550- return
30551- }
30552-
30553- func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
30554- r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
30555- if r0 != 0 {
30556- errcode = syscall.Errno(r0)
30557- }
30558- return
30559- }
30560-
30561- func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
30562- r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
30563- if r1 == 0 {
30564- if e1 != 0 {
30565- err = errnoErr(e1)
30566- } else {
30567- err = syscall.EINVAL
30568- }
30569- }
30570- return
30571- }
30572-
30573- func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
30574- r0, _, e1 := syscall.Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
30575- n = int32(r0)
30576- if n == -1 {
30577- if e1 != 0 {
30578- err = errnoErr(e1)
30579- } else {
30580- err = syscall.EINVAL
30581- }
30582- }
30583- return
30584- }
30585-
30586- func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
30587- r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
30588- if r0 != 0 {
30589- errcode = syscall.Errno(r0)
30590- }
30591- return
30592- }
30593-
30594- func GetACP() (acp uint32) {
30595- r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
30596- acp = uint32(r0)
30597- return
30598- }
30599-
30600- func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
30601- r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
30602- nwrite = int32(r0)
30603- if nwrite == 0 {
30604- if e1 != 0 {
30605- err = errnoErr(e1)
30606- } else {
30607- err = syscall.EINVAL
30608- }
30609- }
30610- return
30611- }
30612-
30613- func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
30614- r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
30615- if r1&0xff == 0 {
30616- if e1 != 0 {
30617- err = errnoErr(e1)
30618- } else {
30619- err = syscall.EINVAL
30620- }
30621- }
30622- return
30623- }
30624-
30625- func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
30626- r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
30627- if r1&0xff == 0 {
30628- if e1 != 0 {
30629- err = errnoErr(e1)
30630- } else {
30631- err = syscall.EINVAL
30632- }
30633- }
30634- return
30635- }
30636-
30637- func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
30638- r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
30639- if r0 != 0 {
30640- neterr = syscall.Errno(r0)
30641- }
30642- return
30643- }
30644-
30645- func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
30646- r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
30647- if r0 != 0 {
30648- neterr = syscall.Errno(r0)
30649- }
30650- return
30651- }
30652-
30653- func NetApiBufferFree(buf *byte) (neterr error) {
30654- r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
30655- if r0 != 0 {
30656- neterr = syscall.Errno(r0)
30657- }
30658- return
30659- }
30660-
30661- func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
30662- r1, _, e1 := syscall.Syscall9(procLookupAccountSidW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
30663- if r1 == 0 {
30664- if e1 != 0 {
30665- err = errnoErr(e1)
30666- } else {
30667- err = syscall.EINVAL
30668- }
30669- }
30670- return
30671- }
30672-
30673- func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
30674- r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
30675- if r1 == 0 {
30676- if e1 != 0 {
30677- err = errnoErr(e1)
30678- } else {
30679- err = syscall.EINVAL
30680- }
30681- }
30682- return
30683- }
30684-
30685- func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
30686- r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
30687- if r1 == 0 {
30688- if e1 != 0 {
30689- err = errnoErr(e1)
30690- } else {
30691- err = syscall.EINVAL
30692- }
30693- }
30694- return
30695- }
30696-
30697- func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
30698- r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
30699- if r1 == 0 {
30700- if e1 != 0 {
30701- err = errnoErr(e1)
30702- } else {
30703- err = syscall.EINVAL
30704- }
30705- }
30706- return
30707- }
30708-
30709- func GetLengthSid(sid *SID) (len uint32) {
30710- r0, _, _ := syscall.Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
30711- len = uint32(r0)
30712- return
30713- }
30714-
30715- func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
30716- r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
30717- if r1 == 0 {
30718- if e1 != 0 {
30719- err = errnoErr(e1)
30720- } else {
30721- err = syscall.EINVAL
30722- }
30723- }
30724- return
30725- }
30726-
30727- func AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, subAuth0 uint32, subAuth1 uint32, subAuth2 uint32, subAuth3 uint32, subAuth4 uint32, subAuth5 uint32, subAuth6 uint32, subAuth7 uint32, sid **SID) (err error) {
30728- r1, _, e1 := syscall.Syscall12(procAllocateAndInitializeSid.Addr(), 11, uintptr(unsafe.Pointer(identAuth)), uintptr(subAuth), uintptr(subAuth0), uintptr(subAuth1), uintptr(subAuth2), uintptr(subAuth3), uintptr(subAuth4), uintptr(subAuth5), uintptr(subAuth6), uintptr(subAuth7), uintptr(unsafe.Pointer(sid)), 0)
30729- if r1 == 0 {
30730- if e1 != 0 {
30731- err = errnoErr(e1)
30732- } else {
30733- err = syscall.EINVAL
30734- }
30735- }
30736- return
30737- }
30738-
30739- func FreeSid(sid *SID) (err error) {
30740- r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
30741- if r1 != 0 {
30742- if e1 != 0 {
30743- err = errnoErr(e1)
30744- } else {
30745- err = syscall.EINVAL
30746- }
30747- }
30748- return
30749- }
30750-
30751- func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) {
30752- r0, _, _ := syscall.Syscall(procEqualSid.Addr(), 2, uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2)), 0)
30753- isEqual = r0 != 0
30754- return
30755- }
30756-
30757- func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) {
30758- r1, _, e1 := syscall.Syscall(procCheckTokenMembership.Addr(), 3, uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember)))
30759- if r1 == 0 {
30760- if e1 != 0 {
30761- err = errnoErr(e1)
30762- } else {
30763- err = syscall.EINVAL
30764- }
30765- }
30766- return
30767- }
30768-
30769- func OpenProcessToken(h Handle, access uint32, token *Token) (err error) {
30770- r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(h), uintptr(access), uintptr(unsafe.Pointer(token)))
30771- if r1 == 0 {
30772- if e1 != 0 {
30773- err = errnoErr(e1)
30774- } else {
30775- err = syscall.EINVAL
30776- }
30777- }
30778- return
30779- }
30780-
30781- func GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
30782- r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(t), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
30783- if r1 == 0 {
30784- if e1 != 0 {
30785- err = errnoErr(e1)
30786- } else {
30787- err = syscall.EINVAL
30788- }
30789- }
30790- return
30791- }
30792-
30793- func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
30794- r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
30795- if r1 == 0 {
30796- if e1 != 0 {
30797- err = errnoErr(e1)
30798- } else {
30799- err = syscall.EINVAL
30800- }
30801- }
30802- return
30803- }