summaryrefslogtreecommitdiffstats
path: root/third_party/rust/fuchsia-zircon/tools
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/fuchsia-zircon/tools
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/fuchsia-zircon/tools')
-rwxr-xr-xthird_party/rust/fuchsia-zircon/tools/gen_status.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/third_party/rust/fuchsia-zircon/tools/gen_status.py b/third_party/rust/fuchsia-zircon/tools/gen_status.py
new file mode 100755
index 0000000000..c2a954bdb1
--- /dev/null
+++ b/third_party/rust/fuchsia-zircon/tools/gen_status.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+# Copyright 2016 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# A tool for autogenerating the mapping between Status and zx_status_t
+# Usage: python gen_status.py zircon/system/public/zircon/errors.h {sys,enum,match}
+import re
+import sys
+
+status_re = re.compile('#define\s+(ZX_\w+)\s+\((\-?\d+)\)$')
+
+def parse(in_filename):
+ result = []
+ for line in file(in_filename):
+ m = status_re.match(line)
+ if m:
+ result.append((m.group(1), int(m.group(2))))
+ return result
+
+def to_snake_case(name):
+ result = []
+ for element in name.split('_'):
+ result.append(element[0] + element[1:].lower())
+ return ''.join(result)
+
+def out(style, l):
+ print('// Auto-generated using tools/gen_status.py')
+ longest = max(len(name) for (name, num) in l)
+ if style == 'sys':
+ for (name, num) in l:
+ print('pub const %s : zx_status_t = %d;' % (name.ljust(longest), num))
+ if style == 'enum':
+ print('pub enum Status {')
+ for (name, num) in l:
+ print(' %s = %d,' % (to_snake_case(name[3:]), num))
+ print('');
+ print(' /// Any zx_status_t not in the set above will map to the following:')
+ print(' UnknownOther = -32768,')
+ print('}')
+ if style == 'match':
+ for (name, num) in l:
+ print(' sys::%s => Status::%s,' % (name, to_snake_case(name[3:])))
+ print(' _ => Status::UnknownOther,')
+
+
+l = parse(sys.argv[1])
+out(sys.argv[2], l)