c_log.pl:
# add_traces.pl (C) Marko Kivij?rvi 2006
# Dummy checks
die "Specify an input file!\n" if $ARGV[0] eq "";
die "File not found!\n" unless -e $ARGV[0];
die "Incorrect file extension for a C/C++ file!\n"
if ( $ARGV[0] !~ /(.*)\.(c|cpp)$/ );
# Constants
#my $INC_TRACER_H = "#include \"tracer.h\"\n";
my $TRACER = "printLogFile";
# Parse output filename from the input filename
my $file = $ARGV[0];
#my $origFile = $1."-orig.".$2;
#system("cp $file $origFile" );
# Reset the input record separator (newline) so the entire file is read at once
undef $/;
# Read the input file
$_ = <>; # All there
# Adds a tracer macro after each function definition
s/
(\w+) # Possible function return type: int void ...
\s+
(\w+) # Function name
\s*? # Possible empty space
\( # Opening brace
([^)=->]*?) # Possible function parameters
\) # Closing brace
[^{!();#\\]*?
\{ # Opening curly brace
/
Parse($&,$1,$2,$3,$4) # Print the match and add the macro
/gxe; # g = repeat, x = split regex to multiple lines, e = evaluate substitution
open OUT, ">$file" or die "Cannot open file $file $!\n";
print OUT;
close OUT;
exit 0;
sub Parse {
my $match = shift;
my $ret = shift;
my $func = shift;
my $param = shift;
if ( $func eq "if" || $func eq "switch" || $func eq "while" || $ret eq 'if') {
return $match;
}
my $debug = $match."\n ";
$debug .= $TRACER."(\"";
$debug .= $func."\(".$param."\)";
$debug .= "\\n\");\n ";
return $debug;
}
-----------------------------------------------------
del comment:
sed -e 's*.*/*g' ui10engine.c | sed -e 's/.*//g' | sed -n '/./p'
------------------------------------------------
c_log_statment:
die "Specify an input file !\n" if $ARGV[0] eq "";
die "File not found!/n" unless -e $ARGV[0];
die "Incorrect file extension for a C/C++ file!\n"
if ( $ARGV[0] !~ /(.*)\.(c|cpp)$/);
#Constans
my $TRACER = "printlog";
#Parse output filename from the input filename
my $file = $ARGV[0];
#Reset the input record separator (newline) so the entire file is read at once
undef $/;
#Read the input file
$_ = <>; #All there
#Adds a tracer macro after each function definition
s/
(\w+) # Possible function return type: int void ...
\s+
(\w+) # Function name
\s*? # Possible empty space
\( # Opening brace
([^)=->]*?) # Possible function parameters
\) # Closing brcae
[^{!();#\\]*?
\{
\s*?
(\s*\w+\s*\w+\s*\[?\d*\]?,?=?\s*\w*\s*;\s*\n\s*)*
/
Parse($&,$1,$2,$3,$4,$5)
/gxe; # g = repeat, x = split regex to multiple lines, e = evaluate substitution
open OUT, ">$file" or die "Cannot open file $file $!\n";
print OUT;
close OUT;
exit 0;
sub Parse {
my $match = shift;
my $ret = shift;
my $func = shift;
my $param = shift;
my $statement = shift;
if ( $func eq "if" || $func eq "switch" || $func eq "while" || $ret eq "if" ) {
return $match;
}
my $debug = $match."\n ";
$debug .= $TRACER."(\"";
$debug .= $func."\\\(".$param."\\\ )";
$debug .= "\\n\");\n ";
return $debug;
}
-----------------------------------------------------------------
dc.l
lex 学习,清除c,c++注释
编译
lex dc.l
gcc -o dc dc.c -ll or gcc -o dc dc.c -lfl
代码
%{
#include <string.h>
%}
%s quotation_comment comment
%%
/"[ /t]*[^"] * {printf("%s",yytext); BEGIN (quotation_comment);}
/"[ /t]*///*[^"] * {printf("%s",yytext); BEGIN (quotation_comment);}
<quotation_comment>/" {printf("%s",yytext); BEGIN (INITIAL);}
.*$ {}
///* { BEGIN(comment) ; }
<comment>/*// { BEGIN(INITIAL); }
<comment>/n { }
<comment>. { }
%%
-------------------------------------
find . -name srce | xargs -i cp {} {}.bak