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 DString &htmldir)
static DString path2URL (const DString &path)
static bool execute (const DString &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 DString & htmldir)
static

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

Return values
truesuccess
falsean error has occurred.

Definition at line 41 of file htags.cpp.

42{
43 StringVector inputSource = Config_getList(INPUT);
44 bool quiet = Config_getBool(QUIET);
45 bool warnings = Config_getBool(WARNINGS);
46 DString htagsOptions = ""; //Config_getString(HTAGS_OPTIONS);
47 DString projectName = Config_getString(PROJECT_NAME);
48 DString projectNumber = Config_getString(PROJECT_NUMBER);
49
50 if (inputSource.empty())
51 {
53 }
54 else if (inputSource.size()==1)
55 {
56 g_inputDir.setPath(inputSource.back());
57 if (!g_inputDir.exists())
58 err("Cannot find directory {}. "
59 "Check the value of the INPUT tag in the configuration file.\n",
60 inputSource.back()
61 );
62 }
63 else
64 {
65 err("If you use USE_HTAGS then INPUT should specify a single directory.\n");
66 return false;
67 }
68
69 /*
70 * Construct command line for htags(1).
71 */
72 DString commandLine = " -g -s -a -n ";
73 if (!quiet) commandLine += "-v ";
74 if (warnings) commandLine += "-w ";
75 if (!htagsOptions.empty())
76 {
77 commandLine += ' ';
78 commandLine += htagsOptions;
79 }
80 if (!projectName.empty())
81 {
82 commandLine += "-t \"";
83 commandLine += projectName;
84 if (!projectNumber.empty())
85 {
86 commandLine += '-';
87 commandLine += projectNumber;
88 }
89 commandLine += "\" ";
90 }
91 commandLine += " \"" + htmldir + "\"";
92 std::string oldDir = Dir::currentDirPath();
94 //printf("CommandLine=[%s]\n",qPrint(commandLine));
95 bool result=Portable::system("htags",commandLine,false)==0;
96 if (!result)
97 {
98 err("Problems running htags. Check your installation\n");
99 }
100 Dir::setCurrent(oldDir);
101 return result;
102}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
static std::string currentDirPath()
Definition dir.cpp:348
std::string absPath() const
Definition dir.cpp:370
void setPath(const std::string &path)
Definition dir.cpp:235
static bool setCurrent(const std::string &path)
Definition dir.cpp:356
bool exists() const
Definition dir.cpp:263
#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:34
#define err(fmt,...)
Definition message.h:127
int system(const DString &command, const DString &args, bool commandHasConsole=true)
Definition portable.cpp:121

References Dir::absPath(), Config_getBool, Config_getList, Config_getString, Dir::currentDirPath(), DString::empty(), err, Dir::exists(), g_inputDir, Dir::setCurrent(), Dir::setPath(), and Portable::system().

Referenced by generateOutput().

◆ loadFilemap()

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

load filemap and make index.

Parameters
htmlDirof HTML directory generated by htags(1).
Return values
truesuccess
falseerror

Definition at line 110 of file htags.cpp.

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

References err, FileInfo::exists(), DString::find(), g_symbolMap, FileInfo::isReadable(), DString::left(), DString::mid(), DString::npos, Portable::openInputStream(), DString::rfind(), DString::str(), and DString::stripWhiteSpace().

Referenced by generateOutput().

◆ path2URL()

DString Htags::path2URL ( const DString & 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 159 of file htags.cpp.

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

References Dir::absPath(), DString::empty(), g_inputDir, g_symbolMap, DString::length(), DString::mid(), and DString::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: