diff options
Diffstat (limited to 'other/Kermit/src/unload.cpp')
| -rw-r--r-- | other/Kermit/src/unload.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/other/Kermit/src/unload.cpp b/other/Kermit/src/unload.cpp new file mode 100644 index 0000000..90630ea --- /dev/null +++ b/other/Kermit/src/unload.cpp | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* | ||
| 2 | * unload.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <Kermit> | ||
| 6 | #include <string> | ||
| 7 | #include <iostream> | ||
| 8 | #include <fstream> | ||
| 9 | #include <stack> | ||
| 10 | |||
| 11 | #define PROGRAM "unload" | ||
| 12 | #define VERSION "0.0.1" | ||
| 13 | #define AUTHOR "palmers / teso" | ||
| 14 | |||
| 15 | #define LINE_LENGTH 16384 | ||
| 16 | |||
| 17 | |||
| 18 | void usage (char *s) | ||
| 19 | { | ||
| 20 | cout << PROGRAM << VERSION << " by " << AUTHOR << endl; | ||
| 21 | cout << "Usage: " << s << " [options] <file>" << endl; | ||
| 22 | cout << "Options:" << endl; | ||
| 23 | cout << "\t-l:\t restore in linear order [default: reversed order]" << endl; | ||
| 24 | cout << endl; | ||
| 25 | exit (0); | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | int main (int argc, char **argv) | ||
| 30 | { | ||
| 31 | bool linear = false; | ||
| 32 | int x = 0; | ||
| 33 | ifstream fs; | ||
| 34 | char line[LINE_LENGTH + 1]; | ||
| 35 | Patch *tp = NULL; | ||
| 36 | rwKernel *rw = NULL; | ||
| 37 | |||
| 38 | if (argc < 2) | ||
| 39 | usage (argv[0]); | ||
| 40 | |||
| 41 | for (x = 1; x < argc; x++) | ||
| 42 | { | ||
| 43 | if (argv[x][0] == '-') | ||
| 44 | { | ||
| 45 | switch (argv[x][1]) | ||
| 46 | { | ||
| 47 | case 'l': | ||
| 48 | linear = true; | ||
| 49 | break; | ||
| 50 | default: | ||
| 51 | cout << "unknow option: " << argv[x] << endl; | ||
| 52 | usage (argv[0]); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | fs.open (argv[argc - 1]); | ||
| 59 | if (!fs.is_open ()) | ||
| 60 | { | ||
| 61 | cerr << "failed to open \"" << argv[argc - 1] << "\"" << endl; | ||
| 62 | abort (); | ||
| 63 | } | ||
| 64 | |||
| 65 | if (linear) | ||
| 66 | { | ||
| 67 | while (!fs.eof ()) | ||
| 68 | { | ||
| 69 | fs.getline (line, LINE_LENGTH, '\n'); | ||
| 70 | tp = new Patch (string (line), rw); | ||
| 71 | tp->remove (); | ||
| 72 | delete tp; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | else | ||
| 76 | { | ||
| 77 | stack<Patch *> pstack; | ||
| 78 | while (!fs.eof ()) | ||
| 79 | { | ||
| 80 | fs.getline (line, LINE_LENGTH, '\n'); | ||
| 81 | tp = new Patch (string (line), rw); | ||
| 82 | pstack.push (tp); | ||
| 83 | } | ||
| 84 | |||
| 85 | while (!pstack.empty ()) | ||
| 86 | { | ||
| 87 | tp = pstack.top (); | ||
| 88 | tp->remove (); | ||
| 89 | delete tp; | ||
| 90 | pstack.pop (); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | return 0; | ||
| 95 | } | ||
