summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Bley <claudio.bley@googlemail.com>2013-11-01 11:10:13 +0200
committerEli Zaretskii <eliz@gnu.org>2013-11-01 11:10:13 +0200
commit0e7690deacc3232f1a0bd3902255ffa34292e5cf (patch)
tree9459348a527f4b61408cefe9f08538460a651669
parent019c8218f07fd2acca84661be01147c50908d903 (diff)
downloademacs-0e7690deacc3232f1a0bd3902255ffa34292e5cf.tar.gz
Fix handling of comments in NetPBM image files.
src/image.c (pbm_next_char): New function. (pbm_scan_number): Use it. lisp/image.el (image-type-header-regexps): Fix the 'pbm' part to allow comments in pbm files.
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/image.el5
-rw-r--r--src/ChangeLog4
-rw-r--r--src/image.c51
4 files changed, 40 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a73c38bd522..fd8e77c9c53 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
2013-11-01 Claudio Bley <claudio.bley@googlemail.com>
+ * image.el (image-type-header-regexps): Fix the 'pbm' part to
+ allow comments in pbm files.
+
* term/w32-win.el (dynamic-library-alist): Support newer versions
of libjpeg starting with v7: look only for the DLL from the
version against which Emacs was built.
diff --git a/lisp/image.el b/lisp/image.el
index 6ce5b82ec48..69d890719d2 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -34,7 +34,10 @@
(defconst image-type-header-regexps
`(("\\`/[\t\n\r ]*\\*.*XPM.\\*/" . xpm)
- ("\\`P[1-6][[:space:]]+\\(?:#.*[[:space:]]+\\)*[0-9]+[[:space:]]+[0-9]+" . pbm)
+ ("\\`P[1-6]\\\(?:\
+\\(?:\\(?:#[^\r\n]*[\r\n]\\)?[[:space:]]\\)+\
+\\(?:\\(?:#[^\r\n]*[\r\n]\\)?[0-9]\\)+\
+\\)\\{2\\}" . pbm)
("\\`GIF8[79]a" . gif)
("\\`\x89PNG\r\n\x1a\n" . png)
("\\`[\t\n\r ]*#define \\([a-z0-9_]+\\)_width [0-9]+\n\
diff --git a/src/ChangeLog b/src/ChangeLog
index 0d58733f4bf..bfa28105571 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,8 @@
2013-11-01 Claudio Bley <claudio.bley@googlemail.com>
- * image.c (Qlibjpeg_version): New variable.
+ * image.c (pbm_next_char): New function.
+ (pbm_scan_number): Use it.
+ (Qlibjpeg_version): New variable.
(syms_of_image): DEFSYM and initialize it.
2013-10-31 Jan Djärv <jan.h.d@swipnet.se>
diff --git a/src/image.c b/src/image.c
index fca1bb077f6..958295c5d09 100644
--- a/src/image.c
+++ b/src/image.c
@@ -5106,6 +5106,27 @@ pbm_image_p (Lisp_Object object)
}
+/* Get next char skipping comments in Netpbm header. Returns -1 at
+ end of input. */
+
+static int
+pbm_next_char (unsigned char **s, unsigned char *end)
+{
+ int c = -1;
+
+ while (*s < end && (c = *(*s)++, c == '#'))
+ {
+ /* Skip to the next line break. */
+ while (*s < end && (c = *(*s)++, c != '\n' && c != '\r'))
+ ;
+
+ c = -1;
+ }
+
+ return c;
+}
+
+
/* Scan a decimal number from *S and return it. Advance *S while
reading the number. END is the end of the string. Value is -1 at
end of input. */
@@ -5115,28 +5136,16 @@ pbm_scan_number (unsigned char **s, unsigned char *end)
{
int c = 0, val = -1;
- while (*s < end)
- {
- /* Skip white-space. */
- while (*s < end && (c = *(*s)++, c_isspace (c)))
- ;
+ /* Skip white-space. */
+ while ((c = pbm_next_char (s, end)) != -1 && c_isspace (c))
+ ;
- if (c == '#')
- {
- /* Skip comment to end of line. */
- while (*s < end && (c = *(*s)++, c != '\n'))
- ;
- }
- else if (c_isdigit (c))
- {
- /* Read decimal number. */
- val = c - '0';
- while (*s < end && (c = *(*s)++, c_isdigit (c)))
- val = 10 * val + c - '0';
- break;
- }
- else
- break;
+ if (c_isdigit (c))
+ {
+ /* Read decimal number. */
+ val = c - '0';
+ while ((c = pbm_next_char (s, end)) != -1 && c_isdigit (c))
+ val = 10 * val + c - '0';
}
return val;