Doxygen
Loading...
Searching...
No Matches
Htags Struct Reference

This class is a namespace for HTAGS related functions. More...

#include <src/htags.h>

Static Public Member Functions

static bool loadFilemap (const QCString &htmldir)
 
static QCString path2URL (const QCString &path)
 
static bool execute (const QCString &htmldir)
 

Static Public Attributes

static bool useHtags = FALSE
 

Detailed Description

This class is a namespace for HTAGS related functions.

Definition at line 21 of file htags.h.

Member Function Documentation

◆ execute()

bool Htags::execute ( const QCString & htmldir)
static

constructs command line of htags(1) and executes it.

Return values
TRUEsuccess
FALSEan error has occurred.

Definition at line 38 of file htags.cpp.

39{
40 const StringVector &inputSource = Config_getList(INPUT);
41 bool quiet = Config_getBool(QUIET);
42 bool warnings = Config_getBool(WARNINGS);
43 QCString htagsOptions = ""; //Config_getString(HTAGS_OPTIONS);
44 QCString projectName = Config_getString(PROJECT_NAME);
45 QCString projectNumber = Config_getString(PROJECT_NUMBER);
46
47 if (inputSource.empty())
48 {
50 }
51 else if (inputSource.size()==1)
52 {
53 g_inputDir.setPath(inputSource.back());
54 if (!g_inputDir.exists())
55 err("Cannot find directory %s. "
56 "Check the value of the INPUT tag in the configuration file.\n",
57 inputSource.back().c_str()
58 );
59 }
60 else
61 {
62 err("If you use USE_HTAGS then INPUT should specify a single directory.\n");
63 return FALSE;
64 }
65
66 /*
67 * Construct command line for htags(1).
68 */
69 QCString commandLine = " -g -s -a -n ";
70 if (!quiet) commandLine += "-v ";
71 if (warnings) commandLine += "-w ";
72 if (!htagsOptions.isEmpty())
73 {
74 commandLine += ' ';
75 commandLine += htagsOptions;
76 }
77 if (!projectName.isEmpty())
78 {
79 commandLine += "-t \"";
80 commandLine += projectName;
81 if (!projectNumber.isEmpty())
82 {
83 commandLine += '-';
84 commandLine += projectNumber;
85 }
86 commandLine += "\" ";
87 }
88 commandLine += " \"" + htmldir + "\"";
89 std::string oldDir = Dir::currentDirPath();
91 //printf("CommandLine=[%s]\n",qPrint(commandLine));
92 bool result=Portable::system("htags",commandLine,FALSE)==0;
93 if (!result)
94 {
95 err("Problems running %s. Check your installation\n", "htags");
96 }
97 Dir::setCurrent(oldDir);
98 return result;
99}
static std::string currentDirPath()
Definition dir.cpp:340
std::string absPath() const
Definition dir.cpp:363
void setPath(const std::string &path)
Definition dir.cpp:229
static bool setCurrent(const std::string &path)
Definition dir.cpp:348
bool exists() const
Definition dir.cpp:257
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
#define Config_getList(name)
Definition config.h:38
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
std::vector< std::string > StringVector
Definition containers.h:33
static Dir g_inputDir
Definition htags.cpp:31
#define err(fmt,...)
Definition message.h:84
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
Definition portable.cpp:106
#define FALSE
Definition qcstring.h:34

References Config_getBool, Config_getList, Config_getString, Dir::currentDirPath(), err, FALSE, g_inputDir, QCString::isEmpty(), Dir::setCurrent(), and Portable::system().

Referenced by generateOutput().

◆ loadFilemap()

bool Htags::loadFilemap ( const QCString & htmlDir)
static

load filemap and make index.

Parameters
htmlDirof HTML directory generated by htags(1).
Return values
TRUEsuccess
FALSEerror

Definition at line 107 of file htags.cpp.

108{
109 QCString fileMapName = htmlDir+"/HTML/FILEMAP";
110 FileInfo fi(fileMapName.str());
111 /*
112 * Construct FILEMAP dictionary.
113 *
114 * In FILEMAP, URL includes 'html' suffix but we cut it off according
115 * to the method of FileDef class.
116 *
117 * FILEMAP format:
118 * <NAME>\t<HREF>.html\n
119 * QDICT:
120 * dict[<NAME>] = <HREF>
121 */
122 if (fi.exists() && fi.isReadable())
123 {
124 std::ifstream f = Portable::openInputStream(fileMapName);
125 if (f.is_open())
126 {
127 std::string lineStr;
128 while (getline(f,lineStr))
129 {
130 QCString line(lineStr);
131 //printf("Read line: %s",qPrint(line));
132 int sep = line.find('\t');
133 if (sep!=-1)
134 {
135 QCString key = line.left(sep).stripWhiteSpace();
136 QCString value = line.mid(sep+1).stripWhiteSpace();
137 int ext=value.findRev('.');
138 if (ext!=-1) value=value.left(ext); // strip extension
139 g_symbolMap.emplace(key.str(),value.str());
140 //printf("Key/Value=(%s,%s)\n",qPrint(key),qPrint(value));
141 }
142 }
143 return true;
144 }
145 else
146 {
147 err("file %s cannot be opened\n",qPrint(fileMapName));
148 }
149 }
150 return false;
151}
const std::string & str() const
Definition qcstring.h:537
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString left(size_t len) const
Definition qcstring.h:214
static std::unordered_map< std::string, std::string > g_symbolMap
Definition htags.cpp:32
std::ifstream openInputStream(const QCString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:676
const char * qPrint(const char *s)
Definition qcstring.h:672

References err, FileInfo::exists(), QCString::find(), QCString::findRev(), g_symbolMap, FileInfo::isReadable(), QCString::left(), QCString::mid(), Portable::openInputStream(), qPrint(), QCString::str(), and QCString::stripWhiteSpace().

Referenced by generateOutput().

◆ path2URL()

QCString Htags::path2URL ( const QCString & path)
static

convert path name into the url in the hypertext generated by htags.

Parameters
pathpath name
Returns
URL nullptr: not found.

Definition at line 157 of file htags.cpp.

158{
159 QCString url,symName=path;
160 QCString dir = g_inputDir.absPath();
161 size_t dl=dir.length();
162 if (symName.length()>dl+1)
163 {
164 symName = symName.mid(dl+1);
165 }
166 if (!symName.isEmpty())
167 {
168 auto it = g_symbolMap.find(symName.str());
169 //printf("path2URL=%s symName=%s result=%p\n",qPrint(path),qPrint(symName),result);
170 if (it!=g_symbolMap.end())
171 {
172 url = QCString("HTML/"+it->second);
173 }
174 }
175 return url;
176}
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226

References g_inputDir, g_symbolMap, QCString::isEmpty(), QCString::length(), QCString::mid(), and QCString::str().

Referenced by FileDefImpl::getSourceFileBase().

Member Data Documentation

◆ useHtags

bool Htags::useHtags = FALSE
static

The documentation for this struct was generated from the following files: