utf.asm: add some error cases
[nasm/autotest.git] / syncfiles.pl
blobea77ca4daa54bac1ebf53539c97087ae6f184729
1 #!/usr/bin/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 %def_hints = ('object-ending' => '.o',
9 'path-separator' => '/',
10 'continuation' => "\\");
12 sub do_transform($$) {
13 my($l, $h) = @_;
15 $l =~ s/\x01/$$h{'object-ending'}/g;
16 $l =~ s/\x02/$$h{'path-separator'}/g;
17 $l =~ s/\x03/$$h{'continuation'}/g;
19 return $l;
22 @file_list = ();
24 $first = 1;
25 $first_file = $ARGV[0];
26 die unless (defined($first_file));
28 foreach $file (@ARGV) {
29 open(FILE, "< $file\0") or die;
31 # First, read the syntax hints
32 %hints = %def_hints;
33 while (defined($line = <FILE>)) {
34 if ($line =~ /^\#\s+\@(\S+)\:\s*\"([^\"]+)\"/) {
35 $hints{$1} = $2;
39 # Read and process the file
40 seek(FILE,0,0);
41 @lines = ();
42 $processing = 0;
43 while (defined($line = <FILE>)) {
44 chomp $line;
45 if ($processing) {
46 if ($line eq '#--- End File Lists ---#') {
47 push(@lines, $line."\n");
48 $processing = 0;
49 } elsif ($first) {
50 my $xl = $line;
51 my $oe = "\Q$hints{'object-ending'}";
52 my $ps = "\Q$hints{'path-separator'}";
53 my $cn = "\Q$hints{'continuation'}";
55 $xl =~ s/${oe}(\s|$)/\x01$1/g;
56 $xl =~ s/${ps}/\x02/g;
57 $xl =~ s/${cn}$/\x03/;
58 push(@file_list, $xl);
59 push(@lines, $line);
61 } else {
62 push(@lines, $line."\n");
63 if ($line eq '#--- Begin File Lists ---#') {
64 $processing = 1;
65 if (!$first) {
66 push(@lines, "# Edit in $first_file, not here!\n");
67 foreach $l (@file_list) {
68 push(@lines, do_transform($l, \%hints)."\n");
74 close(FILE);
76 # Write the file back out
77 if (!$first) {
78 open(FILE, "> $file\0") or die;
79 print FILE @lines;
80 close(FILE);
83 undef @lines;
84 $first = 0;