avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] Re: [avr-gcc-list] Re: What Happened to the sbi() and cbi


From: Ned Konz
Subject: [avr-libc-dev] Re: [avr-gcc-list] Re: What Happened to the sbi() and cbi() Macros????
Date: Mon, 31 Jan 2005 09:46:11 -0800
User-agent: KMail/1.7.2

On Monday 31 January 2005 9:41 am, I wrote:

> (3) make a conversion program that can modify old code in place. Somehow
> make it really clear that people should use it to help them migrate old
> code. In the case of cbi() and sbi() this could be a simple Perl script:
>
> ---
> #!/usr/bin/perl -pi.bak
> # Rewrite sbi() and cbi() macro usage
> # Will make backup files with .bak extensions when run as described.
> #
> # Usage:
> #  perl -pi.bak file [...]
>
> # cbi(reg,bit)
> s/\bcbi\s*\(\s*([^,)]+)\s*,\s*([^,)]+)\s*\)/$1 &= ~($2)/g;
>
> # sbi(reg,bit)
> s/\bsbi\s*\(\s*([^,)]+)\s*,\s*([^,)]+)\s*\)/$1 |= $2/g;
> ---

Of course, I got that wrong, as the second argument is a bit *number*. Sorry, 
I don't use these macros.


Anyway, assuming that BIT() is defined, it would look like this:


#!/usr/bin/perl -pi.bak
# Rewrite sbi() and cbi() macro usage
# Will make backup files with .bak extensions when run as described.
# Assumes the existence of a BIT() macro like:
#
# #define BIT(n) ((unsigned char)(1<<n))
#
# Usage:
#  perl -pi.bak file [...]

# cbi(reg,bit)
s/\bcbi\s*\(\s*([^,)]+)\s*,\s*([^,)]+)\s*\)/$1 &= ~BIT($2)/g;

# sbi(reg,bit)
s/\bsbi\s*\(\s*([^,)]+)\s*,\s*([^,)]+)\s*\)/$1 |= BIT($2)/g;

-- 
Ned Konz
http://bike-nomad.com





reply via email to

[Prev in Thread] Current Thread [Next in Thread]