bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Case Insensitive problem


From: Benoît Rouits
Subject: Case Insensitive problem
Date: Wed, 06 Jun 2001 11:09:51 +0200

Hello,
Due to the problem of case insensitive test on win32 systems
clients with
case sensitive servers (e.g. unix, etc..), my aim is to make a
clean part of
code to insert in CVS sources between #ifdef
case_insensitive[...]#endif.
I made two function : 
void basename(directory, filename, path) that splits path into
directory and filename ; and 
int case_insensitive_exist(return_name ,directory, file)
to test if a file exists in the given directory and return the
matching return_name
tu use for stat(), acces(), open() etc ...
I would very appreciate your advice to find the places i have
to modify.
Please read also the code attached and tell me what you think
about it.
I would like to start again discussion on how to fix this
problem.

to star discussing, please refer to :
http://www.mail-archive.com/bug-cvs%40gnu.org/msg01177.html

cheers,
Ben (waiting for discussion)
-- 
     Benoit Rouits     | Tel : (+33) 1 4922 7719
Free Software Engineer | http://www.alcove.com
/*give the directory and the filename extracted from the path*/
/* in : "path". out : "directory", "filename" (must be malloc'd) */
#define SEPARATOR '/'
#define MAXLEN 256
void basename(directory,filename,path)
    char *directory;
    char *filename;
    char *path;
{
    /* reverse a string */
    /* in : "str". out : "rev" (must be malloc'd) */
    void s_reverse(rev, str)
        char *rev;
        char *str;
    {
        int i;
        for (i=strlen(str)-1;i>=0;i--)
        {
            rev[strlen(str)-i-1]=str[i];
        }
        rev[strlen(str)]='\0';
    }

    int i;
    char rev_path[MAXLEN];
    char rev_file[MAXLEN];
    char rev_dir[MAXLEN];

    s_reverse(rev_path,path);
    i=0;
    /* extract filname (reversed) */
    while (rev_path[i] != SEPARATOR && i < strlen(rev_path))
    {
        rev_file[i]=rev_path[i];
        i++;
    }
    rev_file[i]='\0';
    s_reverse(filename, rev_file);
    /* extract directory (reversed) */
    while (i < strlen(rev_path))
    {
        rev_dir[i-strlen(rev_file)]=rev_path[i+1];
        i++;
    }
    rev_dir[strlen(rev_path)-strlen(rev_file)]='\0';
    s_reverse(directory, rev_dir);
}
/* gives "filename" that exists in "directory" with CASE INSENSITIVE TEST*/
/* in : "file", "directory". out :"return-name" (must be malloc'd) */
/* return : 1 if filename exists (CASE INSENSITIVE), 0 if not */
int case_insensitive_exist(return_name ,directory, file)
    char *return_name;
    char *directory;
    char *file;
{
    int exist = 0;
    struct dirent *d_ent; /* need of <dirent.h> */
    DIR *dp;
        
    /* Converts a string s into upper-case string dest. Need of <ctype.h> */
    /* Warning : you must malloc "dest" ! */
    void s_toupper(dest,s)
        char *dest;
        char *s;
    {
        int i;
                
        for (i=0;i<=strlen(s);i++)
        {
            dest[i]=(char)toupper((int)s[i]);
        }
    }
    /* open directory*/
    dp=opendir(directory);
    if (dp)
    {
        char upper_d_name[MAXLEN];
        char upper_file[MAXLEN];
        /* list directory */
        while (d_ent=readdir(dp))
        {   /* compare case-insensitive */
            s_toupper(upper_d_name,d_ent->d_name);
            s_toupper(upper_file, file);
            if (!strcmp(upper_d_name,upper_file))
            {
                exist=1;
                break;
            }
        }
    }
    if (exist)
    {
        strcpy (return_name,d_ent->d_name);
        return 1;
    }
    else
    {
        strcpy(return_name,file);
        return 0;
    }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]