Refactor some generic reading/writing routines out of moviefile.cpp
[lsnes.git] / src / util / fattest.cpp
blobda57051cfaffc26e0dff9d5fc5d31122ff2c1e47
1 #include "library/filesystem.hpp"
2 #include <cstring>
3 #include <sstream>
4 #include <iostream>
6 int main(int argc, char** argv)
8 filesystem x(argv[1]);
9 if(!strcmp(argv[2], "allocate")) {
10 uint32_t c = x.allocate_cluster();
11 std::cerr << "Allocated cluster " << c << std::endl;
13 if(!strcmp(argv[2], "delete")) {
14 std::istringstream s(argv[3]);
15 uint32_t c;
16 s >> c;
17 x.free_cluster_chain(c);
19 if(!strcmp(argv[2], "skip")) {
20 std::istringstream s1(argv[3]);
21 std::istringstream s2(argv[4]);
22 std::istringstream s3(argv[5]);
23 uint32_t c1, c2, c3;
24 s1 >> c1;
25 s2 >> c2;
26 s3 >> c3;
27 size_t r = x.skip_data(c1, c2, c3);
28 std::cerr << "Skip_data: cluster=" << c1 << " ptr=" << c2 << " amount=" << r << std::endl;
30 if(!strcmp(argv[2], "read")) {
31 std::istringstream s1(argv[3]);
32 std::istringstream s2(argv[4]);
33 std::istringstream s3(argv[5]);
34 uint32_t c1, c2, c3;
35 s1 >> c1;
36 s2 >> c2;
37 s3 >> c3;
38 char* buf = (char*)calloc(c3 + 1, 1);
39 size_t r = x.read_data(c1, c2, buf, c3);
40 std::cerr << "Read_data: cluster=" << c1 << " ptr=" << c2 << " amount=" << r << std::endl;
41 std::cerr << buf << std::endl;
43 if(!strcmp(argv[2], "write")) {
44 std::istringstream s1(argv[3]);
45 std::istringstream s2(argv[4]);
46 uint32_t c1, c2, c4, c5;
47 s1 >> c1;
48 s2 >> c2;
49 x.write_data(c1, c2, argv[5], strlen(argv[5]), c4, c5);
50 std::cerr << "Write_data: cluster=" << c1 << " ptr=" << c2 << " rcluster=" << c4
51 << " rptr=" << c5 << std::endl;