summaryrefslogtreecommitdiff
path: root/support/rfil/examples/encodingtable
blob: 59c12d459d57d80d47d41106e9b06a4f158348f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby -w
#--
# Last Change: Tue May 16 18:11:49 2006
#++
=begin rdoc
= encodingtable -- print out a table with different encodings in colums

This is mainly an example how to use the ENC and Kpathsea class. 

== Usage
 encodingtable encoding[.enc] [encoding[.enc] ...]


== Example
 
 $ ./encodingtable ec texnansi 8r 8a

 dec | oct |hex | ECEncoding       | TeXnANSIEncoding | TeXBase1Encoding | StandardEncoding |
 --------------------------------------------------------------------------------------------
   0 |   0 |  0 | grave            | ---              | ---              | ---              |
   1 |   1 |  1 | acute            | Euro             | dotaccent        | ---              |
   2 |   2 |  2 | circumflex       | ---              | fi               | ---              |
   3 |   3 |  3 | tilde            | ---              | fl               | ---              |
   4 |   4 |  4 | dieresis         | fraction         | fraction         | ---              |
   5 |   5 |  5 | hungarumlaut     | dotaccent        | hungarumlaut     | ---              |
  ...
---
Author:: Patrick Gundlach <patrick@gundla.ch>
=end

# :enddoc:

require 'rfil/tex/enc'
require 'rfil/tex/kpathsea'

include RFIL
include TeX

unless ARGV.size > 0
  puts "Usage: #{File.basename($0)} encoding[.enc] ..."
  exit
end

fmt=" %-16.16s |"

encodings=[]
kpse=Kpathsea.new
ARGV.each { |e|
  kpse.open_file(e.chomp('.enc')+'.enc','enc') { |f|
    encodings.push(ENC.new(f))
  }
}


print "dec | oct |hex |"
encodings.each { |e| print sprintf(fmt,e.encname) }


0.upto(255) { |slot|
  print "\n"+"-"*(16 + encodings.size * 19 ) if slot % 32 == 0

  print sprintf("\n%3d | %3o | %2x |", slot,slot,slot)
  encodings.each { |e|
    print sprintf(fmt, e[slot]==".notdef" ? "---" :  e[slot])
  }
}
puts