linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Anderson Lizardo <anderson.lizardo@openbossa.org>
Subject: [PATCH v2 BlueZ] tools: Add script for updating bt_compidtostr() implementation
Date: Fri,  3 May 2013 16:19:31 -0400	[thread overview]
Message-ID: <1367612371-20930-1-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1365706752-4442-1-git-send-email-anderson.lizardo@openbossa.org>

This script uses curl and html2text to fetch company IDs from
bluetooth.org's "Assigned Numbers" section.
---

v2:

* Use iconv to strip unrelated UTF-8 text from the HTML prior to passing it to
  html2text.
* Add simple sanity check for when HTML parsing fails.


 tools/update_compids.sh |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100755 tools/update_compids.sh

diff --git a/tools/update_compids.sh b/tools/update_compids.sh
new file mode 100755
index 0000000..296e32f
--- /dev/null
+++ b/tools/update_compids.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Download the list of company IDs from bluetooth.org and generate a diff which
+# can be applied to source tree to update bt_compidtostr(). Usage:
+#
+# 1) ./tools/update_compids.sh | git apply -p0
+# 2) Inspect changes to make sure they are sane
+# 3) git commit -m "lib: Update list of company identifiers" lib/bluetooth.c
+#
+# Requires html2text: http://www.mbayer.de/html2text/
+#
+set -e -u
+
+tmpdir=$(mktemp -d)
+trap "rm -rf $tmpdir" EXIT
+
+mkdir $tmpdir/lib
+cp lib/bluetooth.c $tmpdir/lib/bluetooth.c.orig
+cp lib/bluetooth.c $tmpdir/lib/bluetooth.c
+
+cd $tmpdir
+
+path=en-us/specification/assigned-numbers-overview/company-identifiers
+# Use "iconv -c" to strip unwanted unicode characters
+curl https://www.bluetooth.org/$path | iconv -c -f UTF-8 -t ISO-8859-1 | \
+    html2text -ascii -o identifiers.txt
+
+sed -n '/^const char \*bt_compidtostr(int compid)/,/^}/p' \
+    lib/bluetooth.c > old.c
+
+echo -e 'const char *bt_compidtostr(int compid)\n{\n\tswitch (compid) {' > new.c
+cat identifiers.txt |
+    perl -ne 'm/^(\d+)\s+0x[0-9a-f]+\s+(.*)/i &&
+        print "\tcase $1:\n\t\treturn \"$2\";\n"' >> new.c
+if ! grep -q "return \"" new.c; then
+    echo "ERROR: could not parse company IDs from bluetooth.org" >&2
+    exit 1
+fi
+echo -e '\tcase 65535:\n\t\treturn "internal use";' >> new.c
+echo -e '\tdefault:\n\t\treturn "not assigned";\n\t}\n}' >> new.c
+
+diff -Naur old.c new.c | patch -sp0 lib/bluetooth.c
+diff -Naur lib/bluetooth.c.orig lib/bluetooth.c
-- 
1.7.9.5


  parent reply	other threads:[~2013-05-03 20:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 18:59 [PATCH BlueZ 1/2] tools: Add script for updating bt_compidtostr() implementation Anderson Lizardo
2013-04-11 18:59 ` [PATCH BlueZ 2/2] lib: Fix list of company identifiers Anderson Lizardo
2013-04-30 10:32   ` Johan Hedberg
2013-04-30 10:06 ` [PATCH BlueZ 1/2] tools: Add script for updating bt_compidtostr() implementation Johan Hedberg
2013-04-30 12:32   ` Anderson Lizardo
2013-04-30 12:36     ` Anderson Lizardo
2013-04-30 13:49       ` Johan Hedberg
2013-05-03 20:19 ` Anderson Lizardo [this message]
2013-05-16 13:13   ` [PATCH v2 BlueZ] " Anderson Lizardo
2013-05-17  7:28     ` Johan Hedberg
2013-05-17 10:49       ` Anderson Lizardo
2013-05-17 14:21   ` [PATCH v3 " Anderson Lizardo
2013-05-19  4:06     ` Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1367612371-20930-1-git-send-email-anderson.lizardo@openbossa.org \
    --to=anderson.lizardo@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).