On Thu, 27 Mar 2008, Garth Dahlstrom wrote:

> I'm also in awe of your mad perl skillz...   I think your script belongs on
> the wiki... other projects may someday need its services...

<blush> thanks, I'm (actually) glad it was useful. Now THAT
tool-making stuff I can do. c++, no so much.

Those deprecated c++ method thingies (QT-something.tolower,
etc), many of those are amenable to mechanical solution, with
a few correct examples I can whack some of those dead maybe.

I should not have posted that script, it's bad. I'll include the
final one here (mess upon mess). It got all but 20 or so which
I did manually, a few oddly-formed calls (no format string;
line continuations). Final one is shorter too (a good omen).

The trick was to do it in two passes. First, as it transformed
the old qDebug() lines to the proposed final, it output "foox()
<< ..." instead of "qDebug() << ...". That way, I could (1)
egrep for the transformed lines looking for well-formed-ness
and (2) egrep for qDebug lines it missed. When the ratio good
vs. bad was tolerable I got fresh sources, made it output the
real function name, did manual fixes, checked it and shipped it.

invoked via

        ./fixqDebug [ -v -n ] *.cpp



#!/usr/bin/perl -w

# Fix all the qDebug()s

use Getopt::Std;
use vars qw/$opt_n $opt_v/;

        getopts ('nv');

        foreach (@ARGV) {
                print "File: $_\n" if $opt_v;
                &process ($_);
        }


# Process each input file.
#
sub process {
my $fn= shift;

my $ofn= "$fn.temp";
my $needwrite= 0;

        open (I, "<$fn") or die ("Can't read $fn?!");
        open (O, ">$ofn") or die ("Can't create temp file $ofn!");

        while (<I>) {
                # Match one of these, sets $fmt, $argstring accordingly.
                #                   qDebug   ("format", arg1, arg2);      (with 
arg(s))
                #                   qDebug   ("foox");                     (no 
args)
                #                   qDebug   (arg1);                    (fails 
on these)
                my ($indent, $fmt, $argstring, $outdent)= 
/(.+)qDebug\s*\(\s*"(.+)"\s*,\s*(.*)\s*\);(.*)/;
                if (not defined $fmt) {
                        $argstring= "";                                 # will 
be no args,
                        ($indent, $fmt, $outdent)=        
/(.+)qDebug\s*\(\s*"(.+)"\s*\);(.*)/;
                }
                if (not $fmt) {                                         # no 
match? copy to output
                        print O $_;
                        next;
                }

# Found target string.

                ++$needwrite;
                my $was= $_;                                            # for 
output later

# Now interpret the format string, and whenever we find %format, output the 
format
# string up to that point, then the first argument in the list.

                my (@F)= split (/\%[-\.\d]*[A-Za-z]/, $fmt);            # %s 
%-2d %-4.2e
                my (@A)= split (/\s*,\s*/, $argstring);                 # list 
of args

                my $out= "${indent}qDebug()";
                foreach (@F) {
                        $out .= " << " . "\"$_\"";
                        if (scalar @A) { $out.= " << " . shift @A; }
                }
                $out .= ";$outdent\n";
                print "!was $was$indent$out$outdent" if $opt_v;
                print O "$out";
        }
        close I;
        close O;
        if (!$opt_n && $needwrite) {
                `mv $fn $fn.orig`;
                `mv $ofn $fn`;
        } else {
                `rm $ofn`;
        }
}

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to