From 35baea42d794bec1fd5f2200f1f6f48877c5c26c Mon Sep 17 00:00:00 2001 From: Leo Uino Date: Thu, 14 Jul 2011 11:06:47 +0900 Subject: First attempt at parsing --- lpg/libqr/qrparse.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lpg/libqr/qrparse.c (limited to 'lpg/libqr/qrparse.c') diff --git a/lpg/libqr/qrparse.c b/lpg/libqr/qrparse.c new file mode 100644 index 0000000..4a9312f --- /dev/null +++ b/lpg/libqr/qrparse.c @@ -0,0 +1,59 @@ +#include +#include +#include + +#include +#include +#include + +#include "testqr.xbm" + +int main(int argc, char ** argv) +{ + struct qr_data * data; + int ret; + + ret = qr_code_parse(testqr_bits, + testqr_width, + (testqr_width + CHAR_BIT - 1) / CHAR_BIT, + testqr_height, + &data); + + fprintf(stderr, "qr_code_parse returned %d\n", ret); + + if (ret == 0) { + const char * ec_str, * type_str; + char * data_str; + size_t data_len; + enum qr_data_type data_type; + + fprintf(stderr, "version = %d\n", data->version); + switch (data->ec) { + case QR_EC_LEVEL_L: ec_str = "L"; break; + case QR_EC_LEVEL_M: ec_str = "M"; break; + case QR_EC_LEVEL_Q: ec_str = "Q"; break; + case QR_EC_LEVEL_H: ec_str = "H"; break; + default: ec_str = "(unknown)"; break; + } + fprintf(stderr, "EC level %s\n", ec_str); + + data_type = qr_parse_data(data, &data_str, &data_len); + switch (data_type) { + case QR_DATA_INVALID: type_str = "(invalid)"; break; + case QR_DATA_ECI: type_str = "ECI"; break; + case QR_DATA_NUMERIC: type_str = "numeric"; break; + case QR_DATA_ALPHA: type_str = "alpha"; break; + case QR_DATA_8BIT: type_str = "8-bit"; break; + case QR_DATA_KANJI: type_str = "kanji"; break; + case QR_DATA_MIXED: type_str = "mixed"; break; + case QR_DATA_FNC1: type_str = "FNC1"; break; + default: type_str = "(unknown)"; break; + } + fprintf(stderr, "Data type: %s; %lu bytes\nContent: %s\n", type_str, data_len, data_str); + free(data_str); + qr_free_data(data); + } + + return 0; +} + -- cgit v1.2.3-70-g09d2