include/nana/L_buffer.h

Go to the documentation of this file.
00001 /*
00002  * L_buffer.h -  interface to the circular buffer logging routines.
00003  *
00004  * Copyright (c) 1997 Phil Maker
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00020  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00022  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00023  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00024  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00025  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00026  * SUCH DAMAGE.
00027  *
00028  * Id: L_buffer.h,v 1.1.1.1 1997/11/23 11:45:50 pjm Exp 
00029  */
00030 
00031 
00032 #ifndef _L_buffer_h_
00033 #define _L_buffer_h_ 1
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 
00040 #ifndef _nana_config_h_
00041 #include <nana-config.h>
00042 #endif
00043 
00044 #include <stddef.h>
00045 
00046 /*
00047  * L_BUFFER - the user must use L_buffer_create() to make one
00048  *    of these for each log buffer you require.
00049  */
00050 
00051 typedef struct {
00052   size_t size;       /* number of bytes allocated */
00053   char *data;        /* the actual data[] to write into */
00054   size_t free;       /* the current location we are writing into */
00055   int wraparound;    /* true if buffer should wraparond */
00056 } L_BUFFER;
00057 
00058 /*
00059  * L_buffer_create - malloc's the log buffer and initialises it.
00060  *
00061  * L_buffer_wraparound - set the wraparound option for the log buffer.
00062  *     Note: L_buffer_create sets wraparound on by default.
00063  *
00064  * L_buffer_printf - does printf style formatting to a log buffer.
00065  *
00066  * L_buffer_puts - copies a string to a log buffer. Note that no trialing
00067  *      newline is added. This be a fair bit faster than the L_buffer_printf
00068  *      routine since we don't scan the string more than once.
00069  *
00070  * L_buffer_putchar - adds a single character to the buffer. The fastest
00071  *      way to get data into the buffer.
00072  *
00073  * L_buffer_dump - print to standard error the contents of the log buffer
00074  *      in time order (oldest first).
00075  *
00076  * L_buffer_clear - clear the log buffer as if its just been created. This
00077  *      operation is seperate from L_buffer_dump since you want to make 
00078  *      sure you've captured the dump'ed data before clearing it.
00079  *
00080  * L_buffer_free - free the memory malloc'ed for the buffer.
00081  */
00082 
00083 L_BUFFER *L_buffer_create(size_t size);
00084 
00085 void L_buffer_wraparound(L_BUFFER *b, int wraparound);
00086 
00087 #ifdef __GNUC__
00088 void L_buffer_printf(L_BUFFER *b, const char *format, ...) 
00089   __attribute__((format (printf, 2, 3)));
00090 #else
00091 void L_buffer_printf(L_BUFFER *b, const char *format, ...);
00092 #endif
00093 
00094 void L_buffer_puts(L_BUFFER *b, char *str);
00095 
00096 void L_buffer_putchar(L_BUFFER *b, char c);
00097 
00098 #ifdef stdin 
00099 void L_buffer_dump(L_BUFFER *b, FILE *fp);
00100 #endif
00101 
00102 void L_buffer_clear(L_BUFFER *b);
00103 
00104 void L_buffer_delete(L_BUFFER *);
00105 
00106 #ifdef __cplusplus
00107 }
00108 #endif
00109 
00110 #endif /* _L_buffer_h_ */
00111 

Generated on Sun Aug 21 04:18:13 2005 for Udanax-Green by doxygen1.3.4