dvitomp fix from Akira
[mplib] / src / texk / kpathsea / fn.h
1 /* fn.h: arbitrarily long filenames (or just strings).
2
3    Copyright 2001, 2005 Olaf Weber.
4    Copyright 1993, 2008 Karl Berry.
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but 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 License
17    along with this library; if not, see <http://www.gnu.org/licenses/>.  */
18
19 #ifndef KPATHSEA_FN_H
20 #define KPATHSEA_FN_H
21
22 #include <kpathsea/c-proto.h>
23 #include <kpathsea/types.h>
24
25 /* Arbitrarily long filenames; it's inconvenient to use obstacks here,
26    because we want to maintain a null terminator.  Also used for
27    dynamically growing strings even when the null byte isn't necessary,
28    e.g., in `variable.c', since I don't want to pass obstacks around
29    everywhere, and one can't free parts of an obstack arbitrarily.  */
30
31 typedef struct
32 {
33   string str;
34   unsigned allocated;
35   unsigned length; /* includes the terminating null byte, if any */
36 } fn_type;
37
38 #define FN_STRING(fn) ((fn).str)
39 #define FN_ALLOCATED(fn) ((fn).allocated)
40 #define FN_LENGTH(fn) ((fn).length)
41
42
43 /* Create a new empty fn.  */
44 extern KPSEDLL fn_type fn_init P1H(void);
45
46 /* Create a new fn from the first LEN characters from S and a null.  */
47 extern KPSEDLL fn_type fn_copy0 P2H(const_string s,  unsigned len);
48
49 /* Free what's been allocated.  Can also just free the string if it's
50    been extracted out.  Fatal error if nothing allocated in F.  */
51 extern KPSEDLL void fn_free P1H(fn_type *f);
52
53 /* Append the character C to the fn F.  Don't append trailing null.  */
54 extern KPSEDLL void fn_1grow P2H(fn_type *f, char c);
55
56 /* Append LENGTH bytes from SOURCE to F.  */
57 extern KPSEDLL void fn_grow P3H(fn_type *f, const_string source, unsigned length);
58
59 /* Concatenate the component S to the fn F.  Assumes string currently in
60    F is null terminated.  */
61 extern KPSEDLL void fn_str_grow P2H(fn_type *f, const_string s);
62
63 /* Add a null to F's string at position LOC, and update its length.
64    Fatal error if LOC is past the end of the string.  */
65 extern KPSEDLL void fn_shrink_to P2H(fn_type *f, unsigned loc);
66
67 #endif /* not KPATHSEA_FN_H */