为kdevelop增加中文标示符支持功能, 以3.5.4为例

[ 2012-05-19 20:22:25 | 作者: Admin ]
: | |
//----------------------------------将Kate文档的Unicode代码转换成 UTF-8--------------------------------------------------
1.将读取到的文件内容转换成Locale位编码
    a)修改  languages/cpp/backgroundparser.cpp 的函数KDevSourceProvider::contents
        将contents = QString( editIface->text().ascii() );

        改为 QTextCodec *codec=QTextCodec::codecForName("UTF-8");//((KateDocument*)doc)->config()->codec();//add by mark den
QTextEncoder *encode=codec->makeEncoder();//add by mark den
int length=editIface->text().length();
contents=encode->fromUnicode(editIface->text(),length);//add by mark den
       在contents = stream.read();语句后面增加
QTextCodec *codec=QTextCodec::codecForName("UTF-8");
QTextEncoder *encode=codec->makeEncoder();
int length=contents.length();
contents=encode->fromUnicode(contents,length);
    b)修改lib/cppparser/driver.cpp 的DefaultSourceProvider::contents 函数
        在source = s.read();语句后面增加
QTextCodec *codec=QTextCodec::codecForName("UTF-8");//add by mark den
QTextEncoder *encode=codec->makeEncoder();//add by mark den
        int len=source.length();
        source=encode->fromUnicode(source,len);

  编译并安装 languages/cpp/,lib/cppparser/所有插件

//----------------------------------使类向导在语法上支持中文标识符-------------------------------------------------------------
2.修改lib/cppparser/lexer.cpp 的 Lexer::nextToken函数
     将 else if( ch.isLetter() || ch == '_') 修改成
     else if( ch.isLetter() || ch == '_'||(unsigned char)((char)ch) >= (char)0x80 && (unsigned char)((char)ch) <= (char)0xff)//mark den
3.防止中文CPP文件不能正常打开,修改lib/cppparser/lexer.cpp
    修改244行,while( !currentChar().isNull() && currentChar() != '\n' )
    499行if( currentChar().isNull() )
4. 修改lib/cppparser/lexer.cpp的 Lexer::tokenize函数
                 将 if( currentChar().isNull() )
                          break
改为 if( currentChar() )
continue;
break;
                  编译后复制文件
                  cp lib/cppparser/.libs/libkdevcppparser.so.0.0.0 /usr/local/lib64/
5.  修改lib/cppparser/lexer.h 的 inline readIdentifier函数
  将 while( currentChar().isLetterOrNumber() || currentChar() == '_' )
  改为 while( currentChar().isLetterOrNumber() || currentChar() == '_' ||(unsigned char)((char)currentChar()) >= (char)0x80 && (unsigned char)((char)currentChar()) <= (char)0xff )
  编译并安装lib/cppparser/kdevcppparser.so
//--------------------------------左边显示中文类名----------------------------------------------------
6. parts/classview/classviewwidget.cpp
  添加
    #define SAVE_CODEC "UTF-8"
  修改几个函数函数,
                      NamespaceDomBrowserItem::setup,ClassDomBrowserItem::setup,TypeAliasDomBrowserItem::setup
                      VariableDomBrowserItem::setup,FunctionDomBrowserItem::setup,FolderBrowserItem::setup
  将
      setText( 0, txt );
  改为
QTextCodec* codec=QTextCodec::codecForName(SAVE_CODEC);//add by mark den
QTextDecoder *decode=codec->makeDecoder();//add by mark den
int length=txt.length();//add by mark den
QString displayName=decode->toUnicode( txt.ascii(),length );//add by mark den
// printf("%s(%d)%s:decode->toUnicode %s\n",__FILE__,__LINE__,__FUNCTION__,txt.ascii());
setText( 0, displayName );//modify by mark den
//------------------------------上部下拉框显示中文函数名------------------------------------------------------
7.  修改 parts/classview/navigator.cpp的  void Navigator::refreshNavBars(const QString &activeFileName, bool clear) 函数
  修改2处
      item->setItem( 0, fullFunctionItem( *it ) )
  改为
