Re: debug statements to debugs statements

2007-04-28 Thread Henrik Nordstrom
lör 2007-04-28 klockan 00:14 +0300 skrev Tsantilas Christos:
 Here is the patch which converts the debug statements to debugs statements:
 http://www.chtsanti.net/others/CONVER_DEBUGS.diff
 It is not excellent but it is not so bad...

Applied with a bit of whitespace cleanup

 - Less aggressive folding of lines

 - Indent fixes little here and there. Maninly after if, or in switch
statemetnts.

Regards
Henrik


signature.asc
Description: Detta är en digitalt signerad	meddelandedel


Re: debug statements to debugs statements

2007-04-27 Thread Tsantilas Christos
Here is the patch which converts the debug statements to debugs statements:
http://www.chtsanti.net/others/CONVER_DEBUGS.diff
It is not excellent but it is not so bad...

Regards,
 Christos



Re: debug statements to debugs statements

2007-04-22 Thread Tsantilas Christos
I do a first conversion from debug statements to debugs statements.
The patch is big (~750K) to post it to mailing list so I put the result
here:
http://www.chtsanti.net/others/CONVER_DEBUGS.diff
I hope that it is something needed for squid3 because the conversion
takes a lot of my time (specially when you have to merge with many
changes in main squid3 head)..

My Comments:
1) Should I create a temporary branch? If squid developers decide that
this work needed, will be easier the merging with Duane works for large
objects and the merging with main squid code.

2)  I did not format the result. I try to run the astyle
(version:1.20.2) and it changed too many things in code. Moreover the
formated code I took as result in some cases was really bad
   Which version of the astyle used in squid3?

3) I did not convert the debugs statements which have formating strings
with field width or precision modifiers. The reason is that I am not so
sure that the result will be really better. For example a printf
statement like the following:
 printf(Float:%.2f, Hex Integer:%x  Dec Integer: %05d \n\n,2.345,
13,13);

using iostreams can be written as:
 cout   Float: 
  setprecision(3)  2.345 
   ,Hex Integer: 
  hex  13  dec 
   Dec Integer:  
  setw(5)  setfill('0')  13  endl;

  Moreover a cout  resetiosflags (..)  must be included in debugs
statement to avoid a debugs statement change the look of consequently
debugs.
Of course in the other hand, you have not to check if we have float or
double or integer or long long integer.
Are conversions like the above OK?


4) I was not able to use ios manipulators like hex/dec or endl inside
some files eg wccp2.cc file. The compiler (g++ 4.1.2) always return the
following message:
  wccp2.cc:1455: error: ‘hex’ was not declared in this scope

I try to include iostream and iomanim inside this file but the result
was the same. The strange is that happens only in some of the c++ files
not in all of them.
Any idea?

Regards,
Christos



Re: debug statements to debugs statements

