src/ccodegen.c

changeset 46
534a4ef4143d
parent 45
1f3835182aeb
child 47
c39ecbbca7c0
equal deleted inserted replaced
45:1f3835182aeb 46:534a4ef4143d
37 "long", "register", "return", "short", "signed", "sizeof", "static", 37 "long", "register", "return", "short", "signed", "sizeof", "static",
38 "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", 38 "struct", "switch", "typedef", "union", "unsigned", "void", "volatile",
39 "while", NULL 39 "while", NULL
40 }; 40 };
41 41
42 int check_ctype(char *word, size_t len) {
43 return (word[len-2] == '_' && word[len-1] == 't');
44 }
45
46 int check_cdirective(char *word) {
47 return (word[0] == '#');
48 }
49
50 #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ 42 #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \
51 dp += sizeof(str)-1 43 dp += sizeof(str)-1
52 44
53 void cparseline(char *src, UcxBuffer *destbuf, highlighter_t *hltr) { 45 void cparseline(char *src, UcxBuffer *destbuf, HighlighterData *hltr) {
54 /* TODO: workaround for using old code with UcxBuffer */ 46 /* TODO: workaround for using old code with UcxBuffer */
55 char *dest = destbuf->space + destbuf->pos; 47 char *dest = destbuf->space + destbuf->pos;
56 48
57 memset(hltr->word, 0, WORDBUF_SIZE); 49 memset(hltr->word, 0, WORDBUF_SIZE);
58 size_t wp = 0, ifp = 0, sp = (size_t)-1, dp = 0; 50 size_t wp = 0, ifp = 0, sp = (size_t)-1, dp = 0;
144 dp = writeescapedchar(dest, dp, c); 136 dp = writeescapedchar(dest, dp, c);
145 } else if (!iswordcharacter(c)) { 137 } else if (!iswordcharacter(c)) {
146 /* interpret word int_t */ 138 /* interpret word int_t */
147 if (wp > 0 && wp < WORDBUF_SIZE) { 139 if (wp > 0 && wp < WORDBUF_SIZE) {
148 int closespan = 1; 140 int closespan = 1;
149 if (check_keyword(hltr->word, hltr->keywords)) { 141 if (check_keyword(hltr->word, ckeywords)) {
150 memcpy_const(dest, dp, 142 memcpy_const(dest, dp,
151 "<span class=\"c2html-keyword\">"); 143 "<span class=\"c2html-keyword\">");
152 } else if (hltr->istype(hltr->word, wp)) { 144 } else if (hltr->word[wp-2] == '_'
145 && hltr->word[wp-1] == 't') {
153 memcpy_const(dest, dp, 146 memcpy_const(dest, dp,
154 "<span class=\"c2html-type\">"); 147 "<span class=\"c2html-type\">");
155 } else if (hltr->isdirective(hltr->word)) { 148 } else if (hltr->word[0] == '#') {
156 isinclude = !strncmp( 149 isinclude = !strncmp(
157 "#include", hltr->word, WORDBUF_SIZE); 150 "#include", hltr->word, WORDBUF_SIZE);
158 memcpy_const(dest, dp, 151 memcpy_const(dest, dp,
159 "<span class=\"c2html-directive\">"); 152 "<span class=\"c2html-directive\">");
160 } else if (check_capsonly(hltr->word, wp)) { 153 } else if (check_capsonly(hltr->word, wp)) {

mercurial