qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs clang.c htmlsrc.c lisp.c perl.c qe.h xml...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs clang.c htmlsrc.c lisp.c perl.c qe.h xml...
Date: Mon, 20 Jan 2014 18:04:01 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/01/20 18:04:01

Modified files:
        .              : clang.c htmlsrc.c lisp.c perl.c qe.h xml.c 
                         html.c latex-mode.c orgmode.c qe.c util.c 

Log message:
        simplify colorize_line functions: always pass NUL terminated line
        
        * added ustrstart, ustrstr and ustristr utility functions
        * simplified org_mode_colorize

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/qemacs/htmlsrc.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/lisp.c?cvsroot=qemacs&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/qemacs/perl.c?cvsroot=qemacs&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.126&r2=1.127
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/html.c?cvsroot=qemacs&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/qemacs/orgmode.c?cvsroot=qemacs&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.130&r2=1.131
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.58&r2=1.59

Patches:
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- clang.c     6 Jan 2014 09:40:20 -0000       1.43
+++ clang.c     20 Jan 2014 18:04:00 -0000      1.44
@@ -119,9 +119,6 @@
         c = *p++;
 
         switch (c) {
-        case '\n':
-            p--;
-            goto the_end;
         case '/':
             if (*p == '*') {
                 /* normal comment */

Index: htmlsrc.c
===================================================================
RCS file: /sources/qemacs/qemacs/htmlsrc.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- htmlsrc.c   5 Jan 2014 23:42:54 -0000       1.6
+++ htmlsrc.c   20 Jan 2014 18:04:00 -0000      1.7
@@ -66,7 +66,6 @@
     HTML_SCRIPT    = 0x80,      /* <SCRIPT> [...] </SCRIPT> */
 };
 
-/* CG: Should rely on len instead of '\n' */
 static void htmlsrc_colorize_line(unsigned int *buf, int len,
                                   int *colorize_state_ptr, int state_only)
 {
@@ -89,9 +88,6 @@
         p_start = p;
         c = *p;
 
-        if (c == '\n')
-            break;
-
         if (state & HTML_SCRIPTTAG) {
             while (p < p_end) {
                 if (*p++ == '>') {
@@ -108,8 +104,11 @@
                     break;
             }
             js_state = state & ~HTML_SCRIPT;
-            c_colorize_line (p_start, p - p_start,
-                             &js_state, state_only);
+            c = *p;     /* save char to set '\0' delimiter */
+            *p = '\0';
+            /* XXX: should have javascript specific colorize_func */
+            c_colorize_line(p_start, p - p_start, &js_state, state_only);
+            *p = c;
             state = js_state | HTML_SCRIPT;
             if (p < p_end) {
                 p_start = p;
@@ -121,8 +120,7 @@
         }
         if (state & HTML_COMMENT) {
             for (; p < p_end; p++) {
-                if (*p == '-' && p[1] == '-'
-                &&  p[2] == '>') {
+                if (*p == '-' && p[1] == '-' && p[2] == '>') {
                     p += 2;
                     state &= ~HTML_COMMENT;
                     break;
@@ -207,7 +205,7 @@
             ||   p[1] == '!' || p[1] == '/' || p[1] == '?')) {
                 //set_color(p_start, p, QE_STYLE_HTML_TEXT);
                 p_start = p;
-                if (ustristart (p, "<script", NULL)) {
+                if (ustristart(p, "<script", NULL)) {
                     state |= HTML_SCRIPTTAG;
                     break;
                 }
@@ -224,7 +222,7 @@
                     state |= HTML_TAG;
                 break;
             }
-            if (*p == '&' && get_html_entity (p)) {
+            if (*p == '&' && get_html_entity(p)) {
                 state |= HTML_ENTITY;
                 break;
             }

Index: lisp.c
===================================================================
RCS file: /sources/qemacs/qemacs/lisp.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- lisp.c      10 Jan 2014 01:09:26 -0000      1.4
+++ lisp.c      20 Jan 2014 18:04:00 -0000      1.5
@@ -39,8 +39,8 @@
 
     if (colstate & IN_STRING) {
         for (j = i; j < n;) {
-            if (str[j] == '\\') {
-                j += 2;
+            if (str[j] == '\\' && ++j < n) {
+                j++;
             } else
             if (str[j++] == '"') {
                 colstate &= ~IN_STRING;
@@ -52,7 +52,7 @@
     }
     if (colstate & IN_COMMENT) {
         for (j = i; j < n; j++) {
-            if (str[j] == '|' && str[j + 1] == '#') {
+            if (str[j] == '|' && j + 1 < n && str[j + 1] == '#') {
                 j += 2;
                 colstate &= ~IN_COMMENT;
                 break;
@@ -99,7 +99,6 @@
             break;
         }
         i++;
-        continue;
     }
     *statep = colstate;
 }

Index: perl.c
===================================================================
RCS file: /sources/qemacs/qemacs/perl.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- perl.c      5 Jan 2014 23:42:54 -0000       1.10
+++ perl.c      20 Jan 2014 18:04:00 -0000      1.11
@@ -37,6 +37,7 @@
 #define IN_INPUT        0x08
 
 /* CG: bogus if multiple regions are colorized, should use signature */
+/* XXX: should move this to mode data */
 static unsigned int perl_eos[100];
 static int perl_eos_len;
 
@@ -185,8 +186,9 @@
                     s2 = perl_var(str, s1, n);
                 }
                 if (s2 > s1) {
-                    umemcpy(perl_eos, str + s1, s2 - s1);
-                    perl_eos_len = s2 - s1;
+                    perl_eos_len = min((int)(s2 - s1), countof(perl_eos) - 1);
+                    umemcpy(perl_eos, str + s1, perl_eos_len);
+                    perl_eos[perl_eos_len] = '\0';
                     colstate |= IN_INPUT;
                 }
                 i += 2;

Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -b -r1.126 -r1.127
--- qe.h        19 Jan 2014 17:25:03 -0000      1.126
+++ qe.h        20 Jan 2014 18:04:00 -0000      1.127
@@ -281,13 +281,18 @@
 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);
+int ustrstart(const unsigned int *str, const char *val,
+              const unsigned int **pp);
+int ustristart(const unsigned int *str, const char *val,
+               const unsigned int **pp);
+const unsigned int *ustrstr(const unsigned int *str, const char *val);
+const unsigned int *ustristr(const unsigned int *str, const char *val);
 static inline unsigned int *umemmove(unsigned int *dest,
-                                     unsigned int *src, int count) {
+                                     const unsigned int *src, int count) {
     return (unsigned int *)memmove(dest, src, count * sizeof(unsigned int));
 }
 static inline unsigned int *umemcpy(unsigned int *dest,
-                                    unsigned int *src, int count) {
+                                    const unsigned int *src, int count) {
     return (unsigned int *)memcpy(dest, src, count * sizeof(unsigned int));
 }
 int umemcmp(const unsigned int *s1, const unsigned int *s2, int count);
@@ -968,9 +973,9 @@
                                     unsigned int *buf, int buf_size,
                                     int *offset1, int line_num);
 
-/* colorize a line : this function modifies buf to set the char
-   styles. 'buf' is guaranted to have one more char after its len
-   (it is either '\n' or '\0') */
+/* colorize a line: this function modifies buf to set the char
+ * styles. 'buf' is guaranted to have one more '\0' char after its len.
+ */
 typedef void (*ColorizeFunc)(unsigned int *buf, int len,
                              int *colorize_state_ptr, int state_only);
 

Index: xml.c
===================================================================
RCS file: /sources/qemacs/qemacs/xml.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- xml.c       5 Jan 2014 23:42:54 -0000       1.13
+++ xml.c       20 Jan 2014 18:04:00 -0000      1.14
@@ -27,10 +27,10 @@
     XML_TAG_SCRIPT,
     XML_TAG_STYLE,
     XML_STYLE,
-    XML_SCRIPT = 0x10, /* special mode for inside a script, ored with c mode */
+    XML_SCRIPT = 0x80, /* special mode for inside a script, ored with c mode */
 };
 
-static void xml_colorize_line(unsigned int *buf, __unused__ int len,
+static void xml_colorize_line(unsigned int *buf, int len,
                               int *colorize_state_ptr, int state_only)
 {
     int c, state;
@@ -58,16 +58,18 @@
     for (;;) {
         p_start = p;
         c = *p;
-        if (c == '\n') {
-            goto the_end;
-        } else if (c == '<' && state == 0) {
+
+        if (c == '\0')
+            break;
+
+        if (c == '<' && state == 0) {
             p++;
             if (p[0] == '!' && p[1] == '-' && p[2] == '-') {
                 p += 3;
                 state = XML_COMMENT;
                 /* wait until end of comment */
             parse_comment:
-                while (*p != '\n') {
+                while (*p != '\0') {
                     if (p[0] == '-' && p[1] == '-' && p[2] == '>') {
                         p += 3;
                         state = 0;
@@ -81,16 +83,18 @@
                 /* we are in a tag */
                 if (ustristart(p, "SCRIPT", (const unsigned int **)&p)) {
                     state = XML_TAG_SCRIPT;
-                } else if (ustristart(p, "STYLE", (const unsigned int **)&p)) {
+                } else
+                if (ustristart(p, "STYLE", (const unsigned int **)&p)) {
                     state = XML_TAG_STYLE;
                 }
             parse_tag:
-                while (*p != '\n') {
+                while (*p != '\0') {
                     if (*p == '>') {
                         p++;
                         if (state == XML_TAG_SCRIPT)
                             state = XML_SCRIPT;
-                        else if (state == XML_TAG_STYLE)
+                        else
+                        if (state == XML_TAG_STYLE)
                             state = XML_STYLE;
                         else
                             state = 0;
@@ -105,19 +109,24 @@
                     p_start = p;
                 parse_script:
                     for (;;) {
-                        if (*p == '\n') {
+                        if (*p == '\0') {
                             state &= ~XML_SCRIPT;
+                            /* XXX: should have javascript specific 
colorize_func */
                             c_colorize_line(p_start, p - p_start, &state, 
state_only);
                             state |= XML_SCRIPT;
                             break;
-                        } else if (ustristart(p, "</SCRIPT", (const unsigned 
int **)&p1)) {
-                            while (*p1 != '\n' && *p1 != '>')
-                                p1++;
-                            if (*p1 == '>')
-                                p1++;
-                            /* XXX: need to add '\n' */
+                        } else
+                        if (ustristart(p, "</SCRIPT", (const unsigned int 
**)&p1)) {
+                            while (*p1 != '\0') {
+                                if (*p1++ == '>')
+                                    break;
+                            }
                             state &= ~XML_SCRIPT;
+                            c = *p;
+                            *p = '\0';
+                            /* XXX: should have javascript specific 
colorize_func */
                             c_colorize_line(p_start, p - p_start, &state, 
state_only);
+                            *p = c;
                             state |= XML_SCRIPT;
                             set_color(p, p1, QE_STYLE_TAG);
                             p = p1;
@@ -127,19 +136,21 @@
                             p++;
                         }
                     }
-                } else if (state == XML_STYLE) {
+                } else
+                if (state == XML_STYLE) {
                     /* stylesheet coloring */
                     p_start = p;
                 parse_style:
                     for (;;) {
-                        if (*p == '\n') {
+                        if (*p == '\0') {
                             set_color(p_start, p, QE_STYLE_CSS);
                             break;
-                        } else if (ustristart(p, "</STYLE", (const unsigned 
int **)&p1)) {
-                            while (*p1 != '\n' && *p1 != '>')
-                                p1++;
-                            if (*p1 == '>')
-                                p1++;
+                        } else
+                        if (ustristart(p, "</STYLE", (const unsigned int 
**)&p1)) {
+                            while (*p1 != '\0') {
+                                if (*p1++ != '>')
+                                    break;
+                            }
                             set_color(p_start, p, QE_STYLE_CSS);
                             set_color(p, p1, QE_STYLE_TAG);
                             p = p1;
@@ -156,7 +167,6 @@
             p++;
         }
     }
- the_end:
     *colorize_state_ptr = state;
 }
 

Index: html.c
===================================================================
RCS file: /sources/qemacs/qemacs/html.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- html.c      15 Jan 2014 15:54:27 -0000      1.25
+++ html.c      20 Jan 2014 18:04:01 -0000      1.26
@@ -831,6 +831,7 @@
 /* search for HTML tag */
 static int html_mode_probe(ModeDef *mode, ModeProbeData *p1)
 {
+    static const uint32_t magic = (1 << '\r') | (1 << '\n') | (1 << '\t') | (1 
<< '\033');
     const unsigned char *p = p1->buf;
     int c, score;
 
@@ -839,9 +840,9 @@
         c = *p;
         if (c == '\0')
             break;
-        if (c < 32 && (c != '\r' && c != '\n' && c != '\t' && c != '\033'))
+        if (c < 32 && !(magic & (1 << c)))
             return 0;
-        if (c == '<' && stristart(cs8(p), "<HTML", NULL))
+        if (c == '<' && stristart(cs8(p), "<html", NULL))
             score = 100;
         p++;
     }

Index: latex-mode.c
===================================================================
RCS file: /sources/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- latex-mode.c        13 Jan 2014 10:31:56 -0000      1.39
+++ latex-mode.c        20 Jan 2014 18:04:01 -0000      1.40
@@ -42,19 +42,26 @@
         p_start = p;
         c = *p;
         switch (c) {
-        case '\n':
+        case '\0':
+        case '\n':      /* Should not happen */
             goto the_end;
         case '`':
             p++;
             /* a ``string'' */
             if (*p == '`') {
-                while (1) {
+                for (;;) {
                     p++;
-                    if (*p == '\n' || (*p == '\'' && *(p+1) == '\''))
+                    if (*p == '\0') {
+                        /* Should either flag an error or propagate
+                         * string style to the next line
+                         */
                         break;
                 }
-                if (*p == '\'' && *++p == '\'')
-                    p++;
+                    if (*p == '\'' && p[1] == '\'') {
+                        p += 2;
+                        break;
+                    }
+                }
                 set_color(p_start, p, QE_STYLE_STRING);
             }
             break;
@@ -64,7 +71,7 @@
             if (*p == '\'' || *p == '\"' || *p == '~' || *p == '%' || *p == 
'\\') {
                 p++;
             } else {
-                while (*p != '{' && *p != '[' && *p != '\n' && *p != ' ' && *p 
!= '\\')
+                while (*p != '\0' && *p != '{' && *p != '[' && *p != ' ' && *p 
!= '\\')
                     p++;
             }
             set_color(p_start, p, QE_STYLE_FUNCTION);
@@ -76,7 +83,7 @@
                 if (*p++ == '[') {
                     /* handle [keyword] */
                     p_start = p;
-                    while (*p != ']' && *p != '\n')
+                    while (*p != '\0' && *p != ']')
                         p++;
                     set_color(p_start, p, QE_STYLE_KEYWORD);
                     if (*p == ']')
@@ -85,7 +92,7 @@
                     int braces = 0;
                     /* handle {variable} */
                     p_start = p;
-                    while (*p != '\n') {
+                    while (*p != '\0') {
                         if (*p == '{') {
                             braces++;
                         } else
@@ -108,7 +115,7 @@
         case '%':
             p++;
             /* line comment */
-            while (*p != '\n')
+            while (*p != '\0')
                 p++;
             set_color(p_start, p, QE_STYLE_COMMENT);
             break;

Index: orgmode.c
===================================================================
RCS file: /sources/qemacs/qemacs/orgmode.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- orgmode.c   16 Jan 2014 14:34:14 -0000      1.8
+++ orgmode.c   20 Jan 2014 18:04:01 -0000      1.9
@@ -49,88 +49,38 @@
     QE_STYLE_TYPE,
 };
 
-static int str4_match_str(unsigned int *str, int n, const char *str1,
-                          int *matchlen)
+static int org_todo_keyword(const unsigned int *str)
 {
-    int i;
-
-    for (i = 0; i < n && str1[i]; i++) {
-        if (str[i] != str1[i])
-            return 0;
-    }
-    if (matchlen)
-        *matchlen = i;
-    return 1;
-}
-
-#if 0
-static int str4_find_str(unsigned int *str, int n, const char *str1)
-{
-    int i, c = str1[0];
-
-    for (i = 0; i < n; i++) {
-        if (str[i] == c && str4_match_str(str + i, n - i, str1, NULL))
-            return i;
-    }
-    return -1;
-}
-#endif
-
-static int str4_match_istr(unsigned int *str, int n, const char *str1,
-                           int *matchlen)
-{
-    int i;
-
-    for (i = 0; i < n && str1[i]; i++) {
-        if (qe_toupper(str[i]) != qe_toupper(str1[i]))
-            return 0;
-    }
-    if (matchlen)
-        *matchlen = i;
-    return 1;
-}
-
-static int str4_find_istr(unsigned int *str, int n, const char *str1)
-{
-    int i, c = qe_toupper(str1[0]);
-
-    for (i = 0; i < n; i++) {
-        if (qe_toupper(str[i]) == c
-        &&  str4_match_istr(str + i, n - i, str1, NULL)) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-static int org_todo_keyword(unsigned int *str, int n)
-{
-    int kw, j;
+    const unsigned int *p;
+    int kw;
 
     for (kw = 0; kw < countof(OrgTodoKeywords); kw++) {
-        if (str4_match_str(str, n, OrgTodoKeywords[kw].keyword, &j)
-        &&  j < n && str[j] == ' ')
+        if (ustrstart(str, OrgTodoKeywords[kw].keyword, &p) && *p == ' ')
             return kw;
     }
     return -1;
 }
 
-static int org_scan_chunk(unsigned int *str, int i0, int n,
+static int org_scan_chunk(const unsigned int *str,
                           const char *begin, const char *end, int min_width)
 {
-    int i = i0, j;
+    int i, j;
 
-    for (j = 0; begin[j]; j++) {
-        if (str[i + j] != begin[j])
+    for (i = 0; begin[i]; i++) {
+        if (str[i] != begin[i])
+            return 0;
+    }
+    for (j = 0; j < min_width; j++) {
+        if (str[i + j] == '\0')
             return 0;
     }
-    for (i += j + min_width; i < n; i++) {
+    for (i += j; str[i] != '\0'; i++) {
         for (j = 0; end[j]; j++) {
             if (str[i + j] != end[j])
                 break;
         }
         if (!end[j])
-            return i + j - i0;
+            return i + j;
     }
     return 0;
 }
@@ -142,9 +92,9 @@
     int i = 0, j = 0, kw, base_style = 0, has_space;
 
     if (colstate & IN_BLOCK) {
-        for (j = i; j < n && str[j] == ' '; )
+        for (j = i; str[j] == ' '; )
             j++;
-        if (str4_match_istr(str + j, n - j, "#+end_", NULL)) {
+        if (ustristart(str + j, "#+end_", NULL)) {
             colstate &= ~(IN_BLOCK | IN_LISP);
         } else {
             if (colstate & IN_LISP) {
@@ -159,15 +109,15 @@
 
     if (str[i] == '*') {
         /* Check for heading: initial string of '*' followed by ' ' */
-        for (j = i + 1; j < n && str[j] == '*'; j++)
+        for (j = i + 1; str[j] == '*'; j++)
             continue;
 
-        if (j < n && str[j] == ' ') {
+        if (str[j] == ' ') {
             base_style = OrgBulletStyles[(j - i - 1) % BULLET_STYLES];
             set_color(str + i, str + j + 1, base_style);
             i = j + 1;
 
-            kw = org_todo_keyword(str + i, n - i);
+            kw = org_todo_keyword(str + i);
             if (kw > -1) {
                 j = i + strlen(OrgTodoKeywords[kw].keyword) + 1;
                 set_color(str + i, str + j, OrgTodoKeywords[kw].style);
@@ -175,23 +125,23 @@
             }
         }
     } else {
-        while (i < n && str[i] == ' ')
+        while (str[i] == ' ')
             i++;
 
         if (str[i] == '#') {
-            if (str[i+1] == ' ') {  /* [ \t]*[#][ ] -> comment */
+            if (str[i + 1] == ' ') {  /* [ \t]*[#][ ] -> comment */
                 set_color(str + i, str + n, QE_STYLE_COMMENT);
                 i = n;
             } else
-            if (str[i+1] == '+') {  /* [ \t]*[#][+] -> metadata */
+            if (str[i + 1] == '+') {  /* [ \t]*[#][+] -> metadata */
                 /* Should interpret litteral examples:
                  * #+BEGIN_xxx / #+END_xxx
                  * #+BEGIN_LATEX / #+END_LATEX
                  * #+BEGIN_SRC / #+END_SRC
                  */
-                if (str4_match_istr(str + i, n - i, "#+begin_", NULL)) {
+                if (ustristart(str + i, "#+begin_", NULL)) {
                     colstate |= IN_BLOCK;
-                    if (str4_find_istr(str + i, n - i, "lisp")) {
+                    if (ustristr(str + i, "lisp")) {
                         colstate |= IN_LISP;
                     }
                 }
@@ -221,43 +171,46 @@
 
     has_space = 1;
 
-    while (i < n) {
+    for (;;) {
         int chunk = 0;
         int c = str[i];
 
+        if (c == '\0')
+            break;
+
         if (has_space || c == '\\') {
             switch (c) {
             case '#':
                 break;
             case '*':  /* bold */
-                chunk = org_scan_chunk(str, i, n, "*", "*", 1);
+                chunk = org_scan_chunk(str + i, "*", "*", 1);
                 break;
             case '/':  /* italic */
-                chunk = org_scan_chunk(str, i, n, "/", "/", 1);
+                chunk = org_scan_chunk(str + i, "/", "/", 1);
                 break;
             case '_':  /* underline */
-                chunk = org_scan_chunk(str, i, n, "_", "_", 1);
+                chunk = org_scan_chunk(str + i, "_", "_", 1);
                 break;
             case '=':  /* code */
-                chunk = org_scan_chunk(str, i, n, "=", "=", 1);
+                chunk = org_scan_chunk(str + i, "=", "=", 1);
                 break;
             case '~':  /* verbatim */
-                chunk = org_scan_chunk(str, i, n, "~", "~", 1);
+                chunk = org_scan_chunk(str + i, "~", "~", 1);
                 break;
             case '+':  /* strike-through */
-                chunk = org_scan_chunk(str, i, n, "+", "+", 1);
+                chunk = org_scan_chunk(str + i, "+", "+", 1);
                 break;
             case '@':  /* litteral stuff @@...@@ */
-                chunk = org_scan_chunk(str, i, n, "@@", "@@", 1);
+                chunk = org_scan_chunk(str + i, "@@", "@@", 1);
                 break;
             case '[':  /* wiki syntax for links [[...]..[...]] */
-                chunk = org_scan_chunk(str, i, n, "[[", "]]", 1);
+                chunk = org_scan_chunk(str + i, "[[", "]]", 1);
                 break;
             case '{': /* LaTeX syntax for macros {{{...}}} and {} */
                 if (str[i + 1] == '}')
                     chunk = 2;
                 else
-                    chunk = org_scan_chunk(str, i, n, "{{{", "}}}", 1);
+                    chunk = org_scan_chunk(str + i, "{{{", "}}}", 1);
                 break;
             case '\\':  /* TeX syntax: \keyword \- \[ \] \( \) */
                 if (str[i + 1] == '\\') {  /* \\ escape */
@@ -269,16 +222,15 @@
                     chunk = 2;
                     break;
                 }
-                for (chunk = 1; i + chunk < n
-                && qe_isalnum(str[i + chunk]); chunk++) {
+                for (chunk = 1; qe_isalnum(str[i + chunk]); chunk++) {
                     continue;
                 }
                 if (chunk > 0)
                     break;
-                chunk = org_scan_chunk(str, i, n, "\\(", "\\)", 1);
+                chunk = org_scan_chunk(str + i, "\\(", "\\)", 1);
                 if (chunk > 0)
                     break;
-                chunk = org_scan_chunk(str, i, n, "\\[", "\\]", 1);
+                chunk = org_scan_chunk(str + i, "\\[", "\\]", 1);
                 if (chunk > 0)
                     break;
                 break;

Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -b -r1.130 -r1.131
--- qe.c        19 Jan 2014 17:25:03 -0000      1.130
+++ qe.c        20 Jan 2014 18:04:01 -0000      1.131
@@ -3180,20 +3180,14 @@
 
         for (l = s->colorize_nb_valid_lines; l <= line_num; l++) {
             len = eb_get_line(s->b, buf, buf_size, &offset);
-            // XXX: should force \0 instead of \n
-            buf[len] = '\n';
-
             s->colorize_func(buf, len, &colorize_state, 1);
             s->colorize_states[l] = colorize_state;
         }
     }
 
     /* compute line color */
-    len = eb_get_line(s->b, buf, buf_size, offsetp);
-    // XXX: should force \0 instead of \n
-    buf[len] = '\n';
-
     colorize_state = s->colorize_states[line_num];
+    len = eb_get_line(s->b, buf, buf_size, offsetp);
     s->colorize_func(buf, len, &colorize_state, 0);
 
     /* XXX: if state is same as previous, minimize invalid region? */
@@ -3272,16 +3266,11 @@
 int get_non_colorized_line(EditState *s, unsigned int *buf, int buf_size,
                            int *offsetp, int line_num)
 {
-    int len;
-
     if (s->b->b_styles) {
         return get_staticly_colorized_line(s, buf, buf_size, offsetp, 
line_num);
+    } else {
+        return eb_get_line(s->b, buf, buf_size, offsetp);
     }
-
-    len = eb_get_line(s->b, buf, buf_size, offsetp);
-    // XXX: should force \0 instead of \n
-    buf[len] = '\n';
-    return len;
 }
 
 #define RLE_EMBEDDINGS_SIZE    128

Index: util.c
===================================================================
RCS file: /sources/qemacs/qemacs/util.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- util.c      16 Jan 2014 14:24:04 -0000      1.58
+++ util.c      20 Jan 2014 18:04:01 -0000      1.59
@@ -740,25 +740,54 @@
     return 0;
 }
 
+int ustrstart(const unsigned int *str, const char *val,
+              const unsigned int **pp)
+{
+    for (; *val != '\0'; val++, str++) {
+        /* assuming val is ASCII or Latin1 */
+        if (*str != *val)
+            return 0;
+    }
+    if (pp)
+        *pp = str;
+    return 1;
+}
+
+const unsigned int *ustrstr(const unsigned int *str, const char *val)
+{
+    int c = val[0];
+
+    for (; *str != '\0'; str++) {
+        if (*str == c && ustrstart(str, val, NULL))
+            return str;
+    }
+    return NULL;
+}
+
 int ustristart(const unsigned int *str, const char *val,
-               const unsigned int **ptr)
+               const unsigned int **pp)
 {
-    const unsigned int *p;
-    const char *q;
-    p = str;
-    q = val;
-    while (*q != '\0') {
-        /* XXX: should filter style information */
-        if (qe_toupper(*p) != qe_toupper(*q))
+    for (; *val != '\0'; val++, str++) {
+        /* assuming val is ASCII or Latin1 */
+        if (qe_toupper(*str) != qe_toupper(*val))
             return 0;
-        p++;
-        q++;
     }
-    if (ptr)
-        *ptr = p;
+    if (pp)
+        *pp = str;
     return 1;
 }
 
+const unsigned int *ustristr(const unsigned int *str, const char *val)
+{
+    int c = qe_toupper(val[0]);
+
+    for (; *str != '\0'; str++) {
+        if (qe_toupper(*str) == c && ustristart(str, val, NULL))
+            return str;
+    }
+    return NULL;
+}
+
 int umemcmp(const unsigned int *s1, const unsigned int *s2, int count)
 {
     for (; count > 0; count--, s1++, s2++) {



reply via email to

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