Changeset 2854 for trunk/kLdr/kLdrHlp.c


Ignore:
Timestamp:
Nov 3, 2006, 4:39:12 AM (19 years ago)
Author:
bird
Message:

Hacking away on the PE module interpreter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrHlp.c

    r2846 r2854  
    527527
    528528/**
     529 * Get the pointer to the filename part of the name.
     530 *
     531 * @returns Pointer to where the filename starts within the string pointed to by pszFilename.
     532 * @returns Pointer to the terminator char if no filename.
     533 * @param   pszFilename     The filename to parse.
     534 */
     535char   *kldrHlpGetFilename(const char *pszFilename)
     536{
     537    const char *pszLast = NULL;
     538    for (;;)
     539    {
     540        char ch = *pszFilename;
     541#if defined(__OS2__) || defined(__WIN__)
     542        if (ch == '/' || ch == '\\' || ch == ':')
     543        {
     544            while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':')
     545                /* nothing */;
     546            pszLast = pszFilename;
     547        }
     548#else
     549        if (ch == '/')
     550        {
     551            while ((ch = *++pszFilename) == '/')
     552                /* betsuni */;
     553            pszLast = pszFilename;
     554        }
     555#endif
     556        if (!ch)
     557            return (char *)(pszLast ? pszLast : pszFilename);
     558        pszFilename++;
     559    }
     560}
     561
     562
     563/**
     564 * Gets the filename suffix.
     565 *
     566 * @returns Pointer to where the suffix starts within the string pointed to by pszFilename.
     567 * @returns Pointer to the terminator char if no suffix.
     568 * @param   pszFilename     The filename to parse.
     569 */
     570char   *kldrHlpGetSuff(const char *pszFilename)
     571{
     572    const char *pszDot = NULL;
     573    pszFilename = kldrHlpGetFilename(pszFilename);
     574    for (;;)
     575    {
     576        char ch = *pszFilename;
     577        if (ch == '.')
     578        {
     579            while ((ch = *++pszFilename) == '.')
     580                /* nothing */;
     581            if (ch)
     582                pszDot = pszFilename - 1;
     583        }
     584        if (!ch)
     585            return (char *)(pszDot ? pszDot : pszFilename);
     586        pszFilename++;
     587    }
     588}
     589
     590
     591/**
     592 * Gets the filename extention.
     593 *
     594 * @returns Pointer to where the extension starts within the string pointed to by pszFilename.
     595 * @returns Pointer to the terminator char if no extension.
     596 * @param   pszFilename     The filename to parse.
     597 */
     598char   *kldrHlpGetExt(const char *pszFilename)
     599{
     600    char *psz = kldrHlpGetSuff(pszFilename);
     601    return *psz ? psz + 1 : psz;
     602}
     603
     604
     605
     606/**
    529607 * Terminate the process.
    530608 *
     
    717795#endif
    718796
     797
     798int     kLdrHlpMemIComp(const void *pv1, const void *pv2, size_t cb)
     799{
     800    const uint8_t *pb1 = (const uint8_t *)pv1;
     801    const uint8_t *pb2 = (const uint8_t *)pv2;
     802    while (cb)
     803    {
     804        if (*pb1 != *pb2)
     805        {
     806            const uint8_t u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1;
     807            const uint8_t u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2;
     808            if (u1 != u2)
     809                return (int)*pb1 - (int)*pb2;
     810        }
     811        pb1++;
     812        pb2++;
     813    }
     814    return 0;
     815}
     816
     817
     818int     kLdrHlpStrIComp(const char *pv1, const char *pv2)
     819{
     820    const uint8_t *pb1 = (const uint8_t *)pv1;
     821    const uint8_t *pb2 = (const uint8_t *)pv2;
     822    for (;;)
     823    {
     824        if (*pb1 != *pb2)
     825        {
     826            const uint8_t u1 = *pb1 >= 'a' && *pb1 <= 'z' ? *pb1 - 'a' : *pb1;
     827            const uint8_t u2 = *pb2 >= 'a' && *pb2 <= 'z' ? *pb2 - 'a' : *pb2;
     828            if (u1 != u2)
     829                return (int)*pb1 - (int)*pb2;
     830        }
     831        if (!*pb1)
     832            break;
     833        pb1++;
     834        pb2++;
     835    }
     836    return 0;
     837}
     838
Note: See TracChangeset for help on using the changeset viewer.