C++博客-技术笔记——Beyond Programming-随笔分类-磨刀不误砍柴工http://www.cppblog.com/archiveman/category/13204.html欢迎喜欢技术的朋友来转转zh-cnSun, 20 Jun 2010 15:15:09 GMTSun, 20 Jun 2010 15:15:09 GMT60GNU C/C++简易编译支持脚本http://www.cppblog.com/archiveman/archive/2010/06/20/118291.htmlDavid FangDavid FangSun, 20 Jun 2010 03:50:00 GMThttp://www.cppblog.com/archiveman/archive/2010/06/20/118291.htmlhttp://www.cppblog.com/archiveman/comments/118291.htmlhttp://www.cppblog.com/archiveman/archive/2010/06/20/118291.html#Feedback0http://www.cppblog.com/archiveman/comments/commentRss/118291.htmlhttp://www.cppblog.com/archiveman/services/trackbacks/118291.html
#!/bin/sh
#comc.sh: script that helps programming 
in C/C++
#author:Don

sources
=`ls -*.c *.cpp *.cxx *.h 2>/dev/null`
lastsource
=`ls -*.c *.cpp *.cxx *.h 2>/dev/null | head -1`

command
=$0
executable
="${PWD##*/}"

case $command in
    
*r) ./"${executable}" </dev/tty >/dev/tty 2>&1 ;;
    
*vc) vim $lastsource ;;
    
*vac) vim $sources ;;
    
*c) gcc --O0 -o $executable $sources && echo "gcc compiled successfully";;
    
*cxx) g++ --O0 -o $executable $sources && echo "g++ compiled successfully";;
esac

放在任何目录下都可以:
然后添加连接到/usr/bin
ln /path/to/compile.sh  /usr/bin/r
ln 
/path/to/compile.sh  /usr/bin/vc
ln 
/path/to/compile.sh  /usr/bin/vac
ln 
/path/to/compile.sh  /usr/bin/c
ln 
/path/to/compile.sh  /usr/bin/cxx

这样写小程序时就能用下面的步骤了:
1.创建程序目录并切换到目录下
mkdir example && cd $_
2.创建源码文件
vim main.cpp
3.编辑代码,保存
4.编译,如果是cpp代码则运行cxx,如果是c代码则运行c,生成的二进制可执行文件名称是程序坐在目录名称。
5.要重新编辑最后一个源文件则运行vc命令,要重新编辑所有源文件则运行vac命令。
6.编译成功后,要运行时运行r命令。

上面是我参考Unix原理于应用上的一个例子写出来的,最近在搞一些算法方面的题目,用这个脚本做些算法题和简单的测试程序还是比较实用的,当然如果要开发大型的软件,特别是要依赖标准库以外的东西,还是要靠Makefile.


David Fang 2010-06-20 11:50 发表评论
]]>
Lua小程序:十六进制字符串和二进制数据间的转换http://www.cppblog.com/archiveman/archive/2010/03/30/111056.htmlDavid FangDavid FangTue, 30 Mar 2010 14:20:00 GMThttp://www.cppblog.com/archiveman/archive/2010/03/30/111056.htmlhttp://www.cppblog.com/archiveman/comments/111056.htmlhttp://www.cppblog.com/archiveman/archive/2010/03/30/111056.html#Feedback0http://www.cppblog.com/archiveman/comments/commentRss/111056.htmlhttp://www.cppblog.com/archiveman/services/trackbacks/111056.html主要是因为最近有这方面的需要(在搞一些 RSA加密的东西)。  阅读全文

David Fang 2010-03-30 22:20 发表评论
]]>
在内存中解压-实用gzip解压类封装http://www.cppblog.com/archiveman/archive/2010/03/05/108983.htmlDavid FangDavid FangFri, 05 Mar 2010 09:51:00 GMThttp://www.cppblog.com/archiveman/archive/2010/03/05/108983.htmlhttp://www.cppblog.com/archiveman/comments/108983.htmlhttp://www.cppblog.com/archiveman/archive/2010/03/05/108983.html#Feedback3http://www.cppblog.com/archiveman/comments/commentRss/108983.htmlhttp://www.cppblog.com/archiveman/services/trackbacks/108983.html阅读全文

David Fang 2010-03-05 17:51 发表评论
]]>
VI/VIM使用小技巧http://www.cppblog.com/archiveman/archive/2010/03/05/108970.htmlDavid FangDavid FangFri, 05 Mar 2010 07:31:00 GMThttp://www.cppblog.com/archiveman/archive/2010/03/05/108970.htmlhttp://www.cppblog.com/archiveman/comments/108970.htmlhttp://www.cppblog.com/archiveman/archive/2010/03/05/108970.html#Feedback0http://www.cppblog.com/archiveman/comments/commentRss/108970.htmlhttp://www.cppblog.com/archiveman/services/trackbacks/108970.html
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
注意单引号和双引号
2.在普通模式下输入Enter键时也能换行(不用切换到插入模式然后换行然后又切回普通模式这么麻烦的)
:nmap <Enter> i<Enter><ESC>

:nmap <CR> i<Enter><ESC>

:nmap <Enter> ylpr<Enter>



David Fang 2010-03-05 15:31 发表评论
]]>