Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/library/base/R/dcf.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ function(file, fields = NULL, all = FALSE, keep.white = NULL)

lines <- readLines(file, skipNul = TRUE, encoding = "bytes")

## Remove comment lines (if any)
comments <- grepl("^#", lines)
if (any(comments)) lines <- lines[!comments]

## Try to find out about invalid things: mostly, lines which do not
## start with blanks but have no ':' ...
ind <- grep(paste0("^[^", ascii_blank, "][^:]*$"), lines)
Expand Down
3 changes: 1 addition & 2 deletions src/library/base/man/dcf.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ write.dcf(x, file = "", append = FALSE, useBytes = FALSE,
\url{https://www.debian.org/doc/debian-policy/ch-controlfields.html}.

Note that \R does not require encoding in UTF-8, which is a recent
Debian requirement. Nor does it use the Debian-specific sub-format
which allows comment lines starting with \samp{#}.
Debian requirement.
}

\note{
Expand Down
6 changes: 5 additions & 1 deletion src/main/dcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env)
bool blank_skip, field_skip = false;
int whatlen, dynwhat, buflen = 8096; // was 100, but that re-alloced often
char *line, *buf;
regex_t blankline, contline, trailblank, regline, eblankline;
regex_t blankline, contline, trailblank, regline, eblankline, commentline;
regmatch_t regmatch[1];
SEXP file, what, what2, retval, retval2, dims, dimnames;
Rconnection con = NULL;
Expand Down Expand Up @@ -122,6 +122,7 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env)
tre_regcompb(&contline, "^[ \t]+", REG_EXTENDED);
tre_regcompb(&regline, "^[^:]+:[ \t]*", REG_EXTENDED);
tre_regcompb(&eblankline, "^[ \f\n\r\t\v]+\\.[ \f\n\r\t\v]*$", REG_EXTENDED);
tre_regcompb(&commentline, "^#", REG_EXTENDED);

k = 0;
lastm = -1; /* index of the field currently being recorded */
Expand Down Expand Up @@ -149,6 +150,8 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env)
field_fold = true;
n_eblanklines = 0;
}
} else if(tre_regexecb(&commentline, line, 0, 0, 0) == 0) {
/* comment-line detected. skipping it per DCF specification */
} else {
blank_skip = false;
if(tre_regexecb(&contline, line, 1, regmatch, 0) == 0) {
Expand Down Expand Up @@ -308,6 +311,7 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env)
tre_regfree(&trailblank);
tre_regfree(&regline);
tre_regfree(&eblankline);
tre_regfree(&commentline);

if(!blank_skip) k++;

Expand Down