htags.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Copyright (C) 1997-2008 by Dimitri van Heesch.
00004  *
00005  * Permission to use, copy, modify, and distribute this software and its
00006  * documentation under the terms of the GNU General Public License is hereby 
00007  * granted. No representations are made about the suitability of this software 
00008  * for any purpose. It is provided "as is" without express or implied warranty.
00009  * See the GNU General Public License for more details.
00010  *
00011  * Documents produced by Doxygen are derivative works derived from the
00012  * input used in their production; they are not affected by this license.
00013  *
00014  */
00015 
00016 #include <stdio.h>
00017 
00018 #include <qdir.h>
00019 #include <qdict.h>
00020 
00021 #include "qtbc.h"
00022 #include "htags.h"
00023 #include "util.h"
00024 #include "message.h"
00025 #include "config.h"
00026 #include "portable.h"
00027 
00028 
00029 bool Htags::useHtags = FALSE;
00030 
00031 static QDir g_inputDir;
00032 static QDict<QCString> g_symbolDict(10007);
00033 
00038 bool Htags::execute(const QCString &htmldir)
00039 {
00040   static QStrList &inputSource = Config_getList("INPUT");
00041   static bool quiet = Config_getBool("QUIET");
00042   static bool warnings = Config_getBool("WARNINGS");
00043   static QCString htagsOptions = ""; //Config_getString("HTAGS_OPTIONS");
00044   static QCString projectName = Config_getString("PROJECT_NAME");
00045   static QCString projectNumber = Config_getString("PROJECT_NUMBER");
00046 
00047   QCString cwd = convertToQCString(QDir::currentDirPath());
00048   if (inputSource.isEmpty())
00049   {
00050     g_inputDir.setPath(cwd);
00051   }
00052   else if (inputSource.count()==1)
00053   {
00054     g_inputDir.setPath(inputSource.first());
00055     if (!g_inputDir.exists())
00056       err("Error: Cannot find directory %s. "
00057           "Check the value of the INPUT tag in the configuration file.\n",
00058           inputSource.first()
00059          );
00060   }
00061   else
00062   {
00063     err("Error: If you use USE_HTAGS then INPUT should specific a single directory. \n");
00064     return FALSE;
00065   }
00066 
00067   /*
00068    * Construct command line for htags(1).
00069    */
00070   QCString commandLine = " -g -s -a -n ";
00071   if (!quiet)   commandLine += "-v ";
00072   if (warnings) commandLine += "-w ";
00073   if (!htagsOptions.isEmpty()) 
00074   {
00075     commandLine += ' ';
00076     commandLine += htagsOptions;
00077   }
00078   if (!projectName.isEmpty()) 
00079   {
00080     commandLine += "-t \"";
00081     commandLine += projectName;
00082     if (!projectNumber.isEmpty()) 
00083     {
00084       commandLine += '-';
00085       commandLine += projectNumber;
00086     }
00087     commandLine += "\" ";
00088   }
00089   commandLine += " \"" + htmldir + "\"";
00090   QCString oldDir = convertToQCString(QDir::currentDirPath());
00091   QDir::setCurrent(g_inputDir.absPath());
00092   //printf("CommandLine=[%s]\n",commandLine.data());
00093   bool result=portable_system("htags",commandLine,FALSE)==0;
00094   QDir::setCurrent(oldDir);
00095   return result;
00096 }
00097 
00098 
00104 bool Htags::loadFilemap(const QCString &htmlDir)
00105 {
00106   QCString fileMapName = htmlDir+"/HTML/FILEMAP";
00107   QCString fileMap;
00108   QFileInfo fi(fileMapName);
00109   /*
00110    * Construct FILEMAP dictionary using QDict.
00111    *
00112    * In FILEMAP, URL includes 'html' suffix but we cut it off according
00113    * to the method of FileDef class.
00114    *
00115    * FILEMAP format:
00116    * <NAME>\t<HREF>.html\n
00117    * QDICT:
00118    * dict[<NAME>] = <HREF>
00119    */
00120   if (fi.exists() && fi.isReadable())
00121   {
00122     QFile f(fileMapName);
00123     const int maxlen = 8192;
00124     QCString line(maxlen+1);
00125     line.at(maxlen)='\0';
00126     if (f.open(IO_ReadOnly))
00127     {
00128       while (f.readLine(line.data(),maxlen)>0)
00129       {
00130         //printf("Read line: %s",line.data());
00131         int sep = line.find('\t');
00132         if (sep!=-1)
00133         {
00134           QCString key   = line.left(sep).stripWhiteSpace();
00135           QCString value = line.mid(sep+1).stripWhiteSpace();
00136           int ext=value.findRev('.');
00137           if (ext!=-1) value=value.left(ext); // strip extension
00138           g_symbolDict.setAutoDelete(TRUE);
00139           g_symbolDict.insert(key,new QCString(value));
00140           //printf("Key/Value=(%s,%s)\n",key.data(),value.data());
00141         }
00142       }
00143       return TRUE;
00144     }
00145     else
00146     {
00147       err("Error: file %s cannot be opened\n",fileMapName.data()); 
00148     }
00149   }
00150   return FALSE;
00151 }
00152 
00157 QCString Htags::path2URL(const QCString &path)
00158 {
00159   QCString url,symName=path;
00160   QCString dir = convertToQCString(g_inputDir.absPath());
00161   int dl=dir.length();
00162   if ((int)symName.length()>dl+1)
00163   {
00164     symName = symName.mid(dl+1);
00165   }
00166   if (!symName.isEmpty())
00167   {
00168     QCString *result = g_symbolDict[symName];
00169     //printf("path2URL=%s symName=%s result=%p\n",path.data(),symName.data(),result);
00170     if (result)
00171     {
00172       url = "HTML/" + *result;
00173     }
00174   }
00175   return url;
00176 }
00177 



Generated on Mon Mar 31 10:58:38 2008 by  doxygen 1.5.1