• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1module TeX
2  module Hyphen
3    module TeXLive
4      module Source
5        def list_synonyms
6          if synonyms && synonyms.length > 0
7            sprintf " synonyms=%s", synonyms.join(',')
8          else
9            ''
10          end
11        end
12
13        def list_hyphenmins
14          lmin = lefthyphenmin
15          rmin = righthyphenmin
16          sprintf "lefthyphenmin=%s \\\n\trighthyphenmin=%s", lmin, rmin
17        end
18
19        # ext: 'pat' or 'hyp'
20        # filetype: 'patterns' or 'exceptions'
21        def plain_text_line(ext, filetype) # TODO Figure out if we will sr-cyrl to be generated again
22          return "" if ['ar', 'fa', 'grc-x-ibycus', 'mn-cyrl-x-lmc'].include? @bcp47
23
24          if @bcp47 =~ /^sh-/
25            # TODO Warning AR 2018-09-12
26            filename = sprintf 'hyph-sh-latn.%s.txt,hyph-sh-cyrl.%s.txt', ext, ext
27          else
28            filename = sprintf 'hyph-%s.%s.txt', @bcp47, ext
29            filepath = File.join(PATH::TXT, filename)
30            # check for existence of file and that it’s not empty
31            unless File.file?(filepath) && File.read(filepath).length > 0
32              # if the file we were looking for was a pattern file, something’s wrong
33              if ext == 'pat'
34                raise sprintf("There is some problem with plain patterns for language [%s]!!!", @bcp47)
35              else # the file is simply an exception file and we’re happy
36                filename = '' # And we return and empty file name after all
37              end
38            end
39          end
40
41          sprintf "file_%s=%s", filetype, filename
42        end
43
44        def exceptions_line
45          plain_text_line('hyp', 'exceptions')
46        end
47
48        def patterns_line
49          plain_text_line('pat', 'patterns')
50        end
51
52        def pTeX_patterns
53          if italic?
54            sprintf 'hyph-%s.tex', @bcp47
55          elsif encoding
56            sprintf 'hyph-%s.%s.tex', @bcp47, encoding
57          else
58            legacy_patterns
59          end
60        end
61
62        def list_loader
63          # which loader to use
64          if ['ar', 'fa'].include? @bcp47
65            sprintf "file=%s \\\n\tfile_patterns=", loadhyph
66          elsif @bcp47 == 'grc-x-ibycus'
67            # TODO: fix this
68            sprintf "file=%s \\\n\tluaspecial=\"disabled:8-bit only\"", loadhyph
69          else
70            sprintf "file=%s", loadhyph
71          end
72        end
73
74        def list_run_files
75          return [] if use_old_loader
76
77          files = []
78
79          files << File.join(PATH::HYPHU8, 'loadhyph', loadhyph)
80          if has_apostrophes?
81            files << File.join(PATH::HYPHU8, 'patterns', 'quote', sprintf("hyph-quote-%s.tex", bcp47))
82          end
83
84          files << File.join(PATH::HYPHU8, 'patterns', 'tex', sprintf('hyph-%s.tex', bcp47))
85          # FIXME That line is awful -- AR 2020-11-22
86          if encoding && encoding != "ascii" && !['la-x-classic', 'mk'].include?( bcp47) then
87            files << File.join(PATH::HYPHU8, 'patterns', 'ptex', sprintf('hyph-%s.%s.tex', bcp47, encoding))
88          elsif ['cop', 'mk'].include? bcp47 # FIXME That one too!
89            files << File.join(PATH::HYPHU8, 'patterns', 'tex-8bit', legacy_patterns)
90          end
91
92          # we skip the mongolian language for luatex files
93          return files if bcp47 == "mn-cyrl-x-lmc"
94
95          ['pat', 'hyp'].each do |t|
96            files << File.join(PATH::HYPHU8, 'patterns', 'txt', sprintf('hyph-%s.%s.txt', bcp47, t))
97          end
98
99          if bcp47 =~ /^sh-/
100            # duplicate entries (will be removed later)
101            files << File.join(PATH::HYPHU8, 'patterns', 'tex', 'hyph-sr-cyrl.tex')
102            ['pat', 'hyp'].each do |t|
103              # duplicate entries (will be removed later)
104              files << File.join(PATH::HYPHU8, 'patterns', 'txt', sprintf('hyph-sr-cyrl.%s.txt', t))
105            end
106          end
107
108          files
109        end
110
111        def package
112          extract_metadata
113          @package
114        end
115      end
116    end
117  end
118end
119