|
Graphviz
2.29.20120523.0446
|
00001 /* $Id$ $Revision$ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /************************************************************************* 00005 * Copyright (c) 2011 AT&T Intellectual Property 00006 * All rights reserved. This program and the accompanying materials 00007 * are made available under the terms of the Eclipse Public License v1.0 00008 * which accompanies this distribution, and is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * 00011 * Contributors: See CVS logs. Details at http://www.graphviz.org/ 00012 *************************************************************************/ 00013 00014 #ifdef __cplusplus 00015 extern "C" { 00016 #endif 00017 00018 #ifndef AGXBUF_H 00019 #define AGXBUF_H 00020 00021 /* Extensible buffer: 00022 * Malloc'ed memory is never released until agxbfree is called. 00023 */ 00024 typedef struct { 00025 unsigned char *buf; /* start of buffer */ 00026 unsigned char *ptr; /* next place to write */ 00027 unsigned char *eptr; /* end of buffer */ 00028 int dyna; /* true if buffer is malloc'ed */ 00029 } agxbuf; 00030 00031 /* agxbinit: 00032 * Initializes new agxbuf; caller provides memory. 00033 * Assume if init is non-null, hint = sizeof(init[]) 00034 */ 00035 extern void agxbinit(agxbuf * xb, unsigned int hint, 00036 unsigned char *init); 00037 00038 /* agxbput_n: 00039 * Append string s of length n into xb 00040 */ 00041 extern int agxbput_n(agxbuf * xb, const char *s, unsigned int n); 00042 00043 /* agxbput: 00044 * Append string s into xb 00045 */ 00046 extern int agxbput(agxbuf * xb, const char *s); 00047 00048 /* agxbfree: 00049 * Free any malloced resources. 00050 */ 00051 extern void agxbfree(agxbuf * xb); 00052 00053 /* agxbpop: 00054 * Removes last character added, if any. 00055 */ 00056 extern int agxbpop(agxbuf * xb); 00057 00058 /* agxbmore: 00059 * Expand buffer to hold at least ssz more bytes. 00060 */ 00061 extern int agxbmore(agxbuf * xb, int unsigned ssz); 00062 00063 /* agxbputc: 00064 * Add character to buffer. 00065 * int agxbputc(agxbuf*, char) 00066 */ 00067 #define agxbputc(X,C) ((((X)->ptr >= (X)->eptr) ? agxbmore(X,1) : 0), \ 00068 (int)(*(X)->ptr++ = ((unsigned char)C))) 00069 00070 /* agxbuse: 00071 * Null-terminates buffer; resets and returns pointer to data; 00072 * char* agxbuse(agxbuf* xb) 00073 */ 00074 #define agxbuse(X) (agxbputc(X,'\0'),(char*)((X)->ptr = (X)->buf)) 00075 00076 /* agxbstart: 00077 * Return pointer to beginning of buffer. 00078 * char* agxbstart(agxbuf* xb) 00079 */ 00080 #define agxbstart(X) ((char*)((X)->buf)) 00081 00082 /* agxblen: 00083 * Return number of characters currently stored. 00084 * int agxblen(agxbuf* xb) 00085 */ 00086 #define agxblen(X) (((X)->ptr)-((X)->buf)) 00087 00088 /* agxbclear: 00089 * Resets pointer to data; 00090 * void agxbclear(agxbuf* xb) 00091 */ 00092 #define agxbclear(X) ((void)((X)->ptr = (X)->buf)) 00093 00094 /* agxbnext: 00095 * Next position for writing. 00096 * char* agxbnext(agxbuf* xb) 00097 */ 00098 #define agxbnext(X) ((char*)((X)->ptr)) 00099 00100 #endif 00101 00102 #ifdef __cplusplus 00103 } 00104 #endif
1.7.5