summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/generic/hyph-utf8/generate-plain-patterns.rb
blob: 85d1d99dbf9ab8529a417d9e057896c8b6eb9f85 (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
# encoding: utf-8

# this file generates plain patterns (one-per-line) out of TeX source

# use 'gem install unicode' if unicode is missing on your computer

require_relative 'lib/tex/hyphen/language.rb'
# include OldLanguage::TeXLive
include TeX::Hyphen

# FIXME Close files!
# FIXME sr-cyrl?
print 'Generating plain files for (parenthesised tags are skipped) '
Language.all.sort.each do |language|
	bcp47 = language.bcp47

	if language.use_old_loader || bcp47 == 'mn-cyrl-x-lmc'
		print '(', language.bcp47, ') '
		next
	else
		print bcp47, ' '
	end

	outfile = Proc.new do |ext|
		File.open File.join(PATH::TXT, sprintf('hyph-%s.%s.txt', bcp47, ext)), 'w'
	end

	# patterns
	patterns = language.extract_apostrophes
	file = outfile.('pat')
	patterns[:plain].each do |pattern|
		file.puts pattern
	end

	# apostrophes if applicable
	with_apostrophe = patterns[:with_apostrophe]
	if with_apostrophe
		file = File.open File.join(PATH::QUOTE, sprintf('hyph-quote-%s.tex', bcp47)), 'w'
		file.printf "\\bgroup\n\\lccode`\\’=`\\’\n\\patterns{\n"
		with_apostrophe.each do |pattern|
			file.printf "%s\n", pattern
		end
		file.puts "}\n\\egroup\n"
	end

	# exceptions
	unless language.exceptions == ""
		file = outfile.('hyp') # This ensure a file is created, even if it may be empty
		file.puts language.exceptions
	end

	### FIXME Do issue #33 instead
	### # characters
	### file = outfile.('chr')
	### language.extract_characters.each do |character|
	### 	file.puts character
	### end

	### FIXME Do something else instead
	### # comments and licence
	### file = outfile.('lic')
	### file.puts language.comments_and_licence

	### file.close
end
puts