summaryrefslogtreecommitdiffstats
path: root/usr.bin/cut/cut.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-05-24 09:11:18 +0000
committertjr <tjr@FreeBSD.org>2002-05-24 09:11:18 +0000
commit425cb2e9e10401a92230e2b0a892ebe2ae2def38 (patch)
tree531af5374d3784b91434660aae49872b0f61e03b /usr.bin/cut/cut.c
parent4b1ea82b13bbf533ac3e19fdee9e171eb17574fe (diff)
downloadFreeBSD-src-425cb2e9e10401a92230e2b0a892ebe2ae2def38.zip
FreeBSD-src-425cb2e9e10401a92230e2b0a892ebe2ae2def38.tar.gz
Allow byte/character positions >_POSIX2_LINE_MAX to be specified by
dynamically growing the `positions' array.
Diffstat (limited to 'usr.bin/cut/cut.c')
-rw-r--r--usr.bin/cut/cut.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c
index 93737fc..12d0e83 100644
--- a/usr.bin/cut/cut.c
+++ b/usr.bin/cut/cut.c
@@ -62,6 +62,7 @@ void c_cut (FILE *, const char *);
void f_cut (FILE *, const char *);
void get_list (char *);
int main (int, char **);
+void needpos(size_t);
static void usage (void);
int
@@ -133,7 +134,7 @@ main(argc, argv)
size_t autostart, autostop, maxval;
-char positions[_POSIX2_LINE_MAX + 1];
+char *positions;
void
get_list(list)
@@ -175,23 +176,40 @@ get_list(list)
errx(1, "[-cf] list: illegal list value");
if (!stop || !start)
errx(1, "[-cf] list: values may not include zero");
- if (stop > _POSIX2_LINE_MAX)
- errx(1, "[-cf] list: %ld too large (max %d)",
- (long)stop, _POSIX2_LINE_MAX);
- if (maxval < stop)
+ if (maxval < stop) {
maxval = stop;
+ needpos(maxval + 1);
+ }
for (pos = positions + start; start++ <= stop; *pos++ = 1);
}
/* overlapping ranges */
- if (autostop && maxval > autostop)
+ if (autostop && maxval > autostop) {
maxval = autostop;
+ needpos(maxval + 1);
+ }
/* set autostart */
if (autostart)
memset(positions + 1, '1', autostart);
}
+void
+needpos(size_t n)
+{
+ static size_t npos;
+
+ /* Grow the positions array to at least the specified size. */
+ if (n > npos) {
+ if (npos == 0)
+ npos = n;
+ while (n > npos)
+ npos *= 2;
+ if ((positions = realloc(positions, npos)) == NULL)
+ err(1, "realloc");
+ }
+}
+
/* ARGSUSED */
void
c_cut(fp, fname)
OpenPOWER on IntegriCloud