File size: 5,059 Bytes
806d4b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

#help_index "DolDoc/Misc"

CColorROPU32 highlight_hash_type_colors[HTt_TYPES_NUM]=
        DOC_COLOR_EXPORT_SYS_SYM,0,DOC_COLOR_DEFINE_STR,DOC_COLOR_GLBL_VAR,
        DOC_COLOR_CLASS,DOC_COLOR_KEYWORD,DOC_COLOR_FUN,0,0,DOC_COLOR_KEYWORD,
        DOC_COLOR_KEYWORD,DOC_COLOR_KEYWORD,DOC_COLOR_REG,0,0,0,0};

U32 *DocHighlight(CDocEntry *doc_e,U8 *src,I64 len,I64 _tmp_u32_attr)
{//Be aware of ::/Demo/ToHtmlToTXTDemo/ToHtml.HC.
  U32 *res=MAlloc((len+1)*sizeof(U32)),*dst=res;
  U8 *ptr;
  CDocSettings *s=&doc_e->settings;
  I64 ch,ch1,last_ch,tmp_u32_attr,mask_tmp_u32_attr=_tmp_u32_attr&0xFFFFF000,
        comment_depth,brace_depth=s->brace_depth,paren_depth=s->paren_depth;
  CHash *tmph;
  switch [s->state] {
    case DOCSS_NORMAL:
hl_normal:
      while (len) {
        while (len && !Bt(char_bmp_alpha_numeric,*src)) {
          tmp_u32_attr=_tmp_u32_attr;
          ch1=*src++;
          switch (ch1) {
            case '/':
              if (len>=2) {
                if (*src=='/') {
                  tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;
                  *dst++=ch1+tmp_u32_attr;
                  *dst++=*src++ +tmp_u32_attr;
                  len-=2;
                  goto hl_cpp_comment;
                } else if (*src=='*') {
                  tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;
                  *dst++=ch1+tmp_u32_attr;
                  *dst++=*src++ +tmp_u32_attr;
                  len-=2;
                  comment_depth=1;
                  goto hl_comment;
                }
              }
              break;
            case '\'':
              tmp_u32_attr=DOC_COLOR_CHAR_CONST<<8|mask_tmp_u32_attr;
              *dst++=ch1+tmp_u32_attr;
              len--;
              goto hl_single_quote;
            case '\"':
              tmp_u32_attr=DOC_COLOR_STR<<8|mask_tmp_u32_attr;
              *dst++=ch1+tmp_u32_attr;
              len--;
              goto hl_dbl_quote;
            case '(':
              if (paren_depth++&1)
                tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;
              break;
            case ')':
              if (--paren_depth&1)
                tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;
              break;
            case '{':
              if (brace_depth++&1)
                tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;
              break;
            case '}':
              if (--brace_depth&1)
                tmp_u32_attr=DOC_COLOR_ALT_TEXT<<8|mask_tmp_u32_attr;
              break;
          }
          *dst++=ch1+tmp_u32_attr;
          if (!--len) goto hl_normal_done;
        }
        ptr=src;
        while (len && Bt(char_bmp_alpha_numeric,*src)) {
          src++;
          len--;
        }
        ch=*src;
        *src=0;
        if (tmph=HashFind(ptr,adam_task->hash_table,
              HTT_EXPORT_SYS_SYM|HTT_DEFINE_STR|HTT_GLBL_VAR|HTT_CLASS|
              HTT_INTERNAL_TYPE|HTT_FUN|HTT_KEYWORD|HTT_ASM_KEYWORD|
              HTT_OPCODE|HTT_REG))
          tmp_u32_attr=highlight_hash_type_colors[HashTypeNum(tmph)]<<8|
                mask_tmp_u32_attr;
        else
          tmp_u32_attr=_tmp_u32_attr;
        while (ch1=*ptr++)
          *dst++=ch1+tmp_u32_attr;
        *src=ch;
      }
hl_normal_done:
      s->state=DOCSS_NORMAL;
      s->comment_depth=0;
      break;
    case DOCSS_SINGLE_QUOTE:
      tmp_u32_attr=DOC_COLOR_CHAR_CONST<<8|mask_tmp_u32_attr;
hl_single_quote:
      last_ch=0;
      while (len--) {
        ch1=*src++;
        *dst++=ch1+tmp_u32_attr;
        if (last_ch!='\\' && ch1=='\'')
          goto hl_normal;
        if (last_ch=='\\' && ch1=='\\')
          last_ch=0;
        else
          last_ch=ch1;
      }
      s->state=DOCSS_SINGLE_QUOTE;
      s->comment_depth=0;
      break;
    case DOCSS_DBL_QUOTE:
      tmp_u32_attr=DOC_COLOR_CHAR_CONST<<8|mask_tmp_u32_attr;
hl_dbl_quote:
      last_ch=0;
      while (len--) {
        ch1=*src++;
        *dst++=ch1+tmp_u32_attr;
        if (last_ch!='\\' && ch1=='\"')
          goto hl_normal;
        if (last_ch=='\\' && ch1=='\\')
          last_ch=0;
        else
          last_ch=ch1;
      }
      s->state=DOCSS_DBL_QUOTE;
      s->comment_depth=0;
      break;
    case DOCSS_COMMENT:
      tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;
      comment_depth=s->comment_depth;
hl_comment:
      last_ch=0;
      while (len--) {
        ch1=*src++;
        *dst++=ch1+tmp_u32_attr;
        if (last_ch=='*' && ch1=='/') {
          if (!--comment_depth)
            goto hl_normal;
        } else if (last_ch=='/' && ch1=='*')
          comment_depth++;
        last_ch=ch1;
      }
      s->state=DOCSS_COMMENT;
      s->comment_depth=comment_depth;
      break;
    case DOCSS_CPP_Z_COMMENT:
      tmp_u32_attr=DOC_COLOR_COMMENT<<8|mask_tmp_u32_attr;
hl_cpp_comment:
      while (len--)
        *dst++=*src++ +tmp_u32_attr;
      s->state=DOCSS_CPP_Z_COMMENT;
      s->comment_depth=0;
      break;
  }
  s->paren_depth=paren_depth;
  s->brace_depth=brace_depth;
  *dst=0;
  return res;
}