xref: /freebsd/contrib/sendmail/libsm/string.c (revision b51f459a2098622c31ed54f5c1bf0e03efce403b)
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 **	Side Effects:
32 **		none.
33 */
34 
35 void
36 stripquotes(s)
37 	char *s;
38 {
39 	register char *p;
40 	register char *q;
41 	register char c;
42 
43 	if (s == NULL)
44 		return;
45 
46 	p = q = s;
47 	do
48 	{
49 		c = *p++;
50 		if (c == '\\')
51 			c = *p++;
52 		else if (c == '"')
53 			continue;
54 		*q++ = c;
55 	} while (c != '\0');
56 }
57 
58 /*
59 **  UNFOLDSTRIPQUOTES -- Strip quotes & quote bits from a string.
60 **
61 **	Parameters:
62 **		s -- the string to strip.
63 **
64 **	Returns:
65 **		none.
66 */
67 
68 void
69 unfoldstripquotes(s)
70 	char *s;
71 {
72 	char *p, *q, c;
73 
74 	if (s == NULL)
75 		return;
76 
77 	p = q = s;
78 	do
79 	{
80 		c = *p++;
81 		if (c == '\\' || c == '\n')
82 			c = *p++;
83 		else if (c == '"')
84 			continue;
85 		*q++ = c;
86 	} while (c != '\0');
87 }
88