some scripte.add log in each function perl

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值