From b8c4786b3341e344afaac70c880e501d4367f95e Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Fri, 13 Dec 2024 10:38:34 -0500 Subject: [PATCH] Allow INCLUDE/DO/SYSINCLUDE to take a QuotedString argument. This allows for filenames with spaces in them. --- man/remind.1.in | 17 ++++++++--------- src/files.c | 2 +- src/main.c | 18 ++++++++++++++++++ src/protos.h | 1 + tests/test.cmp | 5 +++++ tests/test.rem | 2 ++ tests/with space.rem | 1 + 7 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 tests/with space.rem diff --git a/man/remind.1.in b/man/remind.1.in index 72602fe8..1377d1be 100644 --- a/man/remind.1.in +++ b/man/remind.1.in @@ -1927,19 +1927,18 @@ commands. .SH THE DO, INCLUDE AND SYSINCLUDE COMMANDS .PP \fBRemind\fR allows you to include other files in your reminder script, -similar to the C preprocessor #include directive. For example, your -system administrator may maintain a file of holidays or system-wide -reminders. You can include these in your reminder script as follows: +similar to the C preprocessor #include directive. For example, you +might organize different reminders into different files like this: .PP .nf - INCLUDE /usr/share/remind/holidays - INCLUDE /usr/share/remind/reminders + INCLUDE holidays.rem + INCLUDE birthdays.rem + INCLUDE "quote files with spaces.rem" .fi .PP -(The actual pathnames vary from system to system - ask your system -administrator.) -.PP -\fBINCLUDE\fR files can be nested up to a depth of 8. +\fBINCLUDE\fR files can be nested up to a depth of 8. As shown above, if a +filename has spaces in it (not recommended!) you can use double-quotes +around the filename. .PP If you specify a filename of "-" in the \fBINCLUDE\fR command, \fBRemind\fR will begin reading from standard input. diff --git a/src/files.c b/src/files.c index 2b649fe7..5d457001 100644 --- a/src/files.c +++ b/src/files.c @@ -608,7 +608,7 @@ int DoInclude(ParsePtr p, enum TokTypes tok) DBufInit(&buf); DBufInit(&fullname); DBufInit(&path); - if ( (r=ParseToken(p, &buf)) ) return r; + if ( (r=ParseTokenOrQuotedString(p, &buf)) ) return r; e = VerifyEoln(p); if (e) Eprint("%s", GetErr(e)); diff --git a/src/main.c b/src/main.c index 7555d1f7..2369345a 100644 --- a/src/main.c +++ b/src/main.c @@ -600,6 +600,24 @@ int ParseNonSpaceChar(ParsePtr p, int *err, int peek) return ch; } +/***************************************************************/ +/* */ +/* ParseTokenOrQuotedString */ +/* */ +/* Parse either a token or a double-quote-delimited string. */ +/* */ +/***************************************************************/ +int ParseTokenOrQuotedString(ParsePtr p, DynamicBuffer *dbuf) +{ + int c, err; + c = ParseNonSpaceChar(p, &err, 1); + if (err) return err; + if (c != '"') { + return ParseToken(p, dbuf); + } + return ParseQuotedString(p, dbuf); +} + /***************************************************************/ /* */ /* ParseQuotedString */ diff --git a/src/protos.h b/src/protos.h index 561094f3..ce252296 100644 --- a/src/protos.h +++ b/src/protos.h @@ -88,6 +88,7 @@ int JulianToGregorianOffset(int y, int m); int ParseChar (ParsePtr p, int *err, int peek); int ParseToken (ParsePtr p, DynamicBuffer *dbuf); int ParseQuotedString (ParsePtr p, DynamicBuffer *dbuf); +int ParseTokenOrQuotedString (ParsePtr p, DynamicBuffer *dbuf); int ParseIdentifier (ParsePtr p, DynamicBuffer *dbuf); expr_node * ParseExpr(ParsePtr p, int *r); void print_expr_nodes_stats(void); diff --git a/tests/test.cmp b/tests/test.cmp index a93848a8..22806f17 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -16232,6 +16232,11 @@ IF 1 ../tests/test.rem(1435): Can't open file: /non/existent/file/should/not/work/wookie ENDIF +do "with space.rem" +REM MSG D'oh, a file whose name has spaces! [filename()] +D'oh, a file whose name has spaces! ../tests/with space.rem + + DEBUG -e Var hash: total = 100141; maxlen = 5; avglen = 1.142 Func hash: total = 100016; maxlen = 5; avglen = 1.140 diff --git a/tests/test.rem b/tests/test.rem index b3334445..c93b5439 100644 --- a/tests/test.rem +++ b/tests/test.rem @@ -1435,6 +1435,8 @@ IF 1 INCLUDE /non/existent/file/should/not/work/wookie ENDIF +do "with space.rem" + DEBUG -e # Output expression-node stats diff --git a/tests/with space.rem b/tests/with space.rem new file mode 100644 index 00000000..524d6d04 --- /dev/null +++ b/tests/with space.rem @@ -0,0 +1 @@ +REM MSG D'oh, a file whose name has spaces! [filename()]