pjl 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e529424d3227987169bcd9a06cac0f672532d42
4
+ data.tar.gz: 079f31b129672a1dbf6975a4c63a734cb999a31d
5
+ SHA512:
6
+ metadata.gz: 02586fd7a02cdd59030f54c04a8a66b31954c445864255696a63c8cee756701be7897148a25cde4b719868a9f799951b5c1afc5c699dd96d2d028b05aaa1a51d
7
+ data.tar.gz: cb1937fb2bb4cc2f3807e9c2eeac59140570cdfd3b676438dba1afc625ad8b33b014e488ca46b2a8b40f6a1fa093f8bd5698ab5c234294c38d3636b39259de2e
data/LICENSE ADDED
@@ -0,0 +1,35 @@
1
+ _ _ _
2
+ _ __ _ _| |__ _ _ _ __ (_) |
3
+ | '__| | | | '_ \| | | |_____| '_ \| | |
4
+ | | | |_| | |_) | |_| |_____| |_) | | |
5
+ |_| \__,_|_.__/ \__, | | .__// |_|
6
+ |___/ |_| |__/
7
+
8
+
9
+ Copyright (c) 2012, Bertram Scharpf <software@bertram-scharpf.de>.
10
+ All rights reserved.
11
+
12
+ Redistribution and use in source and binary forms, with or without
13
+ modification, are permitted provided that the following conditions are
14
+ met:
15
+
16
+ * Redistributions of source code must retain the above copyright
17
+ notice, this list of conditions and the following disclaimer.
18
+
19
+ * Redistributions in binary form must reproduce the above copyright
20
+ notice, this list of conditions and the following disclaimer in
21
+ the documentation and/or other materials provided with the
22
+ distribution.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+
data/README ADDED
@@ -0,0 +1,37 @@
1
+ = ruby-pjl 1.1 -- Generating PJL in Ruby
2
+
3
+ Just write some PJL commands by a Ruby program.
4
+
5
+
6
+ == Contents
7
+
8
+ * class PJL
9
+
10
+
11
+ == Functionality
12
+
13
+ $ cd example
14
+
15
+ Get help.
16
+
17
+ $ ./ifbrother -H
18
+
19
+ Pipe a PostScript file to the printer.
20
+
21
+ $ cat nikolaus.ps | ./ifbrother | cat >/dev/ulpt0
22
+
23
+ Set up the filter.
24
+
25
+ $ vi printcap
26
+ $ sudo vi /etc/printcap
27
+
28
+
29
+ == Writing Filters
30
+
31
+ See the files <code>example/if*</code> for how to do it.
32
+
33
+
34
+ == TODO
35
+
36
+ Write some more documentation.
37
+
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # ifbrother -- Print to Brother MFC7420
5
+ #
6
+
7
+ require "pjl/appl"
8
+
9
+
10
+ class MFC7420Appl < PjlAppl
11
+
12
+ NAME = "ifbrother"
13
+ VERSION = "1.0"
14
+ SUMMARY = "This is just a template"
15
+
16
+ RES = 600
17
+
18
+ GS = %W(
19
+ gs -q -dBATCH -dPARANOIDSAFER -dQUIET -dNOPAUSE
20
+ -sDEVICE=ljet2p -r#{RES} -sOutputFile=- -
21
+ )
22
+
23
+ def frame
24
+ job "#@login@#@host-#$$" do
25
+ set :ras1200mode => :off
26
+ set :resolution => RES
27
+ set :economode => :off
28
+ set :sourcetray => :tray1
29
+ set :mediatype => :regular
30
+ set :orientation => :portrait
31
+ set :paper => :a4
32
+ set :pageprotect => :auto
33
+ enter :pcl do
34
+ system *GS
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ exit MFC7420Appl.run
42
+
@@ -0,0 +1,63 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ #
4
+ # ifcanon -- input filter for Canon printer
5
+ #
6
+
7
+ require "pjl/appl"
8
+ require "socket"
9
+
10
+ class CanonIRAppl < PjlAppl
11
+
12
+ NAME = "ifcanon"
13
+ VERSION = "1.0"
14
+ SUMMARY = "Printer driver for Canon IR"
15
+
16
+ attr_writer :tray
17
+
18
+ define_option "t", :tray=, "NUM", "paper source"
19
+ alias_option "t", "tray"
20
+
21
+ def run
22
+ @tray ||= ($0 =~ /-tray(\d+)\z/) && $1.to_i
23
+ super
24
+ end
25
+
26
+ private
27
+
28
+ def job
29
+ uel
30
+ pjl "CQue2.0-2"
31
+ yield
32
+ ensure
33
+ uel
34
+ end
35
+
36
+ GS = %w(
37
+ gs -q -dBATCH -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ljet4 -sOutputFile=- -
38
+ )
39
+
40
+ def frame
41
+ uh = "#@login@#@host"
42
+ h, = Socket.gethostname.split "."
43
+ jn = "#{h}-#$$!#@login@#@host"
44
+ job do
45
+ comment :canpjl, :set, :username => uh
46
+ comment :canpjl, :set, :docname => jn
47
+ comment :canpjl, :set, :sortermode => :genericon
48
+ comment :canpjl, :set, :staple => :genericoff
49
+ comment :canpjl, :set, :punch => :genericoff
50
+ comment :canpjl, :set, :booklet => :genericoff
51
+ if @tray then
52
+ set :mediasource => :"tray#@tray"
53
+ end
54
+ enter :pcl do
55
+ system *GS
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ exit CanonIRAppl.run
63
+
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # iffile -- Print to file
5
+ #
6
+
7
+ require "supplement"
8
+ require "pjl/appl"
9
+
10
+
11
+ class FileAppl < PjlAppl
12
+
13
+ NAME = "iffile"
14
+ VERSION = "1.0"
15
+ SUMMARY = "Printer driver writing to a file"
16
+
17
+ OUTDIR = "/var/tmp/lpd-files"
18
+
19
+ def run
20
+ File.open output_path, "w" do |f|
21
+ f.puts $stdin.read
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def output_path
28
+ File.directory? OUTDIR or Dir.mkdir! OUTDIR
29
+ timestamp = Time.now.strftime "%Y%m%d-%H%M%S"
30
+ File.join OUTDIR, "lpd-job-#@login@#@host-#{timestamp}-#$$"
31
+ end
32
+
33
+ end
34
+
35
+ exit FileAppl.run
36
+
@@ -0,0 +1,46 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ #
4
+ # ifkyocera -- input filter kyocera printer
5
+ #
6
+
7
+ require "pjl/appl"
8
+
9
+ class KyoceraFSAppl < PjlAppl
10
+
11
+ NAME = "ifkyocera"
12
+ VERSION = "1.0"
13
+ SUMMARY = "Printer driver for Kyocera FS"
14
+
15
+ private
16
+
17
+ def frame
18
+ puts <<-EOT
19
+ !R! FRPO N7,1; CMNT Postscripts settumble cannnot do that.; EXIT,E;
20
+ EOT
21
+ display = "#@login@#@host"
22
+ job "#@login@#@host-#$$", :display => display do
23
+ rdymsg :display => display
24
+ set :economode => :off
25
+ enter :postscript do
26
+ l = $stdin.readline
27
+ case l
28
+ when /^%!/, /^%PDF/ then
29
+ begin
30
+ print l
31
+ end while l = readline
32
+ else
33
+ Pipe.run %w(a2ps -q) do |p|
34
+ p.feed l
35
+ p.feed $stdin
36
+ end
37
+ end
38
+ end
39
+ rdymsg :display => ""
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ exit KyoceraFSAppl.run
46
+
@@ -0,0 +1,31 @@
1
+ %!PS-Adobe-3.0
2
+
3
+ %
4
+ % nikolaus.ps -- Das Haus vom Nikolaus
5
+ %
6
+
7
+ % << /Duplex true >> setpagedevice
8
+ % statusdict begin true setduplexmode true settumble end
9
+
10
+ /Phi { 5 sqrt 1 sub 2 div } def
11
+
12
+ newpath
13
+
14
+ 100 100 moveto
15
+ 100 200 lineto
16
+ 200 200 lineto
17
+ 100 100 lineto
18
+ 200 100 lineto
19
+ 100 200 lineto
20
+ 100 100 2 div add 200 100 Phi mul add lineto
21
+ 200 200 lineto
22
+ 200 100 lineto
23
+
24
+ stroke
25
+
26
+ /Courier findfont 10 scalefont setfont
27
+ 100 350 moveto
28
+ (Das ist das Haus vom Nikolaus.) show
29
+
30
+ showpage
31
+
@@ -0,0 +1,44 @@
1
+ #
2
+ # printcap -- Example FreeBSD printer configuration
3
+ #
4
+
5
+ # (C) 2016 Bertram Scharpf <software@bertram-scharpf.de>
6
+
7
+ # WARNING! The filter-path capability "fp" below is an extension
8
+ # written by me and filed in December 2015
9
+ # (<https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=205604>).
10
+ # The FreeBSD community is ignoring my proposal as diligently as possible.
11
+ #
12
+ # The problem: After lpd was started by the "service" command (not
13
+ # /etc/rc.d/lpd from the command line!) the PATH environment variable
14
+ # is set as in /etc/login.conf. If the filter is a Ruby script containing
15
+ # a shebang line calling "env", the interpreter maybe will not be found.
16
+ #
17
+ # #!/usr/bin/env ruby
18
+ #
19
+ # Possible solutions:
20
+ #
21
+ # - Patch your base system and "make buildworld" etc. again.
22
+ #
23
+ # - Replace the shebang line using an explicit path:
24
+ #
25
+ # #!/usr/local/bin/ruby
26
+ #
27
+ # - Set an extended PATH variable for the lpd daemon in /etc/rc.conf:
28
+ #
29
+ # lpd_enable="YES"
30
+ # lpd_env="PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin"
31
+ #
32
+ # - Check the path capability in /etc/login.conf.
33
+ #
34
+ # Good luck!
35
+ #
36
+
37
+ mfc7420|brother|lp:\
38
+ :mx=0:\
39
+ :sd=/var/spool/lpd/mfc7420:\
40
+ :sh:\
41
+ :lp=/dev/ulpt0:\
42
+ :fp=/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin:\
43
+ :if=/usr/libexec/lpr/ifbrother:
44
+
@@ -0,0 +1,125 @@
1
+ #
2
+ # pjl.rb -- PJL generation
3
+ #
4
+
5
+ =begin rdoc
6
+
7
+ :section: Classes definied here
8
+
9
+ PJL generates PJL code.
10
+
11
+ =end
12
+
13
+
14
+ class Object
15
+ def to_pjlkey ; to_s ; end
16
+ end
17
+ class String
18
+ def to_pjlkey ; v = gsub '"', "''" ; %Q("#{v}") ; end
19
+ end
20
+ class Symbol
21
+ def to_pjlkey ; r = to_s; r.upcase! ; r ; end
22
+ end
23
+ class Array
24
+ def to_pjlkey ; map { |x| x.to_pjlkey }.join ; end
25
+ end
26
+
27
+
28
+ # PJL generation
29
+ #
30
+ # = Example
31
+ #
32
+ # class MyPrinter
33
+ # include PJL
34
+ # def run
35
+ # job "job-#$$" do
36
+ # rdymsg :display => "wait..."
37
+ # enter :postscript do
38
+ # puts "%!PS"
39
+ # ...
40
+ # end
41
+ # end
42
+ # end
43
+ # end
44
+ # MyPrinter.new.run
45
+ #
46
+ module PJL
47
+
48
+ def job name, *args
49
+ print "\0"*32
50
+ uel
51
+ pjl
52
+ j = { :name => name.to_s }
53
+ args.push j
54
+ pjl :job, *args
55
+ yield
56
+ ensure
57
+ pjl :eoj, j
58
+ uel
59
+ end
60
+
61
+ def lparm p
62
+ m = @m
63
+ @m = { :lparm => p.to_sym }
64
+ yield
65
+ ensure
66
+ @m = m
67
+ end
68
+
69
+ def iparm p
70
+ m = @m
71
+ @m = { :iparm => p.to_sym }
72
+ yield
73
+ ensure
74
+ @m = m
75
+ end
76
+
77
+ def noop
78
+ pjl
79
+ end
80
+ alias nop noop
81
+
82
+ def method_missing name, *args, &block
83
+ if block then
84
+ super
85
+ else
86
+ args.each { |a|
87
+ case a
88
+ when String, Symbol, Hash then next
89
+ else super
90
+ end
91
+ }
92
+ if name.to_s =~ /\Apjl_/ then name = $'.to_sym end
93
+ pjl name, *args
94
+ end
95
+ end
96
+
97
+ def enter language
98
+ pjl :enter, :language => language.to_sym
99
+ yield
100
+ ensure
101
+ uel
102
+ pjl
103
+ end
104
+
105
+ private
106
+
107
+ def uel
108
+ print "\e%-12345X"
109
+ end
110
+
111
+ def pjl *args
112
+ opt = {}
113
+ opt.update args.pop while args.last.is_a? Hash
114
+ l = []
115
+ args.flatten!
116
+ args.each { |a| l.push a }
117
+ @m and @m.each { |k,v| l.push [ k, :":", v] }
118
+ opt .each { |k,v| l.push [ k, :"=", v] }
119
+ cmd = "@PJL"
120
+ l.each { |x| cmd << " " << x.to_pjlkey }
121
+ puts cmd
122
+ end
123
+
124
+ end
125
+
@@ -0,0 +1,64 @@
1
+ #
2
+ # pjl/appl.rb -- Application
3
+ #
4
+
5
+ require "appl"
6
+ require "pjl"
7
+
8
+ class PjlAppl < Application
9
+
10
+ NAME = "pjlappl"
11
+ VERSION = "0.0"
12
+ SUMMARY = "This is just a template"
13
+
14
+ DESCRIPTION = "Call this as an input filter from printcap."
15
+
16
+ attr_writer :width, :length, :indent, :login, :host
17
+ attr_bang :plain, :debug
18
+
19
+ define_option "c", :plain!, "pass through control characters"
20
+ alias_option "c", "passctrl"
21
+ define_option "w", :width=, "NUM", "width"
22
+ alias_option "w", "width"
23
+ define_option "l", :length=, "NUM", "length"
24
+ alias_option "l", "length"
25
+ define_option "i", :indent=, "NUM", "indent"
26
+ alias_option "i", "indent"
27
+ define_option "n", :login=, "STR", "login name"
28
+ alias_option "n", "login"
29
+ define_option "h", :host=, "STR", "host name"
30
+ alias_option "h", "host"
31
+
32
+ define_option "g", :debug!, "lots of ugly debugging information"
33
+ alias_option "g", "debug"
34
+
35
+ define_option "H", :help, "show this options list"
36
+ alias_option "H", "help"
37
+ define_option "V", :version, "show version information"
38
+ alias_option "V", "version"
39
+
40
+ def run
41
+ @host ||= gethostname
42
+ @host, = @host.split "."
43
+ @acct_file = @args.shift
44
+ if @plain then
45
+ while (l = readline) do
46
+ print l
47
+ end
48
+ else
49
+ frame
50
+ end
51
+ rescue EOFError
52
+ end
53
+
54
+ include PJL
55
+
56
+ private
57
+
58
+ def gethostname
59
+ require "socket"
60
+ Socket.gethostname
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,23 @@
1
+ #
2
+ # pjl/version.rb -- Name and version number
3
+ #
4
+
5
+ module PJL
6
+
7
+ NAME = "pjl"
8
+ VERSION = "1.1".freeze
9
+
10
+ SUMMARY = "PJL generation"
11
+
12
+ DESCRIPTION = <<EOT
13
+ Write PJL (Printer Job Language) commands from a Ruby program.
14
+ EOT
15
+
16
+ COPYRIGHT = "(C) 2013-2016 Bertram Scharpf"
17
+ LICENSE = "BSD-2-Clause"
18
+ AUTHOR = "Bertram Scharpf <software@bertram-scharpf.de>"
19
+ TEAM = [ "Bertram Scharpf"]
20
+ HOMEPAGE = "http://www.bertram-scharpf.de/software/pjl"
21
+
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pjl
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ platform: ruby
6
+ authors:
7
+ - Bertram Scharpf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: |
28
+ Write PJL (Printer Job Language) commands from a Ruby program.
29
+ email: Bertram Scharpf <software@bertram-scharpf.de>
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - README
34
+ - LICENSE
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - example/ifbrother
39
+ - example/ifcanon
40
+ - example/iffile
41
+ - example/ifkyocera
42
+ - example/nikolaus.ps
43
+ - example/printcap
44
+ - lib/pjl.rb
45
+ - lib/pjl/appl.rb
46
+ - lib/pjl/version.rb
47
+ homepage: http://www.bertram-scharpf.de/software/pjl
48
+ licenses:
49
+ - BSD-2-Clause
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options:
53
+ - "--charset"
54
+ - utf-8
55
+ - "--main"
56
+ - lib/pjl.rb
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements:
70
+ - Some other tools from the same author
71
+ rubyforge_project: NONE
72
+ rubygems_version: 2.6.4
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: PJL generation
76
+ test_files: []