1.1 --- a/libe2access/host/e2access.c Sat Feb 19 00:44:46 2022 +0100
1.2 +++ b/libe2access/host/e2access.c Sat Feb 19 01:34:52 2022 +0100
1.3 @@ -32,6 +32,7 @@
1.4 #include "file.h"
1.5 #include "format.h"
1.6 #include "image.h"
1.7 +#include "input.h"
1.8 #include "path.h"
1.9 #include "utils.h"
1.10
1.11 @@ -580,101 +581,6 @@
1.12 return _remove(fs, argc, argv, 0);
1.13 }
1.14
1.15 -/* Read a line from a file into the given buffer. */
1.16 -
1.17 -struct read_line_state
1.18 -{
1.19 - char *buffer, *start, *end, *eolp;
1.20 - size_t remaining;
1.21 -};
1.22 -
1.23 -static char *read_line(FILE *fp, struct read_line_state *state)
1.24 -{
1.25 - size_t nread;
1.26 -
1.27 - do
1.28 - {
1.29 - do
1.30 - {
1.31 - /* Search for a newline character in any available text. */
1.32 -
1.33 - if (state->end > state->start)
1.34 - {
1.35 - state->eolp = strchr(state->start, '\n');
1.36 -
1.37 - if (state->eolp != NULL)
1.38 - {
1.39 - *(state->eolp) = '\0';
1.40 - return state->eolp;
1.41 - }
1.42 - }
1.43 -
1.44 - /* Obtain more text if necessary. */
1.45 -
1.46 - nread = fread(state->end, sizeof(char), state->remaining, fp);
1.47 -
1.48 - /* Handle end of file condition. */
1.49 -
1.50 - if (!nread)
1.51 - {
1.52 - if (state->end > state->start)
1.53 - return state->end;
1.54 - else
1.55 - return NULL;
1.56 - }
1.57 -
1.58 - /* Zero-terminate the string for searching. */
1.59 -
1.60 - *(state->end + nread) = '\0';
1.61 -
1.62 - /* Advance the end of string and subtract remaining space. */
1.63 -
1.64 - state->end += nread;
1.65 - state->remaining -= nread;
1.66 - }
1.67 - while (state->remaining);
1.68 -
1.69 - /* Copy the remaining text to the start of the buffer. */
1.70 -
1.71 - if (state->start > state->buffer)
1.72 - {
1.73 - strcpy(state->buffer, state->start);
1.74 -
1.75 - state->end -= (state->start - state->buffer);
1.76 - state->start = state->buffer;
1.77 - state->remaining = BUFSIZE - 1 - (state->end - state->buffer);
1.78 - }
1.79 - }
1.80 - while (state->remaining);
1.81 -
1.82 - return NULL;
1.83 -}
1.84 -
1.85 -/* Parse the text in the given region, returning details of arguments. */
1.86 -
1.87 -static void parse_line(char *start, char *end, int *num_args, char *args[], const int max_args)
1.88 -{
1.89 - *num_args = 0;
1.90 -
1.91 - while ((start != NULL) && (start < end) && (*num_args < max_args))
1.92 - {
1.93 - args[*num_args] = start;
1.94 - (*num_args)++;
1.95 -
1.96 - /* NOTE: Only handling spaces as delimiters. */
1.97 -
1.98 - start = strchr(start, ' ');
1.99 -
1.100 - if (start != NULL)
1.101 - {
1.102 - *start = '\0';
1.103 -
1.104 - if (start < end)
1.105 - start++;
1.106 - }
1.107 - }
1.108 -}
1.109 -
1.110 /* Read operations from a script file. */
1.111
1.112 enum op_results
1.113 @@ -719,6 +625,7 @@
1.114 state.buffer = buffer;
1.115 state.start = buffer;
1.116 state.end = buffer;
1.117 + state.buffer_size = BUFSIZE;
1.118 state.remaining = BUFSIZE - 1;
1.119
1.120 while (read_line(fp, &state) != NULL)