File: dds_quote.c

package info (click to toggle)
dds2tar 2.5.2-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 528 kB
  • sloc: ansic: 2,889; makefile: 593; sh: 213; csh: 50
file content (47 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include "dds2tar.h"
int dds_unquote(char*p){
	char *q ;

	/* do nothing if there is no quote */
	while ( *p && *p != '\\' ) p++ ;
	if ( *p == '\0' ) return 1 ;

	q = p ;
	while ( *p ){
		if ( *p == '\\' ) {
			char c = p[1] ;
			switch (c){
				case '\\' : *q++ = '\\'   , p+=2 ; continue ;
				case 't'  : *q++ = '\t'   , p+=2 ; continue ;
				case 'n'  : *q++ = '\n'   , p+=2 ; continue ;
				case 'f'  : *q++ = '\f'   , p+=2 ; continue ;
				case 'b'  : *q++ = '\b'   , p+=2 ; continue ;
				case 'r'  : *q++ = '\r'   , p+=2 ; continue ;
				case '?'  : *q++ = '\177' , p+=2 ; continue ;
			}
			if ( '0' <= c && c <= '9' ){
				int x = 0 ;
				int n = 0 ;
				sscanf(p+1,"%03o%n",&x,&n);
				*q++ = x ; p+=n+1 ; continue ;
			}
			/*
			 * Here we should never be, but if, we just proceed.
			 */
		}
		*q++ = *p++ ;
	}
	*q++ = '\0' ;
	return 1 ;
}

#ifdef TEST_IT
int main(int argc,char*argv[]){
	if ( argc < 2 ) return 0 ;
	dds_unquote(argv[1]);
	puts(argv[1]);
	return 0 ;
}
#endif