You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
4.2 KiB
131 lines
4.2 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
* Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org>
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public
|
||
|
* License as published by the Free Software Foundation version 2.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; see the file COPYING. If not, write to
|
||
15 years ago
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
15 years ago
|
*
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include "tdefile_cpp.h"
|
||
15 years ago
|
|
||
|
#include <kurl.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kgenericfactory.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
|
typedef KGenericFactory<KCppPlugin> CppFactory;
|
||
|
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdefile_cpp, CppFactory("tdefile_cpp"))
|
||
15 years ago
|
|
||
13 years ago
|
KCppPlugin::KCppPlugin(TQObject *parent, const char *name,
|
||
15 years ago
|
const TQStringList &args)
|
||
13 years ago
|
: KFilePlugin(parent, name, args)
|
||
15 years ago
|
{
|
||
|
kdDebug(7034) << "c++ plugin\n";
|
||
|
makeMimeTypeInfo("text/x-c++src");
|
||
|
makeMimeTypeInfo("text/x-chdr");
|
||
|
}
|
||
|
|
||
15 years ago
|
void KCppPlugin::makeMimeTypeInfo(const TQString& mimetype)
|
||
15 years ago
|
{
|
||
|
KFileMimeTypeInfo* info = addMimeTypeInfo( mimetype );
|
||
|
|
||
|
KFileMimeTypeInfo::GroupInfo* group =
|
||
|
addGroupInfo(info, "General", i18n("General"));
|
||
|
|
||
|
KFileMimeTypeInfo::ItemInfo* item;
|
||
15 years ago
|
item = addItemInfo(group, "Lines", i18n("Lines"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
15 years ago
|
item = addItemInfo(group, "Code", i18n("Code"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
15 years ago
|
item = addItemInfo(group, "Comment", i18n("Comment"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
15 years ago
|
item = addItemInfo(group, "Blank", i18n("Blank"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
15 years ago
|
item = addItemInfo(group, "Strings", i18n("Strings"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
15 years ago
|
item = addItemInfo(group, "i18n Strings", i18n("i18n Strings"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
15 years ago
|
item = addItemInfo(group, "Included Files", i18n("Included Files"), TQVariant::Int);
|
||
15 years ago
|
setAttributes(item, KFileMimeTypeInfo::Averaged);
|
||
|
}
|
||
|
|
||
|
bool KCppPlugin::readInfo( KFileMetaInfo& info, uint )
|
||
|
{
|
||
15 years ago
|
TQFile f(info.path());
|
||
15 years ago
|
if (!f.open(IO_ReadOnly))
|
||
|
return false;
|
||
|
|
||
|
int codeLines = 0;
|
||
|
int commentLines = 0;
|
||
|
int totalLines = 0;
|
||
|
int emptyLines = 0;
|
||
|
int Strings = 0;
|
||
|
int Stringsi18n = 0;
|
||
|
int Includes = 0;
|
||
|
|
||
|
bool inComment = false;
|
||
|
|
||
15 years ago
|
TQString line;
|
||
15 years ago
|
|
||
15 years ago
|
TQTextStream stream( &f );
|
||
15 years ago
|
while (!stream.eof())
|
||
|
{
|
||
|
line = stream.readLine();
|
||
|
totalLines++;
|
||
|
|
||
|
if (line.stripWhiteSpace().isEmpty())
|
||
|
{
|
||
|
emptyLines++;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
13 years ago
|
if (line.contains("/*")) inComment = true;
|
||
15 years ago
|
|
||
|
if (!inComment)
|
||
|
{
|
||
|
codeLines++;
|
||
13 years ago
|
if (line.contains(TQRegExp("^\\s*#\\s*include"))) Includes++;
|
||
15 years ago
|
|
||
13 years ago
|
int pos = line.find("//");
|
||
15 years ago
|
if (pos>=0) commentLines++;
|
||
|
// truncate the comment - we don't want to count strings in it
|
||
|
line.truncate(pos);
|
||
|
|
||
13 years ago
|
Strings+=line.contains(TQRegExp("\".*\""));
|
||
|
Stringsi18n+=line.contains(TQRegExp("(?:i18n|I18N_NOOP)\\s*\\("));
|
||
15 years ago
|
}
|
||
|
else
|
||
|
commentLines++;
|
||
|
|
||
13 years ago
|
if (line.contains("*/")) inComment = false;
|
||
15 years ago
|
}
|
||
|
|
||
|
KFileMetaInfoGroup group = appendGroup(info, "General");
|
||
|
|
||
|
appendItem(group, "Lines", int(totalLines));
|
||
|
appendItem(group, "Code", int(codeLines));
|
||
|
appendItem(group, "Comment", int(commentLines));
|
||
|
appendItem(group, "Blank", int(emptyLines));
|
||
|
appendItem(group, "Strings", int(Strings));
|
||
|
appendItem(group, "i18n Strings", int(Stringsi18n));
|
||
|
appendItem(group, "Included Files", int(Includes));
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefile_cpp.moc"
|