⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 str.c

📁 source code of armboot for s3c4510
💻 C
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:    str.c
 *
 * Purpose: String operations (used to replace "string.h")
 *
 * Author:  Jenda Jao
 *
 * Date:    Jan 08, 2002
 *
 * Functions:
 *
 * Revision History:
 *
 */

#include "str.h"





/*---------------------  Static Definitions  ------------------------*/

/*---------------------  Static Types  ------------------------------*/

/*---------------------  Static Macros  -----------------------------*/

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/

/*---------------------  Export Variables  --------------------------*/



#if 0
int STR_iStrcmp (char *dst, char *src) 
{
    int ret = 0;


    ret = *(unsigned char *)src - *(unsigned char *)dst;
    while (!ret && *dst) {
        src++, dst++;
        ret = *(unsigned char *)src - *(unsigned char *)dst;
    }

    if (ret < 0)
        ret = -1 ;
    else if (ret > 0)
        ret = 1 ;

    return ret;
}


int STR_iStrcat (char *dst, char *src) 
{
    char *  cp = dst;
    int     length = 0;


    /* find end of dst */
    while (*cp)
        cp++;
    for (*cp = *src; *src != '\0'; ) {
        cp++, src++;
        *cp = *src;
        length++;
    }
    return length;
}


char *STRpszStrcat (char *dst, char *src) 
{
    char *  cp = dst;


    /* find end of dst */
    while (*cp)
        cp++;
    for (*cp = *src; *src != '\0'; ) {
        cp++, src++;
        *cp = *src;
    }
    return dst;
}


char *STRpszStrcatchr (char *dst, char c) 
{
    char *  cp = dst;


    /* find end of dst */
    while (*cp)
        cp++;
    *cp++ = c;
    *cp = '\0';
    return dst;
}

int STR_iStrcpy (char *dst, char *src) 
{
    char *  cp = dst;
    int     length = 0;


    /* Copy src over dst */
    for (*cp = *src; *src != '\0'; ) {
        cp++, src++;
        *cp = *src;
        length++;
    }
    return length;
}


char *STR_pszStrcpy (char *dst, char *src) 
{
    char *  cp = dst;


    /* Copy src over dst */
    for (*cp = *src; *src != '\0'; ) {
        cp++, src++;
        *cp = *src;
    }
    return dst;
}


int STR_iStrlen (char *str) 
{
    int length = 0;


    while (*str++)
        length++;
    return length;
}
#endif

void *STR_pvMemcpy (void *dst, void *src, UINT16 count) 
{
    void *  ret = dst;


    while (count--) {
        *(char *)dst = *(char *)src;
        dst = (char *)dst + 1;
        src = (char *)src + 1;
    }

    return ret;
}


void *STR_pvMemset (void *dst, char val, UINT16 count) 
{
    void *  start = dst;

    while (count--) {
        *(char *)dst = (char)val;
        dst = (char *)dst + 1;
    }

    return start;
}

#if 0
int STRiMemcmp(void *dst, void *src, UINT16 count) 
{
    if (!count)

        return (0);

    while (--count && (*(char *)dst == *(char *)src)) {
        dst = (char *)dst + 1;
        src = (char *)src + 1;
    }

    return (*((unsigned char *)dst) - *((unsigned char *)src));
}


BOOL STRbIsPrint (CHAR c) 
{
    return ((0x20 <= c) && (c <= 0x7E));
}


BOOL STRbIsDigit (CHAR c) 
{
    return (('0' <= c) && (c <= '9'));
}


BOOL STRbIsXDigit (CHAR c) 
{
    return ((('0' <= c) && (c <= '9'))
            || (('A' <= c) && (c <= 'F'))
            || (('a' <= c) && (c <= 'f'))
            );
}


CHAR STRcToInt (CHAR c) 
{
    if (c <= '9')
        return (c - '0');
    else
        return (c - 'A' + 10);
}


CHAR STRcToUpper (CHAR c) 
{
    if ( (c >= 'a') && (c <= 'z') )
        return (c - ('a' - 'A'));
    else
        return (c);
}


//
// No leading zero or space will be added
//
int STRiU32ToStr (PSTR pszResult, UINT32 u32Value, INT iRadix) 
{
    UINT8   u8Nibble;
    PCHAR   pchResult = pszResult;
    PCHAR   pchFirstDig = pszResult;
    char    temp;
    int     length = 0;


    // step 1. we convert digits in reverse order
    do {
        u8Nibble = (UINT8)(u32Value % iRadix);
        u32Value /= iRadix;

        if (u8Nibble < 10)
            *pchResult = (char)(u8Nibble + '0');
        else
            *pchResult = (char)(u8Nibble - 10 + 'A');
        pchResult++;
        length++;
    } while (u32Value > 0);

    // end of string is 0
    *pchResult-- = '\0';                /* terminate string; p points to last digit */

    // step 2. reverse digits now
    do {
        temp = *pchResult;
        *pchResult = *pchFirstDig;
        *pchFirstDig = temp;

        --pchResult;
        ++pchFirstDig;
    } while (pchFirstDig < pchResult);  /* repeat until halfway */

    return length;
}
#endif

#ifdef __MODULE_WEB_SMART
#if 0
//
// Leading will pad with zero digit
//

int STRiU32ToStrHexPad (PSTR pszResult, UINT32 u32Value, UINT8 byDigCnt) 
{
    UINT8   u8Nibble;
    PCHAR   pchResult = pszResult + byDigCnt;
    int     tmp = byDigCnt;


    // end of string is 0
    *pchResult = '\0';

    // each time we convert one nibble to one digit
    while (byDigCnt--) {
        u8Nibble = LONIBBLE(u32Value);
        u32Value >>= 4;

        pchResult--;
        if (u8Nibble < 10)
            *pchResult = (char)(u8Nibble + '0');
        else
            *pchResult = (char)(u8Nibble - 10 + 'A');
    }

    return tmp;
}


UINT32 STR_u32StrDecToU32 (char *str) 
{
    UINT32  dwValue = 0;
    UINT8    byLen;


    // convert string to num value
    for (byLen = 0; STRbIsDigit(str[byLen]); byLen++)
        dwValue = dwValue * 10 + STRcToInt(str[byLen]);

    return dwValue;
}
#endif

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -