qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs charset.c latex-mode.c list.c qe.c qe.h ...


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs charset.c latex-mode.c list.c qe.c qe.h ...
Date: Mon, 07 Jan 2008 16:25:23 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/01/07 16:25:23

Modified files:
        .              : charset.c latex-mode.c list.c qe.c qe.h util.c 
        libqhtml       : css.c cssparse.c xmlparse.c 

Log message:
        fixed crash on charset_completion
        renamed css_strtolower -> qe_strtolower
        use offsetof for SAVED_DATA_SIZE macro (this stuff must go)
        cosmetics in css_get_enum
        remarks
        fixed text-mode colorization bug: because of saved_data stuff, 
          must reset colorization function after mode restore.  This saved data
          stuff is bogus and should be rewritten
        smaller version of roman numeral converter
        fixed alpha converter
        smaller implementation of css_counter_str
        fixed list_mode name: no longer generates extra mode completion entry

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/charset.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/latex-mode.c?cvsroot=qemacs&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/qemacs/list.c?cvsroot=qemacs&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/qemacs/util.c?cvsroot=qemacs&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/css.c?cvsroot=qemacs&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/cssparse.c?cvsroot=qemacs&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/xmlparse.c?cvsroot=qemacs&r1=1.15&r2=1.16

Patches:
Index: charset.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/charset.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- charset.c   3 Jan 2008 18:31:24 -0000       1.15
+++ charset.c   7 Jan 2008 16:25:22 -0000       1.16
@@ -266,6 +266,7 @@
     for (charset = first_charset; charset != NULL; charset = charset->next) {
         if (strxstart(charset->name, input, NULL))
             add_string(cs, charset->name);
+        if (charset->aliases) {
         for (q = p = charset->aliases;; q++) {
             if (*q == '\0' || *q == '|') {
                 if (q > p) {
@@ -275,7 +276,8 @@
                 }
                 if (*q == '\0')
                     break;
-                p = ++q;
+                    p = q + 1;
+                }
             }
         }
     }

Index: latex-mode.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/latex-mode.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- latex-mode.c        4 Jan 2008 23:04:11 -0000       1.24
+++ latex-mode.c        7 Jan 2008 16:25:22 -0000       1.25
@@ -135,6 +135,7 @@
 static int latex_mode_init(EditState *s, ModeSavedData *saved_data)
 {
     int ret;
+
     ret = text_mode_init(s, saved_data);
     if (ret)
         return ret;

Index: list.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/list.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- list.c      3 Jan 2008 09:51:31 -0000       1.6
+++ list.c      7 Jan 2008 16:25:22 -0000       1.7
@@ -93,6 +93,7 @@
 static int list_init(void)
 {
     memcpy(&list_mode, &text_mode, sizeof(ModeDef));
+    list_mode.name = "list";
     list_mode.mode_probe = NULL;
     list_mode.mode_init = list_mode_init;
     list_mode.mode_close = list_mode_close;

Index: qe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- qe.c        4 Jan 2008 22:24:39 -0000       1.60
+++ qe.c        7 Jan 2008 16:25:22 -0000       1.61
@@ -94,9 +94,8 @@
         int size;
 
         /* lower case convert for C mode, Perl... */
-        pstrcpy(buf, sizeof(buf) - 10, m->name);
-        css_strtolower(buf, sizeof(buf));
-        pstrcat(buf, sizeof(buf) - 10, "-mode");
+        qe_strtolower(buf, sizeof(buf) - 10, m->name);
+        pstrcat(buf, sizeof(buf), "-mode");
         size = strlen(buf) + 1;
         /* constant immediate string parameter */
         size += snprintf(buf + size, sizeof(buf) - size,
@@ -1584,6 +1583,7 @@
         s->mode->mode_close(s);
         qe_free(&s->mode_data);
         s->mode = NULL;
+        set_colorize_func(s, NULL);
 
         /* try to remove the raw or mode specific data if it is no
            longer used. */
@@ -1621,7 +1621,8 @@
                     m = &text_mode;
                     b->data_type = &raw_data_type;
                 }
-            } else if (b->data_type != m->data_type) {
+            } else
+            if (b->data_type != m->data_type) {
                 /* non raw data type requested, but the the buffer has
                    a different type: we cannot switch mode, so we fall
                    back to text */
@@ -6580,7 +6581,6 @@
 
 int text_mode_init(EditState *s, ModeSavedData *saved_data)
 {
-    set_colorize_func(s, NULL);
     eb_add_callback(s->b, eb_offset_callback, &s->offset);
     eb_add_callback(s->b, eb_offset_callback, &s->offset_top);
     if (!saved_data) {
@@ -6594,6 +6594,7 @@
         memcpy(s, saved_data->generic_data, SAVED_DATA_SIZE);
     }
     s->hex_mode = 0;
+    set_colorize_func(s, NULL);
     return 0;
 }
 

Index: qe.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/qe.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- qe.h        4 Jan 2008 22:24:39 -0000       1.56
+++ qe.h        7 Jan 2008 16:25:23 -0000       1.57
@@ -227,7 +227,7 @@
     return (qe_inrange(c, 'A', 'Z') ? c + 'a' - 'A' : c);
 }
 
-void css_strtolower(char *buf, int buf_size);
+void qe_strtolower(char *buf, int buf_size, const char *str);
 void skip_spaces(const char **pp);
 
 int strfind(const char *list, const char *s);
@@ -980,7 +980,8 @@
     EditState *next_window;
 };
 
