Matteo Niccoli wrote:
> Didn't find any other examples. At the moment rust code is recognized
> as ASCII C program text.

src/usr.bin/file/text.c has an array of special matches for text.

It has various omissions, though.

<!doctype html> is matched as SGML.
import means Java, but not python or go.

etc. I suppose it doesn't hurt to add a few more entries, but every entry
slows down file. So we shouldn't go too wild.

Anyway, this adds support for go by matching "package". It also removes two
entries that result in false positives if they match too soon.

Index: text.c
===================================================================
RCS file: /cvs/src/usr.bin/file/text.c,v
retrieving revision 1.3
diff -u -p -r1.3 text.c
--- text.c      18 Apr 2017 14:16:48 -0000      1.3
+++ text.c      15 Jan 2019 06:58:36 -0000
@@ -31,14 +31,13 @@ static const char *text_words[][3] = {
        { "import", "Java program", "text/x-java" },
        { "\"libhdr\"", "BCPL program", "text/x-bcpl" },
        { "\"LIBHDR\"", "BCPL program", "text/x-bcpl" },
-       { "//", "C++ program", "text/x-c++" },
        { "virtual", "C++ program", "text/x-c++" },
        { "class", "C++ program", "text/x-c++" },
        { "public:", "C++ program", "text/x-c++" },
        { "private:", "C++ program", "text/x-c++" },
-       { "/*", "C program", "text/x-c" },
        { "#include", "C program", "text/x-c" },
        { "char", "C program", "text/x-c" },
+       { "package", "Go program", "text/x-go" },
        { "The", "English", "text/plain" },
        { "the", "English", "text/plain" },
        { "double", "C program", "text/x-c" },

Reply via email to