1 
2 static char rcsid[] = "@(#)$Id: qstrings.c,v 1.2 1995/09/29 17:41:30 wfp5p Exp $";
3 
4 /*******************************************************************************
5  *  The Elm Mail System  -  $Revision: 1.2 $   $State: Exp $
6  *
7  *                      Copyright (c) 1988-1995 USENET Community Trust
8  * 			Copyright (c) 1986,1987 Dave Taylor
9  *******************************************************************************
10  * Bug reports, patches, comments, suggestions should be sent to:
11  *
12  *      Bill Pemberton, Elm Coordinator
13  *      flash@virginia.edu
14  *
15  *******************************************************************************
16  * $Log: qstrings.c,v $
17  * Revision 1.2  1995/09/29  17:41:30  wfp5p
18  * Alpha 8 (Chip's big changes)
19  *
20  * Revision 1.1.1.1  1995/04/19  20:38:33  wfp5p
21  * Initial import of elm 2.4 PL0 as base for elm 2.5.
22  *
23  ******************************************************************************/
24 
25 /** This file contains equivalent routines to the string routines, but
26      modifed to handle quoted strings.
27 
28 **/
29 
30 #include "elm_defs.h"
31 
qstrpbrk(source,keys)32 char *qstrpbrk(source, keys)
33 const char *source, *keys;
34 {
35 	/** Returns a pointer to the first character of source that is any
36 	    of the specified keys, or NULL if none of the keys are present
37 	    in the source string.
38 	**/
39 
40 	register const char *s, *k;
41 	register int len;
42 
43 	s = source;
44 	while (*s != '\0') {
45 	  len = len_next_part(s);
46 	  if (len == 1) {
47 	    for (k = keys; *k; k++)
48 	      if (*k == *s)
49 		return (char *)s;
50 	  }
51 	  s += len;
52 	}
53 
54 	return(NULL);
55 }
56 
57 int
qstrspn(source,keys)58 qstrspn(source, keys)
59 const char *source, *keys;
60 {
61 	/** This function returns the length of the substring of
62 	    'source' (starting at zero) that consists ENTIRELY of
63 	    characters from 'keys'.  This is used to skip over a
64 	    defined set of characters with parsing, usually.
65 	**/
66 
67 	register int loc = 0, key_index = 0, len;
68 
69 	while (source[loc] != '\0') {
70 	  key_index = 0;
71 	  len = len_next_part(&source[loc]);
72 	  if (len > 1)
73 	    return(loc);
74 
75 	  while (keys[key_index] != source[loc])
76 	    if (keys[key_index++] == '\0')
77 	      return(loc);
78 	  loc++;
79 	}
80 
81 	return(loc);
82 }
83 
84 int
qstrcspn(source,keys)85 qstrcspn(source, keys)
86 const char *source, *keys;
87 {
88 	/** This function returns the length of the substring of
89 	    'source' (starting at zero) that consists entirely of
90 	    characters NOT from 'keys'.  This is used to skip to a
91 	    defined set of characters with parsing, usually.
92 	    NOTE that this is the opposite of strspn() above
93 	**/
94 
95 	register int loc = 0, key_index = 0, len;
96 
97 	while (source[loc] != '\0') {
98 	  key_index = 0;
99 	  len = len_next_part(&source[loc]);
100 	  if (len > 1) {
101 	    loc += len;
102 	    continue;
103 	  }
104 
105 	  while (keys[key_index] != '\0')
106 	    if (keys[key_index++] == source[loc])
107 	      return(loc);
108 	  loc++;
109 	}
110 
111 	return(loc);
112 }
113