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