extras/ignorecase.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 30 Mar 2003 20:44:57 +0000
changeset 555 cb2a2f1202f1
child 576 5da65f8e9a50
permissions -rw-r--r--
Initial add.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
555
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/** \file ignorecase.c */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
#include <stdio.h>
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
#include <stdlib.h>
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#include <string.h>
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
#include <ctype.h>
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#include "physfs.h"
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include "ignorecase.h"
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
/**
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
 * Please see ignorecase.h for details.
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
 *
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
 * License: this code is public domain. I make no warranty that it is useful,
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
 *  correct, harmless, or environmentally safe.
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
 *
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
 * This particular file may be used however you like, including copying it
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
 *  verbatim into a closed-source project, exploiting it commercially, and
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
 *  removing any trace of my name from the source (although I hope you won't
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
 *  do that). I welcome enhancements and corrections to this file, but I do
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
 *  not require you to send me patches if you make changes.
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
 *
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 * Unless otherwise stated, the rest of PhysicsFS falls under the GNU Lesser
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
 *  General Public License: http://www.gnu.org/licenses/lgpl.txt
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
 *
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 *  \author Ryan C. Gordon.
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
/* I'm not screwing around with stricmp vs. strcasecmp... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
static int caseInsensitiveStringCompare(const char *x, const char *y)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    int ux, uy;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    do
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
        ux = toupper((int) *x);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
        uy = toupper((int) *y);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
        if (ux != uy)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
            return((ux > uy) ? 1 : -1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        x++;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        y++;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    } while ((ux) && (uy));
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    return(0);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
} /* caseInsensitiveStringCompare */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
static int locateOneElement(char *buf)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    char *ptr;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    char **rc;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    char **i;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
    if (PHYSFS_exists(buf))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
        return(1);  /* quick rejection: exists in current case. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    ptr = strrchr(buf, '/');  /* find entry at end of path. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    if (ptr == NULL)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        rc = PHYSFS_enumerateFiles("/");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        ptr = buf;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    else
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
        *ptr = '\0';
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        rc = PHYSFS_enumerateFiles(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        *ptr = '/';
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        ptr++;  /* point past dirsep to entry itself. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    } /* else */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
    for (i = rc; *i != NULL; i++)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
        if (caseInsensitiveStringCompare(*i, ptr) == 0)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
        {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
            strcpy(ptr, *i); /* found a match. Overwrite with this case. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            PHYSFS_freeList(rc);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    } /* for */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    /* no match at all... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    PHYSFS_freeList(rc);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    return(0);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
} /* locateOneElement */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
int PHYSFSEXT_locateCorrectCase(char *buf)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    int rc;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    char *ptr;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    char *prevptr;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    while (*buf == '/')  /* skip any '/' at start of string... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        buf++;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    ptr = prevptr = buf;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    if (*ptr == '\0')
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
        return(0);  /* Uh...I guess that's success. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    while (ptr = strchr(ptr + 1, '/'))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
        *ptr = '\0';  /* block this path section off */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
        rc = locateOneElement(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
        *ptr = '/'; /* restore path separator */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        if (!rc)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
            return(-2);  /* missing element in path. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
    } /* while */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    /* check final element... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    return(locateOneElement(buf) ? 0 : -1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
} /* PHYSFSEXT_locateCorrectCase */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
#ifdef TEST_PHYSFSEXT_LOCATECORRECTCASE
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
int main(int argc, char **argv)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
    int rc;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    char buf[128];
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    PHYSFS_file *f;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    if (!PHYSFS_init(argv[0]))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
        fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    if (!PHYSFS_addToSearchPath(".", 1))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    if (!PHYSFS_setWriteDir("."))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
        fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    if (!PHYSFS_mkdir("/a/b/c"))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    if (!PHYSFS_mkdir("/a/b/C"))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
    f = PHYSFS_openWrite("/a/b/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    PHYSFS_close(f);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    if (f == NULL)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    f = PHYSFS_openWrite("/a/b/C/X.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    PHYSFS_close(f);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    if (f == NULL)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    strcpy(buf, "/a/b/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        printf("test 1 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    strcpy(buf, "/a/B/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
        printf("test 2 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    strcpy(buf, "/a/b/C/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    if ((rc != 0) || (strcmp(buf, "/a/b/C/X.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        printf("test 3 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
    strcpy(buf, "/a/b/c/X.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
        printf("test 4 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
    strcpy(buf, "/a/b/c/z.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    if ((rc != -1) || (strcmp(buf, "/a/b/c/z.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
        printf("test 5 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    strcpy(buf, "/A/B/Z/z.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    if ((rc != -2) || (strcmp(buf, "/a/b/Z/z.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
        printf("test 6 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    printf("Testing completed.\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    printf("  If no errors were reported, you're good to go.\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    PHYSFS_delete("/a/b/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    PHYSFS_delete("/a/b/C/X.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    PHYSFS_delete("/a/b/c");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
    PHYSFS_delete("/a/b/C");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
    PHYSFS_delete("/a/b");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    PHYSFS_delete("/a");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    return(0);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
} /* main */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
#endif
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
/* end of ignorecase.c ... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217