diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/Kermit/src/load.cpp | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/Kermit/src/load.cpp')
| -rw-r--r-- | other/Kermit/src/load.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/other/Kermit/src/load.cpp b/other/Kermit/src/load.cpp new file mode 100644 index 0000000..2d40735 --- /dev/null +++ b/other/Kermit/src/load.cpp | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /* | ||
| 2 | * load.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 "load" | ||
| 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-v:\t be verbose" << endl; | ||
| 24 | cout << "\t-E:\t proceed even if errors occour" << endl; | ||
| 25 | cout << endl; | ||
| 26 | exit (0); | ||
| 27 | } | ||
| 28 | |||
| 29 | |||
| 30 | int main (int argc, char **argv) | ||
| 31 | { | ||
| 32 | bool verbose = false, | ||
| 33 | err_continue = false; | ||
| 34 | int x = 0; | ||
| 35 | ifstream fs; | ||
| 36 | char line[LINE_LENGTH + 1]; | ||
| 37 | Patch *tp = NULL; | ||
| 38 | rwKernel *rw = NULL; | ||
| 39 | SymbolTable *st = NULL; | ||
| 40 | Addr2AddrList *a2a = NULL; | ||
| 41 | |||
| 42 | if (argc < 2) | ||
| 43 | usage (argv[0]); | ||
| 44 | |||
| 45 | for (x = 1; x < argc; x++) | ||
| 46 | { | ||
| 47 | if (argv[x][0] == '-') | ||
| 48 | { | ||
| 49 | switch (argv[x][1]) | ||
| 50 | { | ||
| 51 | case 'v': | ||
| 52 | verbose = true; | ||
| 53 | break; | ||
| 54 | case 'E': | ||
| 55 | err_continue = true; | ||
| 56 | break; | ||
| 57 | default: | ||
| 58 | cout << "unknow option: " << argv[x] << endl; | ||
| 59 | usage (argv[0]); | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | rw = new rwKernel (); | ||
| 66 | genDummyValMap (); | ||
| 67 | st = new SymbolTable (rw); | ||
| 68 | a2a = genReplaceValMap (st); | ||
| 69 | |||
| 70 | fs.open (argv[argc - 1]); | ||
| 71 | if (!fs.is_open ()) | ||
| 72 | { | ||
| 73 | cerr << "failed to open \"" << argv[argc - 1] << "\"" << endl; | ||
| 74 | abort (); | ||
| 75 | } | ||
| 76 | |||
| 77 | if (verbose) | ||
| 78 | cout << "done." << endl; | ||
| 79 | |||
| 80 | while (!fs.eof ()) | ||
| 81 | { | ||
| 82 | fs.getline (line, LINE_LENGTH, '\n'); | ||
| 83 | tp = new Patch (string (line), rw); | ||
| 84 | |||
| 85 | if (tp->isClean ()) | ||
| 86 | tp->link (a2a); | ||
| 87 | |||
| 88 | if (tp->isLinked ()) | ||
| 89 | tp->apply (); | ||
| 90 | else if (verbose) | ||
| 91 | { | ||
| 92 | cout << "#" << x << ": Linking Failed" << endl; | ||
| 93 | if (err_continue) | ||
| 94 | continue; | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | if (tp->isApplied () && verbose) | ||
| 98 | cout << "#" << x << ": Success" << endl; | ||
| 99 | else | ||
| 100 | { | ||
| 101 | cout << "#" << x << ": Applying Failed" << endl; | ||
| 102 | if (err_continue) | ||
| 103 | continue; | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | delete tp; | ||
| 107 | } | ||
| 108 | if (verbose) | ||
| 109 | cout << "done." << endl; | ||
| 110 | fs.close (); | ||
| 111 | return 0; | ||
| 112 | } | ||
