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