chiark / gitweb /
Infrastructure: Strip away crufty CVS $Id$ tags.
[mLib] / hex.h
1 /* -*-c-*-
2  *
3  * Hexadecimal encoding and decoding
4  *
5  * (c) 2001 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
12  * mLib is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Library General Public License as
14  * published by the Free Software Foundation; either version 2 of the
15  * License, or (at your option) any later version.
16  *
17  * mLib is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with mLib; if not, write to the Free
24  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  * MA 02111-1307, USA.
26  */
27
28 #ifndef MLIB_HEX_H
29 #define MLIB_HEX_H
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include "dstr.h"
38
39 /*----- Data structures ---------------------------------------------------*/
40
41 typedef struct hex_ctx {
42   unsigned long acc;                    /* Accumulator for output data */
43   unsigned qsz;                         /* Length of data queued */
44   unsigned lnlen;                       /* Length of the current line */
45   const char *indent;                   /* Newline-and-indent string */
46   unsigned maxline;                     /* Maximum permitted line length */
47 } hex_ctx;
48
49 /*----- Functions provided ------------------------------------------------*/
50
51 /* --- @hex_encode@ --- *
52  *
53  * Arguments:   @hex_ctx *ctx@ = pointer to a context block
54  *              @const void *p@ = pointer to a source buffer
55  *              @size_t sz@ = size of the source buffer
56  *              @dstr *d@ = pointer to destination string
57  *
58  * Returns:     ---
59  *
60  * Use:         Encodes a binary string in hex.
61  */
62
63 extern void hex_encode(hex_ctx */*ctx*/, const void */*p*/, size_t /*sz*/,
64                        dstr */*d*/);
65
66 /* --- @hex_decode@ --- *
67  *
68  * Arguments:   @hex_ctx *ctx@ = pointer to a context block
69  *              @const void *p@ = pointer to a source buffer
70  *              @size_t sz@ = size of the source buffer
71  *              @dstr *d@ = pointer to destination string
72  *
73  * Returns:     ---
74  *
75  * Use:         Decodes a binary string in hex.  Pass in a null source
76  *              pointer when you thing you've finished.
77  */
78
79 extern void hex_decode(hex_ctx */*ctx*/, const void */*p*/, size_t /*sz*/,
80                        dstr */*d*/);
81
82 /* --- @hex_init@ --- *
83  *
84  * Arguments:   @hex_ctx *ctx@ = pointer to context block to initialize
85  *
86  * Returns:     ---
87  *
88  * Use:         Initializes a hex context properly.
89  */
90
91 extern void hex_init(hex_ctx */*ctx*/);
92
93 /*----- That's all, folks -------------------------------------------------*/
94
95 #ifdef __cplusplus
96   }
97 #endif
98
99 #endif