hschumann2/TempleOS-Source-Code
0847
1 2#help_index "DolDoc/Misc"3 4CColorROPU32 highlight_hash_type_colors[HTt_TYPES_NUM]=5 DOC_COLOR_EXPORT_SYS_SYM,0,DOC_COLOR_DEFINE_STR,DOC_COLOR_GLBL_VAR,6 DOC_COLOR_CLASS,DOC_COLOR_KEYWORD,DOC_COLOR_FUN,0,0,DOC_COLOR_KEYWORD,7 DOC_COLOR_KEYWORD,DOC_COLOR_KEYWORD,DOC_COLOR_REG,0,0,0,0};8 9U32 *DocHighlight(CDocEntry *doc_e,U8 *src,I64 len,I64 _tmp_u32_attr)10{//Be aware of ::/Demo/ToHtmlToTXTDemo/ToHtml.HC.11 U32 *res=MAlloc((len+1)*sizeof(U32)),*dst=res;12 U8 *ptr;13 CDocSettings *s=&doc_e->settings;14 I64 ch,ch1,last_ch,tmp_u32_attr,mask_tmp_u32_attr=_tmp_u32_attr&0xFFFFF000,15 comment_depth,brace_depth=s->brace_depth,paren_depth=s->paren_depth;16 CHash *tmph;17 switch [s->state] {18 case DOCSS_NORMAL:19hl_normal:20 while (len) {21 while (len && !Bt(char_bmp_alpha_numeric,*src)) {22 tmp_u32_attr=_tmp_u32_attr;23 ch1=*src++;24 switch (ch1) {25 case '/':26 if (len>=2) {27 if (*src=='/') {28 tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;29 *dst++=ch1+tmp_u32_attr;30 *dst++=*src++ +tmp_u32_attr;31 len-=2;32 goto hl_cpp_comment;33 } else if (*src=='*') {34 tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;35 *dst++=ch1+tmp_u32_attr;36 *dst++=*src++ +tmp_u32_attr;37 len-=2;38 comment_depth=1;39 goto hl_comment;40 }41 }42 break;43 case '\'':44 tmp_u32_attr=DOC_COLOR_CHAR_CONST<<8|mask_tmp_u32_attr;45 *dst++=ch1+tmp_u32_attr;46 len--;47 goto hl_single_quote;48 case '\"':49 tmp_u32_attr=DOC_COLOR_STR<<8|mask_tmp_u32_attr;50 *dst++=ch1+tmp_u32_attr;51 len--;52 goto hl_dbl_quote;53 case '(':54 if (paren_depth++&1)55 tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;56 break;57 case ')':58 if (--paren_depth&1)59 tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;60 break;61 case '{':62 if (brace_depth++&1)63 tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;64 break;65 case '}':66 if (--brace_depth&1)67 tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;68 break;69 }70 *dst++=ch1+tmp_u32_attr;71 if (!--len) goto hl_normal_done;72 }73 ptr=src;74 while (len && Bt(char_bmp_alpha_numeric,*src)) {75 src++;76 len--;77 }78 ch=*src;79 *src=0;80 if (tmph=HashFind(ptr,adam_task->hash_table,81 HTT_EXPORT_SYS_SYM|HTT_DEFINE_STR|HTT_GLBL_VAR|HTT_CLASS|82 HTT_INTERNAL_TYPE|HTT_FUN|HTT_KEYWORD|HTT_ASM_KEYWORD|83 HTT_OPCODE|HTT_REG))84 tmp_u32_attr=highlight_hash_type_colors[HashTypeNum(tmph)]<<8|85 mask_tmp_u32_attr;86 else87 tmp_u32_attr=_tmp_u32_attr;88 while (ch1=*ptr++)89 *dst++=ch1+tmp_u32_attr;90 *src=ch;91 }92hl_normal_done:93 s->state=DOCSS_NORMAL;94 s->comment_depth=0;95 break;96 case DOCSS_SINGLE_QUOTE:97 tmp_u32_attr=DOC_COLOR_CHAR_CONST<<8|mask_tmp_u32_attr;98hl_single_quote:99 last_ch=0;100 while (len--) {101 ch1=*src++;102 *dst++=ch1+tmp_u32_attr;103 if (last_ch!='\\' && ch1=='\'')104 goto hl_normal;105 if (last_ch=='\\' && ch1=='\\')106 last_ch=0;107 else108 last_ch=ch1;109 }110 s->state=DOCSS_SINGLE_QUOTE;111 s->comment_depth=0;112 break;113 case DOCSS_DBL_QUOTE:114 tmp_u32_attr=DOC_COLOR_CHAR_CONST<<8|mask_tmp_u32_attr;115hl_dbl_quote:116 last_ch=0;117 while (len--) {118 ch1=*src++;119 *dst++=ch1+tmp_u32_attr;120 if (last_ch!='\\' && ch1=='\"')121 goto hl_normal;122 if (last_ch=='\\' && ch1=='\\')123 last_ch=0;124 else125 last_ch=ch1;126 }127 s->state=DOCSS_DBL_QUOTE;128 s->comment_depth=0;129 break;130 case DOCSS_COMMENT:131 tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;132 comment_depth=s->comment_depth;133hl_comment:134 last_ch=0;135 while (len--) {136 ch1=*src++;137 *dst++=ch1+tmp_u32_attr;138 if (last_ch=='*' && ch1=='/') {139 if (!--comment_depth)140 goto hl_normal;141 } else if (last_ch=='/' && ch1=='*')142 comment_depth++;143 last_ch=ch1;144 }145 s->state=DOCSS_COMMENT;146 s->comment_depth=comment_depth;147 break;148 case DOCSS_CPP_Z_COMMENT:149 tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;150hl_cpp_comment:151 while (len--)152 *dst++=*src++ +tmp_u32_attr;153 s->state=DOCSS_CPP_Z_COMMENT;154 s->comment_depth=0;155 break;156 }157 s->paren_depth=paren_depth;158 s->brace_depth=brace_depth;159 *dst=0;160 return res;161}162 