emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114889: Fix handling of comments in NetPBM image fi


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r114889: Fix handling of comments in NetPBM image files.
Date: Fri, 01 Nov 2013 09:11:32 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114889
revision-id: address@hidden
parent: address@hidden
author: Claudio Bley <address@hidden>
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Fri 2013-11-01 11:10:13 +0200
message:
  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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/image.el                  image.el-20091113204419-o5vbwnq5f7feedwu-1320
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/image.c                    image.c-20091113204419-o5vbwnq5f7feedwu-2969
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-11-01 09:04:16 +0000
+++ b/lisp/ChangeLog    2013-11-01 09:10:13 +0000
@@ -1,5 +1,8 @@
 2013-11-01  Claudio Bley  <address@hidden>
 
+       * 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.

=== modified file 'lisp/image.el'
--- a/lisp/image.el     2013-10-27 23:04:16 +0000
+++ b/lisp/image.el     2013-11-01 09:10:13 +0000
@@ -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\

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-11-01 08:52:22 +0000
+++ b/src/ChangeLog     2013-11-01 09:10:13 +0000
@@ -1,6 +1,8 @@
 2013-11-01  Claudio Bley  <address@hidden>
 
-       * 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  <address@hidden>

=== modified file 'src/image.c'
--- a/src/image.c       2013-11-01 08:52:22 +0000
+++ b/src/image.c       2013-11-01 09:10:13 +0000
@@ -5106,6 +5106,27 @@
 }
 
 
+/* 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 @@
 {
   int c = 0, val = -1;
 
-  while (*s < end)
+  /* Skip white-space.  */
+  while ((c = pbm_next_char (s, end)) != -1 && c_isspace (c))
+    ;
+
+  if (c_isdigit (c))
     {
-      /* Skip white-space.  */
-      while (*s < end && (c = *(*s)++, 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;
+      /* Read decimal number.  */
+      val = c - '0';
+      while ((c = pbm_next_char (s, end)) != -1 && c_isdigit (c))
+        val = 10 * val + c - '0';
     }
 
   return val;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]