<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package ExtUtils::ParseXS::CountLines;
use strict;

our $VERSION = '3.18';

our $SECTION_END_MARKER;

sub TIEHANDLE {
  my ($class, $cfile, $fh) = @_;
  $cfile =~ s/\\/\\\\/g;
  $cfile =~ s/"/\\"/g;
  $SECTION_END_MARKER = qq{#line --- "$cfile"};

  return bless {
    buffer =&gt; '',
    fh =&gt; $fh,
    line_no =&gt; 1,
  }, $class;
}

sub PRINT {
  my $self = shift;
  for (@_) {
    $self-&gt;{buffer} .= $_;
    while ($self-&gt;{buffer} =~ s/^([^\n]*\n)//) {
      my $line = $1;
      ++$self-&gt;{line_no};
      $line =~ s|^\#line\s+---(?=\s)|#line $self-&gt;{line_no}|;
      print {$self-&gt;{fh}} $line;
    }
  }
}

sub PRINTF {
  my $self = shift;
  my $fmt = shift;
  $self-&gt;PRINT(sprintf($fmt, @_));
}

sub DESTROY {
  # Not necessary if we're careful to end with a "\n"
  my $self = shift;
  print {$self-&gt;{fh}} $self-&gt;{buffer};
}

sub UNTIE {
  # This sub does nothing, but is necessary for references to be released.
}

sub end_marker {
  return $SECTION_END_MARKER;
}

1;
</pre></body></html>