src/c2html.c

changeset 17
7ea86024aef0
parent 16
fa0bcd0444eb
child 18
5085b57e3fd6
--- a/src/c2html.c	Wed Jul 10 16:31:16 2013 +0200
+++ b/src/c2html.c	Wed Jul 10 17:57:03 2013 +0200
@@ -45,20 +45,30 @@
   "while", NULL
 };
 
-int istype(char *word, size_t len) {
+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
+};
+
+int isctype(char *word, size_t len) {
   return (word[len-2] == '_' && word[len-1] == 't');
 }
 
-int isdirective(char *word) {
+int iscdirective(char *word) {
   return (word[0] == '#');
 }
 
-int notypes(char *word, size_t len) {
-  return 0;
+int isjtype(char *word, size_t len) {
+  return isupper(word[0]);
 }
 
-int nodirectives(char *word) {
-  return 0;
+int isjdirective(char *word) {
+  return word[0] == '@';
 }
 
 typedef struct {
@@ -278,7 +288,7 @@
       } else {
         if (isstring) {
           dp = writeescapedchar(dest, dp, c);
-        } else if (!isalnum(c) && c != '_' && c != '#' && c != '.') {
+        } else if (!isalnum(c) && c!='_' && c!='#' && c!='.' && c!='@') {
           /* interpret word int_t */
           if (wp > 0 && wp < WORDBUF_SIZE) {
             int closespan = 1;
@@ -336,6 +346,7 @@
       "  c2html [Options] FILE\n\n"
       " Options:\n"
       "  -h                    Prints this help message\n"
+      "  -j                    Highlight Java instead of C source code\n"
       "  -o <output>           Output file (if not specified, stdout is used)\n"
       "  -p                    Disable highlighting (plain text)\n"
       "\n");
@@ -356,18 +367,23 @@
   settings.highlight = 1;
   
   highlighter_t highlighter;
-  highlighter.isdirective = isdirective;
-  highlighter.istype = istype;
+  highlighter.isdirective = iscdirective;
+  highlighter.istype = isctype;
   highlighter.keywords = ckeywords;
   
   char optc;
-  while ((optc = getopt(argc, argv, "ho:p")) != -1) {
+  while ((optc = getopt(argc, argv, "hjo:p")) != -1) {
     switch (optc) {
       case 'o':
         if (!(optarg[0] == '-' && optarg[1] == 0)) {
           settings.outfilename = optarg;
         }
         break;
+      case 'j':
+        highlighter.isdirective = isjdirective;
+        highlighter.istype = isjtype;
+        highlighter.keywords = jkeywords;
+        break;
       case 'p':
         settings.highlight = 0;
         break;

mercurial