add a config file git-buildpackage
[debian/dds2tar] / dds_quote.c
1 #include <stdio.h>
2 #include "dds2tar.h"
3 int dds_unquote(char*p){
4         char *q ;
5
6         /* do nothing if there is no quote */
7         while ( *p && *p != '\\' ) p++ ;
8         if ( *p == '\0' ) return 1 ;
9
10         q = p ;
11         while ( *p ){
12                 if ( *p == '\\' ) {
13                         char c = p[1] ;
14                         switch (c){
15                                 case '\\' : *q++ = '\\'   , p+=2 ; continue ;
16                                 case 't'  : *q++ = '\t'   , p+=2 ; continue ;
17                                 case 'n'  : *q++ = '\n'   , p+=2 ; continue ;
18                                 case 'f'  : *q++ = '\f'   , p+=2 ; continue ;
19                                 case 'b'  : *q++ = '\b'   , p+=2 ; continue ;
20                                 case 'r'  : *q++ = '\r'   , p+=2 ; continue ;
21                                 case '?'  : *q++ = '\177' , p+=2 ; continue ;
22                         }
23                         if ( '0' <= c && c <= '9' ){
24                                 int x = 0 ;
25                                 int n = 0 ;
26                                 sscanf(p+1,"%03o%n",&x,&n);
27                                 *q++ = x ; p+=n+1 ; continue ;
28                         }
29                         /*
30                          * Here we should never be, but if, we just proceed.
31                          */
32                 }
33                 *q++ = *p++ ;
34         }
35         *q++ = '\0' ;
36         return 1 ;
37 }
38
39 #ifdef TEST_IT
40 int main(int argc,char*argv[]){
41         if ( argc < 2 ) return 0 ;
42         dds_unquote(argv[1]);
43         puts(argv[1]);
44         return 0 ;
45 }
46 #endif
47