/* static void css_parse(Tcs3_diag *diag, gchar *data) * the buffer 'data' should contain a css stylesheet * the comments are removed from this buffer by this function * so if you don't want this, make a copy of the stylesheet * before you pass it on to this function */ static void css_parse(Tcs3_diag *diag, gchar *data) { gchar *tmp = data; gint count = 0, parsable_css = 1; if (!data) { DEBUG_MSG("css_parse, no data!\n"); return; } if (diag->styletype == onestyle) { gint prev_end = 0; Tcs3_prevtype_onestyle prevtype = end; gchar *text[3] = {NULL, NULL, NULL}; DEBUG_MSG("css_parse, onestyle\n"); while (tmp[count] && parsable_css) { switch (tmp[count]) { case ':': if (prevtype == end) { text[0] = g_strndup(&tmp[prev_end], count - prev_end); strip_any_whitespace(text[0]); prev_end = count+1; prevtype = property; } break; case ';': if (prevtype == property) { text[1] = g_strndup(&tmp[prev_end], count - prev_end); strip_any_whitespace(text[1]); prev_end = count+1; prevtype = value; } break; case '*': if ((count > 0)&& (tmp[count-1] == '/')) { gint count2 = count, cont=1, movelen; DEBUG_MSG("css_parse, found the start of a comment on %d\n", count); while (tmp[++count2] && cont) { if (tmp[count2] == '/' && tmp[count2-1] == '*') { cont=0; } } DEBUG_MSG("css_parse, before move, tmp='%s'\n", tmp); movelen = strlen(&tmp[count2]); memmove(&tmp[count-1], &tmp[count2], movelen); tmp[count-1 + movelen] = '\0'; DEBUG_MSG("css_parse, after move, tmp='%s'\n", tmp); } break; case '<': case '>': parsable_css = 0; DEBUG_MSG("css_parse, this is not a valid stylesheet\n"); break; default: /* do nothing */ break; } if (prevtype == value) { GtkTreeIter iter; gtk_list_store_append(diag->lstore, &iter); gtk_list_store_set(diag->lstore,&iter,1, text[0],2,text[1],-1); /*gtk_clist_append(GTK_CLIST(diag->clist), text);*/ g_free(text[0]); g_free(text[1]); prevtype = end; } count++; } } else { /* multistyle */ gint prev_end = 0, i; Tcs3_prevtype_multistyle prevtype = mselectorend; gchar *text[4] = {NULL, NULL, NULL, NULL}; DEBUG_MSG("css_parse, multistylestyle\n"); while (tmp[count] && parsable_css) { switch (tmp[count]) { case '}': /* found end of block */ if (prevtype != mselectorend) { prevtype = mselectorend; prev_end = count+1; g_free(text[0]); text[0]=NULL; } break; case '{': /* found selector */ if (prevtype == mselectorend) { text[0] = g_strndup(&tmp[prev_end], count - prev_end); strip_any_whitespace(text[0]); prev_end = count+1; prevtype = mselector; } break; case ':': if (prevtype == mselector || prevtype == mend) { text[1] = g_strndup(&tmp[prev_end], count - prev_end); strip_any_whitespace(text[1]); prev_end = count+1; prevtype = mproperty; } break; case ';': if (prevtype == mproperty) { text[2] = g_strndup(&tmp[prev_end], count - prev_end); strip_any_whitespace(text[2]); prev_end = count+1; prevtype = mvalue; } break; case '*': if ((count > 0)&& (tmp[count-1] == '/')) { gint count2 = count, cont=1, movelen; DEBUG_MSG("css_parse, found the start of a comment on %d\n", count); while (tmp[++count2] && cont) { if (tmp[count2] == '/' && tmp[count2-1] == '*') { cont=0; } } DEBUG_MSG("css_parse, before move, tmp='%s'\n", tmp); movelen = strlen(&tmp[count2]); memmove(&tmp[count-1], &tmp[count2], movelen); tmp[count-1 + movelen] = '\0'; DEBUG_MSG("css_parse, after move, tmp='%s'\n", tmp); } break; case '<': case '>': parsable_css = 0; DEBUG_MSG("css_parse, this is not a valid stylesheet\n"); break; default: /* do nothing */ break; } if (prevtype == mvalue) { GtkTreeIter iter; gtk_list_store_append(diag->lstore, &iter); gtk_list_store_set(diag->lstore,&iter,0,text[0],1, text[1],2,text[2],-1); /*gtk_clist_append(GTK_CLIST(diag->clist), text);*/ g_free(text[1]); text[1] = NULL; g_free(text[2]); text[2] = NULL; prevtype = mend; } count++; } for (i=0;i<4;i++) { if (text[i]){ g_free(text[i]); } } } /*gtk_clist_sort(GTK_CLIST(diag->clist));*/ DEBUG_MSG("css_parse, finished\n"); }
static void parse_tagstring(Tbfwin *bfwin, gchar * tagstring, gint pos, gint end) { GList *tmplist = NULL; gchar *tmpstring, *item, *value, *tmp; gint count, prevtag, item_value_delimiter; Ttagitem *tag_item; Ttagpopup *tag_popup; gboolean in_quote, has_quotes; Ttagdialog tagdia[] = { {"body", G_CALLBACK(body_dialog)}, {"a", G_CALLBACK(quickanchor_dialog)}, {"p", G_CALLBACK(p_dialog)}, {"div", G_CALLBACK(div_dialog)}, {"span", G_CALLBACK(span_dialog)}, {"h1", G_CALLBACK(h1_dialog)}, {"h2", G_CALLBACK(h2_dialog)}, {"h3", G_CALLBACK(h3_dialog)}, {"h4", G_CALLBACK(h4_dialog)}, {"h5", G_CALLBACK(h5_dialog)}, {"h6", G_CALLBACK(h6_dialog)}, {"hr", G_CALLBACK(quickrule_dialog)}, {"font", G_CALLBACK(font_dialog)}, {"basefont", G_CALLBACK(basefont_dialog)}, {"table", G_CALLBACK(tabledialog_dialog)}, {"tr", G_CALLBACK(tablerowdialog_dialog)}, {"th", G_CALLBACK(tableheaddialog_dialog)}, {"td", G_CALLBACK(tabledatadialog_dialog)}, {"frameset", G_CALLBACK(frameset_dialog)}, {"frame",G_CALLBACK(frame_dialog)}, {"form",G_CALLBACK(formdialog_dialog)}, {"textarea",G_CALLBACK(textareadialog_dialog)}, {"select",G_CALLBACK(selectdialog_dialog)}, {"option",G_CALLBACK(optiondialog_dialog)}, {"meta",G_CALLBACK(meta_dialog)}, {"img",G_CALLBACK(image_insert_dialog)}, {"input",G_CALLBACK(inputdialog_rpopup)}, {"button",G_CALLBACK(buttondialog_dialog)}, {"link",G_CALLBACK(linkdialog_dialog)} }; DEBUG_MSG("parse_tagstring, started, tagstring=%s\n", tagstring); /* parsing the values from this tag */ tmpstring = g_strdup(tagstring); strip_any_whitespace(tmpstring); item_value_delimiter = prevtag = count = 0; has_quotes = in_quote = FALSE; while (tmpstring[count] != '\0') { /* extra spacing like between the name = value can be ignored */ if (g_ascii_isspace((gchar)tmpstring[count])) { gint count2 = count+1; /* search for the next character, is that a = or a " then we will ignore this space */ while (tmpstring[count2] != '\0') { if (g_ascii_isspace((gchar)tmpstring[count2]) || tmpstring[count2]=='\n') { count2++; } else { if (tmpstring[count2] == '=' || tmpstring[count2] == '"') { DEBUG_MSG("found ignorable spaces, increasing count from %d to %d\n", count, count2); count = count2; } break; } } } DEBUG_MSG("tmpstring[%d]=%c\n",count,tmpstring[count]); /* spaces (delimiters) are allowed within quotes, so we have to keep track of quotes */ if (tmpstring[count] == '"') { has_quotes = TRUE; if (in_quote) { in_quote = FALSE; } else { in_quote = TRUE; } } /* to split the item and the value we have to keep track of '=' characters */ if (tmpstring[count] == '=' && !in_quote) { item_value_delimiter = count; } /* it is a delimiter if it a space (or tab, newline), outside a quote or the last character of the string */ if ((g_ascii_isspace((gchar)tmpstring[count]) && (in_quote == FALSE)) || (tmpstring[count + 1] == '\0')) { if (prevtag == (count - 1)) { DEBUG_MSG("parse_tagstring, two spaces!\n"); prevtag = count; } else if (prevtag == 0) { DEBUG_MSG("parse_tagstring, this is the name of the tag itself\n"); prevtag = count; } else { DEBUG_MSG("parse_tagstring, making split, count=%d, prevtag=%d\n", count, prevtag); if (item_value_delimiter > prevtag) { item = g_strndup(&tmpstring[prevtag + 1], item_value_delimiter - prevtag - 1); DEBUG_MSG("item from %d to %d=%s\n", prevtag+1, item_value_delimiter - prevtag - 1, item); if (has_quotes == TRUE) { gchar *tmp; tmp = g_strndup(&tmpstring[item_value_delimiter + 1], count - item_value_delimiter - 1); g_strstrip(tmp); value = g_strndup(&tmp[1], strlen(tmp)-1); g_free(tmp); value = trunc_on_char(value, '"'); DEBUG_MSG("value from %d to %d=%s", item_value_delimiter + 2, count - item_value_delimiter - 2, value); } else { value = g_strndup(&tmpstring[item_value_delimiter + 1], count - item_value_delimiter); g_strstrip(value); } } else { item = g_strndup(&tmpstring[prevtag + 1], count - prevtag); value = g_strdup(""); } tmp = item; item = g_utf8_strdown(item, -1); g_free (tmp); g_strstrip(item); tag_item = g_malloc(sizeof(Ttagitem)); tag_item->item = item; tag_item->value = value; tmplist = g_list_append(tmplist, tag_item); DEBUG_MSG("parse_tagstring, item=%s with value=%s appended to list %p\n", item, value, tmplist); prevtag = count; has_quotes = FALSE; } } count++; } g_free(tmpstring); tag_popup = g_malloc(sizeof(Ttagpopup)); tag_popup->taglist = tmplist; tag_popup->pos = pos; tag_popup->end = end; DEBUG_MSG("parse_tagstring, tag_popup->pos=%d, tag_popup->end=%d\n", tag_popup->pos, tag_popup->end); tmpstring = g_strdup(tagstring); tmpstring = trunc_on_char(tmpstring, ' '); tmp = tmpstring; tmpstring = g_utf8_strdown(tmpstring, -1); g_free (tmp); /* identifying which tag we have */ DEBUG_MSG("parse_tagstring, searching for dialog for %s\n", tmpstring); { gint i, numitems = (sizeof(tagdia)/sizeof(Ttagdialog)); for (i=0;i<numitems;i++) { if (strcmp(tmpstring, tagdia[i].tag) == 0) { tagdia[i].func(bfwin, tag_popup); break; } } } /* if (strcmp(tmpstring, "card") == 0) { carddialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "postfield") == 0) { postfielddialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "setvar") == 0) { vardialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "go") == 0) { godialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "do") == 0) { dodialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "anchor") == 0) { anchordialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "access") == 0) { accessdialog_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "script") == 0) { script_cb(NULL, tag_popup); } else if (strcmp(tmpstring, "link") == 0) { link_cb(NULL, tag_popup); } else*/ /* if (strcmp(tmpstring, "input") == 0) { DEBUG_MSG("parse_tagstring, identified as INPUT tag, splitting tag!\n"); input_tag_splitter(bfwin, tag_popup); }*/ tmplist = g_list_first(tmplist); while (tmplist) { g_free(((Ttagitem *) tmplist->data)->item); g_free(((Ttagitem *) tmplist->data)->value); g_free(tmplist->data); tmplist = g_list_next(tmplist); } g_list_free(tmplist); g_free(tag_popup); g_free(tmpstring); }