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 38 of file htags.cpp.

39{
40 StringVector inputSource = Config_getList(INPUT);
41 bool quiet = Config_getBool(QUIET);
42 bool warnings = Config_getBool(WARNINGS);
43 DString htagsOptions = ""; //Config_getString(HTAGS_OPTIONS);
44 DString projectName = Config_getString(PROJECT_NAME);
45 DString 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 {}. "
56 "Check the value of the INPUT tag in the configuration file.\n",
57 inputSource.back()
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 DString commandLine = " -g -s -a -n ";
70 if (!quiet) commandLine += "-v ";
71 if (warnings) commandLine += "-w ";
72 if (!htagsOptions.empty())
73 {
74 commandLine += ' ';
75 commandLine += htagsOptions;
76 }
77 if (!projectName.empty())
78 {
79 commandLine += "-t \"";
80 commandLine += projectName;
81 if (!projectNumber.empty())
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 htags. Check your installation\n");
96 }
97 Dir::setCurrent(oldDir);
98 return result;
99}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
static std::string currentDirPath()
Definition dir.cpp:343
std::string absPath() const
Definition dir.cpp:365
void setPath(const std::string &path)
Definition dir.cpp:230
static bool setCurrent(const std::string &path)
Definition dir.cpp:351
bool exists() const
Definition dir.cpp:258
#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:127
int system(const DString &command, const DString &args, bool commandHasConsole=true)
Definition portable.cpp:105

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 107 of file htags.cpp.

108{
109 DString 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 DString line(lineStr);
131 //printf("Read line: %s",qPrint(line));
132 if (size_t sep = line.find('\t'); sep!=DString::npos)
133 {
134 DString key = line.left(sep).stripWhiteSpace();
135 DString value = line.mid(sep+1).stripWhiteSpace();
136 size_t ext=value.rfind('.');
137 if (ext!=DString::npos) value=value.left(ext); // strip extension
138 g_symbolMap.emplace(key.str(),value.str());
139 //printf("Key/Value=(%s,%s)\n",qPrint(key),qPrint(value));
140 }
141 }
142 return true;
143 }
144 else
145 {
146 err("file {} cannot be opened\n",fileMapName);
147 }
148 }
149 return false;
150}
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:248
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:182
DString left(size_t len) const
Definition dstring.h:310
const std::string & str() const
Definition dstring.h:649
static std::unordered_map< std::string, std::string > g_symbolMap
Definition htags.cpp:32
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:676

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 156 of file htags.cpp.

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

References Dir::absPath(), DString::DString(), 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: