/[qemacs]/qemacs/libqhtml/cssparse.c
ViewVC logotype

Diff of /qemacs/libqhtml/cssparse.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by chqrlie, Sun May 8 15:07:29 2005 UTC revision 1.4 by chqrlie, Wed May 11 15:12:14 2005 UTC
# Line 83  static int css_get_length(int *length_pt Line 83  static int css_get_length(int *length_pt
83          unit++;          unit++;
84          if (f < 0 && unit != CSS_UNIT_PERCENT)          if (f < 0 && unit != CSS_UNIT_PERCENT)
85              return -1;              return -1;
86          switch(unit) {          switch (unit) {
87          case CSS_UNIT_PIXEL:          case CSS_UNIT_PIXEL:
88              num = (int)(f);              num = (int)(f);
89              break;              break;
# Line 156  static char *css_parse_string(const char Line 156  static char *css_parse_string(const char
156      p = *pp;      p = *pp;
157      q = buf;      q = buf;
158      sep = *p++;      sep = *p++;
159      for(;;) {      for (;;) {
160          c = *p++;          c = *p++;
161          if (c == sep || c == '\0')          if (c == sep || c == '\0')
162              break;              break;
# Line 249  CSSProperty *css_parse_properties(CSSPar Line 249  CSSProperty *css_parse_properties(CSSPar
249          skip_spaces(&p);          skip_spaces(&p);
250          /* find the property */          /* find the property */
251          def = css_properties;          def = css_properties;
252          for(;;) {          for (;;) {
253              if (def >= css_properties + NB_PROPERTIES) {              if (def >= css_properties + NB_PROPERTIES) {
254                  css_error1(b, "unsupported property '%s'", property);                  css_error1(b, "unsupported property '%s'", property);
255                  /* property not found skip it: find next ';' */                  /* property not found skip it: find next ';' */
256                  while (*p && *p != ';')                  while (*p && *p != ';')
257                      p++;                      p++;
258                  goto next;                  goto next;
259              }              }
260              if (!strcmp(def->name, property))              if (!strcmp(def->name, property))
# Line 265  CSSProperty *css_parse_properties(CSSPar Line 265  CSSProperty *css_parse_properties(CSSPar
265          type = def->type;          type = def->type;
266    
267          nb_args = 0;          nb_args = 0;
268          for(;;) {          for (;;) {
269              /* get argument */              /* get argument */
270              skip_spaces(&p);              skip_spaces(&p);
271              if (*p == ';' || *p == '\0')              if (*p == ';' || *p == '\0')
# Line 395  CSSProperty *css_parse_properties(CSSPar Line 395  CSSProperty *css_parse_properties(CSSPar
395              goto next;              goto next;
396          got_val:          got_val:
397              /* specific handling may be necessary. We do them here */              /* specific handling may be necessary. We do them here */
398              switch(property_index) {              switch (property_index) {
399              case CSS_font_size:              case CSS_font_size:
400                  if (unit == CSS_UNIT_NONE) {                  if (unit == CSS_UNIT_NONE) {
401                      if (val == 7) {                      if (val == 7) {
# Line 432  CSSProperty *css_parse_properties(CSSPar Line 432  CSSProperty *css_parse_properties(CSSPar
432                  args[0].type = unit;                  args[0].type = unit;
433                  args[0].u.val = val;                  args[0].u.val = val;
434                  if (property_index == CSS_border) {                  if (property_index == CSS_border) {
435                      for(i=0;i<4;i++)                      for (i = 0; i < 4; i++)
436                          css_add_prop(&last_prop, property_index1 + 1 + i,                          css_add_prop(&last_prop, property_index1 + 1 + i,
437                                       &args[0]);                                       &args[0]);
438                  } else {                  } else {
# Line 457  CSSProperty *css_parse_properties(CSSPar Line 457  CSSProperty *css_parse_properties(CSSPar
457              CSSPropertyValue v1, v2, v3, v4;              CSSPropertyValue v1, v2, v3, v4;
458              /* handle specifically the four args case */              /* handle specifically the four args case */
459              v1 = args[0];              v1 = args[0];
460              switch(nb_args) {              switch (nb_args) {
461              case 1:              case 1:
462                  args[1] = args[2] = args[3] = v1;                  args[1] = args[2] = args[3] = v1;
463                  break;                  break;
# Line 485  CSSProperty *css_parse_properties(CSSPar Line 485  CSSProperty *css_parse_properties(CSSPar
485                  args[0] = v4;                  args[0] = v4;
486                  break;                  break;
487              }              }
488              for(i=0;i<4;i++)              for (i = 0; i < 4; i++)
489                  css_add_prop(&last_prop, property_index + 1 + i, &args[i]);                  css_add_prop(&last_prop, property_index + 1 + i, &args[i]);
490          } else if (type & CSS_TYPE_TWO) {          } else if (type & CSS_TYPE_TWO) {
491              if (nb_args == 1)              if (nb_args == 1)
492                  args[1] = args[0];                  args[1] = args[0];
493              for(i=0;i<2;i++)              for (i = 0; i < 2; i++)
494                  css_add_prop(&last_prop, property_index + 1 + i, &args[i]);                  css_add_prop(&last_prop, property_index + 1 + i, &args[i]);
495          } else if (type & CSS_TYPE_ARGS) {          } else if (type & CSS_TYPE_ARGS) {
496              /* unbounded number of args */              /* unbounded number of args */
# Line 524  void css_dump_properties(CSSProperty *pr Line 524  void css_dump_properties(CSSProperty *pr
524              printf("inherit");              printf("inherit");
525          } else {          } else {
526              value = &prop->value;              value = &prop->value;
527              for(j=0;j<prop->nb_values;j++) {              for (j = 0; j < prop-> nb_values;j++) {
528                  val = value->u.val;                  val = value->u.val;
529                  switch(value->type) {                  switch (value->type) {
530                  case CSS_UNIT_EX:                  case CSS_UNIT_EX:
531                      printf("%0.1fex", (double)val / CSS_LENGTH_FRAC_BASE);                      printf("%0.1fex", (double)val / CSS_LENGTH_FRAC_BASE);
532                      break;                      break;
# Line 550  void css_dump_properties(CSSProperty *pr Line 550  void css_dump_properties(CSSProperty *pr
550                          else                          else
551                              p = def->name + strlen(def->name) + 1;                              p = def->name + strlen(def->name) + 1;
552                          i = 0;                          i = 0;
553                          for(;;) {                          for (;;) {
554                              p1 = strchr(p, ',');                              p1 = strchr(p, ',');
555                              if (i == val) {                              if (i == val) {
556                                  if (!p1)                                  if (!p1)
# Line 619  static void free_selector(CSSSimpleSelec Line 619  static void free_selector(CSSSimpleSelec
619  {  {
620      CSSStyleSheetAttributeEntry *attr, *attr1;      CSSStyleSheetAttributeEntry *attr, *attr1;
621    
622      for(attr = ss->attrs; attr != NULL; attr = attr1) {      for (attr = ss->attrs; attr != NULL; attr = attr1) {
623          attr1 = attr->next;          attr1 = attr->next;
624          free(attr);          free(attr);
625      }      }
# Line 632  void css_free_style_sheet(CSSStyleSheet Line 632  void css_free_style_sheet(CSSStyleSheet
632      CSSProperty *p, *p1;      CSSProperty *p, *p1;
633      CSSSimpleSelector *ss, *ss1;      CSSSimpleSelector *ss, *ss1;
634    
635      for(e = s->first_entry; e != NULL; e = e1) {      for (e = s->first_entry; e != NULL; e = e1) {
636          e1 = e->next;          e1 = e->next;
637                    
638          for(ss = e->sel.next; ss != NULL; ss = ss1) {          for (ss = e->sel.next; ss != NULL; ss = ss1) {
639              ss1 = ss->next;              ss1 = ss->next;
640              free_selector(ss);              free_selector(ss);
641              free(ss);              free(ss);
642          }          }
643          free_selector(&e->sel);          free_selector(&e->sel);
644    
645          for(p = e->props; p != NULL; p = p1) {          for (p = e->props; p != NULL; p = p1) {
646              p1 = p->next;              p1 = p->next;
647              free(p);              free(p);
648          }          }
# Line 677  static int bgetc(CSSParseState *b) Line 677  static int bgetc(CSSParseState *b)
677                  b->ptr--;                  b->ptr--;
678              return '/';              return '/';
679          }          }
680          for(;;) {          for (;;) {
681              ch = bgetc1(b);              ch = bgetc1(b);
682              if (ch != '*')              if (ch != '*')
683                  continue;                  continue;
# Line 699  static void read_string(CSSParseState *b Line 699  static void read_string(CSSParseState *b
699    
700      quote = *ch_ptr;      quote = *ch_ptr;
701      q = ident;      q = ident;
702      for(;;) {      for (;;) {
703          ch = bgetc(b);          ch = bgetc(b);
704          if (ch == quote)          if (ch == quote)
705              break;              break;
# Line 718  static void read_ident(CSSParseState *b, Line 718  static void read_ident(CSSParseState *b,
718    
719      c = *ch_ptr;      c = *ch_ptr;
720      q = ident;      q = ident;
721      for(;;) {      for (;;) {
722          if (!((c >= 'A' && c <= 'Z') ||          if (!((c >= 'A' && c <= 'Z') ||
723                (c >= 'a' && c <= 'z') ||                (c >= 'a' && c <= 'z') ||
724                (c >= '0' && c <= '9') ||                (c >= '0' && c <= '9') ||
# Line 793  static void dup_selector(CSSSimpleSelect Line 793  static void dup_selector(CSSSimpleSelect
793    
794      first_attr = NULL;      first_attr = NULL;
795      plast_attr = &first_attr;      plast_attr = &first_attr;
796      for(attr = src->attrs; attr != NULL; attr = attr->next)      for (attr = src->attrs; attr != NULL; attr = attr->next)
797          add_attribute(&plast_attr, attr->attr,          add_attribute(&plast_attr, attr->attr,
798                        attr->op, attr->value);                        attr->op, attr->value);
799      memcpy(dest, src, sizeof(CSSSimpleSelector));      memcpy(dest, src, sizeof(CSSSimpleSelector));
# Line 806  static CSSProperty *dup_properties(CSSPr Line 806  static CSSProperty *dup_properties(CSSPr
806      CSSProperty *p, *first_p, **plast_p;      CSSProperty *p, *first_p, **plast_p;
807      first_p = NULL;      first_p = NULL;
808      plast_p = &first_p;      plast_p = &first_p;
809      for(p = props; p != NULL; p = p->next) {      for (p = props; p != NULL; p = p->next) {
810          css_add_prop_values(&plast_p, p->property, p->nb_values, &p->value);          css_add_prop_values(&plast_p, p->property, p->nb_values, &p->value);
811      }      }
812      return first_p;      return first_p;
# Line 818  void css_merge_style_sheet(CSSStyleSheet Line 818  void css_merge_style_sheet(CSSStyleSheet
818      CSSStyleSheetEntry *e, *e1;      CSSStyleSheetEntry *e, *e1;
819      CSSSimpleSelector *ss, *ss1, ss2, **pss;      CSSSimpleSelector *ss, *ss1, ss2, **pss;
820    
821      for(e = a->first_entry; e != NULL; e = e->next) {      for (e = a->first_entry; e != NULL; e = e->next) {
822          /* add selector */          /* add selector */
823          dup_selector(&ss2, &e->sel);          dup_selector(&ss2, &e->sel);
824          e1 = add_style_entry(s, &ss2, e->media);          e1 = add_style_entry(s, &ss2, e->media);
825                    
826          /* add selector operations */          /* add selector operations */
827          pss = &e1->sel.next;          pss = &e1->sel.next;
828          for(ss = e->sel.next; ss != NULL; ss = ss->next) {          for (ss = e->sel.next; ss != NULL; ss = ss->next) {
829              ss1 = malloc(sizeof(CSSSimpleSelector));              ss1 = malloc(sizeof(CSSSimpleSelector));
830              dup_selector(ss1, ss);              dup_selector(ss1, ss);
831              *pss = ss1;              *pss = ss1;
# Line 874  static void parse_simple_selector(CSSSim Line 874  static void parse_simple_selector(CSSSim
874          css_strtolower(tag, sizeof(tag));          css_strtolower(tag, sizeof(tag));
875    
876      /* read '.class', '[xxx]', ':pseudo-class' */      /* read '.class', '[xxx]', ':pseudo-class' */
877      for(;;) {      for (;;) {
878          bskip_spaces(b, &ch);          bskip_spaces(b, &ch);
879          if (ch == '.') {          if (ch == '.') {
880              /* read the class and add it as an attribute */              /* read the class and add it as an attribute */
# Line 893  static void parse_simple_selector(CSSSim Line 893  static void parse_simple_selector(CSSSim
893              if (b->ignore_case)              if (b->ignore_case)
894                  css_strtolower(attribute, sizeof(attribute));                  css_strtolower(attribute, sizeof(attribute));
895    
896              switch(ch) {              switch (ch) {
897              case '~':              case '~':
898                  op = CSS_ATTR_OP_IN_LIST;                  op = CSS_ATTR_OP_IN_LIST;
899                  ch = bgetc(b);                  ch = bgetc(b);
# Line 966  void css_parse_style_sheet(CSSStyleSheet Line 966  void css_parse_style_sheet(CSSStyleSheet
966            
967      ch = bgetc(b);      ch = bgetc(b);
968      media = CSS_MEDIA_ALL;      media = CSS_MEDIA_ALL;
969      for(;;) {      for (;;) {
970      redo:      redo:
971          first_eprops = s->plast_entry;          first_eprops = s->plast_entry;
972          bskip_spaces(b, &ch);          bskip_spaces(b, &ch);
# Line 985  void css_parse_style_sheet(CSSStyleSheet Line 985  void css_parse_style_sheet(CSSStyleSheet
985          if (ch == '@') {          if (ch == '@') {
986              ch = bgetc(b);              ch = bgetc(b);
987              read_ident(b, &ch, tag, sizeof(tag));              read_ident(b, &ch, tag, sizeof(tag));
988              switch(css_get_enum(tag, "media,page")) {              switch (css_get_enum(tag, "media,page")) {
989              case 0:              case 0:
990                  /* @media */                  /* @media */
991                  media = 0;                  media = 0;
992                  for(;;) {                  for (;;) {
993                      bskip_spaces(b, &ch);                      bskip_spaces(b, &ch);
994                      read_ident(b, &ch, tag, sizeof(tag));                      read_ident(b, &ch, tag, sizeof(tag));
995                      val = css_get_enum(tag, "tty,screen,print,tv,speech,all");                      val = css_get_enum(tag, "tty,screen,print,tv,speech,all");
# Line 1030  void css_parse_style_sheet(CSSStyleSheet Line 1030  void css_parse_style_sheet(CSSStyleSheet
1030          }          }
1031                                    
1032          /* parse a selector list */          /* parse a selector list */
1033          for(;;) {          for (;;) {
1034              /* parse simple selectors with operations */              /* parse simple selectors with operations */
1035              last_ss = NULL;              last_ss = NULL;
1036              last_tree_op = CSS_TREE_OP_NONE;              last_tree_op = CSS_TREE_OP_NONE;
1037              for(;;) {              for (;;) {
1038                  int tree_op;                  int tree_op;
1039                  bskip_spaces(b, &ch);                  bskip_spaces(b, &ch);
1040                  parse_simple_selector(ss, b, &ch);                  parse_simple_selector(ss, b, &ch);
# Line 1094  void css_parse_style_sheet(CSSStyleSheet Line 1094  void css_parse_style_sheet(CSSStyleSheet
1094             problems, but it would still not be sufficient. */             problems, but it would still not be sufficient. */
1095          props = css_parse_properties(b, value);          props = css_parse_properties(b, value);
1096          i = 0;          i = 0;
1097          for(e = *first_eprops; e != NULL; e = e->next) {          for (e = *first_eprops; e != NULL; e = e->next) {
1098              if (i == 0)              if (i == 0)
1099                  e->props = props;                  e->props = props;
1100              else              else
# Line 1122  static void dump_selector(CSSSimpleSelec Line 1122  static void dump_selector(CSSSimpleSelec
1122  {  {
1123      CSSStyleSheetAttributeEntry *ae;      CSSStyleSheetAttributeEntry *ae;
1124    
1125      switch(ss->tree_op) {      switch (ss->tree_op) {
1126      case CSS_TREE_OP_DESCENDANT:      case CSS_TREE_OP_DESCENDANT:
1127          dump_selector(ss->next);          dump_selector(ss->next);
1128          printf(" ");          printf(" ");
# Line 1148  static void dump_selector(CSSSimpleSelec Line 1148  static void dump_selector(CSSSimpleSelec
1148      ae = ss->attrs;      ae = ss->attrs;
1149      while (ae != NULL) {      while (ae != NULL) {
1150          printf("[%s", css_ident_str(ae->attr));          printf("[%s", css_ident_str(ae->attr));
1151          switch(ae->op) {          switch (ae->op) {
1152          case CSS_ATTR_OP_EQUAL:          case CSS_ATTR_OP_EQUAL:
1153              printf("=%s", ae->value);              printf("=%s", ae->value);
1154              break;              break;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26