s-gnu-diff.sh: removed
[s-roff.git] / tmac / hyphenex.pl
blob3456cf167e4dd59d8e1479ca366e792966332dcf
1 #!/usr/bin/env perl
2 #@ hyphenex.pl
3 #@ This small filter converts a hyphenation exception log article for
4 #@ TUGBoat to a real \hyphenation block.
5 #@ Version 1.2 (2007/11/16)
6 #@ Synopsis:
7 #@ [perl] hyphenex.pl < tugboat-article > hyphenation-exceptions
9 # Written by Werner Lemberg <wl@gnu.org>.
10 # Public domain.
12 # Adapted to S-roff by Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
14 # print header
15 print "% Hyphenation exceptions for US English,\n";
16 print "% based on hyphenation exception log articles in TUGboat.\n";
17 print "%\n";
18 print "% Copyright 2007 TeX Users Group.\n";
19 print "% You may freely use, modify and/or distribute this file.\n";
20 print "%\n";
21 print "% This is an automatically generated file. Do not edit!\n";
22 print "%\n";
23 print "% Please contact the TUGboat editorial staff <tugboat\@tug.org>\n";
24 print "% for corrections and omissions.\n";
25 print "\n";
26 print "\\hyphenation{\n";
28 while (<>) {
29 # retain only lines starting with \1 ... \6 or \tabalign
30 next if not (m/^\\[123456]/ || m/^\\tabalign/);
31 # remove final newline
32 chop;
33 # remove all TeX commands except \1 ... \6
34 s/\\[^123456\s{]+//g;
35 # remove all paired { ... }
36 1 while s/{(.*?)}/\1/g;
37 # skip lines which now have only whitespace before `&'
38 next if m/^\s*&/;
39 # remove comments
40 s/%.*//;
41 # remove trailing whitespace
42 s/\s*$//;
43 # remove trailing `*' (used as a marker in the document)
44 s/\*$//;
45 # split at whitespace
46 @field = split(' ');
47 if ($field[0] eq "\\1" || $field[0] eq "\\4") {
48 print " $field[2]\n";
50 elsif ($field[0] eq "\\2" || $field[0] eq "\\5") {
51 print " $field[2]\n";
52 # handle multiple suffixes separated by commata
53 @suffix_list = split(/,/, "$field[3]");
54 foreach $suffix (@suffix_list) {
55 print " $field[2]$suffix\n";
58 elsif ($field[0] eq "\\3" || $field[0] eq "\\6") {
59 # handle multiple suffixes separated by commata
60 @suffix_list = split(/,/, "$field[3],$field[4]");
61 foreach $suffix (@suffix_list) {
62 print " $field[2]$suffix\n";
65 else {
66 # for `&', split at `&' with trailing whitespace
67 @field = split(/&\s*/);
68 print " $field[1]\n";
72 # print trailer
73 print "}\n";
74 print "\n";
75 print "% EOF\n";
76 # s-it2-mode