-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstash.go
88 lines (78 loc) · 2.02 KB
/
stash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package config
import (
"os"
"reflect"
)
type stash struct {
file *os.File
line int64
searchVal bool
searchKey bool
inBlock int
canSkip bool
skip bool
bkQueue []bool
bkMulti bool
mapKey reflect.Value
setVar bool
searchVar bool
searchVarBlock bool
cwd string
vars []map[string]string
}
func (cfg *Config) popStash() error {
if cfg.inBlock > 0 {
return cfg.error("invalid config file, block not closed by \"}\"")
}
if len(cfg.stash) > 0 {
current := cfg.stash[len(cfg.stash)-1]
cfg.stash = cfg.stash[:len(cfg.stash)-1]
cfg.file = current.file
cfg.line = current.line
cfg.searchVal = current.searchVal
cfg.searchKey = current.searchKey
cfg.inBlock = current.inBlock
cfg.canSkip = current.canSkip
cfg.skip = current.skip
cfg.bkMulti = current.bkMulti
cfg.mapKey = current.mapKey
cfg.setVar = current.setVar
cfg.searchVar = current.searchVar
cfg.searchVarBlock = current.searchVarBlock
cfg.cwd = current.cwd
cfg.bkQueue = make([]bool, len(current.bkQueue))
cfg.vars = make([]map[string]string, len(current.vars))
copy(cfg.bkQueue, current.bkQueue)
copy(cfg.vars, current.vars)
}
return nil
}
func (cfg *Config) pushStash() {
s := &stash{
file: cfg.file,
line: cfg.line,
searchVal: cfg.searchVal,
searchKey: cfg.searchKey,
inBlock: cfg.inBlock,
canSkip: cfg.canSkip,
skip: cfg.skip,
bkMulti: cfg.bkMulti,
mapKey: cfg.mapKey,
setVar: cfg.setVar,
searchVar: cfg.searchVar,
searchVarBlock: cfg.searchVarBlock,
cwd: cfg.cwd,
}
s.bkQueue = make([]bool, len(cfg.bkQueue))
s.vars = make([]map[string]string, len(cfg.vars))
copy(s.bkQueue, cfg.bkQueue)
copy(s.vars, cfg.vars)
cfg.inSearchKey()
cfg.inBlock = 0
cfg.inInclude = 0
cfg.currentVar = make(map[string]string)
cfg.searchVar = false
cfg.setVar = false
cfg.searchVarBlock = false
cfg.stash = append(cfg.stash, s)
}