qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs arm.c ebnf.c icon.c qe.h clang.c extra-m...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs arm.c ebnf.c icon.c qe.h clang.c extra-m...
Date: Mon, 29 May 2017 02:21:42 -0400 (EDT)

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        17/05/29 02:21:42

Modified files:
        .              : arm.c ebnf.c icon.c qe.h clang.c extra-modes.c 
                         makemode.c util.c 

Log message:
        colorizers: some factorisation
        - pass initial character to `ustr_get_identifier` and `ustr_get_word`.
        - add lowercasing variant `ustr_get_identifier_lc()`
        - remove `get_word_lc()` in makemode.c
        - remove `get_js_identifier()` in clang.c

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/arm.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/ebnf.c?cvsroot=qemacs&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/qemacs/icon.c?cvsroot=qemacs&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.268&r2=1.269
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.131&r2=1.132
http://cvs.savannah.gnu.org/viewcvs/qemacs/extra-modes.c?cvsroot=qemacs&r1=1.65&r2=1.66
http://cvs.savannah.gnu.org/viewcvs/qemacs/makemode.c?cvsroot=qemacs&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.83&r2=1.84

Patches:
Index: arm.c
===================================================================
RCS file: /sources/qemacs/qemacs/arm.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- arm.c       15 Apr 2017 09:39:02 -0000      1.7
+++ arm.c       29 May 2017 06:21:42 -0000      1.8
@@ -198,8 +198,8 @@
     /* Combined assembly / C source / filename listing:
      * determine line type by looking at line start
      */
-    char keyword[16];
-    int i, w, start, c, len, colstate = cp->colorize_state;
+    char kbuf[16];
+    int i, w, start, c, colstate = cp->colorize_state;
 
     for (w = 0; qe_isblank(str[w]); w++)
         continue;
@@ -260,13 +260,8 @@
                     continue;
                 }
                 if (qe_isalpha_(c)) {
-                    keyword[0] = c;
-                    for (len = 1; qe_isalnum_(str[i]); i++) {
-                        if (len < countof(keyword) - 1)
-                            keyword[len++] = str[i];
-                    }
-                    keyword[len] = '\0';
-                    if (strfind(syn->keywords, keyword))
+                    i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, 
n);
+                    if (strfind(syn->keywords, kbuf))
                         SET_COLOR(str, start, i, LST_STYLE_KEYWORD);
                     continue;
                 }

Index: ebnf.c
===================================================================
RCS file: /sources/qemacs/qemacs/ebnf.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ebnf.c      16 Apr 2017 21:51:20 -0000      1.5
+++ ebnf.c      29 May 2017 06:21:42 -0000      1.6
@@ -60,8 +60,8 @@
 static void ebnf_colorize_line(QEColorizeContext *cp,
                                unsigned int *str, int n, ModeDef *syn)
 {
-    char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start = 0, c, style, len;
+    char kbuf[MAX_KEYWORD_SIZE];
+    int i = 0, start = 0, c, style;
     int colstate = cp->colorize_state;
 
     if (colstate & IN_EBNF_COMMENT1)
@@ -164,22 +164,12 @@
             }
             /* parse identifiers and keywords */
             if (qe_isalpha_(c) || c == U_HORIZONTAL_ELLIPSIS) {
-                len = 0;
-                keyword[len++] = c;
-                for (; i < n; i++) {
-                    if (qe_isalnum_(str[i])) {
-                        if (len < countof(keyword) - 1)
-                            keyword[len++] = c;
-                    } else {
-                        break;
-                    }
-                }
-                keyword[len] = '\0';
-                if (strfind(syn->keywords, keyword)) {
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
+                if (strfind(syn->keywords, kbuf)) {
                     style = EBNF_STYLE_KEYWORD;
                     break;
                 }
-                if (strfind(syn->types, keyword)) {
+                if (strfind(syn->types, kbuf)) {
                     style = EBNF_STYLE_TYPE;
                     break;
                 }

Index: icon.c
===================================================================
RCS file: /sources/qemacs/qemacs/icon.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- icon.c      17 Apr 2017 09:16:24 -0000      1.7
+++ icon.c      29 May 2017 06:21:42 -0000      1.8
@@ -154,14 +154,7 @@
                 break;
             }
             if (qe_isalpha_(c) || (c == '$' && qe_isalnum_(str[i]))) {
-                klen = 0;
-                kbuf[klen++] = c;
-                while (qe_isalnum_(c = str[i])) {
-                    if (klen < countof(kbuf) - 1)
-                        kbuf[klen++] = c;
-                    i++;
-                }
-                kbuf[klen] = '\0';
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
 
                 if (start == indent && kbuf[0] == '$'
                 &&  strfind(icon_directives, kbuf + 1)) {

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.268
retrieving revision 1.269
diff -u -b -r1.268 -r1.269
--- qe.h        21 May 2017 07:57:19 -0000      1.268
+++ qe.h        29 May 2017 06:21:42 -0000      1.269
@@ -435,9 +435,11 @@
     return str[i] == '(';
 }
 
-int ustr_get_identifier(char *buf, int buf_size,
+int ustr_get_identifier(char *buf, int buf_size, int c,
                         const unsigned int *str, int i, int n);
-int ustr_get_word(char *buf, int buf_size,
+int ustr_get_identifier_lc(char *buf, int buf_size, int c,
+                           const unsigned int *str, int i, int n);
+int ustr_get_word(char *buf, int buf_size, int c,
                   const unsigned int *str, int i, int n);
 
 int qe_strcollate(const char *s1, const char *s2);

Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -b -r1.131 -r1.132
--- clang.c     18 May 2017 14:09:56 -0000      1.131
+++ clang.c     29 May 2017 06:21:42 -0000      1.132
@@ -1549,32 +1549,11 @@
     "void|var|"
 };
 
-static int get_js_identifier(char *buf, int buf_size, unsigned int *p)
-{
-    unsigned int c;
-    int i, j;
-
-    i = j = 0;
-    c = p[i];
-    if (qe_isalpha_(c) || c == '$') {
-        for (;;) {
-            if (j < buf_size - 1)
-                buf[j++] = (c < 0xFF) ? c : 0xFF;
-            i++;
-            c = p[i];
-            if (!qe_isalnum_(c))
-                break;
-        }
-    }
-    buf[j] = '\0';
-    return i;
-}
-
 static void js_colorize_line(QEColorizeContext *cp,
                              unsigned int *str, int n, ModeDef *syn)
 {
     int i = 0, start, i1, indent;
-    int c, style, klen, delim, prev, tag;
+    int c, style, delim, prev, tag;
     char kbuf[64];
     int mode_flags = syn->colorize_flags;
     int flavor = (mode_flags & CLANG_FLAVOR);
@@ -1759,9 +1738,7 @@
                 break;
             }
             if (qe_isalpha_(c) || c == '$') {
-                klen = get_js_identifier(kbuf, countof(kbuf), str + start);
-                i = start + klen;
-
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
                 if (cp->state_only && !tag)
                     continue;
 

Index: extra-modes.c
===================================================================
RCS file: /sources/qemacs/qemacs/extra-modes.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -b -r1.65 -r1.66
--- extra-modes.c       21 May 2017 07:57:19 -0000      1.65
+++ extra-modes.c       29 May 2017 06:21:42 -0000      1.66
@@ -208,8 +208,8 @@
 static void basic_colorize_line(QEColorizeContext *cp,
                                 unsigned int *str, int n, ModeDef *syn)
 {
-    char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start, c, style, len;
+    char kbuf[MAX_KEYWORD_SIZE];
+    int i = 0, start, c, style;
 
     while (i < n) {
         start = i;
@@ -244,24 +244,15 @@
         }
         /* parse identifiers and keywords */
         if (qe_isalpha_(c)) {
-            len = 0;
-            keyword[len++] = qe_tolower(c);
-            for (; i < n; i++) {
-                if (qe_isalnum_(str[i])) {
-                    if (len < countof(keyword) - 1)
-                        keyword[len++] = qe_tolower(str[i]);
-                } else {
-                    if (qe_findchar("$&address@hidden", str[i]))
+            i += ustr_get_identifier_lc(kbuf, countof(kbuf), c, str, i, n);
+            if (i < n && qe_findchar("$&address@hidden", str[i]))
                         i++;
-                    break;
-                }
-            }
-            keyword[len] = '\0';
-            if (strfind(syn->keywords, keyword)) {
+
+            if (strfind(syn->keywords, kbuf)) {
                 SET_COLOR(str, start, i, BASIC_STYLE_KEYWORD);
                 continue;
             }
-            if (strfind(syn->types, keyword)) {
+            if (strfind(syn->types, kbuf)) {
                 SET_COLOR(str, start, i, BASIC_STYLE_TYPE);
                 continue;
             }
@@ -575,8 +566,8 @@
 static void pascal_colorize_line(QEColorizeContext *cp,
                                  unsigned int *str, int n, ModeDef *syn)
 {
-    char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start = i, c, k, style = 0, len;
+    char kbuf[MAX_KEYWORD_SIZE];
+    int i = 0, start = i, c, k, style = 0;
     int colstate = cp->colorize_state;
 
     if (colstate & IN_PASCAL_COMMENT)
@@ -666,17 +657,11 @@
             }
             /* parse identifiers and keywords */
             if (qe_isalpha_(c)) {
-                len = 0;
-                keyword[len++] = qe_tolower(c);
-                for (; qe_isalnum_(str[i]); i++) {
-                    if (len < countof(keyword) - 1)
-                        keyword[len++] = qe_tolower(str[i]);
-                }
-                keyword[len] = '\0';
-                if (strfind(syn->keywords, keyword)) {
+                i += ustr_get_identifier_lc(kbuf, countof(kbuf), c, str, i, n);
+                if (strfind(syn->keywords, kbuf)) {
                     style = PASCAL_STYLE_KEYWORD;
                 } else
-                if (strfind(syn->types, keyword)) {
+                if (strfind(syn->types, kbuf)) {
                     style = PASCAL_STYLE_TYPE;
                 } else {
                     k = i;
@@ -755,8 +740,8 @@
 static void ada_colorize_line(QEColorizeContext *cp,
                                  unsigned int *str, int n, ModeDef *syn)
 {
-    char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start = i, c, k, style, len;
+    char kbuf[MAX_KEYWORD_SIZE];
+    int i = 0, start = i, c, k, style;
     int colstate = cp->colorize_state;
 
     if (colstate & IN_ADA_COMMENT1)
@@ -849,17 +834,11 @@
         }
         /* parse identifiers and keywords */
         if (qe_isalpha_(c)) {
-            len = 0;
-            keyword[len++] = qe_tolower(c);
-            for (; qe_isalnum_(str[i]); i++) {
-                if (len < countof(keyword) - 1)
-                    keyword[len++] = qe_tolower(str[i]);
-            }
-            keyword[len] = '\0';
-            if (strfind(syn->keywords, keyword)) {
+            i += ustr_get_identifier_lc(kbuf, countof(kbuf), c, str, i, n);
+            if (strfind(syn->keywords, kbuf)) {
                 style = ADA_STYLE_KEYWORD;
             } else
-            if (strfind(syn->types, keyword)) {
+            if (strfind(syn->types, kbuf)) {
                 style = ADA_STYLE_TYPE;
             } else
             if (check_fcall(str, i))
@@ -1430,8 +1409,8 @@
 static void sql_colorize_line(QEColorizeContext *cp,
                               unsigned int *str, int n, ModeDef *syn)
 {
-    char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start = i, c, style, len;
+    char kbuf[MAX_KEYWORD_SIZE];
+    int i = 0, start = i, c, style;
     int state = cp->colorize_state;
 
     if (state & IN_SQL_COMMENT)
@@ -1494,22 +1473,12 @@
         }
         /* parse identifiers and keywords */
         if (qe_isalpha_(c)) {
-            len = 0;
-            keyword[len++] = qe_tolower(c);
-            for (; i < n; i++) {
-                if (qe_isalnum_(str[i])) {
-                    if (len < countof(keyword) - 1)
-                        keyword[len++] = qe_tolower(str[i]);
-                } else {
-                    break;
-                }
-            }
-            keyword[len] = '\0';
-            if (strfind(syn->keywords, keyword)) {
+            i += ustr_get_identifier_lc(kbuf, countof(kbuf), c, str, i, n);
+            if (strfind(syn->keywords, kbuf)) {
                 SET_COLOR(str, start, i, SQL_STYLE_KEYWORD);
                 continue;
             }
-            if (strfind(syn->types, keyword)) {
+            if (strfind(syn->types, kbuf)) {
                 SET_COLOR(str, start, i, SQL_STYLE_TYPE);
                 continue;
             }
@@ -1600,7 +1569,7 @@
 static void lua_colorize_line(QEColorizeContext *cp,
                               unsigned int *str, int n, ModeDef *syn)
 {
-    int i = 0, start = i, c, sep = 0, level = 0, level1, klen, style;
+    int i = 0, start = i, c, sep = 0, level = 0, level1, style;
     int state = cp->colorize_state;
     char kbuf[64];
 
@@ -1694,12 +1663,7 @@
                 continue;
             }
             if (qe_isalpha_(c)) {
-                for (klen = 0, i--; qe_isalnum_(str[i]); i++) {
-                    if (klen < countof(kbuf) - 1)
-                        kbuf[klen++] = str[i];
-                }
-                kbuf[klen] = '\0';
-
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
                 if (strfind(syn->keywords, kbuf)) {
                     SET_COLOR(str, start, i, LUA_STYLE_KEYWORD);
                     continue;
@@ -2276,7 +2240,7 @@
 static void coffee_colorize_line(QEColorizeContext *cp,
                                  unsigned int *str, int n, ModeDef *syn)
 {
-    int i = 0, start = i, c, style = 0, sep, klen, prev, i1;
+    int i = 0, start = i, c, style = 0, sep, prev, i1;
     int state = cp->colorize_state;
     char kbuf[64];
 
@@ -2539,12 +2503,7 @@
                 break;
             }
             if (qe_isalpha_(c)) {
-                for (klen = 0, i--; qe_isalnum_(str[i]); i++) {
-                    if (klen < countof(kbuf) - 1)
-                        kbuf[klen++] = str[i];
-                }
-                kbuf[klen] = '\0';
-
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
                 if (strfind(syn->keywords, kbuf)) {
                     style = COFFEE_STYLE_KEYWORD;
                     break;
@@ -2623,7 +2582,7 @@
 static void python_colorize_line(QEColorizeContext *cp,
                                  unsigned int *str, int n, ModeDef *syn)
 {
-    int i = 0, start = i, c, style = 0, sep, klen, i1, tag = 0;
+    int i = 0, start = i, c, style = 0, sep, i1, tag = 0;
     int state = cp->colorize_state;
     char kbuf[64];
 
@@ -2780,12 +2739,7 @@
             }
         has_alpha:
             if (qe_isalpha_(c)) {
-                for (klen = 0, i--; qe_isalnum_(str[i]); i++) {
-                    if (klen < countof(kbuf) - 1)
-                        kbuf[klen++] = str[i];
-                }
-                kbuf[klen] = '\0';
-
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
                 if (strfind(syn->keywords, kbuf)) {
                     tag = strequal(kbuf, "def");
                     style = PYTHON_STYLE_KEYWORD;
@@ -4252,8 +4206,8 @@
 static void agena_colorize_line(QEColorizeContext *cp,
                                 unsigned int *str, int n, ModeDef *syn)
 {
-    char keyword[MAX_KEYWORD_SIZE];
-    int i = 0, start = i, c, style = 0, sep = 0, len;
+    char kbuf[MAX_KEYWORD_SIZE];
+    int i = 0, start = i, c, style = 0, sep = 0;
     int state = cp->colorize_state;
 
     if (state & IN_AGENA_COMMENT)
@@ -4317,17 +4271,11 @@
         default:
             /* parse identifiers and keywords */
             if (qe_isalpha_(c)) {
-                len = 0;
-                keyword[len++] = c;
-                for (; i < n && qe_isalnum_(str[i]); i++) {
-                    if (len < countof(keyword) - 1)
-                        keyword[len++] = str[i];
-                }
-                keyword[len] = '\0';
-                if (strfind(syn->keywords, keyword))
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
+                if (strfind(syn->keywords, kbuf))
                     style = AGENA_STYLE_KEYWORD;
                 else
-                if (strfind(syn->types, keyword))
+                if (strfind(syn->types, kbuf))
                     style = AGENA_STYLE_TYPE;
                 else
                 if (check_fcall(str, i))
@@ -4871,9 +4819,7 @@
                 break;
             }
             if (qe_isalpha_(c)) {
-                i--;
-                i += ustr_get_identifier(kbuf, countof(kbuf), str, i, n);
-
+                i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n);
                 if (strfind(syn->keywords, kbuf)) {
                     style = MAGPIE_STYLE_KEYWORD;
                     break;
@@ -5080,9 +5026,7 @@
                 break;
             }
             if (qe_isalpha_(c) || c > 0xA0) {
-                i--;
-                i += ustr_get_word(kbuf, countof(kbuf), str, i, n);
-
+                i += ustr_get_word(kbuf, countof(kbuf), c, str, i, n);
                 if (strfind(syn->keywords, kbuf)) {
                     style = FALCON_STYLE_KEYWORD;
                     break;

Index: makemode.c
===================================================================
RCS file: /sources/qemacs/qemacs/makemode.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- makemode.c  15 Apr 2017 09:39:02 -0000      1.29
+++ makemode.c  29 May 2017 06:21:42 -0000      1.30
@@ -22,28 +22,6 @@
 
 /*---------------- Makefile colors ----------------*/
 
-/* grab an identifier from a uint buf, stripping color.
- * return char count.
- */
-static int get_word_lc(char *buf, int buf_size, unsigned int *p)
-{
-    unsigned int c;
-    int i, j;
-
-    i = j = 0;
-    c = p[i];
-    if (qe_isalpha_(c)) {
-        do {
-            if (j < buf_size - 1)
-                buf[j++] = qe_tolower(c);
-            i++;
-            c = p[i];
-        } while (qe_isalnum_(c));
-    }
-    buf[j] = '\0';
-    return i;
-}
-
 enum {
     MAKEFILE_STYLE_TEXT       = QE_STYLE_DEFAULT,
     MAKEFILE_STYLE_COMMENT    = QE_STYLE_COMMENT,
@@ -63,7 +41,7 @@
     unsigned int c;
 
     if (qe_isalpha_(str[i])) {
-        get_word_lc(buf, countof(buf), str);
+        ustr_get_identifier_lc(buf, countof(buf), str[i], str, i + 1, n);
         if (strfind("ifeq|ifneq|ifdef|ifndef|include|else|endif", buf))
             goto preprocess;
     }
@@ -245,8 +223,7 @@
             continue;
         default:
             if (qe_isalpha_(c)) {
-                i -= 1;
-                i += get_word_lc(buf, countof(buf), str + i);
+                i += ustr_get_identifier_lc(buf, countof(buf), c, str, i, n);
                 if (strfind("if|else|endif|set|true|false|include", buf)) {
                     SET_COLOR(str, start, i, CMAKE_STYLE_KEYWORD);
                 } else

Index: util.c
===================================================================
RCS file: /sources/qemacs/qemacs/util.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -b -r1.83 -r1.84
--- util.c      21 May 2017 07:57:19 -0000      1.83
+++ util.c      29 May 2017 06:21:42 -0000      1.84
@@ -908,17 +908,43 @@
     return 0;
 }
 
-int ustr_get_identifier(char *buf, int buf_size,
+int ustr_get_identifier(char *buf, int buf_size, int c,
                         const unsigned int *str, int i, int n)
 {
     int len = 0, j;
 
+    if (len < buf_size) {
+        /* c is assumed to be an ASCII character */
+        buf[len++] = c;
+    }
+    for (j = i; j < n; j++) {
+        c = str[j];
+        if (!qe_isalnum_(c))
+            break;
+        if (len < buf_size - 1)
+            buf[len++] = c;
+    }
+    if (len < buf_size) {
+        buf[len] = '\0';
+    }
+    return j - i;
+}
+
+int ustr_get_identifier_lc(char *buf, int buf_size, int c,
+                           const unsigned int *str, int i, int n)
+{
+    int len = 0, j;
+
+    if (len < buf_size) {
+        /* c is assumed to be an ASCII character */
+        buf[len++] = qe_tolower(c);
+    }
     for (j = i; j < n; j++) {
-        int c = str[j];
+        c = str[j];
         if (!qe_isalnum_(c))
             break;
         if (len < buf_size - 1)
-            buf[len++] = str[j];
+            buf[len++] = qe_tolower(c);
     }
     if (len < buf_size) {
         buf[len] = '\0';
@@ -926,7 +952,7 @@
     return j - i;
 }
 
-int ustr_get_word(char *buf, int buf_size,
+int ustr_get_word(char *buf, int buf_size, int c,
                   const unsigned int *str, int i, int n)
 {
     buf_t outbuf, *out;
@@ -934,8 +960,9 @@
 
     out = buf_init(&outbuf, buf, buf_size);
 
+    buf_putc_utf8(out, c);
     for (j = i; j < n; j++) {
-        int c = str[j];
+        c = str[j];
         if (!qe_isword(c))
             break;
         buf_putc_utf8(out, c);



reply via email to

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