4 Copyright (C) 2003 Andreas Gruenbacher <a.gruenbacher@bestbits.at>
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2.1 of the License, or (at
9 your option) any later version.
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program. If not, see <http://www.gnu.org/licenses/>.
26 const char *quote(const char *str, const char *quote_chars)
28 static char *quoted_str;
29 static size_t quoted_str_len;
30 const unsigned char *s;
37 for (nonpr = 0, s = (unsigned char *)str; *s != '\0'; s++)
38 if (*s == '\\' || strchr(quote_chars, *s))
43 if (high_water_alloc((void **)"ed_str, "ed_str_len,
44 (s - (unsigned char *)str) + nonpr * 3 + 1))
46 for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) {
47 if (*s == '\\' || strchr(quote_chars, *s)) {
49 *q++ = '0' + ((*s >> 6) );
50 *q++ = '0' + ((*s >> 3) & 7);
51 *q++ = '0' + ((*s ) & 7);