Blame src/dstring.h

Packit 1ef1a9
/* dstring.h - Dynamic string handling include file.  Requires strings.h.
Packit 1ef1a9
   Copyright (C) 1990-1992, 2004, 2007, 2010, 2014-2015 Free Software
Packit 1ef1a9
   Foundation, Inc.
Packit 1ef1a9
Packit 1ef1a9
   This program is free software; you can redistribute it and/or modify
Packit 1ef1a9
   it under the terms of the GNU General Public License as published by
Packit 1ef1a9
   the Free Software Foundation; either version 3, or (at your option)
Packit 1ef1a9
   any later version.
Packit 1ef1a9
Packit 1ef1a9
   This program is distributed in the hope that it will be useful,
Packit 1ef1a9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 1ef1a9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 1ef1a9
   GNU General Public License for more details.
Packit 1ef1a9
Packit 1ef1a9
   You should have received a copy of the GNU General Public
Packit 1ef1a9
   License along with this program; if not, write to the Free
Packit 1ef1a9
   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit 1ef1a9
   Boston, MA 02110-1301 USA.  */
Packit 1ef1a9
Packit 1ef1a9
#ifndef NULL
Packit 1ef1a9
#define NULL 0
Packit 1ef1a9
#endif
Packit 1ef1a9
Packit 1ef1a9
/* A dynamic string consists of record that records the size of an
Packit 1ef1a9
   allocated string and the pointer to that string.  The actual string
Packit 1ef1a9
   is a normal zero byte terminated string that can be used with the
Packit 1ef1a9
   usual string functions.  The major difference is that the
Packit 1ef1a9
   dynamic_string routines know how to get more space if it is needed
Packit 1ef1a9
   by allocating new space and copying the current string.  */
Packit 1ef1a9
Packit 1ef1a9
typedef struct
Packit 1ef1a9
{
Packit 1ef1a9
  int ds_length;		/* Actual amount of storage allocated.  */
Packit 1ef1a9
  char *ds_string;		/* String.  */
Packit 1ef1a9
} dynamic_string;
Packit 1ef1a9
Packit 1ef1a9
Packit 1ef1a9
/* Macros that look similar to the original string functions.
Packit 1ef1a9
   WARNING:  These macros work only on pointers to dynamic string records.
Packit 1ef1a9
   If used with a real record, an "&" must be used to get the pointer.  */
Packit 1ef1a9
#define ds_strlen(s)		strlen ((s)->ds_string)
Packit 1ef1a9
#define ds_strcmp(s1, s2)	strcmp ((s1)->ds_string, (s2)->ds_string)
Packit 1ef1a9
#define ds_strncmp(s1, s2, n)	strncmp ((s1)->ds_string, (s2)->ds_string, n)
Packit 1ef1a9
#define ds_index(s, c)		index ((s)->ds_string, c)
Packit 1ef1a9
#define ds_rindex(s, c)		rindex ((s)->ds_string, c)
Packit 1ef1a9
Packit 1ef1a9
void ds_init (dynamic_string *string, int size);
Packit 1ef1a9
void ds_resize (dynamic_string *string, int size);
Packit 1ef1a9
char *ds_fgetname (FILE *f, dynamic_string *s);
Packit 1ef1a9
char *ds_fgets (FILE *f, dynamic_string *s);
Packit 1ef1a9
char *ds_fgetstr (FILE *f, dynamic_string *s, char eos);