Home | History | Annotate | Line # | Download | only in acpisrc
asutils.c revision 1.1.1.2.20.1
      1           1.1  jruoho /******************************************************************************
      2           1.1  jruoho  *
      3           1.1  jruoho  * Module Name: asutils - common utilities
      4           1.1  jruoho  *
      5           1.1  jruoho  *****************************************************************************/
      6           1.1  jruoho 
      7       1.1.1.2  jruoho /*
      8  1.1.1.2.20.1     tls  * Copyright (C) 2000 - 2013, Intel Corp.
      9           1.1  jruoho  * All rights reserved.
     10           1.1  jruoho  *
     11       1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     13       1.1.1.2  jruoho  * are met:
     14       1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.1.1.2  jruoho  *    without modification.
     17       1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.1.1.2  jruoho  *    binary redistribution.
     22       1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.1.1.2  jruoho  *    from this software without specific prior written permission.
     25       1.1.1.2  jruoho  *
     26       1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1.1.2  jruoho  * Software Foundation.
     29       1.1.1.2  jruoho  *
     30       1.1.1.2  jruoho  * NO WARRANTY
     31       1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1.1.2  jruoho  */
     43           1.1  jruoho 
     44           1.1  jruoho #include "acpisrc.h"
     45           1.1  jruoho 
     46           1.1  jruoho 
     47  1.1.1.2.20.1     tls /*******************************************************************************
     48  1.1.1.2.20.1     tls  *
     49  1.1.1.2.20.1     tls  * FUNCTION:    AsStrlwr (strlwr)
     50  1.1.1.2.20.1     tls  *
     51  1.1.1.2.20.1     tls  * PARAMETERS:  SrcString       - The source string to convert
     52  1.1.1.2.20.1     tls  *
     53  1.1.1.2.20.1     tls  * RETURN:      None
     54  1.1.1.2.20.1     tls  *
     55  1.1.1.2.20.1     tls  * DESCRIPTION: Convert string to lowercase
     56  1.1.1.2.20.1     tls  *
     57  1.1.1.2.20.1     tls  * NOTE: This is not a POSIX function, so it appears here so that we don't have
     58  1.1.1.2.20.1     tls  * header file issues with the various hosts/compilers/clibs.
     59  1.1.1.2.20.1     tls  *
     60  1.1.1.2.20.1     tls  ******************************************************************************/
     61  1.1.1.2.20.1     tls 
     62  1.1.1.2.20.1     tls void
     63  1.1.1.2.20.1     tls AsStrlwr (
     64  1.1.1.2.20.1     tls     char                    *SrcString)
     65  1.1.1.2.20.1     tls {
     66  1.1.1.2.20.1     tls     char                    *String;
     67  1.1.1.2.20.1     tls 
     68  1.1.1.2.20.1     tls 
     69  1.1.1.2.20.1     tls     /* Walk entire string, lowercasing the letters */
     70  1.1.1.2.20.1     tls 
     71  1.1.1.2.20.1     tls     if (SrcString)
     72  1.1.1.2.20.1     tls     {
     73  1.1.1.2.20.1     tls         for (String = SrcString; *String; String++)
     74  1.1.1.2.20.1     tls         {
     75  1.1.1.2.20.1     tls             *String = (char) ACPI_TOLOWER (*String);
     76  1.1.1.2.20.1     tls         }
     77  1.1.1.2.20.1     tls     }
     78  1.1.1.2.20.1     tls }
     79  1.1.1.2.20.1     tls 
     80  1.1.1.2.20.1     tls 
     81           1.1  jruoho /******************************************************************************
     82           1.1  jruoho  *
     83           1.1  jruoho  * FUNCTION:    AsSkipUntilChar
     84           1.1  jruoho  *
     85           1.1  jruoho  * DESCRIPTION: Find the next instance of the input character
     86           1.1  jruoho  *
     87           1.1  jruoho  ******************************************************************************/
     88           1.1  jruoho 
     89           1.1  jruoho char *
     90           1.1  jruoho AsSkipUntilChar (
     91           1.1  jruoho     char                    *Buffer,
     92           1.1  jruoho     char                    Target)
     93           1.1  jruoho {
     94           1.1  jruoho 
     95           1.1  jruoho     while (*Buffer != Target)
     96           1.1  jruoho     {
     97           1.1  jruoho         if (!*Buffer)
     98           1.1  jruoho         {
     99  1.1.1.2.20.1     tls             return (NULL);
    100           1.1  jruoho         }
    101           1.1  jruoho 
    102           1.1  jruoho         Buffer++;
    103           1.1  jruoho     }
    104           1.1  jruoho 
    105           1.1  jruoho     return (Buffer);
    106           1.1  jruoho }
    107           1.1  jruoho 
    108           1.1  jruoho 
    109           1.1  jruoho /******************************************************************************
    110           1.1  jruoho  *
    111           1.1  jruoho  * FUNCTION:    AsSkipPastChar
    112           1.1  jruoho  *
    113           1.1  jruoho  * DESCRIPTION: Find the next instance of the input character, return a buffer
    114           1.1  jruoho  *              pointer to this character+1.
    115           1.1  jruoho  *
    116           1.1  jruoho  ******************************************************************************/
    117           1.1  jruoho 
    118           1.1  jruoho char *
    119           1.1  jruoho AsSkipPastChar (
    120           1.1  jruoho     char                    *Buffer,
    121           1.1  jruoho     char                    Target)
    122           1.1  jruoho {
    123           1.1  jruoho 
    124           1.1  jruoho     while (*Buffer != Target)
    125           1.1  jruoho     {
    126           1.1  jruoho         if (!*Buffer)
    127           1.1  jruoho         {
    128  1.1.1.2.20.1     tls             return (NULL);
    129           1.1  jruoho         }
    130           1.1  jruoho 
    131           1.1  jruoho         Buffer++;
    132           1.1  jruoho     }
    133           1.1  jruoho 
    134           1.1  jruoho     Buffer++;
    135           1.1  jruoho 
    136           1.1  jruoho     return (Buffer);
    137           1.1  jruoho }
    138           1.1  jruoho 
    139           1.1  jruoho 
    140           1.1  jruoho /******************************************************************************
    141           1.1  jruoho  *
    142           1.1  jruoho  * FUNCTION:    AsReplaceData
    143           1.1  jruoho  *
    144           1.1  jruoho  * DESCRIPTION: This function inserts and removes data from the file buffer.
    145           1.1  jruoho  *              if more data is inserted than is removed, the data in the buffer
    146  1.1.1.2.20.1     tls  *              is moved to make room. If less data is inserted than is removed,
    147           1.1  jruoho  *              the remaining data is moved to close the hole.
    148           1.1  jruoho  *
    149           1.1  jruoho  ******************************************************************************/
    150           1.1  jruoho 
    151           1.1  jruoho char *
    152           1.1  jruoho AsReplaceData (
    153           1.1  jruoho     char                    *Buffer,
    154           1.1  jruoho     UINT32                  LengthToRemove,
    155           1.1  jruoho     char                    *BufferToAdd,
    156           1.1  jruoho     UINT32                  LengthToAdd)
    157           1.1  jruoho {
    158           1.1  jruoho     UINT32                  BufferLength;
    159           1.1  jruoho 
    160           1.1  jruoho 
    161           1.1  jruoho     /*
    162           1.1  jruoho      * Buffer is a string, so the length must include the terminating zero
    163           1.1  jruoho      */
    164           1.1  jruoho     BufferLength = strlen (Buffer) + 1;
    165           1.1  jruoho 
    166           1.1  jruoho     if (LengthToRemove != LengthToAdd)
    167           1.1  jruoho     {
    168           1.1  jruoho         /*
    169           1.1  jruoho          * Move some of the existing data
    170           1.1  jruoho          * 1) If adding more bytes than removing, make room for the new data
    171           1.1  jruoho          * 2) if removing more bytes than adding, delete the extra space
    172           1.1  jruoho          */
    173           1.1  jruoho         if (LengthToRemove > 0)
    174           1.1  jruoho         {
    175           1.1  jruoho             Gbl_MadeChanges = TRUE;
    176           1.1  jruoho             memmove ((Buffer + LengthToAdd), (Buffer + LengthToRemove), (BufferLength - LengthToRemove));
    177           1.1  jruoho         }
    178           1.1  jruoho     }
    179           1.1  jruoho 
    180           1.1  jruoho     /*
    181           1.1  jruoho      * Now we can move in the new data
    182           1.1  jruoho      */
    183           1.1  jruoho     if (LengthToAdd > 0)
    184           1.1  jruoho     {
    185           1.1  jruoho         Gbl_MadeChanges = TRUE;
    186           1.1  jruoho         memmove (Buffer, BufferToAdd, LengthToAdd);
    187           1.1  jruoho     }
    188           1.1  jruoho 
    189           1.1  jruoho     return (Buffer + LengthToAdd);
    190           1.1  jruoho }
    191           1.1  jruoho 
    192           1.1  jruoho 
    193           1.1  jruoho /******************************************************************************
    194           1.1  jruoho  *
    195           1.1  jruoho  * FUNCTION:    AsInsertData
    196           1.1  jruoho  *
    197           1.1  jruoho  * DESCRIPTION: This function inserts and removes data from the file buffer.
    198           1.1  jruoho  *              if more data is inserted than is removed, the data in the buffer
    199  1.1.1.2.20.1     tls  *              is moved to make room. If less data is inserted than is removed,
    200           1.1  jruoho  *              the remaining data is moved to close the hole.
    201           1.1  jruoho  *
    202           1.1  jruoho  ******************************************************************************/
    203           1.1  jruoho 
    204           1.1  jruoho char *
    205           1.1  jruoho AsInsertData (
    206           1.1  jruoho     char                    *Buffer,
    207           1.1  jruoho     char                    *BufferToAdd,
    208           1.1  jruoho     UINT32                  LengthToAdd)
    209           1.1  jruoho {
    210           1.1  jruoho     UINT32                  BufferLength;
    211           1.1  jruoho 
    212           1.1  jruoho 
    213           1.1  jruoho     if (LengthToAdd > 0)
    214           1.1  jruoho     {
    215           1.1  jruoho         /*
    216           1.1  jruoho          * Buffer is a string, so the length must include the terminating zero
    217           1.1  jruoho          */
    218           1.1  jruoho         BufferLength = strlen (Buffer) + 1;
    219           1.1  jruoho 
    220           1.1  jruoho         /*
    221           1.1  jruoho          * Move some of the existing data
    222           1.1  jruoho          * 1) If adding more bytes than removing, make room for the new data
    223           1.1  jruoho          * 2) if removing more bytes than adding, delete the extra space
    224           1.1  jruoho          */
    225           1.1  jruoho         Gbl_MadeChanges = TRUE;
    226           1.1  jruoho         memmove ((Buffer + LengthToAdd), Buffer, BufferLength);
    227           1.1  jruoho 
    228           1.1  jruoho         /*
    229           1.1  jruoho          * Now we can move in the new data
    230           1.1  jruoho          */
    231           1.1  jruoho         memmove (Buffer, BufferToAdd, LengthToAdd);
    232           1.1  jruoho     }
    233           1.1  jruoho 
    234           1.1  jruoho     return (Buffer + LengthToAdd);
    235           1.1  jruoho }
    236           1.1  jruoho 
    237           1.1  jruoho 
    238           1.1  jruoho /******************************************************************************
    239           1.1  jruoho  *
    240           1.1  jruoho  * FUNCTION:    AsRemoveData
    241           1.1  jruoho  *
    242           1.1  jruoho  * DESCRIPTION: This function inserts and removes data from the file buffer.
    243           1.1  jruoho  *              if more data is inserted than is removed, the data in the buffer
    244  1.1.1.2.20.1     tls  *              is moved to make room. If less data is inserted than is removed,
    245           1.1  jruoho  *              the remaining data is moved to close the hole.
    246           1.1  jruoho  *
    247           1.1  jruoho  ******************************************************************************/
    248           1.1  jruoho 
    249           1.1  jruoho char *
    250           1.1  jruoho AsRemoveData (
    251           1.1  jruoho     char                    *StartPointer,
    252           1.1  jruoho     char                    *EndPointer)
    253           1.1  jruoho {
    254           1.1  jruoho     UINT32                  BufferLength;
    255           1.1  jruoho 
    256           1.1  jruoho 
    257           1.1  jruoho     /*
    258           1.1  jruoho      * Buffer is a string, so the length must include the terminating zero
    259           1.1  jruoho      */
    260           1.1  jruoho     BufferLength = strlen (EndPointer) + 1;
    261           1.1  jruoho 
    262           1.1  jruoho     Gbl_MadeChanges = TRUE;
    263           1.1  jruoho     memmove (StartPointer, EndPointer, BufferLength);
    264           1.1  jruoho 
    265           1.1  jruoho     return (StartPointer);
    266           1.1  jruoho }
    267