qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs win32.c x11.c xml.c shell.c tty.c util.c...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs win32.c x11.c xml.c shell.c tty.c util.c...
Date: Sat, 15 Dec 2007 16:02:49 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        07/12/15 16:02:48

Modified files:
        .              : win32.c x11.c xml.c shell.c tty.c util.c 
                         buffer.c charset.c clang.c cutils.h cutils.c 
                         dired.c latex-mode.c qe.h qe.c ligtoqe.c 
                         kmaptoqe.c cptoqe.c Makefile 
        libqhtml       : css.c cssparse.c xmlparse.c 

Log message:
        no longer use ctype.h macros and functions
        - ctype.h has strong constraints on arguments
        - ctype.h implements bogus irrelevant inefficient locale specific 
behaviour
        - use replacement css_xxx functions
        - all take int arguments: can be any value, yet only test ASCII subset
        - all css_isxxx return true boolean (1 or 0)
        - removed utoupper(int) -> css_toupper(int) has same functionality
        
        resolved ffmpeg clash on string functions from cutils.c module
        - added #defines to make them local
        - renamed some strixxx functions to strxxxx (extended behaviour)
        - moved case insensitive stuff to util.c
        
        fixed bug in strtokey: C-M-x combinations were not recognized
        improved eb_changecase
        fixed C comment parsing in css parser

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/win32.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/x11.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/shell.c?cvsroot=qemacs&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/qemacs/tty.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/buffer.c?cvsroot=qemacs&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.h?cvsroot=qemacs&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/qemacs/cutils.c?cvsroot=qemacs&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/qemacs/dired.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.42&r2=1.43
http://cvs.savannah.gnu.org/viewcvs/qemacs/ligtoqe.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/kmaptoqe.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/cptoqe.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/Makefile?cvsroot=qemacs&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/css.c?cvsroot=qemacs&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/cssparse.c?cvsroot=qemacs&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/xmlparse.c?cvsroot=qemacs&r1=1.12&r2=1.13

Patches:
Index: win32.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/win32.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- win32.c     12 Dec 2007 11:49:03 -0000      1.8
+++ win32.c     15 Dec 2007 16:02:47 -0000      1.9
@@ -72,7 +72,7 @@
         skip_spaces((const char **)&p);
         if (*p == '\0')
             break;
-        while (*p != '\0' && !css_is_space(*p))
+        while (*p != '\0' && !css_isspace(*p))
             p++;
         count++;
     }
@@ -88,7 +88,7 @@
         if (*p == '\0')
             break;
         argv[argc++] = p;
-        while (*p != '\0' && !css_is_space(*p))
+        while (*p != '\0' && !css_isspace(*p))
             p++;
         *p = '\0';
         p++;

Index: x11.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/x11.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- x11.c       15 Dec 2007 07:31:11 -0000      1.16
+++ x11.c       15 Dec 2007 16:02:47 -0000      1.17
@@ -22,7 +22,6 @@
 
 #include <unistd.h>
 #include <fcntl.h>
-#include <ctype.h>
 #include <signal.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>

Index: xml.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/xml.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- xml.c       12 Dec 2007 02:51:05 -0000      1.7
+++ xml.c       15 Dec 2007 16:02:47 -0000      1.8
@@ -165,13 +165,13 @@
     const char *p;
 
     p = (const char *)p1->buf;
-    while (css_is_space(*p))
+    while (css_isspace((unsigned char)*p))
         p++;
     if (*p != '<')
         return 0;
     p++;
     if (*p != '!' && *p != '?' && *p != '/' && 
-        !isalpha((unsigned char)*p))
+        !css_isalpha((unsigned char)*p))
         return 0;
     return 90; /* leave some room for more specific XML parser */
 }

Index: shell.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/shell.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- shell.c     15 Dec 2007 07:30:20 -0000      1.26
+++ shell.c     15 Dec 2007 16:02:47 -0000      1.27
@@ -23,7 +23,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <ctype.h>
 #include <errno.h>
 #include <signal.h>
 #include <time.h>
@@ -751,7 +750,7 @@
             s->esc1 = c;
             break;
         }
-        if (c >= '0' && c <= '9') {
+        if (css_isdigit(c)) {
             if (s->nb_esc_params < MAX_ESC_PARAMS) {
                 if (!s->has_params[s->nb_esc_params]) {
                     s->esc_params[s->nb_esc_params] = 0;
@@ -1357,7 +1356,7 @@
             c = eb_nextc(b, offset, &offset);
             if (c == ':')
                 break;
-            if (!isdigit(c))
+            if (!css_isdigit(c))
                 goto next_line;
             line_num = line_num * 10 + c - '0';
         }

Index: tty.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/tty.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- tty.c       12 Dec 2007 11:49:03 -0000      1.24
+++ tty.c       15 Dec 2007 16:02:47 -0000      1.25
@@ -26,7 +26,6 @@
 #include <termios.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <ctype.h>
 #include <signal.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
@@ -413,7 +412,7 @@
         }
         break;
     case IS_CSI:
-        if (isdigit(ch)) {
+        if (css_isdigit(ch)) {
             ts->input_param = ts->input_param * 10 + ch - '0';
             break;
         }

Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- util.c      13 Dec 2007 23:13:11 -0000      1.24
+++ util.c      15 Dec 2007 16:02:48 -0000      1.25
@@ -359,17 +359,108 @@
     const char *p;
 
     p = *pp;
-    while (css_is_space(*p))
+    while (css_isspace(*p))
         p++;
     *pp = p;
 }
 
-/* need this for >= 256 */
-static inline int utoupper(int c)
+/**
+ * Return TRUE if val is a prefix of str (case independent). If it
+ * returns TRUE, ptr is set to the next character in 'str' after the
+ * prefix.
+ *
+ * @param str input string
+ * @param val prefix to test
+ * @param ptr updated after the prefix in str in there is a match
+ * @return TRUE if there is a match */
+int stristart(const char *str, const char *val, const char **ptr)
 {
-    if (c >= 'a' && c <= 'z')
-        c += 'A' - 'a';
-    return c;
+    const char *p, *q;
+
+    p = str;
+    q = val;
+    while (*q != '\0') {
+        if (css_toupper((unsigned char)*p) != css_toupper((unsigned char)*q)) {
+            return 0;
+        }
+        p++;
+        q++;
+    }
+    if (ptr)
+        *ptr = p;
+    return 1;
+}
+
+/**
+ * Return TRUE if val is a prefix of str (case independent). If it
+ * returns TRUE, ptr is set to the next character in 'str' after the
+ * prefix.
+ *
+ * Spaces, dashes and underscores are also ignored in this comparison.
+ *
+ * @param str input string
+ * @param val prefix to test
+ * @param ptr updated after the prefix in str in there is a match
+ * @return TRUE if there is a match */
+int strxstart(const char *str, const char *val, const char **ptr)
+{
+    const char *p, *q;
+    p = str;
+    q = val;
+    while (*q != '\0') {
+        if (css_toupper((unsigned char)*p) != css_toupper((unsigned char)*q)) {
+            if (*p == '-' || *p == '_' || *p == ' ') {
+                p++;
+                continue;
+            }
+            if (*q == '-' || *q == '_' || *q == ' ') {
+                q++;
+                continue;
+            }
+            return 0;
+        }
+        p++;
+        q++;
+    }
+    if (ptr)
+        *ptr = p;
+    return 1;
+}
+
+/**
+ * Compare strings str1 and str2 case independently.
+ * Spaces, dashes and underscores are also ignored in this comparison.
+ *
+ * @param str1 input string 1 (left operand)
+ * @param str2 input string 2 (right operand)
+ * @return -1, 0, +1 reflecting the sign of str1 <=> str2
+ */
+int strxcmp(const char *str1, const char *str2)
+{
+    const char *p, *q;
+    int d;
+    
+    p = str1;
+    q = str2;
+    for (;;) {
+        d = css_toupper((unsigned char)*p) - css_toupper((unsigned char)*q);
+        if (d) {
+            if (*p == '-' || *p == '_' || *p == ' ') {
+                p++;
+                continue;
+            }
+            if (*q == '-' || *q == '_' || *q == ' ') {
+                q++;
+                continue;
+            }
+            return d < 0 ? -1 : +1;
+        }
+        if (!*p)
+            break;
+        p++;
+        q++;
+    }
+    return 0;
 }
 
 int ustristart(const unsigned int *str, const char *val,
@@ -380,7 +471,7 @@
     p = str;
     q = val;
     while (*q != '\0') {
-        if (utoupper(*p) != utoupper(*q))
+        if (css_toupper(*p) != css_toupper(*q))
             return 0;
         p++;
         q++;
@@ -405,7 +496,7 @@
     for (;;) {
         c = *p;
         /* Should stop on spaces and eat them */
-        if (c == '\0' || css_is_space(c) || strchr(stop, c))
+        if (c == '\0' || css_isspace(c) || strchr(stop, c))
             break;
         if ((q - buf) < buf_size - 1)
             *q++ = c;
@@ -516,7 +607,7 @@
     if (p[0] == 'f' && p[1] >= '1' && p[1] <= '9') {
         i = p[1] - '0';
         p += 2;
-        if (p1 == isdigit((unsigned char)*p))
+        if (css_isdigit(*p))
             i = i * 10 + *p++ - '0';
         key = KEY_F1 + i - 1;
         *pp = p1;
@@ -544,7 +635,7 @@
         p += 2;
         key = KEY_META(strtokey1(&p));
     } else
-    if (p[0] == 'C' && p[1] == '-' && p[0] == 'M' && p[1] == '-') {
+    if (p[0] == 'C' && p[1] == '-' && p[2] == 'M' && p[3] == '-') {
         p += 4;
         key = KEY_META(KEY_CTRL(strtokey1(&p)));
     } else {
@@ -609,7 +700,7 @@
 
 int to_hex(int key)
 {
-    if (key >= '0' && key <= '9')
+    if (css_isdigit(key))
         return key - '0';
     else if (key >= 'a' && key <= 'f')
         return key - 'a' + 10;
@@ -664,7 +755,7 @@
     def = custom_colors;
     count = nb_css_colors + nb_custom_colors;
     while (count > 0) {
-        if (stristart(def->name, input, NULL))
+        if (strxstart(def->name, input, NULL))
             add_string(cs, def->name);
         def++;
         count--;
@@ -675,7 +766,7 @@
                                   const char *name)
 {
     while (count > 0) {
-        if (!stricmp(def->name, name)) {
+        if (!strxcmp(def->name, name)) {
             return def;
         }
         def++;
@@ -736,7 +827,7 @@
     }
     
     rgba[3] = 0xff;
-    if (isxdigit((unsigned char)*p)) {
+    if (css_isxdigit((unsigned char)*p)) {
         goto parse_num;
     } else if (*p == '#') {
         /* handle '#' notation */
@@ -832,10 +923,9 @@
 {
     int c;
 
-    /* XXX: handle unicode */
-    while (*buf) {
-        c = tolower((unsigned char)*buf);
-        *buf++ = c;
+    /* XXX: handle unicode / utf8 */
+    while ((c = (unsigned char)*buf) != '\0') {
+        *buf++ = css_tolower(c);
     }
 }
 
@@ -1088,4 +1178,3 @@
         *(void **)pp = p;
     return p;
 }
-

Index: buffer.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/buffer.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- buffer.c    15 Dec 2007 07:24:03 -0000      1.16
+++ buffer.c    15 Dec 2007 16:02:48 -0000      1.17
@@ -1522,7 +1522,7 @@
         c = eb_nextc(b, offset, &offset);
         if (c == '\n')
             return 1;
-        if (!isspace(c))
+        if (!css_isspace(c))
             break;
     }
     return 0;

Index: charset.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/charset.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- charset.c   12 Dec 2007 11:49:02 -0000      1.11
+++ charset.c   15 Dec 2007 16:02:48 -0000      1.12
@@ -264,13 +264,13 @@
     const char *p, *q;
 
     for (charset = first_charset; charset != NULL; charset = charset->next) {
-        if (stristart(charset->name, input, NULL))
+        if (strxstart(charset->name, input, NULL))
             add_string(cs, charset->name);
         for (q = p = charset->aliases;; q++) {
             if (*q == '\0' || *q == '|') {
                 if (q > p) {
                     pstrncpy(name, sizeof(name), p, q - p);
-                    if (stristart(name, input, NULL))
+                    if (strxstart(name, input, NULL))
                         add_string(cs, name);
                 }
                 if (*q == '\0')
@@ -286,7 +286,7 @@
     QECharset *charset;
 
     for (charset = first_charset; charset != NULL; charset = charset->next) {
-        if (!stricmp(charset->name, name)
+        if (!strxcmp(charset->name, name)
         ||  strfind(charset->aliases, name, 1)) {
             return charset;
         }

Index: clang.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/clang.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- clang.c     15 Dec 2007 09:57:21 -0000      1.14
+++ clang.c     15 Dec 2007 16:02:48 -0000      1.15
@@ -38,18 +38,13 @@
 
     c = *p;
     q = buf;
-    if ((c >= 'a' && c <= 'z') ||
-        (c >= 'A' && c <= 'Z') || 
-        (c == '_')) {
+    if (css_isalpha(c) || c == '_') {
         do {
             if ((q - buf) < buf_size - 1)
                 *q++ = c;
             p++;
             c = *p;
-        } while ((c >= 'a' && c <= 'z') ||
-                 (c >= 'A' && c <= 'Z') ||
-                 (c == '_') ||
-                 (c >= '0' && c <= '9'));
+        } while (css_isalnum(c) || c == '_');
     }
     *q = '\0';
     return q - buf;
@@ -196,18 +191,16 @@
         normal:
             if (state & C_PREPROCESS)
                 break;
-            if (c >= '0' && c <= '9') {
-                while (!(p & 0x7f) && (isalnum(*p) || *p == '.')) {
+            if (css_isdigit(c)) {
+                while (css_isalnum(*p) || *p == '.') {
                     p++;
                 }
                 set_color(p_start, p, QE_STYLE_NUMBER);
                 continue;
             }
-            if ((c >= 'a' && c <= 'z') ||
-                (c >= 'A' && c <= 'Z') || 
-                (c == '_')) {
+            if (css_isalpha(c) || c == '_') {
                 
-                /* XXX: should support :: */
+                /* XXX: should support :: and $ */
                 klen = 0;
                 p--;
                 do {
@@ -215,17 +208,14 @@
                         kbuf[klen++] = c;
                     p++;
                     c = *p;
-                } while ((c >= 'a' && c <= 'z') ||
-                         (c >= 'A' && c <= 'Z') ||
-                         (c == '_') ||
-                         (c >= '0' && c <= '9'));
+                } while (css_isalnum(c) || c == '_');
 
                 kbuf[klen] = '\0';
                 p1 = p;
-                while (*p1 == ' ' || *p1 == '\t')
+                while (css_isblank(*p1))
                     p1++;
                 p2 = p1;
-                while (*p2 == '*' || *p2 == ' ' || *p2 == '\t')
+                while (*p2 == '*' || css_isblank(*p2))
                     p2++;
                 if (strfind(c_keywords, kbuf, 0)) {
                     set_color(p_start, p, QE_STYLE_KEYWORD);

Index: cutils.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- cutils.h    3 Dec 2007 16:10:38 -0000       1.9
+++ cutils.h    15 Dec 2007 16:02:48 -0000      1.10
@@ -23,20 +23,19 @@
 
 #include <stdlib.h>
 
+/* These definitions prevent a clash with ffmpeg's cutil module. */
+
+#define strstart(str, val, ptr)    qe_strstart(str, val, ptr)
+#define pstrcpy(buf, sz, str)      qe_pstrcpy(buf, sz, str)
+#define pstrcat(buf, sz, str)      qe_pstrcat(buf, sz, str)
+#define pstrncpy(buf, sz, str, n)  qe_pstrncpy(buf, sz, str, n)
+
 int strstart(const char *str, const char *val, const char **ptr);
-int stristart(const char *str, const char *val, const char **ptr);
-int stricmp(const char *str1, const char *str2);
 void pstrcpy(char *buf, int buf_size, const char *str);
 char *pstrcat(char *buf, int buf_size, const char *s);
-
-/* CG: These definitions should be moved to a different header to
- * avoid conflict with ffmpeg's cutil module.
- */
 char *pstrncpy(char *buf, int buf_size, const char *s, int len);
 
-/* list.c */
-
-/* Double linked lists. Same api as the linux kernel */
+/* Double linked lists. Same API as the linux kernel */
 
 struct list_head {
     struct list_head *next, *prev;

Index: cutils.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cutils.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- cutils.c    6 Dec 2007 17:59:23 -0000       1.10
+++ cutils.c    15 Dec 2007 16:02:48 -0000      1.11
@@ -18,19 +18,12 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <string.h>
-#include <stdarg.h>
-#include <ctype.h>
 
 #include "cutils.h"
 
-#if !defined(CONFIG_NOCUTILS)
-/* these functions are defined in ffmpeg/libavformat/cutils.c and
- * conflict with this module because of extra functions referenced
- * in the ffmpeg module.  This module should not be linked with
- * qemacs with ffmpeg support.
+/* these functions are duplicated from ffmpeg/libavformat/cutils.c
+ * conflict is resolved by redefining the symbols in cutils.h
  */
 
 /**
@@ -58,85 +51,6 @@
     return 1;
 }
 
-#if 0
-/* need this for >= 256 */
-static inline int utoupper(int c)
-{
-    if (c >= 'a' && c <= 'z')
-        c += 'A' - 'a';
-    return c;
-}
-#endif
-
-/**
- * Return TRUE if val is a prefix of str (case independent).
- * If it returns TRUE, ptr is set to the next character in 'str' after
- * the prefix.
- * Spaces, dashes and underscores are also ignored in this comparison.
- *
- * @param str input string
- * @param val prefix to test
- * @param ptr updated after the prefix in str in there is a match
- * @return TRUE if there is a match */
-int stristart(const char *str, const char *val, const char **ptr)
-{
-    const char *p, *q;
-    p = str;
-    q = val;
-    while (*q != '\0') {
-        if (toupper((unsigned char)*p) != toupper((unsigned char)*q)) {
-            if (*p == '-' || *p == '_' || *p == ' ') {
-                p++;
-                continue;
-            }
-            if (*q == '-' || *q == '_' || *q == ' ') {
-                q++;
-                continue;
-            }
-            return 0;
-        }
-        p++;
-        q++;
-    }
-    if (ptr)
-        *ptr = p;
-    return 1;
-}
-
-/**
- * Compare strings str1 and str2 case independently.
- * Spaces, dashes and underscores are also ignored in this comparison.
- *
- * @param str1 input string 1 (left operand)
- * @param str2 input string 2 (right operand)
- * @return -1, 0, +1 reflecting the sign of str1 <=> str2
- */
-int stricmp(const char *str1, const char *str2)
-{
-    const char *p, *q;
-    p = str1;
-    q = str2;
-    for (;;) {
-        if (toupper((unsigned char)*p) != toupper((unsigned char)*q)) {
-            if (*p == '-' || *p == '_' || *p == ' ') {
-                p++;
-                continue;
-            }
-            if (*q == '-' || *q == '_' || *q == ' ') {
-                q++;
-                continue;
-            }
-            return (toupper((unsigned char)*p) <
-                    toupper((unsigned char)*q)) ? -1 : +1;
-        }
-        if (!*p)
-            break;
-        p++;
-        q++;
-    }
-    return 0;
-}
-
 /**
  * Copy the string str to buf. If str length is bigger than buf_size -
  * 1 then it is clamped to buf_size - 1.
@@ -167,8 +81,8 @@
 /* strcat and truncate. */
 char *pstrcat(char *buf, int buf_size, const char *s)
 {
-    int len;
-    len = strlen(buf);
+    int len = strlen(buf);
+
     if (len < buf_size) 
         pstrcpy(buf + len, buf_size - len, s);
     return buf;
@@ -195,5 +109,3 @@
     }
     return buf;
 }
-
-#endif

Index: dired.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/dired.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- dired.c     12 Dec 2007 11:49:02 -0000      1.11
+++ dired.c     15 Dec 2007 16:02:48 -0000      1.12
@@ -177,7 +177,7 @@
     const char *p;
     
     for (p = sort_order; *p; p++) {
-        switch (tolower((unsigned char)*p)) {
+        switch (css_tolower((unsigned char)*p)) {
         case 'n':       /* name */
             hs->sort_mode &= ~DIRED_SORT_MASK;
             hs->sort_mode |= DIRED_SORT_NAME;

Index: latex-mode.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- latex-mode.c        15 Dec 2007 07:32:45 -0000      1.17
+++ latex-mode.c        15 Dec 2007 16:02:48 -0000      1.18
@@ -206,7 +206,7 @@
     struct latex_function *func;
 
     for (func = latex_funcs; func->name; func++) {
-        if (stristart(func->name, input, NULL))
+        if (strxstart(func->name, input, NULL))
             add_string(cs, func->name);
     }
 }
@@ -216,7 +216,7 @@
     struct latex_function *func;
 
     for (func = latex_funcs; func->name; func++) {
-        if (!stricmp(func->name, name))
+        if (!strxcmp(func->name, name))
             return func;
     }
     return NULL;

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- qe.h        15 Dec 2007 07:34:44 -0000      1.34
+++ qe.h        15 Dec 2007 16:02:48 -0000      1.35
@@ -27,7 +27,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <ctype.h>
 #include <signal.h>
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -158,8 +157,52 @@
 void splitpath(char *dirname, int dirname_size,
                char *filename, int filename_size, const char *pathname);
 
-int strfind(const char *keytable, const char *str, int casefold);
+static inline int css_isspace(int ch) {
+    /* CG: what about \v and \f */
+    return (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
+}
+static inline int css_isblank(int ch) {
+    return (ch == ' ' || ch == '\t');
+}
+static inline int css_isdigit(int ch) {
+    return (ch >= '0' && ch <= '9');
+}
+static inline int css_isupper(int ch) {
+    return (ch >= 'A' && ch <= 'Z');
+}
+static inline int css_islower(int ch) {
+    return (ch >= 'a' && ch <= 'z');
+}
+static inline int css_isalpha(int ch) {
+    return ((ch | ('a' - 'A')) >= 'a' && (ch | ('a' - 'A')) <= 'z');
+}
+static inline int css_isxdigit(int ch) {
+    return ((ch >= '0' && ch <= '9') ||
+            ((ch | ('a' - 'A')) >= 'a' && (ch | ('a' - 'A')) <= 'f'));
+}
+static inline int css_isalnum(int ch) {
+    return ((ch >= '0' && ch <= '9') ||
+            ((ch | ('a' - 'A')) >= 'a' && (ch | ('a' - 'A')) <= 'z'));
+}
+static inline int css_isword(int c) {
+    /* XXX: any unicode char >= 128 is considered as word. */
+    return css_isalnum(c) || (c == '_') || (c >= 128);
+}
+static inline int css_toupper(int ch) {
+    return (ch >= 'a' && ch <= 'z') ? ch + 'A' - 'a' : ch;
+}
+static inline int css_tolower(int ch) {
+    return (ch >= 'A' && ch <= 'Z') ? ch + 'a' - 'A' : ch;
+}
+
+void css_strtolower(char *buf, int buf_size);
 void skip_spaces(const char **pp);
+
+int strfind(const char *keytable, const char *str, int casefold);
+#define stristart(str, val, ptr)   qe_stristart(str, val, ptr)
+int stristart(const char *str, const char *val, const char **ptr);
+int strxstart(const char *str, const char *val, const char **ptr);
+int strxcmp(const char *str1, const char *str2);
 int ustristart(const unsigned int *str, const char *val, const unsigned int 
**ptr);
 static inline void umemmove(unsigned int *dest, unsigned int *src, int len) {
     memmove(dest, src, len * sizeof(unsigned int));
@@ -193,13 +236,6 @@
               a->y1 >= b->y2));
 }
 
-/* CG: what about \v and \f */
-static inline int css_is_space(int ch) {
-    return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');
-}
-
-void css_strtolower(char *buf, int buf_size);
-
 int get_clock_ms(void);
 
 /* Various string packages: should unify these but keep API simple */
@@ -1359,7 +1395,6 @@
 void do_bol(EditState *s);
 void do_eol(EditState *s);
 void do_word_right(EditState *s, int dir);
-int isword(int c);
 int eb_next_paragraph(EditBuffer *b, int offset);
 int eb_start_paragraph(EditBuffer *b, int offset);
 void do_backward_paragraph(EditState *s);

Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- qe.c        15 Dec 2007 07:34:43 -0000      1.42
+++ qe.c        15 Dec 2007 16:02:48 -0000      1.43
@@ -431,15 +431,6 @@
     s->offset = eb_goto_eol(s->b, s->offset);
 }
 
-int isword(int c)
-{
-    /* XXX: any unicode char >= 128 is considered as word. */
-    return (c >= 'a' && c <= 'z') ||
-        (c >= 'A' && c <= 'Z') ||
-        (c >= '0' && c <= '9') ||
-        (c == '_') || (c >= 128);
-}
-
 static void word_right(EditState *s, int w)
 {
     int c, offset1;
@@ -448,7 +439,7 @@
         if (s->offset >= s->b->total_size)
             break;
         c = eb_nextc(s->b, s->offset, &offset1);
-        if (isword(c) == w)
+        if (css_isword(c) == w)
             break;
         s->offset = offset1;
     }
@@ -462,7 +453,7 @@
         if (s->offset == 0)
             break;
         c = eb_prevc(s->b, s->offset, &offset1);
-        if (isword(c) == w)
+        if (css_isword(c) == w)
             break;
         s->offset = offset1;
     }
@@ -581,7 +572,7 @@
     if (!eb_is_empty_line(s->b, offset)) {
         while (offset < par_end) {
             c = eb_nextc(s->b, offset, &offset);
-            if (!isspace(c))
+            if (!css_isspace(c))
                 break;
             indent_size++;
         }
@@ -598,7 +589,7 @@
         space_size = 0;
         while (offset < par_end) {
             c = eb_nextc(s->b, offset, &offset1);
-            if (!isspace(c))
+            if (!css_isspace(c))
                 break;
             offset = offset1;
             space_size++;
@@ -608,7 +599,7 @@
         word_size = 0;
         while (offset < par_end) {
             c = eb_nextc(s->b, offset, &offset1);
-            if (isspace(c))
+            if (css_isspace(c))
                 break;
             offset = offset1;
             word_size++;
@@ -659,16 +650,18 @@
    function). Return next offset */
 static int eb_changecase(EditBuffer *b, int offset, int up)
 {
-    int offset1, ch, len;
+    int offset1, ch, ch1, len;
     char buf[MAX_CHAR_BYTES];
 
     ch = eb_nextc(b, offset, &offset1);
-    if (ch < 128) {
         if (up)
-            ch = toupper(ch);
+        ch1 = css_toupper(ch);
         else
-            ch = tolower(ch);
-    }
+        ch1 = css_tolower(ch);
+
+    if (ch == ch1) {
+        return offset1;
+    } else {
     len = unicode_to_charset(buf, ch, b->charset);
     if (len == (offset1 - offset)) {
         eb_write(b, offset, buf, len);
@@ -677,6 +670,7 @@
         eb_insert(b, offset, buf, len);
     }
     return offset + len;
+    }
 }
 
 void do_changecase_word(EditState *s, int up)
@@ -688,7 +682,7 @@
         if (s->offset >= s->b->total_size)
             break;
         c = eb_nextc(s->b, s->offset, NULL);
-        if (!isword(c))
+        if (!css_isword(c))
             break;
         s->offset = eb_changecase(s->b, s->offset, up);
     }
@@ -3914,7 +3908,7 @@
         if (c->nb_keys == 1) {
             if (!KEY_SPECIAL(key)) {
                 if (c->is_universal_arg) {
-                    if (key >= '0' && key <= '9') {
+                    if (css_isdigit(key)) {
                         if (c->argval == NO_ARG)
                             c->argval = 0;
                         c->argval = c->argval * 10 + (key - '0');
@@ -5339,8 +5333,8 @@
         lower_count = 0;
         for (i = 0; i < size; i++) {
             c = buf[i];
-            lower_count += islower(c);
-            upper_count += isupper(c);
+            lower_count += css_islower(c);
+            upper_count += css_isupper(c);
         }
         if (lower_count > 0 && upper_count == 0)
             flags |= SEARCH_FLAG_IGNORECASE;
@@ -5350,7 +5344,7 @@
     for (i = 0; i < size; i++) {
         c = buf[i];
         if (flags & SEARCH_FLAG_IGNORECASE) 
-            buf1[i] = toupper(c);
+            buf1[i] = css_toupper(c);
         else
             buf1[i] = c;
     }
@@ -5379,7 +5373,7 @@
             if (offset == 0)
                 goto word_start_found;
             eb_read(b, offset - 1, &ch, 1);
-            if (!isword(ch))
+            if (!css_isword(ch))
                 goto word_start_found;
             else
                 continue;
@@ -5390,7 +5384,7 @@
         for (;;) {
             eb_read(b, offset + i, &ch, 1);
             if (flags & SEARCH_FLAG_IGNORECASE) 
-                ch = toupper(ch);
+                ch = css_toupper(ch);
             if (ch != buf1[i])
                     break;
             i++;
@@ -5400,7 +5394,7 @@
                     if (offset + size >= total_size)
                         goto word_end_found;
                     eb_read(b, offset + size, &ch, 1);
-                    if (!isword(ch))
+                    if (!css_isword(ch))
                         goto word_end_found;
                     break;
                 }

Index: ligtoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/ligtoqe.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ligtoqe.c   6 Dec 2007 17:59:23 -0000       1.5
+++ ligtoqe.c   15 Dec 2007 16:02:48 -0000      1.6
@@ -21,11 +21,17 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <ctype.h>
 #include <string.h>
+#include <ctype.h>
 #include <getopt.h>
 #include <assert.h>
 
+static inline char *skipspaces(char *p) {
+    while (isspace((unsigned char)*p))
+        p++;
+    return p;
+}
+
 static int unicode_to_utf8(char *buf, unsigned int c)
 {
     char *q;
@@ -138,13 +144,11 @@
     for (;;) {
         if (fgets(buf, sizeof(buf), f) == NULL)
             break;
-        p = buf + strlen(buf) - 1;
-        if (p >= buf && *p == '\n')
-            *p = '\0';
-        p = buf;
+        p = buf + strlen(buf);
+        if (p > buf && p[-1] == '\n')
+            *--p = '\0';
 
-        while (isspace((unsigned char)*p))
-            p++;
+        p = skipspaces(buf);
 
         if (*p == '#' || *p == '\0') {
             if (to_utf8) {
@@ -157,8 +161,7 @@
 
         l->buf_in_size = 0;
         for (;;) {
-            while (isspace((unsigned char)*p))
-                p++;
+            p = skipspaces(p);
             if (*p == '=')
                 break;
             if (*p == '\0') {
@@ -171,8 +174,7 @@
         
         l->buf_out_size = 0;
         for (;;) {
-            while (isspace((unsigned char)*p))
-                p++;
+            p = skipspaces(p);
             /* stop at the first comment */
             if (*p == '\0' || *p == '/')
                 break;

Index: kmaptoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/kmaptoqe.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- kmaptoqe.c  9 Dec 2007 23:31:39 -0000       1.7
+++ kmaptoqe.c  15 Dec 2007 16:02:48 -0000      1.8
@@ -21,8 +21,8 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <ctype.h>
 #include <string.h>
+#include <ctype.h>
 #include <assert.h>
 
 #ifndef countof

Index: cptoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/cptoqe.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- cptoqe.c    6 Dec 2007 17:59:23 -0000       1.8
+++ cptoqe.c    15 Dec 2007 16:02:48 -0000      1.9
@@ -143,7 +143,7 @@
             continue;
         }
 
-        if (p[0] != '0' || tolower((unsigned char)p[1]) != 'x') {
+        if (p[0] != '0' || (p[1] != 'x' && p[1] != 'X')) {
             if (!has_iso_name) {
                 strcpy(iso_name, p);
                 has_iso_name = 1;

Index: Makefile
===================================================================
RCS file: /cvsroot/qemacs/qemacs/Makefile,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- Makefile    10 Dec 2007 10:12:11 -0000      1.18
+++ Makefile    15 Dec 2007 16:02:48 -0000      1.19
@@ -116,11 +116,7 @@
 TARGETS+=qe$(EXE) qe-doc.html kmaps ligatures
 
 OBJS=qe.o charset.o buffer.o \
-     input.o unicode_join.o display.o util.o hex.o list.o 
-
-ifndef CONFIG_FFMPEG
-OBJS+= cutils.o
-endif
+     input.o unicode_join.o display.o util.o hex.o list.o cutils.o
 
 ifndef CONFIG_WIN32
 OBJS+= unix.o tty.o 

Index: libqhtml/css.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/css.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- libqhtml/css.c      12 Dec 2007 11:49:03 -0000      1.11
+++ libqhtml/css.c      15 Dec 2007 16:02:48 -0000      1.12
@@ -2314,7 +2314,7 @@
                         break;
                 }
 
-                space = css_is_space(ch);
+                space = css_isspace(ch);
                 /* collapse spaces if needed */
                 if (space && s->last_space &&
                     (props->white_space == CSS_WHITE_SPACE_NORMAL ||
@@ -3709,7 +3709,7 @@
         c = nextc(s->b, &offset);
         if (c == CSS_CONTENT_EOL)
             continue;
-        space = css_is_space(c);
+        space = css_isspace(c);
         if (space_collapse) {
             if (last_space && space)
                 continue;

Index: libqhtml/cssparse.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/cssparse.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- libqhtml/cssparse.c 12 Dec 2007 11:49:03 -0000      1.9
+++ libqhtml/cssparse.c 15 Dec 2007 16:02:48 -0000      1.10
@@ -61,11 +61,11 @@
     p1 = p;
     if (*p == '+' || *p == '-')
         p++;
-    while (isdigit((unsigned char)*p))
+    while (css_isdigit(*p))
         p++;
     if (*p == '.') {
         p++;
-        while (isdigit((unsigned char)*p))
+        while (css_isdigit(*p))
         p++;
     }
     len = p - p1;
@@ -677,27 +677,28 @@
 
 static int bgetc(CSSParseState *b)
 {
-    int ch;
- redo:
+    int ch, last;
+
+    for (;;) {
     ch = bgetc1(b);
-    if (ch == '/') {
+        if (ch != '/')
+            return ch;
+
         ch = bgetc1(b);
         if (ch != '*') {
             if (ch != EOF)
                 b->ptr--;
             return '/';
         }
+        last = 0;
         for (;;) {
             ch = bgetc1(b);
-            if (ch != '*')
-                continue;
-            ch = bgetc1(b);
-            if (ch == '/')
+            if (ch == EOF)
+                return ch;
+            if (ch == '/' && last == '*')
                 break;
+            last = ch;
         }
-        goto redo;
-    } else {
-        return ch;
     }
 }
 
@@ -729,10 +730,7 @@
     c = *ch_ptr;
     q = ident;
     for (;;) {
-        if (!((c >= 'A' && c <= 'Z') ||
-              (c >= 'a' && c <= 'z') ||
-              (c >= '0' && c <= '9') ||
-              c == '*' || c == '_' || c == '-'))
+        if (!(css_isalnum(c) || c == '*' || c == '_' || c == '-'))
             break;
         if ((q - ident) < ident_size - 1)
             *q++ = c;
@@ -747,7 +745,7 @@
     int c;
 
     c = *ch_ptr;
-    while (css_is_space(c))
+    while (css_isspace(c))
         c = bgetc(b);
     *ch_ptr = c;
 }
@@ -1054,11 +1052,13 @@
                     tree_op = CSS_TREE_OP_PRECEEDED;
                     ch = bgetc(b);
                     goto add_tree;
-                } else if (ch == '>') {
+                } else
+                if (ch == '>') {
                     tree_op = CSS_TREE_OP_CHILD;
                     ch = bgetc(b);
                     goto add_tree;
-                } else if (isalpha(ch)) {
+                } else
+                if (css_isalpha(ch)) {
                     tree_op = CSS_TREE_OP_DESCENDANT;
                 add_tree:
                     ss1 = qe_malloc_dup(ss, sizeof(CSSSimpleSelector));

Index: libqhtml/xmlparse.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/xmlparse.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- libqhtml/xmlparse.c 12 Dec 2007 11:49:03 -0000      1.12
+++ libqhtml/xmlparse.c 15 Dec 2007 16:02:48 -0000      1.13
@@ -1045,12 +1045,13 @@
     int d;
 
     while (*s2) {
-        d = (unsigned char)*s2 - tolower((unsigned char)*s1);
+        d = (unsigned char)*s2 - css_tolower((unsigned char)*s1);
         if (d)
             return d;
         s2++;
         s1++;
     }
+    /* XXX: Should only return 0 if (*s1) is separator */
     return 0;
 }
 




reply via email to

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