1.1 --- a/libe2access/host/e2access.c Sun Mar 06 01:30:32 2022 +0100
1.2 +++ b/libe2access/host/e2access.c Sun Mar 06 18:20:32 2022 +0100
1.3 @@ -20,97 +20,15 @@
1.4 */
1.5
1.6 #include <stdio.h>
1.7 -#include <string.h>
1.8 #include <unistd.h>
1.9
1.10 #include <ext2fs/ext2fs.h>
1.11
1.12 -#include "input.h"
1.13 #include "ops.h"
1.14 #include "session.h"
1.15
1.16
1.17
1.18 -/* Copy buffer size. */
1.19 -
1.20 -extern int BUFSIZE;
1.21 -
1.22 -/* Maximum number of arguments in scripts. */
1.23 -
1.24 -const int MAX_ARGS = 32;
1.25 -
1.26 -
1.27 -
1.28 -/* Read operations from a script file. */
1.29 -
1.30 -enum op_results
1.31 -{
1.32 - OP_SUCCESS = 0,
1.33 - OP_FAILED = 1,
1.34 - OP_UNKNOWN = 2,
1.35 -};
1.36 -
1.37 -int handle_op_result(const char *operation, enum op_results op_result)
1.38 -{
1.39 - if (op_result == OP_UNKNOWN)
1.40 - {
1.41 - fprintf(stderr, "Operation not recognised: %s\n", operation);
1.42 - return 1;
1.43 - }
1.44 - else if (op_result == OP_FAILED)
1.45 - {
1.46 - fprintf(stderr, "Operation failed: %s\n", operation);
1.47 - return 1;
1.48 - }
1.49 - else
1.50 - return 0;
1.51 -}
1.52 -
1.53 -enum op_results run_operation(ext2_filsys fs, const char *operation, int argc, char *argv[]);
1.54 -
1.55 -int run_script(ext2_filsys fs, int argc, char *argv[])
1.56 -{
1.57 - FILE *fp;
1.58 - char buffer[BUFSIZE];
1.59 - struct read_line_state state;
1.60 - enum op_results op_result;
1.61 - int num_args;
1.62 - char *args[MAX_ARGS];
1.63 - int i;
1.64 -
1.65 - for (i = 0; i < argc; i++)
1.66 - {
1.67 - fp = fopen(argv[i], "r");
1.68 -
1.69 - state.buffer = buffer;
1.70 - state.start = buffer;
1.71 - state.end = buffer;
1.72 - state.buffer_size = BUFSIZE;
1.73 - state.remaining = BUFSIZE - 1;
1.74 -
1.75 - while (read_line(fp, &state) != NULL)
1.76 - {
1.77 - parse_line(state.start, state.eolp, &num_args, args, MAX_ARGS);
1.78 -
1.79 - if (num_args > 1)
1.80 - {
1.81 - op_result = run_operation(fs, args[0], num_args - 1, &args[1]);
1.82 -
1.83 - if (handle_op_result(args[0], op_result))
1.84 - return 1;
1.85 - }
1.86 -
1.87 - state.start = state.eolp + 1;
1.88 - }
1.89 -
1.90 - fclose(fp);
1.91 - }
1.92 -
1.93 - return 0;
1.94 -}
1.95 -
1.96 -
1.97 -
1.98 /* Help message. */
1.99
1.100 char help_text[] = "\
1.101 @@ -145,13 +63,7 @@
1.102
1.103 /* Operations exposed by the program. */
1.104
1.105 -struct operation
1.106 -{
1.107 - const char *name;
1.108 - int (*fn)(ext2_filsys, int, char *[]);
1.109 -};
1.110 -
1.111 -static struct operation operations[] = {
1.112 +struct operation operations[] = {
1.113 {"copy-in", copy_in},
1.114 {"copy-out", copy_out},
1.115 {"ls", list},
1.116 @@ -163,30 +75,6 @@
1.117 {NULL, NULL},
1.118 };
1.119
1.120 -/* Invocation of operations. */
1.121 -
1.122 -enum op_results run_operation(ext2_filsys fs, const char *operation, int argc, char *argv[])
1.123 -{
1.124 - struct operation *op;
1.125 - int exitcode;
1.126 -
1.127 - for (op = &operations[0]; op->name != NULL; op++)
1.128 - {
1.129 - if (!strcmp(operation, op->name))
1.130 - {
1.131 - exitcode = op->fn(fs, argc, argv);
1.132 - if (exitcode)
1.133 - return OP_FAILED;
1.134 - break;
1.135 - }
1.136 - }
1.137 -
1.138 - if (op->name == NULL)
1.139 - return OP_UNKNOWN;
1.140 -
1.141 - return OP_SUCCESS;
1.142 -}
1.143 -
1.144 /* Main program. */
1.145
1.146 int main(int argc, char *argv[])