Chinaunix

标题: 如何检索程序中的函数? [打印本页]

作者: ljmmail    时间: 2011-05-23 23:21
标题: 如何检索程序中的函数?
本帖最后由 ljmmail 于 2011-05-23 23:43 编辑

程序中使用了大量的  sprintf() 函数, 现在希望通过脚本查询函数中程序使用情况, 得到如下的处理结果:
file.c: sprintf(buf, "%s, %s, %ld, %s\n", dqdh,  jgdh, SQLCODE, sqlca.sqlerrm);
主要是显示 sprintf() 到分号部分, 以便于对函数中使用的格式化串和变量做检查.
作者: xiaopan3322    时间: 2011-05-23 23:36
sprintf() 到冒号部分

哪里有冒号?

样本数据呢?
作者: Shell_HAT    时间: 2011-05-24 03:23
  1. grep "sprintf(.*);" *.c
复制代码

作者: ljmmail    时间: 2011-05-24 07:57
上面的 grep 命令不可以处理多行书写的 sprintf() 调用.
使用
sed  -n  '/sprintf/,/;/'p   *.c
可以得到需要的查询结果, 但是对于哪些单行书写的 sprintf() 就会多出一行数据.

sed  -n  '/sprintf/,/;/'p  pc9254.ec
                                                sprintf(sfda.bz, "扣费户清算金额错");
                                                goto  JFERROR;
                                        sprintf(sfda.bz, "收费组事务提交错");
                                        PCLog(TLEVEL,"[0432] %s %s!\n", sfbz2.qdzl, sfda.bz);
                sprintf(stErrInfo.szErrMsg,"[0737] 扣费入帐%d笔, 错误%d笔",nRzCnt,nBrzCnt);
        else
                strcpy(stErrInfo.szErrMsg,"[0739] 本日无批量扣费入帐!");
                sprintf(stErrInfo.szErrCmt,"[0773] 取账号(%s)信息错", zhdh);
                PCLog(TLEVEL," %s!\n", stErrInfo.szErrCmt);
                sprintf(stErrInfo.szErrCmt, "[0783] 获取 %s 账户科目错",  kmxx->kmdh);
                PCLog(TLEVEL," %s!\n", stErrInfo.szErrCmt);

其中 sprintf() 之外的语句就不是我需要的处理内容.
作者: yinyuemi    时间: 2011-05-24 08:17
本帖最后由 yinyuemi 于 2011-05-24 08:29 编辑

回复 4# ljmmail


    Try:
  1. awk -vRS="sprintf([^;]*);" '{print RT}'
复制代码

作者: ljmmail    时间: 2011-05-24 23:28
还是不行的, 没有看到后面的赋值变量
sprintf(selString, "select rowid  from  %s into temp  tmp_ghinst ;
sprintf(insString, "insert into %s  select * from %s a where a.rowid in "
                        "(select * from tmp_ghinst b where b.rowid >=%ld and b.rowid <%ld )  %s ;
sprintf(selString, "select rowid  from  %s where %s into temp tmp_pcldele ;
作者: yinyuemi    时间: 2011-05-24 23:43
回复 6# ljmmail


    那是因为你要的内容里包含;
再试试:
  1. awk -vRS="sprintf([^)]*);" '{print RT}'
复制代码

作者: ly5066113    时间: 2011-05-25 14:00
回复 4# ljmmail


改成 awk '/sprintf/,/;/' *.c
作者: ljmmail    时间: 2011-05-25 21:41
实验后, 发现可以使用
awk '/sprintf/,/);/'   *.c
将检索的结束标志设置为  );  这样就没有问题了.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2