elixir/lib.py
2017-05-10 21:41:20 +02:00

171 lines
2.9 KiB
Python
Executable file

#!/usr/bin/python3
# This file is part of Elixir, a source code cross-referencer.
#
# Copyright (C) 2017 Mikaël Bouillot
# <mikael.bouillot@free-electrons.com>
#
# Elixir is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Elixir. If not, see <http://www.gnu.org/licenses/>.
import subprocess
import re
import sys
def script (*args):
args = ('./script.sh',) + args
p = subprocess.run (args, stdout=subprocess.PIPE)
p = p.stdout
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