Changeset 304 for trunk/src


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

Fixed casing paths on win32.

Location:
trunk/src
Files:
3 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++)
  • 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.