forked from isbm/go-deb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shlibs.go
83 lines (68 loc) · 1.78 KB
/
shlibs.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
package deb
import (
"bufio"
"regexp"
"strings"
)
type SharedLibrary struct {
tag string
library string
version string
dependencies []string
}
func NewSharedLibrary() *SharedLibrary {
shl := new(SharedLibrary)
shl.dependencies = make([]string, 0)
return shl
}
type SharedLibsFile struct {
libraries []SharedLibrary
}
// Tag returns possible shared library tag. Usually it is an empty string.
func (shl *SharedLibrary) Tag() string {
return shl.tag
}
// Name returns the name of the shared library.
func (shl *SharedLibrary) Name() string {
return shl.library
}
// Version returns the version of the shared library.
func (shl *SharedLibrary) Version() string {
return shl.version
}
// Dependencies returns the list of dependencies of the shared library.
func (shl *SharedLibrary) Dependencies() []string {
return shl.dependencies
}
func NewSharedLibsFile() *SharedLibsFile {
shl := new(SharedLibsFile)
shl.libraries = make([]SharedLibrary, 0)
return shl
}
func (shlf *SharedLibsFile) parse(data []byte) error {
var line string
scn := bufio.NewScanner(strings.NewReader(string(data)))
for scn.Scan() {
line = strings.TrimSpace(scn.Text())
if line != "" && !strings.HasPrefix(line, "#") {
shl := NewSharedLibrary()
fe := strings.SplitN(line, " ", 2)
if strings.HasSuffix(fe[0], ":") {
shl.tag = fe[0]
line = fe[1]
}
fe = strings.SplitN(line, " ", 3)
shl.library, shl.version = fe[0], fe[1]
fe = regexp.MustCompile(`[\\,\\|]`).Split(fe[2], -1)
for _, v := range fe {
shl.dependencies = append(shl.dependencies, strings.TrimSpace(v))
}
shlf.libraries = append(shlf.libraries, *shl)
}
}
return nil
}
// Libraries returns shared libraries
func (shl *SharedLibsFile) Libraries() []SharedLibrary {
return shl.libraries
}