1 /******************************************************************************
3 * Module Name: asutils - common utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
47 /*******************************************************************************
49 * FUNCTION: AsStrlwr (strlwr)
51 * PARAMETERS: SrcString - The source string to convert
55 * DESCRIPTION: Convert string to lowercase
57 * NOTE: This is not a POSIX function, so it appears here so that we don't have
58 * header file issues with the various hosts/compilers/clibs.
60 ******************************************************************************/
69 /* Walk entire string, lowercasing the letters */
73 for (String
= SrcString
; *String
; String
++)
75 *String
= (char) ACPI_TOLOWER (*String
);
81 /******************************************************************************
83 * FUNCTION: AsSkipUntilChar
85 * DESCRIPTION: Find the next instance of the input character
87 ******************************************************************************/
95 while (*Buffer
!= Target
)
109 /******************************************************************************
111 * FUNCTION: AsSkipPastChar
113 * DESCRIPTION: Find the next instance of the input character, return a buffer
114 * pointer to this character+1.
116 ******************************************************************************/
124 while (*Buffer
!= Target
)
140 /******************************************************************************
142 * FUNCTION: AsReplaceData
144 * DESCRIPTION: This function inserts and removes data from the file buffer.
145 * if more data is inserted than is removed, the data in the buffer
146 * is moved to make room. If less data is inserted than is removed,
147 * the remaining data is moved to close the hole.
149 ******************************************************************************/
154 UINT32 LengthToRemove
,
162 * Buffer is a string, so the length must include the terminating zero
164 BufferLength
= strlen (Buffer
) + 1;
166 if (LengthToRemove
!= LengthToAdd
)
169 * Move some of the existing data
170 * 1) If adding more bytes than removing, make room for the new data
171 * 2) if removing more bytes than adding, delete the extra space
173 if (LengthToRemove
> 0)
175 Gbl_MadeChanges
= TRUE
;
176 memmove ((Buffer
+ LengthToAdd
), (Buffer
+ LengthToRemove
), (BufferLength
- LengthToRemove
));
181 * Now we can move in the new data
185 Gbl_MadeChanges
= TRUE
;
186 memmove (Buffer
, BufferToAdd
, LengthToAdd
);
189 return (Buffer
+ LengthToAdd
);
193 /******************************************************************************
195 * FUNCTION: AsInsertData
197 * DESCRIPTION: This function inserts and removes data from the file buffer.
198 * if more data is inserted than is removed, the data in the buffer
199 * is moved to make room. If less data is inserted than is removed,
200 * the remaining data is moved to close the hole.
202 ******************************************************************************/
216 * Buffer is a string, so the length must include the terminating zero
218 BufferLength
= strlen (Buffer
) + 1;
221 * Move some of the existing data
222 * 1) If adding more bytes than removing, make room for the new data
223 * 2) if removing more bytes than adding, delete the extra space
225 Gbl_MadeChanges
= TRUE
;
226 memmove ((Buffer
+ LengthToAdd
), Buffer
, BufferLength
);
229 * Now we can move in the new data
231 memmove (Buffer
, BufferToAdd
, LengthToAdd
);
234 return (Buffer
+ LengthToAdd
);
238 /******************************************************************************
240 * FUNCTION: AsRemoveData
242 * DESCRIPTION: This function inserts and removes data from the file buffer.
243 * if more data is inserted than is removed, the data in the buffer
244 * is moved to make room. If less data is inserted than is removed,
245 * the remaining data is moved to close the hole.
247 ******************************************************************************/
258 * Buffer is a string, so the length must include the terminating zero
260 BufferLength
= strlen (EndPointer
) + 1;
262 Gbl_MadeChanges
= TRUE
;
263 memmove (StartPointer
, EndPointer
, BufferLength
);
265 return (StartPointer
);