00001 /* $Id: agxbuf.h,v 1.6 2006/01/04 20:04:51 erg Exp $ $Revision: 1.6 $ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /********************************************************** 00005 * This software is part of the graphviz package * 00006 * http://www.graphviz.org/ * 00007 * * 00008 * Copyright (c) 1994-2004 AT&T Corp. * 00009 * and is licensed under the * 00010 * Common Public License, Version 1.0 * 00011 * by AT&T Corp. * 00012 * * 00013 * Information and Software Systems Research * 00014 * AT&T Research, Florham Park NJ * 00015 **********************************************************/ 00016 00017 #ifdef __cplusplus 00018 extern "C" { 00019 #endif 00020 00021 #ifndef AGXBUF_H 00022 #define AGXBUF_H 00023 00024 /* Extensible buffer: 00025 * Malloc'ed memory is never released until agxbfree is called. 00026 */ 00027 typedef struct { 00028 unsigned char *buf; /* start of buffer */ 00029 unsigned char *ptr; /* next place to write */ 00030 unsigned char *eptr; /* end of buffer */ 00031 int dyna; /* true if buffer is malloc'ed */ 00032 } agxbuf; 00033 00034 /* agxbinit: 00035 * Initializes new agxbuf; caller provides memory. 00036 * Assume if init is non-null, hint = sizeof(init[]) 00037 */ 00038 extern void agxbinit(agxbuf * xb, unsigned int hint, 00039 unsigned char *init); 00040 00041 /* agxbput_n: 00042 * Append string s of length n into xb 00043 */ 00044 extern int agxbput_n(agxbuf * xb, char *s, unsigned int n); 00045 00046 /* agxbput: 00047 * Append string s into xb 00048 */ 00049 extern int agxbput(agxbuf * xb, char *s); 00050 00051 /* agxbfree: 00052 * Free any malloced resources. 00053 */ 00054 extern void agxbfree(agxbuf * xb); 00055 00056 /* agxbpop: 00057 * Removes last character added, if any. 00058 */ 00059 extern int agxbpop(agxbuf * xb); 00060 00061 /* agxbmore: 00062 * Expand buffer to hold at least ssz more bytes. 00063 */ 00064 extern int agxbmore(agxbuf * xb, int unsigned ssz); 00065 00066 /* agxbputc: 00067 * Add character to buffer. 00068 * int agxbputc(agxbuf*, char) 00069 */ 00070 #define agxbputc(X,C) ((((X)->ptr >= (X)->eptr) ? agxbmore(X,1) : 0), \ 00071 (int)(*(X)->ptr++ = ((unsigned char)C))) 00072 00073 /* agxbuse: 00074 * Null-terminates buffer; resets and returns pointer to data; 00075 * char* agxbuse(agxbuf* xb) 00076 */ 00077 #define agxbuse(X) (agxbputc(X,'\0'),(char*)((X)->ptr = (X)->buf)) 00078 00079 /* agxbstart: 00080 * Return pointer to beginning of buffer. 00081 * char* agxbstart(agxbuf* xb) 00082 */ 00083 #define agxbstart(X) ((char*)((X)->buf)) 00084 00085 /* agxblen: 00086 * Return number of characters currently stored. 00087 * int agxblen(agxbuf* xb) 00088 */ 00089 #define agxblen(X) (((X)->ptr)-((X)->buf)) 00090 00091 /* agxbclear: 00092 * Resets pointer to data; 00093 * void agxbclear(agxbuf* xb) 00094 */ 00095 #define agxbclear(X) ((void)((X)->ptr = (X)->buf)) 00096 00097 /* agxbnext: 00098 * Next position for writing. 00099 * char* agxbnext(agxbuf* xb) 00100 */ 00101 #define agxbnext(X) ((char*)((X)->ptr)) 00102 00103 #endif 00104 00105 #ifdef __cplusplus 00106 } 00107 #endif