annotate libcommon/revnibbles.c @ 135:49f259cdb39e

doc/User-oriented-commands: update for output redirection
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Feb 2021 00:31:31 +0000
parents 4360a7906f34
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 encode_hex_digit(d)
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 unsigned d;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 {
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 if (d <= 9)
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 return(d + '0');
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 else
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 return(d - 10 + 'A');
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 }
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 decode_reversed_nibbles(bytes, nbytes, dest)
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char *bytes;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned nbytes;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 char *dest;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 {
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 u_char *sp;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char *dp;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned n, c;
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 sp = bytes;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 dp = dest;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 for (n = 0; n < nbytes; n++) {
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 c = *sp & 0xF;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 *dp++ = encode_hex_digit(c);
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 c = *sp >> 4;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 *dp++ = encode_hex_digit(c);
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sp++;
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
4360a7906f34 reversed nibbles parsing functions factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }