test/test_physfs.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 06 Apr 2002 23:49:17 +0000
changeset 191 0b95b9fd25e3
parent 182 a47c39af46ad
child 214 19846c18071b
permissions -rw-r--r--
Darwin patches.
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
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#include <stdio.h>
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    10
#include <stdlib.h>
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    11
#include <errno.h>
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    12
#include <string.h>
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    13
164
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    14
#if (defined __MWERKS__)
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    15
#include <SIOUX.h>
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    16
#endif
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    17
191
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    18
#if ((defined __APPLE__) && (defined __MACH__))
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    19
#  if (!defined __DARWIN__)
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    20
#    define __DARWIN__
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    21
#  endif
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    22
#endif
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    23
0b95b9fd25e3 Darwin patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 182
diff changeset
    24
#if ((!defined WIN32) && (!defined __MACOS__) && (!defined __DARWIN__))
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    25
#define HAVE_READLINE
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
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    28
#if (defined HAVE_READLINE)
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    29
#include <unistd.h>
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    30
#include <readline.h>
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    31
#include <history.h>
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    32
#endif
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
    33
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#include "physfs.h"
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#define TEST_VERSION_MAJOR  0
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
#define TEST_VERSION_MINOR  1
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    38
#define TEST_VERSION_PATCH  1
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    40
static FILE *history_file = NULL;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    41
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    42
static void output_versions(void)
35
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_Version 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
    PHYSFS_VERSION(&compiled);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    PHYSFS_getLinkedVersion(&linked);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    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
    51
           " 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
    52
           " 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
    53
            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
    54
            (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
    55
            (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
    56
} /* output_versions */
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
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    59
static void output_archivers(void)
35
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
    const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    const PHYSFS_ArchiveInfo **i;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    printf("Supported archive types:\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    if (*rc == NULL)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        printf(" * Apparently, NONE!\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    else
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        for (i = rc; *i != NULL; i++)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
        {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
            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
    72
                    (*i)->extension, (*i)->description,
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
                    (*i)->author, (*i)->url);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        } /* for */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    } /* else */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    76
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    77
    printf("\n");
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
} /* output_archivers */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    81
static int cmd_quit(char *args)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    82
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    83
    return(0);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    84
} /* cmd_quit */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    85
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    86
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    87
static int cmd_init(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    88
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    89
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    90
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    91
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    92
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    93
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
    94
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    95
    if (PHYSFS_init(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    96
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    97
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    98
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
    99
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   100
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   101
} /* cmd_init */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   102
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   103
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   104
static int cmd_deinit(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   105
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   106
    if (PHYSFS_deinit())
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   107
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   108
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   109
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   110
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   111
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   112
} /* cmd_deinit */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   113
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   114
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   115
static int cmd_addarchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   116
{
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   117
    char *ptr = strrchr(args, ' ');
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   118
    int appending = atoi(ptr + 1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   119
    *ptr = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   120
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   121
    if (*args == '\"')
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   122
    {
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   123
        args++;
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   124
        *(ptr - 1) = '\0';
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   125
    } /* if */
165
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   126
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   127
    /*printf("[%s], [%d]\n", args, appending);*/
cbb1b0dcf6da Handles quoted arguments a little bit better (needs some overhauling to do it right, though).
Ryan C. Gordon <icculus@icculus.org>
parents: 164
diff changeset
   128
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   129
    if (PHYSFS_addToSearchPath(args, appending))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   130
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   131
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   132
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   133
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   134
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   135
} /* cmd_addarchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   136
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   137
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   138
static int cmd_removearchive(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   139
{
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
   140
    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
   141
    {
d826bf2c38c8 More hacks to 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
        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
   143
        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
   144
    } /* 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
   145
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   146
    if (PHYSFS_removeFromSearchPath(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   147
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   148
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   149
        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
   150
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   151
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   152
} /* cmd_removearchive */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   153
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   154
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   155
static int cmd_enumerate(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   156
{
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
   157
    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
   158
d826bf2c38c8 More hacks to 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
    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
   160
    {
d826bf2c38c8 More hacks to 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
        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
   162
        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
   163
    } /* 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
   164
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   165
    rc = PHYSFS_enumerateFiles(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   166
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   167
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   168
        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
   169
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   170
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   171
        int file_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   172
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   173
        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
   174
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   175
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   176
        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
   177
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   178
    } /* else */
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
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   181
} /* cmd_enumerate */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   184
static int cmd_getdirsep(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   185
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   186
    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
   187
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   188
} /* cmd_getdirsep */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   191
static int cmd_getlasterror(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   192
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   193
    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
   194
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   195
} /* cmd_getlasterror */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   198
static int cmd_getcdromdirs(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   199
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   200
    char **rc = PHYSFS_getCdRomDirs();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   201
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   202
    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
   203
        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
   204
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   205
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   206
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   207
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   208
        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
   209
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   210
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   211
        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
   212
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   213
    } /* else */
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
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   216
} /* cmd_getcdromdirs */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   219
static int cmd_getsearchpath(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   220
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   221
    char **rc = PHYSFS_getSearchPath();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   222
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   223
    if (rc == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   224
        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
   225
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   226
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   227
        int dir_count;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   228
        char **i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   229
        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
   230
            printf("%s\n", *i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   231
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   232
        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
   233
        PHYSFS_freeList(rc);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   234
    } /* else */
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
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   237
} /* cmd_getcdromdirs */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   240
static int cmd_getbasedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   241
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   242
    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
   243
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   244
} /* cmd_getbasedir */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   247
static int cmd_getuserdir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   248
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   249
    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
   250
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   251
} /* cmd_getuserdir */
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
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   254
static int cmd_getwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   255
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   256
    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
   257
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   258
} /* cmd_getwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   259
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   260
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   261
static int cmd_setwritedir(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   262
{
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
   263
    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
   264
    {
d826bf2c38c8 More hacks to 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
        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
   266
        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
   267
    } /* 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
   268
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   269
    if (PHYSFS_setWriteDir(args))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   270
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   271
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   272
        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
   273
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   274
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   275
} /* cmd_setwritedir */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   276
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   277
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   278
static int cmd_permitsyms(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   279
{
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
   280
    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
   281
d826bf2c38c8 More hacks to 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
    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
   283
    {
d826bf2c38c8 More hacks to 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
        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
   285
        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
   286
    } /* 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
   287
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   288
    num = atoi(args);
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   289
    PHYSFS_permitSymbolicLinks(num);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   290
    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
   291
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   292
} /* cmd_permitsyms */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   293
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   294
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   295
static int cmd_setsaneconfig(char *args)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   296
{
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   297
    char *org;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   298
    char *appName;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   299
    char *arcExt;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   300
    int inclCD;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   301
    int arcsFirst;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   302
    char *ptr = args;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   303
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   304
        /* ugly. */
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   305
    org = ptr;
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   306
    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
   307
    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
   308
    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
   309
    arcsFirst = atoi(ptr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   310
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   311
    if (strcmp(arcExt, "!") == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   312
        arcExt = NULL;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   313
101
bd18e17ad6ad Changed PHYSFS_setSaneConfig()'s behaviour. API BREAKAGE.
Ryan C. Gordon <icculus@icculus.org>
parents: 74
diff changeset
   314
    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
   315
        printf("Successful.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   316
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   317
        printf("Failure. reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   318
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   319
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   320
} /* cmd_setsaneconfig */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   321
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   322
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   323
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
   324
{
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
   325
    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
   326
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   327
        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
   328
        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
   329
    } /* 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
   330
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   331
    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
   332
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   333
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   334
        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
   335
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   336
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   337
} /* cmd_mkdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   338
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   339
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   340
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
   341
{
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
   342
    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
   343
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   344
        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
   345
        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
   346
    } /* 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
   347
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   348
    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
   349
        printf("Successful.\n");
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   350
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   351
        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
   352
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   353
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   354
} /* cmd_delete */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   355
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   356
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   357
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
   358
{
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
   359
    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
   360
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   361
    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
   362
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   363
        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
   364
        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
   365
    } /* 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
   366
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   367
    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
   368
    if (rc)
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   369
        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
   370
    else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   371
        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
   372
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   373
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   374
} /* cmd_getrealdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   375
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   376
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   377
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
   378
{
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
   379
    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
   380
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   381
    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
   382
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   383
        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
   384
        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
   385
    } /* 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
   386
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   387
    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
   388
    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
   389
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   390
} /* cmd_exists */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   391
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   392
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   393
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
   394
{
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
   395
    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
   396
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   397
    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
   398
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   399
        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
   400
        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
   401
    } /* 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
   402
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   403
    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
   404
    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
   405
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   406
} /* cmd_isdir */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   407
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   408
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   409
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
   410
{
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
   411
    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
   412
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   413
    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
   414
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   415
        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
   416
        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
   417
    } /* 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
   418
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   419
    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
   420
    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
   421
    return(1);
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   422
} /* cmd_issymlink */
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   423
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   424
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   425
static int cmd_cat(char *args)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   426
{
170
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   427
    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
   428
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   429
    if (*args == '\"')
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   430
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   431
        args++;
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   432
        args[strlen(args) - 1] = '\0';
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   433
    } /* if */
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   434
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   435
    f = PHYSFS_openRead(args);
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   436
    if (f == NULL)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   437
        printf("failed to open. Reason: [%s].\n", PHYSFS_getLastError());
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   438
    else
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   439
    {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   440
        while (1)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   441
        {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   442
            char buffer[128];
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   443
            PHYSFS_sint64 rc;
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   444
            PHYSFS_sint64 i;
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   445
            rc = PHYSFS_read(f, buffer, 1, sizeof (buffer));
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   446
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   447
            for (i = 0; i < rc; i++)
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   448
                fputc((int) buffer[i], stdout);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   449
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   450
            if (rc < sizeof (buffer))
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   451
            {
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   452
                printf("\n\n");
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   453
                if (!PHYSFS_eof(f))
132
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   454
                {
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   455
                    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
   456
                           PHYSFS_getLastError());
b53fa5093749 Added typedefs and platform-specific i/o.
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   457
                } /* if */
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   458
                PHYSFS_close(f);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   459
                return(1);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   460
            } /* if */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   461
        } /* while */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   462
    } /* else */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   463
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   464
    return(1);
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   465
} /* cmd_cat */
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   466
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   467
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
   468
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
   469
{
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   470
    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
   471
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   472
    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
   473
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   474
        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
   475
        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
   476
    } /* 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
   477
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   478
    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
   479
    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
   480
        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
   481
    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
   482
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   483
        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
   484
        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
   485
            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
   486
        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
   487
            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
   488
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   489
        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
   490
    } /* 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
   491
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   492
    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
   493
} /* 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
   494
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   495
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   496
#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
   497
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   498
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
   499
{
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   500
    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
   501
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   502
    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
   503
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   504
        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
   505
        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
   506
    } /* 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
   507
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   508
    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
   509
    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
   510
        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
   511
    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
   512
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   513
        size_t bw = strlen(WRITESTR);
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   514
        PHYSFS_sint64 rc = PHYSFS_write(f, WRITESTR, 1, 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
   515
        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
   516
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   517
            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
   518
                   (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
   519
        } /* 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
   520
        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
   521
        {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   522
            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
   523
        } /* 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
   524
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   525
        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
   526
    } /* 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
   527
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   528
    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
   529
} /* 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
   530
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   531
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   532
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
   533
{
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   534
    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
   535
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   536
    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
   537
    {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   538
        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
   539
        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
   540
    } /* 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
   541
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   542
    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
   543
    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
   544
        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
   545
    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
   546
    {
d826bf2c38c8 More hacks to 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
        size_t bw = strlen(WRITESTR);
d826bf2c38c8 More hacks to 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
        PHYSFS_sint64 rc = PHYSFS_write(f, WRITESTR, 1, 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
   549
        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
   550
        {
182
a47c39af46ad Patched to compile on Linux/gcc.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   551
            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
   552
                   (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
   553
        } /* 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
   554
        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
   555
        {
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   556
            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
   557
        } /* 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
   558
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   559
        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
   560
    } /* 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
   561
d826bf2c38c8 More hacks to handle quoted arguments. Write, append, and filelength tests. Upped version to 0.1.1.
Ryan C. Gordon <icculus@icculus.org>
parents: 165
diff changeset
   562
    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
   563
} /* 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
   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
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   566
/* 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
   567
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
   568
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   569
    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
   570
    int in_quotes = 0;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   571
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   572
    if (str != NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   573
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   574
        for (; *str != '\0'; str++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   575
        {
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
   576
            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
   577
                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
   578
            else if ((*str == ' ') && (!in_quotes))
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   579
                retval++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   580
        } /* for */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   581
        retval++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   582
    } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   583
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   584
    return(retval);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   585
} /* count_args */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   586
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   587
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   588
static int cmd_help(char *args);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   589
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   590
typedef struct
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   591
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   592
    const char *cmd;
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   593
    int (*func)(char *args);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   594
    int argcount;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   595
    const char *usage;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   596
} command_info;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   597
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   598
static const command_info commands[] =
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   599
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   600
    { "quit",           cmd_quit,           0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   601
    { "q",              cmd_quit,           0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   602
    { "help",           cmd_help,           0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   603
    { "init",           cmd_init,           1, "<argv0>"                    },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   604
    { "deinit",         cmd_deinit,         0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   605
    { "addarchive",     cmd_addarchive,     2, "<archiveLocation> <append>" },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   606
    { "removearchive",  cmd_removearchive,  1, "<archiveLocation>"          },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   607
    { "enumerate",      cmd_enumerate,      1, "<dirToEnumerate>"           },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   608
    { "getlasterror",   cmd_getlasterror,   0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   609
    { "getdirsep",      cmd_getdirsep,      0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   610
    { "getcdromdirs",   cmd_getcdromdirs,   0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   611
    { "getsearchpath",  cmd_getsearchpath,  0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   612
    { "getbasedir",     cmd_getbasedir,     0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   613
    { "getuserdir",     cmd_getuserdir,     0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   614
    { "getwritedir",    cmd_getwritedir,    0, NULL                         },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   615
    { "setwritedir",    cmd_setwritedir,    1, "<newWriteDir>"              },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   616
    { "permitsymlinks", cmd_permitsyms,     1, "<1or0>"                     },
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   617
    { "setsaneconfig",  cmd_setsaneconfig,  4, "<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
   618
    { "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
   619
    { "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
   620
    { "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
   621
    { "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
   622
    { "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
   623
    { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
108
90f7ad8a0ab5 Added "cat" command.
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   624
    { "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
   625
    { "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
   626
    { "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
   627
    { "write",          cmd_write,          1, "<fileToCreateOrTrash>"      },
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   628
    { NULL,             NULL,              -1, NULL                         }
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   629
};
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   630
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   631
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
   632
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   633
    if (cmdinfo->argcount == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   634
        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
   635
    else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   636
        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
   637
} /* output_usage */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   638
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   639
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   640
static int cmd_help(char *args)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   641
{
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   642
    const command_info *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   643
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   644
    printf("Commands:\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   645
    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
   646
        output_usage("  -", i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   647
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   648
    return(1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   649
} /* output_cmd_help */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   650
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   651
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   652
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
   653
{
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   654
    const char *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   655
    char *writeptr = copy;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   656
    int spacecount = 0;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   657
    int have_first = 0;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   658
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   659
    for (i = orig; *i != '\0'; i++)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   660
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   661
        if (*i == ' ')
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   662
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   663
            if ((*(i + 1) != ' ') && (*(i + 1) != '\0'))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   664
            {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   665
                if ((have_first) && (!spacecount))
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   666
                {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   667
                    spacecount++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   668
                    *writeptr = ' ';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   669
                    writeptr++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   670
                } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   671
            } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   672
        } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   673
        else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   674
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   675
            have_first = 1;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   676
            spacecount = 0;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   677
            *writeptr = *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   678
            writeptr++;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   679
        } /* else */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   680
    } /* for */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   681
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   682
    *writeptr = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   683
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   684
    /*
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   685
    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
   686
    */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   687
} /* trim_command */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   688
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   689
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   690
static int process_command(char *complete_cmd)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   691
{
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   692
    const command_info *i;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   693
    char *cmd_copy = malloc(strlen(complete_cmd) + 1);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   694
    char *args;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   695
    int rc = 1;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   696
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   697
    if (cmd_copy == NULL)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   698
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   699
        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
   700
        return(0);
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   701
    } /* if */
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   702
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   703
    trim_command(complete_cmd, cmd_copy);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   704
    args = strchr(cmd_copy, ' ');
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   705
    if (args != NULL)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   706
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   707
        *args = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   708
        args++;
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   709
    } /* else */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   710
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   711
    if (cmd_copy[0] != '\0')
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   712
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   713
        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
   714
        {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   715
            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
   716
            {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   717
                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
   718
                    output_usage("usage:", i);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   719
                else
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   720
                    rc = i->func(args);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   721
                break;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   722
            } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   723
        } /* for */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   724
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   725
        if (i->cmd == NULL)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   726
            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
   727
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   728
#if (defined HAVE_READLINE)
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   729
        add_history(complete_cmd);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   730
        if (history_file)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   731
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   732
            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
   733
            fflush(history_file);
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   734
        } /* if */
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   735
#endif
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   736
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   737
    } /* if */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   738
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   739
    free(cmd_copy);
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   740
    return(rc);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   741
} /* process_command */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   742
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   743
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   744
static void open_history_file(void)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   745
{
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   746
#if (defined HAVE_READLINE)
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   747
#if 0
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   748
    const char *envr = getenv("TESTPHYSFS_HISTORY");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   749
    if (!envr)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   750
        return;
42
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   751
#else
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   752
    char envr[256];
c9cab2b09437 Added more API calls, always uses a history file, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 40
diff changeset
   753
    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
   754
    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
   755
#endif
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   756
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   757
    if (access(envr, F_OK) == 0)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   758
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   759
        char buf[512];
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   760
        FILE *f = fopen(envr, "r");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   761
        if (!f)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   762
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   763
            printf("\n\n"
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   764
                   "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
   765
                   "  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
   766
                    envr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   767
            return;
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   768
        } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   769
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   770
        do
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   771
        {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   772
            fgets(buf, sizeof (buf), f);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   773
            if (buf[strlen(buf) - 1] == '\n')
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   774
                buf[strlen(buf) - 1] = '\0';
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   775
            add_history(buf);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   776
        } while (!feof(f));
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   777
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   778
        fclose(f);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   779
    } /* if */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   780
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   781
    history_file = fopen(envr, "ab");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   782
    if (!history_file)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   783
    {
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   784
        printf("\n\n"
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   785
               "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
   786
               "  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
   787
                envr);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   788
    } /* if */
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   789
#endif
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   790
} /* open_history_file */
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   791
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   792
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   793
int main(int argc, char **argv)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
{
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   795
    char *buf = NULL;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   796
    int rc = 0;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   797
164
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   798
#if (defined __MWERKS__)
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   799
    extern tSIOUXSettings SIOUXSettings;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   800
    SIOUXSettings.asktosaveonclose = 0;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   801
    SIOUXSettings.autocloseonquit = 1;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   802
    SIOUXSettings.rows = 40;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   803
    SIOUXSettings.columns = 120;
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   804
#endif
a93a65be81fb Added Metrowerks SIOUX setup code.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   805
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   806
    printf("\n");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   807
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   808
    if (!PHYSFS_init(argv[0]))
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   809
    {
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   810
        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
   811
        return(1);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   812
    } /* if */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   813
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   814
    output_versions();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   815
    output_archivers();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   816
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   817
    open_history_file();
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   818
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   819
    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
   820
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   821
    do
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   822
    {
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   823
#if (defined HAVE_READLINE)
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   824
        buf = readline("> ");
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   825
#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
   826
        int i;
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   827
        buf = malloc(512);
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   828
        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
   829
        printf("> ");
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   830
        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
   831
        {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   832
            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
   833
            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
   834
            {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   835
                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
   836
                break;
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   837
            } /* if */
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   838
            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
   839
            {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   840
                buf[i] = '\0';
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   841
                break;
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   842
            } /* else if */
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   843
            else if (ch == '\b')
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   844
            {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   845
                if (i > 0)
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   846
                    i--;
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   847
            } /* else if */
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   848
            else
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   849
            {
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   850
                buf[i] = (char) ch;
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   851
            } /* else */
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   852
        } /* for */
72
ad828df14344 Made dependency on readline optional.
Ryan C. Gordon <icculus@icculus.org>
parents: 42
diff changeset
   853
#endif
74
a4a5066fb640 Compiles and runs on Visual C. What an uphill climb THAT was.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   854
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   855
        rc = process_command(buf);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   856
        free(buf);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   857
    } while (rc);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   858
40
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   859
    if (!PHYSFS_deinit())
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   860
        printf("PHYSFS_deinit() failed!\n  reason: %s.\n", PHYSFS_getLastError());
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   861
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   862
    if (history_file)
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   863
        fclose(history_file);
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   864
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   865
/*
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   866
    printf("\n\ntest_physfs written by ryan c. gordon.\n");
8cc16df4bada Much more complete. Still more to go.
Ryan C. Gordon <icculus@icculus.org>
parents: 38
diff changeset
   867
    printf(" it makes you shoot teh railgun bettar.\n");
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
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   870
    return(0);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   871
} /* main */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   872
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   873
/* end of test_physfs.c ... */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   874