FreeCalypso > hg > fc-pcsc-tools
annotate libutil/revnibbles.c @ 176:0ead466ba987
bfsearch-booty: grcard-fs-tree renamed to grcard2-fs-tree
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 02 Mar 2021 05:08:34 +0000 |
parents | 2557012666ea |
children |
rev | line source |
---|---|
7
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements some reversed-nibbles parsing functions. |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 decode_reversed_nibbles(bytes, nbytes, dest) |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 u_char *bytes; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 unsigned nbytes; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 char *dest; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 { |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char *sp; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char *dp; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 unsigned n, c; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 sp = bytes; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 dp = dest; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 for (n = 0; n < nbytes; n++) { |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 c = *sp & 0xF; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 *dp++ = encode_hex_digit(c); |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 c = *sp >> 4; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 *dp++ = encode_hex_digit(c); |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 sp++; |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
4360a7906f34
reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
159
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
26 |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
27 pack_reversed_nibbles(nibbles, bytes, nbytes) |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
28 u_char *nibbles, *bytes; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
29 unsigned nbytes; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
30 { |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
31 u_char *sp, *dp; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
32 unsigned n; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
33 |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
34 sp = nibbles; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
35 dp = bytes; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
36 for (n = 0; n < nbytes; n++) { |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
37 *dp++ = sp[0] | (sp[1] << 4); |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
38 sp += 2; |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
39 } |
2557012666ea
libutil: pack_reversed_nibbles() moved to revnibbles.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
158
diff
changeset
|
40 } |