aboutsummaryrefslogtreecommitdiffstats
path: root/tools/make-usb.py
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2019-04-14 22:24:58 +0100
committerGerald Combs <gerald@wireshark.org>2019-04-14 21:36:58 +0000
commit1c4885deaf448e0ed30d8266043d3f776bcc8c33 (patch)
treef21dddca9a4e4991e22ba1424cc029e6355fc774 /tools/make-usb.py
parent651bdf592b0334d559c0e5e90d787fda635ecaf3 (diff)
make-usb.py: use octal escape sequences
Fixes errors like: epan/dissectors/usb.c:15220:42: error: hex escape sequence out of range { 0x0cad9001, "PowerPad Pocket PC\xc2\xa0Device" }, Change-Id: I8c120892c0d52aceb3f6767401e7944353495825 Fixes: v3.1.0rc0-524-g6f57aa72a8 ("Make a couple of scripts Python 3 only.") Reviewed-on: https://code.wireshark.org/review/32854 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'tools/make-usb.py')
-rwxr-xr-xtools/make-usb.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/tools/make-usb.py b/tools/make-usb.py
index 19d776bd85..b63f477314 100755
--- a/tools/make-usb.py
+++ b/tools/make-usb.py
@@ -34,15 +34,21 @@ products = dict()
vendors_str="static const value_string usb_vendors_vals[] = {\n"
products_str="static const value_string usb_products_vals[] = {\n"
+# Escape backslashes, quotes, control characters and non-ASCII characters.
+escapes = {}
+for i in range(256):
+ if i in b'\\"':
+ escapes[i] = '\\%c' % i
+ elif i in range(0x20, 0x80) or i in b'\t':
+ escapes[i] = chr(i)
+ else:
+ escapes[i] = '\\%03o' % i
for utf8line in lines:
# Convert single backslashes to double (escaped) backslashes, escape quotes, etc.
utf8line = utf8line.rstrip()
- utf8line = utf8line.replace('\\', '\\\\')
- utf8line = utf8line.replace('"', '\\"')
utf8line = re.sub("\?+", "?", utf8line)
- # Finally, convert non-ASCII UTF-8 sequences to C-style escapes
- line = utf8line.encode('UTF-8').decode('ascii', 'backslashreplace')
+ line = ''.join(escapes[byte] for byte in utf8line.encode('utf8'))
if line == "# Vendors, devices and interfaces. Please keep sorted.":
mode = MODE_VENDOR_PRODUCT