]> git.sur5r.net Git - cc65/blob - src/ca65/macpack/cvt-mac.pl
More lineinfo usage.
[cc65] / src / ca65 / macpack / cvt-mac.pl
1 #!/usr/bin/perl
2
3 # Check number of params
4 die "Usage: cvt-cfg.pl input output varname\n" unless ($#ARGV == 2);
5
6 # Get the parameters
7 $InputName  = shift (@ARGV);
8 $OutputName = shift (@ARGV);
9 $VarName    = shift (@ARGV);
10
11 # Open both files
12 open (IN, "<$InputName") or die "Cannot open $InputName\n";
13 open (OUT, ">$OutputName") or die "Cannot open $OutputName\n";
14
15 # Print the header to the output file
16 print OUT "static char $VarName" . "[] = \n";
17
18 # Read from input, print to output
19 while ($Line = <IN>) {
20
21     # Remove the newline
22     chomp $Line;
23
24     # Separate an existing comment. No need to be overly clever, just ignore
25     # semicolons in strings.
26     if ($Line =~ /(.*?)(\s*)(;\s*)(.*?)\s*$/) {
27         $Line         = $1;
28         $CommentSpace = $2;
29         $Comment      = $4;
30     } else {
31         $CommentSpace = "";
32         $Comment      = "";
33     }
34
35     # Remove leading and trailing spaces
36     $Line =~ s/^\s*|\s*$//g;
37
38     # Ignore empty lines
39     if ($Line eq "") {
40         if ($Comment ne "") {
41             print OUT "/* $Comment */\n";
42         }
43         next;
44     }
45
46     # Replace control chars
47     $Line =~ s/\\/\\\\/g;
48     $Line =~ s/\"/\\\"/g;
49     $Line =~ s/\'/\\\'/g;
50
51     # Print to output
52     print OUT "\"$Line\\n\"";
53
54     # Add a comment if we have one
55     if ($Comment ne "") {
56         print OUT "$CommentSpace/* $Comment */";
57     }
58
59     # Terminate the line
60     print OUT "\n";
61 }
62
63 # Terminate the variable declaration
64 print OUT ";\n";
65
66 # Close the files
67 close IN;
68 close OUT;
69
70 # Done
71 exit 0;
72
73
74
75