revert between 56095 -> 55830 in arch
[AROS.git] / tools / cxref / html.c
bloba08cfaa349ac4aeb156b7f55502d5e6a9c99e2cc
1 /***************************************
2 $Header$
4 C Cross Referencing & Documentation tool. Version 1.5f.
6 Writes the HTML output.
7 ******************/ /******************
8 Written by Andrew M. Bishop
10 This file Copyright 1995,96,97,98,99,2001,02,04 Andrew M. Bishop
11 It may be distributed under the GNU Public License, version 2, or
12 any higher version. See section COPYING of the GNU Public license
13 for conditions under which this file may be redistributed.
14 ***************************************/
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
23 #include "memory.h"
24 #include "datatype.h"
25 #include "cxref.h"
27 /*+ The file extension to use for the output files. +*/
28 #define HTML_FILE ".html"
29 #define HTML_FILE_BACKUP ".html~"
31 /*+ The file extension to use for the output source files. +*/
32 #define HTML_SRC_FILE ".src.html"
34 /*+ The name of the output tex file that contains the appendix. +*/
35 #define HTML_APDX ".apdx"
37 /*+ A macro to determine the HTML version we should produce. +*/
38 #define HTML20 (option_html&1)
39 #define HTML32 (option_html&2)
40 #define HTMLSRC (option_html&16)
42 /*+ The comments are to be inserted verbatim. +*/
43 extern int option_verbatim_comments;
45 /*+ The type of HTML output to produce. +*/
46 extern int option_html;
48 /*+ The name of the directory for the output. +*/
49 extern char* option_odir;
51 /*+ The base name of the file for the output. +*/
52 extern char* option_name;
54 /*+ The information about the cxref run, +*/
55 extern char *run_command, /*+ the command line options. +*/
56 *run_cpp_command; /*+ the cpp command and options. +*/
58 /*+ The directories to go back to get to the base output directory. +*/
59 static char* goback=NULL;
61 static void WriteHTMLFilePart(File file);
62 static void WriteHTMLInclude(Include inc);
63 static void WriteHTMLSubInclude(Include inc,int depth);
64 static void WriteHTMLDefine(Define def);
65 static void WriteHTMLTypedef(Typedef type);
66 static void WriteHTMLStructUnion(StructUnion su,int depth);
67 static void WriteHTMLVariable(Variable var);
68 static void WriteHTMLFunction(Function func);
70 static void WriteHTMLDocument(char* name,int appendix);
71 static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile);
72 static void WriteHTMLPostamble(FILE* f,int sourcefile);
74 void WriteHTMLSource(char *name);
76 static char* html(char* c,int verbatim);
78 /*+ The output file for the HTML. +*/
79 static FILE* of;
81 /*+ The name of the file. +*/
82 static char *filename;
85 /*++++++++++++++++++++++++++++++++++++++
86 Write an html file for a complete File structure and all components.
88 File file The File structure to output.
89 ++++++++++++++++++++++++++++++++++++++*/
91 void WriteHTMLFile(File file)
93 char* ofile;
94 int i;
96 filename=file->name;
98 /* Write the including file. */
100 WriteHTMLDocument(file->name,0);
102 /* Open the file */
104 ofile=ConcatStrings(4,option_odir,"/",file->name,HTML_FILE);
106 of=fopen(ofile,"w");
107 if(!of)
109 struct stat stat_buf;
110 int i,ofl=strlen(ofile);
112 for(i=strlen(option_odir)+1;i<ofl;i++)
113 if(ofile[i]=='/')
115 ofile[i]=0;
116 if(stat(ofile,&stat_buf))
117 mkdir(ofile,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
118 ofile[i]='/';
121 of=fopen(ofile,"w");
124 if(!of)
125 {fprintf(stderr,"cxref: Failed to open the HTML output file '%s'\n",ofile);exit(1);}
127 for(goback="",i=strlen(file->name);i>0;i--)
128 if(file->name[i]=='/')
129 goback=ConcatStrings(2,goback,"../");
131 /* Write out a header. */
133 WriteHTMLPreamble(of,ConcatStrings(5,"Cross reference for ",file->name," of ",option_name,"."),0);
135 /*+ The file structure is broken into its components and they are each written out. +*/
137 WriteHTMLFilePart(file);
139 if(file->includes)
141 Include inc =file->includes;
142 fprintf(of,"\n<hr>\n<h2>Included Files</h2>\n\n");
144 WriteHTMLInclude(inc);
146 while((inc=inc->next));
149 if(file->defines)
151 Define def =file->defines;
152 fprintf(of,"\n<hr>\n<h2>Preprocessor definitions</h2>\n\n");
154 if(def!=file->defines)
155 fprintf(of,"<p>\n");
156 WriteHTMLDefine(def);
158 while((def=def->next));
161 if(file->typedefs)
163 Typedef type=file->typedefs;
165 WriteHTMLTypedef(type);
167 while((type=type->next));
170 if(file->variables)
172 int any_to_mention=0;
173 Variable var=file->variables;
176 if(var->scope&(GLOBAL|LOCAL|EXTERNAL|EXTERN_F))
177 any_to_mention=1;
179 while((var=var->next));
181 if(any_to_mention)
183 int first_ext=1,first_local=1;
184 Variable var=file->variables;
186 if(var->scope&GLOBAL)
187 WriteHTMLVariable(var);
189 while((var=var->next));
190 var=file->variables;
192 if(var->scope&(EXTERNAL|EXTERN_F) && !(var->scope&GLOBAL))
194 if(first_ext)
195 {fprintf(of,"\n<hr>\n<h2>External Variables</h2>\n\n"); first_ext=0;}
196 else
197 fprintf(of,"<p>\n");
198 WriteHTMLVariable(var);
201 while((var=var->next));
202 var=file->variables;
204 if(var->scope&LOCAL)
206 if(first_local)
207 {fprintf(of,"\n<hr>\n<h2>Local Variables</h2>\n\n"); first_local=0;}
208 else
209 fprintf(of,"<p>\n");
210 WriteHTMLVariable(var);
213 while((var=var->next));
217 if(file->functions)
219 Function func=file->functions;
221 if(func->scope&(GLOBAL|EXTERNAL))
222 WriteHTMLFunction(func);
224 while((func=func->next));
225 func=file->functions;
227 if(func->scope&LOCAL)
228 WriteHTMLFunction(func);
230 while((func=func->next));
233 WriteHTMLPostamble(of,0);
235 fclose(of);
237 /* Write out the source file. */
239 if(HTMLSRC)
240 WriteHTMLSource(file->name);
242 /* Clear the memory in html() */
244 html(NULL,0); html(NULL,0); html(NULL,0); html(NULL,0);
248 /*++++++++++++++++++++++++++++++++++++++
249 Write a File structure out.
251 File file The File to output.
252 ++++++++++++++++++++++++++++++++++++++*/
254 static void WriteHTMLFilePart(File file)
256 int i;
258 if(HTMLSRC)
259 fprintf(of,"<h1><a name=\"file\" href=\"%s%s%s\">File %s</a></h1>\n",goback,file->name,HTML_SRC_FILE,html(file->name,0));
260 else
261 fprintf(of,"<h1><a name=\"file\">File %s</a></h1>\n",html(file->name,0));
263 if(file->comment)
265 if(option_verbatim_comments)
266 fprintf(of,"<pre>\n%s\n</pre>\n\n",html(file->comment,0));
267 else
269 char *rcs1=strstr(file->comment,"$Header"),*rcs2=NULL;
270 if(rcs1)
272 rcs2=strstr(&rcs1[1],"$");
273 if(rcs2)
275 rcs2[0]=0;
276 fprintf(of,"<b>RCS %s</b>\n<p>\n",html(&rcs1[1],0));
277 rcs2[0]='$';
280 if(rcs2)
281 fprintf(of,"%s\n<p>\n",html(&rcs2[2],0));
282 else
283 fprintf(of,"%s\n<p>\n",html(file->comment,0));
287 if(file->inc_in->n)
289 int i;
291 if(HTML20)
292 fprintf(of,"<dl compact>\n");
293 else
294 fprintf(of,"<table>\n");
295 for(i=0;i<file->inc_in->n;i++)
297 if(HTML20 && i==0)
298 fprintf(of,"<dt>Included in:\n<dd><ul>\n");
299 else if(HTML32 && i==0)
300 fprintf(of,"<tr><td>Included in:\n");
301 else if(HTML32)
302 fprintf(of,"<tr><td>&nbsp;\n");
303 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a><br>\n",HTML20?"li":"td",goback,file->inc_in->s[i],html(file->inc_in->s[i],0));
305 if(HTML20)
306 fprintf(of,"</ul>\n</dl>\n");
307 else
308 fprintf(of,"</table>\n");
311 if(file->f_refs->n || file->v_refs->n)
313 if(HTML20)
314 fprintf(of,"<dl compact>\n");
315 else
316 fprintf(of,"<table>\n");
319 if(file->f_refs->n)
321 int others=0;
323 if(HTML20)
324 fprintf(of,"<dt>References Functions:\n<dd><ul>\n");
325 else
326 fprintf(of,"<tr><td>References Functions:\n");
328 for(i=0;i<file->f_refs->n;i++)
329 if(file->f_refs->s2[i])
331 if(HTML32 && i!=others)
332 fprintf(of,"<tr><td>&nbsp;\n");
333 if(HTML20)
334 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i],0),html(file->f_refs->s2[i],0));
335 else
336 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i],0),goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s2[i],0));
338 else
339 others++;
341 if(others)
343 if(HTML20)
344 fprintf(of,"<li>");
345 else if(i==others)
346 fprintf(of,"<td colspan=2>");
347 else
348 fprintf(of,"<tr><td>&nbsp;\n<td colspan=2>");
349 for(i=0;i<file->f_refs->n;i++)
350 if(!file->f_refs->s2[i])
351 fprintf(of,--others?" %s(),":" %s()",html(file->f_refs->s1[i],0));
352 fprintf(of,"\n");
355 if(HTML20)
356 fprintf(of,"</ul>\n");
359 if(file->v_refs->n)
361 int others=0;
363 if(HTML20)
364 fprintf(of,"<dt>References Variables:\n<dd><ul>\n");
365 else
366 fprintf(of,"<tr><td>References Variables:\n");
368 for(i=0;i<file->v_refs->n;i++)
369 if(file->v_refs->s2[i])
371 if(HTML32 && i!=others)
372 fprintf(of,"<tr><td>&nbsp;\n");
373 if(HTML20)
374 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s : %s</a>\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i],0),html(file->v_refs->s2[i],0));
375 else
376 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a><td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i],0),goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s2[i],0));
378 else
379 others++;
381 if(others)
383 if(HTML20)
384 fprintf(of,"<li>");
385 else if(i==others)
386 fprintf(of,"<td colspan=2>");
387 else
388 fprintf(of,"<tr><td>&nbsp;\n<td colspan=2>");
389 for(i=0;i<file->v_refs->n;i++)
390 if(!file->v_refs->s2[i])
391 fprintf(of,--others?" %s,":" %s",html(file->v_refs->s1[i],0));
392 fprintf(of,"\n");
395 if(HTML20)
396 fprintf(of,"</ul>\n");
399 if(file->f_refs->n || file->v_refs->n)
401 if(HTML20)
402 fprintf(of,"</dl>\n");
403 else
404 fprintf(of,"</table>\n");
409 /*++++++++++++++++++++++++++++++++++++++
410 Write an Include structure out.
412 Include inc The Include structure to output.
413 ++++++++++++++++++++++++++++++++++++++*/
415 static void WriteHTMLInclude(Include inc)
417 if(inc->comment)
418 fprintf(of,"%s\n<p>\n",html(inc->comment,0));
420 fprintf(of,"<ul>\n");
422 if(inc->scope==LOCAL)
423 fprintf(of,"<li><tt><a href=\"%s%s"HTML_FILE"#file\">#include \"%s\"</a></tt>\n",goback,inc->name,html(inc->name,0));
424 else
425 fprintf(of,"<li><tt>#include &lt;%s&gt;</tt>\n",html(inc->name,0));
427 if(inc->includes)
428 WriteHTMLSubInclude(inc->includes,1);
430 fprintf(of,"</ul>\n");
434 /*++++++++++++++++++++++++++++++++++++++
435 Write an Sub Include structure out. (An include structure that is included from another file.)
437 Include inc The Include structure to output.
439 int depth The depth of the include hierarchy.
440 ++++++++++++++++++++++++++++++++++++++*/
442 static void WriteHTMLSubInclude(Include inc,int depth)
444 fprintf(of,"<ul>\n");
446 while(inc)
448 if(inc->scope==LOCAL)
449 fprintf(of,"<li><tt><a href=\"%s%s"HTML_FILE"#file\">#include \"%s\"</a></tt>\n",goback,inc->name,html(inc->name,0));
450 else
451 fprintf(of,"<li><tt>#include &lt;%s&gt;</tt>\n",html(inc->name,0));
453 if(inc->includes)
454 WriteHTMLSubInclude(inc->includes,depth+1);
456 inc=inc->next;
459 fprintf(of,"</ul>\n");
463 /*++++++++++++++++++++++++++++++++++++++
464 Write a Define structure out.
466 Define def The Define structure to output.
467 ++++++++++++++++++++++++++++++++++++++*/
469 static void WriteHTMLDefine(Define def)
471 int i;
472 int pargs=0;
474 if(def->comment)
475 fprintf(of,"%s\n<p>\n",html(def->comment,0));
477 if(HTMLSRC)
478 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">#define %s</a>",goback,filename,HTML_SRC_FILE,def->lineno,html(def->name,0));
479 else
480 fprintf(of,"<tt>#define %s",html(def->name,0));
482 if(def->value)
483 fprintf(of," %s",html(def->value,0));
485 if(def->args->n)
487 fprintf(of,"( ");
488 for(i=0;i<def->args->n;i++)
489 fprintf(of,i?", %s":"%s",html(def->args->s1[i],0));
490 fprintf(of," )");
492 fprintf(of,"</tt><br>\n");
494 for(i=0;i<def->args->n;i++)
495 if(def->args->s2[i])
496 pargs=1;
498 if(pargs)
500 fprintf(of,"<dl compact>\n");
501 for(i=0;i<def->args->n;i++)
502 fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(def->args->s1[i],0),def->args->s2[i]?html(def->args->s2[i],0):"");
503 fprintf(of,"</dl>\n");
508 /*++++++++++++++++++++++++++++++++++++++
509 Write a Typedef structure out.
511 Typedef type The Typedef structure to output.
512 ++++++++++++++++++++++++++++++++++++++*/
514 static void WriteHTMLTypedef(Typedef type)
516 fprintf(of,"\n<hr>\n<h2>");
518 if(!strncmp("enum",type->name,4))
519 fprintf(of,"<a name=\"type-enum-%s\">",&type->name[5]);
520 else
521 if(!strncmp("union",type->name,5))
522 fprintf(of,"<a name=\"type-union-%s\">",&type->name[6]);
523 else
524 if(!strncmp("struct",type->name,6))
525 fprintf(of,"<a name=\"type-struct-%s\">",&type->name[7]);
526 else
527 fprintf(of,"<a name=\"type-%s\">",type->name);
529 if(type->type)
530 fprintf(of,"Typedef %s",html(type->name,0));
531 else
532 fprintf(of,"Type %s",html(type->name,0));
534 fprintf(of,"</a></h2>\n");
536 if(type->comment)
537 fprintf(of,"%s\n<p>\n",html(type->comment,0));
539 if(type->type)
541 if(HTMLSRC)
542 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">typedef %s</a></tt><br>\n",goback,filename,HTML_SRC_FILE,type->lineno,html(type->type,0));
543 else
544 fprintf(of,"<tt>typedef %s</tt><br>\n",html(type->type,0));
546 else if(type->sutype)
548 if(HTMLSRC)
549 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">%s</a></tt><br>\n",goback,filename,HTML_SRC_FILE,type->lineno,html(type->sutype->name,0));
550 else
551 fprintf(of,"<tt>%s</tt><br>\n",html(type->sutype->name,0));
554 if(type->sutype)
556 if(HTML20)
557 fprintf(of,"<ul>\n");
558 else
559 fprintf(of,"<table>\n");
560 WriteHTMLStructUnion(type->sutype,0);
561 if(HTML20)
562 fprintf(of,"</ul>\n");
563 else
564 fprintf(of,"</table>\n");
566 else
567 if(type->typexref)
569 fprintf(of,"<dl compact>\n<dt>See:\n<dd><ul>\n");
570 if(type->typexref->type)
571 fprintf(of,"<li><a href=\"#type-%s\">Typedef %s</a>\n",type->typexref->name,html(type->typexref->name,0));
572 else
573 if(!strncmp("enum",type->typexref->name,4))
574 fprintf(of,"<li><a href=\"#type-enum-%s\">Type %s</a>\n",&type->typexref->name[5],html(type->typexref->name,0));
575 else
576 if(!strncmp("union",type->typexref->name,5))
577 fprintf(of,"<li><a href=\"#type-union-%s\">Type %s</a>\n",&type->typexref->name[6],html(type->typexref->name,0));
578 else
579 if(!strncmp("struct",type->typexref->name,6))
580 fprintf(of,"<li><a href=\"#type-struct-%s\">Type %s</a>\n",&type->typexref->name[7],html(type->typexref->name,0));
581 fprintf(of,"</ul>\n</dl>\n");
586 /*++++++++++++++++++++++++++++++++++++++
587 Write a structure / union structure out.
589 StructUnion su The structure / union to write.
591 int depth The current depth within the structure.
592 ++++++++++++++++++++++++++++++++++++++*/
594 static void WriteHTMLStructUnion(StructUnion su, int depth)
596 int i;
597 char* splitsu=NULL;
599 splitsu=strstr(su->name,"{...}");
600 if(splitsu) splitsu[-1]=0;
602 if(HTML20)
604 if(depth && su->comment && !su->comps)
605 fprintf(of,"<li><tt>%s; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </tt>%s<br>\n",html(su->name,0),html(su->comment,0));
606 else if(!depth || su->comps)
607 fprintf(of,"<li><tt>%s</tt><br>\n",html(su->name,0));
608 else
609 fprintf(of,"<li><tt>%s;</tt><br>\n",html(su->name,0));
611 else
613 fprintf(of,"<tr><td>");
614 for(i=0;i<depth;i++)
615 fprintf(of,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
616 if(!depth || su->comps)
617 fprintf(of,"<tt>%s</tt>",html(su->name,0));
618 else
619 fprintf(of,"<tt>%s;</tt>",html(su->name,0));
620 fprintf(of,"<td>");
621 if(depth && su->comment && !su->comps)
622 fprintf(of,html(su->comment,0));
623 else
624 fprintf(of,"&nbsp;");
625 fprintf(of,"\n");
628 if(!depth || su->comps)
630 if(HTML20)
632 fprintf(of,"<ul>\n");
633 fprintf(of,"<li><tt>{</tt><br>\n");
635 else
637 fprintf(of,"<tr><td>");
638 for(i=0;i<depth;i++)
639 fprintf(of,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
640 fprintf(of,"&nbsp;&nbsp;&nbsp;<tt>{</tt>");
641 fprintf(of,"<td>&nbsp;\n");
644 for(i=0;i<su->n_comp;i++)
645 WriteHTMLStructUnion(su->comps[i],depth+1);
647 if(HTML20)
649 fprintf(of,"<li><tt>}</tt><br>\n");
650 fprintf(of,"</ul>\n");
652 else
654 fprintf(of,"<tr><td>");
655 for(i=0;i<depth;i++)
656 fprintf(of,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
657 fprintf(of,"&nbsp;&nbsp;&nbsp;<tt>}</tt>");
658 fprintf(of,"<td>&nbsp;\n");
661 if(splitsu)
663 if(HTML20)
665 if(depth && su->comment)
666 fprintf(of,"<li><tt>%s; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </tt>%s<br>\n",splitsu[5]?html(&splitsu[6],0):"",html(su->comment,0));
667 else
668 fprintf(of,"<li><tt>%s;</tt><br>\n",splitsu[5]?html(&splitsu[6],0):"");
670 else
672 fprintf(of,"<tr><td>");
673 for(i=0;i<depth;i++)
674 fprintf(of,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
675 fprintf(of,"<tt>%s;</tt>",splitsu[5]?html(&splitsu[6],0):"");
676 if(depth && su->comment)
677 fprintf(of,"<td>%s\n",html(su->comment,0));
678 else
679 fprintf(of,"<td>&nbsp;\n");
684 if(splitsu) splitsu[-1]=' ';
688 /*++++++++++++++++++++++++++++++++++++++
689 Write a Variable structure out.
691 Variable var The Variable structure to output.
692 ++++++++++++++++++++++++++++++++++++++*/
694 static void WriteHTMLVariable(Variable var)
696 int i;
698 if(var->scope&GLOBAL)
699 fprintf(of,"\n<hr>\n<h2><a name=\"var-%s\">Global Variable %s</a></h2>\n",var->name,html(var->name,0));
700 else
701 fprintf(of,"<b><a name=\"var-%s\">%s</a></b><br>\n",var->name,html(var->name,0));
703 if(var->comment)
704 fprintf(of,"%s\n<p>\n",html(var->comment,0));
706 if(HTMLSRC && var->scope&(GLOBAL|LOCAL))
708 if(var->incfrom)
709 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">",goback,var->incfrom,HTML_SRC_FILE,var->lineno);
710 else
711 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">",goback,filename,HTML_SRC_FILE,var->lineno);
713 else
714 fprintf(of,"<tt>");
716 if(var->scope&LOCAL)
717 fprintf(of,"static ");
718 else
719 if(!(var->scope&GLOBAL) && var->scope&(EXTERNAL|EXTERN_F))
720 fprintf(of,"extern ");
722 fprintf(of,"%s",html(var->type,0));
724 if(HTMLSRC)
725 fprintf(of,"</a></tt><br>\n");
726 else
727 fprintf(of,"</tt><br>\n");
729 if(var->scope&(GLOBAL|LOCAL))
731 if(var->incfrom || var->visible->n || var->used->n)
733 if(HTML20)
734 fprintf(of,"<dl compact>\n");
735 else
736 fprintf(of,"<table>\n");
739 if(var->incfrom)
741 if(HTML20)
742 fprintf(of,"<dt>Included from:\n<dd><ul>\n");
743 else
744 fprintf(of,"<tr><td>Included from\n");
745 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",HTML20?"li":"td",goback,var->incfrom,var->name,html(var->incfrom,0));
746 if(HTML20)
747 fprintf(of,"</ul>\n");
750 if(var->visible->n)
752 for(i=0;i<var->visible->n;i++)
754 if(HTML20 && i==0)
755 fprintf(of,"<dt>Visible in:\n<dd><ul>\n");
756 else if(HTML32 && i==0)
757 fprintf(of,"<tr><td>Visible in:\n");
758 else if(HTML32)
759 fprintf(of,"<tr><td>&nbsp;\n");
760 if(var->visible->s1[i][0]=='$' && !var->visible->s1[i][1])
761 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td>&nbsp;<td",goback,var->visible->s2[i],html(var->visible->s2[i],0));
762 else
763 if(HTML20)
764 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s1[i],0),html(var->visible->s2[i],0));
765 else
766 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s1[i],0),goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s2[i],0));
768 if(HTML20)
769 fprintf(of,"</ul>\n");
772 if(var->used->n)
774 for(i=0;i<var->used->n;i++)
776 if(HTML20 && i==0)
777 fprintf(of,"<dt>Used in:\n<dd><ul>\n");
778 else if(HTML32 && i==0)
779 fprintf(of,"<tr><td>Used in:\n");
780 else if(HTML32)
781 fprintf(of,"<tr><td>&nbsp;\n");
782 if(var->used->s1[i][0]=='$' && !var->used->s1[i][1])
783 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td>&nbsp;<td",goback,var->used->s2[i],html(var->used->s2[i],0));
784 else
786 if(var->scope&LOCAL)
787 fprintf(of,"<%s><a href=\"#func-%s\">%s()</a>\n",HTML20?"li":"td",var->used->s1[i],html(var->used->s1[i],0));
788 else
789 if(HTML20)
790 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s1[i],0),html(var->used->s2[i],0));
791 else
792 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s1[i],0),goback,var->used->s2[i],var->used->s1[i],html(var->used->s2[i],0));
795 if(HTML20)
796 fprintf(of,"</ul>\n");
799 if(var->incfrom || var->visible->n || var->used->n)
801 if(HTML20)
802 fprintf(of,"</dl>\n");
803 else
804 fprintf(of,"\n</table>\n");
807 else
808 if(var->scope&(EXTERNAL|EXTERN_F) && var->defined)
810 if(HTML20)
811 fprintf(of,"<dl compact>\n");
812 else
813 fprintf(of,"<table>\n");
814 if(HTML20)
815 fprintf(of,"<dt>Defined in:\n<dd><ul>\n");
816 else
817 fprintf(of,"<tr><td>Defined in:\n");
818 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",HTML20?"li":"td",goback,var->defined,html(var->name,0),var->defined);
819 if(HTML20)
820 fprintf(of,"</ul>\n</dl>\n");
821 else
822 fprintf(of,"\n</table>\n");
827 /*++++++++++++++++++++++++++++++++++++++
828 Write a Function structure out.
830 Function func The Function structure to output.
831 ++++++++++++++++++++++++++++++++++++++*/
833 static void WriteHTMLFunction(Function func)
835 int i,pret,pargs;
836 char* comment2=NULL,*type;
838 if(func->scope&(GLOBAL|EXTERNAL))
839 fprintf(of,"\n<hr>\n<h2><a name=\"func-%s\">Global Function %s()</a></h2>\n",func->name,html(func->name,0));
840 else
841 fprintf(of,"\n<hr>\n<h2><a name=\"func-%s\">Local Function %s()</a></h2>\n",func->name,html(func->name,0));
843 if(func->comment)
845 if(option_verbatim_comments)
846 fprintf(of,"<pre>\n%s\n</pre>\n\n",html(func->comment,0));
847 else
849 comment2=strstr(func->comment,"\n\n");
850 if(comment2)
851 comment2[0]=0;
852 fprintf(of,"%s\n<p>\n",html(func->comment,0));
856 if(HTMLSRC)
858 if(func->incfrom)
859 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">",goback,func->incfrom,HTML_SRC_FILE,func->lineno);
860 else
861 fprintf(of,"<tt><a href=\"%s%s%s#line%d\">",goback,filename,HTML_SRC_FILE,func->lineno);
863 else
864 fprintf(of,"<tt>");
866 if(func->scope&LOCAL)
867 fprintf(of,"static ");
868 if(func->scope&INLINED)
869 fprintf(of,"inline ");
871 if((type=strstr(func->type,"()")))
872 type[0]=0;
873 fprintf(of,"%s ( ",html(func->type,0));
875 for(i=0;i<func->args->n;i++)
876 fprintf(of,i?", %s":"%s",html(func->args->s1[i],0));
878 if(type)
879 {fprintf(of," %s",html(&type[1],0));type[0]='(';}
880 else
881 fprintf(of," )");
883 if(HTMLSRC)
884 fprintf(of,"</a></tt><br>\n");
885 else
886 fprintf(of,"</tt><br>\n");
888 pret =strncmp("void ",func->type,5) && func->cret;
889 for(pargs=0,i=0;i<func->args->n;i++)
890 pargs = pargs || ( strcmp("void",func->args->s1[i]) && func->args->s2[i] );
892 if(pret || pargs)
894 fprintf(of,"<dl compact>\n");
895 if(pret)
896 fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(func->type,0),func->cret?html(func->cret,0):"&nbsp;");
897 if(pargs)
898 for(i=0;i<func->args->n;i++)
899 fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(func->args->s1[i],0),func->args->s2[i]?html(func->args->s2[i],0):"&nbsp;");
900 fprintf(of,"</dl>\n");
903 if(comment2)
905 fprintf(of,"%s\n<p>\n",html(&comment2[2],0));
906 comment2[0]='\n';
909 if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n)
911 if(HTML20)
912 fprintf(of,"<dl compact>\n");
913 else
914 fprintf(of,"<table>\n");
917 if(func->protofile)
919 if(HTML20)
920 fprintf(of,"<dt>Prototyped in:\n<dd><ul>\n");
921 else
922 fprintf(of,"<tr><td>Prototyped in:\n");
923 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td colspan=2",goback,func->protofile,html(func->protofile,0));
924 if(HTML20)
925 fprintf(of,"</ul>\n");
928 if(func->incfrom)
930 if(HTML20)
931 fprintf(of,"<dt>Included from:\n<dd><ul>\n");
932 else
933 fprintf(of,"<tr><td>Included from:\n");
934 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",HTML20?"li":"td colspan=2",goback,func->incfrom,func->name,html(func->incfrom,0));
935 if(HTML20)
936 fprintf(of,"</ul>\n");
939 if(func->calls->n)
941 int others=0;
943 if(HTML20)
944 fprintf(of,"<dt>Calls:\n<dd><ul>\n");
945 else
946 fprintf(of,"<tr><td>Calls:\n");
948 for(i=0;i<func->calls->n;i++)
949 if(func->calls->s2[i])
951 if(HTML32 && i!=others)
952 fprintf(of,"<tr><td>&nbsp;\n");
953 if(HTML20)
954 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s1[i],0),html(func->calls->s2[i],0));
955 else
956 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s1[i],0),goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s2[i],0));
958 else
959 others++;
961 if(others)
963 if(HTML20)
964 fprintf(of,"<li>");
965 else if(i==others)
966 fprintf(of,"<td colspan=2>");
967 else
968 fprintf(of,"<tr><td>&nbsp;\n<td colspan=2>");
969 for(i=0;i<func->calls->n;i++)
970 if(!func->calls->s2[i])
971 fprintf(of,--others?"%s(), ":"%s()",html(func->calls->s1[i],0));
972 fprintf(of,"\n");
975 if(HTML20)
976 fprintf(of,"</ul>\n");
979 if(func->called->n)
981 if(HTML20)
982 fprintf(of,"<dt>Called by:\n<dd><ul>\n");
983 else
984 fprintf(of,"<tr><td>Called by:\n");
985 for(i=0;i<func->called->n;i++)
987 if(HTML32 && i!=0)
988 fprintf(of,"<tr><td>&nbsp;\n");
989 if(HTML20)
990 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s1[i],0),html(func->called->s2[i],0));
991 else
992 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s1[i],0),goback,func->called->s2[i],func->called->s1[i],html(func->called->s2[i],0));
994 if(HTML20)
995 fprintf(of,"</ul>\n");
998 if(func->used->n)
1000 if(HTML20)
1001 fprintf(of,"<dt>Used in:\n<dd><ul>\n");
1002 else
1003 fprintf(of,"<tr><td>Used in:\n");
1004 for(i=0;i<func->used->n;i++)
1006 if(HTML32 && i!=0)
1007 fprintf(of,"<tr><td>&nbsp;\n");
1008 if(func->used->s1[i][0]=='$' && !func->used->s1[i][1])
1009 fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td>&nbsp;<td",goback,func->used->s2[i],html(func->used->s2[i],0));
1010 else
1011 if(HTML20)
1012 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s1[i],0),html(func->used->s2[i],0));
1013 else
1014 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s1[i],0),goback,func->used->s2[i],func->used->s1[i],html(func->used->s2[i],0));
1016 if(HTML20)
1017 fprintf(of,"</ul>\n");
1020 if(func->f_refs->n)
1022 int others=0;
1024 if(HTML20)
1025 fprintf(of,"<dt>References Functions:\n<dd><ul>\n");
1026 else
1027 fprintf(of,"<tr><td>References Functions:\n");
1029 for(i=0;i<func->f_refs->n;i++)
1030 if(func->f_refs->s2[i])
1032 if(HTML32 && i!=others)
1033 fprintf(of,"<tr><td>&nbsp;\n");
1034 if(HTML20)
1035 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s1[i],0),html(func->f_refs->s2[i],0));
1036 else
1037 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s1[i],0),goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s2[i],0));
1039 else
1040 others++;
1042 if(others)
1044 if(HTML20)
1045 fprintf(of,"<li>");
1046 else if(i==others)
1047 fprintf(of,"<td colspan=2>");
1048 else
1049 fprintf(of,"<tr><td>&nbsp;\n<td colspan=2>");
1050 for(i=0;i<func->f_refs->n;i++)
1051 if(!func->f_refs->s2[i])
1052 fprintf(of,--others?"%s(), ":"%s()",html(func->f_refs->s1[i],0));
1053 fprintf(of,"\n");
1056 if(HTML20)
1057 fprintf(of,"</ul>\n");
1060 if(func->v_refs->n)
1062 int others=0;
1064 if(HTML20)
1065 fprintf(of,"<dt>References Variables:\n<dd><ul>\n");
1066 else
1067 fprintf(of,"<tr><td>References Variables:\n");
1069 for(i=0;i<func->v_refs->n;i++)
1070 if(func->v_refs->s2[i])
1072 if(HTML32 && i!=others)
1073 fprintf(of,"<tr><td>&nbsp;\n");
1074 if(HTML20)
1075 fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s : %s</a>\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s1[i],0),html(func->v_refs->s2[i],0));
1076 else
1077 fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a><td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s1[i],0),goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s2[i],0));
1079 else
1080 others++;
1082 if(others)
1084 if(HTML20)
1085 fprintf(of,"<li>");
1086 else if(i==others)
1087 fprintf(of,"<td colspan=2>");
1088 else
1089 fprintf(of,"<tr><td>&nbsp;\n<td colspan=2>");
1090 for(i=0;i<func->v_refs->n;i++)
1091 if(!func->v_refs->s2[i])
1092 fprintf(of,--others?"%s, ":"%s",html(func->v_refs->s1[i],0));
1093 fprintf(of,"\n");
1096 if(HTML20)
1097 fprintf(of,"</ul>\n");
1100 if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n)
1102 if(HTML20)
1103 fprintf(of,"</dl>\n");
1104 else
1105 fprintf(of,"\n</table>\n");
1110 /*++++++++++++++++++++++++++++++++++++++
1111 Write out a file that will include the current information.
1113 char* name The name of the file.
1115 int appendix set to non-zero if the appendix file is to be added, else a normal source file.
1116 ++++++++++++++++++++++++++++++++++++++*/
1118 static void WriteHTMLDocument(char* name,int appendix)
1120 FILE *in,*out;
1121 char line[256];
1122 int seen=0;
1123 char *inc_file,*ofile,*ifile;
1125 if(appendix)
1126 inc_file=ConcatStrings(4,"<a href=\"",name,HTML_FILE,"\">Appendix</a><br>\n");
1127 else
1128 inc_file=ConcatStrings(6,"<a href=\"",name,HTML_FILE,"#file\">",name,"</a><br>\n");
1129 ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE);
1130 ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP);
1132 in =fopen(ifile,"r");
1133 if(!in)
1135 in =fopen(ifile,"w");
1136 if(!in)
1137 {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ifile);exit(1);}
1139 WriteHTMLPreamble(in,ConcatStrings(3,"Cross Reference Of ",option_name,"."),1);
1140 WriteHTMLPostamble(in,1);
1141 fclose(in);
1143 in =fopen(ifile,"r");
1146 out=fopen(ofile,"w");
1148 if(!out)
1149 {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);exit(1);}
1151 while(fgets(line,256,in))
1153 if(!strcmp(inc_file,line) ||
1154 (!strncmp("<!--",line,4) && !strncmp(inc_file,line+4,strlen(inc_file))) ||
1155 (!strncmp("<!-- ",line,5) && !strncmp(inc_file,line+5,strlen(inc_file))))
1156 {seen=1;break;}
1157 if(line[0]=='<' && !strcmp("<!-- End-Of-Source-Files -->\n",line))
1159 if(appendix)
1161 fputs(line,out);
1162 fputs("\n",out);
1163 fputs("<!-- Appendix -->\n",out);
1164 fputs("\n",out);
1165 fputs("<hr>\n",out);
1166 fputs("<h1>Appendix</h1>\n",out);
1167 fputs("\n",out);
1168 fputs(inc_file,out);
1170 else
1172 fputs(inc_file,out);
1173 fputs("\n",out);
1174 fputs(line,out);
1177 else
1178 fputs(line,out);
1181 fclose(in);
1182 fclose(out);
1184 if(!seen)
1186 unlink(ifile);
1187 rename(ofile,ifile);
1189 else
1190 unlink(ofile);
1194 /*++++++++++++++++++++++++++++++++++++++
1195 Write out a standard pre-amble.
1197 FILE* f The file to write the pre amble to.
1199 char* title The title of the file.
1201 int sourcefile True if the Source-Files line is to be included.
1202 ++++++++++++++++++++++++++++++++++++++*/
1204 static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile)
1206 if(HTML20)
1207 fputs("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n",f);
1208 else
1209 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n",f);
1210 fputs("\n",f);
1211 fputs("<!-- This HTML file generated by cxref. -->\n",f);
1212 fputs("<!-- cxref program (c) Andrew M. Bishop 1995,96,97,98,99. -->\n",f);
1213 fputs("\n",f);
1214 if(!sourcefile)
1216 fputs("<!--\n",f);
1217 if(filename)
1218 fprintf(f,"Cxref: %s %s\n",run_command,filename);
1219 else
1220 fprintf(f,"Cxref: %s\n",run_command);
1221 fprintf(f,"CPP : %s\n",run_cpp_command);
1222 fputs("-->\n",f);
1223 fputs("\n",f);
1225 fputs("<HTML>\n",f);
1226 fputs("\n",f);
1227 fputs("<HEAD>\n",f);
1228 fputs("<TITLE>",f);
1229 fputs(title,f);
1230 fputs("</TITLE>\n",f);
1231 fputs("</HEAD>\n",f);
1232 fputs("\n",f);
1233 fputs("<BODY>\n",f);
1234 fputs("\n",f);
1235 if(sourcefile)
1237 fputs("<h1>Source Files</h1>\n",f);
1238 fputs("\n",f);
1239 fputs("<!-- Begin-Of-Source-Files -->\n",f);
1244 /*++++++++++++++++++++++++++++++++++++++
1245 Write out a standard post-amble. This includes the end of document marker.
1247 FILE* f The file to write the post amble to.
1249 int sourcefile True if the Source-Files line is to be included.
1250 ++++++++++++++++++++++++++++++++++++++*/
1252 static void WriteHTMLPostamble(FILE* f,int sourcefile)
1254 if(sourcefile)
1256 fputs("\n",f);
1257 fputs("<!-- End-Of-Source-Files -->\n",f);
1259 fputs("\n",f);
1260 fputs("</BODY>\n",f);
1261 fputs("</HTML>\n",f);
1265 /*++++++++++++++++++++++++++++++++++++++
1266 Write out the appendix information.
1268 StringList files The list of files to write.
1270 StringList2 funcs The list of functions to write.
1272 StringList2 vars The list of variables to write.
1274 StringList2 types The list of types to write.
1275 ++++++++++++++++++++++++++++++++++++++*/
1277 void WriteHTMLAppendix(StringList files,StringList2 funcs,StringList2 vars,StringList2 types)
1279 char* ofile;
1280 int i;
1282 filename=NULL;
1284 /* Write the bits to the including file. */
1286 WriteHTMLDocument(ConcatStrings(2,option_name,HTML_APDX),1);
1288 /* Open the file */
1290 ofile=ConcatStrings(5,option_odir,"/",option_name,HTML_APDX,HTML_FILE);
1292 of=fopen(ofile,"w");
1294 if(!of)
1295 {fprintf(stderr,"cxref: Failed to open the HTML appendix file '%s'\n",ofile);exit(1);}
1297 /* Write the file structure out */
1299 WriteHTMLPreamble(of,ConcatStrings(3,"Cross reference index of ",option_name,"."),0);
1301 fprintf(of,"<h1>Cross References</h1>\n");
1303 if(files->n || funcs->n || vars->n || types->n)
1305 fprintf(of,"<ul>\n");
1306 if(files->n)
1307 fprintf(of,"<li><a href=\"#files\">Files</a>\n");
1308 if(funcs->n)
1309 fprintf(of,"<li><a href=\"#functions\">Global Functions</a>\n");
1310 if(vars->n)
1311 fprintf(of,"<li><a href=\"#variables\">Global Variables</a>\n");
1312 if(types->n)
1313 fprintf(of,"<li><a href=\"#types\">Defined Types</a>\n");
1314 fprintf(of,"</ul>\n");
1317 /* Write out the appendix of files. */
1319 if(files->n)
1321 fprintf(of,"\n<hr>\n<h2><a name=\"files\">Files</a></h2>\n");
1322 fprintf(of,"<ul>\n");
1323 for(i=0;i<files->n;i++)
1324 fprintf(of,"<li><a href=\"%s"HTML_FILE"#file\">%s</a>\n",files->s[i],html(files->s[i],0));
1325 fprintf(of,"</ul>\n");
1328 /* Write out the appendix of functions. */
1330 if(funcs->n)
1332 fprintf(of,"\n<hr>\n<h2><a name=\"functions\">Global Functions</a></h2>\n");
1333 fprintf(of,"<ul>\n");
1334 for(i=0;i<funcs->n;i++)
1335 fprintf(of,"<li><a href=\"%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",funcs->s2[i],funcs->s1[i],html(funcs->s1[i],0),html(funcs->s2[i],0));
1336 fprintf(of,"</ul>\n");
1339 /* Write out the appendix of variables. */
1341 if(vars->n)
1343 fprintf(of,"\n<hr>\n<h2><a name=\"variables\">Global Variables</a></h2>\n");
1344 fprintf(of,"<ul>\n");
1345 for(i=0;i<vars->n;i++)
1346 fprintf(of,"<li><a href=\"%s"HTML_FILE"#var-%s\">%s : %s</a>\n",vars->s2[i],vars->s1[i],html(vars->s1[i],0),html(vars->s2[i],0));
1347 fprintf(of,"</ul>\n");
1350 /* Write out the appendix of types. */
1352 if(types->n)
1354 fprintf(of,"\n<hr>\n<h2><a name=\"types\">Defined Types</a></h2>\n");
1355 fprintf(of,"<ul>\n");
1356 for(i=0;i<types->n;i++)
1357 if(!strncmp("enum",types->s1[i],4))
1358 fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-enum-%s\">%s : %s</a>\n",types->s2[i],&types->s1[i][5],html(types->s1[i],0),html(types->s2[i],0));
1359 else
1360 if(!strncmp("union",types->s1[i],5))
1361 fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-union-%s\">%s : %s</a>\n",types->s2[i],&types->s1[i][6],html(types->s1[i],0),html(types->s2[i],0));
1362 else
1363 if(!strncmp("struct",types->s1[i],6))
1364 fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-struct-%s\">%s : %s</a>\n",types->s2[i],&types->s1[i][7],html(types->s1[i],0),html(types->s2[i],0));
1365 else
1366 fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-%s\">%s : %s</a>\n",types->s2[i],types->s1[i],html(types->s1[i],0),html(types->s2[i],0));
1367 fprintf(of,"</ul>\n");
1370 WriteHTMLPostamble(of,0);
1372 fclose(of);
1374 /* Clear the memory in html(,0) */
1376 html(NULL,0); html(NULL,0); html(NULL,0); html(NULL,0);
1380 /*++++++++++++++++++++++++++++++++++++++
1381 Delete the HTML file and main file reference that belong to the named file.
1383 char *name The name of the file to delete.
1384 ++++++++++++++++++++++++++++++++++++++*/
1386 void WriteHTMLFileDelete(char *name)
1388 FILE *in,*out;
1389 char line[256];
1390 int seen=0;
1391 char *inc_file,*ofile,*ifile;
1393 ofile=ConcatStrings(4,option_odir,"/",name,HTML_FILE);
1394 unlink(ofile);
1396 inc_file=ConcatStrings(6,"<a href=\"",name,HTML_FILE,"#file\">",name,"</a><br>\n");
1397 ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE);
1398 ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP);
1400 in =fopen(ifile,"r");
1401 out=fopen(ofile,"w");
1403 if(in && !out)
1404 {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);fclose(in);}
1405 else if(in)
1407 while(fgets(line,256,in))
1409 if(!strcmp(inc_file,line) ||
1410 (!strncmp("<!--",line,4) && !strncmp(inc_file,line+4,strlen(inc_file)-1)) ||
1411 (!strncmp("<!-- ",line,5) && !strncmp(inc_file,line+5,strlen(inc_file)-1)))
1412 seen=1;
1413 else
1414 fputs(line,out);
1417 fclose(in);
1418 fclose(out);
1420 if(seen)
1422 unlink(ifile);
1423 rename(ofile,ifile);
1425 else
1426 unlink(ofile);
1428 else if(out)
1430 fclose(out);
1431 unlink(ofile);
1436 /*++++++++++++++++++++++++++++++++++++++
1437 Write out the source file.
1439 char *name The name of the source file.
1440 ++++++++++++++++++++++++++++++++++++++*/
1442 void WriteHTMLSource(char *name)
1444 FILE *in,*out;
1445 char line[256];
1446 char *ofile,*ifile;
1447 int lineno=0;
1448 char pad[5];
1450 ifile=name;
1451 ofile=ConcatStrings(4,option_odir,"/",name,HTML_SRC_FILE);
1453 in =fopen(ifile,"r");
1454 if(!in)
1455 {fprintf(stderr,"cxref: Failed to open the source file '%s'\n",ifile);exit(1);}
1457 out=fopen(ofile,"w");
1458 if(!out)
1459 {fprintf(stderr,"cxref: Failed to open the HTML output source file '%s'\n",ofile);exit(1);}
1461 WriteHTMLPreamble(out,ConcatStrings(2,"Source File ",name),0);
1462 fputs("<pre>\n",out);
1464 strcpy(pad," ");
1466 while(fgets(line,256,in))
1468 lineno++;
1469 if(lineno==10)
1470 pad[3]=0;
1471 else if(lineno==100)
1472 pad[2]=0;
1473 else if(lineno==1000)
1474 pad[1]=0;
1475 else if(lineno==10000)
1476 pad[0]=0;
1477 fprintf(out,"<a name=\"line%d\">%d%s|</a> %s",lineno,lineno,pad,html(line,1));
1480 fputs("</pre>\n",out);
1481 WriteHTMLPostamble(out,0);
1483 fclose(in);
1484 fclose(out);
1488 /*++++++++++++++++++++++++++++++++++++++
1489 Make the input string safe to output as HTML ( not <, >, & or " ).
1491 char* html Returns a safe HTML string.
1493 char* c A non-safe HTML string.
1495 int verbatim Set to true if the text is to be output verbatim ignoring the comment +html+ directives.
1497 The function can only be called four times in each fprintf() since it returns one of only four static strings.
1498 ++++++++++++++++++++++++++++++++++++++*/
1500 static char* html(char* c,int verbatim)
1502 static char safe[4][256],*malloced[4]={NULL,NULL,NULL,NULL};
1503 static int which=0;
1504 int copy=0,skip=0;
1505 int i=0,j=0,delta=7,len=256-delta;
1506 char* ret;
1508 which=(which+1)%4;
1509 ret=safe[which];
1511 safe[which][0]=0;
1513 if(malloced[which])
1514 {Free(malloced[which]);malloced[which]=NULL;}
1516 if(c)
1518 if(!verbatim)
1519 i=CopyOrSkip(c,"html",&copy,&skip);
1521 while(1)
1523 for(;j<len && c[i];i++)
1525 if(copy)
1526 {ret[j++]=c[i]; if(c[i]=='\n') copy=0;}
1527 else if(skip)
1528 { if(c[i]=='\n') skip=0;}
1529 else
1530 switch(c[i])
1532 case 12: /* ^L */
1533 break;
1534 case '<':
1535 strcpy(&ret[j],"&lt;");j+=4;
1536 break;
1537 case '>':
1538 strcpy(&ret[j],"&gt;");j+=4;
1539 break;
1540 case '&':
1541 strcpy(&ret[j],"&amp;");j+=5;
1542 break;
1543 case '\n':
1544 if(j && ret[j-1]=='\n')
1546 strcpy(&ret[j],"<br>");j+=4;
1548 ret[j++]=c[i];
1549 break;
1550 default:
1551 ret[j++]=c[i];
1553 if(c[i]=='\n')
1554 if(!verbatim)
1555 i+=CopyOrSkip(c+i,"html",&copy,&skip);
1558 if(c[i]) /* Not finished */
1560 if(malloced[which])
1561 malloced[which]=Realloc(malloced[which],len+delta+256);
1562 else
1563 {malloced[which]=Malloc(len+delta+256); strncpy(malloced[which],ret,(unsigned)j);}
1564 ret=malloced[which];
1565 len+=256;
1567 else
1568 {ret[j]=0; break;}
1572 return(ret);