change it ourselves. */
int re_max_failures = 2000;
-typedef const unsigned char *fail_stack_elt_t;
+typedef unsigned char *fail_stack_elt_t;
typedef struct
{
register char *fastmap = bufp->fastmap;
unsigned char *pattern = bufp->buffer;
unsigned long size = bufp->used;
- const unsigned char *p = pattern;
+ unsigned char *p = pattern;
register unsigned char *pend = pattern + size;
/* Assume that each path through the pattern can be null until
/* This converts PTR, a pointer into one of the search strings `string1'
and `string2' into an offset from the beginning of that string. */
-#define POINTER_TO_OFFSET(ptr) \
- (FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1)
+#define POINTER_TO_OFFSET(ptr) \
+ (FIRST_STRING_P (ptr) \
+ ? ((regoff_t) ((ptr) - string1)) \
+ : ((regoff_t) ((ptr) - string2 + size1)))
/* Macros for dealing with the split strings in re_match_2. */
if (regs->num_regs > 0)
{
regs->start[0] = pos;
- regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1
- : d - string2 + size1);
+ regs->end[0] = (MATCHING_IN_FIRST_STRING
+ ? ((regoff_t) (d - string1))
+ : ((regoff_t) (d - string2 + size1)));
}
/* Go through the first `min (num_regs, regs->num_regs)'
regs->start[mcnt] = regs->end[mcnt] = -1;
else
{
- regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]);
- regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]);
+ regs->start[mcnt]
+ = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]);
+ regs->end[mcnt]
+ = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]);
}
}
/* What can be done about a byte or field. */
enum field_action
{
- field_omit,
- field_output
+ FIELD_OMIT,
+ FIELD_OUTPUT
};
/* In byte mode, which bytes to output.
/* Nonzero if we have ever read standard input. */
static int have_read_stdin;
+/* If nonzero, this is the index of the first field in a range that goes
+ to end of line. */
+static int eol_range_start;
+
/* If non-zero, display usage information and exit. */
static int show_help;
inbuf = (char *) xmalloc (line_size);
for (optc = 0; optc < line_size; optc++)
- fields[optc] = field_omit;
+ fields[optc] = FIELD_OMIT;
while ((optc = getopt_long (argc, argv, "b:c:d:f:ns", longopts, (int *) 0))
!= EOF)
int dash_found = 0; /* Nonzero if a '-' is found in this field. */
int value = 0; /* If nonzero, a number being accumulated. */
int fields_selected = 0; /* Number of fields selected so far. */
- /* If nonzero, index of first field in a range that goes to end of line. */
- int eol_range_start = 0;
for (;;)
{
/* No. A simple range, before and disjoint from
the range going to end of line. Fill it. */
for (; initial <= value; initial++)
- fields[initial] = field_output;
+ fields[initial] = FIELD_OUTPUT;
}
/* In any case, some fields were selected. */
{
/* There is no range going to end of line. */
for (; initial <= value; initial++)
- fields[initial] = field_output;
+ fields[initial] = FIELD_OUTPUT;
fields_selected++;
}
value = 0;
if (value >= line_size)
enlarge_line (value);
- fields[value] = field_output;
+ fields[value] = FIELD_OUTPUT;
value = 0;
fields_selected++;
}
array from the end of line point. */
if (eol_range_start)
for (initial = eol_range_start; initial < line_size; initial++)
- fields[initial] = field_output;
+ fields[initial] = FIELD_OUTPUT;
return fields_selected;
}
}
/* Print the file open for reading on stream STREAM
- with the bytes marked `field_omit' in `fields' removed from each line. */
+ with the bytes marked `FIELD_OMIT' in `fields' removed from each line. */
static void
cut_bytes (stream)
if (++char_count == line_size - 1)
enlarge_line (char_count);
- if (fields[char_count] == field_output || c == '\n')
+ if (fields[char_count] == FIELD_OUTPUT || c == '\n')
*outbufptr++ = c;
}
while (c != '\n');
}
/* Print the file open for reading on stream STREAM
- with the fields marked `field_omit' in `fields' removed from each line.
+ with the fields marked `FIELD_OMIT' in `fields' removed from each line.
All characters are initially stowed in the raw input buffer, until
at least one field has been found. */
break;
}
- if (fields[curr_field] == field_output && c != '\n')
+ if (fields[curr_field] == FIELD_OUTPUT && c != '\n')
{
/* Working on a field. It, and its terminating
delimiter, go only into the processed buffer. */
*inbufptr++ = c;
}
- if (c == delim && ++curr_field == line_size - 1)
- enlarge_line (curr_field);
+ if (c == delim)
+ {
+ ++curr_field;
+ if (curr_field == line_size - 1)
+ enlarge_line (curr_field);
+ }
}
while (c != '\n');
if (fieldfound)
{
/* Something was found. Print it. */
+
+ if ((unsigned char) outbufptr[-1] == delim && eol_range_start == 0)
+ {
+ /* Suppress the trailing delimiter unless there is a range
+ extending to end of line. */
+ --outbufptr;
+ }
+
fwrite (outbuf, sizeof (char), outbufptr - outbuf, stdout);
if (c == '\n')
putc (c, stdout);
inbuf = newp;
for (i = line_size; i < new_size; i++)
- fields[i] = field_omit;
+ fields[i] = FIELD_OMIT;
line_size = new_size;
}