src/javacodegen.c

changeset 29
ec6e97454e64
parent 28
1be8ea902ef4
child 32
10389d866a4d
     1.1 --- a/src/javacodegen.c	Sat Apr 25 19:01:16 2015 +0200
     1.2 +++ b/src/javacodegen.c	Sat Apr 25 19:14:57 2015 +0200
     1.3 @@ -49,6 +49,9 @@
     1.4      return word[0] == '@';
     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 +
    1.10  void jparseline(char *src, char *dest, highlighter_t *hltr) {
    1.11      size_t sp = 0, dp = 0;
    1.12      /* indent */
    1.13 @@ -64,8 +67,7 @@
    1.14  
    1.15      if (hltr->iscommentml) {
    1.16          iscomment = 1;
    1.17 -        memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29);
    1.18 -        dp += 29;
    1.19 +        memcpy_const(dest, dp, "<span class=\"c2html-comment\">");
    1.20      }
    1.21  
    1.22      for (char c = src[sp] ; c ; c=src[++sp]) {
    1.23 @@ -74,14 +76,12 @@
    1.24              if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') {
    1.25                  iscomment = 0;
    1.26                  hltr->iscommentml = 0;
    1.27 -                memcpy(&(dest[dp]), "/</span>", 8);
    1.28 -                dp += 8;
    1.29 +                memcpy_const(dest, dp, "/</span>");
    1.30                  continue;
    1.31              } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) {
    1.32                  iscomment = 1;
    1.33                  hltr->iscommentml = (src[sp+1] == '*');
    1.34 -                memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29);
    1.35 -                dp += 29;
    1.36 +                memcpy_const(dest, dp, "<span class=\"c2html-comment\">");
    1.37              }
    1.38          }
    1.39  
    1.40 @@ -97,20 +97,19 @@
    1.41              /* strings */
    1.42              if (!isescaping && (c == '\'' || c == '\"')) {
    1.43                  if (isstring) {
    1.44 +                    dp = writeescapedchar(dest, dp, c);
    1.45                      if (c == quote) {
    1.46                          isstring = 0;
    1.47 -                        memcpy(&(dest[dp]), "<span class=\"c2html-string\">", 28);
    1.48 -                        dp += 28;
    1.49 -                        dp = writeescapedchar(dest, dp, c);
    1.50 +                        memcpy_const(dest, dp, "</span>");
    1.51                      } else {
    1.52                          dp = writeescapedchar(dest, dp, c);
    1.53                      }
    1.54                  } else {
    1.55                      isstring = 1;
    1.56                      quote = c;
    1.57 +                    memcpy_const(dest, dp,
    1.58 +                        "<span class=\"c2html-string\">");
    1.59                      dp = writeescapedchar(dest, dp, c);
    1.60 -                    memcpy(&(dest[dp]), "</span>", 7);
    1.61 -                    dp += 7;
    1.62                  }
    1.63              } else {
    1.64                  if (isstring) {
    1.65 @@ -120,21 +119,17 @@
    1.66                      if (wp > 0 && wp < WORDBUF_SIZE) {
    1.67                          int closespan = 1;
    1.68                          if (iskeyword(hltr->word, hltr->keywords)) {
    1.69 -                            memcpy(&(dest[dp]),
    1.70 -                                "<span class=\"c2html-keyword\">", 29);
    1.71 -                            dp += 29;
    1.72 +                            memcpy_const(dest, dp, 
    1.73 +                                "<span class=\"c2html-keyword\">");
    1.74                          } else if (hltr->istype(hltr->word, wp)) {
    1.75 -                            memcpy(&(dest[dp]),
    1.76 -                                "<span class=\"c2html-type\">", 26);
    1.77 -                            dp += 26;
    1.78 +                            memcpy_const(dest, dp, 
    1.79 +                                "<span class=\"c2html-type\">");
    1.80                          } else if (hltr->isdirective(hltr->word)) {
    1.81 -                            memcpy(&(dest[dp]),
    1.82 -                                "<span class=\"c2html-directive\">", 31);
    1.83 -                            dp += 31;
    1.84 +                            memcpy_const(dest, dp, 
    1.85 +                                "<span class=\"c2html-directive\">");
    1.86                          } else if (iscapsonly(hltr->word, wp)) {
    1.87 -                            memcpy(&(dest[dp]),
    1.88 -                                "<span class=\"c2html-macroconst\">", 32);
    1.89 -                            dp += 32;
    1.90 +                            memcpy_const(dest, dp, 
    1.91 +                                "<span class=\"c2html-macroconst\">");
    1.92                          } else {
    1.93                              closespan = 0;
    1.94                          }
    1.95 @@ -142,8 +137,7 @@
    1.96                              dp = writeescapedchar(dest, dp, hltr->word[i]);
    1.97                          }
    1.98                          if (closespan) {
    1.99 -                            memcpy(&(dest[dp]), "</span>", 7);
   1.100 -                            dp += 7;
   1.101 +                            memcpy_const(dest, dp, "</span>");
   1.102                          }
   1.103                      }
   1.104                      memset(hltr->word, 0, WORDBUF_SIZE);

mercurial