Skip to content

Commit 8beea2b

Browse files
committed
R-dev-day issue 86 changes
1 parent 3cbed6b commit 8beea2b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/library/base/R/dcf.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ function(file, fields = NULL, all = FALSE, keep.white = NULL)
7575

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

78+
## Remove comment lines (if any)
79+
comments <- grepl("^#", lines)
80+
if (any(comments)) lines <- lines[!comments]
81+
7882
## Try to find out about invalid things: mostly, lines which do not
7983
## start with blanks but have no ':' ...
8084
ind <- grep(paste0("^[^", ascii_blank, "][^:]*$"), lines)

src/library/base/man/dcf.Rd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ write.dcf(x, file = "", append = FALSE, useBytes = FALSE,
106106
\url{https://www.debian.org/doc/debian-policy/ch-controlfields.html}.
107107

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

113112
\note{

src/main/dcf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env)
7272
bool blank_skip, field_skip = false;
7373
int whatlen, dynwhat, buflen = 8096; // was 100, but that re-alloced often
7474
char *line, *buf;
75-
regex_t blankline, contline, trailblank, regline, eblankline;
75+
regex_t blankline, contline, trailblank, regline, eblankline, commentline;
7676
regmatch_t regmatch[1];
7777
SEXP file, what, what2, retval, retval2, dims, dimnames;
7878
Rconnection con = NULL;
@@ -122,6 +122,7 @@ attribute_hidden SEXP do_readDCF(SEXP call, SEXP op, SEXP args, SEXP env)
122122
tre_regcompb(&contline, "^[ \t]+", REG_EXTENDED);
123123
tre_regcompb(&regline, "^[^:]+:[ \t]*", REG_EXTENDED);
124124
tre_regcompb(&eblankline, "^[ \f\n\r\t\v]+\\.[ \f\n\r\t\v]*$", REG_EXTENDED);
125+
tre_regcompb(&commentline, "^#", REG_EXTENDED);
125126

126127
k = 0;
127128
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)
149150
field_fold = true;
150151
n_eblanklines = 0;
151152
}
153+
} else if(tre_regexecb(&commentline, line, 0, 0, 0) == 0) {
154+
/* comment-line detected. skipping it per DCF specification */
152155
} else {
153156
blank_skip = false;
154157
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)
308311
tre_regfree(&trailblank);
309312
tre_regfree(&regline);
310313
tre_regfree(&eblankline);
314+
tre_regfree(&commentline);
311315

312316
if(!blank_skip) k++;
313317

0 commit comments

Comments
 (0)