⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.c

📁 飞漫公司的minigui的1.6.8收费增值版本的demon等示例程序
💻 C
📖 第 1 页 / 共 5 页
字号:
            a_Dw_page_hand_over_break(DW_PAGE(html->dw),                                    html->stack[(html)->stack_top].style);        a_Dw_page_flush(DW_PAGE(html->dw));        html->dw = html->stack[html->stack_top].page;    }}/* * Push the tag (copying attributes from the top of the stack) */static void Html_push_tag(DilloHtml *html, char *tag, int tagsize){    char *tagstr;    int n_items;    /* Save the element's name (no parameters) into tagstr. */    tagstr = g_strdup(Html_tags_get_name(html->CurrTagIdx));    n_items = html->stack_top + 1;    a_List_add(html->stack, n_items, html->stack_max);    /* We'll copy the former stack item and just change the tag and its index     * instead of copying all fields except for tag.  --Jcid */    html->stack[n_items] = html->stack[n_items - 1];    html->stack[n_items].tag = tagstr;    html->stack[n_items].tag_idx = html->CurrTagIdx;    html->stack_top = n_items;    /* proper memory management, may be unref'd later */    a_Dw_style_ref (html->stack[html->stack_top].style);    if (html->stack[html->stack_top].table_cell_style)        a_Dw_style_ref (html->stack[html->stack_top].table_cell_style);    html->dw = html->stack[html->stack_top].page;}/* * Remove the stack's topmost tag (only if it matches) * If it matches, TRUE is returned. */static gboolean Html_cleanup_tag(DilloHtml *html, char *tag){    if (html->stack_top &&            Html_match_tag(html->stack[html->stack_top].tag, tag, strlen(tag))) {        a_Dw_style_unref (html->stack[html->stack_top].style);        if (html->stack[html->stack_top].table_cell_style)            a_Dw_style_unref (html->stack[html->stack_top].table_cell_style);        g_free(html->stack[html->stack_top--].tag);        Html_eventually_pop_dw(html);        return TRUE;    }    else        return FALSE;}/* * Default close function for tags. * (conditional cleanup of the stack) * There're several ways of doing it. Considering the HTML 4.01 spec * which defines optional close tags, and the will to deliver useful diagnose * messages for bad-formed HTML, it'll go as follows: *   1.- Search the stack for the first tag that requires a close tag. *   2.- If it matches, clean all the optional-close tags in between. *   3.- Cleanup the matching tag. (on error, give a warning message) * * If 'old_mode' is enabled: *   1.- Search the stack for a matching tag. *   2.- If it exists, clean all the tags in between. *   3.- Cleanup the matching tag. (on error, give a warning message) */static void Html_tag_cond_cleanup(DilloHtml *html, char *tag, int tagsize,                                  int old_mode){    int stack_idx, cmp = 1;    /* Look for the candidate tag to close */    stack_idx = html->stack_top;    while (stack_idx &&            (cmp = strcmp(Html_tags_get_name(html->CurrTagIdx),                        html->stack[stack_idx].tag)) &&            (old_mode ||                Html_tags_get_endtag(html->stack[stack_idx].tag_idx) == 'O')){        --stack_idx;    }    if (stack_idx == 0)        return;    /* clean, up to the matching tag */    if (cmp == 0) {        /* There's a valid matching tag in the stack */        while (html->stack_top >= stack_idx) {            a_Dw_style_unref (html->stack[html->stack_top].style);            if (html->stack[html->stack_top].table_cell_style)                a_Dw_style_unref (html->stack[html->stack_top].table_cell_style);            g_free(html->stack[html->stack_top--].tag);        }        Html_eventually_pop_dw(html);    }    else {        char *stag = g_strndup(tag, tagsize);        MSG_HTML("unexpected closing tag: %s. -- expected </%s>\n",                stag, html->stack[stack_idx].tag);        g_free(stag);    }}/* * Do a paragraph break and push the tag. This pops unclosed <p> tags * off the stack, if there are any. */static void Html_par_push_tag (DilloHtml *html, char *tag, int tagsize){    Html_push_tag (html, tag, tagsize);    a_Dw_page_add_parbreak (DW_PAGE (html->dw), 9,                          html->stack[(html)->stack_top].style);}/* * Cleanup (conditional), and Pop the tag (if it matches) */static void Html_pop_tag(DilloHtml *html, char *tag, int tagsize){    Html_tag_cond_cleanup(html, tag, tagsize, prefs.use_old_parser);}/* * Some parsing routines. *//* * Used by Html_parse_length and Html_parse_multi_length_list. */static DwStyleLength Html_parse_length_or_multi_length (const char *attr,                                                        char **endptr){    DwStyleLength l;    double v;    char *end;    v = strtod (attr, &end);    switch (*end) {    case '%':        end++;        l = DW_STYLE_CREATE_PER_LENGTH (v / 100);        break;    case '*':        end++;        l = DW_STYLE_CREATE_REL_LENGTH (v);        break;    default:        l = DW_STYLE_CREATE_ABS_LENGTH ((int)v);        break;    }    if (endptr)        *endptr = end;    return l;}/* * Returns a length or a percentage, or DW_STYLE_UNDEF_LENGTH in case * of an error, or if attr is NULL. */static DwStyleLength Html_parse_length (DilloHtml *html, const char *attr){    DwStyleLength l;    char *end;    l = Html_parse_length_or_multi_length (attr, &end);    if (DW_STYLE_IS_REL_LENGTH (l))        /* not allowed as &Length; */        return DW_STYLE_LENGTH_AUTO;    else {        /* allow only whitespaces */        if (*end && !isspace (*end)) {            MSG_HTML("Garbage after length: %s\n", attr);            return DW_STYLE_LENGTH_AUTO;        }    }    return l;}/* * Returns a vector of lenghts/percentages. The caller has to g_free the * result when it is not longer used. *//*static DwStyleLength *Html_parse_multi_length_list (const char *attr){   DwStyleLength *l;   int n, max_n;   char *end;   n = 0;   max_n = 8;   l = g_malloc0 (max_n, sizeof (DwStyleLength));   while (TRUE) {      l[n] = Html_parse_length_or_multi_length (attr, &end);      n++;      a_List_add (l, n, max_n);      while (isspace (*end))         end++;      if (*end == ',')         attr = end + 1;      else         // error or end         break;   }   l[n] = DW_STYLE_LENGTH_AUTO;   return l;}*//* * Parse a color attribute. * Return value: parsed color, or default_color (+ error msg) on error. */static gint32 Html_color_parse(DilloHtml *html, const char *subtag, gint32 default_color){    int err = 1;    gint32 color = a_Color_parse (subtag, default_color, &err);    if (err) {        MSG_HTML("color is not in \"#RRGGBB\" format\n");    }    return color;}/* * Handle open HEAD element */static void Html_tag_open_head(DilloHtml *html, char *tag, int tagsize){    if (html->InFlags & IN_BODY) {        MSG_HTML("HEAD element must go before the BODY section\n");    } else {        Html_push_tag(html, tag, tagsize);        html->InFlags |= IN_HEAD;    }}/* * Handle close HEAD element */static void Html_tag_close_head(DilloHtml *html, char *tag, int tagsize){    Html_pop_tag(html, tag, tagsize);    html->InFlags &= ~IN_HEAD;}/* * Handle open TITLE * calls stash init, where the title string will be stored */static void Html_tag_open_title(DilloHtml *html, char *tag, int tagsize){    Html_push_tag(html, tag, tagsize);    Html_stash_init(html);}/* * Handle close TITLE * set page-title in the browser window and in the history. */static void Html_tag_close_title(DilloHtml *html, char *tag, int tagsize){    if (html->InFlags & IN_HEAD) {        /* title is only valid inside HEAD */#if 0        a_Interface_set_page_title(html->linkblock->bw, html->Stash->str);        a_History_set_title(NAV_TOP(html->linkblock->bw), html->Stash->str);#else        printf ("Calling a_Interface_set_page_title: %s\n", html->Stash->str);#endif    }    else {        MSG_HTML("the TITLE element must be inside the HEAD section\n");    }    Html_pop_tag(html, tag, tagsize);}/* * Handle open SCRIPT * initializes stash, where the embedded code will be stored. * MODE_VERBATIM is used because MODE_STASH catches entities. */static void Html_tag_open_script(DilloHtml *html, char *tag, int tagsize){    Html_push_tag(html, tag, tagsize);    Html_stash_init(html);    html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_VERBATIM;}/* * Handle close SCRIPT */static void Html_tag_close_script(DilloHtml *html, char *tag, int tagsize){    /* eventually the stash will be sent to an interpreter for parsing */    Html_pop_tag(html, tag, tagsize);}/* * Handle open STYLE * store the contents to the stash where (in the future) the style * sheet interpreter can get it. */static void Html_tag_open_style(DilloHtml *html, char *tag, int tagsize){    Html_push_tag(html, tag, tagsize);    Html_stash_init(html);    html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_VERBATIM;}/* * Handle close STYLE */static void Html_tag_close_style(DilloHtml *html, char *tag, int tagsize){    /* eventually the stash will be sent to an interpreter for parsing */    Html_pop_tag(html, tag, tagsize);}/* * <BODY> */static void Html_tag_open_body(DilloHtml *html, char *tag, int tagsize){    const char *attrbuf;    DwPage *page;    DwStyle style_attrs, *style;    guint32 color;    page = DW_PAGE (html->dw);    /* HEAD to BODY section transition was done by Html_test_body_section() */    if (!prefs.force_my_colors) {        if ((attrbuf = Html_get_attr(html, tag, tagsize, "bgcolor"))) {            color = Html_color_parse(html, attrbuf, prefs.bg_color);            if ( (color == 0xffffff && !prefs.allow_white_bg) ||                    prefs.force_my_colors )            color = prefs.bg_color;            style_attrs = *html->dw->style;            style_attrs.background_color =                a_Dw_style_color_new (color, html->bw->main_window);            style = a_Dw_style_new (&style_attrs, html->bw->main_window);            a_Dw_widget_set_style (html->dw, style);            a_Dw_style_unref (style);            html->stack[html->stack_top].current_bg_color = color;        }        if ((attrbuf = Html_get_attr(html, tag, tagsize, "text"))) {            color = Html_color_parse(html, attrbuf, prefs.text_color);            HTML_SET_TOP_ATTR (html, color,                a_Dw_style_color_new (color, html->bw->main_window));        }        if ((attrbuf = Html_get_attr(html, tag, tagsize, "link")))            html->linkblock->link_color = Html_color_parse(html, attrbuf,                                                            prefs.link_color);        if ((attrbuf = Html_get_attr(html, tag, tagsize, "vlink")))            html->linkblock->visited_color =                Html_color_parse(html, attrbuf, prefs.visited_color);        if (prefs.force_visited_color &&            html->linkblock->link_color == html->linkblock->visited_color) {            /* get a color that has a "safe distance" from text, link and bg */            html->linkblock->visited_color =                a_Color_vc(html->stack[html->stack_top].style->color->color_val,                        html->linkblock->link_color,                        html->stack[html->stack_top].current_bg_color);        }    }    Html_push_tag (html, tag, tagsize);    html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_BODY;    html->InFlags |= IN_BODY;}/* * <P> * todo: what's the point between adding the parbreak before and *       after the push? * todo: <P> should be closed upon openning a 'block' element. */static void Html_tag_open_p(DilloHtml *html, char *tag, int tagsize){    Html_par_push_tag(html, tag, tagsize);    Html_tag_set_align_attr (html, tag, tagsize);    a_Dw_page_add_parbreak(DW_PAGE (html->dw), 9,                          html->stack[(html)->stack_top].style);}/* * <TABLE> */static void Html_tag_open_table(DilloHtml *html, char *tag, int tagsize)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -