diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-07-14 12:14:46 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-07-14 19:16:59 +0000 |
commit | 06e9b2022c1808d6aeb290cb5786b6042df73215 (patch) | |
tree | ec490c90750b893e172215d3d22f835c65e45785 /ui | |
parent | 338369ec2f89b47729df4b56ccf8fa3eab4ea270 (diff) |
Treat CR-LF at the end of a line like LF.
That way, if we're reading a Windows-format file on UN*X, we handle it
the same way we'd handle a UN*X-format file.
This handles bug 10272 for the cfilter and dfilter file; there are other
configuration files that may need code changes as well.
While we're at it, don't hand non-ASCII characters to isspace().
Change-Id: I4f5efeaa938bcb2d85737ab136c3ca19ea1ddb5b
Reviewed-on: https://code.wireshark.org/review/3045
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/filters.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/ui/filters.c b/ui/filters.c index 60e07f4e9a..3618013ad0 100644 --- a/ui/filters.c +++ b/ui/filters.c @@ -107,6 +107,36 @@ remove_filter_entry(GList *fl, GList *fl_entry) return g_list_remove_link(fl, fl_entry); } +static int +skip_whitespace(FILE *ff) +{ + int c; + + while ((c = getc(ff)) != EOF && c != '\n' && isascii(c) && isspace(c)) + ; + return c; +} + +static int +getc_crlf(FILE *ff) +{ + int c; + + c = getc(ff); + if (c == '\r') { + /* Treat CR-LF at the end of a line like LF, so that if we're reading + * a Windows-format file on UN*X, we handle it the same way we'd handle + * a UN*X-format file. */ + c = getc(ff); + if (c != EOF && c != '\n') { + /* Put back the character after the CR, and process the CR normally. */ + ungetc(c, ff); + c = '\r'; + } + } + return c; +} + void read_filter_list(filter_list_type_t list_type, char **pref_path_return, int *errno_return) @@ -222,15 +252,12 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return, quotes, running to the end of the line. */ /* Skip over leading white space, if any. */ - while ((c = getc(ff)) != EOF && isspace(c)) { - if (c == '\n') { - /* Blank line. */ - continue; - } - } + c = skip_whitespace(ff); if (c == EOF) break; /* Nothing more to read */ + if (c == '\n') + continue; /* Blank line. */ /* "c" is the first non-white-space character. If it's not a quote, it's an error. */ @@ -245,7 +272,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return, /* Get the name of the filter. */ filt_name_index = 0; for (;;) { - c = getc(ff); + c = getc_crlf(ff); if (c == EOF || c == '\n') break; /* End of line - or end of file */ if (c == '"') { @@ -260,7 +287,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return, } if (c == '\\') { /* Next character is escaped */ - c = getc(ff); + c = getc_crlf(ff); if (c == EOF || c == '\n') break; /* End of line - or end of file */ } @@ -291,10 +318,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return, } /* Skip over separating white space, if any. */ - while ((c = getc(ff)) != EOF && isspace(c)) { - if (c == '\n') - break; - } + c = skip_whitespace(ff); if (c == EOF) { if (!ferror(ff)) { @@ -326,7 +350,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return, filt_expr_index++; /* Get the next character. */ - c = getc(ff); + c = getc_crlf(ff); if (c == EOF || c == '\n') break; } |