新人求修改.c 函数注释头思路 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dimingxuan
V2EX    Python

新人求修改.c 函数注释头思路

  •  
  •   dimingxuan 2015-07-02 14:52:58 +08:00 via iPad 3381 次点击
    这是一个创建于 3828 天前的主题,其中的信息可能已经有所发展或是发生改变。
    现在有大量的.c文件需要批量修改函数头,类似的格式为
    /* xxxxxxxx
    xxxxxxxxx
    xxxxxxxx
    @warning xxxxxx
    */
    Xxxx 函数名(xxxxx)
    {
    Xxxxxxxx
    }

    函数头中可能包含/* xxx */,@warning也不一定存在。想在函数头末尾添加类似 @html_文件名_函数名 这样的字段。新人刚学python,想用正则,但貌似正则无法支持 /* */的嵌套,搜到网上有人说用pyparsing可以实现,getting started文档比较简单,没看明白怎么使用。ide里面都能区分注释和函数名,所以想请教一下这个问题的处理思路和方法,是否有现成的方式
    9 条回复    2015-07-03 12:14:28 +08:00
    leavic
        1
    leavic  
       2015-07-02 16:00:55 +08:00   1
    不是很清楚你所谓的函数头是哪里,给个具体的修改例子看看。
    lilydjwg
        2
    lilydjwg  
       2015-07-02 16:10:42 +08:00   1
    这个正则引擎 https://pypi.python.org/pypi/regex 支持嵌套,不过我不觉得用它比 pyparsing 更简单。
    dimingxuan
        3
    dimingxuan  
    OP
       2015-07-02 16:32:54 +08:00 via iPad
    @leavic
    大概每个c文件里都是这样的
    /*
    * @fn fun_add
    * @brief xxx
    .......
    * @warning xx
    */
    int fun_add()
    {
    .....
    }
    函数头都是在函数定义上方,每个c文件里都包含许多函数。
    现在需要改成

    /*
    * @fn fun_add
    * @brief xxx
    .......
    * @warning xx
    @html_文件名_fun_add
    */
    int fun_add()
    {
    .....
    }
    dimingxuan
        4
    dimingxuan  
    OP
       2015-07-02 16:37:03 +08:00 via iPad
    @lilydjwg 您的意思是用pyparsing解决问题?
    lilydjwg
        5
    lilydjwg  
       2015-07-02 17:25:18 +08:00
    @dimingxuan 嗯。pyparsing 比起正则来好学多了~
    mhycy
        6
    mhycy  
       2015-07-02 17:29:41 +08:00   1
    目测意思就是: 解析注释,并在注释中插入文档地址
    /* */会产生嵌套么?记忆中如果有嵌套的话C的编译器是不能正常处理的
    leavic
        7
    leavic  
       2015-07-02 20:07:41 +08:00   1
    这,一行行读进来,读到“*/ ”不就是注释的结尾了?再往前面插入一行没什么难度吧。
    asxalex
        8
    asxalex  
       2015-07-03 09:55:06 +08:00   1
    for i in *.c
    do
    awk '{
    if ($2 == "@warning")
    {print $0 "\n" " @html_'$i'_" func_name}
    else if ($2 == "@fn")
    {func_name = $3}
    else
    {print}
    }' $i
    done
    dimingxuan
        9
    dimingxuan  
    OP
       2015-07-03 12:14:28 +08:00 via iPad
    @asxalex 多谢
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3992 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 05:23 PVG 13:23 LAX 21:23 JFK 00:23
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86