1 /*
2  * L_buffer.h -  interface to the circular buffer logging routines.
3  *
4  * Copyright (c) 1997 Phil Maker
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * Id: L_buffer.h,v 1.1.1.1 1997/11/23 11:45:50 pjm Exp
29  */
30 
31 
32 #ifndef _L_buffer_h_
33 #define _L_buffer_h_ 1
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 
40 #ifndef _nana_config_h_
41 #include <nana-config.h>
42 #endif
43 
44 #include <stddef.h>
45 
46 /*
47  * L_BUFFER - the user must use L_buffer_create() to make one
48  *    of these for each log buffer you require.
49  */
50 
51 typedef struct {
52   size_t size;       /* number of bytes allocated */
53   char *data;        /* the actual data[] to write into */
54   size_t free;       /* the current location we are writing into */
55   int wraparound;    /* true if buffer should wraparond */
56 } L_BUFFER;
57 
58 /*
59  * L_buffer_create - malloc's the log buffer and initialises it.
60  *
61  * L_buffer_wraparound - set the wraparound option for the log buffer.
62  *     Note: L_buffer_create sets wraparound on by default.
63  *
64  * L_buffer_printf - does printf style formatting to a log buffer.
65  *
66  * L_buffer_puts - copies a string to a log buffer. Note that no trialing
67  *      newline is added. This be a fair bit faster than the L_buffer_printf
68  *      routine since we don't scan the string more than once.
69  *
70  * L_buffer_putchar - adds a single character to the buffer. The fastest
71  *      way to get data into the buffer.
72  *
73  * L_buffer_dump - print to standard error the contents of the log buffer
74  *      in time order (oldest first).
75  *
76  * L_buffer_clear - clear the log buffer as if its just been created. This
77  *      operation is seperate from L_buffer_dump since you want to make
78  *      sure you've captured the dump'ed data before clearing it.
79  *
80  * L_buffer_free - free the memory malloc'ed for the buffer.
81  */
82 
83 L_BUFFER *L_buffer_create(size_t size);
84 
85 void L_buffer_wraparound(L_BUFFER *b, int wraparound);
86 
87 #ifdef __GNUC__
88 void L_buffer_printf(L_BUFFER *b, const char *format, ...)
89   __attribute__((format (printf, 2, 3)));
90 #else
91 void L_buffer_printf(L_BUFFER *b, const char *format, ...);
92 #endif
93 
94 void L_buffer_puts(L_BUFFER *b, char *str);
95 
96 void L_buffer_putchar(L_BUFFER *b, char c);
97 
98 #ifdef stdin
99 void L_buffer_dump(L_BUFFER *b, FILE *fp);
100 #endif
101 
102 void L_buffer_clear(L_BUFFER *b);
103 
104 void L_buffer_delete(L_BUFFER *);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* _L_buffer_h_ */
111 
112