qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs/libqhtml css.c css.h cssid.h csstoqe.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs/libqhtml css.c css.h cssid.h csstoqe.c
Date: Thu, 24 Apr 2008 14:02:42 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        08/04/24 14:02:42

Modified files:
        libqhtml       : css.c css.h cssid.h csstoqe.c 

Log message:
        use union to avoid non portable casts
        some simplifications and clarifications
        added copyrights

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/css.c?cvsroot=qemacs&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/css.h?cvsroot=qemacs&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/cssid.h?cvsroot=qemacs&r1=1.1.1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/csstoqe.c?cvsroot=qemacs&r1=1.7&r2=1.8

Patches:
Index: css.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/css.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- css.c       23 Apr 2008 17:05:51 -0000      1.23
+++ css.c       24 Apr 2008 14:02:42 -0000      1.24
@@ -2,6 +2,7 @@
  * CSS core for qemacs.
  *
  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2007-2008 Charlie Gordon.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -440,54 +441,60 @@
                               CSSState *state_parent,
                               __unused__ CSSBox *box)
 {
-    int *ptr, val;
-    const CSSPropertyDef *def;
+    CSSPropertyDef const *def;
+    CSSPropertyStorage *ptr, *parent_ptr;
+    int val;
 
     if (p->property >= NB_PROPERTIES) {
         dprintf("css_eval: invalid property: %d\n", p->property);
         return;
     }
     def = &css_properties[p->property];
-    ptr = (int *)((char *)state + def->struct_offset);
+    ptr = CSSPropertyStoragePtr(state, def->struct_offset);
+    parent_ptr = NULL;
+    if (state_parent) {
+        parent_ptr = CSSPropertyStoragePtr(state_parent, def->struct_offset);
+    }
+
     if (p->value.u.val == CSS_INHERIT) {
         /* XXX: invalid if pointer */
         switch (def->storage) {
         default:
         case CSS_STORAGE_INT:
-            *ptr = *(int *)((char *)state_parent + def->struct_offset);
+            ptr->val = parent_ptr->val;
             break;
         case CSS_STORAGE_PTR:
-            *(void **)ptr = *(void **)((char *)state_parent + 
def->struct_offset);
+            ptr->ptr = parent_ptr->ptr;
             break;
         }
     } else {
         if (def->storage == CSS_STORAGE_PTR) {
-            *(void **)ptr = p;
+            ptr->ptr = p;
         } else {
-            /* CG: factorize this ? */
+            /* def->storage == CSS_STORAGE_INT */
             switch (p->value.type) {
             case CSS_VALUE_COLOR:
             case CSS_UNIT_NONE:
             case CSS_VALUE_INTEGER:
-                *ptr = p->value.u.val;
+                ptr->val = p->value.u.val;
                 break;
             case CSS_UNIT_PIXEL:
                 /* convert from px to display pixels */
-                *ptr = (p->value.u.val * s->px_size) >> CSS_LENGTH_FRAC_BITS;
+                ptr->val = (p->value.u.val * s->px_size) >> 
CSS_LENGTH_FRAC_BITS;
                 break;
             case CSS_UNIT_IN:
                 /* convert from inches to display pixels */
-                *ptr = (p->value.u.val * s->dots_per_inch) >> 
CSS_LENGTH_FRAC_BITS;
+                ptr->val = (p->value.u.val * s->dots_per_inch) >> 
CSS_LENGTH_FRAC_BITS;
                 break;
             case CSS_UNIT_PERCENT:
-                val = *(int *)((char *)state_parent + def->struct_offset);
-                *ptr = (p->value.u.val * val) >> CSS_LENGTH_FRAC_BITS;
+                val = parent_ptr->val;
+                ptr->val = (p->value.u.val * val) >> CSS_LENGTH_FRAC_BITS;
                 break;
             case CSS_UNIT_EX:
                 /* currently, we do not use the font metrics */
                 val = (state->font_size * CSS_EX_SCALE) >>
                     CSS_LENGTH_FRAC_BITS;
-                *ptr = (p->value.u.val * val) >> CSS_LENGTH_FRAC_BITS;
+                ptr->val = (p->value.u.val * val) >> CSS_LENGTH_FRAC_BITS;
                 break;
             case CSS_UNIT_EM:
                 /* special case for font size : inherit from parent */
@@ -495,7 +502,7 @@
                     val = state_parent->font_size;
                 else
                     val = state->font_size;
-                *ptr = (p->value.u.val * val) >> CSS_LENGTH_FRAC_BITS;
+                ptr->val = (p->value.u.val * val) >> CSS_LENGTH_FRAC_BITS;
                 break;
             }
         }
@@ -712,36 +719,57 @@
                     CSSState *state_parent)
 {
     const CSSPropertyDef *def;
-    int *ptr_parent, *ptr, type, val, i;
+    CSSPropertyStorage *ptr, *parent_ptr;
+    int type, val, i;
     CSSProperty *p;
     int pelement_found;
 
     /* inherit properties or set to default value */
-    def = css_properties;
-    while (def < css_properties + NB_PROPERTIES) {
+    for (i = 0; i < NB_PROPERTIES; i++) {
+        def = &css_properties[i];
         type = def->type;
-        /* the TYPE_FOUR are not real css properties */
-        if (!(type & CSS_TYPE_FOUR)) {
-            ptr = (int *)((char *)state + def->struct_offset);
+
+        if (type & CSS_TYPE_FOUR) {
+            /* skip dummy css properties for groups of 4
+             * (left,right,top,bottom)
+             */
+            continue;
+        }
+
+        ptr = CSSPropertyStoragePtr(state, def->struct_offset);
             if (def->type & CSS_TYPE_INHERITED) {
                 /* inherit value */
-                ptr_parent = (int *)((char *)state_parent + 
def->struct_offset);
-                val = *ptr_parent;
+            parent_ptr = CSSPropertyStoragePtr(state_parent, 
def->struct_offset);
+            /* XXX: invalid if pointer? */
+            switch (def->storage) {
+            default:
+            case CSS_STORAGE_INT:
+                ptr->val = parent_ptr->val;
+                break;
+            case CSS_STORAGE_PTR:
+                ptr->ptr = parent_ptr->ptr;
+                break;
+            }
             } else {
-                /* default values: color assumed to transparent, and
-                   if auto is a possible value, then it is
-                   set. Otherwise zero is the value */
+            if (def->storage == CSS_STORAGE_PTR) {
+                ptr->ptr = NULL;
+            } else {
+                /* def->storage == CSS_STORAGE_INT */
+
                 if (type & CSS_TYPE_COLOR) {
+                    /* Colors default to transparent. */
                     val = COLOR_TRANSPARENT;
-                } else if (type & CSS_TYPE_AUTO) {
+                } else
+                if (type & CSS_TYPE_AUTO) {
+                    /* If auto is a possible value, set it. */
                     val = CSS_AUTO;
                 } else {
+                    /* Otherwise, 0 is the default value. */
                     val = 0;
                 }
+                ptr->val = val;
             }
-            *ptr = val;
         }
-        def++;
     }
 
     /* apply generic attributes */
@@ -753,18 +781,18 @@
     }
 
     /* apply explicit properties */
-    p = box->properties;
-    while (p != NULL) {
+    for (p = box->properties; p != NULL; p = p->next) {
         css_eval_property(s, state, p, state_parent, box);
-        p = p->next;
     }
 
     /* first reset counters */
-    if (state->counter_reset)
+    if (state->counter_reset) {
         eval_counter_update(s, state->counter_reset);
+    }
     /* then increment */
-    if (state->counter_increment)
+    if (state->counter_increment) {
         eval_counter_update(s, state->counter_increment);
+    }
     /* alternate content if image (need more ideas) */
     if (state->content_alt &&
         box->content_type == CSS_CONTENT_TYPE_IMAGE) {
@@ -2421,7 +2449,7 @@
         /* remove all boxes from the stack */
         s->box_stack_index = box_stack_base;
     }
-done:
+  done:
     css_release_font(s->ctx->screen, font);
 
     return ret;

Index: css.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/css.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- css.h       23 Apr 2008 17:05:51 -0000      1.9
+++ css.h       24 Apr 2008 14:02:42 -0000      1.10
@@ -1,3 +1,24 @@
+/*
+ * CSS core for qemacs.
+ *
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ * Copyright (c) 2007-2008 Charlie Gordon.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 #ifndef CSS_H
 #define CSS_H
 
@@ -218,6 +239,13 @@
 
 } CSSPropertyDef;
 
+typedef union CSSPropertyStorage {
+    int val;                  /* CSS_STORAGE_INT */
+    struct CSSProperty *ptr;  /* CSS_STORAGE_PTR */
+} CSSPropertyStorage;
+
+#define CSSPropertyStoragePtr(s, off)  ((CSSPropertyStorage*)((char*)(s) + 
(off)))
+
 extern const CSSPropertyDef css_properties[NB_PROPERTIES];
 
 /* CSS parsing */
@@ -648,5 +676,5 @@
 int css_read(CSSFile *f, char *buf, int size);
 void css_close(CSSFile *f);
 
-extern const char docbook_style[];
-extern const char html_style[];
+extern char const docbook_style[];
+extern char const html_style[];

Index: cssid.h
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/cssid.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -b -r1.1.1.1 -r1.2
--- cssid.h     29 May 2004 10:19:50 -0000      1.1.1.1
+++ cssid.h     24 Apr 2008 14:02:42 -0000      1.2
@@ -1,3 +1,23 @@
+/*
+ * CSS core for qemacs.
+ *
+ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 /* definition of builtin CSS identifiers for easy testing in C code */
 
      CSSID(class)

Index: csstoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/csstoqe.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- csstoqe.c   8 Jan 2008 16:37:55 -0000       1.7
+++ csstoqe.c   24 Apr 2008 14:02:42 -0000      1.8
@@ -61,8 +61,18 @@
                 continue;
             }
             /* comments */
-            /* CG: allow // comments ? */
+            if (c == '/' && peekc(stdin) == '/') {
+                /* C++ like comment */
+                for (;;) {
+                    c = getchar();
+                    if (c == EOF)
+                        goto the_end;
+                    if (c == '\n')
+                        goto end_comment;
+                }
+            }
             if (c == '/' && peekc(stdin) == '*') {
+                /* C like comment */
                 getchar();
                 for (;;) {
                     c = getchar();
@@ -81,8 +91,9 @@
                 continue;
             }
         }
-        if (n == 0)
+        if (n == 0) {
             printf("    \"");
+        }
         /* add separator if needed */
         if (!in_string && got_space && isalnum(c) && isalnum(last_c)) {
             putchar(' ');




reply via email to

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