📄 sgml.c
字号:
#include <AttrList.h>static int current_is_class = 0;#endif/* Handle Attribute** ----------------*//* PUBLIC CONST char * SGML_default = ""; ?? */PRIVATE void handle_attribute_name ARGS2( HTStream *, context, CONST char *, s){ HTTag * tag = context->current_tag; attr * attributes = tag->attributes; int high, low, i, diff;#ifdef USE_PRETTYSRC if (psrc_view) { attr_is_href = FALSE; attr_is_name = FALSE; }#endif /* ** Ignore unknown tag. - KW */ if (tag == context->unknown_tag) {#ifdef USE_PRETTYSRC if (psrc_view) context->current_attribute_number = 1; /* anything !=INVALID */#endif return; } /* ** Binary search for attribute name. */ for (low = 0, high = tag->number_of_attributes; high > low; diff < 0 ? (low = i+1) : (high = i)) { i = (low + (high-low)/2); diff = my_casecomp(attributes[i].name, s); if (diff == 0) { /* success: found it */ context->current_attribute_number = i;#ifdef USE_PRETTYSRC if (psrc_view) { attr_is_name = (BOOL) (attributes[i].type == HTMLA_ANAME); attr_is_href = (BOOL) (attributes[i].type == HTMLA_HREF); } else#endif { context->present[i] = YES; Clear_extra(context->value[i]);#ifdef USE_COLOR_STYLE# ifdef USE_PRETTYSRC current_is_class = IS_C(attributes[i]);# else current_is_class = (!strcasecomp("class", s));# endif CTRACE((tfp, "SGML: found attribute %s, %d\n", s, current_is_class));#endif } return; } /* if */ } /* for */ CTRACE((tfp, "SGML: Unknown attribute %s for tag %s\n", s, context->current_tag->name)); context->current_attribute_number = INVALID; /* Invalid */}/* Handle attribute value** ----------------------*/PRIVATE void handle_attribute_value ARGS2( HTStream *, context, CONST char *, s){ if (context->current_attribute_number != INVALID) { StrAllocCopy_extra(context->value[context->current_attribute_number], s);#ifdef USE_COLOR_STYLE if (current_is_class) { strncpy (class_string, s, TEMPSTRINGSIZE); CTRACE((tfp, "SGML: class is '%s'\n", s)); } else { CTRACE((tfp, "SGML: attribute value is '%s'\n", s)); }#endif } else { CTRACE((tfp, "SGML: Attribute value %s ***ignored\n", s)); } context->current_attribute_number = INVALID; /* can't have two assignments! */}/*** Translate some Unicodes to Lynx special codes and output them.** Special codes - ones those output depend on parsing.**** Additional issue, like handling bidirectional text if necessary** may be called from here: zwnj (8204), zwj (8205), lrm (8206), rlm (8207)** - currently they are ignored in SGML.c and LYCharUtils.c** but also in UCdomap.c because they are non printable...***/PRIVATE BOOL put_special_unicodes ARGS2( HTStream *, context, UCode_t, code){ /* (Tgf_nolyspcl) */ if (context->no_lynx_specialcodes) { /* ** We were asked by a "DTD" flag to not generate lynx specials. - kw */ return NO; } if (code == CH_NBSP) { /* S/390 -- gil -- 0657 */ /* ** Use Lynx special character for nbsp. */#ifdef USE_PRETTYSRC if (!psrc_view)#endif PUTC(HT_NON_BREAK_SPACE); } else if (code == CH_SHY) { /* ** Use Lynx special character for shy. */#ifdef USE_PRETTYSRC if (!psrc_view)#endif PUTC(LY_SOFT_HYPHEN); } else if (code == 8194 || code == 8201) { /* ** Use Lynx special character for ensp or thinsp. ** ** Originally, Lynx use space '32' as word delimiter and omits this ** space at end of line if word is wrapped to the next line. There ** are several other spaces in the Unicode repertoire and we should ** teach Lynx to understand them, not only as regular characters but ** in the context of line wrapping. Unfortunately, if we use ** HT_EN_SPACE we override the chartrans tables for those spaces ** with a single '32' for all (but do line wrapping more fancy). ** ** We may treat emsp as one or two ensp (below). */#ifdef USE_PRETTYSRC if (!psrc_view)#endif PUTC(HT_EN_SPACE); } else if (code == 8195) { /* ** Use Lynx special character for emsp. */#ifdef USE_PRETTYSRC if (!psrc_view) {#endif /* PUTC(HT_EN_SPACE); let's stay with a single space :) */ PUTC(HT_EN_SPACE);#ifdef USE_PRETTYSRC }#endif } else { /* ** Return NO if nothing done. */ return NO; } /* ** We have handled it. */ return YES;}#ifdef USE_PRETTYSRCPRIVATE void put_pretty_entity ARGS2(HTStream *, context, int, term){ PSRCSTART(entity); PUTC('&'); PUTS(entity_string); if (term) PUTC((char)term); PSRCSTOP(entity);}PRIVATE void put_pretty_number ARGS1(HTStream *, context){ PSRCSTART(entity); PUTS( (context->isHex ? "&#x" : "&#") ); PUTS(entity_string); PUTC(';'); PSRCSTOP(entity);}#endif /* USE_PRETTYSRC *//* Handle entity** -------------**** On entry,** s contains the entity name zero terminated** Bugs:** If the entity name is unknown, the terminator is treated as** a printable non-special character in all cases, even if it is '<'** Bug-fix:** Modified SGML_character() so we only come here with terminator** as '\0' and check a FoundEntity flag. -- Foteos Macrides**** Modified more (for use with Lynx character translation code):*/PRIVATE char replace_buf [64]; /* buffer for replacement strings */PRIVATE BOOL FoundEntity = FALSE;PRIVATE void handle_entity ARGS2( HTStream *, context, char, term){ UCode_t code; long uck = -1; CONST char *s = context->string->data; /* ** Handle all entities normally. - FM */ FoundEntity = FALSE; if ((code = HTMLGetEntityUCValue(s)) != 0) { /* ** We got a Unicode value for the entity name. ** Check for special Unicodes. - FM */ if (put_special_unicodes(context, code)) {#ifdef USE_PRETTYSRC if (psrc_view) { put_pretty_entity(context, term); }#endif FoundEntity = TRUE; return; } /* ** Seek a translation from the chartrans tables. */ if ((uck = UCTransUniChar(code, context->outUCLYhndl)) >= 32 &&/* =============== work in ASCII below here =============== S/390 -- gil -- 0672 */ uck < 256 && (uck < 127 || uck >= LYlowest_eightbit[context->outUCLYhndl])) {#ifdef USE_PRETTYSRC if (psrc_view) { put_pretty_entity(context, term); } else#endif PUTC(FROMASCII((char)uck)); FoundEntity = TRUE; return; } else if ((uck == -4 || (context->T.repl_translated_C0 && uck > 0 && uck < 32)) && /* ** Not found; look for replacement string. */ (uck = UCTransUniCharStr(replace_buf, 60, code, context->outUCLYhndl, 0) >= 0)) {#ifdef USE_PRETTYSRC if (psrc_view) { put_pretty_entity(context, term); } else#endif PUTS(replace_buf); FoundEntity = TRUE; return; } /* ** If we're displaying UTF-8, try that now. - FM */#ifndef USE_PRETTYSRC if (context->T.output_utf8 && PUTUTF8(code)) { FoundEntity = TRUE; return; }#else if (context->T.output_utf8 && (psrc_view ? (UCPutUtf8_charstring((HTStream *)context->target, (putc_func_t*)(fake_put_character), code)): PUTUTF8(code) ) ) { if (psrc_view) { put_pretty_entity(context, term); } FoundEntity = TRUE; return; }#endif /* ** If it's safe ASCII, use it. - FM */ if (code >= 32 && code < 127) {#ifdef USE_PRETTYSRC if (psrc_view) { put_pretty_entity(context, term); } else#endif PUTC(FROMASCII((char)code)); FoundEntity = TRUE; return; }/* =============== work in ASCII above here =============== S/390 -- gil -- 0682 */ /* ** Ignore zwnj (8204) and zwj (8205), if we get to here. ** Note that zwnj may have been handled as <WBR> ** by the calling function. - FM */ if (!strcmp(s, "zwnj") || !strcmp(s, "zwj")) { CTRACE((tfp, "handle_entity: Ignoring '%s'.\n", s));#ifdef USE_PRETTYSRC if (psrc_view) { put_pretty_entity(context, term); }#endif FoundEntity = TRUE; return; } /* ** Ignore lrm (8206), and rln (8207), if we get to here. - FM */ if (!strcmp(s, "lrm") || !strcmp(s, "rlm")) { CTRACE((tfp, "handle_entity: Ignoring '%s'.\n", s));#ifdef USE_PRETTYSRC if (psrc_view) { put_pretty_entity(context, term); }#endif FoundEntity = TRUE; return; } } /* ** If entity string not found, display as text. */#ifdef USE_PRETTYSRC if (psrc_view) PSRCSTART(badseq);#endif CTRACE((tfp, "SGML: Unknown entity '%s' %ld %ld\n", s, (long)code, uck)); /* S/390 -- gil -- 0695 */ PUTC('&'); PUTS(s); if (term != '\0') PUTC(term);#ifdef USE_PRETTYSRC if (psrc_view) PSRCSTOP(badseq);#endif}/* Handle comment** --------------*/PRIVATE void handle_comment ARGS1( HTStream *, context){ CONST char *s = context->string->data; CTRACE((tfp, "SGML Comment:\n<%s>\n", s)); if (context->csi == NULL && strncmp(s, "!--#", 4) == 0 && LYCheckForCSI(context->node_anchor, (char **)&context->url) == TRUE) { LYDoCSI(context->url, s, (char **)&context->csi); } else { LYCommentHacks(context->node_anchor, context->string->data); } return;}/* Handle identifier** -----------------*/PRIVATE void handle_identifier ARGS1( HTStream *, context){ CONST char *s = context->string->data; CTRACE((tfp, "SGML Identifier:\n<%s>\n", s)); return;}/* Handle doctype** --------------*/PRIVATE void handle_doctype ARGS1( HTStream *, context){ CONST char *s = context->string->data; CTRACE((tfp, "SGML Doctype:\n<%s>\n", s)); return;}PRIVATE void SGML_write PARAMS(( HTStream * me, CONST char * s, int l));/* Handle marked** -------------*/PRIVATE void handle_marked ARGS1( HTStream *, context){ CONST char *s = context->string->data; CTRACE((tfp, "SGML Marked Section:\n<%s>\n", s)); if (!strncmp(context->string->data, "![INCLUDE[", 10)) { context->string->data[context->string->size - 3] = '\0'; StrAllocCat(context->include, context->string->data + 10); /* @@@ This needs to take charset into account! @@@ the wrong assumptions will be made about the data's charset once it is in include - kw */ } else if (!strncmp(context->string->data, "![CDATA[", 8)) { (*context->actions->_write)(context->target, context->string->data + 8, context->string->size - 11); } return;}/* Handle sgmlent** --------------*/PRIVATE void handle_sgmlent ARGS1( HTStream *, context){ CONST char *s = context->string->data; CTRACE((tfp, "SGML Entity Declaration:\n<%s>\n", s)); return;}/* Handle sgmlent** --------------*/PRIVATE void handle_sgmlele ARGS1( HTStream *, context){ CONST char *s = context->string->data; CTRACE((tfp, "SGML Element Declaration:\n<%s>\n", s)); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -