Changeset 304 for trunk/src/kDepPre


Ignore:
Timestamp:
Aug 11, 2005, 10:17:17 PM (20 years ago)
Author:
bird
Message:

Fixed casing paths on win32.

Location:
trunk/src/kDepPre
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kDepPre/Makefile.kmk

    r270 r304  
    2929kDepPre_TEMPLATE        = BIN
    3030kDepPre_DEFS.linux      = HAVE_FGETC_UNLOCKED=1
    31 kDepPre_DEFS.win32      = NEED_ISBLANK=1
     31kDepPre_DEFS.win32      = NEED_ISBLANK=1 __WIN32__=1
    3232kDepPre_SOURCES         = $(PATH_CURRENT)/kDepPre.c
    3333
  • trunk/src/kDepPre/kDepPre.c

    r260 r304  
    3030#include <string.h>
    3131#include <ctype.h>
     32#ifdef __WIN32__
     33#include <windows.h>
     34#endif
    3235
    3336#ifdef HAVE_FGETC_UNLOCKED
     
    6871
    6972
     73#ifdef __WIN32__
     74/**
     75 * Corrects the case of a path.
     76 * Expects a fullpath!
     77 *
     78 * @param   pszPath     Pointer to the path, both input and output.
     79 *                      The buffer must be able to hold one more byte than the string length.
     80 */
     81void w32_fixcase(char *pszPath)
     82{
     83#define my_assert(expr) \
     84    do { \
     85        if (!(expr)) { \
     86            printf("my_assert: %s, file %s, line %d\npszPath=%s\npsz=%s\n", \
     87                   #expr, __FILE__, __LINE__, pszPath, psz); \
     88            __asm { __asm int 3 } \
     89            exit(1); \
     90        } \
     91    } while (0)
     92   
     93    char *psz = pszPath;
     94    if (*psz == '/' || *psz == '\\')
     95    {
     96        if (psz[1] == '/' || psz[1] == '\\')
     97        {
     98            /* UNC */
     99            my_assert(psz[1] == '/' || psz[1] == '\\');
     100            my_assert(psz[2] != '/' && psz[2] != '\\');
     101
     102            /* skip server name */
     103            psz += 2;
     104            while (*psz != '\\' && *psz != '/')
     105            {
     106                if (!*psz)
     107                    return;
     108                *psz++ = toupper(*psz);
     109            }
     110
     111            /* skip the share name */
     112            psz++;
     113            my_assert(*psz != '/' && *psz != '\\');
     114            while (*psz != '\\' && *psz != '/')
     115            {
     116                if (!*psz)
     117                    return;
     118                *psz++ = toupper(*psz);
     119            }
     120            my_assert(*psz == '/' || *psz == '\\');
     121            psz++;
     122        }
     123        else
     124        {
     125            /* Unix spec */
     126            psz++;
     127        }
     128    }
     129    else
     130    {
     131        /* Drive letter */
     132        my_assert(psz[1] == ':');
     133        *psz = toupper(*psz);
     134        my_assert(psz[0] >= 'A' && psz[0] <= 'Z');
     135        my_assert(psz[2] == '/' || psz[2] == '\\');
     136        psz += 3;
     137    }
     138
     139    /*
     140     * Pointing to the first char after the unc or drive specifier.
     141     */
     142    while (*psz)
     143    {
     144        WIN32_FIND_DATA FindFileData;
     145        HANDLE hDir;
     146        char chSaved0;
     147        char chSaved1;
     148        char *pszEnd;
     149
     150
     151        /* find the end of the component. */
     152        pszEnd = psz;
     153        while (*pszEnd && *pszEnd != '/' && *pszEnd != '\\')
     154            pszEnd++;
     155
     156        /* replace the end with "?\0" */
     157        chSaved0 = pszEnd[0];
     158        chSaved1 = pszEnd[1];
     159        pszEnd[0] = '?';
     160        pszEnd[1] = '\0';
     161
     162        /* find the right filename. */
     163        hDir = FindFirstFile(pszPath, &FindFileData);
     164        pszEnd[1] = chSaved1;
     165        if (!hDir)
     166        {
     167            pszEnd[0] = chSaved0;
     168            return;
     169        }
     170        pszEnd[0] = '\0';
     171        while (stricmp(FindFileData.cFileName, psz))
     172        {
     173            if (!FindNextFile(hDir, &FindFileData))
     174            {
     175                pszEnd[0] = chSaved0;
     176                return;
     177            }
     178        }
     179        strcpy(psz, FindFileData.cFileName);
     180        pszEnd[0] = chSaved0;
     181
     182        /* advance to the next component */
     183        if (!chSaved0)
     184            return;
     185        psz = pszEnd + 1;
     186        my_assert(*psz != '/' && *psz != '\\');
     187    }
     188#undef my_assert
     189}
     190
     191#endif
     192
     193
    70194/**
    71195 * Prints the dependency chain.
     
    85209            &&  pDep->szFilename[pDep->cchFilename - 1] == '>')
    86210            continue;
    87 
     211#ifdef __WIN32__
     212        {
     213        char szFilename[_MAX_PATH + 1];
     214        if (_fullpath(szFilename, pDep->szFilename, sizeof(szFilename)))
     215            w32_fixcase(szFilename);
    88216        fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
     217        }
     218#else       
     219        fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
     220#endif       
    89221    }
    90222    fprintf(pOutput, "\n\n");
     
    105237static unsigned sdbm(const char *str)
    106238{
    107     const char *pszStart;
    108239    unsigned hash = 0;
    109240    int c;
Note: See TracChangeset for help on using the changeset viewer.