Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / tools / acpisrc / asutils.c
bloba3585969654604f3275f94395dbb0efbae059023
1 /******************************************************************************
3 * Module Name: asutils - common utilities
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
44 #include "acpisrc.h"
47 /*******************************************************************************
49 * FUNCTION: AsStrlwr (strlwr)
51 * PARAMETERS: SrcString - The source string to convert
53 * RETURN: None
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 ******************************************************************************/
62 void
63 AsStrlwr (
64 char *SrcString)
66 char *String;
69 /* Walk entire string, lowercasing the letters */
71 if (SrcString)
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 ******************************************************************************/
89 char *
90 AsSkipUntilChar (
91 char *Buffer,
92 char Target)
95 while (*Buffer != Target)
97 if (!*Buffer)
99 return (NULL);
102 Buffer++;
105 return (Buffer);
109 /******************************************************************************
111 * FUNCTION: AsSkipPastChar
113 * DESCRIPTION: Find the next instance of the input character, return a buffer
114 * pointer to this character+1.
116 ******************************************************************************/
118 char *
119 AsSkipPastChar (
120 char *Buffer,
121 char Target)
124 while (*Buffer != Target)
126 if (!*Buffer)
128 return (NULL);
131 Buffer++;
134 Buffer++;
136 return (Buffer);
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 ******************************************************************************/
151 char *
152 AsReplaceData (
153 char *Buffer,
154 UINT32 LengthToRemove,
155 char *BufferToAdd,
156 UINT32 LengthToAdd)
158 UINT32 BufferLength;
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
183 if (LengthToAdd > 0)
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 ******************************************************************************/
204 char *
205 AsInsertData (
206 char *Buffer,
207 char *BufferToAdd,
208 UINT32 LengthToAdd)
210 UINT32 BufferLength;
213 if (LengthToAdd > 0)
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 ******************************************************************************/
249 char *
250 AsRemoveData (
251 char *StartPointer,
252 char *EndPointer)
254 UINT32 BufferLength;
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);