chiark / gitweb /
AIX; nCipher keys; greenock
[ian-dotfiles.git] / gpt
diff --git a/gpt b/gpt
index 5076cc2ea3c8682beeafd44825bdf717f1c81e2c..6bb3a4ea7ac11519531373ad72368d72d6f14b16 100755 (executable)
--- a/gpt
+++ b/gpt
@@ -1,5 +1,56 @@
 #!/usr/bin/perl
 
+#
+#                          =====deeper=nesting===>>
+#
+#                     end of Perl fragment
+#                      \n@@ \_@@  ;@@ )@@ }@@  \w@@
+#                   <------------------------------------
+#
+#                   ------------------------------------>
+#                      if    eval    eval+     eval+
+#                       @@?   @@\_   ignore    include
+#                             @@$     @@-      file
+#    ___                      @@\n              @@<
+#  ,'   `
+#  |      processing                                       processing
+#  `--->  as TEXT                                          as PERL
+#  endif
+#   @@;     vA      <------------------------------------
+#           ||         then
+#   comment ||          ?@@
+#       @@# ||
+#           ||       included text fragment as
+#      else ||         string value    code to write out
+#       @@: ||          (@@             {@@
+#           ||      <------------------------------------
+#           `'
+#                   ------------------------------------>
+#                     end of included text fragment
+#                       @@)  @@}
+#
+#                          <<====deeper=nesting====
+#
+
+# gpt - a generic preprocessing tool
+#  
+#  This file is
+#    Copyright (C) 2001 Ian Jackson <ian@davenant.greenend.org.uk>
+#  
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2, or (at your option)
+#  any later version.
+#  
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#  
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+
 package GenericPrepTemplate;
 
 #BEGIN {
@@ -86,17 +137,22 @@ sub eval_expr () {
 sub process_input () {
     my ($esc,$top,$want,$fh,$value,$wasyes);
     while (length $l) {
-       print DEBUG "L $fn:$lno:",join('',@oplist),
-                   ":`$l' e\`$expr' s\`$substr'\n";
+       print DEBUG "L $fn:${lno}_",join('',@oplist),
+                   "_`$l' e\`$expr' s\`$substr'\n";
        if (@oplist & 1) { # scanning perl
            if ($l =~ m/^()\@\@/ || $l =~ m/([^\000])\@\@/) {
                ($to,$op,$esc,$l) = ($`,$1,$&,$');
                add_perl($to);
                if ($op =~ m/[ \t\n0-9a-zA-Z_\;\)\}?]/ || $op eq '') {
                    $top= pop @oplist;
+                   if ($top eq '?') {
+                       $op eq '?' or err("expected ?\@\@, got \@\@");
+                   } else {
+                       $op ne '?' or err("found ?\@\@ not after \@\@?");
+                   }
                    if (!@oplist) {
                        # And evaluate.
-                       $expr.= $op unless $op =~ m/[?]/;
+                       $expr.= $op unless $op eq '?';
                        $value= eval_expr();
                        if ($top eq '<') {
                            process_file($value);
@@ -124,9 +180,12 @@ sub process_input () {
                ($to,$op,$esc,$l) = ($`,$1,$&,$');
                add_text($to);
                if ($op =~ m/[-< \$?\n]/) {
-                   $substr.= $esc if @oplist;
+                   if (!@oplist) {
+                       add_perl($op) if $op =~ m/[\$]/;
+                   } else {
+                       $substr.= $esc;
+                   }
                    push @oplist, $op;
-                   add_perl($op) if $op =~ m/[\$]/;
                } elsif ($op =~ m/[\)\}\;\:]/) {
                    err("unmatched closing \@\@$op") unless @oplist;
                    $want= pop @oplist;