1 | /* dstring.h - Dynamic string handling include file. Requires strings.h.
|
---|
2 | Copyright (C) 1990-1992, 2004, 2007, 2010, 2014-2015 Free Software
|
---|
3 | Foundation, Inc.
|
---|
4 |
|
---|
5 | This program is free software; you can redistribute it and/or modify
|
---|
6 | it under the terms of the GNU General Public License as published by
|
---|
7 | the Free Software Foundation; either version 3, or (at your option)
|
---|
8 | any later version.
|
---|
9 |
|
---|
10 | This program 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
|
---|
13 | GNU General Public License for more details.
|
---|
14 |
|
---|
15 | You should have received a copy of the GNU General Public
|
---|
16 | License along with this program; if not, write to the Free
|
---|
17 | Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
18 | Boston, MA 02110-1301 USA. */
|
---|
19 |
|
---|
20 | #ifndef NULL
|
---|
21 | #define NULL 0
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* A dynamic string consists of record that records the size of an
|
---|
25 | allocated string and the pointer to that string. The actual string
|
---|
26 | is a normal zero byte terminated string that can be used with the
|
---|
27 | usual string functions. The major difference is that the
|
---|
28 | dynamic_string routines know how to get more space if it is needed
|
---|
29 | by allocating new space and copying the current string. */
|
---|
30 |
|
---|
31 | typedef struct
|
---|
32 | {
|
---|
33 | int ds_length; /* Actual amount of storage allocated. */
|
---|
34 | char *ds_string; /* String. */
|
---|
35 | } dynamic_string;
|
---|
36 |
|
---|
37 |
|
---|
38 | /* Macros that look similar to the original string functions.
|
---|
39 | WARNING: These macros work only on pointers to dynamic string records.
|
---|
40 | If used with a real record, an "&" must be used to get the pointer. */
|
---|
41 | #define ds_strlen(s) strlen ((s)->ds_string)
|
---|
42 | #define ds_strcmp(s1, s2) strcmp ((s1)->ds_string, (s2)->ds_string)
|
---|
43 | #define ds_strncmp(s1, s2, n) strncmp ((s1)->ds_string, (s2)->ds_string, n)
|
---|
44 | #define ds_index(s, c) index ((s)->ds_string, c)
|
---|
45 | #define ds_rindex(s, c) rindex ((s)->ds_string, c)
|
---|
46 |
|
---|
47 | void ds_init (dynamic_string *string, int size);
|
---|
48 | void ds_resize (dynamic_string *string, int size);
|
---|
49 | char *ds_fgetname (FILE *f, dynamic_string *s);
|
---|
50 | char *ds_fgets (FILE *f, dynamic_string *s);
|
---|
51 | char *ds_fgetstr (FILE *f, dynamic_string *s, char eos);
|
---|