KDevelop API Documentation

kdevlicense.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Sascha Cunz <sascha@sacu.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include <qfile.h>
00021 #include <qdatetime.h>
00022 #include <qregexp.h>
00023 
00024 #include "kdevlicense.h"
00025 
00026 KDevLicense::KDevLicense( const QString& name, const QString& fileName )
00027     : m_name( name )
00028 {
00029     readFile( fileName );
00030 }
00031 
00032 void KDevLicense::readFile( const QString& fileName )
00033 {
00034     QFile f(fileName);
00035     if (!f.open(IO_ReadOnly))
00036         return;
00037     QTextStream stream(&f);
00038     QString str;
00039     enum { readingText, readingFiles } mode = readingText;
00040     for(;;)
00041     {
00042         str = stream.readLine();
00043         if( str.isNull() )
00044             break;
00045         if( str == "[FILES]" )
00046             mode = readingFiles;
00047         else if( str == "[PREFIX]" )
00048             mode = readingText;
00049         else if( mode == readingFiles )
00050         {
00051             if( !str.isEmpty() )
00052             {
00053                 m_copyFiles.append( str );
00054             }
00055         } else
00056         m_rawLines.append( str );
00057     }
00058 
00059 }
00060 
00061 QString KDevLicense::assemble( KDevFile::CommentingStyle commentingStyle, const QString& author, const QString& email, int leadingSpaces )
00062 {
00063     // first, build a CPP Style license
00064     
00065     QString strFill;
00066     strFill.fill( ' ', leadingSpaces );
00067     
00068     QString str = 
00069         strFill + "/***************************************************************************\n" +
00070         strFill + " *   Copyright (C) %1 by %2   *\n" +
00071         strFill + " *   %3   *\n" +
00072         strFill + " *                                                                         *\n";
00073     
00074     str = str.arg(QDate::currentDate().year()).arg(author.left(45),-45).arg(email.left(67),-67);
00075     
00076     QStringList::Iterator it;
00077     for( it = m_rawLines.begin(); it != m_rawLines.end(); ++it )
00078     {
00079         str += QString( "%1 *   %2 *\n").arg( strFill ).arg( *it, -69 );
00080     }
00081     
00082     str += strFill + " ***************************************************************************/\n";
00083 
00084     switch( commentingStyle )
00085     {
00086         case KDevFile::CPPStyle:
00087             return str;
00088             
00089         case KDevFile::PascalStyle:
00090             str.replace(QRegExp("/\\**\n \\*"), "{\n  ");
00091             str.replace(QRegExp("\\*\n \\*"), " \n  ");
00092             str.replace(QRegExp(" *\\**/\n"), "}\n");
00093             return str;
00094             
00095         case KDevFile::AdaStyle:
00096             str.replace(QRegExp("/\\*"), "--");
00097             str.replace(QRegExp(" \\*"), "--");
00098             str.replace(QRegExp("\\*/"), "*");
00099             return str;
00100             
00101         case KDevFile::BashStyle:
00102             str.replace(QRegExp("\\*|/"), "#");
00103             str.replace(QRegExp("\n ##"), "\n##");
00104             str.replace(QRegExp("\n #"), "\n# ");
00105             return str;
00106     }
00107 
00108     return "currently unknown/unsupported commenting style";
00109 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:36 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003