diff options
author | Stefan Hajnoczi <stefanha@gmail.com> | 2008-05-10 15:06:21 +0100 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2008-05-20 20:28:48 +0100 |
commit | fbf9295cbbbb2f4ac66d3150b92491ff9c4fccf8 (patch) | |
tree | 04e69a70aedd80a3ed678df50962542a810a1e29 /contrib/errcode/build_errcodedb.py | |
parent | ce298a9628b0f78631a326c1c60b9c8e990f23f8 (diff) | |
download | ipxe-fbf9295cbbbb2f4ac66d3150b92491ff9c4fccf8.tar.gz |
[Contribs] Add README, license text, and invert error code dictionaries.
Diffstat (limited to 'contrib/errcode/build_errcodedb.py')
-rwxr-xr-x | contrib/errcode/build_errcodedb.py | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/contrib/errcode/build_errcodedb.py b/contrib/errcode/build_errcodedb.py index 295c9271..868c2d3a 100755 --- a/contrib/errcode/build_errcodedb.py +++ b/contrib/errcode/build_errcodedb.py @@ -1,4 +1,19 @@ #!/usr/bin/env python +# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>. +# +# This program 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 any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import sys import re @@ -15,6 +30,15 @@ def err(msg): sys.stderr.write('%s: %s\n' % (sys.argv[0], msg)) sys.exit(1) +def to_pxenv_status(errno): + return errno & 0xff + +def to_errfile(errno): + return (errno >> 13) & 0x7ff + +def to_posix_errno(errno): + return (errno >> 24) & 0x7f + def load_header_file(filename, regexp): defines = {} for line in open(filename, 'r'): @@ -42,7 +66,7 @@ def evaluate(defines, expr): err('invalid expression') return eval(pyexpr) -def build(filenames, regexp): +def build(filenames, regexp, selector): unevaluated = {} for filename in filenames: unevaluated.update(load_header_file(filename, regexp)) @@ -59,8 +83,12 @@ def build(filenames, regexp): changed = True if unevaluated: err('unable to evaluate all #defines') - return evaluated -print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE)) -print 'errfile =', repr(build(errfile_files, ERRFILE_RE)) -print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE)) + lookup = {} + for key, val in evaluated.iteritems(): + lookup[selector(val)] = key + return lookup + +print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE, to_pxenv_status)) +print 'errfile =', repr(build(errfile_files, ERRFILE_RE, to_errfile)) +print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE, to_posix_errno)) |