xref: /freebsd/contrib/sendmail/libsm/string.c (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
1 /*
2  * Copyright (c) 2001 Proofpoint, Inc. and its suppliers.
3  *      All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  *
9  */
10 
11 #include <sm/gen.h>
12 SM_RCSID("@(#)$Id: string.c,v 1.4 2013-11-22 20:51:43 ca Exp $")
13 
14 #include <ctype.h>
15 #include <errno.h>
16 
17 #include <sm/string.h>
18 
19 /*
20 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
21 **
22 **	Runs through a string and strips off unquoted quote
23 **	characters and quote bits.  This is done in place.
24 **
25 **	Parameters:
26 **		s -- the string to strip.
27 **
28 **	Returns:
29 **		none.
30 */
31 
32 void
33 stripquotes(s)
34 	char *s;
35 {
36 	register char *p;
37 	register char *q;
38 	register char c;
39 
40 	if (s == NULL)
41 		return;
42 
43 	p = q = s;
44 	do
45 	{
46 		c = *p++;
47 		if (c == '\\')
48 			c = *p++;
49 		else if (c == '"')
50 			continue;
51 		*q++ = c;
52 	} while (c != '\0');
53 }
54 
55 /*
56 **  UNFOLDSTRIPQUOTES -- Strip quotes & quote bits from a string.
57 **
58 **	Parameters:
59 **		s -- the string to strip.
60 **
61 **	Returns:
62 **		none.
63 */
64 
65 void
66 unfoldstripquotes(s)
67 	char *s;
68 {
69 	char *p, *q, c;
70 
71 	if (s == NULL)
72 		return;
73 
74 	p = q = s;
75 	do
76 	{
77 		c = *p++;
78 		if (c == '\\' || c == '\n')
79 			c = *p++;
80 		else if (c == '"')
81 			continue;
82 		*q++ = c;
83 	} while (c != '\0');
84 }
85