test/test_physfs.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 16 Jul 2001 10:32:12 +0000
changeset 38 feb16343f44c
parent 35 1fba29d8a172
child 40 8cc16df4bada
permissions -rw-r--r--
More work; command parsing via readline.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#include <stdio.h>
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
     2
#include <stdlib.h>
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
     3
#include <readline.h>
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
     4
#include <history.h>
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#include "physfs.h"
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
#define TEST_VERSION_MAJOR  0
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#define TEST_VERSION_MINOR  1
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#define TEST_VERSION_PATCH  0
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    11
static void output_versions(void)
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
{
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
    PHYSFS_Version compiled;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
    PHYSFS_Version linked;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    PHYSFS_VERSION(&compiled);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    PHYSFS_getLinkedVersion(&linked);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    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
    20
           " 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
    21
           " 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
    22
            TEST_VERSION_MAJOR, TEST_VERSION_MINOR, TEST_VERSION_PATCH,
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
            compiled.major, compiled.minor, compiled.patch,
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
            linked.major, linked.minor, linked.patch);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
} /* output_versions */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    28
static void output_archivers(void)
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
{
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
    const PHYSFS_ArchiveInfo **rc = PHYSFS_supportedArchiveTypes();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
    const PHYSFS_ArchiveInfo **i;
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    printf("Supported archive types:\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    if (*rc == NULL)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
        printf(" * Apparently, NONE!\n");
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    else
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
        for (i = rc; *i != NULL; i++)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
        {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
            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
    41
                    (*i)->extension, (*i)->description,
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
                    (*i)->author, (*i)->url);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        } /* for */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    } /* else */
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    45
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    46
    printf("\n");
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
} /* output_archivers */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    50
static int cmd_help(char *cmdstr)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    51
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    52
    printf("Commands:\n"
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    53
           "  quit - exit this program.\n"
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    54
           "  help - this information.\n");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    55
    return(1);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    56
} /* output_cmd_help */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    57
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    58
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    59
static int cmd_quit(char *cmdstr)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    60
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    61
    return(0);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    62
} /* cmd_quit */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    63
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    64
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    65
typedef struct
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    66
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    67
    const char *cmd;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    68
    int (*func)(char *cmdstr);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    69
} command_info;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    70
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    71
static command_info commands[] =
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    72
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    73
    {"quit", cmd_quit},
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    74
    {"q",    cmd_quit},
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    75
    {"help", cmd_help},
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    76
    {NULL, NULL}
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    77
};
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    78
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    79
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    80
static int process_command(char *complete_cmd)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    81
{
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    82
    command_info *i;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    83
    char *ptr = strchr(complete_cmd, ' ');
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    84
    char *cmd = NULL;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    85
    int rc = 1;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    86
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    87
    if (ptr == NULL)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    88
    {
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    89
        cmd = malloc(strlen(complete_cmd) + 1);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    90
        strcpy(cmd, complete_cmd);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    91
    } /* if */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    92
    else
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    93
    {
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    94
        *ptr = '\0';
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    95
        cmd = malloc(strlen(complete_cmd) + 1);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    96
        strcpy(cmd, complete_cmd);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    97
        *ptr = ' ';
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    98
    } /* else */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
    99
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   100
    for (i = commands; i->cmd != NULL; i++)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   101
    {
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   102
        if (strcmp(i->cmd, cmd) == 0)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   103
        {
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   104
            rc = i->func(complete_cmd);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   105
            break;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   106
        } /* if */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   107
    } /* for */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   108
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   109
    if (i->cmd == NULL)
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   110
        printf("Unknown command. Enter \"help\" for instructions.\n");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   111
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   112
    free(cmd);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   113
    return(rc);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   114
} /* process_command */
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   115
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   116
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
int main(int argc, char **argv)
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
{
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   119
    char *buf = NULL;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   120
    int rc = 0;
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   121
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   122
    printf("\n");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   123
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
    if (!PHYSFS_init(argv[0]))
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    {
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
        printf("PHYSFS_init() failed!\n  reason: %s\n", PHYSFS_getLastError());
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
        return(1);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    } /* if */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    output_versions();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    output_archivers();
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
38
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   133
    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
   134
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   135
    do
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   136
    {
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   137
        buf = readline("> ");
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   138
        rc = process_command(buf);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   139
        free(buf);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   140
    } while (rc);
feb16343f44c More work; command parsing via readline.
Ryan C. Gordon <icculus@icculus.org>
parents: 35
diff changeset
   141
35
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    return(0);
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
} /* main */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
/* end of test_physfs.c ... */
1fba29d8a172 Initial add. Does VERY little right now.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146