* [lm-sensors] yani-script
@ 2005-07-26 16:03 Jim Cromie
2005-07-26 16:35 ` [lm-sensors] yani-script Yani Ioannou
0 siblings, 1 reply; 2+ messages in thread
From: Jim Cromie @ 2005-07-26 16:03 UTC (permalink / raw)
To: lm-sensors
back in May, Yani wrote a perl script that did a massive code conversion.
In order to understand the regexs in it, I reformatted one of them
to use perls x regex modifier, which allows regex code to be
reformatted for readability. Then I added comments to the regex.
here it is, in hopes it will be useful.
-------------- next part --------------
#!/usr/bin/perl
=head1 SYNOPSIS
this script adds a void* pointer to many calls in linux
source, specifically those that are sysfs callbacks.
For example:
559c567
< static ssize_t show_temp##offset##_crit(struct device *dev, char *buf) \
---
> static ssize_t show_temp##offset##_crit(struct device *dev, char *buf, void *sdata) \
564c572
< static ssize_t show_temp##offset##_status(struct device *dev, char *buf) \
---
> static ssize_t show_temp##offset##_status(struct device *dev, char *buf, void *sdata) \
its used like this:
#!/bin/sh
find linux-2.6.12-rc4-sysfsdyncallback-autoupdate -type f -exec
./updatedyncallback.pl {} \; 2>&1 |tee subs.log
It is, in essence, a -pi.bak script, but obviously not a 1-liner.
=cut
use strict;
my $infile=shift;
if(!defined $infile){
open(IN,"<&STDIN") or die "Could not open an input stream";
} else {
open(IN,"<$infile") or die "Could not open an input stream";
}
my $subs = 0;
my $code = "";
while(<IN>){$code.=$_};
close(IN);
$code =~ s{
( # capture the 'whole' function signature
static # must be static
[\s\\]+? # whitespace, inc \ line-ends
ssize_t # sysfs callback return-type
[\s\\]+?
[^(;]+? # accept chars upto '(' or ';'
# parameter list, with a struct <foo> as 1st arg
\( \s*?struct
[\s\\]+? # allowing whitespace
# where <foo> is one of:
(?:device|device_driver|subsystem|
gendisk|module_attribute|sysdev_attribute|
class|class_device|bus_type|
cpufreq_policy|subsystem|sys_device)
[\s\\]*?
\*[^,);]*?,
[\s\\]*?
char[\s\\]*?
\*[^,);]*?
) # end of capture
[\s\\]*?\) # match literal ) closing the parmlist
}
<$1, void *sdata)>gsx && $subs++;
$code =~ s/(static[\s\\]+?ssize_t[\s\\]+?[^(;]+?\(\s*?struct[\s\\]+?(?:device|device_driver|subsystem|gendisk|module_attribute|sysdev_attribute|class|class_device|bus_type|cpufreq_policy|subsystem|sys_device)[\s\\]*?\*[^,);]*?,[\s\\]*?const[\s\\]+?char[\s\\]*?\*[^,);]*?[\s\\]*?,[\s\\]*size_t[^,);]*?)[\s\\]*\)/$1,
void *sdata)/gs && $subs++;
if($subs){
if(!defined $infile){
open(OUT,">&STDOUT") or die "Could not open an output stream";
}else{
open(OUT,">$infile") or die "Could not open an output stream";
}
$|;
print OUT $code;
close(OUT);
$infile && print STDOUT "$infile updated.\n";
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [lm-sensors] Re: yani-script
2005-07-26 16:03 [lm-sensors] yani-script Jim Cromie
@ 2005-07-26 16:35 ` Yani Ioannou
0 siblings, 0 replies; 2+ messages in thread
From: Yani Ioannou @ 2005-07-26 16:35 UTC (permalink / raw)
To: lm-sensors
Hi Jim,
There are a few newer (and fixed/updated in some manner or another)
scripts in the lkml/lm-sensors archives you might want to look at,
they are essentially the same idea, but the last revision worked with
some other rare cases and added a device_attribute parameter rather
than a void * as the second argument to the callbacks.
On 7/26/05, Jim Cromie <jcromie@divsol.com> wrote:
> In order to understand the regexs in it, I reformatted one of them
> to use perls x regex modifier, which allows regex code to be
> reformatted for readability. Then I added comments to the regex.
>
> here it is, in hopes it will be useful.
This looks useful, my only complaint is that I think you used an older
revision than the one that actually did the massive code change that
was accepted into the mainline kernel. I do at some point intend on
changing the other sysfs attribute callbacks, so its useful for myself
even to have a well documented script to look back at in a few months
:-).
Thanks,
Yani
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-07-26 16:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-26 16:03 [lm-sensors] yani-script Jim Cromie
2005-07-26 16:35 ` [lm-sensors] yani-script Yani Ioannou
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.