Graphviz  2.41.20171026.1811
agxbuf.h
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #ifndef AGXBUF_H
19 #define AGXBUF_H
20 
21 #ifdef _WIN32
22 # ifdef EXPORT_AGXBUF
23 # define AGXBUF_API __declspec(dllexport)
24 # else
25 # define AGXBUF_API __declspec(dllimport)
26 # endif
27 #else
28 # define AGXBUF_API extern
29 #endif
30 
31 /* Extensible buffer:
32  * Malloc'ed memory is never released until agxbfree is called.
33  */
34  typedef struct {
35  unsigned char *buf; /* start of buffer */
36  unsigned char *ptr; /* next place to write */
37  unsigned char *eptr; /* end of buffer */
38  int dyna; /* true if buffer is malloc'ed */
39  } agxbuf;
40 
41 /* agxbinit:
42  * Initializes new agxbuf; caller provides memory.
43  * Assume if init is non-null, hint = sizeof(init[])
44  */
45  AGXBUF_API void agxbinit(agxbuf * xb, unsigned int hint,
46  unsigned char *init);
47 
48 /* agxbput_n:
49  * Append string s of length n into xb
50  */
51  AGXBUF_API size_t agxbput_n(agxbuf * xb, const char *s, size_t n);
52 
53 /* agxbput:
54  * Append string s into xb
55  */
56  AGXBUF_API size_t agxbput(agxbuf * xb, const char *s);
57 
58 /* agxbfree:
59  * Free any malloced resources.
60  */
61  AGXBUF_API void agxbfree(agxbuf * xb);
62 
63 /* agxbpop:
64  * Removes last character added, if any.
65  */
66  AGXBUF_API int agxbpop(agxbuf * xb);
67 
68 /* agxbmore:
69  * Expand buffer to hold at least ssz more bytes.
70  */
71  AGXBUF_API int agxbmore(agxbuf * xb, size_t ssz);
72 
73 /* agxbputc:
74  * Add character to buffer.
75  * int agxbputc(agxbuf*, char)
76  */
77 #define agxbputc(X,C) ((((X)->ptr >= (X)->eptr) ? agxbmore(X,1) : 0), (void)(*(X)->ptr++ = ((unsigned char)C)))
78 
79 /* agxbuse:
80  * Null-terminates buffer; resets and returns pointer to data;
81  * char* agxbuse(agxbuf* xb)
82  */
83 #define agxbuse(X) ((void)agxbputc(X,'\0'),(char*)((X)->ptr = (X)->buf))
84 
85 /* agxbstart:
86  * Return pointer to beginning of buffer.
87  * char* agxbstart(agxbuf* xb)
88  */
89 #define agxbstart(X) ((char*)((X)->buf))
90 
91 /* agxblen:
92  * Return number of characters currently stored.
93  * int agxblen(agxbuf* xb)
94  */
95 #define agxblen(X) (((X)->ptr)-((X)->buf))
96 
97 /* agxbclear:
98  * Resets pointer to data;
99  * void agxbclear(agxbuf* xb)
100  */
101 #define agxbclear(X) ((void)((X)->ptr = (X)->buf))
102 
103 /* agxbnext:
104  * Next position for writing.
105  * char* agxbnext(agxbuf* xb)
106  */
107 #define agxbnext(X) ((char*)((X)->ptr))
108 
109 #endif
110 
111 #ifdef __cplusplus
112 }
113 #endif
unsigned char * buf
Definition: agxbuf.h:35
size_t agxbput(agxbuf *xb, const char *s)
Definition: agxbuf.c:84
int dyna
Definition: agxbuf.h:38
unsigned char * eptr
Definition: agxbuf.h:37
int agxbpop(agxbuf *xb)
Definition: agxbuf.c:103
void agxbinit(agxbuf *xb, unsigned int hint, unsigned char *init)
Definition: agxbuf.c:25
Definition: grammar.c:79
#define AGXBUF_API
Definition: agxbuf.h:28
size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
Definition: agxbuf.c:72
Definition: agxbuf.h:34
unsigned char * ptr
Definition: agxbuf.h:36
void agxbfree(agxbuf *xb)
Definition: agxbuf.c:94
int agxbmore(agxbuf *xb, size_t ssz)
Definition: agxbuf.c:44