1
/* Copyright (c) 2006, Carlos Lamas
3
based on libc/pmstring/strstr_P.S which is
4
Copyright (c) 2005, Werner Boellmann
5
Copyright (c) 2002, Philip Soeberg
9
Redistribution and use in source and binary forms, with or without
10
modification, are permitted provided that the following conditions are met:
12
* Redistributions of source code must retain the above copyright
13
notice, this list of conditions and the following disclaimer.
14
* Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
18
* Neither the name of the copyright holders nor the names of
19
contributors may be used to endorse or promote products derived
20
from this software without specific prior written permission.
22
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
POSSIBILITY OF SUCH DAMAGE. */
34
/* $Id: strstr_PF.S 2191 2010-11-05 13:45:57Z arcanum $ */
38
/** \ingroup avr_pgmspace
39
\fn char *strstr_PF (const char *s1, uint_farptr_t s2)
40
\brief Locate a substring.
42
The strstr_PF() function finds the first occurrence of the substring \c s2
43
in the string \c s1. The terminating '\\0' characters are not
45
The strstr_PF() function is similar to strstr() except that \c s2 is a
46
far pointer to a string in program space.
48
\returns The strstr_PF() function returns a pointer to the beginning of the
49
substring, or NULL if the substring is not found.
50
If \c s2 points to a string of zero length, the function returns \c s1. The
51
contents of RAMPZ SFR are undefined when the function returns */
53
#if !defined(__AVR_TINY__)
55
#if !defined(__DOXYGEN__)
64
; first char of str1 (updated in loop)
65
#define chr1 s2_b3 /* MSB not used */
72
.type _U(strstr_PF), @function
77
LPM_R0_ZPLUS_INIT s2_b2
79
LPM_R0_ZPLUS_NEXT s2_b2
80
tst r0 ; is str2 empty?
82
ret ; return original string (req'd by standard)
86
X_movw ZL, s2_b0 ; reset Z pointer
87
LPM_R0_ZPLUS_INIT s2_b2
88
LPM_R0_ZPLUS_NEXT s2_b2 ; fetch first char
90
.L_findstart_loop_P: ; Find first char
93
tst chr1 ; Is str1 @ end?
94
breq .L_no_match_P ; then return
95
cp chr1, r0 ; Is chr1 == r0?
96
X_movw ret_b0, XL ; store return value
97
brne .L_findstart_loop_P ; If, then start checking string
101
LPM_R0_ZPLUS_NEXT s2_b2
109
adiw XL, 1 ; Increment X with one
124
.size _U(strstr_PF), .L_strstr_end_P - _U(strstr_PF)
126
#endif /* not __DOXYGEN__ */
128
#endif /* !defined(__AVR_TINY__) */