extras/ignorecase.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 20 Jul 2003 20:57:55 +0000
changeset 576 5da65f8e9a50
parent 555 cb2a2f1202f1
child 654 c0ae01de361d
permissions -rw-r--r--
Switched to zlib license.
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
576
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
    21
 *  not require you to send me patches if you make changes. This code has
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
    22
 *  NO WARRANTY.
555
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
 *
576
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
    24
 * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
5da65f8e9a50 Switched to zlib license.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
    25
 *  Please see LICENSE in the root of the source tree.
555
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
 *
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
 *  \author Ryan C. Gordon.
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
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
/* I'm not screwing around with stricmp vs. strcasecmp... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
static int caseInsensitiveStringCompare(const char *x, const char *y)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    int ux, uy;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    do
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
        ux = toupper((int) *x);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
        uy = toupper((int) *y);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
        if (ux != uy)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
            return((ux > uy) ? 1 : -1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        x++;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        y++;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    } while ((ux) && (uy));
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    return(0);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
} /* caseInsensitiveStringCompare */
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
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
static int locateOneElement(char *buf)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    char *ptr;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    char **rc;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    char **i;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    if (PHYSFS_exists(buf))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        return(1);  /* quick rejection: exists in current case. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    ptr = strrchr(buf, '/');  /* find entry at end of path. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    if (ptr == NULL)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        rc = PHYSFS_enumerateFiles("/");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        ptr = buf;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    else
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        *ptr = '\0';
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        rc = PHYSFS_enumerateFiles(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        *ptr = '/';
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
        ptr++;  /* point past dirsep to entry itself. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    } /* else */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    for (i = rc; *i != NULL; i++)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
        if (caseInsensitiveStringCompare(*i, ptr) == 0)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            strcpy(ptr, *i); /* found a match. Overwrite with this case. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            PHYSFS_freeList(rc);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
            return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    } /* for */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    /* no match at all... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    PHYSFS_freeList(rc);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    return(0);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
} /* locateOneElement */
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
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
int PHYSFSEXT_locateCorrectCase(char *buf)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    int rc;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    char *ptr;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
    char *prevptr;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    while (*buf == '/')  /* skip any '/' at start of string... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
        buf++;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    ptr = prevptr = buf;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    if (*ptr == '\0')
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
        return(0);  /* Uh...I guess that's success. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    while (ptr = strchr(ptr + 1, '/'))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
        *ptr = '\0';  /* block this path section off */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
        rc = locateOneElement(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        *ptr = '/'; /* restore path separator */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
        if (!rc)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
            return(-2);  /* missing element in path. */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    } /* while */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    /* check final element... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
    return(locateOneElement(buf) ? 0 : -1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
} /* PHYSFSEXT_locateCorrectCase */
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
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
#ifdef TEST_PHYSFSEXT_LOCATECORRECTCASE
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
int main(int argc, char **argv)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
{
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    int rc;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
    char buf[128];
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    PHYSFS_file *f;
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    if (!PHYSFS_init(argv[0]))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
        fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    if (!PHYSFS_addToSearchPath(".", 1))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
        fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
    if (!PHYSFS_setWriteDir("."))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
        fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    if (!PHYSFS_mkdir("/a/b/c"))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    if (!PHYSFS_mkdir("/a/b/C"))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    f = PHYSFS_openWrite("/a/b/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    PHYSFS_close(f);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    if (f == NULL)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
    f = PHYSFS_openWrite("/a/b/C/X.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    PHYSFS_close(f);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    if (f == NULL)
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    {
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
        return(1);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    } /* if */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    strcpy(buf, "/a/b/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
        printf("test 1 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    strcpy(buf, "/a/B/c/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
        printf("test 2 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
    strcpy(buf, "/a/b/C/x.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
    if ((rc != 0) || (strcmp(buf, "/a/b/C/X.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
        printf("test 3 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    strcpy(buf, "/a/b/c/X.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        printf("test 4 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    strcpy(buf, "/a/b/c/z.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    if ((rc != -1) || (strcmp(buf, "/a/b/c/z.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
        printf("test 5 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    strcpy(buf, "/A/B/Z/z.txt");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
    rc = PHYSFSEXT_locateCorrectCase(buf);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    if ((rc != -2) || (strcmp(buf, "/a/b/Z/z.txt") != 0))
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
        printf("test 6 failed\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    printf("Testing completed.\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    printf("  If no errors were reported, you're good to go.\n");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
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/X.txt");
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/C");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    PHYSFS_delete("/a/b");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    PHYSFS_delete("/a");
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    PHYSFS_deinit();
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    return(0);
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
} /* main */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
#endif
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
/* end of ignorecase.c ... */
cb2a2f1202f1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218