1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 /* Headers and miscellaneous. */
33 #define strrchr rindex
36 char *strchr (), *strrchr ();
40 char *strtok_r (char *, const char *, char **);
44 char *stpcpy (char *dest, const char *src);
48 int strcasecmp (const char *s1, const char *s2);
52 int strncasecmp (const char *s1, const char *s2, size_t n);
56 void *memmem (const void *haystack, size_t haystack_len,
57 const void *needle, size_t needle_len);
60 /* sprintf() wrapper functions for convenience. */
62 /* spprintf() calls sprintf() and returns the address of the null
63 terminator in the resulting string. It should be portable the way
64 it's been implemented. */
67 #define spprintf(BUF, FORMAT, ARGS...) \
68 ((BUF) + sprintf ((BUF), (FORMAT) , ## ARGS))
70 #define spprintf(BUF, FORMAT, ARGS...) \
71 ({ sprintf ((BUF), (FORMAT) , ## ARGS); \
74 #else /* Not GNU C. */
75 char *spprintf (char *buf, const char *format, ...);
76 #endif /* Not GNU C. */
78 /* nsprintf() calls sprintf() and returns the strlen() of the
79 resulting string. It should be portable the way it's been
83 #define nsprintf(BUF, FORMAT, ARGS...) \
84 (sprintf ((BUF), (FORMAT) , ## ARGS))
85 #define nvsprintf(BUF, FORMAT, ARGS) \
86 (vsprintf ((BUF), (FORMAT), (ARGS)))
87 #else /* Not good sprintf(). */
88 #define nsprintf(BUF, FORMAT, ARGS...) \
91 sprintf ((pbuf), (FORMAT) , ## ARGS); \
94 #define nvsprintf(BUF, FORMAT, ARGS) \
97 vsprintf ((pbuf), (FORMAT), (ARGS)); \
100 #endif /* Not good sprintf(). */
101 #else /* Not GNU C. */
102 #if HAVE_GOOD_SPRINTF
103 #define nsprintf sprintf
104 #define nvsprintf vsprintf
105 #else /* Not good sprintf(). */
106 int nsprintf (char *buf, const char *format, ...);
107 int nvsprintf (char *buf, const char *format, va_list args);
108 #endif /* Not good sprintf(). */
109 #endif /* Not GNU C. */
112 long getline (char **lineptr, size_t *n, FILE *stream);
116 long getdelim (char **lineptr, size_t * n, int delimiter, FILE * stream);
121 void mm_reverse (void *, size_t);
122 char *mm_find_reverse (const char *, size_t, const char *, size_t);
123 int mm_case_compare (const void *, const void *, size_t);
125 int st_compare_pad (const char *, size_t, const char *, size_t);
126 char *st_spaces (int);
127 void st_bare_pad_copy (char *dest, const char *src, size_t n);
128 void st_bare_pad_len_copy (char *dest, const char *src, size_t n, size_t len);
129 void st_pad_copy (char *dest, const char *src, size_t n);
130 void st_trim_copy (char *dest, const char *src, size_t n);
131 void st_uppercase (char *);
133 /* Fixed-length strings. */
140 void ls_create (struct fixed_string *, const char *);
141 void ls_create_buffer (struct fixed_string *,
142 const char *, size_t len);
143 void ls_init (struct fixed_string *, const char *, size_t);
144 void ls_shallow_copy (struct fixed_string *, const struct fixed_string *);
145 void ls_destroy (struct fixed_string *);
147 void ls_null (struct fixed_string *);
148 int ls_null_p (const struct fixed_string *);
149 int ls_empty_p (const struct fixed_string *);
151 size_t ls_length (const struct fixed_string *);
152 char *ls_c_str (const struct fixed_string *);
153 char *ls_end (const struct fixed_string *);
157 ls_length (const struct fixed_string *st)
163 ls_c_str (const struct fixed_string *st)
169 ls_end (const struct fixed_string *st)
171 return st->string + st->length;
175 /* Variable length strings. */
179 size_t length; /* Length, not including a null terminator. */
180 size_t capacity; /* Allocated capacity, not including one
181 extra byte allocated for null terminator. */
182 char *string; /* String data, not necessarily null
186 /* Constructors, destructors. */
187 void ds_create (struct string *, const char *);
188 void ds_init (struct string *, size_t);
189 void ds_destroy (struct string *);
191 /* Copy, shrink, extend. */
192 void ds_replace (struct string *, const char *);
193 void ds_clear (struct string *);
194 void ds_extend (struct string *, size_t);
195 void ds_shrink (struct string *);
196 void ds_truncate (struct string *, size_t);
197 void ds_rpad (struct string *, size_t length, char pad);
200 size_t ds_length (const struct string *);
201 char *ds_c_str (const struct string *);
202 char *ds_data (const struct string *);
203 char *ds_end (const struct string *);
204 size_t ds_capacity (const struct string *);
208 int ds_gets (struct string *, FILE *);
209 int ds_get_config_line (FILE *, struct string *, struct file_locator *);
212 void ds_putc (struct string *, int ch);
213 void ds_puts (struct string *, const char *);
214 void ds_concat (struct string *, const char *, size_t);
215 void ds_vprintf (struct string *st, const char *, va_list);
216 void ds_printf (struct string *, const char *, ...)
217 PRINTF_FORMAT (2, 3);
221 ds_putc (struct string *st, int ch)
223 if (st->length == st->capacity)
224 ds_extend (st, st->length + 1);
225 st->string[st->length++] = ch;
229 ds_length (const struct string *st)
235 ds_c_str (const struct string *st)
237 ((char *) st->string)[st->length] = '\0';
242 ds_data (const struct string *st)
248 ds_end (const struct string *st)
250 return st->string + st->length;