test/test_physfs.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 23 Jul 2005 23:00:08 +0000
branchstable-1.0
changeset 732 c28798929210
parent 625 60b5f566a258
child 964 455ef8c1ebf0
permissions -rw-r--r--
Version bump for test program.
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
 *
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
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
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
     9
#if HAVE_CONFIG_H
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    10
#  include <config.h>
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    11
#endif
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    12
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <stdio.h>
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    14
#include <stdlib.h>
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    15
#include <errno.h>
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    16
#include <string.h>
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    17
164
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    18
#if (defined __MWERKS__)
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    19
#include <SIOUX.h>
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    20
#endif
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    21
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    22
#if (defined PHYSFS_HAVE_READLINE)
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    23
#include <unistd.h>
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    24
#include <readline/readline.h>
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
    25
#include <readline/history.h>
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    26
#endif
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    27
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
    28
#include <time.h>
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
    29
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#include "physfs.h"
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
625
60b5f566a258 Last minute changes, fixes, and build system updates for 1.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
    32
#define TEST_VERSION_MAJOR  1
60b5f566a258 Last minute changes, fixes, and build system updates for 1.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
    33
#define TEST_VERSION_MINOR  0
732
c28798929210 Version bump for test program.
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
    34
#define TEST_VERSION_PATCH  1
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    36
static FILE *history_file = NULL;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
    37
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
    38
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    39
static void output_versions(void)
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
{
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    PHYSFS_Version compiled;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    PHYSFS_Version linked;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    PHYSFS_VERSION(&compiled);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    PHYSFS_getLinkedVersion(&linked);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    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
    48
           " 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
    49
           " 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
    50
            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
    51
            (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
    52
            (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
    53
} /* output_versions */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    56
static void output_archivers(void)
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
{
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    const PHYSFS_ArchiveInfo **i;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    printf("Supported archive types:\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    if (*rc == NULL)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
        printf(" * Apparently, NONE!\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    else
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        for (i = rc; *i != NULL; i++)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
            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
    69
                    (*i)->extension, (*i)->description,
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
                    (*i)->author, (*i)->url);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        } /* for */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    } /* else */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    73
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    74
    printf("\n");
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
} /* output_archivers */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    78
static int cmd_quit(char *args)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    79
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    80
    return(0);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    81
} /* cmd_quit */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    82
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    83
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    84
static int cmd_init(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    85
{
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
    86
    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
    87
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    88
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    89
        args[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
    90
    } /* 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
    91
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    92
    if (PHYSFS_init(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    93
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    94
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    95
        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
    96
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    97
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    98
} /* cmd_init */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    99
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   100
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   101
static int cmd_deinit(char *args)
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
    if (PHYSFS_deinit())
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   104
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   105
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   106
        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
   107
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   108
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   109
} /* cmd_deinit */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   110
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   111
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   112
static int cmd_addarchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   113
{
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
   114
    char *ptr = strrchr(args, ' ');
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   115
    int appending = atoi(ptr + 1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   116
    *ptr = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   117
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
   118
    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
   119
    {
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   120
        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
   121
        *(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
   122
    } /* 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
   123
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
    /*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
   125
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   126
    if (PHYSFS_addToSearchPath(args, appending))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   127
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   128
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   129
        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
   130
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   131
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   132
} /* cmd_addarchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   133
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   134
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   135
static int cmd_removearchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   136
{
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
   137
    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
   138
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   139
        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
   140
        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
   141
    } /* 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
   142
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   143
    if (PHYSFS_removeFromSearchPath(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   144
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   145
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   146
        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
   147
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   148
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   149
} /* cmd_removearchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   150
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   151
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   152
static int cmd_enumerate(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   153
{
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
   154
    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
   155
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   156
    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
   157
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   158
        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
   159
        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
   160
    } /* 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
   161
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   162
    rc = PHYSFS_enumerateFiles(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   163
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   164
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   165
        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
   166
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   167
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   168
        int file_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   169
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   170
        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
   171
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   172
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   173
        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
   174
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   175
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   176
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   177
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   178
} /* cmd_enumerate */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   179
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   180
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   181
static int cmd_getdirsep(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   182
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   183
    printf("Directory separator is [%s].\n", PHYSFS_getDirSeparator());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   184
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   185
} /* cmd_getdirsep */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   186
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   187
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   188
static int cmd_getlasterror(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   189
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   190
    printf("last error is [%s].\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   191
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   192
} /* cmd_getlasterror */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   193
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   194
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   195
static int cmd_getcdromdirs(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   196
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   197
    char **rc = PHYSFS_getCdRomDirs();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   198
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   199
    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
   200
        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
   201
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   202
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   203
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   204
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   205
        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
   206
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   207
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   208
        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
   209
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   210
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   211
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   212
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   213
} /* cmd_getcdromdirs */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   214
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   215
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   216
static int cmd_getsearchpath(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   217
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   218
    char **rc = PHYSFS_getSearchPath();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   219
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   220
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   221
        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
   222
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   223
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   224
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   225
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   226
        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
   227
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   228
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   229
        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
   230
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   231
    } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   232
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   233
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   234
} /* cmd_getcdromdirs */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   235
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   236
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   237
static int cmd_getbasedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   238
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   239
    printf("Base dir is [%s].\n", PHYSFS_getBaseDir());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   240
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   241
} /* cmd_getbasedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   242
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   243
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   244
static int cmd_getuserdir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   245
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   246
    printf("User dir is [%s].\n", PHYSFS_getUserDir());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   247
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   248
} /* cmd_getuserdir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   249
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   250
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   251
static int cmd_getwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   252
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   253
    printf("Write dir is [%s].\n", PHYSFS_getWriteDir());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   254
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   255
} /* cmd_getwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   256
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   257
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   258
static int cmd_setwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   259
{
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
   260
    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
   261
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   262
        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
   263
        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
   264
    } /* 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
   265
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   266
    if (PHYSFS_setWriteDir(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   267
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   268
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   269
        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
   270
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   271
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   272
} /* cmd_setwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   273
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   274
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   275
static int cmd_permitsyms(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   276
{
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
   277
    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
   278
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   279
    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
   280
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   281
        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
   282
        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
   283
    } /* 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
   284
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   285
    num = atoi(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   286
    PHYSFS_permitSymbolicLinks(num);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   287
    printf("Symlinks are now %s.\n", num ? "permitted" : "forbidden");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   288
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   289
} /* cmd_permitsyms */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   290
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   291
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   292
static int cmd_setbuffer(char *args)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   293
{
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   294
    if (*args == '\"')
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   295
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   296
        args++;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   297
        args[strlen(args) - 1] = '\0';
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   298
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   299
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   300
    do_buffer_size = (unsigned int) atoi(args);
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   301
    if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   302
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   303
        printf("Further tests will set a (%lu) size buffer.\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   304
                (unsigned long) do_buffer_size);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   305
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   306
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   307
    else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   308
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   309
        printf("Further tests will NOT use a buffer.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   310
    } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   311
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   312
    return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   313
} /* cmd_setbuffer */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   314
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   315
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   316
static int cmd_stressbuffer(char *args)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   317
{
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   318
    int num;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   319
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   320
    if (*args == '\"')
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   321
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   322
        args++;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   323
        args[strlen(args) - 1] = '\0';
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   324
    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   325
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   326
    num = atoi(args);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   327
    if (num < 0)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   328
        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
   329
    else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   330
    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   331
        PHYSFS_file *f;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   332
        int rndnum;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   333
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   334
        printf("Stress testing with (%d) byte buffer...\n", num);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   335
        f = PHYSFS_openWrite("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   336
        if (f == NULL)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   337
            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
   338
        else
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   339
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   340
            int i, j;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   341
            char buf[37];
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   342
            char buf2[37];
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   343
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   344
            if (!PHYSFS_setBuffer(f, num))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   345
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   346
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   347
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   348
                PHYSFS_delete("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   349
                return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   350
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   351
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   352
            strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789");
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   353
            srand((unsigned int) time(NULL));
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   354
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   355
            for (i = 0; i < 10; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   356
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   357
                for (j = 0; j < 10000; j++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   358
                {
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   359
                    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
   360
                    PHYSFS_uint32 left = 36 - right;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   361
                    if (PHYSFS_write(f, buf, left, 1) != 1)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   362
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   363
                        printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   364
                        PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   365
                        return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   366
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   367
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   368
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   369
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   370
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   371
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   372
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   373
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   374
                            PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   375
                            return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   376
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   377
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   378
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   379
                    if (PHYSFS_write(f, buf + left, 1, right) != right)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   380
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   381
                        printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   382
                        PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   383
                        return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   384
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   385
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   386
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   387
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   388
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   389
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   390
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   391
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   392
                            PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   393
                            return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   394
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   395
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   396
                } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   397
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   398
                if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   399
                {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   400
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   401
                    PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   402
                    return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   403
                } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   404
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   405
            } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   406
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   407
            if (!PHYSFS_close(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   408
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   409
                printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   410
                return(1);  /* oh well. */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   411
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   412
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   413
            printf(" ... test file written ...\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   414
            f = PHYSFS_openRead("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   415
            if (f == NULL)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   416
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   417
                printf("Failed to reopen stress file for reading: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   418
                return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   419
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   420
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   421
            if (!PHYSFS_setBuffer(f, num))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   422
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   423
                printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   424
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   425
                return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   426
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   427
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   428
            for (i = 0; i < 10; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   429
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   430
                for (j = 0; j < 10000; j++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   431
                {
538
8752e3c0dbf9 Now compiles on CodeWarrior 6 for MacOS Classic again.
Ryan C. Gordon <icculus@icculus.org>
parents: 528
diff changeset
   432
                    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
   433
                    PHYSFS_uint32 left = 36 - right;
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   434
                    if (PHYSFS_read(f, buf2, left, 1) != 1)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   435
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   436
                        printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   437
                        PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   438
                        return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   439
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   440
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   441
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   442
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   443
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   444
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   445
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   446
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   447
                            PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   448
                            return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   449
                        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   450
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   451
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   452
                    if (PHYSFS_read(f, buf2 + left, 1, right) != right)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   453
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   454
                        printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   455
                        PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   456
                        return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   457
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   458
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   459
                    rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   460
                    if (rndnum == 42)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   461
                    {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   462
                        if (!PHYSFS_flush(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   463
                        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   464
                            printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   465
                            PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   466
                            return(1);
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
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   469
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   470
                    if (memcmp(buf, buf2, 36) != 0)
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("readback is mismatched on iterations (%d, %d).\n", i, j);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   473
                        printf("wanted: [");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   474
                        for (i = 0; i < 36; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   475
                            printf("%c", buf[i]);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   476
                        printf("]\n");
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("   got: [");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   479
                        for (i = 0; i < 36; i++)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   480
                            printf("%c", buf2[i]);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   481
                        printf("]\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   482
                        PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   483
                        return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   484
                    } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   485
                } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   486
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   487
                if (!PHYSFS_flush(f))
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
                    printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   490
                    PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   491
                    return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   492
                } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   493
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   494
            } /* for */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   495
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   496
            printf(" ... test file read ...\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   497
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   498
            if (!PHYSFS_eof(f))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   499
                printf("PHYSFS_eof() returned true! That's wrong.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   500
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   501
            if (!PHYSFS_close(f))
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("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   504
                return(1);  /* oh well. */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   505
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   506
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   507
            PHYSFS_delete("test.txt");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   508
            printf("stress test completed successfully.\n");
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   509
        } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   510
    } /* else */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   511
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   512
    return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   513
} /* cmd_stressbuffer */
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
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   516
static int cmd_setsaneconfig(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   517
{
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   518
    char *org;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   519
    char *appName;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   520
    char *arcExt;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   521
    int inclCD;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   522
    int arcsFirst;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   523
    char *ptr = args;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   524
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   525
        /* ugly. */
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   526
    org = ptr;
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   527
    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
   528
    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
   529
    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
   530
    arcsFirst = atoi(ptr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   531
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   532
    if (strcmp(arcExt, "!") == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   533
        arcExt = NULL;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   534
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   535
    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
   536
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   537
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   538
        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
   539
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   540
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   541
} /* cmd_setsaneconfig */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   542
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   543
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   544
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
   545
{
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
   546
    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
   547
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   548
        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
   549
        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
   550
    } /* 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
   551
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   552
    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
   553
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   554
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   555
        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
   556
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   557
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   558
} /* cmd_mkdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   559
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   560
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   561
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
   562
{
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
   563
    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
   564
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   565
        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
   566
        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
   567
    } /* 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
   568
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   569
    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
   570
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   571
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   572
        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
   573
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   574
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   575
} /* cmd_delete */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   576
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   577
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   578
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
   579
{
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
   580
    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
   581
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   582
    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
   583
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   584
        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
   585
        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
   586
    } /* 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
   587
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   588
    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
   589
    if (rc)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   590
        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
   591
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   592
        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
   593
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   594
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   595
} /* cmd_getrealdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   596
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   597
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   598
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
   599
{
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
   600
    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
   601
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   602
    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
   603
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   604
        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
   605
        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
   606
    } /* 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
   607
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   608
    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
   609
    printf("File %sexists.\n", rc ? "" : "does not ");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   610
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   611
} /* cmd_exists */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   612
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   613
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   614
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
   615
{
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
   616
    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
   617
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   618
    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
   619
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   620
        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
   621
        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
   622
    } /* 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
   623
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   624
    rc = PHYSFS_isDirectory(args);
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   625
    printf("File %s a directory.\n", rc ? "is" : "is NOT");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   626
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   627
} /* cmd_isdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   628
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   629
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   630
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
   631
{
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
   632
    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
   633
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   634
    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
   635
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   636
        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
   637
        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
   638
    } /* 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
   639
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   640
    rc = PHYSFS_isSymbolicLink(args);
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   641
    printf("File %s a symlink.\n", rc ? "is" : "is NOT");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   642
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   643
} /* cmd_issymlink */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   644
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   645
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   646
static int cmd_cat(char *args)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   647
{
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
   648
    PHYSFS_file *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
   649
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   650
    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
   651
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   652
        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
   653
        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
   654
    } /* 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
   655
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   656
    f = PHYSFS_openRead(args);
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   657
    if (f == NULL)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   658
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   659
    else
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   660
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   661
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   662
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   663
            if (!PHYSFS_setBuffer(f, do_buffer_size))
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("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   666
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   667
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   668
                return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   669
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   670
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   671
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   672
        while (1)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   673
        {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   674
            char buffer[128];
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   675
            PHYSFS_sint64 rc;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   676
            PHYSFS_sint64 i;
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   677
            rc = PHYSFS_read(f, buffer, 1, sizeof (buffer));
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   678
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   679
            for (i = 0; i < rc; i++)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   680
                fputc((int) buffer[i], stdout);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   681
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   682
            if (rc < sizeof (buffer))
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   683
            {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   684
                printf("\n\n");
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   685
                if (!PHYSFS_eof(f))
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   686
                {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   687
                    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
   688
                           PHYSFS_getLastError());
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   689
                } /* if */
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   690
                PHYSFS_close(f);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   691
                return(1);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   692
            } /* if */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   693
        } /* while */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   694
    } /* else */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   695
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   696
    return(1);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   697
} /* cmd_cat */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   698
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   699
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
   700
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
   701
{
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   702
    PHYSFS_file *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
   703
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   704
    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
   705
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   706
        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
   707
        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
   708
    } /* 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
   709
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   710
    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
   711
    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
   712
        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
   713
    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
   714
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   715
        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
   716
        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
   717
            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
   718
        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
   719
            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
   720
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   721
        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
   722
    } /* 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
   723
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   724
    return(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
   725
} /* 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
   726
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   727
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   728
#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
   729
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   730
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
   731
{
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   732
    PHYSFS_file *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
   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
    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
   735
    {
d826bf2c38c8 More hacks to 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
        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
   737
        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
   738
    } /* 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
   739
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   740
    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
   741
    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
   742
        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
   743
    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
   744
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   745
        size_t bw;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   746
        PHYSFS_sint64 rc;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   747
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   748
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   749
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   750
            if (!PHYSFS_setBuffer(f, do_buffer_size))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   751
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   752
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   753
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   754
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   755
                return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   756
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   757
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   758
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   759
        bw = strlen(WRITESTR);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   760
        rc = PHYSFS_write(f, WRITESTR, 1, bw);
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   761
        if (rc != bw)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   762
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   763
            printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n",
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   764
                   (int) rc, (int) bw, PHYSFS_getLastError());
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   765
        } /* 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
   766
        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
   767
        {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   768
            printf("Successful.\n");
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   769
        } /* 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
   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
        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
   772
    } /* 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
   773
d826bf2c38c8 More hacks to 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
    return(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
   775
} /* cmd_append */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   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
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   778
static int cmd_write(char *args)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   779
{
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   780
    PHYSFS_file *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
   781
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   782
    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
   783
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   784
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   785
        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
   786
    } /* 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
   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
    f = PHYSFS_openWrite(args);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   789
    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
   790
        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
   791
    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
   792
    {
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   793
        size_t bw;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   794
        PHYSFS_sint64 rc;
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   795
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   796
        if (do_buffer_size)
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   797
        {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   798
            if (!PHYSFS_setBuffer(f, do_buffer_size))
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   799
            {
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   800
                printf("failed to set file buffer. Reason: [%s].\n",
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   801
                        PHYSFS_getLastError());
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   802
                PHYSFS_close(f);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   803
                return(1);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   804
            } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   805
        } /* if */
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   806
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   807
        bw = strlen(WRITESTR);
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   808
        rc = PHYSFS_write(f, WRITESTR, 1, bw);
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   809
        if (rc != bw)
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   810
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   811
            printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n",
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   812
                   (int) rc, (int) bw, PHYSFS_getLastError());
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   813
        } /* 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
   814
        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
   815
        {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   816
            printf("Successful.\n");
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   817
        } /* 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
   818
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   819
        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
   820
    } /* 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
   821
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   822
    return(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
   823
} /* cmd_write */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   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
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   826
static void modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   827
{
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   828
    time_t t = (time_t) modtime;
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   829
    char *str = ctime(&t);
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   830
    strncpy(modstr, str, strsize);
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   831
    modstr[strsize-1] = '\0';
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   832
} /* modTimeToStr */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   833
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   834
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   835
static int cmd_getlastmodtime(char *args)
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   836
{
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   837
    PHYSFS_sint64 rc = PHYSFS_getLastModTime(args);
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   838
    if (rc == -1)
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   839
        printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   840
    else
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   841
    {
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   842
        char modstr[64];
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   843
        modTimeToStr(rc, modstr, sizeof (modstr));
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   844
        printf("Last modified: %s (%ld).\n", modstr, (long) rc);
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   845
    } /* else */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   846
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   847
    return(1);
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   848
} /* cmd_getLastModTime */
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   849
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   850
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   851
/* must have spaces trimmed prior to this call. */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   852
static int count_args(const char *str)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   853
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   854
    int retval = 0;
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   855
    int in_quotes = 0;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   856
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   857
    if (str != NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   858
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   859
        for (; *str != '\0'; str++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   860
        {
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
   861
            if (*str == '\"')
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   862
                in_quotes = !in_quotes;
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
   863
            else if ((*str == ' ') && (!in_quotes))
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   864
                retval++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   865
        } /* for */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   866
        retval++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   867
    } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   868
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   869
    return(retval);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   870
} /* count_args */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   871
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   872
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   873
static int cmd_help(char *args);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   874
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   875
typedef struct
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   876
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   877
    const char *cmd;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   878
    int (*func)(char *args);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   879
    int argcount;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   880
    const char *usage;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   881
} command_info;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   882
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   883
static const command_info commands[] =
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   884
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   885
    { "quit",           cmd_quit,           0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   886
    { "q",              cmd_quit,           0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   887
    { "help",           cmd_help,           0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   888
    { "init",           cmd_init,           1, "<argv0>"                    },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   889
    { "deinit",         cmd_deinit,         0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   890
    { "addarchive",     cmd_addarchive,     2, "<archiveLocation> <append>" },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   891
    { "removearchive",  cmd_removearchive,  1, "<archiveLocation>"          },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   892
    { "enumerate",      cmd_enumerate,      1, "<dirToEnumerate>"           },
374
5b75e3dd2cdd Made "ls" an alias of "enumerate", since I keep typing it without thinking. :)
Ryan C. Gordon <icculus@icculus.org>
parents: 323
diff changeset
   893
    { "ls",             cmd_enumerate,      1, "<dirToEnumerate>"           },
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   894
    { "getlasterror",   cmd_getlasterror,   0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   895
    { "getdirsep",      cmd_getdirsep,      0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   896
    { "getcdromdirs",   cmd_getcdromdirs,   0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   897
    { "getsearchpath",  cmd_getsearchpath,  0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   898
    { "getbasedir",     cmd_getbasedir,     0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   899
    { "getuserdir",     cmd_getuserdir,     0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   900
    { "getwritedir",    cmd_getwritedir,    0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   901
    { "setwritedir",    cmd_setwritedir,    1, "<newWriteDir>"              },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   902
    { "permitsymlinks", cmd_permitsyms,     1, "<1or0>"                     },
495
51ca637c3a28 Fixed setsaneconfig command.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   903
    { "setsaneconfig",  cmd_setsaneconfig,  5, "<org> <appName> <arcExt> <includeCdRoms> <archivesFirst>" },
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   904
    { "mkdir",          cmd_mkdir,          1, "<dirToMk>"                  },
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   905
    { "delete",         cmd_delete,         1, "<dirToDelete>"              },
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   906
    { "getrealdir",     cmd_getrealdir,     1, "<fileToFind>"               },
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   907
    { "exists",         cmd_exists,         1, "<fileToCheck>"              },
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   908
    { "isdir",          cmd_isdir,          1, "<fileToCheck>"              },
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   909
    { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   910
    { "cat",            cmd_cat,            1, "<fileToCat>"                },
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
   911
    { "filelength",     cmd_filelength,     1, "<fileToCheck>"              },
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   912
    { "append",         cmd_append,         1, "<fileToAppend>"             },
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   913
    { "write",          cmd_write,          1, "<fileToCreateOrTrash>"      },
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   914
    { "getlastmodtime", cmd_getlastmodtime, 1, "<fileToExamine>"            },
508
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   915
    { "setbuffer",      cmd_setbuffer,      1, "<bufferSize>"               },
0e75524a96af Added buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 500
diff changeset
   916
    { "stressbuffer",   cmd_stressbuffer,   1, "<bufferSize>"               },
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   917
    { NULL,             NULL,              -1, NULL                         }
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   918
};
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   919
244
c05afa0425a4 Added getlastmodtime command.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   920
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   921
static void output_usage(const char *intro, const command_info *cmdinfo)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   922
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   923
    if (cmdinfo->argcount == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   924
        printf("%s \"%s\" (no arguments)\n", intro, cmdinfo->cmd);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   925
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   926
        printf("%s \"%s %s\"\n", intro, cmdinfo->cmd, cmdinfo->usage);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   927
} /* output_usage */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   928
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   929
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   930
static int cmd_help(char *args)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   931
{
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   932
    const command_info *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   933
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   934
    printf("Commands:\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   935
    for (i = commands; i->cmd != NULL; i++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   936
        output_usage("  -", i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   937
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   938
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   939
} /* output_cmd_help */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   940
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   941
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   942
static void trim_command(const char *orig, char *copy)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   943
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   944
    const char *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   945
    char *writeptr = copy;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   946
    int spacecount = 0;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   947
    int have_first = 0;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   948
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   949
    for (i = orig; *i != '\0'; i++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   950
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   951
        if (*i == ' ')
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   952
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   953
            if ((*(i + 1) != ' ') && (*(i + 1) != '\0'))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   954
            {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   955
                if ((have_first) && (!spacecount))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   956
                {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   957
                    spacecount++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   958
                    *writeptr = ' ';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   959
                    writeptr++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   960
                } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   961
            } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   962
        } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   963
        else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   964
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   965
            have_first = 1;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   966
            spacecount = 0;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   967
            *writeptr = *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   968
            writeptr++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   969
        } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   970
    } /* for */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   971
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   972
    *writeptr = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   973
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   974
    /*
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   975
    printf("\n command is [%s].\n", copy);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   976
    */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   977
} /* trim_command */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   978
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   979
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   980
static int process_command(char *complete_cmd)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   981
{
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   982
    const command_info *i;
500
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   983
    char *cmd_copy;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   984
    char *args;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   985
    int rc = 1;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   986
500
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   987
    if (complete_cmd == NULL)  /* can happen if user hits CTRL-D, etc. */
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   988
    {
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   989
        printf("\n");
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   990
        return(0);
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   991
    } /* if */
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   992
6de777c231e3 Now handles readline() returning NULL correctly (user hits CTRL-D, etc).
Ryan C. Gordon <icculus@icculus.org>
parents: 495
diff changeset
   993
    cmd_copy = malloc(strlen(complete_cmd) + 1);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   994
    if (cmd_copy == NULL)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   995
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   996
        printf("\n\n\nOUT OF MEMORY!\n\n\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   997
        return(0);
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   998
    } /* if */
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   999
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1000
    trim_command(complete_cmd, cmd_copy);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1001
    args = strchr(cmd_copy, ' ');
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1002
    if (args != NULL)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1003
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1004
        *args = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1005
        args++;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1006
    } /* else */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1007
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1008
    if (cmd_copy[0] != '\0')
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1009
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1010
        for (i = commands; i->cmd != NULL; i++)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1011
        {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1012
            if (strcmp(i->cmd, cmd_copy) == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1013
            {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1014
                if ((i->argcount >= 0) && (count_args(args) != i->argcount))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1015
                    output_usage("usage:", i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1016
                else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1017
                    rc = i->func(args);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1018
                break;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1019
            } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1020
        } /* for */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1021
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1022
        if (i->cmd == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1023
            printf("Unknown command. Enter \"help\" for instructions.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1024
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
  1025
#if (defined PHYSFS_HAVE_READLINE)
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1026
        add_history(complete_cmd);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1027
        if (history_file)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1028
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1029
            fprintf(history_file, "%s\n", complete_cmd);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1030
            fflush(history_file);
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1031
        } /* if */
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
  1032
#endif
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
  1033
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1034
    } /* if */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1035
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1036
    free(cmd_copy);
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1037
    return(rc);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1038
} /* process_command */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1039
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1040
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1041
static void open_history_file(void)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1042
{
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
  1043
#if (defined PHYSFS_HAVE_READLINE)
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
  1044
#if 0
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1045
    const char *envr = getenv("TESTPHYSFS_HISTORY");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1046
    if (!envr)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1047
        return;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
  1048
#else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
  1049
    char envr[256];
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
  1050
    strcpy(envr, PHYSFS_getUserDir());
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
  1051
    strcat(envr, ".testphys_history");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
  1052
#endif
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1053
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1054
    if (access(envr, F_OK) == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1055
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1056
        char buf[512];
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1057
        FILE *f = fopen(envr, "r");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1058
        if (!f)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1059
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1060
            printf("\n\n"
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1061
                   "Could not open history file [%s] for reading!\n"
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1062
                   "  Will not have past history available.\n\n",
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1063
                    envr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1064
            return;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1065
        } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1066
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1067
        do
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1068
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1069
            fgets(buf, sizeof (buf), f);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1070
            if (buf[strlen(buf) - 1] == '\n')
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1071
                buf[strlen(buf) - 1] = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1072
            add_history(buf);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1073
        } while (!feof(f));
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1074
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1075
        fclose(f);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1076
    } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1077
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1078
    history_file = fopen(envr, "ab");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1079
    if (!history_file)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1080
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1081
        printf("\n\n"
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1082
               "Could not open history file [%s] for appending!\n"
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1083
               "  Will not be able to record this session's history.\n\n",
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1084
                envr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1085
    } /* if */
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
  1086
#endif
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1087
} /* open_history_file */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1088
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1089
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1090
int main(int argc, char **argv)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1091
{
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1092
    char *buf = NULL;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1093
    int rc = 0;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1094
164
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1095
#if (defined __MWERKS__)
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1096
    extern tSIOUXSettings SIOUXSettings;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1097
    SIOUXSettings.asktosaveonclose = 0;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1098
    SIOUXSettings.autocloseonquit = 1;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1099
    SIOUXSettings.rows = 40;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1100
    SIOUXSettings.columns = 120;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1101
#endif
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
  1102
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1103
    printf("\n");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1104
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1105
    if (!PHYSFS_init(argv[0]))
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1106
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1107
        printf("PHYSFS_init() failed!\n  reason: %s.\n", PHYSFS_getLastError());
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1108
        return(1);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1109
    } /* if */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1110
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1111
    output_versions();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1112
    output_archivers();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1113
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1114
    open_history_file();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
  1115
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1116
    printf("Enter commands. Enter \"help\" for instructions.\n");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1117
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1118
    do
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1119
    {
214
19846c18071b Initial autoconf support.
Ryan C. Gordon <icculus@icculus.org>
parents: 191
diff changeset
  1120
#if (defined PHYSFS_HAVE_READLINE)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
  1121
        buf = readline("> ");
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
  1122
#else
74
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1123
        int i;
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
  1124
        buf = malloc(512);
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
  1125
        memset(buf, '\0', 512);
74
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1126
        printf("> ");
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1127
        for (i = 0; i < 511; i++)
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1128
        {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1129
            int ch = fgetc(stdin);
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1130
            if (ch == EOF)
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1131
            {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1132
                strcpy(buf, "quit");
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1133
                break;
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1134
            } /* if */
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1135
            else if ((ch == '\n') || (ch == '\r'))
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1136
            {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1137
                buf[i] = '\0';
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icc&#