File indexing completed on 2024-05-12 15:49:58

0001 #!/usr/bin/perl
0002 
0003 # This perl script read stdin and write on stdout. It shall be an XML language file.
0004 #
0005 # * If the name of the language is 'HTML', then it creates the language 'PHP (HTML)'
0006 #   which shall be used for PHP hl.
0007 #
0008 # * If the name of the language is something else (say '*'), it creates the language '*/PHP'.
0009 #   This new language is the same as the old one, but is able to detect PHP everywhere.
0010 #
0011 # This script will correctly set extensions & mimetype, and will replace
0012 # <IncludeRules context="##*"> by <IncludeRules context="##*/PHP">
0013 #
0014 # Generated languages need a language named 'PHP/PHP', which shall take care of PHP hl itself
0015 # and which will be called every time something like <?php is encountred.
0016 #
0017 # SPDX-FileCopyrightText: Jan Villat <jan.villat@net2000.ch>
0018 # License: LGPL
0019 
0020 my $file = "";
0021 
0022 open(my $input, '<:encoding(UTF-8)', $ARGV[0])
0023   or die "Could not open file '$ARGV[0]': $!";
0024 
0025 open(my $output, '>:encoding(UTF-8)', $ARGV[1])
0026   or die "Could not open file '$ARGV[1]': $!";
0027 
0028 while (<$input>)
0029 {
0030   $file .= $_;
0031 }
0032 
0033 $warning = "\n\n<!-- ***** THIS FILE WAS GENERATED BY A SCRIPT - DO NOT EDIT ***** -->\n";
0034 
0035 $file =~ s/(?=<language)/$warning\n\n\n/;
0036 
0037 if ($file =~ /<language[^>]+name="HTML"/)
0038 {
0039   $root = 1;
0040 }
0041 
0042 if ($root == 1)
0043 {
0044   $file =~ s/<language([^>]+)name="[^"]*"/<language$1name="PHP (HTML)"/s;
0045   $file =~ s/<language([^>]+)section="[^"]*"/<language$1section="Scripts"/s;
0046   $file =~ s/<language([^>]+)extensions="[^"]*"/<language$1extensions="*.php;*.php3;*.wml;*.phtml;*.phtm;*.inc;*.ctp"/s;
0047   $file =~ s/<language([^>]+)mimetype="[^"]*"/<language$1mimetype="text\/x-php4-src;text\/x-php3-src;text\/vnd.wap.wml;application\/x-php"/s;
0048   $file =~ s/<language([^>]+)*/<language$1 indenter="cstyle"/s;
0049 }
0050 else
0051 {
0052   if ($file =~ /<language[^>]+hidden="[^"]*"/) {
0053     $file =~ s/<language([^>]+)name="([^"]*)"/<language$1name="$2\/PHP"/s;
0054     $file =~ s/<language([^>]+)hidden="[^"]*"/<language$1hidden="true"/s;
0055   }
0056   else
0057   {
0058     $file =~ s/<language([^>]+)name="([^"]*)"/<language$1name="$2\/PHP" hidden="true"/s;
0059   }
0060   $file =~ s/<language([^>]+)section="[^"]*"/<language$1section="Other"/s;
0061   $file =~ s/<language([^>]+)extensions="[^"]*"/<language$1extensions=""/s;
0062   $file =~ s/<language([^>]+)mimetype="[^"]*"/<language$1mimetype=""/s;
0063 }
0064 
0065 if ($root == 1 || $ARGV[0] =~ /mustache.xml$/)
0066 {
0067   $file =~ s/<(?:RegExpr (attribute="Processing Instruction" context="PI"|context="PI" attribute="Processing Instruction")|itemData name="Processing Instruction")[^\/]+\/>|<context name="PI".*?<\/context>//gs;
0068 }
0069 
0070 $findphp = "<context name=\"FindPHP\" attribute=\"Normal Text\" lineEndContext=\"#stay\">\n<Detect2Chars context=\"##PHP/PHP\" char=\"&lt;\" char1=\"?\" lookAhead=\"true\" />\n</context>\n";
0071 
0072 $file =~ s/<IncludeRules\s([^>]*)context="([^"#]*)##(?!Alerts|Comments|Doxygen|Modelines)([^"]+)"/<IncludeRules $1context="$2##$3\/PHP"/g;
0073 $file =~ s/(<context\s[^>]*[^>\/]>)/$1\n<IncludeRules context="FindPHP" \/>/g;
0074 $file =~ s/(<context\s[^>]*[^>\/])\s*\/>/$1>\n<IncludeRules context="FindPHP" \/>\n<\/context>/g;
0075 $file =~ s/(?=<\/contexts\s*>)/$findphp/;
0076 
0077 print $output $file;
0078 print $output $warning;