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