| 1 |
/* fn.h: arbitrarily long filenames (or just strings). |
| 2 |
|
| 3 |
Copyright 2001, 2005 Olaf Weber. |
| 4 |
Copyright 1993, 2008, 2011 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 |
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */ |
| 23 |
|
| 24 |
#include <kpathsea/c-proto.h> |
| 25 |
#include <kpathsea/types.h> |
| 26 |
|
| 27 |
/* Arbitrarily long filenames; it's inconvenient to use obstacks here, |
| 28 |
because we want to maintain a null terminator. Also used for |
| 29 |
dynamically growing strings even when the null byte isn't necessary, |
| 30 |
e.g., in `variable.c', since I don't want to pass obstacks around |
| 31 |
everywhere, and one can't free parts of an obstack arbitrarily. */ |
| 32 |
|
| 33 |
typedef struct |
| 34 |
{ |
| 35 |
string str; |
| 36 |
unsigned allocated; |
| 37 |
unsigned length; /* includes the terminating null byte, if any */ |
| 38 |
} fn_type; |
| 39 |
|
| 40 |
#define FN_STRING(fn) ((fn).str) |
| 41 |
#define FN_ALLOCATED(fn) ((fn).allocated) |
| 42 |
#define FN_LENGTH(fn) ((fn).length) |
| 43 |
|
| 44 |
|
| 45 |
/* Create a new empty fn. */ |
| 46 |
extern fn_type fn_init (void); |
| 47 |
|
| 48 |
/* Create a new fn from the first LEN characters from S and a null. */ |
| 49 |
extern fn_type fn_copy0 (const_string s, unsigned len); |
| 50 |
|
| 51 |
/* Free what's been allocated. Can also just free the string if it's |
| 52 |
been extracted out. Fatal error if nothing allocated in F. */ |
| 53 |
extern void fn_free (fn_type *f); |
| 54 |
|
| 55 |
/* Append the character C to the fn F. Don't append trailing null. */ |
| 56 |
extern void fn_1grow (fn_type *f, char c); |
| 57 |
|
| 58 |
/* Append LENGTH bytes from SOURCE to F. */ |
| 59 |
extern void fn_grow (fn_type *f, const_string source, unsigned length); |
| 60 |
|
| 61 |
/* Concatenate the component S to the fn F. Assumes string currently in |
| 62 |
F is null terminated. */ |
| 63 |
extern void fn_str_grow (fn_type *f, const_string s); |
| 64 |
|
| 65 |
/* Add a null to F's string at position LOC, and update its length. |
| 66 |
Fatal error if LOC is past the end of the string. */ |
| 67 |
extern void fn_shrink_to (fn_type *f, unsigned loc); |
| 68 |
|
| 69 |
#endif /* MAKE_KPSE_DLL */ |
| 70 |
|
| 71 |
#endif /* not KPATHSEA_FN_H */ |