version 1.67, 2010/05/15 05:50:19 |
version 1.68, 2010/05/15 09:46:31 |
Line 268 ffile(const char *file, struct curparse *curp) |
|
Line 268 ffile(const char *file, struct curparse *curp) |
|
|
|
|
|
static int |
static int |
|
resize_buf(struct buf *buf, size_t initial) |
|
{ |
|
void *tmp; |
|
size_t sz; |
|
|
|
if (buf->sz == 0) |
|
sz = initial; |
|
else |
|
sz = 2 * buf->sz; |
|
tmp = realloc(buf->buf, sz); |
|
if (NULL == tmp) { |
|
perror(NULL); |
|
return(0); |
|
} |
|
buf->buf = tmp; |
|
buf->sz = sz; |
|
return(1); |
|
} |
|
|
|
|
|
static int |
read_whole_file(struct curparse *curp, struct buf *fb, int *with_mmap) |
read_whole_file(struct curparse *curp, struct buf *fb, int *with_mmap) |
{ |
{ |
struct stat st; |
struct stat st; |
char *buf; |
size_t off; |
size_t sz, off; |
|
ssize_t ssz; |
ssize_t ssz; |
|
|
if (-1 == fstat(curp->fd, &st)) { |
if (-1 == fstat(curp->fd, &st)) { |
Line 319 read_whole_file(struct curparse *curp, struct buf *fb, |
|
Line 339 read_whole_file(struct curparse *curp, struct buf *fb, |
|
curp->file); |
curp->file); |
break; |
break; |
} |
} |
if (fb->sz == 0) |
if (! resize_buf(fb, 65536)) |
sz = 65536; |
|
else |
|
sz = 2 * fb->sz; |
|
buf = realloc(fb->buf, sz); |
|
if (NULL == buf) { |
|
perror(NULL); |
|
break; |
break; |
} |
|
fb->buf = buf; |
|
fb->sz = sz; |
|
} |
} |
ssz = read(curp->fd, fb->buf + off, fb->sz - off); |
ssz = read(curp->fd, fb->buf + off, fb->sz - off); |
if (ssz == 0) { |
if (ssz == 0) { |
Line 353 read_whole_file(struct curparse *curp, struct buf *fb, |
|
Line 364 read_whole_file(struct curparse *curp, struct buf *fb, |
|
static void |
static void |
fdesc(struct curparse *curp) |
fdesc(struct curparse *curp) |
{ |
{ |
size_t sz; |
|
struct buf ln, blk; |
struct buf ln, blk; |
int j, i, pos, lnn, comment, with_mmap; |
int j, i, pos, lnn, comment, with_mmap; |
struct man *man; |
struct man *man; |
struct mdoc *mdoc; |
struct mdoc *mdoc; |
|
|
sz = BUFSIZ; |
|
man = NULL; |
man = NULL; |
mdoc = NULL; |
mdoc = NULL; |
memset(&ln, 0, sizeof(struct buf)); |
memset(&ln, 0, sizeof(struct buf)); |
Line 377 fdesc(struct curparse *curp) |
|
Line 386 fdesc(struct curparse *curp) |
|
|
|
for (i = lnn = pos = comment = 0; i < (int)blk.sz; ++i) { |
for (i = lnn = pos = comment = 0; i < (int)blk.sz; ++i) { |
if (pos >= (int)ln.sz) { |
if (pos >= (int)ln.sz) { |
ln.sz += 256; /* Step-size. */ |
if (! resize_buf(&ln, 256)) |
ln.buf = realloc(ln.buf, ln.sz); |
|
if (NULL == ln.buf) { |
|
perror(NULL); |
|
goto bailout; |
goto bailout; |
} |
|
} |
} |
|
|
if ('\n' != blk.buf[i]) { |
if ('\n' != blk.buf[i]) { |