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
29 #include "memcasecmp.h"
37 #include "vsnprintf.h"
38 #include "xvasprintf.h"
44 #define strrchr rindex
49 void buf_reverse (char *, size_t);
50 char *buf_find_reverse (const char *, size_t, const char *, size_t);
51 int buf_compare_case (const char *, const char *, size_t);
52 int buf_compare_rpad (const char *, size_t, const char *, size_t);
53 void buf_copy_rpad (char *, size_t, const char *, size_t);
54 void buf_copy_str_lpad (char *, size_t, const char *);
55 void buf_copy_str_rpad (char *, size_t, const char *);
57 int str_compare_rpad (const char *, const char *);
58 void str_copy_rpad (char *, size_t, const char *);
59 void str_copy_trunc (char *, size_t, const char *);
60 void str_copy_buf_trunc (char *, size_t, const char *, size_t);
61 void str_uppercase (char *);
62 void str_lowercase (char *);
64 /* Fixed-length strings. */
71 void ls_create (struct fixed_string *, const char *);
72 void ls_create_buffer (struct fixed_string *,
73 const char *, size_t len);
74 void ls_init (struct fixed_string *, const char *, size_t);
75 void ls_shallow_copy (struct fixed_string *, const struct fixed_string *);
76 void ls_destroy (struct fixed_string *);
78 void ls_null (struct fixed_string *);
79 int ls_null_p (const struct fixed_string *);
80 int ls_empty_p (const struct fixed_string *);
82 size_t ls_length (const struct fixed_string *);
83 char *ls_c_str (const struct fixed_string *);
84 char *ls_end (const struct fixed_string *);
88 ls_length (const struct fixed_string *st)
94 ls_c_str (const struct fixed_string *st)
100 ls_end (const struct fixed_string *st)
102 return st->string + st->length;
106 /* Variable length strings. */
110 size_t length; /* Length, not including a null terminator. */
111 size_t capacity; /* Allocated capacity, not including one
112 extra byte allocated for null terminator. */
113 char *string; /* String data, not necessarily null
117 /* Constructors, destructors. */
118 void ds_create (struct string *, const char *);
119 void ds_init (struct string *, size_t);
120 void ds_destroy (struct string *);
121 void ds_swap (struct string *, struct string *);
123 /* Copy, shrink, extend. */
124 void ds_replace (struct string *, const char *);
125 void ds_clear (struct string *);
126 void ds_extend (struct string *, size_t);
127 void ds_shrink (struct string *);
128 void ds_truncate (struct string *, size_t);
129 void ds_rpad (struct string *, size_t length, char pad);
130 int ds_rtrim_spaces (struct string *);
131 bool ds_chomp (struct string *, char);
134 bool ds_is_empty (const struct string *);
135 size_t ds_length (const struct string *);
136 char *ds_c_str (const struct string *);
137 char *ds_data (const struct string *);
138 char *ds_end (const struct string *);
139 size_t ds_capacity (const struct string *);
140 int ds_first (const struct string *);
141 int ds_last (const struct string *);
145 int ds_gets (struct string *, FILE *);
146 int ds_get_config_line (FILE *, struct string *, struct file_locator *);
149 void ds_putc (struct string *, int ch);
150 void ds_puts (struct string *, const char *);
151 void ds_concat (struct string *, const char *, size_t);
152 void ds_vprintf (struct string *st, const char *, va_list);
153 void ds_printf (struct string *, const char *, ...)
154 PRINTF_FORMAT (2, 3);
158 ds_putc (struct string *st, int ch)
160 if (st->length == st->capacity)
161 ds_extend (st, st->length + 1);
162 st->string[st->length++] = ch;
166 ds_length (const struct string *st)
172 ds_c_str (const struct string *st)
174 ((char *) st->string)[st->length] = '\0';
179 ds_data (const struct string *st)
185 ds_end (const struct string *st)
187 return st->string + st->length;
191 #define nsprintf sprintf
192 #define nvsprintf vsprintf
194 /* Formats FORMAT into DST, as with sprintf(), and returns the
195 address of the terminating null written to DST. */
197 spprintf (char *dst, const char *format, ...)
202 va_start (args, format);
203 count = nvsprintf (dst, format, args);