-#define SAVED_DATA_SIZE ((int)&((EditState *)0)->end_of_saved_data)
+/* Ugly patch for saving/restoring window data upon switching buffer */
+#define SAVED_DATA_SIZE  offsetof(EditState, end_of_saved_data)
 
 struct DisplayState;
 

Index: util.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/util.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- util.c      4 Jan 2008 22:24:39 -0000       1.33
+++ util.c      7 Jan 2008 16:25:23 -0000       1.34
@@ -390,6 +390,31 @@
         pstrcpy(filename, filename_size, base);
 }
 
+/* Should return int, length of converted string? */
+void qe_strtolower(char *buf, int size, const char *str)
+{
+    int c;
+
+    /* This version only handles ASCII */
+    if (size > 0) {
+        while ((c = (unsigned char)*str++) != '\0' && size > 1) {
+            *buf++ = qe_tolower(c);
+            size--;
+        }
+        *buf = '\0';
+    }
+}
+
+void skip_spaces(const char **pp)
+{
+    const char *p;
+
+    p = *pp;
+    while (qe_isspace(*p))
+        p++;
+    *pp = p;
+}
+
 #if 0
 /* find a word in a list using '|' as separator */
 int strfind(const char *keytable, const char *str)
@@ -425,6 +450,9 @@
     int c1, c2;
 
     q = list;