2007-04-22 Thread Adrian Chadd
On Sun, Apr 22, 2007, Tsantilas Christos wrote:
 Adrian Chadd wrote:
  
  There's now an implied \n (ie, eol) in the debug path; your patch has
  \n's in there.
  
 
 Oops! I really did not see it (@#$%^[EMAIL PROTECTED]@#)! I will try to 
 remove
 it.. But I think It will take me some years :-( .

Erk!



Adrian



Re: debug statements to debugs statements

2007-04-22 Thread Tsantilas Christos
OK, It takes something less than a year...
The patch at:
 http://www.chtsanti.net/others/CONVER_DEBUGS.diff
does not contains \n any more. I hope that it is OK now

Please try to do not find any such error ... in Sunday... you can find
it on Monday morning  :-) !

Regards,
 Christos

 Adrian Chadd wrote:
 
 There's now an implied \n (ie, eol) in the debug path; your patch has
 \n's in there.

 
 Oops! I really did not see it (@#$%^[EMAIL PROTECTED]@#)! I will try to 
 remove
 it.. But I think It will take me some years :-( .
 
 
 



debug statements to debugs statements

2007-04-18 Thread Tsantilas Christos

Hi all,
  Here is a perl script which can be used to convert debug statements 
to new debugs statements :-) .

It mostly works or just  do standard errors.
It does not formats the output. I think the astyle can do the rest work.
Does not convert the debug statements, if the format string contains 
formating flags like %2.1f.


I think can be used as reference for other related convertions too.

Should I proceed with the convertion?
Should I post a patch to bugzila  or open a temporary branch on 
sourceforge better?


Regards,
Christos


#!/usr/bin/perl

#
# Author: Tsantilas Christos
# email:  [EMAIL PROTECTED]
#
#

use File::Copy;



$in=$ARGV[0];
$out=$in.converted;
print $in,$out;
copy($in, $in.original);

if(!open(IN,$in)){
print Can't open input file: $in\n;
exit -1;
}


if(!open(OUT,$out)){
print Can't open output file: $out\n;
exit -1;
}

my $i = 0;
my $line,$mod_statement;
my $t;


while(IN){
$line=$_;
if ( $line =~ /( |\t)debug\((\d*),( )*(\d*)\)/ ) {
	$i=0;
	while($line !~ /\);/){

	if (! ($t=IN) ){
		exit(-1);
	}

	$i=$i+1;
	if($i10){
		# More than 10 lines to a single debug statement?
		# something goes wrong in parsing
		exit(-1);
	}
	$line=$line.$t;
	}
	print Found a debug line : $line  \n;
	$mod_statement=process_debug_command($line);
	if($mod_statement){
	print Converted to line: $mod_statement \n;
	print OUT $mod_statement;
	}
	else{
print Not modified\n;
	print OUT $line;
}
	print -\n\n;
}
else{
	print OUT $line;
}
}

close(IN);
close(OUT);

# Here we believe that we correctly do any convertion so copy new file
# to the original 

copy($in.converted, $in);
exit(0);


sub process_debug_command{
my($line)[EMAIL PROTECTED];
my $dsec,$dlevel,$format,$args,$arg,$val;
my @array_args;

# Handle multilined strings
$line =~ s/\( |\n|\t)*\//g;

#remove newlines
$line =~ s/\n//g;

#print This is the line:$line\n;

#read debug section and level and debug arguments. 
$line =~ /debug\((\d*),( )*(\d*)\)( )*\((.*)\)\;/sm;
$dsec=$1; 
$dlevel=$3;
$args=$5;




if($args =~ /\(.*)\,(.*)/sm){
	$format=$1;
	$args=$2;
}
elsif($args =~ /\(.*)\$/sm){
	$format=$1;
	$args=;
}
else{
	return '';
}
#print Format str:,$format,\n,Args:,$args,\n;



@array_args = split(/,/ , $args );

#print debugs($dsec, $dlevel, $format;
#foreach $arg (@array_args){
#	$val=~ s/^(( |\n|\t)*)//;
#	chomp($val);

#	print , $arg;
#}
#print );\n;


$arg=shift(@array_args);
$arg=~ s/^(( |\n|\t)*)//;
chomp($arg);
# we understand the following %x formats
while( $format =~ s/%(s|lu|ld|d|u|p|x)/  $arg  / ){
	if(!$arg){
	return '';
	}
	$arg=shift(@array_args);
	$arg=~ s/^(( |\n|\t)*)//;
	chomp($arg);
}
if($arg){
 print ERROR remain arg:$arg\n;
 return '';
}
$format=debugs($dsec, $dlevel, \$format\ );\n;
#print debugs($dsec, $dlevel, \$format\ );\n;

return $format;
}


Re: debug statements to debugs statements

2007-04-18 Thread Adrian Chadd
On Wed, Apr 18, 2007, Tsantilas Christos wrote:
 Hi all,
   Here is a perl script which can be used to convert debug statements 
 to new debugs statements :-) .
 It mostly works or just  do standard errors.
 It does not formats the output. I think the astyle can do the rest work.
 Does not convert the debug statements, if the format string contains 
 formating flags like %2.1f.
 
 I think can be used as reference for other related convertions too.
 
 Should I proceed with the convertion?
 Should I post a patch to bugzila  or open a temporary branch on 
 sourceforge better?

I'm going to be slightly greedy/annoying here and say:

* Yes please! Because
* It cuts down on the amount of work required when migrating the codebase
  from C strings (and the C-string-like String type that Squid-3 is currently
  using) as there's a lot of places where C strings are debug'ed and I wasn't
  looking forward to converting them all to %*.s or similar (which allows you
  to pass an int length specifier before a buffer, a pre-requisite for
  logging strings when your strings suddenly aren't NUL-terminated!), but
* I'd just start submitting diffs against Squid-3-HEAD and include whatever can
  be done into the current codebase; this is something that can be done
  very incrementally and shouldn't have any actual operational impact, and
* It makes my next set of work easier (ie, starting to get rid of the C strings
  in Squid-3 and replacing them with String as a temporary stepping stone
  towards refcounted buffers.)

2c,




Adrian



Re: debug statements to debugs statements

2007-04-18 Thread Alex Rousskov
On Wed, 2007-04-18 at 11:30 +0300, Tsantilas Christos wrote:

Here is a perl script which can be used to convert debug statements 
 to new debugs statements :-) .
 It mostly works or just  do standard errors.
 It does not formats the output. I think the astyle can do the rest work.
 Does not convert the debug statements, if the format string contains 
 formating flags like %2.1f.

If you get a chance, please modify the script debugging/logging to use
one line for both the conversion status and the debug statement:

Found: $line\n
Converted: $mod_statement\n
LeftAsIs:  $line\n

This way it is much easier to grep/see debug statements that were _not_
converted, for example.


A few minor suggestions, if I may:

You may want to replace \d* in a line format with \w+ because the
arguments are required and sometimes contain variable names rather than
constants.

You may want to replace space and tab characters in the format with \s.

If you are not using a matched string, no need to use parens. For
example, this may work:
  if ( $line =~ /\sdebug\(\s*\w+\s*,\s*\w+\s*\)/ ) 


Thank you,

Alex.




Re: debug statements to debugs statements

2007-04-18 Thread Tsantilas Christos
Thanks Alex,
  Also I handled some other minor cases and run it in my sources.

Some statistics:
 grep -n Converted CONVERT.log  |wc -l  - 2316
 grep -n LeftAsIs CONVERT.log  |wc -l  - 137

Only 5-6  cases needed some work by me. Now compiles and the debug info
I am getting looks OK.
I will continue testing the results and when I am ready I am going to
post the patch.

Regards,
Christos

Alex Rousskov wrote:
.
 
 If you get a chance, please modify the script debugging/logging to use
 one line for both the conversion status and the debug statement:
 
.
 
 A few minor suggestions, if I may: