Remove limitation on input lines by using getline(3)

This commit is contained in:
Baptiste Daroussin 2015-05-04 22:27:55 +00:00
parent 72cc039d1a
commit 53b89be196
2 changed files with 8 additions and 7 deletions

View File

@ -28,7 +28,7 @@
.\" @(#)checknr.1 8.1 (Berkeley) 6/6/93 .\" @(#)checknr.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd January 26, 2005 .Dd May 5, 2015
.Dt CHECKNR 1 .Dt CHECKNR 1
.Os .Os
.Sh NAME .Sh NAME
@ -157,7 +157,3 @@ There is no way to define a 1 character macro name using
.Pp .Pp
Does not correctly recognize certain reasonable constructs, Does not correctly recognize certain reasonable constructs,
such as conditionals. such as conditionals.
.Pp
Input lines are limited to
.Dv LINE_MAX
(2048) bytes in length.

View File

@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
* structured typesetting. * structured typesetting.
*/ */
#include <err.h> #include <err.h>
#define _WITH_GETLINE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -284,11 +285,14 @@ process(FILE *f)
{ {
int i, n; int i, n;
char mac[5]; /* The current macro or nroff command */ char mac[5]; /* The current macro or nroff command */
char *line;
size_t linecap;
int pl; int pl;
static char line[256]; /* the current line */
line = NULL;
linecap = 0;
stktop = -1; stktop = -1;
for (lineno = 1; fgets(line, sizeof line, f); lineno++) { for (lineno = 1; getline(&line, &linecap, f) > 0; lineno++) {
if (line[0] == '.') { if (line[0] == '.') {
/* /*
* find and isolate the macro/command name. * find and isolate the macro/command name.
@ -367,6 +371,7 @@ process(FILE *f)
} }
} }
} }
free(line);
/* /*
* We've hit the end and look at all this stuff that hasn't been * We've hit the end and look at all this stuff that hasn't been
* matched yet! Complain, complain. * matched yet! Complain, complain.