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

📄 pprint.c

📁 我搜集到的一个java常用类库的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        PPrintAsp(fout, indent, lexer, node);    else if (node->type == JsteTag)        PPrintJste(fout, indent, lexer, node);    else if (node->type == PhpTag)        PPrintPhp(fout, indent, lexer, node);    else if (node->tag->model & CM_EMPTY || node->type == StartEndTag)    {        if (!(node->tag->model & CM_INLINE))            PCondFlushLine(fout, indent);        if (node->tag == tag_br && node->prev && node->prev->tag != tag_br && BreakBeforeBR)            PFlushLine(fout, indent);        if (MakeClean && node->tag == tag_wbr)            PPrintString(fout, indent, " ");        else            PPrintTag(lexer, fout, mode, indent, node);        if (node->tag == tag_param || node->tag == tag_area)            PCondFlushLine(fout, indent);        else if (node->tag == tag_br || node->tag == tag_hr)            PFlushLine(fout, indent);    }    else /* some kind of container element */    {        if (node->tag && node->tag->parser == ParsePre)        {            PCondFlushLine(fout, indent);            indent = 0;            PCondFlushLine(fout, indent);            PPrintTag(lexer, fout, mode, indent, node);            PFlushLine(fout, indent);            for (content = node->content;                    content != null;                    content = content->next)                PPrintTree(fout, (mode | PREFORMATTED | NOWRAP), indent, lexer, content);            PCondFlushLine(fout, indent);            PPrintEndTag(fout, mode, indent, node);            PFlushLine(fout, indent);            if (IndentContent == no && node->next != null)                PFlushLine(fout, indent);        }        else if (node->tag == tag_style || node->tag == tag_script)        {            PCondFlushLine(fout, indent);            indent = 0;            PCondFlushLine(fout, indent);            PPrintTag(lexer, fout, mode, indent, node);            PFlushLine(fout, indent);            for (content = node->content;                    content != null;                    content = content->next)                PPrintTree(fout, (mode | PREFORMATTED | NOWRAP |CDATA), indent, lexer, content);            PCondFlushLine(fout, indent);            PPrintEndTag(fout, mode, indent, node);            PFlushLine(fout, indent);            if (IndentContent == no && node->next != null)                PFlushLine(fout, indent);        }        else if (node->tag->model & CM_INLINE)        {            if (MakeClean)            {                /* discards <font> and </font> tags */                if (node->tag == tag_font)                {                    for (content = node->content;                            content != null;                            content = content->next)                        PPrintTree(fout, mode, indent, lexer, content);                    return;                }                /* replace <nobr>...</nobr> by &nbsp; or &#160; etc. */                if (node->tag == tag_nobr)                {                    for (content = node->content;                            content != null;                            content = content->next)                        PPrintTree(fout, mode|NOWRAP, indent, lexer, content);                    return;                }            }            /* otherwise a normal inline element */            PPrintTag(lexer, fout, mode, indent, node);            /* indent content for SELECT, TEXTAREA, MAP, OBJECT and APPLET */            if (ShouldIndent(node))            {                PCondFlushLine(fout, indent);                indent += spaces;                for (content = node->content;                        content != null;                        content = content->next)                    PPrintTree(fout, mode, indent, lexer, content);                PCondFlushLine(fout, indent);                indent -= spaces;                PCondFlushLine(fout, indent);            }            else            {                for (content = node->content;                        content != null;                        content = content->next)                    PPrintTree(fout, mode, indent, lexer, content);            }            PPrintEndTag(fout, mode, indent, node);        }        else /* other tags */        {            PCondFlushLine(fout, indent);            if (SmartIndent && node->prev != null)                PFlushLine(fout, indent);            if (HideEndTags == no || !(node->tag && (node->tag->model & CM_OMITST)))            {                PPrintTag(lexer, fout, mode, indent, node);                if (ShouldIndent(node))                    PCondFlushLine(fout, indent);                else if (node->tag->model & CM_HTML || node->tag == tag_noframes ||                            (node->tag->model & CM_HEAD && !(node->tag == tag_title)))                    PFlushLine(fout, indent);            }            if (node->tag == tag_body && BurstSlides)                PPrintSlide(fout, mode, (IndentContent ? indent+spaces : indent), lexer);            else            {                last = null;                for (content = node->content;                        content != null; content = content->next)                {                    /* kludge for naked text before block level tag */                    if (last && !IndentContent && last->type == TextNode &&                        content->tag && content->tag->model & CM_BLOCK)                    {                        PFlushLine(fout, indent);                        PFlushLine(fout, indent);                    }                    PPrintTree(fout, mode,                        (ShouldIndent(node) ? indent+spaces : indent), lexer, content);                    last = content;                }            }            /* don't flush line for td and th */            if (ShouldIndent(node) ||                ((node->tag->model & CM_HTML || node->tag == tag_noframes ||                    (node->tag->model & CM_HEAD && !(node->tag == tag_title)))                    && HideEndTags == no))            {                PCondFlushLine(fout, (IndentContent ? indent+spaces : indent));                if (HideEndTags == no || !(node->tag->model & CM_OPT))                {                    PPrintEndTag(fout, mode, indent, node);                    PFlushLine(fout, indent);                }            }            else            {                if (HideEndTags == no || !(node->tag->model & CM_OPT))                    PPrintEndTag(fout, mode, indent, node);                PFlushLine(fout, indent);            }            if (IndentContent == no &&                node->next != null &&                HideEndTags == no &&                (node->tag->model & (CM_BLOCK|CM_LIST|CM_DEFLIST|CM_TABLE)))            {                PFlushLine(fout, indent);            }        }    }}void PPrintXMLTree(Out *fout, uint mode, uint indent,                    Lexer *lexer, Node *node){    if (node == null)        return;    if (node->type == TextNode)    {        PPrintText(fout, mode, indent,                    lexer, node->start, node->end);    }    else if (node->type == CommentTag)    {        PCondFlushLine(fout, indent);        PPrintComment(fout, 0, lexer, node);        PCondFlushLine(fout, 0);    }    else if (node->type == RootNode)    {        Node *content;        for (content = node->content;                content != null;                content = content->next)           PPrintXMLTree(fout, mode, indent, lexer, content);    }    else if (node->type == DocTypeTag)        PPrintDocType(fout, indent, lexer, node);    else if (node->type == ProcInsTag)        PPrintPI(fout, indent, lexer, node);    else if (node->type == SectionTag)        PPrintSection(fout, indent, lexer, node);    else if (node->type == AspTag)        PPrintAsp(fout, indent, lexer, node);    else if (node->type == JsteTag)        PPrintJste(fout, indent, lexer, node);    else if (node->type == PhpTag)        PPrintPhp(fout, indent, lexer, node);    else if (node->tag->model & CM_EMPTY || node->type == StartEndTag)    {        PCondFlushLine(fout, indent);        PPrintTag(lexer, fout, mode, indent, node);        PFlushLine(fout, indent);        if (node->next)            PFlushLine(fout, indent);    }    else /* some kind of container element */    {        Node *content;        Bool mixed = no;        int cindent;        for (content = node->content; content; content = content->next)        {            if (content->type == TextNode)            {                mixed = yes;                break;            }        }        PCondFlushLine(fout, indent);        if (XMLPreserveWhiteSpace(node))        {            indent = 0;            cindent = 0;            mixed = no;        }        else if (mixed)            cindent = indent;        else            cindent = indent + spaces;        PPrintTag(lexer, fout, mode, indent, node);        if (!mixed)            PFlushLine(fout, indent);         for (content = node->content;                content != null;                content = content->next)            PPrintXMLTree(fout, mode, cindent, lexer, content);        if (!mixed)            PCondFlushLine(fout, cindent);        PPrintEndTag(fout, mode, indent, node);        PCondFlushLine(fout, indent);        if (node->next)            PFlushLine(fout, indent);    }}Node *FindHead(Node *root){    Node *node;    node = root->content;    while (node && node->tag != tag_html)        node = node->next;    if (node == null)        return null;    node = node->content;    while (node && node->tag != tag_head)        node = node->next;    return node;}Node *FindBody(Node *root){    Node *node;    node = root->content;    while (node && node->tag != tag_html)        node = node->next;    if (node == null)        return null;    node = node->content;    while (node && node->tag != tag_body)        node = node->next;    return node;}/* split parse tree by h2 elements and output to separate files *//* counts number of h2 children belonging to node */int CountSlides(Node *node){    int count = 1;    for (node = node->content; node; node = node->next)        if (node->tag == tag_h2)            ++count;    return count;}/*   inserts a space gif called "dot.gif" to ensure   that the  slide is at least n pixels high */void PrintVertSpacer(Out *fout, uint indent){    PCondFlushLine(fout, indent);    PPrintString(fout, indent ,     "<img width=\"0\" height=\"0\" hspace=\"1\" src=\"dot.gif\" vspace=\"%d\" align=\"left\">");    PCondFlushLine(fout, indent);}void PrintNavBar(Out *fout, uint indent){    char buf[128];    PCondFlushLine(fout, indent);    PPrintString(fout, indent , "<center><small>");    if (slide > 1)    {        sprintf(buf, "<a href=\"slide%d.html\">previous</a> | ", slide-1);        PPrintString(fout, indent , buf);        PCondFlushLine(fout, indent);        if (slide < count)            PPrintString(fout, indent , "<a href=\"slide1.html\">start</a> | ");        else            PPrintString(fout, indent , "<a href=\"slide1.html\">start</a>");        PCondFlushLine(fout, indent);    }    if (slide < count)    {        sprintf(buf, "<a href=\"slide%d.html\">next</a>", slide+1);        PPrintString(fout, indent , buf);    }    PPrintString(fout, indent , "</small></center>");    PCondFlushLine(fout, indent);}/*  Called from PPrintTree to print the content of a slide from  the node slidecontent. On return slidecontent points to the  node starting the next slide or null. The variables slide  and count are used to customise the navigation bar.*/void PPrintSlide(Out *fout, uint mode, uint indent, Lexer *lexer){    Node *content, *last;    char buf[256];    /* insert div for onclick handler */    sprintf(buf, "<div onclick=\"document.location='slide%d.html'\">",                    (slide < count ? slide + 1 : 1));    PPrintString(fout, indent, buf);    PCondFlushLine(fout, indent);    /* first print the h2 element and navbar */    if (slidecontent->tag == tag_h2)    {        PrintNavBar(fout, indent);        /* now print an hr after h2 */        AddC('<', linelen++);        AddC(FoldCase('h', UpperCaseTags), linelen++);        AddC(FoldCase('r', UpperCaseTags), linelen++);        if (XmlOut == yes)            PPrintString(fout, indent , " />");        else            AddC('>', linelen++);        if (IndentContent == yes)            PCondFlushLine(fout, indent);        /* PrintVertSpacer(fout, indent); */        /*PCondFlushLine(fout, indent); */        /* print the h2 element */        PPrintTree(fout, mode,            (IndentContent ? indent+spaces : indent), lexer, slidecontent);        slidecontent = slidecontent->next;    }        /* now continue until we reach the next h2 */    last = null;    content = slidecontent;    for (; content != null; content = content->next)    {        if (content->tag == tag_h2)            break;        /* kludge for naked text before block level tag */        if (last && !IndentContent && last->type == TextNode &&            content->tag && content->tag->model & CM_BLOCK)        {            PFlushLine(fout, indent);            PFlushLine(fout, indent);        }        PPrintTree(fout, mode,            (IndentContent ? indent+spaces : indent), lexer, content);        last = content;    }    slidecontent = content;    /* now print epilog */    PCondFlushLine(fout, indent);    PPrintString(fout, indent , "<br clear=\"all\">");    PCondFlushLine(fout, indent);    AddC('<', linelen++);    AddC(FoldCase('h', UpperCaseTags), linelen++);    AddC(FoldCase('r', UpperCaseTags), linelen++);    if (XmlOut == yes)        PPrintString(fout, indent , " />");    else        AddC('>', linelen++);    if (IndentContent == yes)        PCondFlushLine(fout, indent);    PrintNavBar(fout, indent);    /* end tag for div */    PPrintString(fout, indent, "</div>");    PCondFlushLine(fout, indent);}/*Add meta element for page transition effect, this works on IE but not NS*/void AddTransitionEffect(Lexer *lexer, Node *root, int effect, float duration){    Node *head = FindHead(root);    char transition[128];    if (0 <= effect && effect <= 23)        sprintf(transition, "revealTrans(Duration=%g,Transition=%d)", duration, effect);    else        sprintf(transition, "blendTrans(Duration=%g)", duration);    if (head)    {        Node *meta = InferredTag(lexer, "meta");        AddAttribute(meta, "http-equiv", "Page-Enter");        AddAttribute(meta, "content", transition);        InsertNodeAtStart(head, meta);    }}void CreateSlides(Lexer *lexer, Node *root){    Node *body;    char buf[128];    Out out;    FILE *fp;    body = FindBody(root);    count = CountSlides(body);    slidecontent = body->content;    AddTransitionEffect(lexer, root, EFFECT_BLEND, 3.0);    for (slide = 1; slide <= count; ++slide)    {        sprintf(buf, "slide%d.html", slide);        out.state = FSM_ASCII;        out.encoding = CharEncoding;        if ((fp = fopen(buf, "w")))        {            out.fp = fp;            PPrintTree(&out, null, 0, lexer, root);            PFlushLine(&out, 0);            fclose(fp);        }    }    /*     delete superfluous slides by deleting slideN.html     for N = count+1, count+2, etc. until no such file     is found.         */    for (;;)    {        sprintf(buf, "slide%d.html", slide);        if (unlink(buf) != 0)            break;        ++slide;    }}

⌨️ 快捷键说明

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