#!/usr/bin/perl -w # (c) Copyright 2012. Francois Gouget. use strict; my $name0=$0; $name0 =~ s+^.*/++; my $opt_file; my $usage; while (@ARGV > 0) { my $arg=shift @ARGV; if ($arg eq "-?" or $arg eq "-h" or $arg eq "--help") { $usage=0; } elsif ($arg =~ /^-/) { print STDERR "$name0:error: unknown '$arg' option\n"; $usage=2; last; } elsif (!defined $opt_file) { $opt_file=$arg; } else { print STDERR "$name0:error: unknown '$arg' option\n"; $usage=2; last; } } if (!defined $usage) { if (!defined $opt_file) { print STDERR "$name0:error: you must specify the path to the PO file to fix\n"; $usage=2; } } if (defined $usage) { if ($usage) { print STDERR "$name0:error: try '$name0 --help' for more information\n"; exit $usage; } print "Usage: $name0 MC_FILE [--help]\n"; print "\n"; print "Adds a full stop at the end of the winerror.mc messages,\n"; print "\n"; print "Options:\n"; print " MC_FILE The source MC file\n"; print " --help, -h Shows this help message\n"; exit 0; } my $fh; if (!open($fh, "<:encoding(utf-8)", $opt_file)) { print STDERR "$name0:error: unable to open '$opt_file' for reading: $!\n"; exit 1; } my @lines; while (my $line=<$fh>) { if ($line =~ /^\.$/) { $lines[-1] =~ s/\n$/.\n/ if ($lines[-1] !~ /\.\n$/); } push @lines, $line; } close($fh); if (!open($fh, ">:encoding(utf-8)", $opt_file)) { print STDERR "$name0:error: unable to open '$opt_file' for writing: $!\n"; exit 1; } print $fh @lines; close($fh);