// This file is part of Visual D // // Visual D integrates the D programming language into Visual Studio // Copyright (c) 2010 by Rainer Schuetze, All Rights Reserved // // License for redistribution is given by the Artistic License 2.0 // see file LICENSE for further details module visuald.help; import visuald.fileutil; import visuald.dpackage; import visuald.pkgutil; import visuald.hierutil; import visuald.comutil; import dte2 = sdk.vsi.dte80; import stdext.path; import std.file; import std.path; import std.string; import std.utf; import std.uri; import std.conv; import std.array; ////////////////////////////////////////////////////////////////////// static string[][string] tags; alias AssociativeArray!(string, string[]) _wa1; // fully instantiate type info static bool[string] searchAnchors(string file) { bool[string] names; string s = to!string(std.file.read(file)); fulltext: for(size_t pos = 0; pos < s.length; ) { dchar ch = decode(s, pos); if(ch == '<') { if(s[pos..$].startsWith("a name=\"")) { auto p = s[pos+8..$].indexOf('\"'); if(p < 0) break fulltext; string name = s[pos+8 .. pos+8 + p]; names[name] = true; pos += 8 + p + 1; } while(ch != '>' && pos < s.length) { ch = decode(s, pos); if(ch == '\"') { auto p = s[pos..$].indexOf('\"'); if(p < 0) break fulltext; pos += p + 1; } } } else if(ch == '\"') { auto p = s[pos..$].indexOf('\"'); if(p < 0) break fulltext; pos += p + 1; } } return names; } void loadTags() { string installdir = normalizeDir(Package.GetGlobalOptions().DMD.InstallDir) ~ "html/d/"; if(!std.file.exists(installdir ~ "index.html")) { writeToBuildOutputPane("no documentation found at " ~ installdir); return; } tags = tags.init; foreach(string file; dirEntries(installdir, SpanMode.depth)) { try { string bname = baseName(file); if(globMatch(bname, "*.html")) { auto names = searchAnchors(file); foreach(name, b; names) tags[name] ~= file; } } catch(Exception e) { // bad file access, utf8 exception, etc writeToBuildOutputPane("failed to read " ~ file); } } } string replacePath(string s, string href, string path) { string url = "file://" ~ replace(path, "\\", "/"); string t; for( ; ; ) { int pos = s.indexOf(href); if(pos < 0) break; t ~= s[0..pos + href.length]; s = s[pos + href.length .. $]; if(!s.startsWith("http:/")) t ~= url; } t ~= s; return t; } string replaceRef(string s, string path) { s = replacePath(s, `href="`, path); s = replacePath(s, `src="`, path); return s; } string createDisambiguationPage(string word, string[] files) { string installdir = normalizeDir(Package.GetGlobalOptions().DMD.InstallDir) ~ "html/d/"; string fallback = `
` ``; string html = fallback; string idxfile = installdir ~ "index.html"; if(std.file.exists(idxfile)) html = to!string(std.file.read(idxfile)); string start = `