diff --git a/src/library/base/R/dcf.R b/src/library/base/R/dcf.R index 4e280f1c25d..383f447fc24 100644 --- a/src/library/base/R/dcf.R +++ b/src/library/base/R/dcf.R @@ -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) diff --git a/src/library/base/man/dcf.Rd b/src/library/base/man/dcf.Rd index cd4545b932e..03c576e9385 100644 --- a/src/library/base/man/dcf.Rd +++ b/src/library/base/man/dcf.Rd @@ -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{ diff --git a/src/main/dcf.c b/src/main/dcf.c index 5c084b318f4..f96bc4c4247 100644 --- a/src/main/dcf.c +++ b/src/main/dcf.c @@ -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; @@ -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(®line, "^[^:]+:[ \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 */ @@ -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) { @@ -308,6 +311,7 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env) tre_regfree(&trailblank); tre_regfree(®line); tre_regfree(&eblankline); + tre_regfree(&commentline); if(!blank_skip) k++;