tools/icheck/main.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "ichecklib.h"
       
    43 #include <QtCore/QCoreApplication>
       
    44 #include <QString>
       
    45 #include <QStringList>
       
    46 #include <iostream>
       
    47 #include <QDebug>
       
    48 #include <QDir>
       
    49 #include <QFile>
       
    50 #include <QFileInfo>
       
    51 #include <QProcess>
       
    52 
       
    53 using namespace std;
       
    54 
       
    55 QT_USE_NAMESPACE
       
    56 
       
    57 extern QStringList getQTIncludePath();
       
    58 
       
    59 int main(int argc, char *argv[])
       
    60 {
       
    61     int ret = 0;
       
    62     if(argc >= 3){
       
    63         QString err = "";
       
    64         //Extract the file name and path from the arguments
       
    65         QString interfaceHeaderFile = argv[1];
       
    66         QString checkHeaderFile = argv[2];
       
    67 
       
    68         const QString curpath = QDir::currentPath();
       
    69         //Create FileInfos for the header files
       
    70         QFileInfo iFileInfo(interfaceHeaderFile);
       
    71         if (iFileInfo.isDir() || !iFileInfo.exists()){
       
    72             if(iFileInfo.isDir())
       
    73                 err = "Cannot compare a directory: " + interfaceHeaderFile;
       
    74             else
       
    75                 err = "File does not exist: " + interfaceHeaderFile;
       
    76         }
       
    77         if(err.isEmpty()){
       
    78             QFileInfo chFileInfo(checkHeaderFile);
       
    79             if (chFileInfo.isDir() || !chFileInfo.exists()){
       
    80                 if(chFileInfo.isDir())
       
    81                     err = "Cannot compare a directory: " + checkHeaderFile;
       
    82                 else
       
    83                     err = "File does not exist: " + checkHeaderFile;
       
    84             }
       
    85             if(err.isEmpty()){
       
    86                 //Read other parameters
       
    87                 QString outputfile;
       
    88                 for(int i = 3; i < argc; i++)
       
    89                 {
       
    90                     //Read output file
       
    91                     int size = strlen(argv[i]);
       
    92                     if(strncmp(argv[i], "-output", size) == 0){
       
    93                         if( (i + 1) < argc){
       
    94                             outputfile = argv[i + 1];
       
    95                             i++;
       
    96                         }
       
    97                     }
       
    98                 }
       
    99 
       
   100                 //Now create a list of the include path 
       
   101                 QString chIncludepath = chFileInfo.absolutePath();
       
   102                 QStringList chIncludepathlist;
       
   103                 chIncludepathlist << chIncludepath;
       
   104                 chIncludepathlist << getQTIncludePath();
       
   105 
       
   106                 QString iIncludepath = iFileInfo.absolutePath();
       
   107                 QStringList iIncludepathlist;
       
   108                 iIncludepathlist << iIncludepath;
       
   109 
       
   110                 //Create a list of all the soucre files they need to be parsed.
       
   111                 //In our case it is just the header file
       
   112                 QStringList chFilelist;
       
   113                 chFilelist << chFileInfo.absoluteFilePath();
       
   114 
       
   115                 QStringList iFilelist;
       
   116                 iFilelist << iFileInfo.absoluteFilePath();
       
   117 
       
   118                 ICheckLib i_ichecklib;
       
   119                 i_ichecklib.ParseHeader(iIncludepathlist, iFilelist);
       
   120 
       
   121                 ICheckLib ichecklib;
       
   122                 ichecklib.ParseHeader(chIncludepathlist, chFilelist);
       
   123 
       
   124                 if(!ichecklib.check(i_ichecklib, outputfile)){
       
   125                     cout << "Folowing interface items are missing:" << endl;
       
   126                     QStringList errorlist = ichecklib.getErrorMsg();
       
   127                     foreach(QString msg, errorlist){
       
   128                         cout << (const char *)msg.toLatin1() << endl;
       
   129                     }
       
   130                     ret = -1;
       
   131                 }
       
   132                 else
       
   133                     cout << "Interface is full defined.";
       
   134             }
       
   135         }
       
   136 
       
   137         if(!err.isEmpty()) //prit out error
       
   138         {
       
   139             cout << endl << "Error:" << endl;
       
   140             cout << (const char *)err.toLatin1();
       
   141             ret = -2;
       
   142         }
       
   143     }
       
   144     else{
       
   145         cout << "Usage: icheck <Interface header> <headerfile to check>" << endl;
       
   146         cout << "-output ...... Textfile name containing the output result." << endl;
       
   147     }
       
   148     cout << endl;
       
   149     return ret;
       
   150 }