/*************************************** $Header: /home/amb/cxref/src/RCS/html.c 1.46 2004/11/19 19:35:47 amb Exp $ C Cross Referencing & Documentation tool. Version 1.6a. Writes the HTML output. ******************/ /****************** Written by Andrew M. Bishop This file Copyright 1995,96,97,98,99,2001,02,04 Andrew M. Bishop It may be distributed under the GNU Public License, version 2, or any higher version. See section COPYING of the GNU Public license for conditions under which this file may be redistributed. ***************************************/ #include #include #include #include #include #include #include "version.h" #include "memory.h" #include "datatype.h" #include "cxref.h" /*+ The file extension to use for the output files. +*/ #define HTML_FILE ".html" #define HTML_FILE_BACKUP ".html~" /*+ The file extension to use for the output source files. +*/ #define HTML_SRC_FILE ".src.html" /*+ The name of the output tex file that contains the appendix. +*/ #define HTML_APDX ".apdx" /*+ The comments are to be inserted verbatim. +*/ extern int option_verbatim_comments; /*+ The type of HTML output to produce. +*/ extern int option_html; /*+ The name of the directory for the output. +*/ extern char* option_odir; /*+ The base name of the file for the output. +*/ extern char* option_name; /*+ The information about the cxref run, +*/ extern char *run_command, /*+ the command line options. +*/ *run_cpp_command; /*+ the cpp command and options. +*/ /*+ The directories to go back to get to the base output directory. +*/ static char* goback=NULL; /*+ The built-in style sheet. +*/ extern char *html_cxref_style; /* Local functions */ static void WriteHTMLFilePart(File file); static void WriteHTMLInclude(Include inc); static void WriteHTMLSubInclude(Include inc,int depth); static void WriteHTMLDefine(Define def); static void WriteHTMLTypedef(Typedef type); static void WriteHTMLStructUnion(StructUnion su,int depth); static void WriteHTMLVariable(Variable var); static void WriteHTMLFunction(Function func); static void WriteHTMLDocument(char* name,int appendix); static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile); static void WriteHTMLPostamble(FILE* f,int sourcefile); void WriteHTMLSource(char *name); static char* html(char* c,int verbatim); /*+ The output file for the HTML. +*/ static FILE* of; /*+ The name of the file. +*/ static char *filename; /*++++++++++++++++++++++++++++++++++++++ Write an html file for a complete File structure and all components. File file The File structure to output. ++++++++++++++++++++++++++++++++++++++*/ void WriteHTMLFile(File file) { char* ofile; int i; filename=file->name; /* Write the including file. */ goback=""; WriteHTMLDocument(file->name,0); /* Open the file */ ofile=ConcatStrings(4,option_odir,"/",file->name,HTML_FILE); of=fopen(ofile,"w"); if(!of) { struct stat stat_buf; int i,ofl=strlen(ofile); for(i=strlen(option_odir)+1;iname);i>0;i--) if(file->name[i]=='/') goback=ConcatStrings(2,goback,"../"); /* Write out a header. */ WriteHTMLPreamble(of,ConcatStrings(5,"Cross reference for ",file->name," of ",option_name,"."),0); /*+ The file structure is broken into its components and they are each written out. +*/ WriteHTMLFilePart(file); if(file->includes) { Include inc =file->includes; fprintf(of,"\n
\n

Included Files

\n\n"); do{ WriteHTMLInclude(inc); } while((inc=inc->next)); } if(file->defines) { Define def =file->defines; fprintf(of,"\n
\n

Preprocessor definitions

\n\n"); do{ if(def!=file->defines) fprintf(of,"

\n"); WriteHTMLDefine(def); } while((def=def->next)); } if(file->typedefs) { Typedef type=file->typedefs; do{ WriteHTMLTypedef(type); } while((type=type->next)); } if(file->variables) { int any_to_mention=0; Variable var=file->variables; do{ if(var->scope&(GLOBAL|LOCAL|EXTERNAL|EXTERN_F)) any_to_mention=1; } while((var=var->next)); if(any_to_mention) { int first_ext=1,first_local=1; Variable var=file->variables; do{ if(var->scope&GLOBAL) WriteHTMLVariable(var); } while((var=var->next)); var=file->variables; do{ if(var->scope&(EXTERNAL|EXTERN_F) && !(var->scope&GLOBAL)) { if(first_ext) {fprintf(of,"\n


