9 # perl keil2sdcc.pl < keil_header.h > sdcc_header.h
11 # perl keil2sdcc.pl keil_header.h > sdcc_header.h
14 # perl keil2sdcc.pl keil_header.h > sdcc_header.h
17 # keil_header.h and sdcc_header.h must not be the same file since
18 # most shells overwrite the output file before opening the input file.
21 # This script converts Keil-style header files to SDCC. It tries to
22 # be pedantic so don't be surprised if you need to munge it a bit to
23 # get it to work. On the other hand, it doesn't fully parse the C
24 # file (for obvious reasons).
26 # It takes the Keil header file either as an argument or on
27 # stdin and it produces the output on stdout.
29 # This script is inspired by keil2sdcc.pl by Bela Torok but a lot
36 s/\r//g; # remove DOS line endings if necessary
38 # external register (kind of a weird format)
40 # in: EXTERN xdata volatile BYTE GPIF_WAVE_DATA _AT_ 0xE400;
41 # out: EXTERN xdata at 0xE400 volatile BYTE GPIF_WAVE_DATA;
42 # $1: leading whitespace
44 # $3: variable location
45 # $4: trailing comments, etc.
47 if(/^(\s*)EXTERN\s*xdata\s*volatile\s*BYTE\s*(\w+(?:\s*\[\s*\d+\s*\])?)\s+_AT_\s*([^;]+);(.*)$/) {
48 print "$1EXTERN xdata at $3 volatile BYTE $2;$4\n";
55 # out: sfr at 0x80 IOA;
56 # $1: leading whitespace
58 # $3: variable location
59 # $4: trailing comments, etc.
61 if(/^(\s*)sfr\s*(\w+)\s*=\s*([^;]+);(.*)$/) {
62 print "$1sfr at $3 $2;$4\n";
68 # in: sbit SEL = 0x86+0;
69 # out: sbit at 0x86+0 SEL;
70 # $1: leading whitespace
72 # $3: variable location
73 # $4: trailing comments, etc.
75 if(/^(\s*)sbit\s*(\w+)\s*=\s*([^;]+);(.*)$/) {
76 print "$1sbit at $3 $2;$4\n";
82 # entire line is a C++ comment, output it unchanged.
83 if(/^(\s*)\/\
/(.*)$/) {
88 # C comment, slurp lines until the close comment and output it unchanged.
89 if(/^(\s*)\/\
*(.*)$/) {
90 my($ws,$cmt) = ($1,"$2\n");
91 $cmt .= <> while $cmt !~ /\*\/\s
*$/;
97 # preprocessor statement (whitespace followed by '#'), don't change
103 # blank line, don't change
110 die "Unconvertable line: \"$_\"\n";