]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix some c353 edge cases
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 28 Mar 2024 20:22:43 +0000 (13:22 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 28 Mar 2024 20:22:43 +0000 (13:22 -0700)
lib/Perl/Tidy/VerticalAligner.pm
t/snippets/c353.in
t/snippets/expect/c353.c353
t/snippets/expect/c353.def
t/snippets/packing_list.txt
t/snippets29.t

index c6989fc0bf6db119a7eba1b63b45a2b0c2570b88..8767950d821b42ac0d3412fcc87946b85561fb9c 100644 (file)
@@ -5777,7 +5777,11 @@ EOM
     #------------------------------------------------------
     # loop over all lines of this vertical alignment column
     #------------------------------------------------------
-    my ( $current_alignment, $starting_colp );
+
+    my (
+        $current_alignment, $starting_colp,
+        $current_line,      @previous_linked_lines
+    );
     foreach my $item ( @{$rwidths} ) {
         my ( $ix, $width ) = @{$item};
         my $line = $rgroup_lines->[$ix];
@@ -5801,25 +5805,32 @@ EOM
 
         # nothing to do if no more real alignments on right
         if ( $jcolp >= $jmax - 1 ) {
-            $current_alignment = undef;
+            $current_alignment     = undef;
+            $current_line          = undef;
+            @previous_linked_lines = ();
         }
 
         # handle new rhs alignment
         elsif ( !$current_alignment ) {
-            $current_alignment = $alignment;
-            $starting_colp     = $colp;
+            $current_alignment     = $alignment;
+            $current_line          = $line;
+            $starting_colp         = $colp;
+            @previous_linked_lines = ();
         }
 
         # handle change in existing alignment
         elsif ( refaddr($alignment) != refaddr($current_alignment) ) {
 
-            # completely new rhs
+            # change rhs alignment column - new vertical group on right
             if ( $starting_colp != $colp ) {
-                $starting_colp = $colp;
+                $starting_colp         = $colp;
+                @previous_linked_lines = ();
             }
             else {
 
-                # alignment transfer - see if we must increase width
+                # Same starting alignment col on right, but different alignment
+                # object. See if we must increase width of this new alignment
+                # object.
                 my $current_colp = $current_alignment->{column};
                 if ( $current_colp > $colp ) {
                     my $excess = $current_colp - $colp;
@@ -5830,8 +5841,13 @@ EOM
                         $colp = $alignment->{column};
                     }
                 }
+
+                # remember the previous line in case we have to go back and
+                # increasse its width
+                push @previous_linked_lines, $current_line;
             }
             $current_alignment = $alignment;
+            $current_line      = $line;
         }
         else {
             # continuing with same alignment
@@ -5851,16 +5867,30 @@ EOM
             my $excess = $lenp + $pad - $avail;
 
             if ( $excess > 0 ) {
+
                 my $padding_available = $line->get_available_space_on_right();
                 if ( $excess <= $padding_available ) {
                     $line->increase_field_width( $jcolp, $excess );
+
+                    # Increase space of any previous linked lines
+                    foreach my $line_prev (@previous_linked_lines) {
+                        $padding_available =
+                          $line_prev->get_available_space_on_right();
+                        if ( $excess <= $padding_available ) {
+                            $line_prev->increase_field_width( $jcolp, $excess );
+                        }
+                        else {
+                            last;
+                        }
+                    }
                 }
                 else {
                     $pad = 0;
                 }
+
             }
 
-            # increase the space
+            # Add spaces
             $rfields->[$jcolp] = ( SPACE x $pad ) . $rfields->[$jcolp];
             $rfield_lengths->[$jcolp] += $pad;
         }
index 2fee94bcecb14f0c94e53235ef3d327e0c35a915..902feba289eac33dea45ce3e60941c89fd2bb666 100644 (file)
@@ -12,3 +12,15 @@ $unique  ||= $hash   if (1);
 $basepath  = $CWD unless length($basepath);
 $basepath .= '/'  if -d $basepath && $basepath !~ m#/$#;
 
+$$hr  = $1 || $5 || $9 || 0;    # 9 is undef, but 5 is defined..
+$$mr  = $2 || $6 || 0;
+$$sr  = $3 || $7 || 0;
+$ampm = $4 || $8 || $10;
+$$tzr = $11;
+$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12;
+$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM";
+$$hr = 0 if $$hr == 24;
+
+$map = $DEFAULT_MAP               unless defined $map;
+$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|;
+$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
index 2fee94bcecb14f0c94e53235ef3d327e0c35a915..07fe6ad1ce1d10ea39266f1b05c79e669ad87095 100644 (file)
@@ -12,3 +12,15 @@ $unique  ||= $hash   if (1);
 $basepath  = $CWD unless length($basepath);
 $basepath .= '/'  if -d $basepath && $basepath !~ m#/$#;
 
+$$hr   = $1 || $5 || $9 || 0;    # 9 is undef, but 5 is defined..
+$$mr   = $2 || $6 || 0;
+$$sr   = $3 || $7 || 0;
+$ampm  = $4 || $8 || $10;
+$$tzr  = $11;
+$$hr  += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12;
+$$hr   = 0  if $$hr == 12                  && "\U$ampm" eq "AM";
+$$hr   = 0  if $$hr == 24;
+
+$map  = $DEFAULT_MAP               unless defined $map;
+$map  = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|;
+$map .= $DEFAULT_EXT               unless $map =~ m|/[^/]+\.[^/]+$|;
index ac76c4c6843769a461db7eb4b8281d18b7d5c64c..4080cb2057b8f1f5d9cc0c5d15c08677fbaf80f8 100644 (file)
@@ -12,3 +12,15 @@ $unique ||= $hash if (1);
 $basepath = $CWD unless length($basepath);
 $basepath .= '/' if -d $basepath && $basepath !~ m#/$#;
 
+$$hr  = $1 || $5 || $9 || 0;    # 9 is undef, but 5 is defined..
+$$mr  = $2 || $6 || 0;
+$$sr  = $3 || $7 || 0;
+$ampm = $4 || $8 || $10;
+$$tzr = $11;
+$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12;
+$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM";
+$$hr = 0 if $$hr == 24;
+
+$map = $DEFAULT_MAP               unless defined $map;
+$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|;
+$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
index 038440d684104b3a1114b14f2204f75d930ebf90..46b998b561f6a867e21d75115308e64ac4ea7d91 100644 (file)
 ../snippets29.t        git135.def
 ../snippets29.t        git135.git135
 ../snippets29.t        c352.def
+../snippets29.t        c353.c353
+../snippets29.t        c353.def
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets29.t        c353.c353
-../snippets29.t        c353.def
index 53e0f5a5de45412a70a1b796150efe5ebf662ae4..2018287c998a4c8b550acf4b0e6ae815d4720429 100644 (file)
@@ -83,6 +83,18 @@ $unique  ||= $hash   if (1);
 $basepath  = $CWD unless length($basepath);
 $basepath .= '/'  if -d $basepath && $basepath !~ m#/$#;
 
+$$hr  = $1 || $5 || $9 || 0;    # 9 is undef, but 5 is defined..
+$$mr  = $2 || $6 || 0;
+$$sr  = $3 || $7 || 0;
+$ampm = $4 || $8 || $10;
+$$tzr = $11;
+$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12;
+$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM";
+$$hr = 0 if $$hr == 24;
+
+$map = $DEFAULT_MAP               unless defined $map;
+$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|;
+$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
 ----------
 
         'dia' => <<'----------',
@@ -489,6 +501,18 @@ $unique  ||= $hash   if (1);
 $basepath  = $CWD unless length($basepath);
 $basepath .= '/'  if -d $basepath && $basepath !~ m#/$#;
 
+$$hr   = $1 || $5 || $9 || 0;    # 9 is undef, but 5 is defined..
+$$mr   = $2 || $6 || 0;
+$$sr   = $3 || $7 || 0;
+$ampm  = $4 || $8 || $10;
+$$tzr  = $11;
+$$hr  += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12;
+$$hr   = 0  if $$hr == 12                  && "\U$ampm" eq "AM";
+$$hr   = 0  if $$hr == 24;
+
+$map  = $DEFAULT_MAP               unless defined $map;
+$map  = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|;
+$map .= $DEFAULT_EXT               unless $map =~ m|/[^/]+\.[^/]+$|;
 #13...........
         },
 
@@ -510,6 +534,18 @@ $unique ||= $hash if (1);
 $basepath = $CWD unless length($basepath);
 $basepath .= '/' if -d $basepath && $basepath !~ m#/$#;
 
+$$hr  = $1 || $5 || $9 || 0;    # 9 is undef, but 5 is defined..
+$$mr  = $2 || $6 || 0;
+$$sr  = $3 || $7 || 0;
+$ampm = $4 || $8 || $10;
+$$tzr = $11;
+$$hr += 12 if $ampm and "\U$ampm" eq "PM" && $$hr != 12;
+$$hr = 0 if $$hr == 12 && "\U$ampm" eq "AM";
+$$hr = 0 if $$hr == 24;
+
+$map = $DEFAULT_MAP               unless defined $map;
+$map = $DEFAULT_PATH . "/" . $map unless $map =~ m|/|;
+$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
 #14...........
         },
     };