diff options
Diffstat (limited to 'lpg/libqr/data-parse.c')
-rw-r--r-- | lpg/libqr/data-parse.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/lpg/libqr/data-parse.c b/lpg/libqr/data-parse.c index 9129ed7..d497bdf 100644 --- a/lpg/libqr/data-parse.c +++ b/lpg/libqr/data-parse.c @@ -3,18 +3,18 @@ #include <stdlib.h> #include <qr/data.h> -#include "bitstream.h" +#include "qr-bitstream.h" #include "data-common.h" -static enum qr_data_type read_data_type(struct bitstream * stream) +static enum qr_data_type read_data_type(struct qr_bitstream * stream) { const size_t length = 4; unsigned int type; - if (bitstream_remaining(stream) < length) + if (qr_bitstream_remaining(stream) < length) return QR_DATA_INVALID; - type = bitstream_read(stream, length); + type = qr_bitstream_read(stream, length); assert(type < 16); return QR_TYPE_CODES[type]; @@ -24,7 +24,7 @@ static enum qr_data_type parse_numeric(const struct qr_data * data, char ** output, size_t * length) { - struct bitstream * stream; + struct qr_bitstream * stream; size_t field_len, bits; unsigned int digits; unsigned int chunk; @@ -34,10 +34,10 @@ static enum qr_data_type parse_numeric(const struct qr_data * data, buffer = 0; field_len = get_size_field_length(data->format, QR_DATA_NUMERIC); - if (bitstream_remaining(stream) < field_len) + if (qr_bitstream_remaining(stream) < field_len) goto invalid; - digits = bitstream_read(stream, field_len); + digits = qr_bitstream_read(stream, field_len); bits = (digits / 3) * 10; if (digits % 3 == 1) @@ -45,7 +45,7 @@ static enum qr_data_type parse_numeric(const struct qr_data * data, else if (digits % 3 == 2) bits += 7; - if (bitstream_remaining(stream) < bits) + if (qr_bitstream_remaining(stream) < bits) goto invalid; buffer = malloc(digits + 1); @@ -55,7 +55,7 @@ static enum qr_data_type parse_numeric(const struct qr_data * data, p = buffer; for (; bits >= 10; bits -= 10) { - chunk = bitstream_read(stream, 10); + chunk = qr_bitstream_read(stream, 10); if (chunk >= 1000) goto invalid; sprintf(p, "%03u", chunk); @@ -63,7 +63,7 @@ static enum qr_data_type parse_numeric(const struct qr_data * data, } if (bits > 0) { - chunk = bitstream_read(stream, bits); + chunk = qr_bitstream_read(stream, bits); if (chunk >= (bits >= 7 ? 100 : 10)) goto invalid; sprintf(p, "%0*u", bits >= 7 ? 2 : 1, chunk); @@ -84,7 +84,7 @@ static enum qr_data_type parse_alpha(const struct qr_data * data, { static const char charset[45] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; - struct bitstream * stream; + struct qr_bitstream * stream; size_t field_len, bits; unsigned int chars; unsigned int chunk; @@ -94,16 +94,16 @@ static enum qr_data_type parse_alpha(const struct qr_data * data, buffer = 0; field_len = get_size_field_length(data->format, QR_DATA_ALPHA); - if (bitstream_remaining(stream) < field_len) + if (qr_bitstream_remaining(stream) < field_len) goto invalid; - chars = bitstream_read(stream, field_len); + chars = qr_bitstream_read(stream, field_len); bits = (chars / 2) * 11; if (chars % 2 == 1) bits += 6; - if (bitstream_remaining(stream) < bits) + if (qr_bitstream_remaining(stream) < bits) goto invalid; buffer = malloc(chars + 1); @@ -114,7 +114,7 @@ static enum qr_data_type parse_alpha(const struct qr_data * data, for (; bits >= 11; bits -= 11) { unsigned int c1, c2; - chunk = bitstream_read(stream, 11); + chunk = qr_bitstream_read(stream, 11); c1 = chunk / 45; c2 = chunk % 45; if (c1 >= 45) @@ -124,7 +124,7 @@ static enum qr_data_type parse_alpha(const struct qr_data * data, } if (bits > 0) { - chunk = bitstream_read(stream, bits); + chunk = qr_bitstream_read(stream, bits); if (chunk >= 45) goto invalid; *p = charset[chunk]; @@ -143,7 +143,7 @@ static enum qr_data_type parse_8bit(const struct qr_data * data, char ** output, size_t * length) { - struct bitstream * stream; + struct qr_bitstream * stream; size_t field_len; unsigned int bytes; char * p; @@ -151,12 +151,12 @@ static enum qr_data_type parse_8bit(const struct qr_data * data, stream = data->bits; field_len = get_size_field_length(data->format, QR_DATA_8BIT); - if (bitstream_remaining(stream) < field_len) + if (qr_bitstream_remaining(stream) < field_len) return QR_DATA_INVALID; - bytes = bitstream_read(stream, field_len); + bytes = qr_bitstream_read(stream, field_len); - if (bitstream_remaining(stream) < bytes * 8) + if (qr_bitstream_remaining(stream) < bytes * 8) return QR_DATA_INVALID; *output = malloc(bytes + 1); @@ -167,7 +167,7 @@ static enum qr_data_type parse_8bit(const struct qr_data * data, *length = bytes; while (bytes-- > 0) - *p++ = bitstream_read(stream, 8); + *p++ = qr_bitstream_read(stream, 8); *p = '\0'; @@ -183,7 +183,7 @@ static enum qr_data_type parse_kanji(const struct qr_data * data, enum qr_data_type qr_get_data_type(const struct qr_data * data) { - bitstream_seek(data->bits, data->offset); + qr_bitstream_seek(data->bits, data->offset); return read_data_type(data->bits); } @@ -192,7 +192,7 @@ int qr_get_data_length(const struct qr_data * data) size_t field_len; enum qr_data_type type; - bitstream_seek(data->bits, data->offset); + qr_bitstream_seek(data->bits, data->offset); type = read_data_type(data->bits); @@ -208,17 +208,17 @@ int qr_get_data_length(const struct qr_data * data) return -1; } - if (bitstream_remaining(data->bits) < field_len) + if (qr_bitstream_remaining(data->bits) < field_len) return -1; - return (int) bitstream_read(data->bits, field_len); + return (int) qr_bitstream_read(data->bits, field_len); } enum qr_data_type qr_parse_data(const struct qr_data * input, char ** output, size_t * length) { - bitstream_seek(input->bits, input->offset); + qr_bitstream_seek(input->bits, input->offset); switch (read_data_type(input->bits)) { case QR_DATA_NUMERIC: |