Lines Matching refs:buf

56 struct Buf *buf_print_strings(struct Buf * buf, FILE* out)
60 if(!buf || !out)
61 return buf;
63 for (i=0; i < buf->nelts; i++){
64 const char * s = ((char**)buf->elts)[i];
68 return buf;
72 struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
81 buf = buf_strappend (buf, t);
83 return buf;
87 * @param buf A string buffer.
90 * @return buf
92 struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
109 buf = buf_strappend (buf, t);
111 return buf;
127 /* Appends n characters in str to buf. */
128 struct Buf *buf_strnappend (buf, str, n)
129 struct Buf *buf;
133 buf_append (buf, str, n + 1);
136 buf->nelts--;
138 return buf;
141 /* Appends characters in str to buf. */
142 struct Buf *buf_strappend (buf, str)
143 struct Buf *buf;
146 return buf_strnappend (buf, str, strlen (str));
150 struct Buf *buf_strdefine (buf, str, def)
151 struct Buf *buf;
155 buf_strappend (buf, "#define ");
156 buf_strappend (buf, " ");
157 buf_strappend (buf, str);
158 buf_strappend (buf, " ");
159 buf_strappend (buf, def);
160 buf_strappend (buf, "\n");
161 return buf;
165 * @param buf A buffer as a list of strings.
168 * @return buf
170 struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val)
182 buf_append(buf, &str, 1);
183 return buf;
187 * @param buf A buffer as a list of strings.
189 * @return buf
191 struct Buf *buf_m4_undefine (struct Buf *buf, const char* def)
202 buf_append(buf, &str, 1);
203 return buf;
206 /* create buf with 0 elements, each of size elem_size. */
207 void buf_init (buf, elem_size)
208 struct Buf *buf;
211 buf->elts = (void *) 0;
212 buf->nelts = 0;
213 buf->elt_size = elem_size;
214 buf->nmax = 0;
218 void buf_destroy (buf)
219 struct Buf *buf;
221 if (buf && buf->elts)
222 flex_free (buf->elts);
223 buf->elts = (void *) 0;
227 /* appends ptr[] to buf, grow if necessary.
229 * returns buf.
233 struct Buf *buf_append (buf, ptr, n_elem)
234 struct Buf *buf;
241 return buf;
244 if (n_elem + buf->nelts > buf->nmax) {
247 n_alloc = (n_elem + buf->nelts) * buf->elt_size;
250 if (((n_alloc * buf->elt_size) % 512) != 0
251 && buf->elt_size < 512)
254 ((n_alloc * buf->elt_size) % 512)) /
255 buf->elt_size;
257 if (!buf->elts)
258 buf->elts =
259 allocate_array (n_alloc, buf->elt_size);
261 buf->elts =
262 reallocate_array (buf->elts, n_alloc,
263 buf->elt_size);
265 buf->nmax = n_alloc;
268 memcpy ((char *) buf->elts + buf->nelts * buf->elt_size, ptr,
269 n_elem * buf->elt_size);
270 buf->nelts += n_elem;
272 return buf;