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