-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from ggreer/language_options
Language options
- Loading branch information
Showing
6 changed files
with
153 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "lang.h" | ||
#include "util.h" | ||
|
||
lang_spec_t langs[] = { | ||
{"actionscript", {"as", "mxml"}}, | ||
{"ada", {"ada", "adb", "ads"}}, | ||
{"asm", {"asm", "s"}}, | ||
{"batch", {"bat", "cmd"}}, | ||
{"cc", {"c", "h", "xs"}}, | ||
{"cfmx", {"cfc", "cfm", "cfml"}}, | ||
{"clojure", {"clj"}}, | ||
{"cpp", {"cpp", "cc", "cxx", "m", "hpp", "hh", "h", "hxx"}}, | ||
{"csharp", {"cs"}}, | ||
{"css", {"css"}}, | ||
{"delphi", {"pas", "int", "dfm", "nfm", "dof", "dpk", "dproj", "groupproj", "bdsgroup", "bdsproj"}}, | ||
{"elisp", {"el"}}, | ||
{"erlang", {"erl", "hrl"}}, | ||
{"fortran", {"f", "f77", "f90", "f95", "f03", "for", "ftn", "fpp"}}, | ||
{"go", {"go"}}, | ||
{"groovy", {"groovy", "gtmpl", "gpp", "grunit"}}, | ||
{"haskell", {"hs", "lhs"}}, | ||
{"hh", {"h"}}, | ||
{"html", {"htm", "html", "shtml", "xhtml"}}, | ||
{"java", {"java", "properties"}}, | ||
{"js", {"js"}}, | ||
{"jsp", {"jsp", "jspx", "jhtm", "jhtml"}}, | ||
{"lisp", {"lisp", "lsp"}}, | ||
{"lua", {"lua"}}, | ||
{"m4", {"m4"}}, | ||
{"matlab", {"m"}}, | ||
{"make", {"Makefiles", "mk", "mak"}}, | ||
{"mason", {"mas", "mhtml", "mpl", "mtxt"}}, | ||
{"objc", {"m", "h"}}, | ||
{"objcpp", {"mm", "h"}}, | ||
{"ocaml", {"ml", "mli"}}, | ||
{"octave", {"m"}}, | ||
{"parrot", {"pir", "pasm", "pmc", "ops", "pod", "pg", "tg"}}, | ||
{"perl", {"pl", "pm", "pm6", "pod", "t"}}, | ||
{"php", {"php", "phpt", "php3", "php4", "php5", "phtml"}}, | ||
{"plone", {"pt", "cpt", "metadata", "cpy", "py"}}, | ||
{"python", {"py"}}, | ||
{"rake", {"Rakefiles"}}, | ||
{"rs", {"rs"}}, | ||
{"ruby", {"rb", "rhtml", "rjs", "rxml", "erb", "rake", "spec"}}, | ||
{"rust", {"rs"}}, | ||
{"salt", {"sls"}}, | ||
{"scala", {"scala"}}, | ||
{"scheme", {"scm", "ss"}}, | ||
{"shell", {"sh", "bash", "csh", "tcsh", "ksh", "zsh"}}, | ||
{"smalltalk", {"st"}}, | ||
{"sql", {"sql", "ctl"}}, | ||
{"tcl", {"tcl", "itcl", "itk"}}, | ||
{"tex", {"tex", "cls", "sty"}}, | ||
{"tt", {"tt", "tt2", "ttml"}}, | ||
{"vb", {"bas", "cls", "frm", "ctl", "vb", "resx"}}, | ||
{"verilog", {"v", "vh", "sv"}}, | ||
{"vhdl", {"vhd", "vhdl"}}, | ||
{"vim", {"vim"}}, | ||
{"yaml", {"yaml", "yml"}}, | ||
{"xml", {"xml", "dtd", "xsl", "xslt", "ent"}}, | ||
{NULL, {NULL}} | ||
}; | ||
|
||
char* make_lang_regex(const char** extensions) { | ||
int regex_capacity = 100; | ||
char* regex = ag_malloc(regex_capacity); | ||
int regex_length = 3; | ||
int subsequent = 0; | ||
const char** extension; | ||
|
||
strcpy(regex, "\\.("); | ||
|
||
for (extension = extensions; *extension; ++extension) { | ||
int extension_length = strlen(*extension); | ||
while (regex_length + extension_length + 3 + subsequent > regex_capacity) { | ||
regex_capacity *= 2; | ||
regex = ag_realloc(regex, regex_capacity); | ||
} | ||
if (subsequent) { | ||
regex[regex_length++] = '|'; | ||
} else { | ||
subsequent = 1; | ||
} | ||
strcpy(regex + regex_length, *extension); | ||
regex_length += extension_length; | ||
} | ||
|
||
regex[regex_length++] = ')'; | ||
regex[regex_length++] = '$'; | ||
regex[regex_length++] = 0; | ||
return regex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef LANG_H | ||
#define LANG_H | ||
|
||
#define MAX_EXTENSIONS 12 | ||
#define LANG_COUNT 56 | ||
|
||
typedef struct { | ||
const char* name; | ||
const char* extensions[MAX_EXTENSIONS]; | ||
} lang_spec_t; | ||
|
||
extern lang_spec_t langs[]; | ||
|
||
/** | ||
Convert a NULL-terminated array of language extensions | ||
into a regular expression of the form \.(extension1|extension2...)$ | ||
Caller is responsible for freeing the returned string. | ||
*/ | ||
char* make_lang_regex(const char** extensions); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04ec543
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be:
Better yet, for Visual Studio compatibility, it could be rewritten as:
(see kjk@197105d for that and other VS fixes)
04ec543
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also:
i.e. need +1 element for the sentinel element being written to. Without this,
valgrind --dsymutil=yes ./ag
will complain about invalid memory writes and windows might crash (when doing malloc consistency checks).See kjk@8db63a0