chiark / gitweb /
slopecalc handles non-initial @ correctly
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 6 Nov 2010 12:57:40 +0000 (12:57 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 6 Nov 2010 12:57:40 +0000 (12:57 +0000)
layout/slopecalc

index a89dd5e173e7208dc717136d06803dd5cd5c01b2..fd42c16320d6fc5225b8b0c929465aac2f2d5a15 100755 (executable)
@@ -17,8 +17,8 @@
 #  the slope _has_ changed a default distance is supplied
 #
 # the first use of @... to specify an absolute location
-#  acts only to fix the zero point of the absolute position scale
-#  and does not actually specify the location of the current point
+#  acts only to fix the zero point of the absolute position scale;
+#  the (relative to start) location of the current point must already be known
 
 use strict qw(vars refs);
 
@@ -30,8 +30,8 @@ our @cp= ({ L => 0 });
 # $cp[]{H}    height
 # $cp[]{L}    absolute dist
 # $cp[]{S}    slope
-
 our $absoffset;
+
 our $numre= '(?:\\d{1,6}(?:\\.\\d*)?|\\.\\d+)';
 
 our $progname= $0;
@@ -147,10 +147,16 @@ sub parse_args () {
            arg_item(S, $1 * 0.01);
        } elsif (m/^\@([-+]?$numre)$/o) {
            if (defined $absoffset) {
-               arg_item(L, $1 + $absoffset);
-           } else {
-               $absoffset= -$1;
-           }
+               arg_item(L, $1 + $absoffset);
+           } else {
+              if (!@cp) {
+                  $absoffset= -$1;
+              } elsif (defined $cp[$#cp]{L}) {
+                  $absoffset= $cp[$#cp]{L} - $1;
+              } else {
+                  arg_error("point \#$#cp location still unknown at \`$_'");
+              }
+           }
        } elsif (m/^\+($numre)$/o) {
            complete_current_point("new point started because of +...");
            arg_item(L, $cp[$#cp]{L} + $1);