From fab34da3e7899ca7f38ad4a9e4ce498d96f99c5b Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 18 Jan 2013 18:09:21 +0100 Subject: [PATCH 1/4] Added PostScript to languages.yml and a sample file. --- lib/linguist/languages.yml | 6 +++++ samples/PostScript/sierpinski.ps | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 samples/PostScript/sierpinski.ps diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index c61ebd72..9e4f745c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1003,6 +1003,12 @@ PogoScript: lexer: Text only primary_extension: .pogo +PostScript: + type: programming + primary_extension: .ps + extensions: + - .eps + PowerShell: type: programming ace_mode: powershell diff --git a/samples/PostScript/sierpinski.ps b/samples/PostScript/sierpinski.ps new file mode 100644 index 00000000..e3c9f665 --- /dev/null +++ b/samples/PostScript/sierpinski.ps @@ -0,0 +1,41 @@ +%!PS-Adobe-3.0 +%%Creator: Aaron Puchert +%%Title: The Sierpinski triangle +%%Pages: 1 +%%PageOrder: Ascend + +%%BeginProlog +% PAGE SETTINGS +/pageset { + 28.3464566 28.3464566 scale % set cm = 1 + 0.5 0.5 translate + 0 setlinewidth +} def + +% sierpinski(n) draws a sierpinski triangle of order n +/sierpinski { +dup 0 gt { + [0.5 0 0 0.5 0 0] concat dup 1 sub sierpinski + [1 0 0 1 1 0] concat dup 1 sub sierpinski + [1 0 0 1 -1 1] concat dup 1 sub sierpinski + [2 0 0 2 0 -1] concat +} { + newpath + 0 0 moveto + 1 0 lineto + 0 1 lineto + closepath + fill +} ifelse pop} def +%%EndProlog + +%%BeginSetup +<< /PageSize [596 843] >> setpagedevice % A4 +%%EndSetup + +%%Page: Test 1 +pageset +[20 0 10 300 sqrt 0 0] concat +9 sierpinski +showpage +%%EOF From 0436973fb766ed46893180eb26e1a8e797c14f68 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Sun, 2 Jun 2013 18:00:06 +0200 Subject: [PATCH 2/4] Add detection for generated PostScript files. --- lib/linguist/generated.rb | 24 ++++++++++++++++++++++++ test/test_blob.rb | 3 +++ 2 files changed, 27 insertions(+) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 826fdc93..41937ff3 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -57,6 +57,7 @@ module Linguist xcode_project_file? || generated_net_docfile? || generated_parser? || + generated_postscript? || generated_protocol_buffer? end @@ -160,6 +161,29 @@ module Linguist false end + # Internal: Is the blob of PostScript generated? + # + # PostScript files are often generated by other programs. If they tell us so, + # we can detect them. + # + # Returns true or false. + def generated_postscript? + return false unless ['.ps', '.eps'].include? extname + + # We analyze the "%%Creator:" comment, which contains the author/generator + # of the file. If there is one, it should be in one of the first few lines. + creator = lines[0..9].find {|line| line =~ /^%%Creator: /} + return false if creator.nil? + + # Most generators write their version number, while human authors' or companies' + # names don't contain numbers. So look if the line contains digits. Also + # look for some special cases without version numbers. + return creator =~ /[0-9]/ || + creator.include? "mpage" || + creator.include? "draw" || + creator.include? "ImageMagick" + end + # Internal: Is the blob a C++, Java or Python source file generated by the # Protocol Buffer compiler? # diff --git a/test/test_blob.rb b/test/test_blob.rb index a5efbb6f..5df3c53c 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -188,6 +188,9 @@ class TestBlob < Test::Unit::TestCase # PEG.js-generated parsers assert blob("JavaScript/parser.js").generated? + # Generated PostScript + assert !blob("PostScript/sierpinski.ps").generated? + # These examples are too basic to tell assert !blob("JavaScript/empty.js").generated? assert !blob("JavaScript/hello.js").generated? From 53f29344f81193ed26221975fdfe363d706466f6 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Thu, 14 Nov 2013 00:56:53 +0100 Subject: [PATCH 3/4] Changed PostScript type to 'markup' --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 9e4f745c..0f0b1772 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1004,7 +1004,7 @@ PogoScript: primary_extension: .pogo PostScript: - type: programming + type: markup primary_extension: .ps extensions: - .eps From 86329a075864744443d5335c68d98b23656a2e99 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Tue, 3 Dec 2013 17:21:43 +0100 Subject: [PATCH 4/4] Forgot parantheses --- lib/linguist/generated.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 41937ff3..93931f06 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -179,9 +179,9 @@ module Linguist # names don't contain numbers. So look if the line contains digits. Also # look for some special cases without version numbers. return creator =~ /[0-9]/ || - creator.include? "mpage" || - creator.include? "draw" || - creator.include? "ImageMagick" + creator.include?("mpage") || + creator.include?("draw") || + creator.include?("ImageMagick") end # Internal: Is the blob a C++, Java or Python source file generated by the