Chinaunix首页 | 论坛 | 博客
  • 博客访问: 158787
  • 博文数量: 25
  • 博客积分: 1222
  • 博客等级: 中尉
  • 技术积分: 322
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-27 10:18
文章分类
文章存档

2011年(7)

2010年(9)

2009年(9)

我的朋友

分类: LINUX

2010-02-06 23:06:34

参考了别人的文章,记录下有用的代码。
macro SingleLineComment()
{
 hbuf = GetCurrentBuf()
 hwnd = GetCurrentWnd();
 lnFirst = GetWndSelLnFirst(hwnd)
 lnLast = GetWndSelLnLast(hwnd)
 while(lnFirst < lnLast+1)
 {
  tmpBuf = GetBufLine(hbuf,lnFirst)
  if(tmpBuf != Nil)
  {
   commentBuf = cat("//",tmpBuf)
   DelBufLine(hbuf,lnFirst)
   InsBufLine(hbuf,lnFirst,commentBuf)
  }
  lnFirst = lnFirst + 1
 }
 
}
macro strstr(src,dst)
{
 dstLen = strlen(dst)
 srcLen = strlen(src)
 loop = 0
 index = 0
 while(loop < dstLen)
 {
  if(dst[loop] == src[loop])
  {
   index = index +1
   loop = loop + 1
  }
  else
  {
   index = index + 1
   loop = 0
   if((index + dstLen) > srcLen)
   {
    return invalid
   }
  }
 }
 index = index - dstLen
 return index
}
macro SingleLine_UnComment()
{
 hbuf = GetCurrentBuf()
 hwnd = GetCurrentWnd();
 lnFirst = GetWndSelLnFirst(hwnd)
 lnLast = GetWndSelLnLast(hwnd)
 
 while(lnFirst < lnLast+1)
 {
  tmpBuf = GetBufLine(hbuf,lnFirst)
  if(tmpBuf != Nil)
  {
   index = strstr(tmpBuf,"//")
   if(index != invalid)
   {
    index = index + 2
    unCommentBuf = strmid(tmpBuf,index,strlen(tmpBuf))
    DelBufLine(hbuf,lnFirst)
    InsBufLine(hbuf,lnFirst,unCommentBuf)
   }
  }
  lnFirst = lnFirst + 1
 }
}
阅读(1880) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~