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

Fixed casing paths on win32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/w32/pathstuff.c

    r53 r304  
     1#include <windows.h>
    12#include <string.h>
    23#include <stdlib.h>
     4#include <stdio.h>
    35#include "make.h"
    46#include "pathstuff.h"
     7
    58
    69/*
     
    6467
    6568/*
     69 * Corrects the case of a path.
     70 * Expects a fullpath!
     71 */
     72void w32_fixcase(char *pszPath)
     73{
     74#define my_assert(expr) \
     75    do { \
     76        if (!(expr)) { \
     77            printf("my_assert: %s, file %s, line %d\npszPath=%s\npsz=%s\n", \
     78                   #expr, __FILE__, __LINE__, pszPath, psz); \
     79            __asm { __asm int 3 } \
     80            exit(1); \
     81        } \
     82    } while (0)
     83   
     84    char *psz = pszPath;
     85    if (*psz == '/' || *psz == '\\')
     86    {
     87        if (psz[1] == '/' || psz[1] == '\\')
     88        {
     89            /* UNC */
     90            my_assert(psz[1] == '/' || psz[1] == '\\');
     91            my_assert(psz[2] != '/' && psz[2] != '\\');
     92
     93            /* skip server name */
     94            psz += 2;
     95            while (*psz != '\\' && *psz != '/')
     96            {
     97                if (!*psz)
     98                    return;
     99                *psz++ = toupper(*psz);
     100            }
     101
     102            /* skip the share name */
     103            psz++;
     104            my_assert(*psz != '/' && *psz != '\\');
     105            while (*psz != '\\' && *psz != '/')
     106            {
     107                if (!*psz)
     108                    return;
     109                *psz++ = toupper(*psz);
     110            }
     111            my_assert(*psz == '/' || *psz == '\\');
     112            psz++;
     113        }
     114        else
     115        {
     116            /* Unix spec */
     117            psz++;
     118        }
     119    }
     120    else
     121    {
     122        /* Drive letter */
     123        my_assert(psz[1] == ':');
     124        *psz = toupper(*psz);
     125        my_assert(psz[0] >= 'A' && psz[0] <= 'Z');
     126        my_assert(psz[2] == '/' || psz[2] == '\\');
     127        psz += 3;
     128    }
     129
     130    /*
     131     * Pointing to the first char after the unc or drive specifier.
     132     */
     133    while (*psz)
     134    {
     135        WIN32_FIND_DATA FindFileData;
     136        HANDLE hDir;
     137        char chSaved0;
     138        char chSaved1;
     139        char *pszEnd;
     140
     141
     142        /* find the end of the component. */
     143        pszEnd = psz;
     144        while (*pszEnd && *pszEnd != '/' && *pszEnd != '\\')
     145            pszEnd++;
     146
     147        /* replace the end with "?\0" */
     148        chSaved0 = pszEnd[0];
     149        chSaved1 = pszEnd[1];
     150        pszEnd[0] = '?';
     151        pszEnd[1] = '\0';
     152
     153        /* find the right filename. */
     154        hDir = FindFirstFile(pszPath, &FindFileData);
     155        pszEnd[1] = chSaved1;
     156        if (!hDir)
     157        {
     158            pszEnd[0] = chSaved0;
     159            return;
     160        }
     161        pszEnd[0] = '\0';
     162        while (stricmp(FindFileData.cFileName, psz))
     163        {
     164            if (!FindNextFile(hDir, &FindFileData))
     165            {
     166                pszEnd[0] = chSaved0;
     167                return;
     168            }
     169        }
     170        strcpy(psz, FindFileData.cFileName);
     171        pszEnd[0] = chSaved0;
     172
     173        /* advance to the next component */
     174        if (!chSaved0)
     175            return;
     176        psz = pszEnd + 1;
     177        my_assert(*psz != '/' && *psz != '\\');
     178    }
     179#undef my_assert
     180}
     181
     182/*
    66183 * Convert to forward slashes. Resolve to full pathname optionally
    67184 */
     
    76193    else
    77194        strncpy(w32_path, filename, sizeof (w32_path));
     195
     196    w32_fixcase(w32_path);
    78197
    79198    for (p = w32_path; p && *p; p++)
Note: See TracChangeset for help on using the changeset viewer.