Reworked test files for better error reporting
[nasm/perl-rewrite.git] / syncfiles.pl
blobc64cb6720086449d689f3d8cde33ac6851c965da
1 #!/usr/bin/env perl
3 # Sync the output file list between Makefiles
4 # Use the mkdep.pl parameters to get the filename syntax
6 # The first file is the source file; the other ones target.
8 use strict;
9 use warnings;
11 our %def_hints = qw{
12 object-ending .o
13 path-separator /
14 continuation \\
17 sub do_transform($\%) {
18 my($l, $h) = @_;
19 my($ps) = $$h{'path-separator'};
21 $l =~ s/\x01/$$h{'object-ending'}/g;
22 $l =~ s/\x03/$$h{'continuation'}/g;
24 if ($ps eq '') {
25 # Remove the path separator and the preceeding directory
26 $l =~ s/[^\s\=]*\x02//g;
27 } else {
28 # Convert the path separator
29 $l =~ s/\x02/$ps/g;
32 return $l;
36 our @file_list;
38 my $first = 1;
39 my $first_file = $ARGV[0];
40 die unless (defined($first_file));
42 for my $filename (@ARGV) {
43 open( FILE, '<', $filename ) or die;
45 # First, read the syntax hints
46 my %hints = %def_hints;
47 while( my $line = <FILE> ){
48 if ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) {
49 $hints{$1} = $2;
53 # Read and process the file
54 seek(FILE,0,0);
55 my @lines;
56 my $processing = 0;
57 while( my $line = <FILE> ){
58 chomp $line;
59 if ($processing) {
60 if ($line eq '#-- End File Lists --#') {
61 push(@lines, $line."\n");
62 $processing = 0;
63 } elsif ($first) {
64 my $xl = $line;
65 my $oe = "\Q$hints{'object-ending'}";
66 my $ps = "\Q$hints{'path-separator'}";
67 my $cn = "\Q$hints{'continuation'}";
69 $xl =~ s/${oe}(\s|$)/\x01$1/g;
70 $xl =~ s/${ps}/\x02/g;
71 $xl =~ s/${cn}$/\x03/;
72 push(@file_list, $xl);
73 push(@lines, $line);
75 } else {
76 push(@lines, $line."\n");
77 if ($line eq '#-- Begin File Lists --#') {
78 $processing = 1;
79 if (!$first) {
80 push(@lines, "# Edit in $first_file, not here!\n");
81 for my $l (@file_list) {
82 push(@lines, do_transform($l, %hints)."\n");
88 close(FILE);
90 # Write the file back out
91 if (!$first) {
92 open( FILE, '>', $filename ) or die;
93 print FILE @lines;
94 close(FILE);
97 $first = 0;