test/test_physfs.c
author David Yip <dwyip@peach-bun.com>
Mon, 15 Aug 2016 00:50:58 -0500
changeset 1375 20ee02ea086c
parent 1326 ac0fac4fe6d6
child 1455 fbad4116daba
permissions -rw-r--r--
Remove unused variable in zip_hash_ancestors. Under gcc 5.4.0, this generates unused variable warnings, which in combination with -Werror causes a compile error.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     1
/**
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     2
 * Test program for PhysicsFS. May only work on Unix.
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     3
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     5
 *
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     6
 *  This file written by Ryan C. Gordon.
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     7
 */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     8
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include <stdio.h>
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    10
#include <stdlib.h>
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    11
#include <errno.h>
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    12
#include <string.h>
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    13
164
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    14
#if (defined __MWERKS__)
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    15
#include <SIOUX.h>
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    16
#endif
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    17
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    18
#if (defined PHYSFS_HAVE_READLINE)
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    19
#include <unistd.h>
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    20
#include <readline/readline.h>
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    21
#include <readline/history.h>
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    22
#endif
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    23
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
    24
#include <time.h>
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
    25
1242
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
    26
/* Define this, so the compiler doesn't complain about using old APIs. */
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
    27
#define PHYSFS_DEPRECATED
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
    28
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#include "physfs.h"
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
956
3da716cfe09f Upped version to 2.0.0!
Ryan C. Gordon <icculus@icculus.org>
parents: 865
diff changeset
    31
#define TEST_VERSION_MAJOR  2
988
27a1fb1cdc47 Updated test_physfs.c's version to match everything else.
Ryan C. Gordon <icculus@icculus.org>
parents: 956
diff changeset
    32
#define TEST_VERSION_MINOR  1
956
3da716cfe09f Upped version to 2.0.0!
Ryan C. Gordon <icculus@icculus.org>
parents: 865
diff changeset
    33
#define TEST_VERSION_PATCH  0
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    35
static FILE *history_file = NULL;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
    36
