2999
|
1 /* fn.h: arbitrarily long filenames (or just strings). |
|
2 |
|
3 Copyright (C) 1993 Karl Berry. |
|
4 |
|
5 This library is free software; you can redistribute it and/or |
|
6 modify it under the terms of the GNU Library General Public |
|
7 License as published by the Free Software Foundation; either |
|
8 version 2 of the License, or (at your option) any later version. |
|
9 |
|
10 This library is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 Library General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU Library General Public |
|
16 License along with this library; if not, write to the Free Software |
|
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
|
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 fn_type fn_init P1H(void); |
|
45 |
|
46 /* Create a new fn from the first LEN characters from S and a null. */ |
|
47 extern 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 void fn_free P1H(fn_type *f); |
|
52 |
|
53 /* Append the character C to the fn F. Don't append trailing null. */ |
|
54 extern void fn_1grow P2H(fn_type *f, char c); |
|
55 |
|
56 /* Append LENGTH bytes from SOURCE to F. */ |
|
57 extern void fn_grow P3H(fn_type *f, address source, unsigned length); |
|
58 |
|
59 /* Concatenate the component S to the fn F. Assumes string currently in |
|
60 F is null terminated. */ |
|
61 extern 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 void fn_shrink_to P2H(fn_type *f, unsigned loc); |
|
66 |
|
67 #endif /* not KPATHSEA_FN_H */ |