\n

External Variables

\n\n"); first_ext=0;} else fprintf(of,"

\n"); WriteHTMLVariable(var); } } while((var=var->next)); var=file->variables; do{ if(var->scope&LOCAL) { if(first_local) {fprintf(of,"\n


\n

Local Variables

\n\n"); first_local=0;} else fprintf(of,"

\n"); WriteHTMLVariable(var); } } while((var=var->next)); } } if(file->functions) { Function func=file->functions; do{ if(func->scope&(GLOBAL|EXTERNAL)) WriteHTMLFunction(func); } while((func=func->next)); func=file->functions; do{ if(func->scope&LOCAL) WriteHTMLFunction(func); } while((func=func->next)); } WriteHTMLPostamble(of,0); fclose(of); /* Write out the source file. */ if(option_html&16) WriteHTMLSource(file->name); /* Clear the memory in html() */ html(NULL,0); html(NULL,0); html(NULL,0); html(NULL,0); } /*++++++++++++++++++++++++++++++++++++++ Write a File structure out. File file The File to output. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLFilePart(File file) { int i; if(option_html&16) fprintf(of,"

File %s

\n",goback,file->name,HTML_SRC_FILE,html(file->name,0)); else fprintf(of,"

File %s

\n",html(file->name,0)); if(file->comment) { if(option_verbatim_comments) fprintf(of,"
\n%s\n
\n\n",html(file->comment,0)); else { char *rcs1=strstr(file->comment,"$Header"),*rcs2=NULL; if(rcs1) { rcs2=strstr(&rcs1[1],"$"); if(rcs2) { rcs2[0]=0; fprintf(of,"RCS %s\n

\n",html(&rcs1[1],0)); rcs2[0]='$'; } } if(rcs2) fprintf(of,"%s\n

\n",html(&rcs2[2],0)); else fprintf(of,"%s\n

