diff -r f25ba6fd7a08 -r 33ded421c512 src/javacodegen.c --- a/src/javacodegen.c Thu Aug 25 12:16:57 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2016 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "javacodegen.h" - -const char* jkeywords[] = { - "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", - "package", "synchronized", "boolean", "do", "if", "private", "this", - "break", "double", "implements", "protected", "throw", "byte", "else", - "import", "public", "throws", "case", "enum", "instanceof", "return", - "transient", "catch", "extends", "int", "short", "try", "char", "final", - "interface", "static", "void", "class", "finally", "long", "strictfp", - "volatile", "const", "float", "native", "super", "while", NULL -}; - -void java_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) { - /* reset buffers without clearing them */ - hd->primary_buffer->size = hd->primary_buffer->pos = 0; - hd->secondary_buffer->size = hd->secondary_buffer->pos = 0; - - /* alias the buffers for better handling */ - UcxBuffer *wbuf = hd->primary_buffer; - - /* local information */ - size_t sp = (size_t)-1; - int isstring = 0, iscomment = 0, isimport = 0; - char quote = '\0'; - int isescaping = 0; - - if (hd->multiline_comment) { - iscomment = 1; - ucx_buffer_puts(dest, ""); - } - - char c; - do { - c = src[++sp]; - if (!c) break; - - /* comments */ - if (!isstring && c == '/') { - if (hd->multiline_comment && sp > 0 && src[sp-1] == '*') { - iscomment = 0; - hd->multiline_comment = 0; - ucx_buffer_puts(dest, "/"); - continue; - } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { - iscomment = 1; - hd->multiline_comment = (src[sp+1] == '*'); - ucx_buffer_puts(dest, ""); - } - } - - if (iscomment) { - if (c == '\n') { - ucx_buffer_puts(dest, "\n"); - } else { - put_htmlescaped(dest, c); - } - } else if (isimport) { - /* TODO: local imports */ - } else { - /* strings */ - if (!isescaping && (c == '\'' || c == '\"')) { - if (isstring) { - put_htmlescaped(dest, c); - if (c == quote) { - isstring = 0; - ucx_buffer_puts(dest, ""); - } else { - put_htmlescaped(dest, c); - } - } else { - isstring = 1; - quote = c; - ucx_buffer_puts(dest, - ""); - put_htmlescaped(dest, c); - } - } else { - if (isstring) { - put_htmlescaped(dest, c); - } else if (!isalnum(c) && c!='_' && c!='@') { - /* write buffered word, if any */ - if (wbuf->size > 0) { - sstr_t word = sstrn(wbuf->space, wbuf->size); - int closespan = 1; - if (check_keyword(word, jkeywords)) { - ucx_buffer_puts(dest, - ""); - } else if (isupper(word.ptr[0])) { - ucx_buffer_puts(dest, - ""); - } else if (word.ptr[0] == '@') { - ucx_buffer_puts(dest, - ""); - } else if (check_capsonly(word)) { - ucx_buffer_puts(dest, - ""); - } else { - closespan = 0; - } - put_htmlescapedstr(dest, word); - - if (closespan) { - ucx_buffer_puts(dest, ""); - } - } - wbuf->pos = wbuf->size = 0; /* reset buffer */ - - /* write current character */ - put_htmlescaped(dest, c); - } else { - /* buffer the current word */ - ucx_buffer_putc(wbuf, c); - } - } - - isescaping = !isescaping & (c == '\\'); - } - } while (c != '\n'); -}