KDevelop API Documentation

tags.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Jens Dagerbo                                    *
00003  *   jens.dagerbo@swipnet.se                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 namespace ctags
00013 {
00014 #include "readtags.h"
00015 }
00016 
00017 #include "ctagskinds.h"
00018 
00019 #include "tags.h"
00020 
00021 QCString Tags::_tagsfile;
00022 
00023 Tags::TagEntry::TagEntry() {}
00024 
00025 Tags::TagEntry::TagEntry( const QString & tag, const QString & type, const QString & file, const QString & pattern )
00026     : tag(tag), type(type), file(file), pattern(pattern)
00027 {}
00028 
00029 
00030 bool Tags::hasTag( const QString & tag )
00031 {
00032     ctags::tagFileInfo info;
00033     ctags::tagFile * file = ctags::tagsOpen( _tagsfile, &info );
00034     ctags::tagEntry entry;
00035     
00036     bool found = ( ctags::tagsFind( file, &entry, tag.ascii(), TAG_FULLMATCH | TAG_OBSERVECASE ) == ctags::TagSuccess ); 
00037     
00038     ctags::tagsClose( file );
00039     
00040     return found;
00041 }
00042 
00043 unsigned int Tags::numberOfMatches( const QString & tagpart, bool partial )
00044 {
00045     unsigned int n = 0;
00046     
00047     if ( tagpart.isEmpty() ) return 0;
00048     
00049     ctags::tagFileInfo info;
00050     ctags::tagFile * file = ctags::tagsOpen( _tagsfile, &info );
00051     ctags::tagEntry entry;
00052 
00053     if ( ctags::tagsFind( file, &entry, tagpart.ascii(), TAG_OBSERVECASE | (partial ? TAG_PARTIALMATCH : TAG_FULLMATCH) ) == ctags::TagSuccess ) 
00054     {
00055         do 
00056         {
00057             n++;
00058         }
00059         while ( ctags::tagsFindNext( file, &entry ) == ctags::TagSuccess );
00060     }
00061     
00062     ctags::tagsClose( file );
00063     
00064     return n;
00065 }
00066 
00067 Tags::TagList Tags::getMatches( const QString & tagpart, bool partial )
00068 {
00069     Tags::TagList list;
00070     
00071     if ( tagpart.isEmpty() ) return list;
00072         
00073     ctags::tagFileInfo info;
00074     ctags::tagFile * file = ctags::tagsOpen( _tagsfile, &info );
00075     ctags::tagEntry entry;
00076 
00077     if ( ctags::tagsFind( file, &entry, tagpart.ascii(), TAG_OBSERVECASE | (partial ? TAG_PARTIALMATCH : TAG_FULLMATCH) ) == ctags::TagSuccess ) 
00078     {
00079         do 
00080         {
00081             QString type( CTagsKinds::findKind( *(entry.kind), QString( entry.file ).section( '.', -1 ) ) );
00082             QString file( entry.file );
00083             
00084             if ( type.isEmpty() && file.endsWith( "Makefile" ) )
00085             {
00086                 type = "macro";
00087             }
00088             
00089             list << TagEntry( QString( entry.name ), type, file, QString( entry.address.pattern ) );            
00090         }
00091         while ( ctags::tagsFindNext( file, &entry ) == ctags::TagSuccess );
00092     }
00093     
00094     ctags::tagsClose( file );
00095     
00096     return list;
00097 }
00098 
00099 void Tags::setTagsFile( const QString & file )
00100 {
00101     _tagsfile = file.ascii();
00102 }
00103 
00104 QString Tags::getTagsFile( )
00105 {
00106     return QString( _tagsfile );
00107 }
00108 
00109 unsigned int Tags::numberOfPartialMatches( const QString & tagpart )
00110 {
00111     return numberOfMatches( tagpart, true );
00112 }
00113 
00114 unsigned int Tags::numberOfExactMatches( const QString & tagpart )
00115 {
00116     return numberOfMatches( tagpart, false );
00117 }
00118 
00119 Tags::TagList Tags::getPartialMatches( const QString & tagpart )
00120 {
00121     return getMatches( tagpart, true );
00122 }
00123 
00124 Tags::TagList Tags::getExactMatches( const QString & tag )
00125 {
00126     return getMatches( tag, false );
00127 }
00128 
00129 // kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
00130 
00131 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:54 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003