yidabu 2007-4-27 11:48
SciTe配置D语言一键帮助
SciTe配置D语言一键帮助知识若不分享 实在没有意义 http://www.d-programming-language-china.org 20070422点击下面网址查看原文:http://www.d-programming-language-china.orgtag:D语言教程, d语言ide,d语言下载下载CHM帮助文件 先到下D语言官方论坛下载chm帮助文件: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=52020 具体下载地址是: http://thecybershadow.net/d/docs/d.chm 不过这个地址国内不能访问,d-programming-language-china.org试了好多次,才想到可能mjj屏蔽了这个网站。后来用在线代理网址下载下来了。 首先你要按照下面文章安装好scite文本编辑器: http://bbs.d-programming-language-china.org/thread-458-1.htmlSciTe配置D语言一键帮助 把下载下来的帮助文件命名为d1011.chm,保存到..d\tools\d1011.chm 1011是DMD的版本号。 在d.properties中加上: # Commands to for Help F1 command.help.$(file.patterns.d)=$(CurrentWord)!$(ddir)\tools\d1011.chm command.help.subsystem.$(file.patterns.d)=4用D语言生成D语言CHM帮助文件 Greetings,( 本文出处: http://www.d-programming-language-china.org ) Some time ago I released a program which would automatically create an HTML Help project from D's HTML help files. The original release is here: http://www.digitalmars.com/webnews/newsgroups.php?article_id=51175 I've made some improvements, and here's the next version. Most importantly, the program now inserts anchors for Phobos DDOC keywords - thus, when looking up Phobos identifiers from the help index, the page will automatically scroll down to the identifier's documentation. This could make looking up Phobos functions from IDEs much more comfortable. As suggested by Jussi Jumppanen, I've changed the title to "D Programming Language". The program also uses the current version of Kirk McDonald's keyword index ( http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex ). I've attached the program; to make the CHM yourself, place it to dmd/html/, compile and run it. It will generate a Microsoft HTML Help Workshop project, along with the required files. After it's done, open the project file (d.hhp) with Microsoft's CHM compiler, and compile it. I have also updated my pre-built version of the CHM, located here: http://thecybershadow.net/d/docs/d.chm This one is built from 1.011's HTML help files.( 本文出处: http://www.d-programming-language-china.org ) Best regards, Vladimir mailto:thecybershadow@gmail.com [Copy to clipboard] [ - ]CODE: import std.stdio; import std.file; import std.string; import std.regexp; // ******************************************************************** int min(int a, int b) { return a < b ? a : b; } void backSlash(char[] s) // replace path delimiters in-place { //s=s.dup; foreach(inout c;s) if(c=='/') c='\\'; } bool match(char[] line, char[] pattern) { return std.regexp.find(line, pattern)>=0; } char[] getAnchor(char[] s) { int i = std.string.find(s, '#'); if(i<0) return ""; else return s[i..$]; } char[] removeAnchor(char[] s) { int i = std.string.find(s, '#'); if(i<0) return s; else return s[0..i]; } char[] absoluteUrl(char[] base, char[] url) { backSlash(base); backSlash(url); if (url[0]=='#') return base ~ url; while(base[$-1]!='\\') base = base[0..$-1]; while(url[0..3]=="..\\") { url = url[3..$]; do { base = base[0..$-1]; if(base.length==0) return ""; } while(base[$-1]!='\\'); } return base ~ url; } char[] movePath(char[] s) { if(s.length>1 && s[0..2]=="d\\") s = "chm" ~ s[1..$]; return s; } char[] normalize(char[] s) { s = tolower(s); char[] t; foreach(c;s) if(!iswhite(c)) t ~= c; return t; } // ******************************************************************** struct Link { char[] url, title, text; static Link opCall(char[] url, char[] title, char[] text) { backSlash(url); Link my; my.url = strip(url); my.title = strip(title); my.text = strip(text); return my; } } struct LinkBlock { Link caption; Link[] links; static LinkBlock opCall(char[] url, char[] title, char[] text) { backSlash(url); LinkBlock my; my.caption.url = strip(url); my.caption.title = strip(title); my.caption.text = strip(text); return my; } } class Page { char[] newFileName; char[] title; char[] src; Link[] toctop; LinkBlock[] linkBlocks; bool[char[]] anchors; } struct KeyLink { char[] anchor; char[] title; static KeyLink opCall(char[] anchor, char[] title) { KeyLink my; my.anchor = strip(anchor); my.title = strip(title); return my; } } // ******************************************************************** char[][] listdirrec(char[] pathname) { char[][] files = null; bool listing(char[] filename) { char[] file = std.path.join(pathname, filename); if(isdir(file)) { char[] oldpath = pathname; pathname = file; listdir(pathname, &listing); pathname = oldpath; } else { files ~= std.path.join(pathname, filename); } return true; // continue } listdir(pathname, &listing); return files; } Page[char[]] pages; KeyLink[char[]][char[]] keywords; // keywords[normalize(keyword)][original url w/o anchor] = anchor/title char[][char[]] keyTable; void addKeyword(char[] keyword, char[] link, char[] title = null) { keyword = strip(keyword); char[] norm = normalize(keyword); char[] file = removeAnchor(link); backSlash(file); char[] anchor = getAnchor(link); if(title==null && norm in keywords && file in keywords[norm]) // when title is present, it overrides any existing anchors/etc. { if(keywords[norm][file].anchor>anchor) // "less" is better keywords[norm][file] = KeyLink(anchor, title); } else keywords[norm][file] = KeyLink(anchor, title); if(title==null && norm in keyTable) { if(keyTable[norm]>keyword) // "less" is better keyTable[norm] = keyword; } else keyTable[norm] = keyword; } void main() { // clean up if(exists("chm")) foreach(file;listdirrec("chm\\")) std.file.remove(file); else mkdir("chm"); char[][] files = listdirrec("d\\"); foreach(i,file;files) pages[file] = new Page; RegExp re_title = new RegExp(`<title>(Digital Mars - The )?D Programming Language - (.*)</title>`); RegExp re_title2 = new RegExp(`<h1>(.*)</h1>`); RegExp re_heading = new RegExp(`<h2>(.*)</h2>`); RegExp re_heading_link = new RegExp(`<h2><a href="([^"]*)"( title="([^"]*)")?>(.*)</a></h2>`); RegExp re_nav_link = new RegExp(`<li><a href="([^"]*)"( title="(.*)")?>(.*)</a></li>`); RegExp re_anchor = new RegExp(`<a name="([^"]*)">(<.{1,2}>)*([^<]+)<`); RegExp re_anchor_2 = new RegExp(`<a name=([^>]*)>(<.{1,2}>)*([^<]+)<`); RegExp re_link = new RegExp(`<a href="([^"]*)">(<.{1,2}>)*([^<]+)<`); RegExp re_def = new RegExp(`<dt><big>(.*)<u>([^<]+)<`); foreach(fileName,page;pages) with(page) { char[] destdir = movePath(std.path.getDirName(fileName)); if(!exists(destdir)) mkdir(destdir); newFileName = movePath(fileName); if(match(fileName, `\.html$`)) { writefln("Processing "~fileName); src = cast(char[])read(fileName); char[][] lines = splitlines(src); char[][] newlines = null; bool skip = false, intoctop = false, innavblock = false, innavblock2 = false; int dl = 0; char[] anchor = null; anchors[""] = true; foreach(line;lines) { bool nextSkip = skip; if (re_title.test(line)) { title = strip(re_title.match(2)); line = re_title.replace(`<title>` ~ title ~ `</title>`); } if (re_title2.test(line)) if(title=="") title = strip(re_title2.match(1)); if (re_anchor.test(line)) { anchor = '#' ~ re_anchor.match(1); anchors[anchor] = true; } else if (re_anchor_2.test(line)) { anchor = '#' ~ re_anchor_2.match(1); anchors[anchor] = true; } if(match(line, `<div id="toctop">`)) intoctop = true; if(match(line, `<div class="navblock">`)) if(innavblock) { innavblock2 = true; linkBlocks ~= LinkBlock("", "", ""); } else innavblock = true; if(match(line, `</div>`)) intoctop = innavblock2 = false; if(std.string.find(line, `<dl>`)>=0) dl++; if(dl==1) { if(re_def.test(line)) { anchor = re_def.match(2); while("#"~anchor in anchors) anchor ~= '_'; anchors["#"~anchor] = true; line = re_def.pre ~ re_def.replace(`<dt><big>$1<u><a name="` ~ anchor ~ `">$2</a><`) ~ re_def.post; //writefln("new line: ", line); addKeyword(re_def.match(2), fileName ~ "#" ~ anchor); } } if(std.string.find(line, `</dl>`)>=0) dl if(re_heading_link.test(line)) { if(innavblock2) linkBlocks ~=3D LinkBlock(re_heading_link.match(1), re_heading_li= nk.match(3), re_heading_link.match(4)); } else if(re_heading.test(line)) { if(innavblock2) linkBlocks ~=3D LinkBlock("", "", re_heading.match(1)); } if(re_nav_link.test(line)) if(intoctop) toctop ~=3D Link(re_nav_link.match(1), re_nav_link.match(3), re= _nav_link.match(4)); else if(innavblock2) if(re_nav_link.match(1)[0..7]!=3D"http://" && exists(absoluteUrl(= fileName, re_nav_link.match(1)))) linkBlocks[$-1].links ~=3D Link(re_nav_link.match(1), re_nav_lin= k.match(3), re_nav_link.match(4)); //else // writefln("Displaced link: ", line); = if(re_anchor.test(line)) addKeyword(re_anchor.match(3), fileName ~ "#" ~ re_anchor.match(1)= ); else if(re_anchor_2.test(line)) addKeyword(re_anchor_2.match(3), fileName ~ "#" ~ re_anchor_2.matc= h(1)); = if(re_link.test(line)) if(re_link.match(1)[0..min($,7)]!=3D"http://") addKeyword(re_link.match(3), absoluteUrl(fileName, re_link.match(= 1))); = // skip Google ads if(match(line, `^<! // skip navigation bar if(match(line, `^<div id=3D"navigation">$`)) skip =3D nextSkip =3D true; if(match(line, `^<div id=3D"content">$`)) skip =3D nextSkip =3D false; if(!skip) newlines ~=3D line; skip =3D nextSkip; } src =3D join(newlines, newline); write(newFileName, src); } else if(match(fileName, `\.css$`)) { writefln("Processing "~fileName); src =3D cast(char[])read(fileName); char[][] lines =3D splitlines(src); char[][] newlines =3D null; foreach(line;lines) { // skip #div.content positioning if(!match(line, `margin-left:13em;`)) newlines ~=3D line; } src =3D join(newlines, newline); write(newFileName, src); } else { copy(fileName, newFileName); } } = // ************************************************************ Link[] topLinks; bool[char[]] gotLink; foreach(fileName,page;pages) foreach(link;page.toctop) { char[] url =3D absoluteUrl(fileName, link.url); if(!(url in gotLink)) { topLinks ~=3D Link(url, link.title, link.text); gotLink[url] =3D true; } } // retreive keyword link titles foreach(keyNorm,urls;keywords) foreach(url,inout link;urls) if(url in pages) link.title =3D pages[url].title; // ************************************************************ RegExp re_key_new =3D new RegExp(`<tt>(.*)</tt>`); RegExp re_key_link =3D new RegExp(`^\* (.*)\[http://www\.digitalmars\.c= om/([^ ]*) (.*)\]`); char[][] keywordLines =3D splitlines(keywordIndex); char[] keyword; foreach(line;keywordLines) { if(re_key_new.test(line)) keyword =3D re_key_new.match(1); if(re_key_link.test(line)) { char[] url =3D re_key_link.match(2); char[] file =3D removeAnchor(url); char[] anchor =3D getAnchor(url); backSlash(url); = if(file in pages) { if(!(anchor in pages[file].anchors)) { //char[] anchors; foreach(anch,b;pages[file].anchors) anchors~=3Dan= ch~","; //writefln("Invalid URL: " ~ url ~ " out of: " ~ anchors); char[] cmp1 =3D normalize(anchor); foreach(realAnchor,b;pages[file].anchors) { char[] cmp2 =3D normalize(realAnchor); int n =3D min(cmp1.length, cmp2.length); if(n>=3D3 && cmp1[0..n] =3D=3D cmp2[0..n]) { //writefln("Fixing broken anchor " ~ anchor ~ " to " ~ realAnchor= ); anchor =3D realAnchor; break; } = } } if(anchor in pages[file].anchors) { addKeyword(keyword, file ~ anchor, re_key_link.match(1) ~ re_key_li= nk.match(3)); &n