1
/* Copyright (c) 2003, 2007 Reiner Patommel
2
Copyright (c) 2007 Dmitry Xmelkov
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in
12
the documentation and/or other materials provided with the
14
* Neither the name of the copyright holders nor the names of
15
contributors may be used to endorse or promote products derived
16
from this software without specific prior written permission.
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
POSSIBILITY OF SUCH DAMAGE.
32
/* $Id: strsep_P.S,v 1.1.2.1 2007/03/31 23:14:26 dmix Exp $ */
36
/** \ingroup avr_pgmspace
37
\fn char *strsep_P(char **sp, PGM_P delim)
38
\brief Parse a string into tokens.
40
The strsep_P() function locates, in the string referenced by \p *sp,
41
the first occurrence of any character in the string \p delim (or the
42
terminating '\\0' character) and replaces it with a '\\0'. The
43
location of the next character after the delimiter character (or \c
44
NULL, if the end of the string was reached) is stored in \p *sp. An
45
``empty'' field, i.e. one caused by two adjacent delimiter
46
characters, can be detected by comparing the location referenced by
47
the pointer returned in \p *sp to '\\0'. This function is similar to
48
strsep() except that \p delim is a pointer to a string in program
51
\return The strsep_P() function returns a pointer to the original
52
value of \p *sp. If \p *sp is initially \c NULL, strsep_P() returns
55
#if !defined(__DOXYGEN__)
68
.type _U(strsep_P),@function
70
; check a NULL pointer
72
ld XL, Z ; str address
74
X_movw str_lo, XL ; save for return
77
; get a symbol from str
84
brne 2b ; if symbol is't match && no delim end
85
brne 1b ; if symbol is absent in delim[] && not a zero
86
; chr is founded in delim[] (possible, it is a terminating zero of str)
87
tst r0 ; the same, as chr
89
X_movw XL, r0 ; __zero_reg__ is r1
91
; OK, delimeter symbol is founded
92
3: st -X, __zero_reg__ ; replace by '\0'
93
adiw XL, 1 ; address of next token
94
; save result to *sp and return
98
5: X_movw ret_lo, str_lo ; return original address
101
.size _U(strsep_P), . - _U(strsep_P)
102
#endif /* not __DOXYGEN__ */