QString txt=fullFunctionItem( *it ) ;
QTextCodec* codec=QTextCodec::codecForName(SAVE_CODEC);//add by mark den
QTextDecoder *decode=codec->makeDecoder();//add by mark den
int length=txt.length();//add by mark den
QString displayName=decode->toUnicode( txt.ascii(),length );//add by mark den
// printf("%s(%d)%s:decode->toUnicode %s\n",__FILE__,__LINE__,__FUNCTION__,txt.ascii());
item->setItem( 0, displayName );
//------------------------------上部下拉转跳到函数所的行------------------------------------------------------
8.修改 parts/classview/navigator.cpp
  将
          CodeModelUtils::findFunctionDefinitions(NavOp(this,nav->text(0)), files, deflist);
  修改为
QString txt=nav->text(0);
QTextCodec *codec=QTextCodec::codecForName(SAVE_CODEC);////add by mark den
QTextEncoder *encode=codec->makeEncoder();//add by mark den
int length=txt.length();
QString funcName=encode->fromUnicode(txt,length);//add by mark den

CodeModelUtils::findFunctionDefinitions(NavOp(this,funcName), files, deflist);
  将
          CodeModelUtils::findFunctionDeclarations(NavOp(this, nav->text(0)), files, declist);
  修改为
QString txt=nav->text(0);
QTextCodec *codec=QTextCodec::codecForName(SAVE_CODEC);////add by mark den
QTextEncoder *encode=codec->makeEncoder();//add by mark den
int length=txt.length();
QString funcName=encode->fromUnicode(txt,length);//add by mark den

CodeModelUtils::findFunctionDeclarations(NavOp(this,funcName), files, declist);
  编译并安装 part/ 所有插件
//-----------------------------使类向导能显示全局的函数定义-------------------------------------------------------
9.parts/classview/classviewwidget.h
    在类FunctionDomBrowserItem中添加函数
FunctionDomBrowserItem( QListViewItem* parent, FunctionDefinitionDom dom ) : ClassViewItem( parent, dom->name() ), m_dom( dom ) {}//add by den
在类 FolderBrowserItem 中添加函数和变量
QMap<FunctionDefinitionDom, FunctionDomBrowserItem*> m_functions_definition;
        void processFunctionDefinition( FunctionDefinitionDom fun, bool remove=false );//add by mark den
10.parts/classview/classviewwidget.cpp
    修改函数 FolderBrowserItem::processFile
        删除
          for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it ){
   processFunction( *it, remove );
}
      增加
FunctionDefinitionList functionDefinitionList = file->functionDefinitionList();
for( FunctionDefinitionList::Iterator it=functionDefinitionList.begin(); it!=functionDefinitionList.end(); ++it ){
   processFunctionDefinition( *it, remove );//it is a FunctionDefinitionDom
}

    添加函数定义
                void FolderBrowserItem::processFunctionDefinition( FunctionDefinitionDom fun, bool remove ){
                       QStringList scope = fun->scope();
                       QString funName = scope.join(".");
                       if (!funName.isEmpty())
                       return;

                       FunctionDomBrowserItem* item = m_functions_definition.contains( fun ) ? m_functions_definition[ fun ] : 0;
                       if( !item ){
                        if( remove )
                         return;

                        item = new FunctionDomBrowserItem( this, fun );
                        m_functions_definition.insert( fun, item );
                       }

                       if( remove ){
                        m_functions_definition.remove( fun );
                        delete( item );
                        item = 0;
                       }
                  }
//-----------------------------使类向导能显示namespace函数定义-------------------------------------------------------
11.parts/classview/classviewwidget.h
//    在类FunctionDomBrowserItem中添加函数
// FunctionDomBrowserItem( QListViewItem* parent, FunctionDefinitionDom dom ) : ClassViewItem( parent, dom->name() ), m_dom( dom ) {}//add by den
在类 NamespaceDomBrowserItem 中添加函数和变量
QMap<FunctionDefinitionDom, FunctionDomBrowserItem*> m_functions_definition;
        void processFunctionDefinition( FunctionDefinitionDom fun, bool remove=false );//add by mark den