static PHYSFS_uint32 do_buffer_size = 0;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    37
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    38
static void output_versions(void)
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
{
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    PHYSFS_Version compiled;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    PHYSFS_Version linked;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    PHYSFS_VERSION(&compiled);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    PHYSFS_getLinkedVersion(&linked);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    printf("test_physfs version %d.%d.%d.\n"
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
           " Compiled against PhysicsFS version %d.%d.%d,\n"
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
           " and linked against %d.%d.%d.\n\n",
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
            TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH,
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
    50
            (int) compiled.major, (int) compiled.minor, (int) compiled.patch,
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
    51
            (int) linked.major, (int) linked.minor, (int) linked.patch);
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
} /* output_versions */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    55
static void output_archivers(void)
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
{
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    const PHYSFS_ArchiveInfo **i;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    printf("Supported archive types:\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    if (*rc == NULL)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
        printf(" * Apparently, NONE!\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    else
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        for (i = rc; *i != NULL; i++)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
            printf(" * %s: %s\n    Written by %s.\n    %s\n",
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
                    (*i)->extension, (*i)->description,
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
                    (*i)->author, (*i)->url);
1326
ac0fac4fe6d6 Moved supportsSymlinks into PHYSFS_ArchiveInfo.
Ryan C. Gordon <icculus@icculus.org>
parents: 1282
diff changeset
    70
            printf("    %s symbolic links.\n",
ac0fac4fe6d6 Moved supportsSymlinks into PHYSFS_ArchiveInfo.
Ryan C. Gordon <icculus@icculus.org>
parents: 1282
diff changeset
    71
                    (*i)->supportsSymlinks ? "Supports" : "Does not support");
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
        } /* for */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    } /* else */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    74
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    75
    printf("\n");
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
} /* output_archivers */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    79
static int cmd_quit(char *args)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    80
{
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
    81
    return 0;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    82
} /* cmd_quit */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    83
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    84
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    85
static int cmd_init(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    86
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    87
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    88
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    89
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    90
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    91
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    92
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    93
    if (PHYSFS_init(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    94
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    95
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    96
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    97
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
    98
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    99
} /* cmd_init */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   100
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   101
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   102
static int cmd_deinit(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   103
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   104
    if (PHYSFS_deinit())
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   105
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   106
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   107
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   108
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   109
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   110
} /* cmd_deinit */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   111
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   112
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   113
static int cmd_addarchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   114
{
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   115
    char *ptr = strrchr(args, ' ');
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   116
    int appending = atoi(ptr + 1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   117
    *ptr = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   118
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   119
    if (*args == '\"')
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   120
    {
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   121
        args++;
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   122
        *(ptr - 1) = '\0';
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   123
    } /* if */
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   124
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   125
    /*printf("[%s], [%d]\n", args, appending);*/
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   126
1110
803e5e8a0ff8 Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSearchPath.
Ryan C. Gordon <icculus@icculus.org>
parents: 1106
diff changeset
   127
    if (PHYSFS_mount(args, NULL, appending))
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   128
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   129
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   130
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   131
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   132
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   133
} /* cmd_addarchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   134
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   135
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   136
/* wrap free() to avoid calling convention wankery. */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   137
static void freeBuf(void *buf)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   138
{
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   139
    free(buf);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   140
} /* freeBuf */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   141
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   142
typedef enum
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   143
{
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   144
    MNTTYPE_PATH,
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   145
    MNTTYPE_MEMORY,
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   146
    MNTTYPE_HANDLE
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   147
} MountType;
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   148
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   149
static int cmd_mount_internal(char *args, const MountType mnttype)
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   150
{
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   151
    char *ptr;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   152
    char *mntpoint = NULL;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   153
    int appending = 0;
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   154
    int rc = 0;
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   155
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   156
    if (*args == '\"')
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   157
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   158
        args++;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   159
        ptr = strchr(args, '\"');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   160
        if (ptr == NULL)
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   161
        {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   162
            printf("missing string terminator in argument.\n");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   163
            return 1;
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   164
        } /* if */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   165
        *(ptr) = '\0';
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   166
    } /* if */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   167
    else
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   168
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   169
        ptr = strchr(args, ' ');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   170
        *ptr = '\0';
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   171
    } /* else */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   172
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   173
    mntpoint = ptr + 1;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   174
    if (*mntpoint == '\"')
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   175
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   176
        mntpoint++;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   177
        ptr = strchr(mntpoint, '\"');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   178
        if (ptr == NULL)
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   179
        {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   180
            printf("missing string terminator in argument.\n");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   181
            return 1;
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   182
        } /* if */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   183
        *(ptr) = '\0';
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   184
    } /* if */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   185
    else
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   186
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   187
        ptr = strchr(mntpoint, ' ');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   188
        *(ptr) = '\0';
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   189
    } /* else */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   190
    appending = atoi(ptr + 1);
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   191
689
204bb201498a Commented out a printf() and cleaned up some mallocs.
Ryan C. Gordon <icculus@icculus.org>
parents: 681
diff changeset
   192
    /*printf("[%s], [%s], [%d]\n", args, mntpoint, appending);*/
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   193
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   194
    if (mnttype == MNTTYPE_PATH)
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   195
        rc = PHYSFS_mount(args, mntpoint, appending);
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   196
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   197
    else if (mnttype == MNTTYPE_HANDLE)
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   198
    {
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   199
        PHYSFS_File *f = PHYSFS_openRead(args);
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   200
        if (f == NULL)
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   201
        {
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   202
            printf("PHYSFS_openRead('%s') failed. reason: %s.\n", args, PHYSFS_getLastError());
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   203
            return 1;
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   204
        } /* if */
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   205
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   206
        rc = PHYSFS_mountHandle(f, args, mntpoint, appending);
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   207
        if (!rc)
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   208
            PHYSFS_close(f);
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   209
    } /* else if */
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   210
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   211
    else if (mnttype == MNTTYPE_MEMORY)
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   212
    {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   213
        FILE *in = fopen(args, "rb");
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   214
        void *buf = NULL;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   215
        long len = 0;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   216
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   217
        if (in == NULL)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   218
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   219
            printf("Failed to open %s to read into memory: %s.\n", args, strerror(errno));
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   220
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   221
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   222
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   223
        if ( (fseek(in, 0, SEEK_END) != 0) || ((len = ftell(in)) < 0) )
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   224
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   225
            printf("Failed to find size of %s to read into memory: %s.\n", args, strerror(errno));
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   226
            fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   227
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   228
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   229
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   230
        buf = malloc(len);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   231
        if (buf == NULL)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   232
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   233
            printf("Failed to allocate space to read %s into memory: %s.\n", args, strerror(errno));
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   234
            fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   235
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   236
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   237
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   238
        if ((fseek(in, 0, SEEK_SET) != 0) || (fread(buf, len, 1, in) != 1))
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   239
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   240
            printf("Failed to read %s into memory: %s.\n", args, strerror(errno));
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   241
            fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   242
            free(buf);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   243
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   244
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   245
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   246
        fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   247
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   248
        rc = PHYSFS_mountMemory(buf, len, freeBuf, args, mntpoint, appending);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   249
    } /* else */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   250
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   251
    if (rc)
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   252
        printf("Successful.\n");
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   253
    else
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   254
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   255
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   256
    return 1;
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   257
} /* cmd_mount_internal */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   258
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   259
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   260
static int cmd_mount(char *args)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   261
{
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   262
    return cmd_mount_internal(args, MNTTYPE_PATH);
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   263
} /* cmd_mount */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   264
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   265
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   266
static int cmd_mount_mem(char *args)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   267
{
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   268
    return cmd_mount_internal(args, MNTTYPE_MEMORY);
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   269
} /* cmd_mount_mem */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   270
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   271
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   272
static int cmd_mount_handle(char *args)
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   273
{
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   274
    return cmd_mount_internal(args, MNTTYPE_HANDLE);
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   275
} /* cmd_mount_handle */
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   276
1282
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   277
static int cmd_getmountpoint(char *args)
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   278
{
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   279
    if (*args == '\"')
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   280
    {
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   281
        args++;
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   282
        args[strlen(args) - 1] = '\0';
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   283
    } /* if */
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   284
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   285
    printf("Dir [%s] is mounted at [%s].\n", args, PHYSFS_getMountPoint(args));
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   286
    return 1;
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   287
} /* cmd_getmountpoint */
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   288
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   289
static int cmd_removearchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   290
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   291
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   292
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   293
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   294
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   295
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   296
1110
803e5e8a0ff8 Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSearchPath.
Ryan C. Gordon <icculus@icculus.org>
parents: 1106
diff changeset
   297
    if (PHYSFS_unmount(args))
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   298
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   299
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   300
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   301
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   302
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   303
} /* cmd_removearchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   304
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   305
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   306
static int cmd_enumerate(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   307
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   308
    char **rc;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   309
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   310
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   311
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   312
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   313
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   314
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   315
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   316
    rc = PHYSFS_enumerateFiles(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   317
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   318
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   319
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   320
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   321
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   322
        int file_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   323
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   324
        for (i = rc, file_count = 0; *i != NULL; i++, file_count++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   325
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   326
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   327
        printf("\n total (%d) files.\n", file_count);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   328
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   329
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   330
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   331
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   332
} /* cmd_enumerate */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   333
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   334
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   335
static int cmd_getdirsep(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   336
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   337
    printf("Directory separator is [%s].\n", PHYSFS_getDirSeparator());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   338
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   339
} /* cmd_getdirsep */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   340
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   341
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   342
static int cmd_getlasterror(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   343
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   344
    printf("last error is [%s].\n", PHYSFS_getLastError());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   345
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   346
} /* cmd_getlasterror */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   347
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   348
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   349
static int cmd_getcdromdirs(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   350
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   351
    char **rc = PHYSFS_getCdRomDirs();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   352
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   353
    if (rc == NULL)
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   354
        printf("Failure. Reason: [%s].\n", PHYSFS_getLastError());
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   355
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   356
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   357
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   358
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   359
        for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   360
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   361
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   362
        printf("\n total (%d) drives.\n", dir_count);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   363
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   364
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   365
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   366
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   367
} /* cmd_getcdromdirs */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   368
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   369
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   370
static int cmd_getsearchpath(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   371
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   372
    char **rc = PHYSFS_getSearchPath();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   373
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   374
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   375
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   376
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   377
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   378
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   379
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   380
        for (i = rc, dir_count = 0; *i != NULL; i++, dir_count++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   381
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   382
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   383
        printf("\n total (%d) directories.\n", dir_count);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   384
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   385
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   386
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   387
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   388
} /* cmd_getcdromdirs */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   389
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   390
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   391
static int cmd_getbasedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   392
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   393
    printf("Base dir is [%s].\n", PHYSFS_getBaseDir());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   394
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   395
} /* cmd_getbasedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   396
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   397
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   398
static int cmd_getuserdir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   399
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   400
    printf("User dir is [%s].\n", PHYSFS_getUserDir());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   401
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   402
} /* cmd_getuserdir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   403
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   404
1242
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   405
static int cmd_getprefdir(char *args)
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   406
{
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   407
    char *org;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   408
    char *appName;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   409
    char *ptr = args;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   410
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   411
    org = ptr;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   412
    ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   413
    printf("Pref dir is [%s].\n", PHYSFS_getPrefDir(org, appName));
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   414
    return 1;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   415
} /* cmd_getprefdir */
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   416
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   417
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   418
static int cmd_getwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   419
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   420
    printf("Write dir is [%s].\n", PHYSFS_getWriteDir());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   421
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   422
} /* cmd_getwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   423
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   424
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   425
static int cmd_setwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   426
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   427
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   428
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   429
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   430
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   431
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   432
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   433
    if (PHYSFS_setWriteDir(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   434
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   435
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   436
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   437
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   438
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   439
} /* cmd_setwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   440
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   441
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   442
static int cmd_permitsyms(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   443
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   444
    int num;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   445
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   446
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   447
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   448
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   449
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   450
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   451
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   452
    num = atoi(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   453
    PHYSFS_permitSymbolicLinks(num);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   454
    printf("Symlinks are now %s.\n", num ? "permitted" : "forbidden");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   455
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   456
} /* cmd_permitsyms */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   457
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   458
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   459
static int cmd_setbuffer(char *args)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   460
{
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   461
    if (*args == '\"')
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   462
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   463
        args++;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   464
        args[strlen(args) - 1] = '\0';
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   465
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   466
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   467
    do_buffer_size = (unsigned int) atoi(args);
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   468
    if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   469
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   470
        printf("Further tests will set a (%lu) size buffer.\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   471
                (unsigned long) do_buffer_size);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   472
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   473
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   474
    else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   475
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   476
        printf("Further tests will NOT use a buffer.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   477
    } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   478
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   479
    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   480
} /* cmd_setbuffer */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   481
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   482
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   483
static int cmd_stressbuffer(char *args)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   484
{
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   485
    int num;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   486
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   487
    if (*args == '\"')
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   488
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   489
        args++;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   490
        args[strlen(args) - 1] = '\0';
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   491
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   492
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   493
    num = atoi(args);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   494
    if (num < 0)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   495
        printf("buffer must be greater than or equal to zero.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   496
    else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   497
    {
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   498
        PHYSFS_File *f;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   499
        int rndnum;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   500
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   501
        printf("Stress testing with (%d) byte buffer...\n", num);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   502
        f = PHYSFS_openWrite("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   503
        if (f == NULL)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   504
            printf("Couldn't open test.txt for writing: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   505
        else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   506
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   507
            int i, j;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   508
            char buf[37];
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   509
            char buf2[37];
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   510
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   511
            if (!PHYSFS_setBuffer(f, num))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   512
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   513
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   514
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   515
                PHYSFS_delete("test.txt");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   516
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   517
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   518
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   519
            strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789");
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   520
            srand((unsigned int) time(NULL));
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   521
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   522
            for (i = 0; i < 10; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   523
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   524
                for (j = 0; j < 10000; j++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   525
                {
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   526
                    PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   527
                    PHYSFS_uint32 left = 36 - right;
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   528
                    if (PHYSFS_writeBytes(f, buf, left) != left)
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   529
                    {
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   530
                        printf("PHYSFS_writeBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   531
                        PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   532
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   533
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   534
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   535
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   536
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   537
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   538
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   539
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   540
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   541
                            PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   542
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   543
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   544
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   545
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   546
                    if (PHYSFS_writeBytes(f, buf + left, right) != right)
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   547
                    {
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   548
                        printf("PHYSFS_writeBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   549
                        PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   550
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   551
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   552
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   553
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   554
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   555
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   556
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   557
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   558
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   559
                            PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   560
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   561
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   562
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   563
                } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   564
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   565
                if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   566
                {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   567
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   568
                    PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   569
                    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   570
                } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   571
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   572
            } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   573
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   574
            if (!PHYSFS_close(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   575
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   576
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   577
                return 1;  /* oh well. */
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   578
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   579
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   580
            printf(" ... test file written ...\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   581
            f = PHYSFS_openRead("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   582
            if (f == NULL)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   583
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   584
                printf("Failed to reopen stress file for reading: %s.\n", PHYSFS_getLastError());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   585
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   586
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   587
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   588
            if (!PHYSFS_setBuffer(f, num))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   589
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   590
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   591
                PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   592
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   593
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   594
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   595
            for (i = 0; i < 10; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   596
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   597
                for (j = 0; j < 10000; j++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   598
                {
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   599
                    PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0));
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   600
                    PHYSFS_uint32 left = 36 - right;
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   601
                    if (PHYSFS_readBytes(f, buf2, left) != left)
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   602
                    {
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   603
                        printf("PHYSFS_readBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   604
                        PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   605
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   606
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   607
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   608
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   609
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   610
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   611
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   612
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   613
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   614
                            PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   615
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   616
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   617
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   618
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   619
                    if (PHYSFS_readBytes(f, buf2 + left, right) != right)
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   620
                    {
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   621
                        printf("PHYSFS_readBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   622
                        PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   623
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   624
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   625
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   626
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   627
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   628
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   629
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   630
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   631
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   632
                            PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   633
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   634
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   635
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   636
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   637
                    if (memcmp(buf, buf2, 36) != 0)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   638
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   639
                        printf("readback is mismatched on iterations (%d, %d).\n", i, j);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   640
                        printf("wanted: [");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   641
                        for (i = 0; i < 36; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   642
                            printf("%c", buf[i]);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   643
                        printf("]\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   644
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   645
                        printf("   got: [");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   646
                        for (i = 0; i < 36; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   647
                            printf("%c", buf2[i]);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   648
                        printf("]\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   649
                        PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   650
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   651
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   652
                } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   653
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   654
                if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   655
                {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   656
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   657
                    PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   658
                    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   659
                } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   660
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   661
            } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   662
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   663
            printf(" ... test file read ...\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   664
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   665
            if (!PHYSFS_eof(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   666
                printf("PHYSFS_eof() returned true! That's wrong.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   667
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   668
            if (!PHYSFS_close(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   669
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   670
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   671
                return 1;  /* oh well. */
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   672
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   673
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   674
            PHYSFS_delete("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   675
            printf("stress test completed successfully.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   676
        } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   677
    } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   678
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   679
    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   680
} /* cmd_stressbuffer */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   681
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   682
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   683
static int cmd_setsaneconfig(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   684
{
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   685
    char *org;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   686
    char *appName;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   687
    char *arcExt;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   688
    int inclCD;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   689
    int arcsFirst;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   690
    char *ptr = args;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   691
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   692
        /* ugly. */
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   693
    org = ptr;
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   694
    ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   695
    ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; arcExt = ptr;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   696
    ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; inclCD = atoi(arcExt);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   697
    arcsFirst = atoi(ptr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   698
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   699
    if (strcmp(arcExt, "!") == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   700
        arcExt = NULL;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   701
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   702
    if (PHYSFS_setSaneConfig(org, appName, arcExt, inclCD, arcsFirst))
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   703
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   704
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   705
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   706
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   707
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   708
} /* cmd_setsaneconfig */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   709
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   710
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   711
static int cmd_mkdir(char *args)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   712
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   713
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   714
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   715
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   716
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   717
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   718
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   719
    if (PHYSFS_mkdir(args))
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   720
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   721
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   722
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   723
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   724
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   725
} /* cmd_mkdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   726
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   727
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   728
static int cmd_delete(char *args)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   729
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   730
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   731
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   732
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   733
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   734
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   735
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   736
    if (PHYSFS_delete(args))
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   737
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   738
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   739
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   740
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   741
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   742
} /* cmd_delete */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   743
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   744
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   745
static int cmd_getrealdir(char *args)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   746
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   747
    const char *rc;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   748
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   749
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   750
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   751
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   752
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   753
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   754
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   755
    rc = PHYSFS_getRealDir(args);
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   756
    if (rc)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   757
        printf("Found at [%s].\n", rc);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   758
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   759
        printf("Not found.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   760
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   761
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   762
} /* cmd_getrealdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   763
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   764
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   765
static int cmd_exists(char *args)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   766
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   767
    int rc;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   768
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   769
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   770
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   771
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   772
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   773
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   774
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   775
    rc = PHYSFS_exists(args);
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   776
    printf("File %sexists.\n", rc ? "" : "does not ");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   777
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   778
} /* cmd_exists */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   779
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   780
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   781
static int cmd_isdir(char *args)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   782
{
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   783
    PHYSFS_Stat statbuf;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   784
    int rc;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   785
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   786
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   787
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   788
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   789
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   790
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   791
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   792
    rc = PHYSFS_stat(args, &statbuf);
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   793
    if (rc)
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   794
        rc = (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY);
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   795
    printf("File %s a directory.\n", rc ? "is" : "is NOT");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   796
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   797
} /* cmd_isdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   798
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   799
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   800
static int cmd_issymlink(char *args)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   801
{
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   802
    PHYSFS_Stat statbuf;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   803
    int rc;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   804
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   805
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   806
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   807
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   808
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   809
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   810
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   811
    rc = PHYSFS_stat(args, &statbuf);
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   812
    if (rc)
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   813
        rc = (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK);
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   814
    printf("File %s a symlink.\n", rc ? "is" : "is NOT");
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   815
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   816
} /* cmd_issymlink */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   817
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   818
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   819
static int cmd_cat(char *args)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   820
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   821
    PHYSFS_File *f;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   822
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   823
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   824
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   825
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   826
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   827
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   828
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   829
    f = PHYSFS_openRead(args);
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   830
    if (f == NULL)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   831
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   832
    else
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   833
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   834
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   835
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   836
            if (!PHYSFS_setBuffer(f, do_buffer_size))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   837
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   838
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   839
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   840
                PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   841
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   842
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   843
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   844
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   845
        while (1)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   846
        {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   847
            char buffer[128];
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   848
            PHYSFS_sint64 rc;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   849
            PHYSFS_sint64 i;
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   850
            rc = PHYSFS_readBytes(f, buffer, sizeof (buffer));
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   851
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   852
            for (i = 0; i < rc; i++)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   853
                fputc((int) buffer[i], stdout);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   854
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   855
            if (rc < sizeof (buffer))
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   856
            {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   857
                printf("\n\n");
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   858
                if (!PHYSFS_eof(f))
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   859
                {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   860
                    printf("\n (Error condition in reading. Reason: [%s])\n\n",
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   861
                           PHYSFS_getLastError());
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   862
                } /* if */
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   863
                PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   864
                return 1;
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   865
            } /* if */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   866
        } /* while */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   867
    } /* else */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   868
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   869
    return 1;
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   870
} /* cmd_cat */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   871
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   872
1063
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   873
#define CRC32_BUFFERSIZE 512
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   874
static int cmd_crc32(char *args)
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   875
{
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   876
    PHYSFS_File *f;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   877
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   878
    if (*args == '\"')
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   879
    {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   880
        args++;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   881
        args[strlen(args) - 1] = '\0';
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   882
    } /* if */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   883
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   884
    f = PHYSFS_openRead(args);
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   885
    if (f == NULL)
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   886
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   887
    else
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   888
    {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   889
        PHYSFS_uint8 buffer[CRC32_BUFFERSIZE];
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   890
        PHYSFS_uint32 crc = -1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   891
        PHYSFS_sint64 bytesread;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   892
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   893
        while ((bytesread = PHYSFS_readBytes(f, buffer, CRC32_BUFFERSIZE)) > 0)
1063
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   894
        {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   895
            PHYSFS_uint32 i, bit;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   896
            for (i = 0; i < bytesread; i++)
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   897
            {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   898
                for (bit = 0; bit < 8; bit++, buffer[i] >>= 1)
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   899
                    crc = (crc >> 1) ^ (((crc ^ buffer[i]) & 1) ? 0xEDB88320 : 0);
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   900
            } /* for */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   901
        } /* while */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   902
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   903
        if (bytesread < 0)
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   904
        {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   905
            printf("error while reading. Reason: [%s].\n",
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   906
                   PHYSFS_getLastError());
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   907
            return 1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   908
        } /* if */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   909
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   910
        PHYSFS_close(f);
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   911
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   912
        crc ^= -1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   913
        printf("CRC32 for %s: 0x%08X\n", args, crc);
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   914
    } /* else */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   915
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   916
    return 1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   917
} /* cmd_crc32 */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   918
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   919
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   920
static int cmd_filelength(char *args)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   921
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   922
    PHYSFS_File *f;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   923
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   924
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   925
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   926
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   927
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   928
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   929
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   930
    f = PHYSFS_openRead(args);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   931
    if (f == NULL)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   932
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   933
    else
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   934
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   935
        PHYSFS_sint64 len = PHYSFS_fileLength(f);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   936
        if (len == -1)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   937
            printf("failed to determine length. Reason: [%s].\n", PHYSFS_getLastError());
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   938
        else
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   939
            printf(" (cast to int) %d bytes.\n", (int) len);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   940
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   941
        PHYSFS_close(f);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   942
    } /* else */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   943
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   944
    return 1;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   945
} /* cmd_filelength */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   946
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   947
#define WRITESTR "The cat sat on the mat.\n\n"
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   948
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   949
static int cmd_append(char *args)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   950
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   951
    PHYSFS_File *f;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   952
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   953
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   954
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   955
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   956
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   957
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   958
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   959
    f = PHYSFS_openAppend(args);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   960
    if (f == NULL)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   961
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   962
    else
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   963
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   964
        size_t bw;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   965
        PHYSFS_sint64 rc;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   966
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   967
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   968
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   969
            if (!PHYSFS_setBuffer(f, do_buffer_size))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   970
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   971
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   972
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   973
                PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   974
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   975
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   976
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   977
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   978
        bw = strlen(WRITESTR);
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   979
        rc = PHYSFS_writeBytes(f, WRITESTR, bw);
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   980
        if (rc != bw)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   981
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   982
            printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n",
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   983
                   (int) rc, (int) bw, PHYSFS_getLastError());
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   984
        } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   985
        else
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   986
        {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   987
            printf("Successful.\n");
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   988
        } /* else */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   989
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   990
        PHYSFS_close(f);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   991
    } /* else */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   992
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
   993
    return 1;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   994
} /* cmd_append */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   995
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   996
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   997
static int cmd_write(char *args)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   998
{
654
c0ae01de361d Changed PHYSFS_file to PHYSFS_File to match rest of API's naming
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   999
    PHYSFS_File *f;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1000
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1001
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1002
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1003
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1004
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1005
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1006
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1007
    f = PHYSFS_openWrite(args);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1008
    if (f == NULL)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1009
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1010
    else
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1011
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1012
        size_t bw;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1013
        PHYSFS_sint64 rc;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1014
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1015
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1016
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1017
            if (!PHYSFS_setBuffer(f, do_buffer_size))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1018
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1019
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1020
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1021
                PHYSFS_close(f);
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
  1022
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1023
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1024
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1025
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1026
        bw = strlen(WRITESTR);
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
  1027
        rc = PHYSFS_writeBytes(f, WRITESTR, bw);
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1028
        if (rc != bw)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1029
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
  1030
            printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n",
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
  1031
                   (int) rc, (int) bw, PHYSFS_getLastError());
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1032
        } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1033
        else
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1034
        {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1035
            printf("Successful.\n");
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1036
        } /* else */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1037
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1038
        PHYSFS_close(f);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1039
    } /* else */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1040
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
  1041
    return 1;
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1042
} /* cmd_write */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1043
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
  1044
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1045
static char* modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1046
{
1263
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1047
    if (modtime < 0)
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1048
        strncpy(modstr, "Unknown\n", strsize);
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1049
    else
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1050
    {
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1051
        time_t t = (time_t) modtime;
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1052
        char *str = ctime(&t);
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1053
        strncpy(modstr, str, strsize);
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1054
    } /* else */
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1055
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1056
    modstr[strsize-1] = '\0';
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1057
    return modstr;
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1058
} /* modTimeToStr */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1059
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1060
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1061
static int cmd_getlastmodtime(char *args)
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1062
{
1105
a81d0326300f Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1102
diff changeset
  1063
    PHYSFS_Stat statbuf;
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1105
diff changeset
  1064
    if (!PHYSFS_stat(args, &statbuf))
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1065
        printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1066
    else
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1067
    {
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1068
        char modstr[64];
1105
a81d0326300f Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1102
diff changeset
  1069
        modTimeToStr(statbuf.modtime, modstr, sizeof (modstr));
a81d0326300f Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1102
diff changeset
  1070
        printf("Last modified: %s (%ld).\n", modstr, (long) statbuf.modtime);
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1071
    } /* else */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1072
1016
957c97389257 Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents: 988
diff changeset
  1073
    return 1;
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1074
} /* cmd_getLastModTime */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1075
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1076
static int cmd_stat(char *args)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1077
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1078
    PHYSFS_Stat stat;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1079
    char timestring[65];
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1080
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1081
    if (*args == '\"')
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1082
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1083
        args++;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1084
        args[strlen(args) - 1] = '\0';
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1085
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1086
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1105
diff changeset
  1087
    if(!PHYSFS_stat(args, &stat))
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1088
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1089
        printf("failed to stat. Reason [%s].\n", PHYSFS_getLastError());
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1090
        return 1;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1091
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1092
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1093
    printf("Filename: %s\n", args);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1094
    printf("Size %d\n",(int) stat.filesize);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1095
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1096
    if(stat.filetype == PHYSFS_FILETYPE_REGULAR)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1097
        printf("Type: File\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1098
    else if(stat.filetype == PHYSFS_FILETYPE_DIRECTORY)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1099
        printf("Type: Directory\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1100
    else if(stat.filetype == PHYSFS_FILETYPE_SYMLINK)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1101
        printf("Type: Symlink\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1102
    else
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1103
        printf("Type: Unknown\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1104
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1105
    printf("Created at: %s", modTimeToStr(stat.createtime, timestring, 64));
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1106
    printf("Last modified at: %s", modTimeToStr(stat.modtime, timestring, 64));
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1107
    printf("Last accessed at: %s", modTimeToStr(stat.accesstime, timestring, 64));
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1108
    printf("Readonly: %s\n", stat.readonly ? "true" : "false");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1109
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1110
    return 1;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1111
} /* cmd_filelength */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1112
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1113
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1114
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1115
/* must have spaces trimmed prior to this call. */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1116
static int count_args(const char *str)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1117
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1118
    int retval = 0;
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
  1119
    int in_quotes = 0;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1120
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1121
    if (str != NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1122
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1123
        for (; *str != '\0'; str++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1124
        {
165