⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.cc

📁 Doc++,可以根据你的C/C++和java的源码文件中的注释行自动生成Html说明文件的工具
💻 CC
📖 第 1 页 / 共 4 页
字号:
    buf += PATH_DELIMITER;    buf += name;#ifdef DEBUG    if(verb)	printf(_("Opening `%s' to write\n"), buf.c_str());#endif    if(!(f = fopen(buf.c_str(), "wb")))	{	fprintf(stderr, _("Cannot open `%s'\n"), buf.c_str());	exit(-1);	}    return f;}void makeHtmlNames(Entry *entry){    Entry *tmp;    entry->hname = strToHtml(entry->name, 0, entry, false);    if(entry->section == EMPTY_SEC)	entry->section = PACKAGE_SEC;    if(entry->sub)	for(tmp = entry->sub; tmp; tmp = tmp->next)	    makeHtmlNames(tmp);}// This creates names for all those with their own pagesvoid makeFileNames(Entry *entry){    Entry *tmp;    McString file;    if(entry->ownPage)	{	if(language == LANG_JAVA)	    {	    McString pack;	    if(entry->section == PACKAGE_SEC)		file = "package-";	    entry->getPackage(pack);	    if(pack.length())		{		file += pack;		if(entry->section != PACKAGE_SEC)		    file += '.'; 		}	    }	if(language != LANG_JAVA || entry->section != PACKAGE_SEC)	    {	    if(entry->name.length() > 0)		file += entry->name;	    else		if(entry->section == UNION_SEC) // Struct, union, enum		    {		    file += entry->type;#ifdef DEBUG		    if(verb)			{	// This is for unnamed enums / unions etc.			printf(_("Making name from type for:\n"));			entry->dump(stdout);			}#endif		    }	    }	entry->fileName = makeFileName(file, entry);	}    if(entry->sub)	for(tmp = entry->sub; tmp; tmp = tmp->next)	    makeFileNames(tmp);}// This creates filenames for items from their parentsvoid inheritFileNames(Entry *entry){    Entry *tmp;    if(!entry->ownPage)	{	tmp = entry;	while(tmp->parent && tmp->fileName.length() == 0)	    tmp = tmp->parent;	if(tmp != entry)	    {	    entry->fileName = tmp->fileName.c_str();#ifdef DEBUG	    if(verb)		printf(_("Copied `%s %s%s' into `%s'\n"), entry->type.c_str(),		    entry->fullName.c_str(), entry->args.c_str(),		    entry->fileName.c_str());#endif	    }	}    if(entry->sub)	for(tmp = entry->sub; tmp; tmp = tmp->next)	    inheritFileNames(tmp);}// This marks those names that can't be attached to a class// It also junks redundant floating comments as a bad job...void relocateNames(Entry *root){    Entry *e, *next;    e = root->sub;    while(e)	{	next = e->next;	if(!e->ownPage)	    if(useGeneral)		{#ifdef DEBUG		if(verb)		    printf(_("Warning: `%s %s%s' hanging from root with no page\n"),			e->type.c_str(), e->fullName.c_str(), e->args.c_str());#endif		e->general = true;		}	    else		{		root->removeSub(e);		if(!fastNotSmall)		    delete(e);		}	e = next;	}	}// Decide what entries should have their's own pagevoid decideAboutOwnPages(Entry *entry){    Entry *tmp;    if(entry->section == EMPTY_SEC)	entry->section = MANUAL_SEC;    // The Quantel extension bit is to stop annoying stuff like the RCS info    // (often in a FED fold) from turning up in the data...    if(entry->sub || (entry->doc.length() > 1 && !QuantelExtn) || entry->isClass())	entry->ownPage = true;    if(entry->sub && (entry->section == MANUAL_SEC ||	entry->section == PACKAGE_SEC ||	entry->section == NAMESPACE_SEC || (entry->section & CLASS_SEC)))	for(tmp = entry->sub; tmp; tmp = tmp->next)	    if(!(entry->section & CLASS_SEC) || ((entry->section & CLASS_SEC) &&		(tmp->section & CLASS_SEC)))		decideAboutOwnPages(tmp);}void makeHtml(Entry *entry){    Entry *tmp;    int i;    entry->hmemo = strToHtml(entry->memo, 0, entry, false);    entry->hdoc = strToHtml(entry->doc, 0, entry, false);    entry->hargs = strToHtml(entry->args, 0, entry, true, true);    entry->htype = strToHtml(entry->type, 0, entry, true, true);    entry->author = strToHtml(entry->author, 0, entry, false);    entry->version = strToHtml(entry->version, 0, entry, false);    entry->deprecated = strToHtml(entry->deprecated, 0, entry, false);    entry->since = strToHtml(entry->since, 0, entry, false);    for(i = 0; i < entry->retrn.size(); i++)	*entry->retrn[i] = strToHtml(*entry->retrn[i], 0, entry, false);    for(i = 0; i < entry->param.size(); i++)	*entry->param[i] = strToHtml(*entry->param[i], 0, entry, true);    for(i = 0; i < entry->field.size(); i++)	*entry->field[i] = strToHtml(*entry->field[i], 0, entry, false);    for(i = 0; i < entry->exception.size(); i++)	*entry->exception[i] = strToHtml(*entry->exception[i], 0, entry, false);    for(i = 0; i < entry->invariant.size(); i++)	*entry->invariant[i] = strToHtml(*entry->invariant[i], 0, entry, false);    for(i = 0; i < entry->precondition.size(); i++)	*entry->precondition[i] = strToHtml(*entry->precondition[i], 0, entry, false);    for(i = 0; i < entry->postcondition.size(); i++)	*entry->postcondition[i] = strToHtml(*entry->postcondition[i], 0, entry, false);    for(i = 0; i < entry->friends.size(); i++)	*entry->friends[i] = strToHtml(*entry->friends[i], 0, entry, true);    if(entry->sub)	for(tmp = entry->sub; tmp; tmp = tmp->next)	    makeHtml(tmp);}void writePageSub(FILE *f, Entry *e){    McString htype, hargs;#ifdef DEBUG    if(verb)	printf(_("Writing sub for `%s %s%s' to file `%s'\n"), e->type.c_str(),	    e->fullName.c_str(), e->args.c_str(), e->fileName.c_str());#endif    if(withTables)	fprintf(f, "<TR><TD VALIGN=TOP>");    else	fprintf(f, "<DT>\n");    // Show the signature if this is a leaf node (meaning its full    // documentation will be on the current page)    if(e->fileName.length() == 0 || e->general)	{	htype = e->htype;	hargs = e->hargs;	}    // Show the bullet symbol.    fprintf(f, "\n<IMG ALT=\"o\" BORDER=0 SRC=icon1.gif>");    if(htype.length() > 0)	fprintf(f, "%s", htype.c_str());    // label the symbol being here    fprintf(f, "<A NAME=\"%s\"></A>\n", e->name.c_str());    // create a cross reference to the symbol if elsewhere.    if(!e->general && e->fileName.length() > 0)	fprintf(f, "<A HREF=%s><B>%s</B></A>", e->fileName.c_str(),	    e->hname);    else	fprintf(f, "<B>%s</B>", e->hname);    if(hargs.length() > 0)	fprintf(f, "%s", hargs.c_str());    if(withTables)	{	fprintf(f, "</TD><TD><BR>\n");	if(e->hmemo && strlen(e->hmemo) > 0)	    fprintf(f, "<I>%s</I>\n", e->hmemo);	fprintf(f, "</TD></TR>");	}    else	if(e->hmemo && strlen(e->hmemo) > 0)	    fprintf(f, "<DD><I>%s</I>\n", e->hmemo);}void writeManPageRec(const char *dir, Entry *e){    Entry *tmp;    McString buf;    FILE *f;#ifdef DEBUG    if(verb)	printf(_("Writing `%s %s%s' to file `%s'\n"), e->type.c_str(),	    e->fullName.c_str(), e->args.c_str(), e->fileName.c_str());#endif    if(e->general)	writePageSub(generalf, e);    if(e->ownPage)	{#ifdef DEBUG	if((e->fileName == htmlSuffix ||	    e->fileName == (const char *)".2.html") && verb)	    {	    fprintf(stderr, _("Warning: weird filename `%s' for `%s %s%s'\n"),		e->fileName.c_str(), e->type.c_str(), e->fullName.c_str(),		e->args.c_str());	    e->dump(stdout);	    }#endif	if(!(f = myOpen(dir, e->fileName)))	    {	    fprintf(stderr, _("Cannot open `%s' for writing\n"), e->fileName.c_str());	    return;	    }	if(e->section != MANUAL_SEC && e->section != PACKAGE_SEC)	    writeManPage(e, f);	else	    {	    writeHeader(e, f);	    if(printGroupDocBeforeGroup)		{		fprintf(f, "<A NAME=\"DOC.DOCU\"></A>\n");		htmlComment(f, e, (DOC | MEMO));		}	    if(e->sub)		{		if(withTables)		    fprintf(f, "\n<TABLE>\n");		else		    fprintf(f, "\n<HR>\n<DL>\n");		for(tmp = e->sub; tmp; tmp = tmp->next)		    writePageSub(f, tmp);		if(withTables)		    fprintf(f, "\n</TABLE>\n");		else		    fprintf(f, "</DL>\n");		}	    if(!printGroupDocBeforeGroup)		{		fprintf(f, "<A NAME=\"DOC.DOCU\"></A>\n");		htmlComment(f, e, (DOC | MEMO));		}	    writeTags(f, e);	    buf = processTemplate(pageFooter, e);	    fprintf(f, "%s", buf.c_str());	    copyright(f);	    }	fclose(f);	}    if(e->sub && (e->section == MANUAL_SEC || e->section == PACKAGE_SEC ||	e->section == NAMESPACE_SEC || (e->section & CLASS_SEC)))	for(tmp = e->sub; tmp; tmp = tmp->next)	    if(!(e->section & CLASS_SEC) || ((e->section & CLASS_SEC) &&		(tmp->section & CLASS_SEC)))		writeManPageRec(dir, tmp);}static void dumpFile(const char *dir, const char *name, const unsigned char *data, int size){    FILE *f = myOpen(dir, name);    fwrite(data, 1, size, f);    fclose(f);}void readTemplates(){    FILE *f;    int c;    if((f = fopen("indexHeader.inc", "r")))	{	indexHeader = " ";	while((c = fgetc(f)) != EOF)	    indexHeader += c;	fclose(f);	}    if((f = fopen("indexFooter.inc", "r")))	{	indexFooter = " ";	while((c = fgetc(f)) != EOF)	    indexFooter += c;	fclose(f);	}    if((f = fopen("hierHeader.inc", "r")))	{	hierHeader = " ";	while((c = fgetc(f)) != EOF)	    hierHeader += c;	fclose(f);	}    if((f = fopen("hierFooter.inc", "r")))	{	hierFooter = " ";	while((c = fgetc(f)) != EOF)	    hierFooter += c;	fclose(f);	}    if((f = fopen("classHeader.inc", "r")))	{	pageHeader = " ";	while((c = fgetc(f)) != EOF)	    pageHeader += c;	fclose(f);	}    if((f = fopen("classFooter.inc", "r")))	{	pageFooter = " ";	while((c = fgetc(f)) != EOF)	    pageFooter += c;	fclose(f);	}}void doHTML(const char *dir, Entry *root){    FILE *f;    Entry *tmp;    McString buf;    int c;    bool haveManualRootSec = false;    buildHeaders();    buildFooters();    if(makedir(dir, 0755) != 0)	if(errno == EEXIST)	    {	    FILE *exist = fopen(dir, "a");	    if(exist)		{		fprintf(stderr, _("`%s' directory already exists\n"), dir);		fclose(exist);		}	    }	else	    fprintf(stderr, _("Could not create `%s' directory\n"), dir);    decideAboutOwnPages(root);    makeFileNames(root);    if(root->name.length() == 0 || root->section != MANUAL_SEC)	if(root->sublist.size() == 1 && root->sublist[0]->section == MANUAL_SEC)	    {	    root->sublist[0]->fileName = "index";	    root->sublist[0]->fileName += htmlSuffix;	    haveManualRootSec = true;	    }    // This is as items under root with no page inherit this name    root->fileName = GENERAL_NAME;    root->fileName += htmlSuffix;    inheritFileNames(root);    relocateNames(root);    if(root->name.length() > 0 && root->section == MANUAL_SEC)	{	root->fileName = "index";	root->fileName += htmlSuffix;	haveManualRootSec = true;	}#if 0    if(verb)	root->dump(stdout, true);#endif    if(verb)	printf(_("Converting DOC++ to HTML...\n"));    if(root->section == EMPTY_SEC)	root->section = MANUAL_SEC;    for(tmp = root; tmp; tmp = tmp->next)	makeHtmlNames(tmp);    for(tmp = root; tmp; tmp = tmp->next)	// This takes the bulk of the time	makeHtml(tmp);    readTemplates();    if(ownFooter.length() > 0)	{	FILE *in = fopen(ownFooter.c_str(), "r");	if(!in && ownFooter != "none" && ownFooter.length() > 1)	    fprintf(stderr, _("Warning: Can't open `%s', producing no footer.\n"),		ownFooter.c_str());	else	    {	    while((c = fgetc(in)) != EOF)		footer += (char)c;	    fclose(in);	    }	}    if(ownHeader.length() > 0)	{	FILE *in = fopen(ownHeader.c_str(), "r");	if(!in && ownHeader != "none" && ownHeader.length() > 1)	    fprintf(stderr, _("Warning: Can't open `%s', producing no header.\n"),		ownHeader.c_str());	else	    {	    while((c = fgetc(in)) != EOF)		header += (char)c;	    fclose(in);	    }	}    if(verb)	printf(_("Writing files...\n"));    dumpFile(dir, "icon1.gif", blueBall, sizeof(blueBall));    dumpFile(dir, "icon2.gif", greyBall, sizeof(greyBall));    if(javaGraphs && !noClassGraph && relevantClassGraphs(root))	{	dumpFile(dir, "ClassGraph.class", ClassGraph_class,	    sizeof(ClassGraph_class));	dumpFile(dir, "ClassGraphPanel.class", ClassGraphPanel_class,	    sizeof(ClassGraphPanel_class));	dumpFile(dir, "ClassLayout.class", ClassLayout_class,	    sizeof(ClassLayout_class));	dumpFile(dir, "NavigatorButton.class", NavigatorButton_class,	    sizeof(NavigatorButton_class));	}    if(verb)	printf(_("Writing TOC...\n"));    // Table of contents    if(haveManualRootSec)	buf = "toc";    else	buf = "index";    buf += htmlSuffix;    f = myOpen(dir, buf);    writeTOC(f);    fclose(f);    if(!noClassGraph && relevantClassGraphs(root))	// Class heirarchy	{	if(verb)	    printf(_("Writing Class Hierarchy...\n"));	buf = "HIER";	buf += htmlSuffix;	f = myOpen(dir, buf);	writeHIER(f);	fclose(f);	// Java class heirarchy	if(javaGraphs)	    {	    buf = "HIERjava";	    buf += htmlSuffix;	    f = myOpen(dir, buf);	    writeHIERjava(f);	    fclose(f);  	    }	}    /* Render all the rest of the pages to HTML, and output a 'General' file       of floating #defines, global variables / functions etc.    */    // We don't want root page coming out as .html !    root->ownPage = false;    root->general = false;    buf = GENERAL_NAME;    buf += htmlSuffix;    generalf = myOpen(dir, buf);    if(header.length() == 0 && ownHeader.length() == 0)        fprintf(generalf, "%s", generalHeader.c_str());    else        fprintf(generalf, "%s", header.c_str());    if(withTables)	fprintf(generalf, "\n<TABLE>\n");    else	fprintf(generalf, "\n<DL>\n");    // Recursively write all pages    writeManPageRec(dir, root);    if(withTables)	fprintf(generalf, "\n</TABLE>\n");    else	fprintf(generalf, "</DL>\n");    fprintf(generalf, "%s", pageFooter.c_str());    copyright(generalf);    fclose(generalf);}      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -