Conversion du fichier source au format UTF-8
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 7 Dec 2021 03:09:38 +0000 (22:09 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 9 Mar 2022 22:14:43 +0000 (17:14 -0500)
gtx2tex.pl

index 02300f6..03a120b 100644 (file)
@@ -1,9 +1,27 @@
 #!/usr/bin/perl
 
+# The locale functionality is not usable prior to Perl 5.004
+require 5.004;
+
+# Enable to use UTF-8 in this source file
+use utf8;
+
 use File::Basename;
 use Cwd;
 use Getopt::Long;
 
+# Import locale-handling tool set from POSIX module.
+# This example uses: setlocale -- the function call
+#                    LC_CTYPE -- explained below
+use POSIX qw(locale_h);
+
+setlocale(LC_CTYPE, "fr_FR.utf-8");
+
+use locale;
+
+# Configure STDOUT to output in UTF-8
+binmode(STDOUT, ":utf8");
+
 GetOptions( "output=s" => \$output,
            "lyrics" => \$lyrics,
            "verbose" => \$verbose,
@@ -81,7 +99,7 @@ $diminished7 = "\$^{\\circ7}\$";
 do "/usr/local/lib/guitartex/language/$language.pl" or die "cannot load language
     file $language.pl\n";
 
-# Leerzeichen im Dateinamen in Unterstriche ändern
+# Leerzeichen im Dateinamen in Unterstriche ändern
 $outfilename =~ s/\s/\_/g;
 
 # open output file
@@ -94,7 +112,7 @@ $chaptercount = 0;
 
 # Eingabedatei zeilenweise bearbeiten
 while ( <CHORDPRO> ) {
-    # Zeichen für Zeilenende abschneiden
+    # Zeichen für Zeilenende abschneiden
     chomp;
     # wenn am Anfang der Zeile { steht, handelt es sich um eine Direktive
     if ( /^{/ ) {
@@ -170,7 +188,7 @@ sub create_pdf {
 
 sub crdpro { # Bearbeitung der Zeile aus der Eingabedatei
     if ( $lyrics ) {
-        s/\[.*?\]//g; # Akkorde entfernen / On enlève les accords
+        s/\[.*?\]//g; # Akkorde entfernen / On enlève les accords
         print TEX "$_\\\\\n" unless ( /^\s*$/ );
     } else {
 
@@ -178,13 +196,13 @@ sub crdpro { # Bearbeitung der Zeile aus der Eingabedatei
             $_ = uc($_); # Toutes les lettres en majuscule.
         }
 
-        s/\s/$space/g;                                 # Remplace une séquence de plusieurs espaces par un seul
+        s/\s/$space/g;                                 # Remplace une séquence de plusieurs espaces par un seul
         s/(\^)(.*?)(\])/\\\(^\{\2\}\\\)\]/g;   # Ziffern hochstellen / Place les chiffres en haut?
 
         s/\[/\}\\gtxchord{/g;                  # linke Klammer ersetzen / Remplace crochet gauche
         s/\]/}{/g;                             # rechte Klammer ersetzen / Remplace crochet droit
         #      s/(\})(.*?)(\\)/}{\2}\\/g;      # Text zwischen Akkorden in geschweifte Klammern setzen
-        s/$/}/; # rechte Klammer am Ende der Zeile ergänzen
+        s/$/}/; # rechte Klammer am Ende der Zeile ergänzen
         s/^\}//; # rechte Klammer am Anfang der Zeile entfernen
         if ( $_ !~ /^\\/ ) {
             s/^/\\gtxchord\{\}\{/
@@ -193,15 +211,15 @@ sub crdpro { # Bearbeitung der Zeile aus der Eingabedatei
         if ( $uppercase ) {
             s/(gtxchord\{[A-G][B#]?)MAJ7/\1$majeur_sept/g;            # Remplace 'gtxchord{AM'  par 'gtxchord{Am'
 
-            # On recherche le nom de l'accord, suivi d'un bémol ou dièse optionel, suivi de 'sus' + 1 chiffre.
+            # On recherche le nom de l'accord, suivi d'un bémol ou dièse optionel, suivi de 'sus' + 1 chiffre.
             s/(gtxchord\{[A-G][B#]?[0-9]?)SUS([0-9]+)/\1\$^{sus\2}\$/g;
 
-            # Accord demi-diminué
-            # On recherche le nom de l'accord, suivi d'un bémol ou dièse optionel, suivi de 'm7b5'.
+            # Accord demi-diminué
+            # On recherche le nom de l'accord, suivi d'un bémol ou dièse optionel, suivi de 'm7b5'.
             s/(gtxchord\{[A-G][B#]?)M7B5/\1$half_diminished/g;
 
-            # Accords diminués
-            # On recherche le nom de l'accord, suivi d'un bémol ou dièse optionel, suivi de 'mb5'.
+            # Accords diminués
+            # On recherche le nom de l'accord, suivi d'un bémol ou dièse optionel, suivi de 'mb5'.
             s/(gtxchord\{[A-G][B#]?)MB5/\1$diminished/g;
             s/(gtxchord\{[A-G][B#]?)DIM7/\1$diminished7/g;
             s/(gtxchord\{[A-G][B#]?)DIM/\1$diminished/g;
@@ -558,7 +576,7 @@ sub latex_header {
                                                     %%\\doublespacing
                                                     \\setstretch{1.8}
 
-    %------PostScript-Header für die Chord-Songs------
+    %------PostScript-Header für die Chord-Songs------
                                                     %\\special{header=$libpath/chord-common.ps}
 
     \\sloppy
@@ -567,29 +585,29 @@ sub latex_header {
     \\newcommand{\\gtxchord}[2]{\\sbox{\\gtxchordbox}{#1}\\sbox{\\textbox}{#2}%
     \\ifthenelse{\\lengthtest{\\wd\\textbox>\\wd\\gtxchordbox}}%
     {%
-         % Boîte pour les accords (plus gros)
+         % Boîte pour les accords (plus gros)
          \\raisebox{2.5ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\small\\bf#1}}#2%
-                                     }{%
-                                           % Boîte pour les accords (plus gros)
-                                           \\raisebox{2.5ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\small\\bf#1}}\\makebox[\\wd\\gtxchordbox+0.5em][l]{#2}%
-                                                                       }%
-                                       }%
-
-                                           \\newcommand{\\guitartab}{%
-                                                                         \\makebox[0cm][l]{\\raisebox{12.5ex}{\\footnotesize{e}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{10.5ex}{\\footnotesize{B}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{6.5ex}{\\footnotesize{D}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{4.5ex}{\\footnotesize{A}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{2.5ex}{\\footnotesize{E}}}%
-                                                                         ~~
-                                                                         \\makebox[0cm][l]{\\raisebox{13ex}{\\line(1,0){130}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{11ex}{\\line(1,0){130}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{9ex}{\\line(1,0){130}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{7ex}{\\line(1,0){130}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{5ex}{\\line(1,0){130}}}%
-                                                                         \\makebox[0cm][l]{\\raisebox{3ex}{\\line(1,0){130}}}%
-                                                                         ~}
+                                       }{%
+                                             % Boîte pour les accords (plus gros)
+                                             \\raisebox{2.5ex}[2ex][2.5ex]{\\makebox[0pt][l]{\\small\\bf#1}}\\makebox[\\wd\\gtxchordbox+0.5em][l]{#2}%
+                                                                           }%
+                                         }%
+
+                                             \\newcommand{\\guitartab}{%
+                                                                           \\makebox[0cm][l]{\\raisebox{12.5ex}{\\footnotesize{e}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{10.5ex}{\\footnotesize{B}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{6.5ex}{\\footnotesize{D}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{4.5ex}{\\footnotesize{A}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{2.5ex}{\\footnotesize{E}}}%
+                                                                           ~~
+                                                                           \\makebox[0cm][l]{\\raisebox{13ex}{\\line(1,0){130}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{11ex}{\\line(1,0){130}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{9ex}{\\line(1,0){130}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{7ex}{\\line(1,0){130}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{5ex}{\\line(1,0){130}}}%
+                                                                           \\makebox[0cm][l]{\\raisebox{3ex}{\\line(1,0){130}}}%
+                                                                           ~}
 
     \\newcommand{\\basstab}{%
                                 \\makebox[0cm][l]{\\raisebox{8.5ex}{\\footnotesize{G}}}%