src/javacodegen.c

changeset 47
c39ecbbca7c0
parent 46
534a4ef4143d
child 48
b2724c711203
     1.1 --- a/src/javacodegen.c	Tue Aug 23 15:55:02 2016 +0200
     1.2 +++ b/src/javacodegen.c	Tue Aug 23 16:34:02 2016 +0200
     1.3 @@ -44,17 +44,21 @@
     1.4  #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \
     1.5                                      dp += sizeof(str)-1
     1.6  
     1.7 -void jparseline(char *src, UcxBuffer *destbuf, HighlighterData *hltr) {
     1.8 +void jparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) {
     1.9      /* TODO: workaround for using old code with UcxBuffer */
    1.10      char *dest = destbuf->space + destbuf->pos;
    1.11      
    1.12 -    memset(hltr->word, 0, WORDBUF_SIZE);
    1.13 -    size_t wp = 0, sp = (size_t)-1, dp = 0;
    1.14 +    /* TODO: try to replace this buffer */
    1.15 +    char wordbuf[WORDBUF_SIZE];
    1.16 +    sstr_t word;
    1.17 +    word.ptr = wordbuf; word.length = 0;
    1.18 +    
    1.19 +    size_t sp = (size_t)-1, dp = 0;
    1.20      int isstring = 0, iscomment = 0, isimport = 0;
    1.21      char quote = '\0';
    1.22      int isescaping = 0;
    1.23  
    1.24 -    if (hltr->iscommentml) {
    1.25 +    if (*multiline_comment) {
    1.26          iscomment = 1;
    1.27          memcpy_const(dest, dp, "<span class=\"c2html-comment\">");
    1.28      }
    1.29 @@ -66,14 +70,14 @@
    1.30          
    1.31          /* comments */
    1.32          if (!isstring && c == '/') {
    1.33 -            if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') {
    1.34 +            if (*multiline_comment && sp > 0 && src[sp-1] == '*') {
    1.35                  iscomment = 0;
    1.36 -                hltr->iscommentml = 0;
    1.37 +                *multiline_comment = 0;
    1.38                  memcpy_const(dest, dp, "/</span>");
    1.39                  continue;
    1.40              } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) {
    1.41                  iscomment = 1;
    1.42 -                hltr->iscommentml = (src[sp+1] == '*');
    1.43 +                *multiline_comment = (src[sp+1] == '*');
    1.44                  memcpy_const(dest, dp, "<span class=\"c2html-comment\">");
    1.45              }
    1.46          }
    1.47 @@ -85,7 +89,7 @@
    1.48              }
    1.49              dp = writeescapedchar(dest, dp, c);
    1.50          } else if (isimport) {
    1.51 -            // TODO: local imports
    1.52 +            /* TODO: local imports */
    1.53          } else {
    1.54              /* strings */
    1.55              if (!isescaping && (c == '\'' || c == '\"')) {
    1.56 @@ -108,43 +112,41 @@
    1.57                  if (isstring) {
    1.58                      dp = writeescapedchar(dest, dp, c);
    1.59                  } else if (!iswordcharacter(c)) {
    1.60 -                    /* interpret word int_t */
    1.61 -                    if (wp > 0 && wp < WORDBUF_SIZE) {
    1.62 +                    if (word.length > 0 && word.length < WORDBUF_SIZE) {
    1.63                          int closespan = 1;
    1.64 -                        if (check_keyword(hltr->word, jkeywords)) {
    1.65 +                        if (check_keyword(word, jkeywords)) {
    1.66                              memcpy_const(dest, dp, 
    1.67                                  "<span class=\"c2html-keyword\">");
    1.68 -                        } else if (isupper(hltr->word[0])) {
    1.69 +                        } else if (isupper(word.ptr[0])) {
    1.70                              memcpy_const(dest, dp, 
    1.71                                  "<span class=\"c2html-type\">");
    1.72 -                        } else if (hltr->word[0] == '@') {
    1.73 +                        } else if (word.ptr[0] == '@') {
    1.74                              memcpy_const(dest, dp, 
    1.75                                  "<span class=\"c2html-directive\">");
    1.76 -                        } else if (check_capsonly(hltr->word, wp)) {
    1.77 +                        } else if (check_capsonly(word)) {
    1.78                              memcpy_const(dest, dp, 
    1.79                                  "<span class=\"c2html-macroconst\">");
    1.80                          } else {
    1.81                              closespan = 0;
    1.82                          }
    1.83 -                        for (int i = 0 ; i < wp ; i++) {
    1.84 -                            dp = writeescapedchar(dest, dp, hltr->word[i]);
    1.85 +                        for (int i = 0 ; i < word.length ; i++) {
    1.86 +                            dp = writeescapedchar(dest, dp, word.ptr[i]);
    1.87                          }
    1.88                          if (closespan) {
    1.89                              memcpy_const(dest, dp, "</span>");
    1.90                          }
    1.91                      }
    1.92 -                    memset(hltr->word, 0, WORDBUF_SIZE);
    1.93 -                    wp = 0;
    1.94 +                    word.length = 0;
    1.95                      dp = writeescapedchar(dest, dp, c);
    1.96                  } else {
    1.97                      /* read word */
    1.98 -                    if (wp < WORDBUF_SIZE) {
    1.99 -                        hltr->word[wp++] = c;
   1.100 -                    } else if (wp == WORDBUF_SIZE) {
   1.101 +                    if (word.length < WORDBUF_SIZE) {
   1.102 +                        word.ptr[word.length++] = c;
   1.103 +                    } else if (word.length == WORDBUF_SIZE) {
   1.104                          for (int i = 0 ; i < WORDBUF_SIZE ; i++) {
   1.105 -                            dp = writeescapedchar(dest, dp, hltr->word[i]);
   1.106 +                            dp = writeescapedchar(dest, dp, word.ptr[i]);
   1.107                          }
   1.108 -                        wp++;
   1.109 +                        word.length++;
   1.110                          dp = writeescapedchar(dest, dp, c);
   1.111                      } else {
   1.112                          dp = writeescapedchar(dest, dp, c);

mercurial