test/test_physfs.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 01 Jun 2012 05:44:50 -0400
changeset 1283 8bcc48d243df
parent 1282 62256a6a8e4e
child 1326 ac0fac4fe6d6
permissions -rw-r--r--
Added Zip64 support to the .zip archiver. Now we can handle .zip files > 4 gigabytes, etc.
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);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
        } /* for */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    } /* else */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    72
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    73
    printf("\n");
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
} /* output_archivers */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    77
static int cmd_quit(char *args)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    78
{
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
    79
    return 0;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    80
} /* cmd_quit */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    81
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    82
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    83
static int cmd_init(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    84
{
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
    85
    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
    86
    {
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
        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
        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
    89
    } /* 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
    90
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    91
    if (PHYSFS_init(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    92
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    93
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    94
        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
    95
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
    96
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    97
} /* cmd_init */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    98
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    99
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   100
static int cmd_deinit(char *args)
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
    if (PHYSFS_deinit())
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   103
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   104
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   105
        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
   106
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
   107
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   108
} /* cmd_deinit */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   109
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   110
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   111
static int cmd_addarchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   112
{
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
   113
    char *ptr = strrchr(args, ' ');
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   114
    int appending = atoi(ptr + 1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   115
    *ptr = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   116
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
   117
    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
   118
    {
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
        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
        *(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
   121
    } /* 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
   122
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
   123
    /*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
   124
1110
803e5e8a0ff8 Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSearchPath.
Ryan C. Gordon <icculus@icculus.org>
parents: 1106
diff changeset
   125
    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
   126
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   127
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   128
        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
   129
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
   130
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   131
} /* cmd_addarchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   132
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   133
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   134
/* wrap free() to avoid calling convention wankery. */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   135
static void freeBuf(void *buf)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   136
{
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   137
    free(buf);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   138
} /* freeBuf */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   139
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   140
typedef enum
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   141
{
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   142
    MNTTYPE_PATH,
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   143
    MNTTYPE_MEMORY,
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   144
    MNTTYPE_HANDLE
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   145
} MountType;
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   146
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   147
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
   148
{
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   149
    char *ptr;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   150
    char *mntpoint = NULL;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   151
    int appending = 0;
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   152
    int rc = 0;
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   153
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   154
    if (*args == '\"')
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
        args++;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   157
        ptr = strchr(args, '\"');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   158
        if (ptr == NULL)
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   159
        {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   160
            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
   161
            return 1;
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   162
        } /* if */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   163
        *(ptr) = '\0';
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
    else
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   166
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   167
        ptr = strchr(args, ' ');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   168
        *ptr = '\0';
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   169
    } /* else */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   170
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   171
    mntpoint = ptr + 1;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   172
    if (*mntpoint == '\"')
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   173
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   174
        mntpoint++;
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   175
        ptr = strchr(mntpoint, '\"');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   176
        if (ptr == NULL)
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   177
        {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   178
            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
   179
            return 1;
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   180
        } /* if */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   181
        *(ptr) = '\0';
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
    else
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   184
    {
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   185
        ptr = strchr(mntpoint, ' ');
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   186
        *(ptr) = '\0';
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   187
    } /* else */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   188
    appending = atoi(ptr + 1);
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   189
689
204bb201498a Commented out a printf() and cleaned up some mallocs.
Ryan C. Gordon <icculus@icculus.org>
parents: 681
diff changeset
   190
    /*printf("[%s], [%s], [%d]\n", args, mntpoint, appending);*/
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   191
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   192
    if (mnttype == MNTTYPE_PATH)
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   193
        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
   194
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   195
    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
   196
    {
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   197
        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
   198
        if (f == NULL)
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   199
        {
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   200
            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
   201
            return 1;
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   202
        } /* if */
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   203
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   204
        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
   205
        if (!rc)
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   206
            PHYSFS_close(f);
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   207
    } /* else if */
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   208
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   209
    else if (mnttype == MNTTYPE_MEMORY)
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   210
    {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   211
        FILE *in = fopen(args, "rb");
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   212
        void *buf = NULL;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   213
        long len = 0;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   214
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   215
        if (in == NULL)
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
            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
   218
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   219
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   220
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   221
        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
   222
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   223
            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
   224
            fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   225
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   226
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   227
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   228
        buf = malloc(len);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   229
        if (buf == NULL)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   230
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   231
            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
   232
            fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   233
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   234
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   235
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   236
        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
   237
        {
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   238
            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
   239
            fclose(in);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   240
            free(buf);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   241
            return 1;
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   242
        } /* if */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   243
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   244
        fclose(in);
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
        rc = PHYSFS_mountMemory(buf, len, freeBuf, args, mntpoint, appending);
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   247
    } /* else */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   248
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   249
    if (rc)
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   250
        printf("Successful.\n");
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   251
    else
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   252
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   253
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
   254
    return 1;
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   255
} /* cmd_mount_internal */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   256
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   257
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   258
static int cmd_mount(char *args)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   259
{
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   260
    return cmd_mount_internal(args, MNTTYPE_PATH);
681
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   261
} /* cmd_mount */
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   262
451025285d35 Some mount functionality stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 654
diff changeset
   263
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   264
static int cmd_mount_mem(char *args)
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   265
{
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   266
    return cmd_mount_internal(args, MNTTYPE_MEMORY);
1120
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   267
} /* cmd_mount_mem */
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   268
67e5e23425a0 Added PHYSFS_mountMemory().
Ryan C. Gordon <icculus@icculus.org>
parents: 1110
diff changeset
   269
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   270
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
   271
{
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   272
    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
   273
} /* cmd_mount_handle */
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   274
1282
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   275
static int cmd_getmountpoint(char *args)
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   276
{
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   277
    if (*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
        args++;
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   280
        args[strlen(args) - 1] = '\0';
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   281
    } /* if */
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   282
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   283
    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
   284
    return 1;
62256a6a8e4e Added getmointpoint command to test_physfs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1263
diff changeset
   285
} /* cmd_getmountpoint */
1123
6fdff9f9758d Added PHYSFS_mountHandle(). Now you can do archives-in-archives!
Ryan C. Gordon <icculus@icculus.org>
parents: 1120
diff changeset
   286
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   287
static int cmd_removearchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   288
{
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
   289
    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
   290
    {
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
        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
        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
   293
    } /* 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
   294
1110
803e5e8a0ff8 Added PHYSFS_unmount(), deprecated addToSearchPath and removeFromSearchPath.
Ryan C. Gordon <icculus@icculus.org>
parents: 1106
diff changeset
   295
    if (PHYSFS_unmount(args))
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   296
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   297
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   298
        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
   299
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
   300
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   301
} /* cmd_removearchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   302
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   303
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   304
static int cmd_enumerate(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   305
{
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
   306
    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
   307
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
    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
   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
        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
        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
   312
    } /* 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
   313
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
    rc = PHYSFS_enumerateFiles(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   315
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   316
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   317
        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
   318
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   319
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   320
        int file_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   321
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   322
        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
   323
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   324
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   325
        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
   326
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   327
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   328
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
   329
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   330
} /* cmd_enumerate */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   331
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   332
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   333
static int cmd_getdirsep(char *args)
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
    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
   336
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   337
} /* cmd_getdirsep */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   338
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   339
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   340
static int cmd_getlasterror(char *args)
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
    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
   343
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   344
} /* cmd_getlasterror */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   345
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   346
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   347
static int cmd_getcdromdirs(char *args)
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
    char **rc = PHYSFS_getCdRomDirs();
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
    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
   352
        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
   353
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   354
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   355
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   356
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   357
        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
   358
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   359
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   360
        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
   361
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   362
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   363
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
   364
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   365
} /* cmd_getcdromdirs */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   366
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   367
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   368
static int cmd_getsearchpath(char *args)
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
    char **rc = PHYSFS_getSearchPath();
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
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   373
        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
   374
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   375
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   376
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   377
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   378
        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
   379
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   380
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   381
        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
   382
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   383
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   384
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
   385
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   386
} /* cmd_getcdromdirs */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   387
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   388
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   389
static int cmd_getbasedir(char *args)
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
    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
   392
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   393
} /* cmd_getbasedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   394
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   395
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   396
static int cmd_getuserdir(char *args)
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
    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
   399
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   400
} /* cmd_getuserdir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   401
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   402
1242
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   403
static int cmd_getprefdir(char *args)
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   404
{
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   405
    char *org;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   406
    char *appName;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   407
    char *ptr = args;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   408
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   409
    org = ptr;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   410
    ptr = strchr(ptr, ' '); *ptr = '\0'; ptr++; appName = ptr;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   411
    printf("Pref dir is [%s].\n", PHYSFS_getPrefDir(org, appName));
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   412
    return 1;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   413
} /* cmd_getprefdir */
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   414
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1125
diff changeset
   415
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   416
static int cmd_getwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   417
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   418
    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
   419
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   420
} /* cmd_getwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   421
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   422
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   423
static int cmd_setwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   424
{
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
   425
    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
   426
    {
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
        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
        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
   429
    } /* 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
   430
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   431
    if (PHYSFS_setWriteDir(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   432
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   433
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   434
        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
   435
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
   436
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   437
} /* cmd_setwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   438
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   439
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   440
static int cmd_permitsyms(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   441
{
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
   442
    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
   443
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
    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
   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
        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
        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
   448
    } /* 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
   449
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
    num = atoi(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   451
    PHYSFS_permitSymbolicLinks(num);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   452
    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
   453
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   454
} /* cmd_permitsyms */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   455
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   456
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   457
static int cmd_setbuffer(char *args)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   458
{
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   459
    if (*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
        args++;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   462
        args[strlen(args) - 1] = '\0';
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   463
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   464
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   465
    do_buffer_size = (unsigned int) atoi(args);
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   466
    if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   467
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   468
        printf("Further tests will set a (%lu) size buffer.\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   469
                (unsigned long) do_buffer_size);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   470
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   471
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   472
    else
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
        printf("Further tests will NOT use a buffer.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   475
    } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   476
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
   477
    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   478
} /* cmd_setbuffer */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   479
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   480
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   481
static int cmd_stressbuffer(char *args)
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
    int num;
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
    if (*args == '\"')
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
        args++;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   488
        args[strlen(args) - 1] = '\0';
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   489
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   490
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   491
    num = atoi(args);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   492
    if (num < 0)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   493
        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
   494
    else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   495
    {
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
   496
        PHYSFS_File *f;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   497
        int rndnum;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   498
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   499
        printf("Stress testing with (%d) byte buffer...\n", num);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   500
        f = PHYSFS_openWrite("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   501
        if (f == NULL)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   502
            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
   503
        else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   504
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   505
            int i, j;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   506
            char buf[37];
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   507
            char buf2[37];
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   509
            if (!PHYSFS_setBuffer(f, num))
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
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   512
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   513
                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
   514
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   515
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   516
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   517
            strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789");
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   518
            srand((unsigned int) time(NULL));
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   519
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   520
            for (i = 0; i < 10; i++)
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 (j = 0; j < 10000; j++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   523
                {
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   524
                    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
   525
                    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
   526
                    if (PHYSFS_writeBytes(f, buf, left) != left)
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   527
                    {
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   528
                        printf("PHYSFS_writeBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   529
                        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
   530
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   531
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   532
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   533
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   534
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   535
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   536
                        if (!PHYSFS_flush(f))
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
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   539
                            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
   540
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   541
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   542
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   543
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   544
                    if (PHYSFS_writeBytes(f, buf + left, right) != right)
508
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
                        printf("PHYSFS_writeBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   547
                        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
   548
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   549
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   550
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   551
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   552
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   553
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   554
                        if (!PHYSFS_flush(f))
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
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   557
                            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
   558
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   559
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   560
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   561
                } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   562
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   563
                if (!PHYSFS_flush(f))
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
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   566
                    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
   567
                    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   568
                } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   569
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   570
            } /* for */
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
            if (!PHYSFS_close(f))
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
                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
   575
                return 1;  /* oh well. */
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   576
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   577
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   578
            printf(" ... test file written ...\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   579
            f = PHYSFS_openRead("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   580
            if (f == NULL)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   581
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   582
                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
   583
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   584
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   585
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   586
            if (!PHYSFS_setBuffer(f, num))
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
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   589
                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
   590
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   591
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   592
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   593
            for (i = 0; i < 10; i++)
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 (j = 0; j < 10000; j++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   596
                {
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   597
                    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
   598
                    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
   599
                    if (PHYSFS_readBytes(f, buf2, left) != left)
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   600
                    {
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   601
                        printf("PHYSFS_readBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   602
                        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
   603
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   604
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   605
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   606
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   607
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   608
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   609
                        if (!PHYSFS_flush(f))
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
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   612
                            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
   613
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   614
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   615
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   616
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   617
                    if (PHYSFS_readBytes(f, buf2 + left, right) != right)
508
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
                        printf("PHYSFS_readBytes() failed: %s.\n", PHYSFS_getLastError());
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   620
                        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
   621
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   622
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   623
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   624
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   625
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   626
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   627
                        if (!PHYSFS_flush(f))
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
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   630
                            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
   631
                            return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   632
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   633
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   634
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   635
                    if (memcmp(buf, buf2, 36) != 0)
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
                        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
   638
                        printf("wanted: [");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   639
                        for (i = 0; i < 36; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   640
                            printf("%c", buf[i]);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   641
                        printf("]\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   642
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   643
                        printf("   got: [");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   644
                        for (i = 0; i < 36; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   645
                            printf("%c", buf2[i]);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   646
                        printf("]\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   647
                        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
   648
                        return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   649
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   650
                } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   651
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   652
                if (!PHYSFS_flush(f))
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
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   655
                    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
   656
                    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   657
                } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   658
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   659
            } /* for */
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
            printf(" ... test file read ...\n");
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
            if (!PHYSFS_eof(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   664
                printf("PHYSFS_eof() returned true! That's wrong.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   665
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   666
            if (!PHYSFS_close(f))
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
                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
   669
                return 1;  /* oh well. */
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   670
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   671
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   672
            PHYSFS_delete("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   673
            printf("stress test completed successfully.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   674
        } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   675
    } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   676
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
   677
    return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   678
} /* cmd_stressbuffer */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   679
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   680
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   681
static int cmd_setsaneconfig(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   682
{
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   683
    char *org;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   684
    char *appName;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   685
    char *arcExt;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   686
    int inclCD;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   687
    int arcsFirst;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   688
    char *ptr = args;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   689
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   690
        /* ugly. */
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   691
    org = ptr;
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   692
    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
   693
    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
   694
    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
   695
    arcsFirst = atoi(ptr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   696
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   697
    if (strcmp(arcExt, "!") == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   698
        arcExt = NULL;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   699
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   700
    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
   701
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   702
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   703
        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
   704
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
   705
    return 1;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   706
} /* cmd_setsaneconfig */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   707
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   708
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   709
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
   710
{
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
   711
    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
   712
    {
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
        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
        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
   715
    } /* 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
   716
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   717
    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
   718
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   719
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   720
        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
   721
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
   722
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   723
} /* cmd_mkdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   724
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   725
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   726
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
   727
{
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
   728
    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
   729
    {
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
        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
        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
   732
    } /* 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
   733
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   734
    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
   735
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   736
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   737
        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
   738
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
   739
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   740
} /* cmd_delete */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   741
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   742
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   743
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
   744
{
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
   745
    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
   746
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
    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
   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
        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
        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
   751
    } /* 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
   752
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
    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
   754
    if (rc)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   755
        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
   756
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   757
        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
   758
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
   759
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   760
} /* cmd_getrealdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   761
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   762
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   763
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
   764
{
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
   765
    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
   766
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
    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
   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
        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
        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
   771
    } /* 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
   772
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
    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
   774
    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
   775
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   776
} /* cmd_exists */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   777
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   778
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   779
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
   780
{
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   781
    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
   782
    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
   783
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
    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
   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
        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
        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
   788
    } /* 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
   789
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   790
    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
   791
    if (rc)
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   792
        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
   793
    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
   794
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   795
} /* cmd_isdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   796
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   797
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   798
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
   799
{
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   800
    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
   801
    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
   802
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
    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
   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
        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
        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
   807
    } /* 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
   808
1125
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   809
    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
   810
    if (rc)
bcff76dbd9fd Removed isDirectory, isSymLink and exists methods from internal code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1123
diff changeset
   811
        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
   812
    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
   813
    return 1;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   814
} /* cmd_issymlink */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   815
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   816
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   817
static int cmd_cat(char *args)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   818
{
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
   819
    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
   820
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
   821
    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
   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
        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
        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
   825
    } /* 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
   826
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
    f = PHYSFS_openRead(args);
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   828
    if (f == NULL)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   829
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   830
    else
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   831
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   832
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   833
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   834
            if (!PHYSFS_setBuffer(f, 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
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   837
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   838
                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
   839
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   840
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   841
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   842
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   843
        while (1)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   844
        {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   845
            char buffer[128];
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   846
            PHYSFS_sint64 rc;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   847
            PHYSFS_sint64 i;
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   848
            rc = PHYSFS_readBytes(f, buffer, sizeof (buffer));
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   849
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   850
            for (i = 0; i < rc; i++)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   851
                fputc((int) buffer[i], stdout);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   852
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   853
            if (rc < sizeof (buffer))
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
                printf("\n\n");
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   856
                if (!PHYSFS_eof(f))
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   857
                {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   858
                    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
   859
                           PHYSFS_getLastError());
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   860
                } /* if */
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   861
                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
   862
                return 1;
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   863
            } /* if */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   864
        } /* while */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   865
    } /* else */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   866
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
   867
    return 1;
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   868
} /* cmd_cat */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   869
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   870
1063
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   871
#define CRC32_BUFFERSIZE 512
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   872
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
   873
{
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   874
    PHYSFS_File *f;
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
    if (*args == '\"')
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
        args++;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   879
        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
   880
    } /* if */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   881
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   882
    f = PHYSFS_openRead(args);
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   883
    if (f == NULL)
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   884
        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
   885
    else
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   886
    {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   887
        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
   888
        PHYSFS_uint32 crc = -1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   889
        PHYSFS_sint64 bytesread;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   890
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   891
        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
   892
        {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   893
            PHYSFS_uint32 i, bit;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   894
            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
   895
            {
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   896
                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
   897
                    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
   898
            } /* for */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   899
        } /* while */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   900
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   901
        if (bytesread < 0)
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
            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
   904
                   PHYSFS_getLastError());
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   905
            return 1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   906
        } /* if */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   907
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   908
        PHYSFS_close(f);
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
        crc ^= -1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   911
        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
   912
    } /* else */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   913
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   914
    return 1;
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   915
} /* cmd_crc32 */
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   916
efb4c91b8dd6 Added crc32 command to test_physfs.c (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   917
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
   918
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
   919
{
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
   920
    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
   921
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
   922
    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
   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
        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
        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
   926
    } /* 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
   927
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
    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
   929
    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
   930
        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
   931
    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
   932
    {
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
        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
   934
        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
   935
            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
   936
        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
   937
            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
   938
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
        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
   940
    } /* 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
   941
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
   942
    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
   943
} /* 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
   944
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
#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
   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
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
   948
{
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
   949
    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
   950
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
   951
    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
   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
        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
        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
   955
    } /* 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
   956
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
    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
   958
    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
   959
        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
   960
    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
   961
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   962
        size_t bw;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   963
        PHYSFS_sint64 rc;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   964
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   965
        if (do_buffer_size)
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 (!PHYSFS_setBuffer(f, 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
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   970
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   971
                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
   972
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   973
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   974
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   975
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   976
        bw = strlen(WRITESTR);
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
   977
        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
   978
        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
   979
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   980
            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
   981
                   (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
   982
        } /* 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
   983
        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
   984
        {
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
            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
   986
        } /* 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
   987
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
        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
   989
    } /* 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
   990
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
   991
    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
   992
} /* 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
   993
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
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
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
   996
{
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
   997
    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
   998
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
   999
    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
  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
        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
        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
  1003
    } /* 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
  1004
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
    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
  1006
    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
  1007
        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
  1008
    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
  1009
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1010
        size_t bw;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1011
        PHYSFS_sint64 rc;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1012
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1013
        if (do_buffer_size)
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 (!PHYSFS_setBuffer(f, 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
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1018
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1019
                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
  1020
                return 1;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1021
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1022
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1023
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
  1024
        bw = strlen(WRITESTR);
1102
c7bacc6cf152 Updated test_physfs.c to not use deprecated functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1063
diff changeset
  1025
        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
  1026
        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
  1027
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
  1028
            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
  1029
                   (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
  1030
        } /* 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
  1031
        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
  1032
        {
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
            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
  1034
        } /* 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
  1035
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
        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
  1037
    } /* 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
  1038
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
  1039
    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
  1040
} /* 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
  1041
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
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1043
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
  1044
{
1263
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1045
    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
  1046
        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
  1047
    else
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1048
    {
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1049
        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
  1050
        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
  1051
        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
  1052
    } /* else */
3d5ed1d03b34 test_physfs's "stat" command now respects unknown file times (-1).
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
  1053
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1054
    modstr[strsize-1] = '\0';
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1055
    return modstr;
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1056
} /* modTimeToStr */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1057
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1058
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1059
static int cmd_getlastmodtime(char *args)
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1060
{
1105
a81d0326300f Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1102
diff changeset
  1061
    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
  1062
    if (!PHYSFS_stat(args, &statbuf))
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1063
        printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1064
    else
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1065
    {
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1066
        char modstr[64];
1105
a81d0326300f Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1102
diff changeset
  1067
        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
  1068
        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
  1069
    } /* else */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1070
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
  1071
    return 1;
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1072
} /* cmd_getLastModTime */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1073
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1074
static int cmd_stat(char *args)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1075
{
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1076
    PHYSFS_Stat stat;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1077
    char timestring[65];
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1078
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1079
    if (*args == '\"')
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
        args++;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1082
        args[strlen(args) - 1] = '\0';
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1083
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1084
1106
94c3669d0311 Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1105
diff changeset
  1085
    if(!PHYSFS_stat(args, &stat))
1054
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1086
    {
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1087
        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
  1088
        return 1;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1089
    } /* if */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1090
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1091
    printf("Filename: %s\n", args);
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1092
    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
  1093
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1094
    if(stat.filetype == PHYSFS_FILETYPE_REGULAR)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1095
        printf("Type: File\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1096
    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
  1097
        printf("Type: Directory\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_SYMLINK)
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1099
        printf("Type: Symlink\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1100
    else
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1101
        printf("Type: Unknown\n");
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1102
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1103
    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
  1104
    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
  1105
    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
  1106
    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
  1107
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1108
    return 1;
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1109
} /* cmd_filelength */
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1110
57f4af811ffb THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents: 1027
diff changeset
  1111
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
  1112
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1113
/* 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
  1114
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
  1115
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1116
    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
  1117
    int in_quotes = 0;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1118
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1119
    if (str != NULL)
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
        for (; *str != '\0'; str++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1122
        {
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
  1123
            if (*str == '\"')
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
  1124
                in_quotes = !in_quotes;
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gord