| 1 |
#!/usr/bin/env ruby |
| 2 |
# encoding: utf-8 |
| 3 |
|
| 4 |
# this file generates plain patterns (one-per-line) out of TeX source |
| 5 |
|
| 6 |
# use 'gem install unicode' if unicode is missing on your computer |
| 7 |
|
| 8 |
require_relative 'lib/tex/hyphen/language.rb' |
| 9 |
# include OldLanguage::TeXLive |
| 10 |
include TeX::Hyphen |
| 11 |
|
| 12 |
# FIXME Close files! |
| 13 |
# FIXME sr-cyrl? |
| 14 |
print '[1;36mGenerating[0m [0;34mplain files[0m for (parenthesised tags are skipped) ' |
| 15 |
Language.all.sort.each do |language| |
| 16 |
bcp47 = language.bcp47 |
| 17 |
|
| 18 |
if language.use_old_loader || bcp47 == 'mn-cyrl-x-lmc' |
| 19 |
print '([0;31m', language.bcp47, '[0m) ' |
| 20 |
next |
| 21 |
else |
| 22 |
print '[0;32m', bcp47, '[0m ' |
| 23 |
end |
| 24 |
|
| 25 |
outfile = Proc.new do |ext| |
| 26 |
File.open File.join(PATH::TXT, sprintf('hyph-%s.%s.txt', bcp47, ext)), 'w' |
| 27 |
end |
| 28 |
|
| 29 |
# patterns |
| 30 |
patterns = language.extract_apostrophes |
| 31 |
file = outfile.('pat') |
| 32 |
patterns[:plain].each do |pattern| |
| 33 |
file.puts pattern |
| 34 |
end |
| 35 |
|
| 36 |
# apostrophes if applicable |
| 37 |
with_apostrophe = patterns[:with_apostrophe] |
| 38 |
if with_apostrophe |
| 39 |
file = File.open File.join(PATH::QUOTE, sprintf('hyph-quote-%s.tex', bcp47)), 'w' |
| 40 |
file.printf "\\bgroup\n\\lccode`\\’=`\\’\n\\patterns{\n" |
| 41 |
with_apostrophe.each do |pattern| |
| 42 |
file.printf "%s\n", pattern |
| 43 |
end |
| 44 |
file.puts "}\n\\egroup\n" |
| 45 |
end |
| 46 |
|
| 47 |
# exceptions |
| 48 |
unless language.exceptions == "" |
| 49 |
file = outfile.('hyp') # This ensure a file is created, even if it may be empty |
| 50 |
file.puts language.exceptions |
| 51 |
end |
| 52 |
|
| 53 |
### FIXME Do issue #33 instead |
| 54 |
### # characters |
| 55 |
### file = outfile.('chr') |
| 56 |
### language.extract_characters.each do |character| |
| 57 |
### file.puts character |
| 58 |
### end |
| 59 |
|
| 60 |
### FIXME Do something else instead |
| 61 |
### # comments and licence |
| 62 |
### file = outfile.('lic') |
| 63 |
### file.puts language.comments_and_licence |
| 64 |
|
| 65 |
### file.close |
| 66 |
end |
| 67 |
puts |