src/javacodegen.c

changeset 48
b2724c711203
parent 47
c39ecbbca7c0
child 49
f86f0b054464
     1.1 --- a/src/javacodegen.c	Tue Aug 23 16:34:02 2016 +0200
     1.2 +++ b/src/javacodegen.c	Tue Aug 23 17:24:58 2016 +0200
     1.3 @@ -41,26 +41,21 @@
     1.4      "volatile", "const", "float", "native", "super", "while", NULL
     1.5  };
     1.6  
     1.7 -#define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \
     1.8 -                                    dp += sizeof(str)-1
     1.9 +void java_highlighter(char *src, UcxBuffer *dest, int *multiline_comment) {
    1.10  
    1.11 -void jparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) {
    1.12 -    /* TODO: workaround for using old code with UcxBuffer */
    1.13 -    char *dest = destbuf->space + destbuf->pos;
    1.14 -    
    1.15      /* TODO: try to replace this buffer */
    1.16      char wordbuf[WORDBUF_SIZE];
    1.17      sstr_t word;
    1.18      word.ptr = wordbuf; word.length = 0;
    1.19      
    1.20 -    size_t sp = (size_t)-1, dp = 0;
    1.21 +    size_t sp = (size_t)-1;
    1.22      int isstring = 0, iscomment = 0, isimport = 0;
    1.23      char quote = '\0';
    1.24      int isescaping = 0;
    1.25  
    1.26      if (*multiline_comment) {
    1.27          iscomment = 1;
    1.28 -        memcpy_const(dest, dp, "<span class=\"c2html-comment\">");
    1.29 +        ucx_buffer_puts(dest, "<span class=\"c2html-comment\">");
    1.30      }
    1.31  
    1.32      char c;
    1.33 @@ -73,83 +68,81 @@
    1.34              if (*multiline_comment && sp > 0 && src[sp-1] == '*') {
    1.35                  iscomment = 0;
    1.36                  *multiline_comment = 0;
    1.37 -                memcpy_const(dest, dp, "/</span>");
    1.38 +                ucx_buffer_puts(dest, "/</span>");
    1.39                  continue;
    1.40              } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) {
    1.41                  iscomment = 1;
    1.42                  *multiline_comment = (src[sp+1] == '*');
    1.43 -                memcpy_const(dest, dp, "<span class=\"c2html-comment\">");
    1.44 +                ucx_buffer_puts(dest, "<span class=\"c2html-comment\">");
    1.45              }
    1.46          }
    1.47  
    1.48          if (iscomment) {
    1.49              if (c == '\n') {
    1.50 -                memcpy(&(dest[dp]), "</span>", 7);
    1.51 -                dp += 7;
    1.52 +                ucx_buffer_puts(dest, "</span>\n");
    1.53 +            } else {
    1.54 +                put_htmlescaped(dest, c);
    1.55              }
    1.56 -            dp = writeescapedchar(dest, dp, c);
    1.57          } else if (isimport) {
    1.58              /* TODO: local imports */
    1.59          } else {
    1.60              /* strings */
    1.61              if (!isescaping && (c == '\'' || c == '\"')) {
    1.62                  if (isstring) {
    1.63 -                    dp = writeescapedchar(dest, dp, c);
    1.64 +                    put_htmlescaped(dest, c);
    1.65                      if (c == quote) {
    1.66                          isstring = 0;
    1.67 -                        memcpy_const(dest, dp, "</span>");
    1.68 +                        ucx_buffer_puts(dest, "</span>");
    1.69                      } else {
    1.70 -                        dp = writeescapedchar(dest, dp, c);
    1.71 +                        put_htmlescaped(dest, c);
    1.72                      }
    1.73                  } else {
    1.74                      isstring = 1;
    1.75                      quote = c;
    1.76 -                    memcpy_const(dest, dp,
    1.77 +                    ucx_buffer_puts(dest,
    1.78                          "<span class=\"c2html-string\">");
    1.79 -                    dp = writeescapedchar(dest, dp, c);
    1.80 +                    put_htmlescaped(dest, c);
    1.81                  }
    1.82              } else {
    1.83                  if (isstring) {
    1.84 -                    dp = writeescapedchar(dest, dp, c);
    1.85 -                } else if (!iswordcharacter(c)) {
    1.86 +                    put_htmlescaped(dest, c);
    1.87 +                } else if (!check_alnumex(c)) {
    1.88                      if (word.length > 0 && word.length < WORDBUF_SIZE) {
    1.89                          int closespan = 1;
    1.90                          if (check_keyword(word, jkeywords)) {
    1.91 -                            memcpy_const(dest, dp, 
    1.92 +                            ucx_buffer_puts(dest,
    1.93                                  "<span class=\"c2html-keyword\">");
    1.94                          } else if (isupper(word.ptr[0])) {
    1.95 -                            memcpy_const(dest, dp, 
    1.96 +                            ucx_buffer_puts(dest,
    1.97                                  "<span class=\"c2html-type\">");
    1.98                          } else if (word.ptr[0] == '@') {
    1.99 -                            memcpy_const(dest, dp, 
   1.100 +                            ucx_buffer_puts(dest,
   1.101                                  "<span class=\"c2html-directive\">");
   1.102                          } else if (check_capsonly(word)) {
   1.103 -                            memcpy_const(dest, dp, 
   1.104 +                            ucx_buffer_puts(dest,
   1.105                                  "<span class=\"c2html-macroconst\">");
   1.106                          } else {
   1.107                              closespan = 0;
   1.108                          }
   1.109 -                        for (int i = 0 ; i < word.length ; i++) {
   1.110 -                            dp = writeescapedchar(dest, dp, word.ptr[i]);
   1.111 -                        }
   1.112 +                        put_htmlescapedstr(dest, word);
   1.113 +                        
   1.114                          if (closespan) {
   1.115 -                            memcpy_const(dest, dp, "</span>");
   1.116 +                            ucx_buffer_puts(dest, "</span>");
   1.117                          }
   1.118                      }
   1.119                      word.length = 0;
   1.120 -                    dp = writeescapedchar(dest, dp, c);
   1.121 +                    put_htmlescaped(dest, c);
   1.122                  } else {
   1.123                      /* read word */
   1.124                      if (word.length < WORDBUF_SIZE) {
   1.125                          word.ptr[word.length++] = c;
   1.126                      } else if (word.length == WORDBUF_SIZE) {
   1.127 -                        for (int i = 0 ; i < WORDBUF_SIZE ; i++) {
   1.128 -                            dp = writeescapedchar(dest, dp, word.ptr[i]);
   1.129 -                        }
   1.130 -                        word.length++;
   1.131 -                        dp = writeescapedchar(dest, dp, c);
   1.132 +                        /* TODO: this will be removed */
   1.133 +                        ucx_buffer_puts(dest,
   1.134 +                                "!!! WARNING - WORD TOO LONG TO PARSE !!!");
   1.135 +                        word.length = 0;
   1.136                      } else {
   1.137 -                        dp = writeescapedchar(dest, dp, c);
   1.138 +                        put_htmlescaped(dest, c);
   1.139                      }
   1.140                  }
   1.141              }
   1.142 @@ -157,9 +150,4 @@
   1.143              isescaping = !isescaping & (c == '\\');
   1.144          }
   1.145      } while (c != '\n');
   1.146 -    dest[dp] = 0;
   1.147 -    
   1.148 -    /* TODO: workaround */
   1.149 -    destbuf->pos += dp;
   1.150 -    destbuf->size += dp;
   1.151  }

mercurial