12.parts/classview/classviewwidget.cpp
    修改函数FolderBrowserItem::processNamespace
        删除
          for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it ){
   item->processFunction( *it, remove );
}
      增加
FunctionDefinitionList functionDefinitionList = ns->functionDefinitionList();
for( FunctionDefinitionList::Iterator it=functionDefinitionList.begin(); it!=functionDefinitionList.end(); ++it ){
   item->processFunctionDefinition( *it, remove );//it is a FunctionDefinitionDom
}
13.parts/classview/classviewwidget.cpp
    修改函数NamespaceDomBrowserItem::processNamespace
        删除
          for( FunctionList::Iterator it=functionList.begin(); it!=functionList.end(); ++it ){
   item->processFunction( *it, remove );
}
      增加
FunctionDefinitionList functionDefinitionList = ns->functionDefinitionList();
for( FunctionDefinitionList::Iterator it=functionDefinitionList.begin(); it!=functionDefinitionList.end(); ++it ){
   item->processFunctionDefinition( *it, remove );//it is a FunctionDefinitionDom
}
14.  parts/classview/classviewwidget.cpp  添加函数定义
            void NamespaceDomBrowserItem::processFunctionDefinition( FunctionDefinitionDom fun, bool remove ){
             QString funName = fun->scope().join(".");
             QString domName = dom()->scope().join(".");
             if(domName!="")
             domName+="."+dom()->name();
             else
             domName=dom()->name();
//             printf("funName=%s,domName=%s\n",funName.ascii(),domName.ascii());
             if (funName!=domName)
             return;

             FunctionDomBrowserItem* item = m_functions_definition.contains( fun ) ? m_functions_definition[ fun ] : 0;
             if( !item ){
             if( remove )
             return;

             item = new FunctionDomBrowserItem( this, fun );
             m_functions_definition.insert( fun, item );
             }

             if( remove ){
             m_functions_definition.remove( fun );
             delete( item );
             item = 0;
             }
            }

15.编译报错是的中文标示符显示
  在parts/outputviews/makewidget.cpp的653,672,756行调用QTextEdit时append加入trUtf8处理

16.左边变量Variable窗口显示中文变量名(需要GDB命令中的print对中文变量名支持)
  a)在languages/cpp/debugger/variablewidget.cpp的92行增加函数
    static void OctalToAscii(const char *octal,unsigned char *ascii){
      if(octal==NULL)
        return;
      char *p=(char*)octal;
      char *next_p;
      while(*p!=0){
        if(*p=='\\'){
          p++;
          *ascii=strtol(p,&next_p,8);
          ascii++;
          p=next_p;
        }else
          *ascii++=*p++;
      }
      *ascii=0;
    }
  b)在languages/cpp/debugger/variablewidget.cpp的1586行
      VarItem::setText函数内
    将
   QListViewItem::setText(column, strData);
    改为
      unsigned char buf[2048];
      OctalToAscii(strData.ascii(),buf);
   QListViewItem::setText(column, trUtf8((const char*)buf));
  c)在languages/cpp/debugger/variablewidget.cpp的542行
      修改VariableTree::slotAddWatchVariable函数  
  将
        varItem = new VarItem(findWatch(), watchVar);
      改为
        varItem = new VarItem(findWatch(), watchVar.local8Bit());

  d)在languages/cpp/debugger/variablewidget.cpp 的562行
    修改VariableTree::slotEvaluateExpression函数

      VarItem *varItem = new VarItem(recentExpressions_, expression, true /* freeze */);
    改为
      VarItem *varItem=new VarItem(recentExpressions_, (expression.local8Bit()), true /* freeze */);
  
  f)文件languages/cpp/debugger/variablewidget.cpp
    修改函数VarItem::recreateLocallyMaybe
      增加
        unsigned char buf[2048];
        OctalToAscii_1(expression_.ascii(),buf);
        qWarning("%s(%d)%s:=%s",__FILE__,__LINE__,__FUNCTION__,buf);//mark deng,20111224
      将1795,1802行
        arg(expression_),
      改为
