1.1 --- a/src/javacodegen.c Thu Aug 25 12:16:57 2016 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,148 +0,0 @@ 1.4 -/* 1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 1.6 - * 1.7 - * Copyright 2016 Mike Becker. All rights reserved. 1.8 - * 1.9 - * Redistribution and use in source and binary forms, with or without 1.10 - * modification, are permitted provided that the following conditions are met: 1.11 - * 1.12 - * 1. Redistributions of source code must retain the above copyright 1.13 - * notice, this list of conditions and the following disclaimer. 1.14 - * 1.15 - * 2. Redistributions in binary form must reproduce the above copyright 1.16 - * notice, this list of conditions and the following disclaimer in the 1.17 - * documentation and/or other materials provided with the distribution. 1.18 - * 1.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 1.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.29 - * POSSIBILITY OF SUCH DAMAGE. 1.30 - * 1.31 - */ 1.32 - 1.33 -#include "javacodegen.h" 1.34 - 1.35 -const char* jkeywords[] = { 1.36 - "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", 1.37 - "package", "synchronized", "boolean", "do", "if", "private", "this", 1.38 - "break", "double", "implements", "protected", "throw", "byte", "else", 1.39 - "import", "public", "throws", "case", "enum", "instanceof", "return", 1.40 - "transient", "catch", "extends", "int", "short", "try", "char", "final", 1.41 - "interface", "static", "void", "class", "finally", "long", "strictfp", 1.42 - "volatile", "const", "float", "native", "super", "while", NULL 1.43 -}; 1.44 - 1.45 -void java_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) { 1.46 - /* reset buffers without clearing them */ 1.47 - hd->primary_buffer->size = hd->primary_buffer->pos = 0; 1.48 - hd->secondary_buffer->size = hd->secondary_buffer->pos = 0; 1.49 - 1.50 - /* alias the buffers for better handling */ 1.51 - UcxBuffer *wbuf = hd->primary_buffer; 1.52 - 1.53 - /* local information */ 1.54 - size_t sp = (size_t)-1; 1.55 - int isstring = 0, iscomment = 0, isimport = 0; 1.56 - char quote = '\0'; 1.57 - int isescaping = 0; 1.58 - 1.59 - if (hd->multiline_comment) { 1.60 - iscomment = 1; 1.61 - ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); 1.62 - } 1.63 - 1.64 - char c; 1.65 - do { 1.66 - c = src[++sp]; 1.67 - if (!c) break; 1.68 - 1.69 - /* comments */ 1.70 - if (!isstring && c == '/') { 1.71 - if (hd->multiline_comment && sp > 0 && src[sp-1] == '*') { 1.72 - iscomment = 0; 1.73 - hd->multiline_comment = 0; 1.74 - ucx_buffer_puts(dest, "/</span>"); 1.75 - continue; 1.76 - } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { 1.77 - iscomment = 1; 1.78 - hd->multiline_comment = (src[sp+1] == '*'); 1.79 - ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); 1.80 - } 1.81 - } 1.82 - 1.83 - if (iscomment) { 1.84 - if (c == '\n') { 1.85 - ucx_buffer_puts(dest, "</span>\n"); 1.86 - } else { 1.87 - put_htmlescaped(dest, c); 1.88 - } 1.89 - } else if (isimport) { 1.90 - /* TODO: local imports */ 1.91 - } else { 1.92 - /* strings */ 1.93 - if (!isescaping && (c == '\'' || c == '\"')) { 1.94 - if (isstring) { 1.95 - put_htmlescaped(dest, c); 1.96 - if (c == quote) { 1.97 - isstring = 0; 1.98 - ucx_buffer_puts(dest, "</span>"); 1.99 - } else { 1.100 - put_htmlescaped(dest, c); 1.101 - } 1.102 - } else { 1.103 - isstring = 1; 1.104 - quote = c; 1.105 - ucx_buffer_puts(dest, 1.106 - "<span class=\"c2html-string\">"); 1.107 - put_htmlescaped(dest, c); 1.108 - } 1.109 - } else { 1.110 - if (isstring) { 1.111 - put_htmlescaped(dest, c); 1.112 - } else if (!isalnum(c) && c!='_' && c!='@') { 1.113 - /* write buffered word, if any */ 1.114 - if (wbuf->size > 0) { 1.115 - sstr_t word = sstrn(wbuf->space, wbuf->size); 1.116 - int closespan = 1; 1.117 - if (check_keyword(word, jkeywords)) { 1.118 - ucx_buffer_puts(dest, 1.119 - "<span class=\"c2html-keyword\">"); 1.120 - } else if (isupper(word.ptr[0])) { 1.121 - ucx_buffer_puts(dest, 1.122 - "<span class=\"c2html-type\">"); 1.123 - } else if (word.ptr[0] == '@') { 1.124 - ucx_buffer_puts(dest, 1.125 - "<span class=\"c2html-directive\">"); 1.126 - } else if (check_capsonly(word)) { 1.127 - ucx_buffer_puts(dest, 1.128 - "<span class=\"c2html-macroconst\">"); 1.129 - } else { 1.130 - closespan = 0; 1.131 - } 1.132 - put_htmlescapedstr(dest, word); 1.133 - 1.134 - if (closespan) { 1.135 - ucx_buffer_puts(dest, "</span>"); 1.136 - } 1.137 - } 1.138 - wbuf->pos = wbuf->size = 0; /* reset buffer */ 1.139 - 1.140 - /* write current character */ 1.141 - put_htmlescaped(dest, c); 1.142 - } else { 1.143 - /* buffer the current word */ 1.144 - ucx_buffer_putc(wbuf, c); 1.145 - } 1.146 - } 1.147 - 1.148 - isescaping = !isescaping & (c == '\\'); 1.149 - } 1.150 - } while (c != '\n'); 1.151 -}