\n",html(file->comment,0)); } } if(file->inc_in->n) { int i; fprintf(of,"\n"); for(i=0;iinc_in->n;i++) { fprintf(of," \n"); if(i==0) fprintf(of," \n"); } fprintf(of,"
Included in:\n"); else fprintf(of,"  \n"); fprintf(of," %s\n",goback,file->inc_in->s[i],html(file->inc_in->s[i],0)); fprintf(of,"
\n"); } if(file->f_refs->n || file->v_refs->n) fprintf(of,"\n"); if(file->f_refs->n) { int others=0; fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } else others++; if(others) { if(i==others) fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } } if(file->v_refs->n) { int others=0; fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } else others++; if(others) { if(i==others) fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } } if(file->f_refs->n || file->v_refs->n) fprintf(of,"
References Functions:\n"); for(i=0;if_refs->n;i++) if(file->f_refs->s2[i]) { if(i!=others) { fprintf(of,"
 \n"); } fprintf(of," %s()\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i],0)); fprintf(of," %s\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s2[i],0)); fprintf(of,"
"); else { fprintf(of,"
 \n"); fprintf(of," "); } for(i=0;if_refs->n;i++) if(!file->f_refs->s2[i]) fprintf(of,--others?" %s(),":" %s()",html(file->f_refs->s1[i],0)); fprintf(of,"\n"); fprintf(of,"
References Variables:\n"); for(i=0;iv_refs->n;i++) if(file->v_refs->s2[i]) { if(i!=others) { fprintf(of,"
 \n"); } fprintf(of," %s\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i],0)); fprintf(of," %s\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s2[i],0)); fprintf(of,"
"); else { fprintf(of,"
 \n"); fprintf(of," "); } for(i=0;iv_refs->n;i++) if(!file->v_refs->s2[i]) fprintf(of,--others?" %s,":" %s",html(file->v_refs->s1[i],0)); fprintf(of,"\n"); fprintf(of,"
\n"); } /*++++++++++++++++++++++++++++++++++++++ Write an Include structure out. Include inc The Include structure to output. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLInclude(Include inc) { if(inc->comment) fprintf(of,"%s\n

\n",html(inc->comment,0)); fprintf(of,"

    \n"); if(inc->scope==LOCAL) fprintf(of,"
  • #include \"%s\"\n",goback,inc->name,html(inc->name,0)); else fprintf(of,"
  • #include <%s>\n",html(inc->name,0)); if(inc->includes) WriteHTMLSubInclude(inc->includes,1); fprintf(of,"
\n"); } /*++++++++++++++++++++++++++++++++++++++ Write an Sub Include structure out. (An include structure that is included from another file.) Include inc The Include structure to output. int depth The depth of the include hierarchy. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLSubInclude(Include inc,int depth) { int i; for(i=0;i\n"); while(inc) { for(i=0;iscope==LOCAL) fprintf(of,"
  • #include \"%s\"\n",goback,inc->name,html(inc->name,0)); else fprintf(of,"
  • #include <%s>\n",html(inc->name,0)); if(inc->includes) WriteHTMLSubInclude(inc->includes,depth+1); inc=inc->next; } for(i=0;i\n"); } /*++++++++++++++++++++++++++++++++++++++ Write a Define structure out. Define def The Define structure to output. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLDefine(Define def) { int i; int pargs=0; if(def->comment) fprintf(of,"%s\n

    \n",html(def->comment,0)); if(option_html&16) fprintf(of,"#define %s",goback,filename,HTML_SRC_FILE,def->lineno,html(def->name,0)); else fprintf(of,"#define %s",html(def->name,0)); if(def->value) fprintf(of," %s",html(def->value,0)); if(def->args->n) { fprintf(of,"( "); for(i=0;iargs->n;i++) fprintf(of,i?", %s":"%s",html(def->args->s1[i],0)); fprintf(of," )"); } fprintf(of,"
    \n"); for(i=0;iargs->n;i++) if(def->args->s2[i]) pargs=1; if(pargs) { fprintf(of,"

    \n"); for(i=0;iargs->n;i++) { fprintf(of,"
    %s\n",html(def->args->s1[i],0)); fprintf(of,"
    %s\n",def->args->s2[i]?html(def->args->s2[i],0):""); } fprintf(of,"
    \n"); } } /*++++++++++++++++++++++++++++++++++++++ Write a Typedef structure out. Typedef type The Typedef structure to output. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLTypedef(Typedef type) { fprintf(of,"\n
    \n

    "); if(!strncmp("enum",type->name,4)) fprintf(of,"",&type->name[5]); else if(!strncmp("union",type->name,5)) fprintf(of,"",&type->name[6]); else if(!strncmp("struct",type->name,6)) fprintf(of,"",&type->name[7]); else fprintf(of,"",type->name); if(type->type) fprintf(of,"Typedef %s",html(type->name,0)); else fprintf(of,"Type %s",html(type->name,0)); fprintf(of,"

    \n"); if(type->comment) fprintf(of,"%s\n

    \n",html(type->comment,0)); if(type->type) { if(option_html&16) fprintf(of,"typedef %s
    \n",goback,filename,HTML_SRC_FILE,type->lineno,html(type->type,0)); else fprintf(of,"typedef %s
    \n",html(type->type,0)); } else if(type->sutype) { if(option_html&16) fprintf(of,"%s
    \n",goback,filename,HTML_SRC_FILE,type->lineno,html(type->sutype->name,0)); else fprintf(of,"%s
    \n",html(type->sutype->name,0)); } if(type->sutype) { fprintf(of,"\n"); WriteHTMLStructUnion(type->sutype,0); fprintf(of,"
    \n"); } else if(type->typexref) { fprintf(of,"\n"); fprintf(of," \n"); fprintf(of," \n"); fprintf(of,"
    See:\n"); if(type->typexref->type) fprintf(of," Typedef %s\n",type->typexref->name,html(type->typexref->name,0)); else if(!strncmp("enum",type->typexref->name,4)) fprintf(of," Type %s\n",&type->typexref->name[5],html(type->typexref->name,0)); else if(!strncmp("union",type->typexref->name,5)) fprintf(of," Type %s\n",&type->typexref->name[6],html(type->typexref->name,0)); else if(!strncmp("struct",type->typexref->name,6)) fprintf(of," Type %s\n",&type->typexref->name[7],html(type->typexref->name,0)); fprintf(of,"
    \n"); } } /*++++++++++++++++++++++++++++++++++++++ Write a structure / union structure out. StructUnion su The structure / union to write. int depth The current depth within the structure. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLStructUnion(StructUnion su, int depth) { int i; char* splitsu=NULL; splitsu=strstr(su->name,"{...}"); if(splitsu) splitsu[-1]=0; fprintf(of," \n"); fprintf(of," "); for(i=0;icomps) fprintf(of,"%s\n",html(su->name,0)); else fprintf(of,"%s;\n",html(su->name,0)); fprintf(of," "); if(depth && su->comment && !su->comps) fprintf(of,"%s\n",html(su->comment,0)); else fprintf(of," \n"); fprintf(of," \n"); if(!depth || su->comps) { fprintf(of," \n"); fprintf(of," "); for(i=0;i{
    \n"); fprintf(of,"  \n"); fprintf(of," \n"); for(i=0;in_comp;i++) WriteHTMLStructUnion(su->comps[i],depth+1); fprintf(of," \n"); fprintf(of," "); for(i=0;i}\n"); fprintf(of,"  \n"); fprintf(of," \n"); if(splitsu) { fprintf(of," \n"); fprintf(of," "); for(i=0;i%s;\n",splitsu[5]?html(&splitsu[6],0):""); if(depth && su->comment) fprintf(of," %s\n",html(su->comment,0)); else fprintf(of,"  \n"); fprintf(of," \n"); } } if(splitsu) splitsu[-1]=' '; } /*++++++++++++++++++++++++++++++++++++++ Write a Variable structure out. Variable var The Variable structure to output. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLVariable(Variable var) { int i; if(var->scope&GLOBAL) fprintf(of,"\n


    \n

    Global Variable %s

    \n",var->name,html(var->name,0)); else fprintf(of,"%s
    \n",var->name,html(var->name,0)); if(var->comment) fprintf(of,"%s\n

    \n",html(var->comment,0)); if(option_html&16 && var->scope&(GLOBAL|LOCAL)) { if(var->incfrom) fprintf(of,"",goback,var->incfrom,HTML_SRC_FILE,var->lineno); else fprintf(of,"",goback,filename,HTML_SRC_FILE,var->lineno); } else fprintf(of,""); if(var->scope&LOCAL) fprintf(of,"static "); else if(!(var->scope&GLOBAL) && var->scope&(EXTERNAL|EXTERN_F)) fprintf(of,"extern "); fprintf(of,"%s",html(var->type,0)); if(option_html&16 && var->scope&(GLOBAL|LOCAL)) fprintf(of,"
    \n"); else fprintf(of,"

    \n"); if(var->scope&(GLOBAL|LOCAL)) { if(var->incfrom || var->visible->n || var->used->n) fprintf(of,"\n"); if(var->incfrom) { fprintf(of," \n"); fprintf(of," \n"); } if(var->visible->n) { for(i=0;ivisible->n;i++) { if(i==0) { fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } } if(var->used->n) { for(i=0;iused->n;i++) { if(i==0) { fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } } if(var->incfrom || var->visible->n || var->used->n) fprintf(of,"
    Included from\n"); fprintf(of," %s\n",goback,var->incfrom,var->name,html(var->incfrom,0)); fprintf(of,"
    Visible in:\n"); } else { fprintf(of,"
     \n"); } if(var->visible->s1[i][0]=='$' && !var->visible->s1[i][1]) { fprintf(of,"  \n"); fprintf(of," %s\n",goback,var->visible->s2[i],html(var->visible->s2[i],0)); } else { fprintf(of," %s()\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s1[i],0)); fprintf(of," %s\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s2[i],0)); } fprintf(of,"
    Used in:\n"); } else { fprintf(of,"
     \n"); } if(var->used->s1[i][0]=='$' && !var->used->s1[i][1]) fprintf(of,"   %s\n",goback,var->used->s2[i],html(var->used->s2[i],0)); else { if(var->scope&LOCAL) { fprintf(of," %s()\n",var->used->s1[i],html(var->used->s1[i],0)); fprintf(of,"  \n"); } else { fprintf(of," %s()\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s1[i],0)); fprintf(of," %s\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s2[i],0)); } } fprintf(of,"
    \n"); } else if(var->scope&(EXTERNAL|EXTERN_F) && var->defined) { fprintf(of,"\n"); fprintf(of," \n"); fprintf(of," \n"); fprintf(of,"
    Defined in:\n"); fprintf(of," %s\n",goback,var->defined,html(var->name,0),var->defined); fprintf(of,"
    \n"); } } /*++++++++++++++++++++++++++++++++++++++ Write a Function structure out. Function func The Function structure to output. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLFunction(Function func) { int i,pret,pargs; char* comment2=NULL,*type; if(func->scope&(GLOBAL|EXTERNAL)) fprintf(of,"\n


    \n

    Global Function %s()

    \n",func->name,html(func->name,0)); else fprintf(of,"\n
    \n

    Local Function %s()

    \n",func->name,html(func->name,0)); if(func->comment) { if(option_verbatim_comments) fprintf(of,"
    \n%s\n
    \n\n",html(func->comment,0)); else { comment2=strstr(func->comment,"\n\n"); if(comment2) comment2[0]=0; fprintf(of,"%s\n

    \n",html(func->comment,0)); } } if(option_html&16) { if(func->incfrom) fprintf(of,"",goback,func->incfrom,HTML_SRC_FILE,func->lineno); else fprintf(of,"",goback,filename,HTML_SRC_FILE,func->lineno); } else fprintf(of,""); if(func->scope&LOCAL) fprintf(of,"static "); if(func->scope&INLINED) fprintf(of,"inline "); if((type=strstr(func->type,"()"))) type[0]=0; fprintf(of,"%s ( ",html(func->type,0)); for(i=0;iargs->n;i++) fprintf(of,i?", %s":"%s",html(func->args->s1[i],0)); if(type) {fprintf(of," %s",html(&type[1],0));type[0]='(';} else fprintf(of," )"); if(option_html&16) fprintf(of,"
    \n"); else fprintf(of,"

    \n"); pret =strncmp("void ",func->type,5) && func->cret; for(pargs=0,i=0;iargs->n;i++) pargs = pargs || ( strcmp("void",func->args->s1[i]) && func->args->s2[i] ); if(pret || pargs) { fprintf(of,"

    \n"); if(pret) { fprintf(of,"
    %s\n",html(func->type,0)); fprintf(of,"
    %s\n",func->cret?html(func->cret,0):" "); } if(pargs) for(i=0;iargs->n;i++) { fprintf(of,"
    %s\n",html(func->args->s1[i],0)); fprintf(of,"
    %s\n",func->args->s2[i]?html(func->args->s2[i],0):" "); } fprintf(of,"
    \n"); } if(comment2) { fprintf(of,"%s\n

    \n",html(&comment2[2],0)); comment2[0]='\n'; } if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n) fprintf(of,"\n"); if(func->protofile) { fprintf(of," \n"); fprintf(of," \n"); } if(func->incfrom) { fprintf(of," \n"); fprintf(of," \n"); } if(func->calls->n) { int others=0; fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } else others++; if(others) { if(i==others) fprintf(of," \n"); fprintf(of," \n"); } } if(func->called->n) { fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } } if(func->used->n) { fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } } if(func->f_refs->n) { int others=0; fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } else others++; if(others) { if(i==others) fprintf(of," \n"); fprintf(of," \n"); } } if(func->v_refs->n) { int others=0; fprintf(of," \n"); fprintf(of," \n"); fprintf(of," \n"); } else others++; if(others) { if(i==others) fprintf(of," \n"); fprintf(of," \n"); } } if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n) fprintf(of,"
    Prototyped in:\n"); fprintf(of," %s\n",goback,func->protofile,html(func->protofile,0)); fprintf(of,"
    Included from:\n"); fprintf(of," %s\n",goback,func->incfrom,func->name,html(func->incfrom,0)); fprintf(of,"
    Calls:\n"); for(i=0;icalls->n;i++) if(func->calls->s2[i]) { if(i!=others) { fprintf(of,"
     \n"); } fprintf(of," %s()\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s1[i],0)); fprintf(of," %s\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s2[i],0)); fprintf(of,"
    "); else { fprintf(of,"
     \n"); fprintf(of," "); } for(i=0;icalls->n;i++) if(!func->calls->s2[i]) fprintf(of,--others?"%s(), ":"%s()",html(func->calls->s1[i],0)); fprintf(of,"\n"); fprintf(of,"
    Called by:\n"); for(i=0;icalled->n;i++) { if(i!=0) { fprintf(of,"
     \n"); } fprintf(of," %s()\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s1[i],0)); fprintf(of," %s\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s2[i],0)); fprintf(of,"
    Used in:\n"); for(i=0;iused->n;i++) { if(i!=0) { fprintf(of,"
     \n"); } if(func->used->s1[i][0]=='$' && !func->used->s1[i][1]) { fprintf(of,"  \n"); fprintf(of," %s\n",goback,func->used->s2[i],html(func->used->s2[i],0)); } else { fprintf(of," %s()\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s1[i],0)); fprintf(of," %s\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s2[i],0)); } fprintf(of,"
    References Functions:\n"); for(i=0;if_refs->n;i++) if(func->f_refs->s2[i]) { if(i!=others) { fprintf(of,"
     \n"); } fprintf(of," %s()\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s1[i],0)); fprintf(of," %s\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s2[i],0)); fprintf(of,"
    "); else { fprintf(of,"
     \n"); fprintf(of," "); } for(i=0;if_refs->n;i++) if(!func->f_refs->s2[i]) fprintf(of,--others?"%s(), ":"%s()",html(func->f_refs->s1[i],0)); fprintf(of,"\n"); fprintf(of,"
    References Variables:\n"); for(i=0;iv_refs->n;i++) if(func->v_refs->s2[i]) { if(i!=others) { fprintf(of,"
     \n"); } fprintf(of," %s\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s1[i],0)); fprintf(of," %s\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s2[i],0)); fprintf(of,"
    "); else { fprintf(of,"
     \n"); fprintf(of," "); } for(i=0;iv_refs->n;i++) if(!func->v_refs->s2[i]) fprintf(of,--others?"%s, ":"%s",html(func->v_refs->s1[i],0)); fprintf(of,"\n"); fprintf(of,"
    \n"); } /*++++++++++++++++++++++++++++++++++++++ Write out a file that will include the current information. char* name The name of the file. int appendix set to non-zero if the appendix file is to be added, else a normal source file. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLDocument(char* name,int appendix) { FILE *in,*out; char line[256]; int seen=0; char *inc_file,*ofile,*ifile; char *fname; struct stat stat_buf; if(appendix) inc_file=ConcatStrings(4,"Appendix
    \n"); else inc_file=ConcatStrings(6,"",name,"
    \n"); ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE); ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP); in=fopen(ifile,"r"); if(!in) { in =fopen(ifile,"w"); if(!in) {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ifile);exit(1);} WriteHTMLPreamble(in,ConcatStrings(3,"Cross Reference Of ",option_name,"."),1); WriteHTMLPostamble(in,1); fclose(in); in =fopen(ifile,"r"); } out=fopen(ofile,"w"); if(!out) {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);exit(1);} while(fgets(line,256,in)) { if(!strcmp(inc_file,line) || (!strncmp("\n",line)) { if(appendix) { fputs(line,out); fputs("\n",out); fputs("\n",out); fputs("\n",out); fputs("


    \n",out); fputs("

    Appendix

    \n",out); fputs("\n",out); fputs(inc_file,out); } else { fputs(inc_file,out); fputs("\n",out); fputs(line,out); } } else fputs(line,out); } fclose(in); fclose(out); if(!seen) { unlink(ifile); rename(ofile,ifile); } else unlink(ofile); /* Style file */ fname=ConcatStrings(2,option_odir,"/cxref.css"); if(stat(fname,&stat_buf)) { FILE* file=fopen(fname,"w"); if(!file) {fprintf(stderr,"cxref: Cannot write the HTML style file '%s'\n",fname);exit(1);} fputs(html_cxref_style,file); fclose(file); } } /*++++++++++++++++++++++++++++++++++++++ Write out a standard pre-amble. FILE* f The file to write the pre amble to. char* title The title of the file. int sourcefile True if the Source-Files line is to be included. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile) { fputs("\n",f); fputs("\n",f); fputs("\n",f); fputs("\n",f); fputs("\n",f); if(!sourcefile) { fputs("\n",f); fputs("\n",f); } fputs("\n",f); fputs("\n",f); fputs("\n",f); fprintf(f,"%s\n",title); fprintf(f,"\n",goback); fputs("\n",f); fputs("\n",f); fputs("\n",f); fputs("\n",f); if(sourcefile) { fputs("

    Source Files

    \n",f); fputs("\n",f); fputs("\n",f); } } /*++++++++++++++++++++++++++++++++++++++ Write out a standard post-amble. This includes the end of document marker. FILE* f The file to write the post amble to. int sourcefile True if the Source-Files line is to be included. ++++++++++++++++++++++++++++++++++++++*/ static void WriteHTMLPostamble(FILE* f,int sourcefile) { if(sourcefile) { fputs("\n",f); fputs("\n",f); } fputs("\n",f); fputs("\n",f); fputs("\n",f); } /*++++++++++++++++++++++++++++++++++++++ Write out the appendix information. StringList files The list of files to write. StringList2 funcs The list of functions to write. StringList2 vars The list of variables to write. StringList2 types The list of types to write. ++++++++++++++++++++++++++++++++++++++*/ void WriteHTMLAppendix(StringList files,StringList2 funcs,StringList2 vars,StringList2 types) { char* ofile; int i; filename=NULL; /* Write the bits to the including file. */ goback=""; WriteHTMLDocument(ConcatStrings(2,option_name,HTML_APDX),1); /* Open the file */ ofile=ConcatStrings(5,option_odir,"/",option_name,HTML_APDX,HTML_FILE); of=fopen(ofile,"w"); if(!of) {fprintf(stderr,"cxref: Failed to open the HTML appendix file '%s'\n",ofile);exit(1);} /* Write the file structure out */ WriteHTMLPreamble(of,ConcatStrings(3,"Cross reference index of ",option_name,"."),0); fprintf(of,"

    Cross References

    \n"); if(files->n || funcs->n || vars->n || types->n) { fprintf(of,"\n"); } /* Write out the appendix of files. */ if(files->n) { fprintf(of,"\n
    \n

    Files

    \n"); fprintf(of,"
      \n"); for(i=0;in;i++) fprintf(of,"
    • %s
    • \n",files->s[i],html(files->s[i],0)); fprintf(of,"
    \n"); } /* Write out the appendix of functions. */ if(funcs->n) { fprintf(of,"\n
    \n

    Global Functions

    \n"); fprintf(of,"
      \n"); for(i=0;in;i++) fprintf(of,"
    • %s() : %s
    • \n",funcs->s2[i],funcs->s1[i],html(funcs->s1[i],0),html(funcs->s2[i],0)); fprintf(of,"
    \n"); } /* Write out the appendix of variables. */ if(vars->n) { fprintf(of,"\n
    \n

    Global Variables

    \n"); fprintf(of,"
      \n"); for(i=0;in;i++) fprintf(of,"
    • %s : %s
    • \n",vars->s2[i],vars->s1[i],html(vars->s1[i],0),html(vars->s2[i],0)); fprintf(of,"
    \n"); } /* Write out the appendix of types. */ if(types->n) { fprintf(of,"\n
    \n

    Defined Types

    \n"); fprintf(of,"
      \n"); for(i=0;in;i++) if(!strncmp("enum",types->s1[i],4)) fprintf(of,"
    • %s : %s
    • \n",types->s2[i],&types->s1[i][5],html(types->s1[i],0),html(types->s2[i],0)); else if(!strncmp("union",types->s1[i],5)) fprintf(of,"
    • %s : %s
    • \n",types->s2[i],&types->s1[i][6],html(types->s1[i],0),html(types->s2[i],0)); else if(!strncmp("struct",types->s1[i],6)) fprintf(of,"
    • %s : %s
    • \n",types->s2[i],&types->s1[i][7],html(types->s1[i],0),html(types->s2[i],0)); else fprintf(of,"
    • %s : %s
    • \n",types->s2[i],types->s1[i],html(types->s1[i],0),html(types->s2[i],0)); fprintf(of,"
    \n"); } WriteHTMLPostamble(of,0); fclose(of); /* Clear the memory in html(,0) */ html(NULL,0); html(NULL,0); html(NULL,0); html(NULL,0); } /*++++++++++++++++++++++++++++++++++++++ Delete the HTML file and main file reference that belong to the named file. char *name The name of the file to delete. ++++++++++++++++++++++++++++++++++++++*/ void WriteHTMLFileDelete(char *name) { FILE *in,*out; char line[256]; int seen=0; char *inc_file,*ofile,*ifile; ofile=ConcatStrings(4,option_odir,"/",name,HTML_FILE); unlink(ofile); inc_file=ConcatStrings(6,"",name,"
    \n"); ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE); ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP); in =fopen(ifile,"r"); out=fopen(ofile,"w"); if(in && !out) {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);fclose(in);} else if(in) { while(fgets(line,256,in)) { if(!strcmp(inc_file,line) || (!strncmp("