Author: glen Date: Wed Apr 23 15:40:07 2008 GMT Module: SOURCES Tag: HEAD ---- Log message: - scans kernel Kconfig symbols order
---- Files affected: SOURCES: kernel-symsorder.py (NONE -> 1.1) (NEW) ---- Diffs: ================================================================ Index: SOURCES/kernel-symsorder.py diff -u /dev/null SOURCES/kernel-symsorder.py:1.1 --- /dev/null Wed Apr 23 17:40:07 2008 +++ SOURCES/kernel-symsorder.py Wed Apr 23 17:40:02 2008 @@ -0,0 +1,111 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8 +# -*- coding: utf-8 -*- +# +# Parse kernel Kconfig and return all kernel symbols in orders it will write +# likely also to .config file. based on +# +# Parsing code based on http://kernel.org/doc/make/menuconfig2html.py +# +# Authors +# Elan Ruusamäe <[EMAIL PROTECTED]> +# Patryk Zawadzki <[EMAIL PROTECTED]> +# +# Date Created +# 2008-04-23 +# + +# "boolean" not documented type in kconfig-language.txt line 51 + +import os,sys + +class ParsingException(Exception): + pass + +class MenuParser(object): + filename = "" + lineno = 0 + helplen = 0 + result = [] + + # strip quotes from string + def zapquotes(self, str): + if str[0] == '"': str = str[1:str.rfind('"')] + return str + + # pre-proccess input lines. handles line continuations + def preparse(self, data): + x = data.pop(0) + self.lineno = self.lineno + 1 + while True: + if x: + while x[-1] == '\\': + x = x[:-1] + data.pop(0) + self.lineno = self.lineno + 1 + yield x + if data: + x = data.pop(0) + self.lineno = self.lineno + 1 + else: + raise StopIteration + + def parse(self, filename): + self.result = [] + self.readfile(filename) + return self.result + + def readfile(self, filename): + self.filename = filename + lines = open(filename).read().split("\n") + + for line in self.preparse(lines): + if self.helplen: + line = line.expandtabs() + if not len(line) or line[:self.helplen].isspace(): + continue + else: + self.helplen = 0 + self.parseline(line) + + def parseline(self, line): + words = line.strip().split(None, 1) + # skip empty lines + if not len(words): return + # skip comments + if words[0][0] == '#': return + + if words[0] in ('config', 'menuconfig'): + config = words[1] + self.result.append(config) + + elif words[0] in ('bool', 'boolean', 'mainmenu', 'option', 'def_tristate', \ + 'optional', 'comment', 'choice', 'endchoice', 'range', 'def_bool', \ + 'endmenu', 'tristate', 'string', 'hex', 'int', 'prompt', 'default', \ + 'depends', 'select', 'if', 'endif', 'menu'): + pass + + elif words[0] in ('help', '---help---'): + self.helplen = len(line[:line.find(words[0])].expandtabs()) + + elif words[0] == 'source': + file = self.zapquotes(words[1]) + parser = MenuParser() + self.result += parser.parse(file) + + else: + raise ParsingException, "%s:%d: Bad line: %s\n" % (self.filename, self.lineno, line.strip()) + +if __name__ == '__main__': + # called as script, not as lib + if len(sys.argv) != 2: + sys.stderr.write("Usage: symsorder.py kconfigfile\n") + sys.exit(1) + parser = MenuParser() + config = sys.argv[1] + try: + res = parser.parse(config) + except IOError: + sys.stderr.write("File %s missing\n" % config) + except ParsingException, e: + sys.stderr.write(e.message) + ================================================================ _______________________________________________ pld-cvs-commit mailing list [email protected] http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit
