• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env ruby
2# encoding: utf-8
3
4# this file auto-generates loaders for hyphenation patterns - to be improved # No shit, Sherlock -- AR 2018-11-27
5
6require_relative 'lib/tex/hyphen'
7require_relative 'lib/tex/hyphen/texlive'
8include TeX::Hyphen
9include TeXLive
10
11#text_if_native_utf = "\input pattern-loader.tex\n\\ifNativeUtfEightPatterns"
12
13def output(file, string, indent = 0)
14  if string.is_a? Enumerable
15    string.each { |line| output(file, line, indent) }
16  else
17    file.print '  ' * indent
18    file.puts(string)
19  end
20end
21
22print 'Generating loaders for '
23Language.all.each do |language|
24
25# puts language.bcp47
26
27################
28# Header texts #
29################
30
31# a message about auto-generation
32# TODO: write a more comprehensive one
33  text_header = <<-EOHEADER
34% filename: loadhyph-#{language.bcp47}.tex
35% language: #{language.babelname}
36%
37% Loader for hyphenation patterns, generated by
38%     source/generic/hyph-utf8/generate-pattern-loaders.rb
39% See also http://tug.org/tex-hyphen
40%
41% Copyright 2008-#{Time.now.year} TeX Users Group.
42% You may freely use, modify and/or distribute this file.
43% (But consider adapting the scripts if you need modifications.)
44%
45% Once it turns out that more than a simple definition is needed,
46% these lines may be moved to a separate file.
47%
48  EOHEADER
49
50###########
51# lccodes #
52###########
53
54  lccodes_common = []
55  if language.has_apostrophes? then
56    lccodes_common.push("\\lccode`\\'=`\\'")
57  end
58  if language.has_hyphens? then
59    lccodes_common.push("\\lccode`\\-=`\\-")
60  end
61
62  next if language.use_old_loader
63    print language.bcp47, ' '
64
65    filename = File.join(PATH::LOADER, language.loadhyph)
66    File.open(filename, "w") do |file|
67      # puts language.bcp47
68      file.puts text_header
69      file.puts('\begingroup')
70
71      if lccodes_common.length > 0 then
72        file.puts lccodes_common.join("\n")
73      end
74
75      # for ASCII encoding, we don't load any special support files, but simply load everything
76      if language.encoding == 'ascii' && !language.italic?
77        file.puts "% ASCII patterns - no additional support is needed"
78        file.puts "\\message{ASCII #{language.message}}"
79        file.puts "\\input hyph-#{language.bcp47}.tex"
80      else
81        file.puts '% Test for pTeX
82\\ifx\\kanjiskip\\undefined
83% Test for native UTF-8 (which gets only a single argument)
84% That\'s Tau (as in Taco or ΤΕΧ, Tau-Epsilon-Chi), a 2-byte UTF-8 character
85\\def\\testengine#1#2!{\\def\\secondarg{#2}}\\testengine Τ!\\relax
86\\ifx\\secondarg\\empty'
87        output(file, language.format_inputs(language.utf8_chunk), 2)
88        file.puts("\\else\n")
89        output(file, language.format_inputs(language.nonutf8_chunk('8-bit')), 2)
90        file.puts("\\fi\\else\n")
91        output(file, language.format_inputs(language.nonutf8_chunk('pTeX')), 2)
92        file.puts("\\fi\n")
93      end
94
95########################################
96# GROUP nr. 1 - ONLY USABLE WITH UTF-8 #
97########################################
98      # some special cases first
99      #
100      # some languages (sanskrit) are useless in 8-bit engines; we only want to load them for UTF engines
101      # TODO - maybe consider doing something similar for ibycus
102
103#######################
104# GROUP nr. 2 - ASCII #
105#######################
106
107####################################
108# GROUP nr. 3 - different patterns #
109####################################
110      # when lanugage uses old patterns for 8-bit engines, load two different patterns rather than using the converter
111        # greek, coptic
112#########################
113# GROUP nr. 4 - regular #
114#########################
115#######
116# end #
117#######
118      file.puts('\endgroup')
119    end
120end
121
122puts
123