9 # perl keilconv.pl < keil_header.h > sdcc_header.h
11 # perl keilconv.pl keil_header.h > sdcc_header.h
13 # keil_header.h and sdcc_header.h must not be the same file since
14 # most shells overwrite the output file before opening the input file.
17 # This script converts Keil-style header files to SDCC. It tries to
18 # be pedantic so don't be surprised if you need to munge it a bit to
19 # get it to work. On the other hand, it doesn't fully parse the C
20 # file (for obvious reasons).
22 # It takes the Keil header file either as an argument or on
23 # stdin and it produces the output on stdout.
25 # This script is inspired by keil2sdcc.pl by Bela Torok but a lot
32 s/\r//g; # remove DOS line endings if necessary
34 # external register (kind of a weird format)
36 # in: EXTERN xdata volatile BYTE GPIF_WAVE_DATA _AT_ 0xE400;
37 # out: EXTERN xdata at 0xE400 volatile BYTE GPIF_WAVE_DATA;
38 # $1: leading whitespace
40 # $3: variable location
41 # $4: trailing comments, etc.
43 if(/^(\s*)EXTERN\s*xdata\s*volatile\s*BYTE\s*(\w+(?:\s*\[\s*\d+\s*\])?)\s+_AT_\s*([^;]+);(.*)$/) {
44 print "$1EXTERN xdata at $3 volatile BYTE $2;$4\n";
51 # out: sfr at 0x80 IOA;
52 # $1: leading whitespace
54 # $3: variable location
55 # $4: trailing comments, etc.
57 if(/^(\s*)sfr\s*(\w+)\s*=\s*([^;]+);(.*)$/) {
58 print "$1sfr at $3 $2;$4\n";
64 # in: sbit SEL = 0x86+0;
65 # out: sbit at 0x86+0 SEL;
66 # $1: leading whitespace
68 # $3: variable location
69 # $4: trailing comments, etc.
71 if(/^(\s*)sbit\s*(\w+)\s*=\s*([^;]+);(.*)$/) {
72 print "$1sbit at $3 $2;$4\n";
78 # entire line is a C++ comment, output it unchanged.
79 if(/^(\s*)\/\/(.*)$/) {
84 # C comment, slurp lines until the close comment and output it unchanged.
85 if(/^(\s*)\/\*(.*)$/) {
86 my($ws,$cmt) = ($1,"$2\n");
87 $cmt .= <> while $cmt !~ /\*\/\s*$/;
93 # preprocessor statement (whitespace followed by '#'), don't change
99 # blank line, don't change
106 die "Unconvertable line: \"$_\"\n";