1 /*
2 File: unquote.c
3
4 Copyright (C) 2003 Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "config.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <ctype.h>
25 #include "misc.h"
26
27 char *unquote(char *str)
28 {
29 unsigned char *s, *t;
30
31 if (!str)
32 return str;
33
34 for (s = (unsigned char *)str; *s != '\0'; s++)
35 if (*s == '\\')
36 break;
37 if (*s == '\0')
38 return str;
39
40 #define isoctal(c) \
41 ((c) >= '0' && (c) <= '7')
42
43 t = s;
44 do {
45 if (*s == '\\' &&
46 isoctal(*(s+1)) && isoctal(*(s+2)) && isoctal(*(s+3))) {
47 *t++ = ((*(s+1) - '0') << 6) +
48 ((*(s+2) - '0') << 3) +
49 ((*(s+3) - '0') );
50 s += 3;
51 } else
52 *t++ = *s;
53 } while (*s++ != '\0');
54
55 return str;
56 }