From 085604948e1dd722aed063092d4a96254120e993 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Sat, 22 Jul 2017 15:19:22 +0200 Subject: [PATCH] Add support for XPM. (#3706) * .xpm and .pm extensions associated with XPM. * .pm is disambiguated by searching the /* XPM */ string. This is how `file` performs detection and should work with every XPM3 file (most XPM generated by software later than 1991). Added XPM samples: * stick-unfocus.xpm: extracted from Fluxbox (MIT License) https://github.com/fluxbox/fluxbox/blob/0c13ddc0c85ed4445ff8e289387c142e0ac98c77/data/styles/Emerge/pixmaps/stick-unfocus.xpm * cc-public_domain_mark_white.pm: public domain image from https://commons.wikimedia.org/wiki/File:Cc-public_domain_mark_white.svg converted to XPM with ImageMagick (convert input.svg output.xpm). --- lib/linguist/heuristics.rb | 2 + lib/linguist/languages.yml | 8 +++ samples/XPM/cc-public_domain_mark_white.pm | 76 ++++++++++++++++++++++ samples/XPM/stick-unfocus.xpm | 40 ++++++++++++ test/test_heuristics.rb | 7 +- test/test_language.rb | 1 + 6 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 samples/XPM/cc-public_domain_mark_white.pm create mode 100644 samples/XPM/stick-unfocus.xpm diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index c5ecc752..0bba4ea7 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -349,6 +349,8 @@ module Linguist Language["Perl 6"] elsif /\buse\s+(?:strict\b|v?5\.)/.match(data) Language["Perl"] + elsif /^\s*\/\* XPM \*\//.match(data) + Language["XPM"] end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 41cb797f..87ae1122 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -4891,6 +4891,14 @@ XML: - Web.config - packages.config language_id: 399 +XPM: + type: data + extensions: + - ".xpm" + - ".pm" + ace_mode: c_cpp + tm_scope: source.c + language_id: 781846279 XPages: type: programming extensions: diff --git a/samples/XPM/cc-public_domain_mark_white.pm b/samples/XPM/cc-public_domain_mark_white.pm new file mode 100644 index 00000000..700da8ef --- /dev/null +++ b/samples/XPM/cc-public_domain_mark_white.pm @@ -0,0 +1,76 @@ +/* XPM */ +static char *cc_public_domain_mark_white[] = { +/* columns rows colors chars-per-pixel */ +"52 53 17 1 ", +" c black", +". c #111111111111", +"X c #222222222222", +"o c gray20", +"O c #444444444444", +"+ c #555555555555", +"@ c gray40", +"# c #777777777777", +"$ c #888888888888", +"% c gray60", +"& c #AAAAAAAAAAAA", +"* c #BBBBBBBBBBBB", +"= c gray80", +"- c #DDDDDDDDDDDD", +"; c #EEEEEEEEEEEE", +": c white", +"> c None", +/* pixels */ +">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", +">>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>", +">>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>", +">>>>>>>>>>>>>> >>>>>>>>>>>>>>>", +">>>>>>>>>>>> >>>>>>>>>>>>>", +">>>>>>>>>>> .OOOOX >>>>>>>>>>>", +">>>>>>>>> .@&-:::::::;%@. >>>>>>>>>>", +">>>>>>>> X%:::::::::::::::&O >>>>>>>>>", +">>>>>>> .%:::::::::::::::::::%X >>>>>>>>", +">>>>>> +;::::::::::::::::::::::# >>>>>>>", +">>>>> $:::::::::::::::::::::::::%. >>>>>>", +">>>>> %:::::::::::::::::::::::::::=. >>>>>", +">>>> %:::::::::::::::::::::::::::::=. >>>>>", +">>> $:::::::::::;$@Oo XO#&::::::::::% >>>>", +">>> +::::::::::=+ X$:::::::::# >>>>", +">> .#-:::::::$. O-::::::::X >>>", +">> @=::::@ .=::::::::% >>>", +">> O&:% .=::::::::::O >>", +"> X o .=:::::::::::& >>", +"> X #;::*o.=:::::::::::::. >>", +"> o:%O &::::::-::::::::::::::@ >", +" #:::*@ X*:::::::::::::::::::::% >", +" &:::::-#. X%:::::::::::::::::::; >", +" -:::::::; .#;::::::::::::::::: >", +" ::::::::* @-:::::::::::::::X >", +" ::::::::* +*:::::::::::::O >", +" ::::::::* X. o%:::::::::::O >", +" ::::::::* #;#X X#;::::::::o >", +" ;:::::::- +:::%o .@-:::::: >", +" *:::::::: .:::::*+ +*:::; >", +" &::::::::X %::::::-@. o%:* >", +" @::::::::# X;:::::::;#X X@ >", +"> .::::::::= o;::::-O=::%o >", +"> =::::::::O .#*&@. X;:::*+ >>", +"> @::::::::- o:::::-@. >>", +">> -::::::::% @::::::;#X >>", +">> @:::::::::% *::::::::@ >>>", +">> =:::::::::*X .$::::::::;. >>>", +">>> o;:::::::::;$X .@-:::::::::+ >>>>", +">>> +::::::::::::=$@OO+#&;::::::::::$ >>>>", +">>>> #:::::::::::::::::::::::::::::% >>>>>", +">>>>> #:::::::::::::::::::::::::::% >>>>>>", +">>>>>> +;::::::::::::::::::::::::$ >>>>>>", +">>>>>> o=:::::::::::::::::::::;O >>>>>>>", +">>>>>>> @-:::::::::::::::::;#. >>>>>>>>", +">>>>>>>> @=:::::::::::::-#. >>>>>>>>>", +">>>>>>>>>> .@&*;::::;&#o >>>>>>>>>>", +">>>>>>>>>>> >>>>>>>>>>>>", +">>>>>>>>>>>> >>>>>>>>>>>>>", +">>>>>>>>>>>>>> >>>>>>>>>>>>>>>", +">>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>", +">>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>", +">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +}; diff --git a/samples/XPM/stick-unfocus.xpm b/samples/XPM/stick-unfocus.xpm new file mode 100644 index 00000000..10b0a2f4 --- /dev/null +++ b/samples/XPM/stick-unfocus.xpm @@ -0,0 +1,40 @@ +/* XPM */ +static char * stick_unfocus_xpm[] = { +"20 17 20 1", +" c None", +". c #EBEBEB", +"+ c #E9E9E9", +"@ c #E6E6E6", +"# c #E5E5E5", +"$ c #E2E2E2", +"% c #DFDFDF", +"& c #DEDEDE", +"* c #FEFEFE", +"= c #C4C4C4", +"- c #898989", +"; c #B7B7B7", +"> c #6A6A6A", +", c #B9B9B9", +"' c #E4E4E4", +") c #686868", +"! c #E0E0E0", +"~ c #666666", +"{ c #E8E8E8", +"] c #E1E1E1", +"....................", +"....................", +".....+@#$%&%$#@+....", +"....+*********=&+...", +"....@*********-=#...", +"....#**;;;;;**>,'...", +"....$**;**;;**);$...", +"....%**;;;;;**>;&...", +"....&**;***;**>;&...", +"....&**;;;;;**>;&...", +"....!*********~;!...", +"....!*********>,&...", +"....@=->)>>>)>-=#...", +"....+&=,;;;;;,=&+...", +".....{]%%&&&&%@+....", +"....................", +"...................."}; diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 36cedf0d..6414b898 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -221,11 +221,12 @@ class TestHeuristcs < Minitest::Test }) end - # Candidate languages = ["Perl", "Perl 6"] - def test_pm_perl_by_heuristics + # Candidate languages = ["Perl", "Perl 6", "XPM"] + def test_pm_by_heuristics assert_heuristics({ "Perl" => all_fixtures("Perl", "*.pm"), - "Perl 6" => all_fixtures("Perl 6", "*.pm") + "Perl 6" => all_fixtures("Perl 6", "*.pm"), + "XPM" => all_fixtures("XPM", "*.pm") }) end diff --git a/test/test_language.rb b/test/test_language.rb index b8ad306c..c1d6e7cc 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -63,6 +63,7 @@ class TestLanguage < Minitest::Test assert_equal Language['Vim script'], Language.find_by_alias('vim') assert_equal Language['Vim script'], Language.find_by_alias('viml') assert_equal Language['reStructuredText'], Language.find_by_alias('rst') + assert_equal Language['XPM'], Language.find_by_alias('xpm') assert_equal Language['YAML'], Language.find_by_alias('yml') assert_nil Language.find_by_alias(nil) end