src/c2html.c

changeset 17
7ea86024aef0
parent 16
fa0bcd0444eb
child 18
5085b57e3fd6
     1.1 --- a/src/c2html.c	Wed Jul 10 16:31:16 2013 +0200
     1.2 +++ b/src/c2html.c	Wed Jul 10 17:57:03 2013 +0200
     1.3 @@ -45,20 +45,30 @@
     1.4    "while", NULL
     1.5  };
     1.6  
     1.7 -int istype(char *word, size_t len) {
     1.8 +const char* jkeywords[] = {
     1.9 +  "abstract", "continue", "for", "new", "switch", "assert", "default", "goto",
    1.10 +  "package", "synchronized", "boolean", "do", "if", "private", "this",
    1.11 +  "break", "double", "implements", "protected", "throw", "byte", "else",
    1.12 +  "import", "public", "throws", "case", "enum", "instanceof", "return",
    1.13 +  "transient", "catch", "extends", "int", "short", "try", "char", "final",
    1.14 +  "interface", "static", "void", "class", "finally", "long", "strictfp",
    1.15 +  "volatile", "const", "float", "native", "super", "while", NULL
    1.16 +};
    1.17 +
    1.18 +int isctype(char *word, size_t len) {
    1.19    return (word[len-2] == '_' && word[len-1] == 't');
    1.20  }
    1.21  
    1.22 -int isdirective(char *word) {
    1.23 +int iscdirective(char *word) {
    1.24    return (word[0] == '#');
    1.25  }
    1.26  
    1.27 -int notypes(char *word, size_t len) {
    1.28 -  return 0;
    1.29 +int isjtype(char *word, size_t len) {
    1.30 +  return isupper(word[0]);
    1.31  }
    1.32  
    1.33 -int nodirectives(char *word) {
    1.34 -  return 0;
    1.35 +int isjdirective(char *word) {
    1.36 +  return word[0] == '@';
    1.37  }
    1.38  
    1.39  typedef struct {
    1.40 @@ -278,7 +288,7 @@
    1.41        } else {
    1.42          if (isstring) {
    1.43            dp = writeescapedchar(dest, dp, c);
    1.44 -        } else if (!isalnum(c) && c != '_' && c != '#' && c != '.') {
    1.45 +        } else if (!isalnum(c) && c!='_' && c!='#' && c!='.' && c!='@') {
    1.46            /* interpret word int_t */
    1.47            if (wp > 0 && wp < WORDBUF_SIZE) {
    1.48              int closespan = 1;
    1.49 @@ -336,6 +346,7 @@
    1.50        "  c2html [Options] FILE\n\n"
    1.51        " Options:\n"
    1.52        "  -h                    Prints this help message\n"
    1.53 +      "  -j                    Highlight Java instead of C source code\n"
    1.54        "  -o <output>           Output file (if not specified, stdout is used)\n"
    1.55        "  -p                    Disable highlighting (plain text)\n"
    1.56        "\n");
    1.57 @@ -356,18 +367,23 @@
    1.58    settings.highlight = 1;
    1.59    
    1.60    highlighter_t highlighter;
    1.61 -  highlighter.isdirective = isdirective;
    1.62 -  highlighter.istype = istype;
    1.63 +  highlighter.isdirective = iscdirective;
    1.64 +  highlighter.istype = isctype;
    1.65    highlighter.keywords = ckeywords;
    1.66    
    1.67    char optc;
    1.68 -  while ((optc = getopt(argc, argv, "ho:p")) != -1) {
    1.69 +  while ((optc = getopt(argc, argv, "hjo:p")) != -1) {
    1.70      switch (optc) {
    1.71        case 'o':
    1.72          if (!(optarg[0] == '-' && optarg[1] == 0)) {
    1.73            settings.outfilename = optarg;
    1.74          }
    1.75          break;
    1.76 +      case 'j':
    1.77 +        highlighter.isdirective = isjdirective;
    1.78 +        highlighter.istype = isjtype;
    1.79 +        highlighter.keywords = jkeywords;
    1.80 +        break;
    1.81        case 'p':
    1.82          settings.highlight = 0;
    1.83          break;

mercurial