emacs-diffs
[Top][All Lists]
Advanced

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

master 2236ee40ea: Parse XBM images which use character escapes for hex


From: Po Lu
Subject: master 2236ee40ea: Parse XBM images which use character escapes for hex literals
Date: Thu, 17 Feb 2022 20:13:57 -0500 (EST)

branch: master
commit 2236ee40ea78973d9377e845bfd0ee3a58cd4386
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Parse XBM images which use character escapes for hex literals
    
    * src/image.c (xbm_scan): Implement parsing of hex escapes in
    character literals.
---
 src/image.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/image.c b/src/image.c
index 5c1bf8d7be..d012fcea6a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -3681,6 +3681,48 @@ xbm_scan (char **s, char *end, char *sval, int *ival)
       *ival = value;
       return overflow ? XBM_TK_OVERFLOW : XBM_TK_NUMBER;
     }
+  /* Character literal.  XBM images typically contain hex escape
+     sequences and not actual characters, so we only try to handle
+     that here.  */
+  else if (c == '\'')
+    {
+      int value = 0, digit;
+      bool overflow = false;
+
+      if (*s == end)
+       return 0;
+
+      c = *(*s)++;
+
+      if (c != '\\' || *s == end)
+       return 0;
+
+      c = *(*s)++;
+
+      if (c == 'x')
+       {
+         while (*s < end)
+           {
+             c = *(*s)++;
+
+             if (c == '\'')
+               {
+                 *ival = value;
+                 return overflow ? XBM_TK_OVERFLOW : XBM_TK_NUMBER;
+               }
+
+             digit = char_hexdigit (c);
+
+             if (digit < 0)
+               return 0;
+
+             overflow |= INT_MULTIPLY_WRAPV (value, 16, &value);
+             value += digit;
+           }
+
+         return 0;
+       }
+    }
   else if (c_isalpha (c) || c == '_')
     {
       *sval++ = c;



reply via email to

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