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