Skip to content
Browse files

Allow values with spaces to be set in xcowsayrc

  • Loading branch information...
1 parent 7df9cba commit 9e80f4d8efadab27a0f40fff835174825c957c3b @nickg committed Nov 19, 2012
Showing with 23 additions and 6 deletions.
  1. +14 −5 src/config_file.c
  2. +9 −1 xcowsay.6
View
19 src/config_file.c
@@ -76,13 +76,19 @@ static token_t next_token(FILE *f, strbuf_t* sbuf, int *lineno, jmp_buf *escape)
{
clear_buf(sbuf);
bool skip_to_eol = false;
+ bool in_quotes = false;
for (;;) {
char next = fgetc(f);
if (EOF == next)
return (has_chars(sbuf) && !skip_to_eol) ? tTOKEN : tEOF;
else if ('\n' == next) {
skip_to_eol = false;
- if (has_chars(sbuf)) {
+ if (in_quotes) {
+ fprintf(stderr, "xcowsayrc: line %d: Newline in quoted string",
+ *lineno);
+ longjmp(*escape, 4);
+ }
+ else if (has_chars(sbuf)) {
ungetc('\n', f);
return tTOKEN;
}
@@ -92,8 +98,10 @@ static token_t next_token(FILE *f, strbuf_t* sbuf, int *lineno, jmp_buf *escape)
}
}
else if (!skip_to_eol) {
- if (isalpha(next) || isdigit(next) || '_' == next
- || '/' == next || '.' == next || '-' == next)
+ if (next == '"')
+ in_quotes = !in_quotes;
+ else if (isalpha(next) || isdigit(next) || '_' == next
+ || '/' == next || '.' == next || '-' == next || in_quotes)
push_char(sbuf, next);
else if (has_chars(sbuf)) {
ungetc(next, f);
@@ -106,7 +114,8 @@ static token_t next_token(FILE *f, strbuf_t* sbuf, int *lineno, jmp_buf *escape)
else if ('#' == next)
skip_to_eol = true;
else {
- fprintf(stderr, "Illegal character in xcowsayrc: %c\n", next);
+ fprintf(stderr, "xcowsayrc: line %d: Illegal character: %c\n",
+ *lineno, next);
longjmp(*escape, 3);
}
}
@@ -220,7 +229,7 @@ void parse_config_file(void)
int lineno = 1;
for (;;) {
while ((tok = next_token(frc, opt_buf, &lineno, &escape))
- == tNEWLINE)
+ == tNEWLINE)
expect(tNEWLINE, tok, true, lineno, &escape);
expect(tTOKEN, tok, true, lineno, &escape);
View
10 xcowsay.6
@@ -67,7 +67,15 @@ display time to 10 seconds:
display_time = 10000
.RE
.PP
-The character '#' begins a comment which lasts until the end of the line.
+The character '#' begins a comment which lasts until the end of the
+line.
+
+Values containing spaces should be enclosed in quotes. For example:
+.PP
+.RS
+font = "mono 28"
+.RE
+.PP
.SH OPTIONS
Note that these options override any settings in the config file.

0 comments on commit 9e80f4d

Please sign in to comment.
Something went wrong with that request. Please try again.