forked from bootlin/elixir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.py
executable file
·174 lines (166 loc) · 3.08 KB
/
lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python3
# This file is part of Elixir, a source code cross-referencer.
#
# Copyright (C) 2017 Mikaël Bouillot
#
# Elixir is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Elixir is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
import subprocess
def script (*args):
args = ('./script.sh',) + args
# subprocess.run was introduced in Python 3.5
# fall back to subprocess.check_output if it's not available
if hasattr(subprocess, 'run'):
p = subprocess.run (args, stdout=subprocess.PIPE)
p = p.stdout
else:
p = subprocess.check_output(args)
return p
def scriptLines (*args):
p = script (*args)
p = p.split (b'\n')
del p[-1]
return p
def unescape (bstr):
subs = (
('\1','\n'),
)
for a,b in subs:
a = a.encode()
b = b.encode()
bstr = bstr.replace (a, b)
return bstr
blacklist = (
b'if',
b'dev',
b'i',
b'ret',
b'err',
b'flags',
b'h',
b'u32',
b'data',
b'const',
b'skb',
b'len',
b'name',
b'priv',
b'p',
b'inode',
b'val',
b'u8',
b'info',
b'buf',
b'rc',
b'type',
b'out',
b'cmd',
b'port',
b'size',
b'page',
b'tp',
b'pdev',
b'state',
b'addr',
b'rdev',
b'sk',
b'count',
b'hw',
b'lock',
b'error',
b'reg',
b'file',
b's',
b'u64',
b'id',
b'tmp',
b'u16',
b'codec',
b'bool',
b'req',
b'bp',
b'c',
b'chip',
b'r',
b'n',
b'value',
b'false',
b'start',
b'index',
b'res',
b'regs',
b'j',
b'true',
b'base',
b'irq',
b'x',
b'net',
b'mode',
b'vcpu',
b'host',
b'spec',
b'card',
b'sb',
b'mask',
b'list',
b'ops',
b'next',
b'ctx',
b'event',
b'mddev',
b'q',
b'attr',
b'cpu',
b'desc',
b'msg',
b't',
b'entry',
b'arg',
b'idx',
b'end',
b'root',
b'memset',
b'struct',
b'static',
b'define',
b'NULL',
b'sizeof',
b'status',
b'device',
b'adapter',
b'inline',
b'offset',
b'failed',
b'dentry',
b'retval',
b'buffer',
b'length',
b'result',
b'unlikely',
b'extern',
b'driver',
)
def isIdent (bstr):
if len (bstr) < 2:
return False
elif bstr in blacklist:
return False
else:
return True
def autoBytes (arg):
if type (arg) is str:
arg = arg.encode()
elif type (arg) is int:
arg = str(arg).encode()
return arg