#!perl

## no critic: TestingAndDebugging::RequireUseStrict

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2022-11-22'; # DATE
our $DIST = 'App-SubtitleUtils'; # DIST
our $VERSION = '0.011'; # VERSION

$secs_re = qr/[+-]?\d+(?:\.\d*)?/;
$hms_re = qr/\d\d?:\d\d?:\d\d?(?:,\d{1,3})?/;

###

die "Usage: $0 numstart FILE\n" unless @ARGV >= 1;
$num = shift @ARGV;

$para = "";
$lines = 1;
while (1) {
	$_ = <>;
	if (/\S/ || $lines <= 2) {
		s/\015//g;
		$para .= $_;
		$lines++;
	} elsif ($para =~ /\S/) {
		($no, $hms1, $hms2, $text) = $para =~ /(\d+)\n($hms_re) ---?> ($hms_re)\n(.*)/s or
			die "FATAL: Invalid entry in line $.: $para\n";
		print "$num\n$hms1 --> $hms2\n$text\n";
		$num++;
		$para = "";
	} else {
		$para = "";
		$lines = 1;
	}
	last unless $_;
}

# ABSTRACT: Renumber items in .srt
# PODNAME: srtrenumber

__END__

=pod

=encoding UTF-8

=head1 NAME

srtrenumber - Renumber items in .srt

=head1 VERSION

This document describes version 0.011 of srtrenumber (from Perl distribution App-SubtitleUtils), released on 2022-11-22.

=head1 SYNOPSIS

 % srtrenumber <numstart> [FILE]

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-SubtitleUtils>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-SubtitleUtils>.

=head1 HISTORY

2003-02-21 - first written

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 CONTRIBUTING


To contribute, you can send patches by email/via RT, or send pull requests on
GitHub.

Most of the time, you don't need to build the distribution yourself. You can
simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your
system), you can install L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
that are considered a bug and can be reported to me.

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2021, 2020 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-SubtitleUtils>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=cut