arg(QString((char*)buf)),
  g)文件languages/cpp/debugger/variablewidget.cpp
    修改VarItem::createVarobj()
      增加
        unsigned char buf[2048];
        OctalToAscii_1(expression_.ascii(),buf);
        qWarning("%s(%d)%s:=%s",__FILE__,__LINE__,__FUNCTION__,buf);//mark deng,20111224
      将1269,1277行
        arg(expression_),
      改为
arg(QString((char*)buf)),
      
  h)修改languages/cpp/debugger/gdbcontroller.cpp
    将
      dbgProcess_->writeStdin(commandText.local8Bit(), commandText.length());
    改为
  dbgProcess_->writeStdin(commandText.ascii(), commandText.length());

17.下边Disassemble汇编语言窗口显示中文函数名
  a)在languages/cpp/debugger/disassemblewidget.cpp的126行增加函数
    static void OctalToAscii(const char *octal,unsigned char *ascii){
      char *p=(char*)octal;
      char *next_p;
      while(*p!=0&&!='\n'){
        if(*p=='\\'){
          p++;
          *ascii=strtol(p,&next_p,8);
          ascii++;
          p=next_p;
        }else
          *ascii++=*p++;
      }
      *ascii=0;
    }
  b)修改languages/cpp/debugger/disassemblewidget.cpp的160行
    将
      rawdata += QString(addr + " " + fct+"+"+offs + " " + inst + "\n");
    改为
      QString str=QString(addr + " " + fct+"+"+offs + " " + inst + "\n");    
      unsigned char buf[4096];
      OctalToAscii(str.ascii(),buf);
   rawdata += trUtf8((const char*)buf);
18.下边Frame Stack窗口显示中文函数名
  a)在languages/cpp/debugger/framestackwidget.cpp的530行增加函数
    static void OctalToAscii(const char *octal,unsigned char *ascii){
      if(octal==NULL)
        return;
      char *p=(char*)octal;
      char *next_p;
      while(*p!=0&&*p!='\n'){
        if(*p=='\\'){
          p++;
          *ascii=strtol(p,&next_p,8);
          ascii++;
          p=next_p;
        }else
          *ascii++=*p++;
      }
      *ascii=0;
    }
    b)在languages/cpp/debugger/framestackwidget.cpp的546行增加两个虚函数
      void FrameStackItem::setText ( int column, const QString & text ){
          unsigned char buf[4096];    
          OctalToAscii(text.ascii(),buf);   
          QListViewItem::setText(column,QObject::trUtf8((const char*)buf,NULL));
      }
      void ThreadStackItem::setText ( int column, const QString & text ){
          unsigned char buf[4096];    
          OctalToAscii(text.ascii(),buf);   
          QListViewItem::setText(column,QObject::trUtf8((const char*)buf,NULL));
      }
    c)在languages/cpp/debugger/framestackwidget.h的45和52行增加两个虚函数的定义
        virtual void setText ( int column, const QString & text );
[最后修改由 Admin, 于 2013-04-13 13:51:17]
评论Feed 评论Feed: http://www.vTalkback.com/blog/feed.asp?q=comment&id=209

浏览模式: 显示全部 | 评论: 3 | 引用: 0 | 排序 | 浏览: 4410
引用 Admin
[ 2012-05-19 20:25:54 ]
111111
[最后修改由 Admin, 于 2012-07-09 20:47:09]
引用 Admin
[ 2012-06-02 20:36:57 ]
222222
[最后修改由 Admin, 于 2012-07-09 20:47:26]
引用 Admin
[ 2012-06-09 21:43:57 ]
333333
[最后修改由 Admin, 于 2012-07-09 20:47:44]

发表
表情图标
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
UBB代码
转换链接
表情图标
悄悄话
用户名:   密码:  
验证码 * 请输入验证码