format 代码

 

 

#!/bin/bash
#file format.sh
#将某个源代码文件中的全角符号转换成半角符号
#调用astyle 将某个源代码文件转换成linux风格,缩进方式为4个空格

echo $1
#将全角空格转换成半角空格
sed -i 's/ / /' $1
sed -i y/abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,'“"‘’”;#/abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,\'\"\"\'\'\"\;#/ $1
astyle --style=linux --indent=spaces=4 $1

 

 

[root@test3 3]# /usr/local/bin/format.sh /home/yzn/code/3/test3_2.c
-bash: /usr/local/bin/format.sh: /bin/bash^M: bad interpreter: 没有那个文件或目录
[root@test3 3]# dos2unix /usr/local/bin/format.sh
dos2unix: converting file /usr/local/bin/format.sh to UNIX format ...

 

astyle 下载

http://sourceforge.net/projects/astyle/postdownload?source=dlp

astyle 安装

[root@test3 gcc]# make -f Makefile
g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/astyle_main.o ../../src/astyle_main.cpp
g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASBeautifier.o ../../src/ASBeautifier.cpp
../../src/ASBeautifier.cpp: In copy constructor ‘astyle::ASBeautifier::ASBeautifier(const astyle::ASBeautifier&)’:
../../src/ASBeautifier.cpp:104: 警告:基类 ‘class astyle::ASResource’ 应该在复制构造函数中显式地初始化
g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASFormatter.o ../../src/ASFormatter.cpp
../../src/ASFormatter.cpp: In member function ‘bool astyle::ASFormatter::isArrayOperator() const’:
../../src/ASFormatter.cpp:6392: 警告:将 NULL 转换到非指针类型 ‘bool’
../../src/ASFormatter.cpp:6395: 警告:将 NULL 转换到非指针类型 ‘bool’
g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASEnhancer.o ../../src/ASEnhancer.cpp
g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASLocalizer.o ../../src/ASLocalizer.cpp
g++ -DNDEBUG -O3 -W -Wall -fno-rtti -fno-exceptions -c -o obj/ASResource.o ../../src/ASResource.cpp
g++ -s -o bin/astyle obj/astyle_main.o obj/ASBeautifier.o obj/ASFormatter.o obj/ASEnhancer.o obj/ASLocalizer.o obj/ASResource.o

[root@test3 gcc]# ls
bin Makefile obj
[root@test3 gcc]# ls astyle
ls: astyle: 没有那个文件或目录
[root@test3 gcc]# which astyle
/usr/bin/which: no astyle in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

 

Astyle使用教程

http://www.cppblog.com/jokes000/articles/158838.html

posted @ 2013-11-13 20:00  羽化成蝶  阅读(423)  评论(0编辑  收藏  举报