home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cpio11as.zip / DSTRING.H < prev    next >
C/C++ Source or Header  |  1992-02-22  |  3KB  |  72 lines

  1. /* dstring.h - Dynamic string handling include file.  Requires strings.h.
  2.    Copyright (C) 1988, 1989, 1990 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 1, 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 License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  19.    This port is also distributed under the terms of the
  20.    GNU General Public License as published by the
  21.    Free Software Foundation.
  22.  
  23.    Please note that this file is not identical to the
  24.    original GNU release, you should have received this
  25.    code as patch to the official release.
  26.  
  27.    $Header: e:/gnu/cpio/RCS/dstring.h 1.1.0.2 90/09/23 23:11:17 tho Exp $
  28.  */
  29.  
  30. #ifdef MSDOS
  31. #ifndef FILE
  32. #include <stdio.h>
  33. #endif
  34. #endif
  35.  
  36. #ifndef NULL
  37. #define NULL 0
  38. #endif
  39.  
  40. /* A dynamic string consists of record that records the size of an
  41.    allocated string and the pointer to that string.  The actual string
  42.    is a normal zero byte terminated string that can be used with the
  43.    usual string functions.  The major difference is that the
  44.    dynamic_string routines know how to get more space if it is needed
  45.    by allocating new space and copying the current string.  */
  46.  
  47. typedef struct
  48. {
  49.   int ds_length;        /* Actual amount of storage allocated. */
  50.   char *ds_string;        /* String. */
  51. } dynamic_string;
  52.  
  53.  
  54. /* Macros that look similar to the original string functions.
  55.    WARNING:  These macros work only on pointers to dynamic string records.
  56.    If used with a real record, an "&" must be used to get the pointer. */
  57. #define ds_strlen(s)        strlen ((s)->ds_string)
  58. #define ds_strcmp(s1, s2)    strcmp ((s1)->ds_string, (s2)->ds_string)
  59. #define ds_strncmp(s1, s2, n)    strncmp ((s1)->ds_string, (s2)->ds_string, n)
  60. #define ds_index(s, c)        index ((s)->ds_string, c)
  61. #define ds_rindex(s, c)        rindex ((s)->ds_string, c)
  62.  
  63. #ifdef MSDOS
  64. extern void ds_init (dynamic_string *string, int size);
  65. extern void ds_resize (dynamic_string *string, int size);
  66. extern char *ds_fgets (FILE *f, dynamic_string *s);
  67. #else /* not MSDOS */
  68. void ds_init ();
  69. void ds_resize ();
  70. char *ds_fgets ();
  71. #endif /* not MSDOS */
  72.