+    if (!q)
+        return 0;
+
     if (*s == '\0') {
         /* special case the empty string: must match || in list */
         while (*q) {
@@ -465,8 +493,7 @@
 {
     char buf[128];
 
-    pstrcpy(buf, sizeof(buf), s);
-    css_strtolower(buf, sizeof(buf));
+    qe_strtolower(buf, sizeof(buf), s);
     return strfind(list, buf);
 }
 
@@ -493,16 +520,6 @@
     return NULL;
 }
 
-void skip_spaces(const char **pp)
-{
-    const char *p;
-
-    p = *pp;
-    while (qe_isspace(*p))
-        p++;
-    *pp = p;
-}
-
 /**
  * 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
@@ -657,6 +674,8 @@
     skip_spaces(pp);
 }
 
+/* scans a comma separated list of entries, return index of match or -1 */
+/* CG: very similar to strfind */
 int css_get_enum(const char *str, const char *enum_str)
 {
     int val, len;
@@ -667,15 +686,15 @@
     len = strlen(str);
     for (;;) {
         s1 = strchr(s, ',');
-        if (!s1) {
+        if (s1) {
+            if (len == (s1 - s) && !memcmp(s, str, len))
+                return val;
+            s = s1 + 1;
+        } else {
             if (!strcmp(s, str))
                 return val;
             else
                 break;
-        } else {
-            if (len == (s1 - s) && !memcmp(s, str, len))
-                return val;
-            s = s1 + 1;
         }
         val++;
     }
@@ -1093,16 +1112,6 @@
     }
 }
 
-void css_strtolower(char *buf, __unused__ int buf_size)
-{
-    int c;
-
-    /* XXX: handle unicode / utf8 */
-    while ((c = (unsigned char)*buf) != '\0') {
-        *buf++ = qe_tolower(c);
-    }
-}
-
 #ifdef __TINYC__
 
 /* the glibc folks use wrappers, but forgot to put a compatibility

Index: libqhtml/css.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/css.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- libqhtml/css.c      3 Jan 2008 09:51:32 -0000       1.15
+++ libqhtml/css.c      7 Jan 2008 16:25:23 -0000       1.16
@@ -880,40 +880,87 @@
     return box1;
 }
 
-/* NOTE: 'buf' must be large enough */
-/* XXX: find a shorter code :-) */
-static void css_to_roman(char *buf, int n)
+/* Convert a number to alpha representation.
+ * - 'dest' must be large enough for maximum conversion
+ *   namely INT32_MAX (2147483647) -> "FXSHRXW" 8 bytes 
+ *          INT64_MAX (9223372036854775807) -> "CRPXNLSKVLJFHG" 15 bytes 
+ * - n should be greater than 0
+ * - return 0 if conversion succeeds
+ * - return -1 if n not in range, dest untouched
+ */
+static int num_to_alpha(char *dest, int num, int upper)
 {
-    int n1, n10;
-    static const char roman_digits[] = "IVXLCDM";
-    const char *p;
-    char buf1[17], *q;
+    char buf[16], *p;
+    int letter = upper ? 'A' : 'a';
 
-    if (n <= 0 || n >= 4000) {
-        snprintf(buf, sizeof(buf), "%d", n);
-        return;
+    if (num <= 0)
+        return -1;
+
+    p = buf + countof(buf);
+    *--p = '\0';
+
+    num--;
+    while (num >= 26) {
+        *--p = letter + (num % 26);
+        num /= 26;
+        num -= 1;
     }
+    *--p = letter + num;
+
+    memcpy(dest, p, buf + countof(buf) - p);
+    return 0;
+}
+
+/* Convert a number to roman numeral representation.
+ * - 'dest' must be large enough for maximum conversion
+ *   namely 3888 -> "MMMDCCCLXXXVIII" 16 bytes
+ * - n should be in range 1..3999
+ * - return 0 if conversion succeeds
+ * - return -1 if n not in range, dest untouched
+ */
+static int num_to_roman(char *dest, int n, int upper)
+{
+    char buf[16], *q;
+    const char *p;
+    char const digits[7 * 2] = "ivxlcdm" "IVXLCDM";
+
+    if (n <= 0 || n >= 4000)
+        return -1;
 
-    p = roman_digits;
-    q = buf1;
-    while (n != 0) {
-        n10 = n % 10;
-        n1 = n10 % 5;
+    p = digits + (upper ? 7 : 0);
+    q = buf + countof(buf);
+    *--q = '\0';
+
+    while (n > 0) {
+#if 1
+        /* Potentially shorter code :-) */
+#define R(a,b,c,d)  (((a)<<6)|((b)<<4)|((c)<<2)|((d)<<0))
+        int n10;
+        unsigned char const pat[10] = { /* 0, 1, 5, 21, 6, 2, 9, 37, 85, 7 */
+            R(0,0,0,0), R(0,0,0,1), R(0,0,1,1), R(0,1,1,1), R(0,0,1,2),
+            R(0,0,0,2), R(0,0,2,1), R(0,2,1,1), R(2,1,1,1), R(0,0,1,3),
+        };
+        for (n10 = pat[n % 10]; n10; n10 >>= 2) {
+            *--q = p[(n10 & 3) - 1];
+        }
+#else
+        int n10 = n % 10;
+        int n1 = n10 % 5;
         if (n1 == 4) {
-            *q++ = p[1 + (n10 == 9)];
-            *q++ = p[0];
+            *--q = p[1 + (n10 == 9)];
+            *--q = p[0];
         } else {
             while (n1--)
-                *q++ = p[0];
+                *--q = p[0];
             if (n10 >= 5)
-                *q++ = p[1];
+                *--q = p[1];
         }
-        n = n / 10;
+#endif
+        n /= 10;
         p += 2;
     }
-    while (--q >= buf1)
-        *buf++ = *q;
-    *buf = '\0';
+    memcpy(dest, q, buf + countof(buf) - q);
+    return 0;
 }
 
 /* if adjust is true, then always use zero base and increment if
@@ -921,41 +968,48 @@
 static void css_counter_str(char *text, int text_size,
                             int index, int list_style_type, int adjust)
 {
+    char buf[16];
+    const char *p = buf;
+    int upper = 1; /* upper case */
+
     /* insert marker text */
+    index += adjust;
     switch (list_style_type) {
     case CSS_LIST_STYLE_TYPE_DISC:
-        strcpy(text, "o");
-        break;
     case CSS_LIST_STYLE_TYPE_CIRCLE:
-        strcpy(text, "o");
+        p = "o";
+        adjust = 0;
         break;
     case CSS_LIST_STYLE_TYPE_SQUARE:
-        strcpy(text, ".");
+        p = ".";
+        adjust = 0;
         break;
-    case CSS_LIST_STYLE_TYPE_DECIMAL:
-        snprintf(text, text_size, "%d", index + adjust);
-        goto add_dot;
     case CSS_LIST_STYLE_TYPE_LOWER_ALPHA:
+        upper = 0;
+        /* FALL THRU */
     case CSS_LIST_STYLE_TYPE_UPPER_ALPHA:
-        if (index > 25)
-            index = 25;
-        text[0] = 'A' + index;
-        text[1] = '\0';
-        goto add_dot;
+        if (num_to_alpha(buf, index, upper))
+            goto decimal;
+        break;
     case CSS_LIST_STYLE_TYPE_LOWER_ROMAN:
+        upper = 0;
+        /* FALL THRU */
     case CSS_LIST_STYLE_TYPE_UPPER_ROMAN:
-        css_to_roman(text, index + adjust);
-    add_dot:
-        if (adjust)
-            pstrcat(text, text_size, ".");
+        if (num_to_roman(buf, index, upper))
+            goto decimal;
+        break;
+    case CSS_LIST_STYLE_TYPE_DECIMAL:
+    decimal:
+        snprintf(buf, sizeof(buf), "%d", index);
         break;
     default:
-        text[0] = '\0';
+        p = "";
+        adjust = 0;
         break;
     }
-    if (list_style_type == CSS_LIST_STYLE_TYPE_LOWER_ALPHA ||
-        list_style_type == CSS_LIST_STYLE_TYPE_LOWER_ROMAN)
-        css_strtolower(text, text_size);
+    pstrcpy(text, text_size, p);
+    if (adjust)
+        pstrcat(text, text_size, ".");
 }
 
 /* add a marker or an inline box to a list item box */

Index: libqhtml/cssparse.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/cssparse.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- libqhtml/cssparse.c 3 Jan 2008 09:51:33 -0000       1.13
+++ libqhtml/cssparse.c 7 Jan 2008 16:25:23 -0000       1.14
@@ -311,7 +311,7 @@
                             goto next;
                         p++;
                         if (b->ignore_case)
-                            css_strtolower(buf, sizeof(buf));
+                            qe_strtolower(buf, sizeof(buf), buf);
                         args[nb_args].u.attr_id = css_new_ident(buf);
                         unit = CSS_VALUE_ATTR;
                         goto got_val;
@@ -878,7 +878,7 @@
     pclass = 0;
     read_ident(b, &ch, tag, sizeof(tag));
     if (b->ignore_case)
-        css_strtolower(tag, sizeof(tag));
+        qe_strtolower(tag, sizeof(tag), tag);
 
     /* read '.class', '[xxx]', ':pseudo-class' */
     for (;;) {
@@ -898,7 +898,7 @@
             ch = bgetc(b);
             read_ident(b, &ch, attribute, sizeof(attribute));
             if (b->ignore_case)
-                css_strtolower(attribute, sizeof(attribute));
+                qe_strtolower(attribute, sizeof(attribute), attribute);
 
             switch (ch) {
             case '~':

Index: libqhtml/xmlparse.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/xmlparse.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- libqhtml/xmlparse.c 3 Jan 2008 09:51:33 -0000       1.15
+++ libqhtml/xmlparse.c 7 Jan 2008 16:25:23 -0000       1.16
@@ -329,8 +329,7 @@
     value = css_attr_str(box, attr_id);
     if (!value)
         return NULL;
-    pstrcpy(buf, sizeof(buf), value);
-    css_strtolower(buf, sizeof(buf));
+    qe_strtolower(buf, sizeof(buf), value);
     return buf;
 }
 
@@ -842,7 +841,7 @@
         }
     }
     if (s->ignore_case)
-        css_strtolower(tag, sizeof(tag));
+        qe_strtolower(tag, sizeof(tag), tag);
     css_tag = css_new_ident(tag);
 
     /* XXX: should test html_syntax, but need more patches */
@@ -861,7 +860,7 @@
             break;
         get_str(&p, attr_name, sizeof(attr_name), "=/");
         if (s->ignore_case)
-            css_strtolower(attr_name, sizeof(attr_name));
+            qe_strtolower(attr_name, sizeof(attr_name), attr_name);
         if (*p == '=') {
             int och, ch;
             p++;




reply via email to

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