BRL-CAD
vls.h
Go to the documentation of this file.
1/* V L S . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21#ifndef BU_VLS_H
22#define BU_VLS_H
23
24#include "common.h"
25#include <stdio.h> /* for FILE */
26#include <stddef.h> /* for size_t */
27#include <stdarg.h> /* For va_list */
28
29
30#include "bu/defines.h"
31#include "bu/magic.h"
32
33__BEGIN_DECLS
34
35/*----------------------------------------------------------------------*/
36/** @addtogroup bu_vls
37 *
38 * @brief
39 * Variable length strings provide a way for programmers to easily handling
40 * dynamic strings - they serve a function similar to that of std::string in
41 * C++.
42 *
43 * This frees the programmer from concerns about having character arrays large
44 * enough to hold strings.
45 *
46 * Assumption: libc-provided sprintf() function is safe to use in parallel, on
47 * parallel systems.
48 */
49/** @{ */
50/** @file bu/vls.h */
51
52/** Primary bu_vls container */
53struct bu_vls {
54 uint32_t vls_magic;
55 char *vls_str; /**< Dynamic memory for buffer */
56 size_t vls_offset; /**< Positive index into vls_str where string begins */
57 size_t vls_len; /**< Length, not counting the null */
58 size_t vls_max;
59};
60typedef struct bu_vls bu_vls_t;
61#define BU_VLS_NULL ((struct bu_vls *)0)
62
63/**
64 * assert the integrity of a bu_vls struct.
65 */
66#define BU_CK_VLS(_vp) BU_CKMAG(_vp, BU_VLS_MAGIC, "bu_vls")
67
68/**
69 * initializes a bu_vls struct without allocating any memory.
70 */
71#define BU_VLS_INIT(_vp) { \
72 (_vp)->vls_magic = BU_VLS_MAGIC; \
73 (_vp)->vls_str = NULL; \
74 (_vp)->vls_offset = (_vp)->vls_len = (_vp)->vls_max = 0; \
75 }
76
77/**
78 * macro suitable for declaration statement initialization of a bu_vls
79 * struct. does not allocate memory.
80 */
81#define BU_VLS_INIT_ZERO { BU_VLS_MAGIC, NULL, 0, 0, 0 }
82
83/**
84 * returns truthfully whether a bu_vls struct has been initialized.
85 * is not reliable unless the struct has been allocated with
86 * BU_ALLOC(), bu_calloc(), or a previous call to bu_vls_init() or
87 * BU_VLS_INIT() has been made.
88 */
89#define BU_VLS_IS_INITIALIZED(_vp) (((struct bu_vls *)(_vp) != BU_VLS_NULL) && ((_vp)->vls_magic == BU_VLS_MAGIC))
90
91/**
92 * No storage should be allocated at this point, and bu_vls_addr()
93 * must be able to live with that.
94 */
95BU_EXPORT extern void bu_vls_init(struct bu_vls *vp);
96
97/**
98 * DEPRECATED: use if (!vls) bu_vls_init(vls)
99 *
100 * If a VLS is uninitialized, initialize it. If it is already
101 * initialized, leave it alone, caller wants to append to it.
102 */
103DEPRECATED BU_EXPORT extern void bu_vls_init_if_uninit(struct bu_vls *vp);
104
105/**
106 * Allocate storage for a struct bu_vls, call bu_vls_init on it, and
107 * return the result. Allows for creation of dynamically allocated
108 * VLS strings.
109 */
110BU_EXPORT extern struct bu_vls *bu_vls_vlsinit(void);
111
112/**
113 * Return a pointer to the null-terminated string in the vls array.
114 * If no storage has been allocated yet, give back a valid string.
115 */
116BU_EXPORT extern char *bu_vls_addr(const struct bu_vls *vp);
117
118/**
119 * Return a pointer to the null-terminated string in the vls array.
120 * If no storage has been allocated yet, give back a valid string.
121 * (At the moment this function is a mnemonically-named convenience
122 * function which returns a call to bu_vls_addr.)
123 */
124BU_EXPORT extern const char *bu_vls_cstr(const struct bu_vls *vp);
125
126/**
127 * Ensure that the provided VLS has at least 'extra' characters of
128 * space available. Additional space is allocated in minimum step
129 * sized amounts and may allocate more than requested.
130 */
131BU_EXPORT extern void bu_vls_extend(struct bu_vls *vp,
132 size_t extra);
133
134/**
135 * Ensure that the vls has a length of at least 'newlen', and make
136 * that the current length.
137 *
138 * Useful for subroutines that are planning on mucking with the data
139 * array themselves. Not advisable, but occasionally useful.
140 *
141 * Does not change the offset from the front of the buffer, if any.
142 * Does not initialize the value of any of the new bytes.
143 */
144BU_EXPORT extern void bu_vls_setlen(struct bu_vls *vp,
145 size_t newlen);
146/**
147 * Return length of the string, in bytes, not including the null
148 * terminator.
149 */
150BU_EXPORT extern size_t bu_vls_strlen(const struct bu_vls *vp);
151
152/**
153 * Truncate string to at most 'len' characters. If 'len' is negative,
154 * trim off that many from the end. If 'len' is zero, don't release
155 * storage -- user is probably just going to refill it again,
156 * e.g. with bu_vls_gets().
157 */
158BU_EXPORT extern void bu_vls_trunc(struct bu_vls *vp,
159 int len);
160
161/**
162 * "Nibble" 'len' characters off the front of the string. Changes the
163 * length and offset; no data is copied.
164 *
165 * 'len' may be positive or negative. If negative, characters are
166 * un-nibbled.
167 */
168BU_EXPORT extern void bu_vls_nibble(struct bu_vls *vp,
169 b_off_t len);
170
171/**
172 * Releases the memory used for the string buffer.
173 */
174BU_EXPORT extern void bu_vls_free(struct bu_vls *vp);
175
176/**
177 * Releases the memory used for the string buffer and the memory for
178 * the vls structure
179 */
180BU_EXPORT extern void bu_vls_vlsfree(struct bu_vls *vp);
181/**
182 * Return a dynamic copy of a vls. Memory for the string being
183 * returned is acquired using bu_malloc() implying the caller must
184 * bu_free() the returned string.
185 */
186BU_EXPORT extern char *bu_vls_strdup(const struct bu_vls *vp);
187
188/**
189 * Like bu_vls_strdup(), but destructively grab the string from the
190 * source argument 'vp'. This is more efficient than bu_vls_strdup()
191 * for those instances where the source argument 'vp' is no longer
192 * needed by the caller, as it avoids a potentially long buffer copy.
193 *
194 * The source string is destroyed, as if bu_vls_free() had been
195 * called.
196 */
197BU_EXPORT extern char *bu_vls_strgrab(struct bu_vls *vp);
198
199/**
200 * Empty the vls string, and copy in a regular string.
201 */
202BU_EXPORT extern void bu_vls_strcpy(struct bu_vls *vp,
203 const char *s);
204
205/**
206 * Empty the vls string, and copy in a regular string, up to N bytes
207 * long.
208 */
209BU_EXPORT extern void bu_vls_strncpy(struct bu_vls *vp,
210 const char *s,
211 size_t n);
212
213/**
214 * Concatenate a new string onto the end of the existing vls string.
215 */
216BU_EXPORT extern void bu_vls_strcat(struct bu_vls *vp,
217 const char *s);
218
219/**
220 * Concatenate a new string onto the end of the existing vls string.
221 */
222BU_EXPORT extern void bu_vls_strncat(struct bu_vls *vp,
223 const char *s,
224 size_t n);
225
226/**
227 * Concatenate a new vls string onto the end of an existing vls
228 * string. The storage of the source string is not affected.
229 */
230BU_EXPORT extern void bu_vls_vlscat(struct bu_vls *dest,
231 const struct bu_vls *src);
232
233/**
234 * Concatenate a new vls string onto the end of an existing vls
235 * string. The storage of the source string is released (zapped).
236 */
237BU_EXPORT extern void bu_vls_vlscatzap(struct bu_vls *dest,
238 struct bu_vls *src);
239
240/**
241 * Lexicographically compare two vls strings. Returns an integer
242 * greater than, equal to, or less than 0, according as the string s1
243 * is greater than, equal to, or less than the string s2.
244 */
245BU_EXPORT extern int bu_vls_strcmp(struct bu_vls *s1,
246 struct bu_vls *s2);
247
248/**
249 * Lexicographically compare two vls strings up to n characters.
250 * Returns an integer greater than, equal to, or less than 0,
251 * according as the string s1 is greater than, equal to, or less than
252 * the string s2.
253 */
254BU_EXPORT extern int bu_vls_strncmp(struct bu_vls *s1,
255 struct bu_vls *s2,
256 size_t n);
257
258/**
259 * Given and argc & argv pair, convert them into a vls string of
260 * space-separated words.
261 */
262BU_EXPORT extern void bu_vls_from_argv(struct bu_vls *vp,
263 int argc,
264 const char *argv[]);
265
266/**
267 * Write the VLS to the provided file pointer.
268 */
269BU_EXPORT extern void bu_vls_fwrite(FILE *fp,
270 const struct bu_vls *vp);
271
272/**
273 * Write the VLS to the provided file descriptor.
274 */
275BU_EXPORT extern void bu_vls_write(int fd,
276 const struct bu_vls *vp);
277
278/**
279 * Read the remainder of a UNIX file onto the end of a vls.
280 *
281 * Returns -
282 * nread number of characters read
283 * 0 if EOF encountered immediately
284 * -1 read error
285 */
286BU_EXPORT extern int bu_vls_read(struct bu_vls *vp,
287 int fd);
288
289/**
290 * Append a newline-terminated string from the file pointed to by "fp"
291 * to the end of the vls pointed to by "vp". The newline from the
292 * file is read, but not stored into the vls.
293 *
294 * The most common error is to forget to bu_vls_trunc(vp, 0) before
295 * reading the next line into the vls.
296 *
297 * Returns -
298 * >=0 the length of the resulting vls
299 * -1 on EOF where no characters were read or added to the vls
300 */
301BU_EXPORT extern int bu_vls_gets(struct bu_vls *vp,
302 FILE *fp);
303
304/**
305 * Append the given character to the vls.
306 */
307BU_EXPORT extern void bu_vls_putc(struct bu_vls *vp,
308 int c);
309
310/**
311 * Remove leading and trailing white space from a vls string.
312 */
313BU_EXPORT extern void bu_vls_trimspace(struct bu_vls *vp);
314
315
316/**
317 * Format a string into a vls using standard variable arguments.
318 *
319 * %s continues to be a regular null-terminated 'C' string (char *).
320 * %V is a libbu variable-length string (struct bu_vls *).
321 *
322 * Other format specifiers should behave identical to printf().
323 *
324 * This routine appends to the given vls similar to how vprintf
325 * appends to stdout (see bu_vls_sprintf for overwriting the vls).
326 * The implementation ends up calling bu_vls_vprintf().
327 */
328BU_EXPORT extern void bu_vls_printf(struct bu_vls *vls,
329 const char *fmt, ...) _BU_ATTR_PRINTF23;
330
331/**
332 * Format a string into a vls, setting the vls to the given print
333 * specifier expansion. This routine truncates any existing vls
334 * contents beforehand (i.e. it doesn't append, see bu_vls_vprintf for
335 * appending to the vls).
336 *
337 * %s continues to be a regular 'C' string, null terminated.
338 * %V is a pointer to a (struct bu_vls *) string.
339 */
340BU_EXPORT extern void bu_vls_sprintf(struct bu_vls *vls,
341 const char *fmt, ...) _BU_ATTR_PRINTF23;
342
343/**
344 * Efficiently append 'cnt' spaces to the current vls.
345 */
346BU_EXPORT extern void bu_vls_spaces(struct bu_vls *vp,
347 size_t cnt);
348
349/**
350 * Returns number of printed spaces used on final output line of a
351 * potentially multi-line vls. Useful for making decisions on when to
352 * line-wrap.
353 *
354 * Accounts for normal UNIX tab-expansion:
355 * 1 2 3 4
356 * 1234567890123456789012345678901234567890
357 * x x x x
358 *
359 * 0-7 --> 8, 8-15 --> 16, 16-23 --> 24, etc.
360 */
361BU_EXPORT extern size_t bu_vls_print_positions_used(const struct bu_vls *vp);
362
363/**
364 * Given a vls, return a version of that string which has had all
365 * "tab" characters converted to the appropriate number of spaces
366 * according to the UNIX tab convention.
367 */
368BU_EXPORT extern void bu_vls_detab(struct bu_vls *vp);
369
370
371/**
372 * Add a string to the beginning of the vls.
373 */
374BU_EXPORT extern void bu_vls_prepend(struct bu_vls *vp,
375 const char *str);
376
377
378/**
379 * Copy a substring from a source vls into a destination vls
380 *
381 * where:
382 *
383 * begin - the index (0-based) of the beginning character position
384 * in the source vls
385 * nchars - the number of characters to copy
386 *
387 */
388BU_EXPORT extern void bu_vls_substr(struct bu_vls *dest, const struct bu_vls *src,
389 size_t begin, size_t nchars);
390
391/** @brief bu_vls_vprintf implementation */
392
393/**
394 * Format a string into a vls using a varargs list.
395 *
396 * %s continues to be a regular null-terminated 'C' string (char *).
397 * %V is a libbu variable-length string (struct bu_vls *).
398 *
399 * Other format specifiers should behave identical to printf().
400 *
401 * This routine appends to the given vls similar to how vprintf
402 * appends to stdout (see bu_vls_sprintf for overwriting the vls).
403 */
404BU_EXPORT extern void bu_vls_vprintf(struct bu_vls *vls,
405 const char *fmt,
406 va_list ap);
407
408
409/** @brief Routines to encode/decode strings into bu_vls structures. */
410
411/**
412 * given an input string, wrap the string in double quotes if there is
413 * a space and append it to the provided bu_vls. escape any existing
414 * double quotes.
415 *
416 * TODO: consider a specifiable quote character and octal encoding
417 * instead of double quote wrapping. perhaps specifiable encode type:
418 * BU_ENCODE_QUOTE
419 * BU_ENCODE_OCTAL
420 * BU_ENCODE_XML
421 *
422 * More thoughts on encode/decode - the nature of "quoting" is going to
423 * vary depending on the usage context and the language. For some
424 * applications, HEX or BASE64 may be appropriate. For others (like
425 * the problems with arbitrary strings in Tcl which initially motivated
426 * these functions) such wholesale encoding is not needed and it is just
427 * a subset of characters that must be escaped or otherwise identified.
428 *
429 * Given the large set of possible scenarios, it definitely makes sense
430 * to allow an encoding specifying variable, and probably other optional
431 * variables (which may be NULL, depending on the encoding type) specifying
432 * active characters (that need quoting) and an escape character (or
433 * characters? does it take more than one in some scenarios? perhaps start
434 * and end of escape strings would be the most general?)
435 *
436 * This probably makes sense as its own header given that is is really
437 * a feature on top of vls rather than something integral to vls
438 * itself - it would be workable (maybe even practical, if the final
439 * length of the encoded data can be pre-determined) to just work with
440 * char arrays: see bu_str_escape()
441 *
442 * the behavior of this routine is subject to change but should remain
443 * a reversible operation when used in conjunction with
444 * bu_vls_decode().
445 *
446 * returns a pointer to the encoded string (i.e., the substring held
447 * within the bu_vls)
448 */
449BU_EXPORT extern const char *bu_vls_encode(struct bu_vls *vp, const char *str);
450
451
452/**
453 * given an encoded input string, unwrap the string from any
454 * surrounding double quotes and unescape any embedded double quotes.
455 *
456 * the behavior of this routine is subject to change but should remain
457 * the reverse operation of bu_vls_encode().
458 *
459 * returns a pointer to the decoded string (i.e., the substring held
460 * within the bu_vls)
461 */
462BU_EXPORT extern const char *bu_vls_decode(struct bu_vls *vp, const char *str);
463
464/**
465 @brief
466 Automatic string generation routines.
467
468 There are many situations where a calling program, given an input string,
469 needs to produce automatically derived output strings that satisfy some
470 criteria (incremented, special characters removed, etc.) The functions
471 below perform this type of work.
472*/
473
474
475/**
476 * A problem frequently encountered when working with strings in BRL-CAD
477 * is the presence of special characters, characters active in the scripting
478 * language being applied, or other problematic contents that interfere with
479 * processing or readability of strings. This function takes a vls as an
480 * input and simplifies it as follows:
481 *
482 * 1) Reduce characters present to alpha-numeric characters and those
483 * characters supplied to the routine in the "keep" string. Substitute
484 * is performed as follows:
485 *
486 * * Skip any character in the "keep" string
487 *
488 * * Replace diacritic characters(code >= 192) from the extended ASCII set
489 * with a specific mapping from the standard ASCII set. See discussion at:
490 * http://stackoverflow.com/questions/14094621/ for more about this.
491 *
492 * * Replace any non-keep characters that aren't replaced by other
493 * approaches with the '_' underscore character
494 *
495 * 2) Collapses duplicate characters in the "de_dup" string.
496 *
497 * 3) Remove leading and trailing characters in the "trim' string.
498 *
499 * Returns 0 if string was not altered, 1 otherwise.
500 */
501BU_EXPORT extern int bu_vls_simplify(struct bu_vls *vp, const char *keep, const char *de_dup, const char *trim);
502
503
504/**
505 * callback type for bu_vls_incr()
506 */
507typedef int (*bu_vls_uniq_t)(struct bu_vls *v, void *data);
508
509
510/**
511 * A problem frequently encountered when generating names is
512 * generating names that are in some sense structured but avoid
513 * colliding. For example, given a geometry object named:
514 *
515 * @verbatim
516 * engine_part.s
517 * @endverbatim
518 *
519 * An application wanting to make multiple copies of engine_part.s
520 * automatically might want to produce a list of names such as:
521 *
522 * @verbatim
523 * engine_part.s-1, engine_part.s-2, engine_part.s-3, ...
524 * @endverbatim
525 *
526 * However, it is equally plausible that the desired pattern might be:
527 *
528 * @verbatim
529 * engine_part_0010.s, engine_part_0020.s, engine_part_0030.s, ...
530 * @endverbatim
531 *
532 * This function implements an engine for generating the "next" name
533 * in a sequence, given an initial name supplied by the caller and
534 * (optionally) information to identify the incrementor in the string
535 * and the incrementing behavior desired. bu_vls_incr does not track
536 * any "state" for individual strings - all information is contained
537 * either in the current state of the input string itself or the
538 * incrementation specifier (more details on the latter can be found
539 * below.)
540 *
541 * @param[in,out] name Contains the "seed" string for the name
542 * generation. Upon return the old string is cleared and the new one
543 * resides in name
544 *
545 * @param[in] regex_str Optional - user supplied regular expression
546 * for locating the incrementer substring.
547 *
548 * @param[in] incr_spec Optional - string of colon separated
549 * parameters defining function behavior.
550 *
551 * @param[in] uniq_test Optional - uniqueness testing function.
552 *
553 * @param[in] data Optional - data to pass to the uniq_test
554 * function call.
555 *
556 *
557 * @section bu_vls_incr_regexp Incrementer Substring Identification
558 *
559 * bu_vls_incr uses regular expressions to identify the numerical part
560 * of a supplied string. By default, if no regular expression is
561 * supplied by the caller, bu_vls_incr will use a numerical sequence
562 * at the end of the string (more precisely, it will use the last
563 * sequence of numbers if and only if there are no non-numerical
564 * characters between that sequence and the end of the string.) If no
565 * appropriate match is found, the incrementer will be appended to the
566 * end of the string.
567 *
568 * When no pre-existing number is found to start the sequence, the
569 * default behavior is to treat the existing string as the "0"-th item
570 * in the sequence. In such cases bu_vls_incr will thus return one,
571 * not zero, as the first incremented name in the sequence.
572 *
573 * If the caller wishes to be more sophisticated about where
574 * incrementers are found in strings, they may supply their own
575 * regular expression that uses parenthesis bounded matchers to
576 * identify numerical identifiers. For example, the regular
577 * expression:
578 *
579 * @verbatim
580 * ([-_:]*[0-9]+[-_:]*)[^0-9]*$
581 * @endverbatim
582 *
583 * will instruct bu_vls_incr to define not just the last number but
584 * the last number and any immediately surrounding separator
585 * characters as the subset of the string to process. Combined with a
586 * custom incrementation specifier, this option allows calling
587 * programs to exercise broad flexibility in how they process strings.
588 *
589 * @section bu_vls_incr_inc Specifying Incrementor Behavior
590 *
591 * The caller may optionally specify incrementation behavior with an
592 * incrementer specification string, which has the following form:
593 * "minwidth:init:max:step[:left_sepchar:right_sepchar]"
594 *
595 * The table below explains the individual elements.
596 *
597 * <table>
598 * <tr><th colspan="2">"minwidth:init:max:step[:left_sepchar:right_sepchar]"</th></tr>
599 * <tr><td>minwidth</td> <td>specifies the minimum number of digits used when printing the incrementer substring</td>
600 * <tr><td>init</td> <td>specifies the initial minimum value to use when returning an incremented string. Overrides the string-based value if that value is less than the init value.</td>
601 * <tr><td>max</td> <td>specifies the maximum value of the incrementer - if the step takes the value past this number, the counter "rolls over" to the init value.</td>
602 * <tr><td>step</td> <td>value by which the incrementor value is increased</td>
603 * <tr><td>left_sepchar</td> <td>optional - specify a character to insert to the left of the numerical substring</td>
604 * <tr><td>right_sepchar</td><td>optional - specify a character to insert to the right of the numerical substring</td>
605 * </table>
606 *
607 * In the case of minwidth, init, max, and step a '0' always indicates
608 * unspecified (i.e. "default") behavior. So, an incrementer
609 * specified as 0:0:0:0 would behave as follows:
610 *
611 * minwidth: width found in string, or standard printf handling if
612 * nothing useful is found. For example, engine_part-001.s would by
613 * default be incremented to engine_part-002.s, preserving the prefix
614 * zeros.
615 *
616 * init: from initial name string, or 0 if not found
617 *
618 * max: LONG_MAX
619 *
620 * step: 1
621 *
622 * The last two separator chars are optional - they are useful if the
623 * caller wants to guarantee a separation between the active
624 * incremented substring and its surroundings. For example, the
625 * following would prefix the incrementer output with an underscore
626 * and add a suffix with a dash:
627 *
628 * @verbatim
629 * 0:0:0:0:_:-
630 * @endverbatim
631 *
632 * @section bu_vls_incr_ex Examples
633 *
634 * To generate a suffix pattern, e.g.,:
635 *
636 * @verbatim
637 * engine_part.s-1, engine_part.s-2, engine_part.s-3, ...
638 * @endverbatim
639 *
640 * Example code is as follows:
641 *
642 * @code
643 * struct bu_vls name = BU_VLS_INIT_ZERO;
644 * bu_vls_sprintf(&name, "engine_part.s");
645 * for (int i = 0; i < 10; i++) {
646 * bu_vls_incr(&name, NULL, "0:0:0:0:-", NULL, NULL);
647 * bu_log("%s\n", bu_vls_cstr(&name));
648 * }
649 * bu_vls_free(&name);
650 * @endcode
651 *
652 * Here we show an infix case. There is no number present in the
653 * original string, we want the number *before* the .s suffix, we're
654 * incrementing by more than 1, we want four numerical digits in the
655 * string, and we want an underscore prefix spacer before the number:
656 *
657 * @verbatim
658 * engine_part_0010.s, engine_part_0020.s, engine_part_0030.s, ...
659 * @endverbatim
660 *
661 * To set this up correctly we take advantage of the bu_path_component
662 * function and construct an initial "seed" string with a zero
663 * incrementer where we need it:
664 *
665 * @code
666 * const char *estr = "engine_part.s"
667 * struct bu_vls name = BU_VLS_INIT_ZERO;
668 * bu_vls_sprintf(&name, "%s0.%s",
669 * bu_path_component(estr, BU_PATH_EXTLESS),
670 * bu_path_component(estr, BU_PATH_EXT));
671 * for (int i = 0; i < 10; i++) {
672 * bu_vls_incr(&name, NULL, "4:10:0:10:_", NULL, NULL);
673 * bu_log("%s\n", bu_vls_cstr(&name));
674 * }
675 * bu_vls_free(&name);
676 * @endcode
677 *
678 */
679BU_EXPORT extern int bu_vls_incr(struct bu_vls *name, const char *regex_str, const char *incr_spec, bu_vls_uniq_t uniq_test, void *data);
680
681__END_DECLS
682
683/** @} */
684
685#endif /* BU_VLS_H */
686
687/*
688 * Local Variables:
689 * mode: C
690 * tab-width: 8
691 * indent-tabs-mode: t
692 * c-file-style: "stroustrup"
693 * End:
694 * ex: shiftwidth=4 tabstop=8
695 */
Header file for the BRL-CAD common definitions.
#define _BU_ATTR_PRINTF23
Definition: defines.h:95
void bu_vls_putc(struct bu_vls *vp, int c)
int bu_vls_read(struct bu_vls *vp, int fd)
int(* bu_vls_uniq_t)(struct bu_vls *v, void *data)
Definition: vls.h:507
char * bu_vls_strdup(const struct bu_vls *vp)
void bu_vls_trimspace(struct bu_vls *vp)
void bu_vls_from_argv(struct bu_vls *vp, int argc, const char *argv[])
void bu_vls_vlsfree(struct bu_vls *vp)
char * bu_vls_strgrab(struct bu_vls *vp)
void bu_vls_vlscat(struct bu_vls *dest, const struct bu_vls *src)
void bu_vls_free(struct bu_vls *vp)
const char * bu_vls_encode(struct bu_vls *vp, const char *str)
Routines to encode/decode strings into bu_vls structures.
struct bu_vls * bu_vls_vlsinit(void)
void bu_vls_write(int fd, const struct bu_vls *vp)
int bu_vls_strcmp(struct bu_vls *s1, struct bu_vls *s2)
void bu_vls_sprintf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
char * bu_vls_addr(const struct bu_vls *vp)
void bu_vls_init(struct bu_vls *vp)
void bu_vls_prepend(struct bu_vls *vp, const char *str)
int bu_vls_strncmp(struct bu_vls *s1, struct bu_vls *s2, size_t n)
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
void bu_vls_fwrite(FILE *fp, const struct bu_vls *vp)
void bu_vls_spaces(struct bu_vls *vp, size_t cnt)
const char * bu_vls_decode(struct bu_vls *vp, const char *str)
void bu_vls_strncat(struct bu_vls *vp, const char *s, size_t n)
int bu_vls_simplify(struct bu_vls *vp, const char *keep, const char *de_dup, const char *trim)
Automatic string generation routines.
void bu_vls_nibble(struct bu_vls *vp, b_off_t len)
int bu_vls_gets(struct bu_vls *vp, FILE *fp)
void bu_vls_detab(struct bu_vls *vp)
void bu_vls_trunc(struct bu_vls *vp, int len)
void bu_vls_vlscatzap(struct bu_vls *dest, struct bu_vls *src)
void bu_vls_extend(struct bu_vls *vp, size_t extra)
void bu_vls_strcpy(struct bu_vls *vp, const char *s)
void bu_vls_setlen(struct bu_vls *vp, size_t newlen)
void bu_vls_substr(struct bu_vls *dest, const struct bu_vls *src, size_t begin, size_t nchars)
int bu_vls_incr(struct bu_vls *name, const char *regex_str, const char *incr_spec, bu_vls_uniq_t uniq_test, void *data)
void bu_vls_strcat(struct bu_vls *vp, const char *s)
void bu_vls_vprintf(struct bu_vls *vls, const char *fmt, va_list ap)
bu_vls_vprintf implementation
DEPRECATED void bu_vls_init_if_uninit(struct bu_vls *vp)
size_t bu_vls_strlen(const struct bu_vls *vp)
void bu_vls_strncpy(struct bu_vls *vp, const char *s, size_t n)
const char * bu_vls_cstr(const struct bu_vls *vp)
size_t bu_vls_print_positions_used(const struct bu_vls *vp)
void float float int * n
Definition: tig.h:74
void int * c
Definition: tig.h:139
#define DEPRECATED
Definition: common.h:400
#define b_off_t
Definition: common.h:222
Global registry of recognized magic numbers.
Definition: vls.h:53
uint32_t vls_magic
Definition: vls.h:54
size_t vls_offset
Definition: vls.h:56
char * vls_str
Definition: vls.h:55
size_t vls_len
Definition: vls.h:57
size_t vls_max
Definition: vls.h:58